diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index dcf6681df0e..125b88c5b8e 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -68,22 +68,17 @@ $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', $optioncss = GETPOST('optioncss', 'alpha'); $socid = GETPOST('socid', 'int'); -// Security check -$id = GETPOST('id', 'int'); -if ($user->socid) { - $socid = $user->socid; -} -$result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); - $diroutputmassaction = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id; +// Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { +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; @@ -100,7 +95,7 @@ $hookmanager->initHooks(array('interventionlist')); $extrafields = new ExtraFields($db); -// fetch optionals attributes and labels +// Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); @@ -143,13 +138,24 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); +// Security check +$id = GETPOST('id', 'int'); +if ($user->socid) { + $socid = $user->socid; +} +$result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); + +$permissiontoread = $user->rights->ficheinter->lire; +$permissiontodelete = $user->rights->ficheinter->supprimer; + /* * Actions */ if (GETPOST('cancel', 'alpha')) { - $action = 'list'; $massaction = ''; + $action = 'list'; + $massaction = ''; } if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; @@ -181,8 +187,6 @@ if (empty($reshook)) { // Mass actions $objectclass = 'Fichinter'; $objectlabel = 'Interventions'; - $permissiontoread = $user->rights->ficheinter->lire; - $permissiontodelete = $user->rights->ficheinter->supprimer; $uploaddir = $conf->ficheinter->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -193,7 +197,6 @@ if (empty($reshook)) { * View */ -$now = dol_now(); $form = new Form($db); $formfile = new FormFile($db); @@ -206,8 +209,13 @@ if (!empty($conf->contrat->enabled)) { $contratstatic = new Contrat($db); } +$now = dol_now(); + +$help_url = ''; $title = $langs->trans("ListOfInterventions"); -llxHeader('', $title); +$morejs = array(); +$morecss = array(); + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields @@ -305,473 +313,541 @@ if ($sall) { 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); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; // Add GroupBy from hooks $parameters = array('all' => $all, 'fieldstosearchall' => $fieldstosearchall); $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; -$sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + /* This old and fast method to get and count full list returns all record so use a high amount of memory. */ + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + /* The fast and low memory method to get and count full list converts the sql into a sql count */ + /*$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $resql = $db->query($sqlforcount); + if ($resql) { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + } else { + dol_print_error($db); + }*/ + + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } + $db->free($resql); } -$sql .= $db->plimit($limit + 1, $offset); -//print $sql; +// Complete request and execute it with limit +$sql .= $db->order($sortfield, $sortorder); +if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); +} $resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); +if (!$resql) { + dol_print_error($db); + exit; +} - $arrayofselected = is_array($toselect) ? $toselect : array(); +$num = $db->num_rows($resql); - if ($socid > 0) { - $soc = new Societe($db); - $soc->fetch($socid); - if (empty($search_company)) { - $search_company = $soc->name; - } - } - $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); - } - if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.urlencode($limit); - } - if ($sall) { - $param .= "&sall=".urlencode($sall); - } - if ($socid) { - $param .= "&socid=".urlencode($socid); - } - if ($search_ref) { - $param .= "&search_ref=".urlencode($search_ref); - } - if ($search_ref_client) { - $param .= "&search_ref_client=".urlencode($search_ref_client); - } - if ($search_company) { - $param .= "&search_company=".urlencode($search_company); - } - if ($search_desc) { - $param .= "&search_desc=".urlencode($search_desc); - } - if ($search_status != '' && $search_status > -1) { - $param .= "&search_status=".urlencode($search_status); - } - if ($show_files) { - $param .= '&show_files='.urlencode($show_files); - } - if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); - } - // Add $param from extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; +// Direct jump if only one record found +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) { + $obj = $db->fetch_object($resql); + $id = $obj->rowid; + header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id); + exit; +} - // List of mass actions available - $arrayofmassactions = array( - 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), - 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), - //'presend'=>$langs->trans("SendByMail"), - ); - if ($user->rights->ficheinter->supprimer) { - $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); - } - if (in_array($massaction, array('presend', 'predelete'))) { - $arrayofmassactions = array(); - } - $massactionbutton = $form->selectMassAction('', $arrayofmassactions); - $newcardbutton = ''; +// Output page +// -------------------------------------------------------------------- - $url = DOL_URL_ROOT.'/fichinter/card.php?action=create'; - if (!empty($socid)) { - $url .= '&socid='.$socid; - } - $newcardbutton = dolGetButtonTitle($langs->trans('NewIntervention'), '', 'fa fa-plus-circle', $url, '', $user->rights->ficheinter->creer); +llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); - // Lines of title fields - print '
'."\n"; + +if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { $hidegeneratedfilelistifempty = 1; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { $hidegeneratedfilelistifempty = 0; } + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + $formfile = new FormFile($db); + // Show list of available documents $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource .= str_replace('&', '&', $param); @@ -821,10 +912,8 @@ if ($resql) { $delallowed = $user->rights->ficheinter->creer; print $formfile->showdocuments('massfilesarea_interventions', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); -} else { - dol_print_error($db); } - +// End of page llxFooter(); $db->close(); diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 595dd077b0e..22ce7e61e7f 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -334,6 +334,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; +$sql .= $db->order($sortfield, $sortorder); /* If a group by is required $sql .= " GROUP BY ";