From feba323283b713e1802b224c8a3fb10eb6ea8cde Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jun 2023 14:09:35 +0200 Subject: [PATCH] Debug v18 --- htdocs/intracommreport/list.php | 258 +++++++++++++++++++++----------- 1 file changed, 174 insertions(+), 84 deletions(-) diff --git a/htdocs/intracommreport/list.php b/htdocs/intracommreport/list.php index c8c6ddfef36..a2c857fc1c7 100644 --- a/htdocs/intracommreport/list.php +++ b/htdocs/intracommreport/list.php @@ -38,7 +38,7 @@ $show_files = GETPOST('show_files', 'int'); $confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); -$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); +$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $search_ref = GETPOST("search_ref", 'alpha'); $search_type = GETPOST("search_type", 'int'); $optioncss = GETPOST('optioncss', 'alpha'); @@ -49,10 +49,11 @@ $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user- $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0); -if (empty($page) || $page == -1) { +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { + // If $page is not defined, or '' or -1 or if we click on clear filters $page = 0; -} // If $page is not defined, or '' or -1 +} $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -178,7 +179,7 @@ if (empty($reshook)) { // Purge search criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - $sall = ""; + $search_all = ""; $search_ref = ""; $search_label = ""; //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type. @@ -206,31 +207,34 @@ if (empty($reshook)) { */ $formother = new FormOther($db); +$intracommreport_static = new IntracommReport($db); $title = $langs->trans('IntracommReportList'.$type); +$helpurl = 'EN:Module_IntracommReport|FR:Module_ProDouane'; +// Build and execute select +// -------------------------------------------------------------------- $sql = 'SELECT i.rowid, i.type_declaration, i.type_export, i.periods, i.mode, i.entity'; - -/* // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); + } } -*/ // Add fields from hooks $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql = preg_replace('/,\s*$/', '', $sql); $sql .= $hookmanager->resPrint; -$sqlfields = $sql; +$sqlfields = $sql; // $sql fields to remove for count total $sql .= ' FROM '.MAIN_DB_PREFIX.'intracommreport as i'; // if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."intracommreport_extrafields as ef on (i.rowid = ef.fk_object)"; $sql .= ' WHERE i.entity IN ('.getEntity('intracommreport').')'; -if ($sall) { - $sql .= natural_search(array_keys($fieldstosearchall), $sall); +if ($search_all) { + $sql .= natural_search(array_keys($fieldstosearchall), $search_all); } // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($search_type) && $search_type != '-1') { @@ -256,23 +260,24 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; */ // Add where from hooks $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= " GROUP BY i.rowid, i.type_declaration, i.type_export, i.periods, i.mode, i.entity"; - +// Add groupby from hooks /* -// Add fields from extrafields -if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); -} +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +$sql = preg_replace('/,\s*$/', '', $sql); */ -// Add fields from hooks -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; - +// Add HAVING from hooks +/* + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint; + */ // Count total nb of records $nbtotalofrecords = ''; @@ -288,7 +293,7 @@ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { dol_print_error($db); } - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -309,7 +314,10 @@ if (!$resql) { $num = $db->num_rows($resql); -$helpurl = 'EN:Module_IntracommReport|FR:Module_ProDouane'; + +// Output page +// -------------------------------------------------------------------- + llxHeader('', $title, $helpurl, ''); // Displays product removal confirmation @@ -329,8 +337,8 @@ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.((int) $limit); } -if ($sall) { - $param .= "&sall=".urlencode($sall); +if ($search_all) { + $param .= "&search_all=".urlencode($search_all); } if ($search_ref) { $param = "&search_ref=".urlencode($search_ref); @@ -367,7 +375,7 @@ if ($user->rights->intracommreport->write) { $newcardbutton .= dolGetButtonTitle($langs->trans("NewDeclaration"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/intracommreport/card.php?action=create&type='.$type); } -print '
'; +print ''; if ($optioncss != '') { print ''; } @@ -377,6 +385,9 @@ print ''; print ''; print ''; print ''; +print ''; +print ''; +print ''; print ''; if (empty($arrayfields['i.fk_product_type']['checked'])) { print ''; @@ -390,38 +401,50 @@ $objecttmp = new IntracommReport($db); $trackid = 'prod'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -if ($sall) { +if ($search_all) { + $setupstring = ''; foreach ($fieldstosearchall as $key => $val) { $fieldstosearchall[$key] = $langs->trans($val); + $setupstring .= $key."=".$val.";"; } - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; + print ''."\n"; + print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; } $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $moreforfilter .= $hookmanager->resPrint; } else { $moreforfilter = $hookmanager->resPrint; } -if ($moreforfilter) { +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print '
'; } $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; -$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields -if ($massactionbutton) { - $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); -} +$selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields +$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); print '
'; -print ''."\n"; +print '
'."\n"; -// Lines with input filters +// Fields title search +// -------------------------------------------------------------------- print ''; +// Action column +if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; +} if (!empty($arrayfields['i.ref']['checked'])) { print ''; } -print ''; +// Action column +if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; +} -print ''; +print ''."\n"; +$totalarray = array(); +$totalarray['nbfield'] = 0; + +// Fields title label +// -------------------------------------------------------------------- print ''; +// Action column +if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; +} if (!empty($arrayfields['i.ref']['checked'])) { print_liste_field_titre($arrayfields['i.ref']['label'], $_SERVER["PHP_SELF"], "i.ref", "", $param, "", $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['i.label']['checked'])) { print_liste_field_titre($arrayfields['i.label']['label'], $_SERVER["PHP_SELF"], "i.label", "", $param, "", $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['i.fk_product_type']['checked'])) { print_liste_field_titre($arrayfields['i.fk_product_type']['label'], $_SERVER["PHP_SELF"], "i.fk_product_type", "", $param, "", $sortfield, $sortorder); + $totalarray['nbfield']++; } /* @@ -496,21 +535,32 @@ $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // No print $hookmanager->resPrint; if (!empty($arrayfields['i.datec']['checked'])) { print_liste_field_titre($arrayfields['i.datec']['label'], $_SERVER["PHP_SELF"], "i.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + $totalarray['nbfield']++; } if (!empty($arrayfields['i.tms']['checked'])) { print_liste_field_titre($arrayfields['i.tms']['label'], $_SERVER["PHP_SELF"], "i.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + $totalarray['nbfield']++; } - -print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); -print "\n"; +// Action column +if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; +} +print ''."\n"; -$intracommreport_static = new IntracommReport($db); - +// Loop on record +// -------------------------------------------------------------------- $i = 0; +$savnbfield = $totalarray['nbfield']; $totalarray = array(); -while ($i < min($num, $limit)) { +$totalarray['nbfield'] = 0; +$imaxinloop = ($limit ? min($num, $limit) : $num); +while ($i < $imaxinloop) { $obj = $db->fetch_object($resql); + if (empty($obj)) { + break; // Should not happen + } $intracommreport_static->id = $obj->rowid; $intracommreport_static->ref = $obj->ref; @@ -522,46 +572,86 @@ while ($i < min($num, $limit)) { $intracommreport_static->status_batch = $obj->tobatch; $intracommreport_static->entity = $obj->entity; - print ''; + if ($mode == 'kanban') { + if ($i == 0) { + print ''; + } + } else { + // Show line of result + $j = 0; + print ''; - // Ref - if (!empty($arrayfields['i.ref']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } - } - // Label - if (!empty($arrayfields['i.label']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; + + // Ref + if (!empty($arrayfields['i.ref']['checked'])) { + print '\n"; + if (!$i) { + $totalarray['nbfield']++; + } } - } - // Type - if (!empty($arrayfields['i.fk_product_type']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; + // Label + if (!empty($arrayfields['i.label']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } - } - // Action - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } - print ''; - } - print ''; - if (!$i) { - $totalarray['nbfield']++; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + + print ''."\n"; } - print "\n"; $i++; }
'; + $searchpicto = $form->showFilterButtons('left'); + print $searchpicto; + print ''; print ''; @@ -456,7 +479,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; */ // Fields from hook $parameters = array('arrayfields'=>$arrayfields); -$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation if (!empty($arrayfields['i.datec']['checked'])) { @@ -468,22 +491,38 @@ if (!empty($arrayfields['i.tms']['checked'])) { print ''; print ''; -$searchpicto = $form->showFilterButtons(); -print $searchpicto; -print ''; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'; + print '
'; + } + // Output Kanban + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($object->id, $arrayofselected)) { + $selected = 1; + } + } + print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected))); + if ($i == ($imaxinloop - 1)) { + print '
'; + print '
'; - print $intracommreport_static->getNomUrl(1); - print "'; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($object->id, $arrayofselected)) { + $selected = 1; + } + print ''; + } + print ''.dol_trunc($obj->label, 80).''; + print $intracommreport_static->getNomUrl(1); + print "'.$obj->fk_product_type.''.dol_trunc($obj->label, 80).''; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) { - $selected = 1; + // Type + if (!empty($arrayfields['i.fk_product_type']['checked'])) { + print ''.$obj->fk_product_type.''; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } + } + print ''; + print '