dolibarr  13.0.2
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 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
27 
28 if (!$user->admin) {
30 }
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("install", "other", "admin"));
34 
35 $optioncss = GETPOST('optioncss', 'alpha');
36 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'moduleoverview';
37 
38 $search_name = GETPOST("search_name", 'alpha');
39 $search_id = GETPOST("search_id", 'alpha');
40 $search_version = GETPOST("search_version", 'alpha');
41 $search_permission = GETPOST("search_permission", 'alpha');
42 
43 $sortfield = GETPOST("sortfield", 'alpha');
44 $sortorder = GETPOST("sortorder", 'alpha');
45 
46 if (!$sortfield) $sortfield = "id";
47 if (!$sortorder) $sortorder = "asc";
48 
49 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
50 $hookmanager->initHooks(array('moduleoverview'));
51 $form = new Form($db);
52 $object = new stdClass();
53 
54 // Definition of fields for lists
55 $arrayfields = array(
56  'name'=>array('label'=>$langs->trans("Modules"), 'checked'=>1, 'position'=>10),
57  'version'=>array('label'=>$langs->trans("Version"), 'checked'=>1, 'position'=>20),
58  'id'=>array('label'=>$langs->trans("IdModule"), 'checked'=>1, 'position'=>30),
59  'module_position'=>array('label'=>$langs->trans("Position"), 'checked'=>1, 'position'=>35),
60  'permission'=>array('label'=>$langs->trans("IdPermissions"), 'checked'=>1, 'position'=>40)
61 );
62 
63 $arrayfields = dol_sort_array($arrayfields, 'position');
64 
65 
66 /*
67  * Actions
68  */
69 
70 $parameters = array();
71 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
72 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
73 
74 if (empty($reshook)) {
75  // Selection of new fields
76  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
77 }
78 
79 
80 // Load list of modules
81 $moduleList = array();
82 $modules = array();
83 $modules_files = array();
84 $modules_fullpath = array();
85 $modulesdir = dolGetModulesDirs();
86 $rights_ids = array();
87 
88 foreach ($modulesdir as $dir) {
89  $handle = @opendir(dol_osencode($dir));
90  if (is_resource($handle)) {
91  while (($file = readdir($handle)) !== false) {
92  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
93  $modName = substr($file, 0, dol_strlen($file) - 10);
94 
95  if ($modName) {
96  //print 'xx'.$dir.$file.'<br>';
97  if (in_array($file, $modules_files)) {
98  // File duplicate
99  print "Warning duplicate file found : ".$file." (Found ".$dir.$file.", already found ".$modules_fullpath[$file].")<br>";
100  }
101  else {
102  // File to load
103  $res = include_once $dir.$file;
104  if (class_exists($modName)) {
105  try {
106  $objMod = new $modName($db);
107 
108  $modules[$objMod->numero] = $objMod;
109  $modules_files[$objMod->numero] = $file;
110  $modules_fullpath[$file] = $dir.$file;
111  }
112  catch (Exception $e) {
113  dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
114  }
115  }
116  else {
117  print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)<br>";
118  }
119  }
120  }
121  }
122  }
123  closedir($handle);
124  }
125 }
126 
127 // create pre-filtered list for modules
128 foreach ($modules as $key=>$module) {
129  $newModule = new stdClass();
130 
131  $newModule->name = $module->getName();
132  $newModule->version = $module->getVersion();
133  $newModule->id = $key;
134  $newModule->module_position = $module->module_position;
135 
136  $alt = $module->name.' - '.$modules_files[$key];
137 
138  if (!empty($module->picto)) {
139  if (preg_match('/^\//', $module->picto)) $newModule->picto = img_picto($alt, $module->picto, 'width="14px"', 1);
140  else $newModule->picto = img_object($alt, $module->picto, 'width="14px"');
141  }
142  else {
143  $newModule->picto = img_object($alt, 'generic', 'width="14px"');
144  }
145 
146  $permission = array();
147  if ($module->rights) {
148  foreach ($module->rights as $rights) {
149  if (empty($rights[0])) {
150  continue;
151  }
152 
153  $permission[] = $rights[0];
154 
155  array_push($rights_ids, $rights[0]);
156  }
157  }
158 
159  $newModule->permission = $permission;
160 
161  // pre-filter list
162  if ($search_name && !stristr($newModule->name, $search_name)) continue;
163  if ($search_version && !stristr($newModule->version, $search_version)) continue;
164  if ($search_id && !stristr($newModule->id, $search_id)) continue;
165 
166  if ($search_permission) {
167  $found = false;
168 
169  foreach ($newModule->permission as $permission) {
170  if (stristr($permission, $search_permission)) {
171  $found = true;
172  break;
173  }
174  }
175 
176  if (!$found) continue;
177  }
178 
179  $moduleList[] = $newModule;
180 }
181 
182 
183 
184 /*
185  * View
186  */
187 
188 llxHeader();
189 
190 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
191 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
192 print '<input type="hidden" name="token" value="'.newToken().'">';
193 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
194 print '<input type="hidden" name="action" value="list">';
195 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
196 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
197 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
198 
199 print_barre_liste($langs->trans("AvailableModules"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $massactionbutton, -1, '', 'title_setup', 0, '', '', 0, 1, 1);
200 
201 print '<span class="opacitymedium">'.$langs->trans("ToActivateModule").'</span>';
202 print '<br>';
203 print '<br>';
204 
205 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
206 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
207 
208 print '<div class="div-table-responsive-no-min">';
209 print '<table class="noborder centpercent">';
210 
211 // Lines with input filters
212 print '<tr class="liste_titre_filter">';
213 
214 if ($arrayfields['name']['checked']) {
215  print '<td class="liste_titre left">';
216  print '<input class="flat" type="text" name="search_name" size="8" value="'.$search_name.'">';
217  print '</td>';
218 }
219 if ($arrayfields['version']['checked']) {
220  print '<td class="liste_titre left">';
221  print '<input class="flat" type="text" name="search_version" size="8" value="'.$search_version.'">';
222  print '</td>';
223 }
224 if ($arrayfields['id']['checked']) {
225  print '<td class="liste_titre left">';
226  print '<input class="flat" type="text" name="search_id" size="8" value="'.$search_id.'">';
227  print '</td>';
228 }
229 if ($arrayfields['module_position']['checked']) {
230  print '<td class="liste_titre left">';
231  print '</td>';
232 }
233 if ($arrayfields['permission']['checked']) {
234  print '<td class="liste_titre left">';
235  print '<input class="flat" type="text" name="search_permission" size="8" value="'.$search_permission.'">';
236  print '</td>';
237 }
238 
239 print '<td class="liste_titre center maxwidthsearch">';
240 $searchpicto = $form->showFilterButtons();
241 print $searchpicto;
242 print '</td>';
243 
244 print '</tr>';
245 
246 print '<tr class="liste_titre">';
247 
248 if ($arrayfields['name']['checked']) {
249  print_liste_field_titre($arrayfields['name']['label'], $_SERVER["PHP_SELF"], "name", "", "", "", $sortfield, $sortorder);
250 }
251 if ($arrayfields['version']['checked']) {
252  print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder);
253 }
254 if ($arrayfields['id']['checked']) {
255  print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder);
256 }
257 if ($arrayfields['module_position']['checked']) {
258  print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder);
259 }
260 if ($arrayfields['permission']['checked']) {
261  print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder);
262 }
263 
264 // Fields from hook
265 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
266 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
267 print $hookmanager->resPrint;
268 
269 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
270 print '</tr>';
271 
272 // sort list
273 if ($sortfield == "name" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) {
274  return strcasecmp($a->name, $b->name); });
275 if ($sortfield == "name" && $sortorder == "desc") usort($moduleList, function (stdClass $a, stdClass $b) {
276  return strcasecmp($b->name, $a->name); });
277 if ($sortfield == "version" && $sortorder == "asc") usort($moduleList, function (stdClass $a, stdClass $b) {
278  return strcasecmp($a->version, $b->version); });
279 if ($sortfield == "version" && $sortorder == "desc") usort($moduleList, function (stdClass $a, stdClass $b) {
280  return strcasecmp($b->version, $a->version); });
281 if ($sortfield == "id" && $sortorder == "asc") usort($moduleList, "compareIdAsc");
282 if ($sortfield == "id" && $sortorder == "desc") usort($moduleList, "compareIdDesc");
283 if ($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "comparePermissionIdsAsc");
284 if ($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "comparePermissionIdsDesc");
285 
286 $moduleList = dol_sort_array($moduleList, 'module_position');
287 
288 foreach ($moduleList as $module) {
289  print '<tr class="oddeven">';
290 
291  if ($arrayfields['name']['checked']) {
292  print '<td width="300" class="nowrap">';
293  print $module->picto;
294  print ' '.$module->name;
295  print "</td>";
296  }
297 
298  if ($arrayfields['version']['checked']) {
299  print '<td>'.$module->version.'</td>';
300  }
301 
302  if ($arrayfields['id']['checked']) {
303  print '<td class="center">'.$module->id.'</td>';
304  }
305 
306  if ($arrayfields['module_position']['checked']) {
307  print '<td class="center">'.$module->module_position.'</td>';
308  }
309 
310  if ($arrayfields['permission']['checked']) {
311  $idperms = '';
312 
313  foreach ($module->permission as $permission) {
314  $idperms .= ($idperms ? ", " : "").$permission;
315  $translationKey = "Permission".$permission;
316 
317  if (!empty($conf->global->MAIN_SHOW_PERMISSION)) {
318  if (empty($langs->tab_translate[$translationKey])) {
319  $tooltip = 'Missing translation (key '.$translationkey.' not found in admin.lang)';
320  $idperms .= ' <img src="../../theme/eldy/img/warning.png" alt="Warning" title="'.$tooltip.'">';
321  }
322  }
323  }
324 
325  print '<td>'.($idperms ? $idperms : "&nbsp;").'</td>';
326  }
327 
328  print '<td></td>';
329  print '</tr>';
330 }
331 
332 print '</table>';
333 print '</div>';
334 print '</form>';
335 print '<br>';
336 
337 sort($rights_ids);
338 $old = '';
339 
340 foreach ($rights_ids as $right_id) {
341  if ($old == $right_id) {
342  print "Warning duplicate id on permission : ".$right_id."<br>";
343  }
344 
345  $old = $right_id;
346 }
347 
348 // End of page
349 llxFooter();
350 $db->close();
351 
352 
360 function compareIdAsc(stdClass $a, stdClass $b)
361 {
362  if ($a->id == $b->id) return 0;
363 
364  return $a->id > $b->id ? -1 : 1;
365 }
366 
374 function compareIdDesc(stdClass $a, stdClass $b)
375 {
376  if ($a->id == $b->id) return 0;
377 
378  return $b->id > $a->id ? -1 : 1;
379 }
380 
388 function comparePermissionIdsAsc(stdClass $a, stdClass $b)
389 {
390  if (empty($a->permission) && empty($b->permission)) return compareIdAsc($a, $b);
391 
392  if (empty($a->permission)) return 1;
393  if (empty($b->permission)) return -1;
394 
395  if ($a->permission[0] == $b->permission[0]) return 0;
396 
397  return $a->permission[0] > $b->permission[0] ? -1 : 1;
398 }
399 
407 function comparePermissionIdsDesc(stdClass $a, stdClass $b)
408 {
409  if (empty($a->permission) && empty($b->permission)) return compareIdDesc($a, $b);
410 
411  if (empty($a->permission)) return -1;
412  if (empty($b->permission)) return 1;
413 
414  if ($a->permission[0] == $b->permission[0]) return 0;
415 
416  return $a->permission[0] > $b->permission[0] ? 1 : -1;
417 }
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolGetModulesDirs($subdir= '')
Return list of modules directories.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage generation of HTML components Only common components must be here.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59