forked from Wavyzz/dolibarr
add common list function for module overview
This commit is contained in:
@@ -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 '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span><br>';
|
||||
print "<br>\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].")<br>";
|
||||
} 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)<br>";
|
||||
}
|
||||
}
|
||||
@@ -97,60 +132,267 @@ foreach ($modulesdir as $dir)
|
||||
}
|
||||
}
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Modules").'</td>';
|
||||
print '<td>'.$langs->trans("Version").'</td>';
|
||||
print '<td class="center">'.$langs->trans("IdModule").'</td>';
|
||||
print '<td>'.$langs->trans("IdPermissions").'</td>';
|
||||
print '</tr>';
|
||||
$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 '<tr class="oddeven"><td width="300" class="nowrap">';
|
||||
$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 "</td>";
|
||||
// Version
|
||||
print '<td>'.$modules[$numero]->getVersion().'</td>';
|
||||
// Id
|
||||
print '<td class="center">'.$numero.'</td>';
|
||||
// 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 '<td>'.($idperms ? $idperms : " ").'</td>';
|
||||
print "</tr>\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 '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
|
||||
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
||||
|
||||
print_barre_liste($langs->trans("AvailableModules"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $massactionbutton, -1, '', 'title_setup', 0, '', '', 0, 1, 1);
|
||||
|
||||
print '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span>';
|
||||
print '<br>';
|
||||
print '<br>';
|
||||
|
||||
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
|
||||
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder centpercent">';
|
||||
|
||||
// Lines with input filters
|
||||
print '<tr class="liste_titre_filter">';
|
||||
|
||||
if($arrayfields['name']['checked'])
|
||||
{
|
||||
print '<td class="liste_titre left">';
|
||||
print '<input class="flat" type="text" name="search_name" size="8" value="'.$search_name.'">';
|
||||
print '</td>';
|
||||
}
|
||||
if($arrayfields['version']['checked'])
|
||||
{
|
||||
print '<td class="liste_titre left">';
|
||||
print '<input class="flat" type="text" name="search_version" size="8" value="'.$search_version.'">';
|
||||
print '</td>';
|
||||
}
|
||||
if($arrayfields['id']['checked'])
|
||||
{
|
||||
print '<td class="liste_titre left">';
|
||||
print '<input class="flat" type="text" name="search_id" size="8" value="'.$search_id.'">';
|
||||
print '</td>';
|
||||
}
|
||||
if($arrayfields['permission']['checked'])
|
||||
{
|
||||
print '<td class="liste_titre left">';
|
||||
print '<input class="flat" type="text" name="search_permission" size="8" value="'.$search_permission.'">';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
print '<td class="liste_titre center maxwidthsearch">';
|
||||
$searchpicto = $form->showFilterButtons();
|
||||
print $searchpicto;
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
|
||||
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 '</tr>';
|
||||
|
||||
// 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 '<tr class="oddeven">';
|
||||
|
||||
if($arrayfields['name']['checked'])
|
||||
{
|
||||
print '<td width="300" class="nowrap">';
|
||||
print $module->picto;
|
||||
print ' '.$module->name;
|
||||
print "</td>";
|
||||
}
|
||||
|
||||
if($arrayfields['version']['checked'])
|
||||
{
|
||||
print '<td>'.$module->version.'</td>';
|
||||
}
|
||||
|
||||
if($arrayfields['id']['checked'])
|
||||
{
|
||||
print '<td class="center">'.$module->id.'</td>';
|
||||
}
|
||||
|
||||
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 .= ' <img src="../../theme/eldy/img/warning.png" alt="Warning" title="'.$tooltip.'">';
|
||||
}
|
||||
}
|
||||
|
||||
print '<td>'.($idperms ? $idperms : " ").'</td>';
|
||||
}
|
||||
|
||||
print '<td></td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
print '</form>';
|
||||
print '<br>';
|
||||
|
||||
sort($rights_ids);
|
||||
$old = '';
|
||||
|
||||
foreach ($rights_ids as $right_id)
|
||||
{
|
||||
if ($old == $right_id) print "Warning duplicate id on permission : ".$right_id."<br>";
|
||||
if ($old == $right_id)
|
||||
{
|
||||
print "Warning duplicate id on permission : ".$right_id."<br>";
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user