From 650bb54051a9c516c4b25b7350d9faaffadcd4b7 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Tue, 8 Sep 2020 10:07:34 +0200 Subject: [PATCH 1/3] add common list function for module overview --- htdocs/admin/system/modules.php | 344 +++++++++++++++++++++++++++----- 1 file changed, 293 insertions(+), 51 deletions(-) diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index 1e5de3b9a46..bba227f9acc 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -25,32 +25,64 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -// Load translation files required by the page -$langs->loadLangs(array("install", "other", "admin")); - if (!$user->admin) accessforbidden(); +// Load translation files required by the page +$langs->loadLangs(array("install", "other", "admin")); + +$optioncss = GETPOST('optioncss', 'alpha'); +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'moduleoverview'; + +$search_name = GETPOST("search_name", 'alpha'); +$search_id = GETPOST("search_id", 'alpha'); +$search_version = GETPOST("search_version", 'alpha'); +$search_permission = GETPOST("search_permission", 'alpha'); + +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); + +if (!$sortfield) $sortfield = "id"; +if (!$sortorder) $sortorder = "asc"; + +// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks +$hookmanager->initHooks(array('moduleoverview')); +$form = new Form($db); +$object = new stdClass(); + +// Definition of fields for lists +$arrayfields = array( + 'name'=>array('label'=>$langs->trans("Modules"), 'checked'=>1, 'position'=>10), + 'version'=>array('label'=>$langs->trans("Version"), 'checked'=>1, 'position'=>20), + 'id'=>array('label'=>$langs->trans("IdModule"), 'checked'=>1, 'position'=>30), + 'permission'=>array('label'=>$langs->trans("IdPermissions"), 'checked'=>1, 'position'=>40) +); + +$arrayfields = dol_sort_array($arrayfields, 'position'); /* - * View + * Actions */ -llxHeader(); +$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'); -print load_fiche_titre($langs->trans("AvailableModules"), '', 'title_setup'); +if (empty($reshook)) +{ + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; +} -print ''.$langs->trans("ToActivateModule").'
'; -print "
\n"; +// Load list of modules +$moduleList = array(); $modules = array(); -$modules_names = array(); $modules_files = array(); $modules_fullpath = array(); $modulesdir = dolGetModulesDirs(); +$rights_ids = array(); -// Load list of modules -$i = 0; foreach ($modulesdir as $dir) { $handle = @opendir(dol_osencode($dir)); @@ -69,7 +101,9 @@ foreach ($modulesdir as $dir) { // File duplicate print "Warning duplicate file found : ".$file." (Found ".$dir.$file.", already found ".$modules_fullpath[$file].")
"; - } else { + } + else + { // File to load $res = include_once $dir.$file; if (class_exists($modName)) @@ -78,15 +112,16 @@ foreach ($modulesdir as $dir) $objMod = new $modName($db); $modules[$objMod->numero] = $objMod; - $modules_names[$objMod->numero] = $objMod->name; $modules_files[$objMod->numero] = $file; $modules_fullpath[$file] = $dir.$file; - $picto[$objMod->numero] = (isset($objMod->picto) && $objMod->picto) ? $objMod->picto : 'generic'; - } catch (Exception $e) + } + catch (Exception $e) { dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR); } - } else { + } + else + { print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)
"; } } @@ -97,60 +132,267 @@ foreach ($modulesdir as $dir) } } -print '
'; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -$var = false; -$sortorder = $modules_names; -ksort($sortorder); -$rights_ids = array(); -foreach ($sortorder as $numero=>$name) +// create pre-filtered list for modules +foreach ($modules as $key=>$module) { - $idperms = ""; - // Module - print '"; - // Version - print ''; - // Id - print ''; - // Permissions - if ($modules[$numero]->rights) + else { - foreach ($modules[$numero]->rights as $rights) + $newModule->picto = img_object($alt, 'generic', 'width="14px"'); + } + + $permission = array(); + if ($module->rights) + { + foreach ($module->rights as $rights) { - $idperms .= ($idperms ? ", " : "").$rights[0]; + if (empty($rights[0])) + { + continue; + } + + $permission[] = $rights[0]; + array_push($rights_ids, $rights[0]); } } - print ''; - print "\n"; + + $newModule->permission = $permission; + + // pre-filter list + if($search_name && !stristr($newModule->name, $search_name)) continue; + if($search_version && !stristr($newModule->version, $search_version)) continue; + if($search_id && !stristr($newModule->id, $search_id)) continue; + + if($search_permission) + { + $found = false; + + foreach($newModule->permission as $permission) + { + if(stristr($permission, $search_permission)) + { + $found = true; + break; + } + } + + if(!$found) continue; + } + + $moduleList[] = $newModule; } + + + +/* + * View + */ + +llxHeader(); + +print ''; +if ($optioncss != '') print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print_barre_liste($langs->trans("AvailableModules"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $massactionbutton, -1, '', 'title_setup', 0, '', '', 0, 1, 1); + +print ''.$langs->trans("ToActivateModule").''; +print '
'; +print '
'; + +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; +$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + +print '
'; +print '
'.$langs->trans("Modules").''.$langs->trans("Version").''.$langs->trans("IdModule").''.$langs->trans("IdPermissions").'
'; - $alt = $name.' - '.$modules_files[$numero]; - if (!empty($picto[$numero])) + $newModule = new stdClass(); + + $newModule->name = $module->getName(); + $newModule->version = $module->getVersion(); + $newModule->id = $key; + + $alt = $module->name.' - '.$modules_files[$key]; + + if (!empty($module->picto)) { - if (preg_match('/^\//', $picto[$numero])) print img_picto($alt, $picto[$numero], 'width="14px"', 1); - else print img_object($alt, $picto[$numero], 'width="14px"'); - } else { - print img_object($alt, $picto[$numero], 'width="14px"'); + if (preg_match('/^\//', $module->picto)) $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1); + else $newModule->picto = img_object($alt, $module->picto, 'width="14px"'); } - print ' '.$modules[$numero]->getName(); - print "'.$modules[$numero]->getVersion().''.$numero.''.($idperms ? $idperms : " ").'
'; + +// Lines with input filters +print ''; + +if($arrayfields['name']['checked']) +{ + print ''; +} +if($arrayfields['version']['checked']) +{ + print ''; +} +if($arrayfields['id']['checked']) +{ + print ''; +} +if($arrayfields['permission']['checked']) +{ + print ''; +} + +print ''; + +print ''; + +print ''; + +if($arrayfields['name']['checked']) +{ + print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder); +} +if($arrayfields['version']['checked']) +{ + print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder); +} +if($arrayfields['id']['checked']) +{ + print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder); +} +if($arrayfields['permission']['checked']) +{ + print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder); +} + +// Fields from hook +$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; + +print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); +print ''; + +// sort list +if($sortfield == "name" && $sortorder == "asc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($a->name, $b->name); }); +if($sortfield == "name" && $sortorder == "desc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($b->name, $a->name); }); +if($sortfield == "version" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($a->version, $b->version); }); +if($sortfield == "version" && $sortorder == "desc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($b->version, $a->version); }); +if($sortfield == "id" && $sortorder == "asc") usort($moduleList, "sortIdAsc"); +if($sortfield == "id" && $sortorder == "desc") usort($moduleList, "sortIdDesc"); +if($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "sortPermissionIdsAsc"); +if($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "sortPermissionIdsDesc"); + +foreach ($moduleList as $module) +{ + print ''; + + if($arrayfields['name']['checked']) + { + print '"; + } + + if($arrayfields['version']['checked']) + { + print ''; + } + + if($arrayfields['id']['checked']) + { + print ''; + } + + if($arrayfields['permission']['checked']) + { + $idperms = ''; + foreach ($module->permission as $permission) + { + $idperms .= ($idperms ? ", " : "").$permission; + + $translationKey = "Permission".$permission; + if(empty($langs->tab_translate[$translationKey])) + { + $tooltip = 'Missing translation (key '.$translation.' not found in admin.lang)'; + $idperms .= ' Warning'; + } + } + + print ''; + } + + print ''; + print ''; +} + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; +$searchpicto = $form->showFilterButtons(); +print $searchpicto; +print '
'; + print $module->picto; + print ' '.$module->name; + print "'.$module->version.''.$module->id.''.($idperms ? $idperms : " ").'
'; print '
'; +print ''; print '
'; + sort($rights_ids); $old = ''; + foreach ($rights_ids as $right_id) { - if ($old == $right_id) print "Warning duplicate id on permission : ".$right_id."
"; + if ($old == $right_id) + { + print "Warning duplicate id on permission : ".$right_id."
"; + } + $old = $right_id; } // End of page llxFooter(); $db->close(); + + +/* + * user-defined sort functions + */ + +function sortIdAsc(stdClass $a, stdClass $b) +{ + return $a->id > $b->id ? -1 : 1; +} + +function sortIdDesc(stdClass $a, stdClass $b) +{ + return $b->id > $a->id ? -1 : 1; +} + +function sortPermissionIdsAsc(stdClass $a, stdClass $b) +{ + if (empty($a->permission) && empty($b->permission)) return sortIdAsc($a, $b); + + if (empty($a->permission)) return 1; + if (empty($b->permission)) return -1; + + return $a->permission[0] > $b->permission[0] ? -1 : 1; +} + +function sortPermissionIdsDesc(stdClass $a, stdClass $b) +{ + if (empty($a->permission) && empty($b->permission)) return sortIdDesc($a, $b); + + if (empty($a->permission)) return -1; + if (empty($b->permission)) return 1; + + return $a->permission[0] > $b->permission[0] ? 1 : -1; +} From 2569c792e768365d60db59826b69bcf8eb125084 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 8 Sep 2020 08:13:56 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/admin/system/modules.php | 81 +++++++++++++++++---------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index bba227f9acc..7181b35f858 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -32,7 +32,7 @@ if (!$user->admin) $langs->loadLangs(array("install", "other", "admin")); $optioncss = GETPOST('optioncss', 'alpha'); -$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'moduleoverview'; +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'moduleoverview'; $search_name = GETPOST("search_name", 'alpha'); $search_id = GETPOST("search_id", 'alpha'); @@ -102,8 +102,7 @@ foreach ($modulesdir as $dir) // File duplicate print "Warning duplicate file found : ".$file." (Found ".$dir.$file.", already found ".$modules_fullpath[$file].")
"; } - else - { + else { // File to load $res = include_once $dir.$file; if (class_exists($modName)) @@ -120,8 +119,7 @@ foreach ($modulesdir as $dir) dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR); } } - else - { + else { print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)
"; } } @@ -140,16 +138,15 @@ foreach ($modules as $key=>$module) $newModule->name = $module->getName(); $newModule->version = $module->getVersion(); $newModule->id = $key; - + $alt = $module->name.' - '.$modules_files[$key]; - + if (!empty($module->picto)) { if (preg_match('/^\//', $module->picto)) $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1); else $newModule->picto = img_object($alt, $module->picto, 'width="14px"'); } - else - { + else { $newModule->picto = img_object($alt, 'generic', 'width="14px"'); } @@ -172,24 +169,24 @@ foreach ($modules as $key=>$module) $newModule->permission = $permission; // pre-filter list - if($search_name && !stristr($newModule->name, $search_name)) continue; - if($search_version && !stristr($newModule->version, $search_version)) continue; - if($search_id && !stristr($newModule->id, $search_id)) continue; + if ($search_name && !stristr($newModule->name, $search_name)) continue; + if ($search_version && !stristr($newModule->version, $search_version)) continue; + if ($search_id && !stristr($newModule->id, $search_id)) continue; - if($search_permission) + if ($search_permission) { $found = false; - foreach($newModule->permission as $permission) + foreach ($newModule->permission as $permission) { - if(stristr($permission, $search_permission)) + if (stristr($permission, $search_permission)) { $found = true; break; } } - if(!$found) continue; + if (!$found) continue; } $moduleList[] = $newModule; @@ -227,25 +224,25 @@ print ''; // Lines with input filters print ''; -if($arrayfields['name']['checked']) +if ($arrayfields['name']['checked']) { print ''; } -if($arrayfields['version']['checked']) +if ($arrayfields['version']['checked']) { print ''; } -if($arrayfields['id']['checked']) +if ($arrayfields['id']['checked']) { print ''; } -if($arrayfields['permission']['checked']) +if ($arrayfields['permission']['checked']) { print ''; print ''; -if($arrayfields['name']['checked']) +if ($arrayfields['name']['checked']) { print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder); } -if($arrayfields['version']['checked']) +if ($arrayfields['version']['checked']) { print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder); } -if($arrayfields['id']['checked']) +if ($arrayfields['id']['checked']) { print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder); } -if($arrayfields['permission']['checked']) +if ($arrayfields['permission']['checked']) { print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder); } @@ -287,46 +284,50 @@ print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $ print ''; // sort list -if($sortfield == "name" && $sortorder == "asc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($a->name, $b->name); }); -if($sortfield == "name" && $sortorder == "desc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($b->name, $a->name); }); -if($sortfield == "version" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($a->version, $b->version); }); -if($sortfield == "version" && $sortorder == "desc") usort($moduleList, function(stdClass $a, stdClass $b) { return strcasecmp($b->version, $a->version); }); -if($sortfield == "id" && $sortorder == "asc") usort($moduleList, "sortIdAsc"); -if($sortfield == "id" && $sortorder == "desc") usort($moduleList, "sortIdDesc"); -if($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "sortPermissionIdsAsc"); -if($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "sortPermissionIdsDesc"); +if ($sortfield == "name" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) { + return strcasecmp($a->name, $b->name); }); +if ($sortfield == "name" && $sortorder == "desc") usort($moduleList, function (stdClass $a, stdClass $b) { + return strcasecmp($b->name, $a->name); }); +if ($sortfield == "version" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) { + return strcasecmp($a->version, $b->version); }); +if ($sortfield == "version" && $sortorder == "desc") usort($moduleList, function (stdClass $a, stdClass $b) { + return strcasecmp($b->version, $a->version); }); +if ($sortfield == "id" && $sortorder == "asc") usort($moduleList, "sortIdAsc"); +if ($sortfield == "id" && $sortorder == "desc") usort($moduleList, "sortIdDesc"); +if ($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "sortPermissionIdsAsc"); +if ($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "sortPermissionIdsDesc"); foreach ($moduleList as $module) { print ''; - if($arrayfields['name']['checked']) + if ($arrayfields['name']['checked']) { print '"; } - - if($arrayfields['version']['checked']) + + if ($arrayfields['version']['checked']) { print ''; } - if($arrayfields['id']['checked']) + if ($arrayfields['id']['checked']) { print ''; } - if($arrayfields['permission']['checked']) + if ($arrayfields['permission']['checked']) { $idperms = ''; foreach ($module->permission as $permission) { $idperms .= ($idperms ? ", " : "").$permission; - + $translationKey = "Permission".$permission; - if(empty($langs->tab_translate[$translationKey])) + if (empty($langs->tab_translate[$translationKey])) { $tooltip = 'Missing translation (key '.$translation.' not found in admin.lang)'; $idperms .= ' Warning'; @@ -374,7 +375,7 @@ function sortIdAsc(stdClass $a, stdClass $b) function sortIdDesc(stdClass $a, stdClass $b) { - return $b->id > $a->id ? -1 : 1; + return $b->id > $a->id ? -1 : 1; } function sortPermissionIdsAsc(stdClass $a, stdClass $b) From 37141b577a6b1508a607ec8368ddba7b981269d3 Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Wed, 9 Sep 2020 08:34:13 +0200 Subject: [PATCH 3/3] fix sticker CI, better names, add missing comapres --- htdocs/admin/system/modules.php | 168 ++++++++++++++++---------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index 7181b35f858..1b482e13238 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -25,8 +25,9 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -if (!$user->admin) +if (!$user->admin) { accessforbidden(); +} // Load translation files required by the page $langs->loadLangs(array("install", "other", "admin")); @@ -68,8 +69,7 @@ $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)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; } @@ -83,30 +83,23 @@ $modules_fullpath = array(); $modulesdir = dolGetModulesDirs(); $rights_ids = array(); -foreach ($modulesdir as $dir) -{ +foreach ($modulesdir as $dir) { $handle = @opendir(dol_osencode($dir)); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') - { + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') { $modName = substr($file, 0, dol_strlen($file) - 10); - if ($modName) - { + if ($modName) { //print 'xx'.$dir.$file.'
'; - if (in_array($file, $modules_files)) - { + if (in_array($file, $modules_files)) { // File duplicate print "Warning duplicate file found : ".$file." (Found ".$dir.$file.", already found ".$modules_fullpath[$file].")
"; } else { // File to load $res = include_once $dir.$file; - if (class_exists($modName)) - { + if (class_exists($modName)) { try { $objMod = new $modName($db); @@ -114,8 +107,7 @@ foreach ($modulesdir as $dir) $modules_files[$objMod->numero] = $file; $modules_fullpath[$file] = $dir.$file; } - catch (Exception $e) - { + catch (Exception $e) { dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR); } } @@ -131,8 +123,7 @@ foreach ($modulesdir as $dir) } // create pre-filtered list for modules -foreach ($modules as $key=>$module) -{ +foreach ($modules as $key=>$module) { $newModule = new stdClass(); $newModule->name = $module->getName(); @@ -141,8 +132,7 @@ foreach ($modules as $key=>$module) $alt = $module->name.' - '.$modules_files[$key]; - if (!empty($module->picto)) - { + if (!empty($module->picto)) { if (preg_match('/^\//', $module->picto)) $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1); else $newModule->picto = img_object($alt, $module->picto, 'width="14px"'); } @@ -151,12 +141,9 @@ foreach ($modules as $key=>$module) } $permission = array(); - if ($module->rights) - { - foreach ($module->rights as $rights) - { - if (empty($rights[0])) - { + if ($module->rights) { + foreach ($module->rights as $rights) { + if (empty($rights[0])) { continue; } @@ -173,14 +160,11 @@ foreach ($modules as $key=>$module) if ($search_version && !stristr($newModule->version, $search_version)) continue; if ($search_id && !stristr($newModule->id, $search_id)) continue; - if ($search_permission) - { + if ($search_permission) { $found = false; - foreach ($newModule->permission as $permission) - { - if (stristr($permission, $search_permission)) - { + foreach ($newModule->permission as $permission) { + if (stristr($permission, $search_permission)) { $found = true; break; } @@ -224,26 +208,22 @@ print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; @@ -261,19 +258,19 @@ print '
'; print $module->picto; print ' '.$module->name; print "'.$module->version.''.$module->id.'
'; // Lines with input filters print ''; -if ($arrayfields['name']['checked']) -{ +if ($arrayfields['name']['checked']) { print ''; } -if ($arrayfields['version']['checked']) -{ +if ($arrayfields['version']['checked']) { print ''; } -if ($arrayfields['id']['checked']) -{ +if ($arrayfields['id']['checked']) { print ''; } -if ($arrayfields['permission']['checked']) -{ +if ($arrayfields['permission']['checked']) { print ''; @@ -258,20 +238,16 @@ print ''; print ''; -if ($arrayfields['name']['checked']) -{ +if ($arrayfields['name']['checked']) { print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder); } -if ($arrayfields['version']['checked']) -{ +if ($arrayfields['version']['checked']) { print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder); } -if ($arrayfields['id']['checked']) -{ +if ($arrayfields['id']['checked']) { print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder); } -if ($arrayfields['permission']['checked']) -{ +if ($arrayfields['permission']['checked']) { print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder); } @@ -292,43 +268,37 @@ if ($sortfield == "version" && $sortorder == "asc") usort($moduleList, function return strcasecmp($a->version, $b->version); }); if ($sortfield == "version" && $sortorder == "desc") usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($b->version, $a->version); }); -if ($sortfield == "id" && $sortorder == "asc") usort($moduleList, "sortIdAsc"); -if ($sortfield == "id" && $sortorder == "desc") usort($moduleList, "sortIdDesc"); -if ($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "sortPermissionIdsAsc"); -if ($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "sortPermissionIdsDesc"); +if ($sortfield == "id" && $sortorder == "asc") usort($moduleList, "compareIdAsc"); +if ($sortfield == "id" && $sortorder == "desc") usort($moduleList, "compareIdDesc"); +if ($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "comparePermissionIdsAsc"); +if ($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "comparePermissionIdsDesc"); -foreach ($moduleList as $module) -{ +foreach ($moduleList as $module) { print ''; - if ($arrayfields['name']['checked']) - { + if ($arrayfields['name']['checked']) { print '"; } - if ($arrayfields['version']['checked']) - { + if ($arrayfields['version']['checked']) { print ''; } - if ($arrayfields['id']['checked']) - { + if ($arrayfields['id']['checked']) { print ''; } - if ($arrayfields['permission']['checked']) - { + if ($arrayfields['permission']['checked']) { $idperms = ''; - foreach ($module->permission as $permission) - { - $idperms .= ($idperms ? ", " : "").$permission; + foreach ($module->permission as $permission) { + $idperms .= ($idperms ? ", " : "").$permission; $translationKey = "Permission".$permission; - if (empty($langs->tab_translate[$translationKey])) - { + + if (empty($langs->tab_translate[$translationKey])) { $tooltip = 'Missing translation (key '.$translation.' not found in admin.lang)'; $idperms .= ' Warning'; } @@ -349,10 +319,8 @@ print '
'; sort($rights_ids); $old = ''; -foreach ($rights_ids as $right_id) -{ - if ($old == $right_id) - { +foreach ($rights_ids as $right_id) { + if ($old == $right_id) { print "Warning duplicate id on permission : ".$right_id."
"; } @@ -364,36 +332,68 @@ llxFooter(); $db->close(); -/* - * user-defined sort functions - */ - -function sortIdAsc(stdClass $a, stdClass $b) + /** + * Compare two modules by their ID for a ascending order + * + * @param stdClass $a First module + * @param stdClass $b Second module + * @return int Compare result (-1, 0, 1) + */ +function compareIdAsc(stdClass $a, stdClass $b) { + if ($a->id == $b->id) return 0; + return $a->id > $b->id ? -1 : 1; } -function sortIdDesc(stdClass $a, stdClass $b) + /** + * Compare two modules by their ID for a descending order + * + * @param stdClass $a First module + * @param stdClass $b Second module + * @return int Compare result (-1, 0, 1) + */ +function compareIdDesc(stdClass $a, stdClass $b) { + if ($a->id == $b->id) return 0; + return $b->id > $a->id ? -1 : 1; } -function sortPermissionIdsAsc(stdClass $a, stdClass $b) + /** + * Compare two modules by their ID for a ascending order + * + * @param stdClass $a First module + * @param stdClass $b Second module + * @return int Compare result (-1, 0, 1) + */ +function comparePermissionIdsAsc(stdClass $a, stdClass $b) { - if (empty($a->permission) && empty($b->permission)) return sortIdAsc($a, $b); + if (empty($a->permission) && empty($b->permission)) return compareIdAsc($a, $b); if (empty($a->permission)) return 1; if (empty($b->permission)) return -1; + if ($a->permission[0] == $b->permission[0]) return 0; + return $a->permission[0] > $b->permission[0] ? -1 : 1; } -function sortPermissionIdsDesc(stdClass $a, stdClass $b) + /** + * Compare two modules by their permissions for a descending order + * + * @param stdClass $a First module + * @param stdClass $b Second module + * @return int Compare result (-1, 0, 1) + */ +function comparePermissionIdsDesc(stdClass $a, stdClass $b) { - if (empty($a->permission) && empty($b->permission)) return sortIdDesc($a, $b); + if (empty($a->permission) && empty($b->permission)) return compareIdDesc($a, $b); if (empty($a->permission)) return -1; if (empty($b->permission)) return 1; + if ($a->permission[0] == $b->permission[0]) return 0; + return $a->permission[0] > $b->permission[0] ? 1 : -1; }
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print $module->picto; print ' '.$module->name; print "'.$module->version.''.$module->id.'