dolibarr 21.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 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$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$sortfield = GETPOST('sortfield', 'aZ09comma');
55$sortorder = GETPOST('sortorder', 'aZ09comma');
56
57if (!$sortfield) {
58 $sortfield = "id";
59}
60if (!$sortorder) {
61 $sortorder = "asc";
62}
63
64// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
65$hookmanager->initHooks(array('moduleoverview'));
66$form = new Form($db);
67$object = new stdClass();
68
69// Definition of fields for lists
70$arrayfields = array(
71 'name' => array('label' => $langs->trans("Modules"), 'checked' => 1, 'position' => 10),
72 'version' => array('label' => $langs->trans("Version"), 'checked' => 1, 'position' => 20),
73 'id' => array('label' => $langs->trans("IdModule"), 'checked' => 1, 'position' => 30),
74 'module_position' => array('label' => $langs->trans("Position"), 'checked' => 1, 'position' => 35),
75 'permission' => array('label' => $langs->trans("IdPermissions"), 'checked' => 1, 'position' => 40)
76);
77
78$arrayfields = dol_sort_array($arrayfields, 'position');
79'@phan-var-force array<string,array{label:string,checked:int<0,1>,position:int}> $arrayfields';
80
81$param = '';
82$info_admin = '';
83
84/*
85 * Actions
86 */
87
88$parameters = array();
89$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90if ($reshook < 0) {
91 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
92}
93
94if (empty($reshook)) {
95 // Selection of new fields
96 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
97}
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
232print_barre_liste($langs->trans("AvailableModules"), empty($page) ? 0 : $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', -1, '', 'title_setup', 0, '', '', 0, 1, 1);
233
234print '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span>';
235print '<br>';
236print '<br>';
237
238$mode = '';
239$arrayofmassactions = array();
240
241$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
242$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
243$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
244$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
245
246$moreforfilter = '';
247
248print '<div class="div-table-responsive-no-min">';
249print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
250
251// Lines with input filters
252print '<tr class="liste_titre_filter">';
253// Action column
254if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
255 print '<td class="liste_titre center maxwidthsearch">';
256 $searchpicto = $form->showFilterButtons();
257 print $searchpicto;
258 print '</td>';
259}
260if ($arrayfields['name']['checked']) {
261 print '<td class="liste_titre left">';
262 print '<input class="flat" type="text" name="search_name" size="8" value="'.dol_escape_htmltag($search_name).'">';
263 print '</td>';
264}
265if ($arrayfields['version']['checked']) {
266 print '<td class="liste_titre left">';
267 print '<input class="flat" type="text" name="search_version" size="6" value="'.dol_escape_htmltag($search_version).'">';
268 print '</td>';
269}
270if ($arrayfields['id']['checked']) {
271 print '<td class="liste_titre left">';
272 print '<input class="flat" type="text" name="search_id" size="6" value="'.dol_escape_htmltag($search_id).'">';
273 print '</td>';
274}
275if ($arrayfields['permission']['checked']) {
276 print '<td class="liste_titre left">';
277 print '<input class="flat" type="text" name="search_permission" size="8" value="'.dol_escape_htmltag($search_permission).'">';
278 print '</td>';
279}
280if ($arrayfields['module_position']['checked']) {
281 print '<td class="liste_titre left">';
282 print '</td>';
283}
284// Action column
285if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
286 print '<td class="liste_titre center maxwidthsearch">';
287 $searchpicto = $form->showFilterButtons();
288 print $searchpicto;
289 print '</td>';
290}
291print '</tr>';
292
293print '<tr class="liste_titre">';
294// Action column
295if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
296 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn');
297}
298if ($arrayfields['name']['checked']) {
299 print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder);
300}
301if ($arrayfields['version']['checked']) {
302 print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder);
303}
304if ($arrayfields['id']['checked']) {
305 print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder, 'nowraponall ');
306}
307if ($arrayfields['permission']['checked']) {
308 print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder);
309}
310if ($arrayfields['module_position']['checked']) {
311 print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder);
312}
313
314// Fields from hook
315$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
316$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
317print $hookmanager->resPrint;
318// Action column
319if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
320 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
321}
322print '</tr>';
323
324// sort list
325if ($sortfield == "name" && $sortorder == "asc") {
326 usort(
327 $moduleList,
329 function (stdClass $a, stdClass $b) {
330 return strcasecmp($a->name, $b->name);
331 }
332 );
333} elseif ($sortfield == "name" && $sortorder == "desc") {
334 usort(
335 $moduleList,
337 static function (stdClass $a, stdClass $b) {
338 return strcasecmp($b->name, $a->name);
339 }
340 );
341} elseif ($sortfield == "version" && $sortorder == "asc") {
342 usort(
343 $moduleList,
345 static function (stdClass $a, stdClass $b) {
346 return strcasecmp($a->version, $b->version);
347 }
348 );
349} elseif ($sortfield == "version" && $sortorder == "desc") {
350 usort(
351 $moduleList,
353 static function (stdClass $a, stdClass $b) {
354 return strcasecmp($b->version, $a->version);
355 }
356 );
357} elseif ($sortfield == "id" && $sortorder == "asc") {
358 usort($moduleList, "compareIdAsc");
359} elseif ($sortfield == "id" && $sortorder == "desc") {
360 usort($moduleList, "compareIdDesc");
361} elseif ($sortfield == "permission" && $sortorder == "asc") {
362 usort($moduleList, "comparePermissionIdsAsc");
363} elseif ($sortfield == "permission" && $sortorder == "desc") {
364 usort($moduleList, "comparePermissionIdsDesc");
365} else {
366 $moduleList = dol_sort_array($moduleList, 'module_position');
367}
368
369foreach ($moduleList as $module) {
370 print '<tr class="oddeven">';
371 // Action column
372 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
373 print '<td></td>';
374 }
375
376 if ($arrayfields['name']['checked']) {
377 print '<td width="300" class="nowrap">';
378 print $module->picto;
379 print ' '.$module->name;
380 print "</td>";
381 }
382
383 if ($arrayfields['version']['checked']) {
384 print '<td class="nowraponall">'.$module->version.'</td>';
385 }
386
387 if ($arrayfields['id']['checked']) {
388 print '<td class="center">'.$module->id.'</td>';
389 }
390
391 if ($arrayfields['permission']['checked']) {
392 $idperms = '';
393
394 foreach ($module->permission as $permission) {
395 $translationKey = "Permission".$permission;
396 $labelpermission = $langs->trans($translationKey);
397 $labelpermission .= ' : '.$arrayofpermissions[$permission]['label'];
398 $idperms .= ($idperms ? ", " : "").'<span title="'.$labelpermission.'">'.$permission.'</a>';
399
400 if (getDolGlobalString('MAIN_SHOW_PERMISSION')) {
401 if (empty($langs->tab_translate[$translationKey])) {
402 $tooltip = 'Missing translation (key '.$translationKey.' not found in admin.lang)';
403 $idperms .= ' <img src="../../theme/eldy/img/warning.png" alt="Warning" title="'.$tooltip.'">';
404 }
405 }
406 }
407
408 print '<td><span class="opacitymedium">'.($idperms ? $idperms : "&nbsp;").'</span></td>';
409 }
410
411 if ($arrayfields['module_position']['checked']) {
412 print '<td class="center">'.$module->module_position.'</td>';
413 }
414
415 // Action column
416 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
417 print '<td></td>';
418 }
419 print '</tr>';
420}
421
422print '</table>';
423print '</div>';
424print '</form>';
425print '<br>';
426
427sort($rights_ids);
428$old = '';
429
430foreach ($rights_ids as $right_id) {
431 if ($old == $right_id) {
432 print "Warning duplicate id on permission : ".$right_id."<br>";
433 }
434
435 $old = $right_id;
436}
437
438// End of page
439llxFooter();
440$db->close();
441
442
451{
452 if ((int) $a->id == (int) $b->id) {
453 return 0;
454 }
455
456 return ((int) $a->id < (int) $b->id) ? -1 : 1;
457}
458
467{
468 if ((int) $a->id == (int) $b->id) {
469 return 0;
470 }
471
472 return ((int) $b->id < (int) $a->id) ? -1 : 1;
473}
474
483{
484 if (empty($a->permission) && empty($b->permission)) {
485 return compareIdAsc($a, $b);
486 }
487
488 if (empty($a->permission)) {
489 return 1;
490 }
491 if (empty($b->permission)) {
492 return -1;
493 }
494
495 if ($a->permission[0] == $b->permission[0]) {
496 return 0;
497 }
498
499 return $a->permission[0] < $b->permission[0] ? -1 : 1;
500}
501
510{
511 if (empty($a->permission) && empty($b->permission)) {
512 return compareIdDesc($a, $b);
513 }
514
515 if (empty($a->permission)) {
516 return -1;
517 }
518 if (empty($b->permission)) {
519 return 1;
520 }
521
522 if ($a->permission[0] == $b->permission[0]) {
523 return 0;
524 }
525
526 return $b->permission[0] < $a->permission[0] ? -1 : 1;
527}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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:466
compareIdAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:450
comparePermissionIdsDesc(stdClass $a, stdClass $b)
Compare two modules by their permissions for a descending order.
Definition modules.php:509
comparePermissionIdsAsc(stdClass $a, stdClass $b)
Compare two modules by their ID for a ascending order.
Definition modules.php:482