From 767b1d60d9a2a371a98479d18f4e189a9480cc3a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Feb 2023 00:16:02 +0100 Subject: [PATCH] Debug v17 --- htdocs/bookmarks/list.php | 373 +++++++++++++----- htdocs/core/actions_massactions.inc.php | 1 - htdocs/core/class/html.form.class.php | 3 + .../modulebuilder/template/myobject_list.php | 9 +- 4 files changed, 286 insertions(+), 100 deletions(-) diff --git a/htdocs/bookmarks/list.php b/htdocs/bookmarks/list.php index c6af6bfdc11..3097d40c141 100644 --- a/htdocs/bookmarks/list.php +++ b/htdocs/bookmarks/list.php @@ -33,11 +33,14 @@ $action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); $show_files = GETPOST('show_files', 'int'); $confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button $toselect = GETPOST('toselect', 'array'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search -$id = GETPOST("id", 'int'); +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'alpha'); -$mode = GETPOST('mode', 'aZ09'); +$mode = GETPOST('mode', 'aZ'); + +$id = GETPOST("id", 'int'); // Load variable for pagination $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; @@ -60,10 +63,17 @@ if (!$sortorder) { // Initialize Objects $object = new Bookmark($db); +$extrafields = new ExtraFields($db); +$arrayfields = array(); +$hookmanager->initHooks(array('bookmarklist')); // Note that conf->hooks_modules contains array + if ($id > 0) { $object->fetch($id); } +$object->fields = dol_sort_array($object->fields, 'position'); +$arrayfields = dol_sort_array($arrayfields, 'position'); + // Security check restrictedArea($user, 'bookmark', $object); @@ -85,18 +95,39 @@ if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massa $massaction = ''; } -if ($action == 'delete' && $permissiontodelete) { - $object->fetch($id); - $res = $object->delete($user); - if ($res > 0) { - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } +$parameters = array(); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } +if (empty($reshook)) { + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { + $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } + + // Mass actions + $objectclass = 'Bookmark'; + $objectlabel = 'Bookmark'; + $uploaddir = $conf->bookmark->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + if ($action == 'delete' && $permissiontodelete) { + $object->fetch($id); + $res = $object->delete($user); + if ($res > 0) { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + } +} /* @@ -105,16 +136,34 @@ if ($action == 'delete' && $permissiontodelete) { $form = new Form($db); +$now = dol_now(); + +//$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject"; +$help_url = ''; $title = $langs->trans("Bookmarks"); +$morejs = array(); +$morecss = array(); -llxHeader('', $title); +// Build and execute select +// -------------------------------------------------------------------- $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,"; $sql .= " u.login, u.lastname, u.firstname"; +// 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 : ''); + } +} +// Add fields from hooks +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= preg_replace('/^,/', '', $hookmanager->resPrint); +$sql = preg_replace('/,\s*$/', '', $sql); $sqlfields = $sql; // $sql fields to remove for count total -$sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid"; +$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid"; $sql .= " WHERE 1=1"; $sql .= " AND b.entity IN (".getEntity('bookmark').")"; if (!$user->admin) { @@ -156,7 +205,18 @@ if (!$resql) { $num = $db->num_rows($resql); + +// Output page +// -------------------------------------------------------------------- + +llxHeader('', $title); + +$arrayofselected = is_array($toselect) ? $toselect : array(); + $param = ''; +if (!empty($mode)) { + $param .= '&mode='.urlencode($mode); +} if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); } @@ -166,8 +226,12 @@ if ($limit > 0 && $limit != $conf->liste_limit) { if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } - -$moreforfilter = ''; +// Add $param from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; +// Add $param from hooks +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook +$param .= $hookmanager->resPrint; // List of mass actions available $arrayofmassactions = array( @@ -195,18 +259,59 @@ print ''; print ''; print ''; print ''; +print ''; print ''; + $newcardbutton = ''; $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bookmarks/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/bookmarks/list.php'), '', $permissiontoadd); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1); -print '
'; -print ''."\n"; +// Add code for pre mass action (confirmation or email presend form) +$topicmail = "SendBookmarkRef"; +$modelmail = "bookmark"; +$objecttmp = new Bookmark($db); +$trackid = 'bookmark'.$object->id; +include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; +$moreforfilter = ''; + +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} + +if (!empty($moreforfilter)) { + print '
'; + print $moreforfilter; + print '
'; +} + +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; +$selectedfields = $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"; + +// Fields title search +// -------------------------------------------------------------------- +// TODO + +$totalarray = array(); +$totalarray['nbfield'] = 0; + +// Fields title label +// -------------------------------------------------------------------- print ''; -//print ""; +if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; +} print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, '', $sortfield, $sortorder); @@ -214,102 +319,176 @@ print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "b.target", "", $param, print_liste_field_titre("Visibility", $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "b.dateb", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, '', $sortfield, $sortorder, 'right '); -print_liste_field_titre(''); -print "\n"; +if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; +} +print ''."\n"; +$totalarray = array(); +$totalarray['nbfield'] = 0; + +// Loop on record +// -------------------------------------------------------------------- $i = 0; -while ($i < min($num, $limit)) { +$savnbfield = $totalarray['nbfield']; +$totalarray = array(); +$totalarray['nbfield'] = 0; +$imaxinloop = ($limit ? min($num, $limit) : $num); +while ($i < $imaxinloop) { $obj = $db->fetch_object($resql); + if (empty($obj)) { + break; // Should not happen + } $object->id = $obj->rowid; $object->ref = $obj->rowid; - print ''; - - // Id - print ''; - - $linkintern = 1; - if (preg_match('/^http/i', $obj->url)) { - $linkintern = 0; - } - $title = $obj->title; - $link = $obj->url; - $canedit = $permissiontoadd; - $candelete = $permissiontodelete; - - // Title - print '\n"; - - // Url - print '\n"; - - // Target - print '\n"; - - // Author - print ''; + } + } else { + // Show here line of result + $j = 0; + print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } - } - print "\n"; - // Date creation - print '"; + // Id + print ''; - // Position - print '"; + $linkintern = 1; + if (preg_match('/^http/i', $obj->url)) { + $linkintern = 0; + } + $title = $obj->title; + $link = $obj->url; + $canedit = $permissiontoadd; + $candelete = $permissiontodelete; - // Actions - print '\n"; + + // Url + print '\n"; + + // Target + print '\n"; + + // Author + print '\n"; + + // Date creation + print '"; + + // Position + print '"; + + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + + print "\n"; } - if ($candelete) { - print 'rowid.'">'.img_delete().''; - } - print ""; - print "\n"; + $i++; } -print "
 
'; - print $object->getNomUrl(1); - print ''; - print dol_escape_htmltag($title); - print "'; - if (empty($linkintern)) { - print img_picto('', 'url', 'class="pictofixedwidth"'); - print 'target ? ' target="newlink" rel="noopener"' : '').'>'; - } else { - //print img_picto('', 'rightarrow', 'class="pictofixedwidth"'); - print ''; - } - print $link; - print ''; - print "'; - if ($obj->target == 0) { - print $langs->trans("BookmarkTargetReplaceWindowShort"); - } - if ($obj->target == 1) { - print $langs->trans("BookmarkTargetNewWindowShort"); - } - print "'; - if ($obj->fk_user > 0) { - if (empty($conf->cache['users'][$obj->fk_user])) { - $tmpuser = new User($db); - $tmpuser->fetch($obj->fk_user); - $conf->cache['users'][$obj->fk_user] = $tmpuser; + if ($mode == 'kanban') { + if ($i == 0) { + print '
'; + print '
'; } - $tmpuser = $conf->cache['users'][$obj->fk_user]; - print $tmpuser->getNomUrl(-1); - } else { - print ''.$langs->trans("Everybody").''; - if (!$user->admin) { - $candelete = false; - $canedit = false; + // Output Kanban + print $object->getKanbanView(''); + if ($i == ($imaxinloop - 1)) { + print '
'; + 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_print_date($db->jdate($obj->dateb), 'day')."'; + print $object->getNomUrl(1); + print ''.$obj->position."'; - if ($canedit) { - print ''.img_edit().""; + // Title + print ''; + print dol_escape_htmltag($title); + print "'; + if (empty($linkintern)) { + print img_picto('', 'url', 'class="pictofixedwidth"'); + print 'target ? ' target="newlink" rel="noopener"' : '').'>'; + } else { + //print img_picto('', 'rightarrow', 'class="pictofixedwidth"'); + print ''; + } + print $link; + print ''; + print "'; + if ($obj->target == 0) { + print $langs->trans("BookmarkTargetReplaceWindowShort"); + } + if ($obj->target == 1) { + print $langs->trans("BookmarkTargetNewWindowShort"); + } + print "'; + if ($obj->fk_user > 0) { + if (empty($conf->cache['users'][$obj->fk_user])) { + $tmpuser = new User($db); + $tmpuser->fetch($obj->fk_user); + $conf->cache['users'][$obj->fk_user] = $tmpuser; + } + $tmpuser = $conf->cache['users'][$obj->fk_user]; + print $tmpuser->getNomUrl(-1); + } else { + print ''.$langs->trans("Everybody").''; + if (!$user->admin) { + $candelete = false; + $canedit = false; + } + } + print "'.dol_print_date($db->jdate($obj->dateb), 'day')."'.$obj->position."'; + 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 '
"; -print '
'; + +// Show total line +include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; + +// If no record found +if ($num == 0) { + $colspan = 1; + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } + print ''.$langs->trans("NoRecordFound").''; +} $db->free($resql); +$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); +$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; + +print ''."\n"; +print ''."\n"; + +print ''."\n"; + // End of page llxFooter(); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 6fe7ab2ac5d..234eeb1e688 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -684,7 +684,6 @@ if (!$error && $massaction == 'cancelorders') { $nbok = 0; - $orders = GETPOST('toselect', 'array'); foreach ($orders as $id_order) { $cmd = new Commande($db); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e04c0bddf11..921618f7edc 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -8534,6 +8534,9 @@ class Form if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { return ''; } + if (empty($array)) { + return ''; + } $tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; // To get list of saved selected fields to show diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 9c27366867f..075813eaed9 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -247,6 +247,9 @@ if (empty($reshook)) { $objectlabel = 'MyObject'; $uploaddir = $conf->mymodule->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + // You can add more action here + // if ($action == 'xxx' && $permissiontoxxx) ... } @@ -547,7 +550,6 @@ $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('che print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; - // Fields title search // -------------------------------------------------------------------- print ''; @@ -620,6 +622,7 @@ $totalarray['nbfield'] = 0; print ''; if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; } foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']); @@ -651,10 +654,12 @@ print $hookmanager->resPrint; // Action column if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; + $totalarray['nbfield']++; } -$totalarray['nbfield']++; print ''."\n"; +$totalarray = array(); +$totalarray['nbfield'] = 0; // Detect if we need a fetch on each output line $needToFetchEachLine = 0;