From 735309b010eb9e02c5fe8ecd4f53bbcbcc266f0a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Dec 2022 01:27:42 +0100 Subject: [PATCH] Dolibarrization --- .../modulebuilder/template/myobject_list.php | 2 +- htdocs/user/group/list.php | 417 ++++++++++++------ 2 files changed, 271 insertions(+), 148 deletions(-) diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 29c9205b1f0..5defa10af43 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -651,7 +651,7 @@ print $hookmanager->resPrint; if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; } -$totalarray['nbfield']++; +$totalarray['nbfield']++; // For the column action print ''."\n"; diff --git a/htdocs/user/group/list.php b/htdocs/user/group/list.php index 1806fd15605..9f7505c3de1 100644 --- a/htdocs/user/group/list.php +++ b/htdocs/user/group/list.php @@ -32,33 +32,45 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; // Load translation files required by page $langs->load("users"); -$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); -$search_group = GETPOST('search_group'); -$optioncss = GETPOST('optioncss', 'alpha'); +$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) -$contextpage = GETPOST('optioncss', 'aZ09'); -$mode = GETPOST('mode', 'aZ'); +$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? +$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation +$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ09'); // Option for the css output (always '' except when 'print') +$mode = GETPOST('mode', 'aZ'); - -// Defini si peux lire/modifier utilisateurs et permisssions -$caneditperms = ($user->admin || $user->hasRight("user", "user", "write")); -// Advanced permissions -if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { - $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write")); -} +$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); +$search_group = GETPOST('search_group'); // 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; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; +// Initialize technical objects +$object = new UserGroup($db); +$extrafields = new ExtraFields($db); +//$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id; +//$hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); +//$extrafields->fetch_name_optionals_label($object->table_element_line); + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + if (!$sortfield) { $sortfield = "g.nom"; } @@ -87,20 +99,28 @@ if (!$user->hasRight("user", "user", "read") && !$user->admin) { accessforbidden(); } +// Defini si peux lire/modifier utilisateurs et permisssions +$caneditperms = ($user->admin || $user->hasRight("user", "user", "write")); +// Advanced permissions +if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { + $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write")); +} + /* * Actions */ if (GETPOST('cancel', 'alpha')) { - $action = 'list'; $massaction = ''; + $action = 'list'; + $massaction = ''; } if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $parameters = array(); -$reshook = $hookmanager->executeHooks('doActions', $parameters); // Note that $action and $object may have been modified by some hooks +$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'); } @@ -110,22 +130,33 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers - $search_label = ""; - $search_date_creation = ""; - $search_date_update = ""; + 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 + foreach ($object->fields as $key => $val) { + $search[$key] = ''; + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = ''; + $search[$key.'_dtend'] = ''; + } + } + $toselect = array(); $search_array_options = array(); } + 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 + } } - /* * View */ -$title = $langs->trans("UserGroups"); + $help_url=""; -llxHeader('', $title, $help_url); +$title = $langs->trans("UserGroups"); +$morejs = array(); +$morecss = array(); + $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec, g.tms as datem, COUNT(DISTINCT ugu.fk_user) as nb, COUNT(DISTINCT ugr.fk_id) as nbpermissions"; $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g"; @@ -139,139 +170,231 @@ if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULT if (!empty($search_group)) { natural_search(array("g.nom", "g.note"), $search_group); } -if ($sall) { - $sql .= natural_search(array("g.nom", "g.note"), $sall); +if ($search_all) { + $sql .= natural_search(array("g.nom", "g.note"), $search_all); } $sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec, g.tms"; + +// 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); - - $nbtotalofrecords = $num; - - $i = 0; - - $param = "&search_group=".urlencode($search_group)."&sall=".urlencode($sall); - if (!empty($mode)) { - $param .= '&mode='.urlencode($mode); - } - - if ($optioncss != '') { - $param .= '&optioncss='.$optioncss; - } - - $text = $langs->trans("UserGroups"); - - $newcardbutton = ''; - $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); - $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); - - if ($caneditperms) { - $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu='); - } - - print '
'."\n"; - if ($optioncss != '') { - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - - print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1); - - if ($sall) { - foreach ($fieldstosearchall as $key => $val) { - $fieldstosearchall[$key] = $langs->trans($val); - } - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; - } - - $moreforfilter = ''; - - //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; - //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - - print '
'; - print ''."\n"; - - print ''; - print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder); - //multicompany - if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) { - print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center '); - } - print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center '); - print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center '); - print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center '); - print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "g.tms", $param, "", '', $sortfield, $sortorder, 'center '); - print_liste_field_titre("", $_SERVER["PHP_SELF"]); - print "\n"; - - $grouptemp = new UserGroup($db); - - $imaxinloop = ($limit ? min($num, $limit) : $num); - - while ($i < $imaxinloop) { - $obj = $db->fetch_object($resql); - $grouptemp->setVarsFromFetchObj($obj); - - $grouptemp->name = $obj->name; - $grouptemp->note = $obj->note; - $grouptemp->members = $obj->nb; - $grouptemp->nb_rights = $obj->nbpermissions; - - if ($mode == 'kanban') { - if ($i == 0) { - print ''; - } - } else { - print ''; - print '"; - //multicompany - if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) { - $mc->getInfo($obj->entity); - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $i++; - } - print "
'; - print '
'; - } - // Output Kanban - print $grouptemp->getKanbanView(''); - if ($i == ($imaxinloop - 1)) { - print '
'; - print '
'; - print $grouptemp->getNomUrl(1); - if (isModEnabled('multicompany') && !$obj->entity) { - print img_picto($langs->trans("GlobalGroup"), 'redstar'); - } - print "'.dol_escape_htmltag($mc->label).''.$obj->nb.''; - print ''.$obj->nbpermissions.''; - print ''.dol_print_date($db->jdate($obj->datec), "dayhour").''.dol_print_date($db->jdate($obj->datem), "dayhour").'
"; - - print '
'; - print "
\n"; - - $db->free($resql); -} else { +if (!$resql) { dol_print_error($db); + exit; } +$num = $db->num_rows($resql); + + +$nbtotalofrecords = $num; + +$i = 0; + + +// Output page +// -------------------------------------------------------------------- + +llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); + +$arrayofselected = is_array($toselect) ? $toselect : array(); + +$param = "&search_group=".urlencode($search_group)."&search_all=".urlencode($search_all); +if (!empty($mode)) { + $param .= '&mode='.urlencode($mode); +} +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +foreach ($search as $key => $val) { + if (is_array($search[$key])) { + foreach ($search[$key] as $skey) { + if ($skey != '') { + $param .= '&search_'.$key.'[]='.urlencode($skey); + } + } + } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) { + $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int')); + $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int')); + $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int')); + } elseif ($search[$key] != '') { + $param .= '&search_'.$key.'='.urlencode($search[$key]); + } +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); +} + +print '
'."\n"; +if ($optioncss != '') { + print ''; +} +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +$newcardbutton = ''; +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); + +if ($caneditperms) { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu='); +} + + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1); + +if ($search_all) { + $setupstring = ''; + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + $setupstring .= $key."=".$val.";"; + } + print ''."\n"; + print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; +} + +$moreforfilter = ''; + +//$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; +//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + +print '
'; +print ''."\n"; + +// Fields title search +// -------------------------------------------------------------------- +// ... + +// Fields title label +// -------------------------------------------------------------------- +print ''; +if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; +} +print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder); +$totalarray['nbfield']++; +//multicompany +if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) { + print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center '); + $totalarray['nbfield']++; +} +print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center '); +$totalarray['nbfield']++; +print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center '); +$totalarray['nbfield']++; +print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center '); +$totalarray['nbfield']++; +print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "g.tms", $param, "", '', $sortfield, $sortorder, 'center '); +$totalarray['nbfield']++; +print_liste_field_titre("", $_SERVER["PHP_SELF"]); +$totalarray['nbfield']++; // For the column action +print "\n"; + + + +$i = 0; +$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 + } + + // Store properties in $object + $object->setVarsFromFetchObj($obj); + + $object->name = $obj->name; + $object->note = $obj->note; + $object->members = $obj->nb; + $object->nb_rights = $obj->nbpermissions; + + if ($mode == 'kanban') { + if ($i == 0) { + print ''; + } + } else { + // Show here line of result + $j = 0; + print ''; + // Action column + if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print ''; + } + + print '"; + //multicompany + if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) { + $mc->getInfo($obj->entity); + print ''; + } + print ''; + print ''; + print ''; + print ''; + // Action column + if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print ''; + } + if (!$i) { + $totalarray['nbfield']++; + } + + print "\n"; + } + $i++; +} +print "
'; + print '
'; + } + // 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 ''; + print $object->getNomUrl(1); + if (isModEnabled('multicompany') && !$obj->entity) { + print img_picto($langs->trans("GlobalGroup"), 'redstar'); + } + print "'.dol_escape_htmltag($mc->label).''.$obj->nb.''; + print ''.$obj->nbpermissions.''; + print ''.dol_print_date($db->jdate($obj->datec), "dayhour").''.dol_print_date($db->jdate($obj->datem), "dayhour").''; + 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 '
'; +print "
\n"; + +$db->free($resql); + // End of page llxFooter(); $db->close();