dolibarr 24.0.0-beta
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';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37
38if (empty($user->admin)) {
40}
41
42// Load translation files required by the page
43$langs->loadLangs(array("install", "other", "admin"));
44
45$action = GETPOST('action', 'aZ09');
46$optioncss = GETPOST('optioncss', 'alpha');
47$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'moduleoverview';
48
49$search_name = GETPOST("search_name", 'alpha');
50$search_id = GETPOST("search_id", 'alpha');
51$search_version = GETPOST("search_version", 'alpha');
52$search_permission = GETPOST("search_permission", 'alpha');
53
54$page = GETPOSTINT('page');
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 // Skip warning for modules being refactored (class split in progress)
137 $silentModules = array('modSupplierOrder', 'modSupplierInvoice', 'modFournisseur');
138 if (!in_array($modName, $silentModules)) {
139 $info_admin .= info_admin("admin/modules.php Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)", 0, 0, '1', 'warning');
140 }
141 }
142 }
143 }
144 }
145 }
146 closedir($handle);
147 }
148}
149'@phan-var-force array<string,DolibarrModules> $modules';
150
151// create pre-filtered list for modules
152foreach ($modules as $key => $module) {
153 $newModule = new stdClass();
154
155 $newModule->name = $module->getName();
156 $newModule->version = $module->getVersion();
157 $newModule->id = $key;
158 $newModule->module_position = $module->getModulePosition();
159
160 $alt = $module->name.' - '.$modules_files[$key];
161
162 if (!empty($module->picto)) {
163 if (preg_match('/^\//', $module->picto)) {
164 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
165 $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1);
166 } else {
167 $newModule->picto = img_object($alt, $module->picto, 'width="14px"');
168 }
169 } else {
170 $newModule->picto = img_object($alt, 'generic', 'width="14px"');
171 }
172
173 $permission = array();
174 if ($module->rights) {
175 foreach ($module->rights as $rights) {
176 if (empty($rights[0])) {
177 continue;
178 }
179 $arrayofpermissions[$rights[0]] = array('label' => 'user->hasRight(\''.$module->rights_class.'\', \''.$rights[4].'\''.(empty($rights[5]) ? '' : ', \''.$rights[5].'\'').')');
180 $permission[] = $rights[0];
181
182 array_push($rights_ids, $rights[0]);
183 }
184 }
185
186 $newModule->permission = $permission;
187
188 // pre-filter list
189 if (!empty($search_name) && !stristr($newModule->name, $search_name)) {
190 continue;
191 }
192 if (!empty($search_version) && !stristr($newModule->version, $search_version)) {
193 continue;
194 }
195 if (!empty($search_id) && !stristr($newModule->id, $search_id)) {
196 continue;
197 }
198
199 if (!empty($search_permission)) {
200 $found = false;
201
202 foreach ($newModule->permission as $permission) {
203 if (stristr($permission, $search_permission)) {
204 $found = true;
205 break;
206 }
207 }
208
209 if (!$found) {
210 continue;
211 }
212 }
213
214 $moduleList[] = $newModule;
215}
216
217
218
219/*
220 * View
221 */
222
223llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-system_modules');
224print $info_admin;
225print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
226if ($optioncss != '') {
227 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
228}
229print '<input type="hidden" name="token" value="'.newToken().'">';
230print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
231print '<input type="hidden" name="action" value="list">';
232print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
233print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
234print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
235
236if (!GETPOSTINT('hidetitle')) {
237 print_barre_liste($langs->trans("AvailableModules"), empty($page) ? 0 : $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', -1, '', 'title_setup', 0, '', '', 0, 1, 1);
238
239 print '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span>';
240 print '<br>';
241}
242print '<br>';
243
244$mode = '';
245$arrayofmassactions = array();
246
247$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
248$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
249$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
250$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
251
252$moreforfilter = '';
253
254print '<div class="div-table-responsive-no-min">';
255print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
256
257// Lines with input filters
258print '<tr class="liste_titre_filter">';
259// Action column
260if ($conf->main_checkbox_left_column) {
261 print '<td class="liste_titre center maxwidthsearch">';
262 $searchpicto = $form->showFilterButtons();
263 print $searchpicto;
264 print '</td>';
265}
266if ($arrayfields['name']['checked']) {
267 print '<td class="liste_titre">';
268 print '<input class="flat width100" type="text" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
269 print '</td>';
270}
271if ($arrayfields['version']['checked']) {
272 print '<td class="liste_titre">';
273 print '<input class="flat width50" type="text" name="search_version" value="'.dol_escape_htmltag($search_version).'">';
274 print '</td>';
275}
276if ($arrayfields['id']['checked']) {
277 print '<td class="liste_titre center">';
278 print '<input class="flat width50" type="text" name="search_id" value="'.dol_escape_htmltag($search_id).'">';
279 print '</td>';
280}
281if ($arrayfields['permission']['checked']) {
282 print '<td class="liste_titre">';
283 print '<input class="flat width100" type="text" name="search_permission" value="'.dol_escape_htmltag($search_permission).'">';
284 print '</td>';
285}
286if ($arrayfields['module_position']['checked']) {
287 print '<td class="liste_titre">';
288 print '</td>';
289}
290// Action column
291if (!$conf->main_checkbox_left_column) {
292 print '<td class="liste_titre center maxwidthsearch">';
293 $searchpicto = $form->showFilterButtons();
294 print $searchpicto;
295 print '</td>';
296}
297print '</tr>';
298
299print '<tr class="liste_titre">';
300// Action column
301if ($conf->main_checkbox_left_column) {
302 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn');
303}
304if ($arrayfields['name']['checked']) {
305 print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder);
306}
307if ($arrayfields['version']['checked']) {
308 print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder);
309}
310if ($arrayfields['id']['checked']) {
311 print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder, 'nowraponall center ');
312}
313if ($arrayfields['permission']['checked']) {
314 print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder);
315}
316if ($arrayfields['module_position']['checked']) {
317 print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder, "right ");
318}
319
320// Fields from hook
321$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
322$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
323print $hookmanager->resPrint;
324// Action column
325if (!$conf->main_checkbox_left_column) {
326 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
327}
328print '</tr>';
329
330// sort list
331if ($sortfield == "name" && $sortorder == "asc") {
332 usort(
333 $moduleList,
335 function (stdClass $a, stdClass $b) {
336 return strcasecmp($a->name, $b->name);
337 }
338 );
339} elseif ($sortfield == "name" && $sortorder == "desc") {
340 usort(
341 $moduleList,
343 static function (stdClass $a, stdClass $b) {
344 return strcasecmp($b->name, $a->name);
345 }
346 );
347} elseif ($sortfield == "version" && $sortorder == "asc") {
348 usort(
349 $moduleList,
351 static function (stdClass $a, stdClass $b) {
352 return strcasecmp($a->version, $b->version);
353 }
354 );
355} elseif ($sortfield == "version" && $sortorder == "desc") {
356 usort(
357 $moduleList,
359 static function (stdClass $a, stdClass $b) {
360 return strcasecmp($b->version, $a->version);
361 }
362 );
363} elseif ($sortfield == "id" && $sortorder == "asc") {
364 usort($moduleList, "compareIdAsc");
365} elseif ($sortfield == "id" && $sortorder == "desc") {
366 usort($moduleList, "compareIdDesc");
367} elseif ($sortfield == "permission" && $sortorder == "asc") {
368 usort($moduleList, "comparePermissionIdsAsc");
369} elseif ($sortfield == "permission" && $sortorder == "desc") {
370 usort($moduleList, "comparePermissionIdsDesc");
371} else {
372 $moduleList = dol_sort_array($moduleList, 'module_position', $sortorder);
373}
374
375foreach ($moduleList as $module) {
376 print '<tr class="oddeven">';
377 // Action column
378 if ($conf->main_checkbox_left_column) {
379 print '<td></td>';
380 }
381
382 if ($arrayfields['name']['checked']) {
383 print '<td width="300" class="nowrap">';
384 print $module->picto;
385 print ' '.dolPrintHTML($module->name);
386 print "</td>";
387 }
388
389 if ($arrayfields['version']['checked']) {
390 print '<td class="nowraponall">'.dolPrintHTML($module->version).'</td>';
391 }
392
393 if ($arrayfields['id']['checked']) {
394 print '<td class="center">'.dolPrintHTML($module->id).'</td>';
395 }
396
397 if ($arrayfields['permission']['checked']) {
398 $idperms = '';
399
400 foreach ($module->permission as $permission) {
401 $translationKey = "Permission".$permission;
402 $labelpermission = $langs->trans($translationKey);
403 $labelpermission .= ' : '.$arrayofpermissions[$permission]['label'];
404 $idperms .= ($idperms ? ", " : "").'<span title="'.$labelpermission.'">'.$permission.'</a>';
405
406 if (getDolGlobalString('MAIN_SHOW_PERMISSION')) {
407 if (empty($langs->tab_translate[$translationKey])) {
408 $tooltip = 'Missing translation (key '.$translationKey.' not found in admin.lang)';
409 $idperms .= ' <img src="../../theme/eldy/img/warning.png" alt="Warning" title="'.$tooltip.'">';
410 }
411 }
412 }
413
414 print '<td><span class="opacitymedium">'.($idperms ? $idperms : "&nbsp;").'</span></td>';
415 }
416
417 if ($arrayfields['module_position']['checked']) {
418 print '<td class="right">'.dolPrintHTML($module->module_position).'</td>';
419 }
420
421 // Action column
422 if (!$conf->main_checkbox_left_column) {
423 print '<td></td>';
424 }
425 print '</tr>';
426}
427
428print '</table>';
429print '</div>';
430print '</form>';
431print '<br>';
432
433sort($rights_ids);
434$old = '';
435
436foreach ($rights_ids as $right_id) {
437 if ($old == $right_id) {
438 print "Warning duplicate id on permission : ".$right_id."<br>";
439 }
440
441 $old = $right_id;
442}
443
444// End of page
445llxFooter();
446$db->close();
447
448
457{
458 if ((int) $a->id == (int) $b->id) {
459 return 0;
460 }
461
462 return ((int) $a->id < (int) $b->id) ? -1 : 1;
463}
464
473{
474 if ((int) $a->id == (int) $b->id) {
475 return 0;
476 }
477
478 return ((int) $b->id < (int) $a->id) ? -1 : 1;
479}
480
489{
490 if (empty($a->permission) && empty($b->permission)) {
491 return compareIdAsc($a, $b);
492 }
493
494 if (empty($a->permission)) {
495 return 1;
496 }
497 if (empty($b->permission)) {
498 return -1;
499 }
500
501 if ($a->permission[0] == $b->permission[0]) {
502 return 0;
503 }
504
505 return $a->permission[0] < $b->permission[0] ? -1 : 1;
506}
507
516{
517 if (empty($a->permission) && empty($b->permission)) {
518 return compareIdDesc($a, $b);
519 }
520
521 if (empty($a->permission)) {
522 return -1;
523 }
524 if (empty($b->permission)) {
525 return 1;
526 }
527
528 if ($a->permission[0] == $b->permission[0]) {
529 return 0;
530 }
531
532 return $b->permission[0] < $a->permission[0] ? -1 : 1;
533}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
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.
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:472
compareIdAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:456
comparePermissionIdsDesc(stdClass $a, stdClass $b)
Compare two modules by their permissions for a descending order.
Definition modules.php:515
comparePermissionIdsAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:488