dolibarr 22.0.5
modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30
31if (empty($user->admin)) {
33}
34
43// Load translation files required by the page
44$langs->loadLangs(array("install", "other", "admin"));
45
46$action = GETPOST('action', 'aZ09');
47$optioncss = GETPOST('optioncss', 'alpha');
48$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'moduleoverview';
49
50$search_name = GETPOST("search_name", 'alpha');
51$search_id = GETPOST("search_id", 'alpha');
52$search_version = GETPOST("search_version", 'alpha');
53$search_permission = GETPOST("search_permission", 'alpha');
54
55$sortfield = GETPOST('sortfield', 'aZ09comma');
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57
58if (!$sortfield) {
59 $sortfield = "id";
60}
61if (!$sortorder) {
62 $sortorder = "asc";
63}
64
65// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
66$hookmanager->initHooks(array('moduleoverview'));
67$form = new Form($db);
68$object = new stdClass();
69
70// Definition of fields for lists
71$arrayfields = array(
72 'name' => array('label' => $langs->trans("Modules"), 'checked' => '1', 'position' => 10),
73 'version' => array('label' => $langs->trans("Version"), 'checked' => '1', 'position' => 20),
74 'id' => array('label' => $langs->trans("IdModule"), 'checked' => '1', 'position' => 30),
75 'module_position' => array('label' => $langs->trans("Position"), 'checked' => '1', 'position' => 35),
76 'permission' => array('label' => $langs->trans("IdPermissions"), 'checked' => '1', 'position' => 40)
77);
78
79$arrayfields = dol_sort_array($arrayfields, 'position');
80
81$param = '';
82$info_admin = '';
83
84
85/*
86 * Actions
87 */
88
89$parameters = array();
90$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
91if ($reshook < 0) {
92 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
93}
94
95if (empty($reshook)) {
96 // Selection of new fields
97 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
98}
99
100// Load list of modules
101$moduleList = array();
102$modules = array();
103$modules_files = array();
104$modules_fullpath = array();
105$modulesdir = dolGetModulesDirs();
106$rights_ids = array();
107$arrayofpermissions = array();
108
109foreach ($modulesdir as $dir) {
110 $handle = @opendir(dol_osencode($dir));
111 if (is_resource($handle)) {
112 while (($file = readdir($handle)) !== false) {
113 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
114 $modName = substr($file, 0, dol_strlen($file) - 10);
115
116 if ($modName) {
117 //print 'xx'.$dir.$file.'<br>';
118 if (in_array($file, $modules_files)) {
119 // File duplicate @phan-suppress-next-line PhanTypeInvalidDimOffset
120 print "Warning duplicate file found : ".$file." (Found ".$dir.$file.", already found ".$modules_fullpath[$file].")<br>";
121 } else {
122 // File to load
123 $res = include_once $dir.$file;
124 if (class_exists($modName)) {
125 try {
126 $objMod = new $modName($db);
127 '@phan-var-force DolibarrModules $objMod';
128
129 $modules[$objMod->numero] = $objMod;
130 $modules_files[$objMod->numero] = $file;
131 $modules_fullpath[$file] = $dir.$file;
132 } catch (Exception $e) {
133 dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
134 }
135 } else {
136 $info_admin .= info_admin("Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)", 0, 0, '1', 'warning');
137 }
138 }
139 }
140 }
141 }
142 closedir($handle);
143 }
144}
145'@phan-var-force array<string,DolibarrModules> $modules';
146
147// create pre-filtered list for modules
148foreach ($modules as $key => $module) {
149 $newModule = new stdClass();
150
151 $newModule->name = $module->getName();
152 $newModule->version = $module->getVersion();
153 $newModule->id = $key;
154 $newModule->module_position = $module->getModulePosition();
155
156 $alt = $module->name.' - '.$modules_files[$key];
157
158 if (!empty($module->picto)) {
159 if (preg_match('/^\//', $module->picto)) {
160 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
161 $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1);
162 } else {
163 $newModule->picto = img_object($alt, $module->picto, 'width="14px"');
164 }
165 } else {
166 $newModule->picto = img_object($alt, 'generic', 'width="14px"');
167 }
168
169 $permission = array();
170 if ($module->rights) {
171 foreach ($module->rights as $rights) {
172 if (empty($rights[0])) {
173 continue;
174 }
175 $arrayofpermissions[$rights[0]] = array('label' => 'user->hasRight(\''.$module->rights_class.'\', \''.$rights[4].'\''.(empty($rights[5]) ? '' : ', \''.$rights[5].'\'').')');
176 $permission[] = $rights[0];
177
178 array_push($rights_ids, $rights[0]);
179 }
180 }
181
182 $newModule->permission = $permission;
183
184 // pre-filter list
185 if (!empty($search_name) && !stristr($newModule->name, $search_name)) {
186 continue;
187 }
188 if (!empty($search_version) && !stristr($newModule->version, $search_version)) {
189 continue;
190 }
191 if (!empty($search_id) && !stristr($newModule->id, $search_id)) {
192 continue;
193 }
194
195 if (!empty($search_permission)) {
196 $found = false;
197
198 foreach ($newModule->permission as $permission) {
199 if (stristr($permission, $search_permission)) {
200 $found = true;
201 break;
202 }
203 }
204
205 if (!$found) {
206 continue;
207 }
208 }
209
210 $moduleList[] = $newModule;
211}
212
213
214
215/*
216 * View
217 */
218
219llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-system_modules');
220print $info_admin;
221print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
222if ($optioncss != '') {
223 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
224}
225print '<input type="hidden" name="token" value="'.newToken().'">';
226print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
227print '<input type="hidden" name="action" value="list">';
228print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
229print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
230print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
231
232if (!GETPOSTINT('hidetitle')) {
233 print_barre_liste($langs->trans("AvailableModules"), empty($page) ? 0 : $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', -1, '', 'title_setup', 0, '', '', 0, 1, 1);
234
235 print '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span>';
236 print '<br>';
237}
238print '<br>';
239
240$mode = '';
241$arrayofmassactions = array();
242
243$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
244$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
245$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
246$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
247
248$moreforfilter = '';
249
250print '<div class="div-table-responsive-no-min">';
251print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
252
253// Lines with input filters
254print '<tr class="liste_titre_filter">';
255// Action column
256if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
257 print '<td class="liste_titre center maxwidthsearch">';
258 $searchpicto = $form->showFilterButtons();
259 print $searchpicto;
260 print '</td>';
261}
262if ($arrayfields['name']['checked']) {
263 print '<td class="liste_titre">';
264 print '<input class="flat width100" type="text" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
265 print '</td>';
266}
267if ($arrayfields['version']['checked']) {
268 print '<td class="liste_titre">';
269 print '<input class="flat width50" type="text" name="search_version" value="'.dol_escape_htmltag($search_version).'">';
270 print '</td>';
271}
272if ($arrayfields['id']['checked']) {
273 print '<td class="liste_titre center">';
274 print '<input class="flat width50" type="text" name="search_id" value="'.dol_escape_htmltag($search_id).'">';
275 print '</td>';
276}
277if ($arrayfields['permission']['checked']) {
278 print '<td class="liste_titre">';
279 print '<input class="flat width100" type="text" name="search_permission" value="'.dol_escape_htmltag($search_permission).'">';
280 print '</td>';
281}
282if ($arrayfields['module_position']['checked']) {
283 print '<td class="liste_titre">';
284 print '</td>';
285}
286// Action column
287if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
288 print '<td class="liste_titre center maxwidthsearch">';
289 $searchpicto = $form->showFilterButtons();
290 print $searchpicto;
291 print '</td>';
292}
293print '</tr>';
294
295print '<tr class="liste_titre">';
296// Action column
297if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
298 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn');
299}
300if ($arrayfields['name']['checked']) {
301 print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder);
302}
303if ($arrayfields['version']['checked']) {
304 print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder);
305}
306if ($arrayfields['id']['checked']) {
307 print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder, 'nowraponall center ');
308}
309if ($arrayfields['permission']['checked']) {
310 print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder);
311}
312if ($arrayfields['module_position']['checked']) {
313 print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder, "right ");
314}
315
316// Fields from hook
317$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
318$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
319print $hookmanager->resPrint;
320// Action column
321if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
322 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
323}
324print '</tr>';
325
326// sort list
327if ($sortfield == "name" && $sortorder == "asc") {
328 usort(
329 $moduleList,
331 function (stdClass $a, stdClass $b) {
332 return strcasecmp($a->name, $b->name);
333 }
334 );
335} elseif ($sortfield == "name" && $sortorder == "desc") {
336 usort(
337 $moduleList,
339 static function (stdClass $a, stdClass $b) {
340 return strcasecmp($b->name, $a->name);
341 }
342 );
343} elseif ($sortfield == "version" && $sortorder == "asc") {
344 usort(
345 $moduleList,
347 static function (stdClass $a, stdClass $b) {
348 return strcasecmp($a->version, $b->version);
349 }
350 );
351} elseif ($sortfield == "version" && $sortorder == "desc") {
352 usort(
353 $moduleList,
355 static function (stdClass $a, stdClass $b) {
356 return strcasecmp($b->version, $a->version);
357 }
358 );
359} elseif ($sortfield == "id" && $sortorder == "asc") {
360 usort($moduleList, "compareIdAsc");
361} elseif ($sortfield == "id" && $sortorder == "desc") {
362 usort($moduleList, "compareIdDesc");
363} elseif ($sortfield == "permission" && $sortorder == "asc") {
364 usort($moduleList, "comparePermissionIdsAsc");
365} elseif ($sortfield == "permission" && $sortorder == "desc") {
366 usort($moduleList, "comparePermissionIdsDesc");
367} else {
368 $moduleList = dol_sort_array($moduleList, 'module_position', $sortorder);
369}
370
371foreach ($moduleList as $module) {
372 print '<tr class="oddeven">';
373 // Action column
374 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
375 print '<td></td>';
376 }
377
378 if ($arrayfields['name']['checked']) {
379 print '<td width="300" class="nowrap">';
380 print $module->picto;
381 print ' '.dolPrintHTML($module->name);
382 print "</td>";
383 }
384
385 if ($arrayfields['version']['checked']) {
386 print '<td class="nowraponall">'.dolPrintHTML($module->version).'</td>';
387 }
388
389 if ($arrayfields['id']['checked']) {
390 print '<td class="center">'.dolPrintHTML($module->id).'</td>';
391 }
392
393 if ($arrayfields['permission']['checked']) {
394 $idperms = '';
395
396 foreach ($module->permission as $permission) {
397 $translationKey = "Permission".$permission;
398 $labelpermission = $langs->trans($translationKey);
399 $labelpermission .= ' : '.$arrayofpermissions[$permission]['label'];
400 $idperms .= ($idperms ? ", " : "").'<span title="'.$labelpermission.'">'.$permission.'</a>';
401
402 if (getDolGlobalString('MAIN_SHOW_PERMISSION')) {
403 if (empty($langs->tab_translate[$translationKey])) {
404 $tooltip = 'Missing translation (key '.$translationKey.' not found in admin.lang)';
405 $idperms .= ' <img src="../../theme/eldy/img/warning.png" alt="Warning" title="'.$tooltip.'">';
406 }
407 }
408 }
409
410 print '<td><span class="opacitymedium">'.($idperms ? $idperms : "&nbsp;").'</span></td>';
411 }
412
413 if ($arrayfields['module_position']['checked']) {
414 print '<td class="right">'.dolPrintHTML($module->module_position).'</td>';
415 }
416
417 // Action column
418 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
419 print '<td></td>';
420 }
421 print '</tr>';
422}
423
424print '</table>';
425print '</div>';
426print '</form>';
427print '<br>';
428
429sort($rights_ids);
430$old = '';
431
432foreach ($rights_ids as $right_id) {
433 if ($old == $right_id) {
434 print "Warning duplicate id on permission : ".$right_id."<br>";
435 }
436
437 $old = $right_id;
438}
439
440// End of page
441llxFooter();
442$db->close();
443
444
453{
454 if ((int) $a->id == (int) $b->id) {
455 return 0;
456 }
457
458 return ((int) $a->id < (int) $b->id) ? -1 : 1;
459}
460
469{
470 if ((int) $a->id == (int) $b->id) {
471 return 0;
472 }
473
474 return ((int) $b->id < (int) $a->id) ? -1 : 1;
475}
476
485{
486 if (empty($a->permission) && empty($b->permission)) {
487 return compareIdAsc($a, $b);
488 }
489
490 if (empty($a->permission)) {
491 return 1;
492 }
493 if (empty($b->permission)) {
494 return -1;
495 }
496
497 if ($a->permission[0] == $b->permission[0]) {
498 return 0;
499 }
500
501 return $a->permission[0] < $b->permission[0] ? -1 : 1;
502}
503
512{
513 if (empty($a->permission) && empty($b->permission)) {
514 return compareIdDesc($a, $b);
515 }
516
517 if (empty($a->permission)) {
518 return -1;
519 }
520 if (empty($b->permission)) {
521 return 1;
522 }
523
524 if ($a->permission[0] == $b->permission[0]) {
525 return 0;
526 }
527
528 return $b->permission[0] < $a->permission[0] ? -1 : 1;
529}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
compareIdDesc(stdClass $a, stdClass $b)
Compare two modules by their ID for a descending order.
Definition modules.php:468
compareIdAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:452
comparePermissionIdsDesc(stdClass $a, stdClass $b)
Compare two modules by their permissions for a descending order.
Definition modules.php:511
comparePermissionIdsAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:484