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