dolibarr  17.0.4
modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2011-2023 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
9  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
10  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
11  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
32 if (!defined('CSRFCHECK_WITH_TOKEN') && (empty($_GET['action']) || $_GET['action'] != 'reset')) { // We force security except to disable modules so we can do it if problem of a module
33  define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
34 }
35 
36 // Load Dolibarr environment
37 require '../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/dolistore.class.php';
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array("errors", "admin", "modulebuilder"));
46 
47 // if we set another view list mode, we keep it (till we change one more time)
48 if (GETPOSTISSET('mode')) {
49  $mode = GETPOST('mode', 'alpha');
50  if ($mode =='common' || $mode =='commonkanban')
51  dolibarr_set_const($db, "MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT", $mode, 'chaine', 0, '', $conf->entity);
52 } else {
53  $mode = (empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : $conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT);
54 }
55 
56 $action = GETPOST('action', 'aZ09');
57 $value = GETPOST('value', 'alpha');
58 $page_y = GETPOST('page_y', 'int');
59 $search_keyword = GETPOST('search_keyword', 'alpha');
60 $search_status = GETPOST('search_status', 'alpha');
61 $search_nature = GETPOST('search_nature', 'alpha');
62 $search_version = GETPOST('search_version', 'alpha');
63 
64 
65 // For dolistore search
66 $options = array();
67 $options['per_page'] = 20;
68 $options['categorie'] = ((GETPOST('categorie', 'int') ?GETPOST('categorie', 'int') : 0) + 0);
69 $options['start'] = ((GETPOST('start', 'int') ?GETPOST('start', 'int') : 0) + 0);
70 $options['end'] = ((GETPOST('end', 'int') ?GETPOST('end', 'int') : 0) + 0);
71 $options['search'] = GETPOST('search_keyword', 'alpha');
72 $dolistore = new Dolistore(false);
73 
74 
75 if (!$user->admin) {
77 }
78 
79 $familyinfo = array(
80  'hr'=>array('position'=>'001', 'label'=>$langs->trans("ModuleFamilyHr")),
81  'crm'=>array('position'=>'006', 'label'=>$langs->trans("ModuleFamilyCrm")),
82  'srm'=>array('position'=>'007', 'label'=>$langs->trans("ModuleFamilySrm")),
83  'financial'=>array('position'=>'009', 'label'=>$langs->trans("ModuleFamilyFinancial")),
84  'products'=>array('position'=>'012', 'label'=>$langs->trans("ModuleFamilyProducts")),
85  'projects'=>array('position'=>'015', 'label'=>$langs->trans("ModuleFamilyProjects")),
86  'ecm'=>array('position'=>'018', 'label'=>$langs->trans("ModuleFamilyECM")),
87  'technic'=>array('position'=>'021', 'label'=>$langs->trans("ModuleFamilyTechnic")),
88  'portal'=>array('position'=>'040', 'label'=>$langs->trans("ModuleFamilyPortal")),
89  'interface'=>array('position'=>'050', 'label'=>$langs->trans("ModuleFamilyInterface")),
90  'base'=>array('position'=>'060', 'label'=>$langs->trans("ModuleFamilyBase")),
91  'other'=>array('position'=>'100', 'label'=>$langs->trans("ModuleFamilyOther")),
92 );
93 
94 $param = '';
95 if (!GETPOST('buttonreset', 'alpha')) {
96  if ($search_keyword) {
97  $param .= '&search_keyword='.urlencode($search_keyword);
98  }
99  if ($search_status && $search_status != '-1') {
100  $param .= '&search_status='.urlencode($search_status);
101  }
102  if ($search_nature && $search_nature != '-1') {
103  $param .= '&search_nature='.urlencode($search_nature);
104  }
105  if ($search_version && $search_version != '-1') {
106  $param .= '&search_version='.urlencode($search_version);
107  }
108 }
109 
110 $dirins = DOL_DOCUMENT_ROOT.'/custom';
111 $urldolibarrmodules = 'https://www.dolistore.com/';
112 
113 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
114 $hookmanager->initHooks(array('adminmodules', 'globaladmin'));
115 
116 
117 /*
118  * Actions
119  */
120 
121 $formconfirm = '';
122 
123 $parameters = array();
124 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
125 if ($reshook < 0) {
126  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
127 }
128 
129 if (GETPOST('buttonreset', 'alpha')) {
130  $search_keyword = '';
131  $search_status = '';
132  $search_nature = '';
133  $search_version = '';
134 }
135 
136 if ($action == 'install') {
137  $error = 0;
138 
139  // $original_file should match format module_modulename-x.y[.z].zip
140  $original_file = basename($_FILES["fileinstall"]["name"]);
141  $original_file = preg_replace('/\s*\‍(\d+\‍)\.zip$/i', '.zip', $original_file);
142  $newfile = $conf->admin->dir_temp.'/'.$original_file.'/'.$original_file;
143 
144  if (!$original_file) {
145  $langs->load("Error");
146  setEventMessages($langs->trans("ErrorModuleFileRequired"), null, 'warnings');
147  $error++;
148  } else {
149  if (!$error && !preg_match('/\.zip$/i', $original_file)) {
150  $langs->load("errors");
151  setEventMessages($langs->trans("ErrorFileMustBeADolibarrPackage", $original_file), null, 'errors');
152  $error++;
153  }
154  if (!$error && !preg_match('/^(module[a-zA-Z0-9]*|theme)_.*\-([0-9][0-9\.]*)\.zip$/i', $original_file)) {
155  $langs->load("errors");
156  setEventMessages($langs->trans("ErrorFilenameDosNotMatchDolibarrPackageRules", $original_file, 'module_*-x.y*.zip'), null, 'errors');
157  $error++;
158  }
159  if (empty($_FILES['fileinstall']['tmp_name'])) {
160  $langs->load("errors");
161  setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
162  $error++;
163  }
164  }
165 
166  if (!$error) {
167  if ($original_file) {
168  @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$original_file);
169  dol_mkdir($conf->admin->dir_temp.'/'.$original_file);
170  }
171 
172  $tmpdir = preg_replace('/\.zip$/i', '', $original_file).'.dir';
173  if ($tmpdir) {
174  @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$tmpdir);
175  dol_mkdir($conf->admin->dir_temp.'/'.$tmpdir);
176  }
177 
178  $result = dol_move_uploaded_file($_FILES['fileinstall']['tmp_name'], $newfile, 1, 0, $_FILES['fileinstall']['error']);
179  if ($result > 0) {
180  $result = dol_uncompress($newfile, $conf->admin->dir_temp.'/'.$tmpdir);
181 
182  if (!empty($result['error'])) {
183  $langs->load("errors");
184  setEventMessages($langs->trans($result['error'], $original_file), null, 'errors');
185  $error++;
186  } else {
187  // Now we move the dir of the module
188  $modulename = preg_replace('/module_/', '', $original_file);
189  $modulename = preg_replace('/\-([0-9][0-9\.]*)\.zip$/i', '', $modulename);
190  // Search dir $modulename
191  $modulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulename; // Example ./mymodule
192 
193  if (!dol_is_dir($modulenamedir)) {
194  $modulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulename; // Example ./htdocs/mymodule
195  //var_dump($modulenamedir);
196  if (!dol_is_dir($modulenamedir)) {
197  setEventMessages($langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat").'<br>'.$langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat2", $modulename, 'htdocs/'.$modulename), null, 'errors');
198  $error++;
199  }
200  }
201 
202  if (!$error) {
203  // TODO Make more test
204  }
205 
206  dol_syslog("Uncompress of module file is a success.");
207 
208  // We check if this is a metapackage
209  $modulenamearrays = array();
210  if (dol_is_file($modulenamedir.'/metapackage.conf')) {
211  // This is a meta package
212  $metafile = file_get_contents($modulenamedir.'/metapackage.conf');
213  $modulenamearrays = explode("\n", $metafile);
214  }
215  $modulenamearrays[$modulename] = $modulename;
216  //var_dump($modulenamearrays);exit;
217 
218  // Lop on each packacge of the metapackage
219  foreach ($modulenamearrays as $modulenameval) {
220  if (strpos($modulenameval, '#') === 0) {
221  continue; // Discard comments
222  }
223  if (strpos($modulenameval, '//') === 0) {
224  continue; // Discard comments
225  }
226  if (!trim($modulenameval)) {
227  continue;
228  }
229 
230  // Now we install the module
231  if (!$error) {
232  @dol_delete_dir_recursive($dirins.'/'.$modulenameval); // delete the target directory
233  $submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulenameval;
234  if (!dol_is_dir($submodulenamedir)) {
235  $submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulenameval;
236  }
237  dol_syslog("We copy now directory ".$submodulenamedir." into target dir ".$dirins.'/'.$modulenameval);
238  $result = dolCopyDir($submodulenamedir, $dirins.'/'.$modulenameval, '0444', 1);
239  if ($result <= 0) {
240  dol_syslog('Failed to call dolCopyDir result='.$result." with param ".$submodulenamedir." and ".$dirins.'/'.$modulenameval, LOG_WARNING);
241  $langs->load("errors");
242  setEventMessages($langs->trans("ErrorFailToCopyDir", $submodulenamedir, $dirins.'/'.$modulenameval), null, 'errors');
243  $error++;
244  }
245  }
246  }
247  }
248  } else {
249  setEventMessages($langs->trans("ErrorFailToRenameFile", $_FILES['fileinstall']['tmp_name'], $newfile), null, 'errors');
250  $error++;
251  }
252  }
253 
254  if (!$error) {
255  setEventMessages($langs->trans("SetupIsReadyForUse", DOL_URL_ROOT.'/admin/modules.php?mainmenu=home', $langs->transnoentitiesnoconv("Home").' - '.$langs->transnoentitiesnoconv("Setup").' - '.$langs->transnoentitiesnoconv("Modules")), null, 'warnings');
256  }
257 }
258 
259 if ($action == 'set' && $user->admin) {
260  $resarray = activateModule($value);
261  dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
262  if (!empty($resarray['errors'])) {
263  setEventMessages('', $resarray['errors'], 'errors');
264  } else {
265  //var_dump($resarray);exit;
266  if ($resarray['nbperms'] > 0) {
267  $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
268  $resqltmp = $db->query($tmpsql);
269  if ($resqltmp) {
270  $obj = $db->fetch_object($resqltmp);
271  //var_dump($obj->nb);exit;
272  if ($obj && $obj->nb > 1) {
273  $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
274  setEventMessages($msg, null, 'warnings');
275  }
276  } else {
277  dol_print_error($db);
278  }
279  }
280  }
281  header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
282  exit;
283 } elseif ($action == 'reset' && $user->admin && GETPOST('confirm') == 'yes') {
284  $result = unActivateModule($value);
285  dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
286  if ($result) {
287  setEventMessages($result, null, 'errors');
288  }
289  header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
290  exit;
291 }
292 
293 
294 
295 /*
296  * View
297  */
298 
299 $form = new Form($db);
300 
301 $morejs = array();
302 $morecss = array("/admin/dolistore/css/dolistore.css");
303 
304 // Set dir where external modules are installed
305 if (!dol_is_dir($dirins)) {
306  dol_mkdir($dirins);
307 }
308 $dirins_ok = (dol_is_dir($dirins));
309 
310 $help_url = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
311 llxHeader('', $langs->trans("Setup"), $help_url, '', '', '', $morejs, $morecss, 0, 0);
312 
313 
314 // Search modules dirs
315 $modulesdir = dolGetModulesDirs();
316 
317 $arrayofnatures = array('core'=>$langs->transnoentitiesnoconv("NativeModules"), 'external'=>$langs->transnoentitiesnoconv("External").' - ['.$langs->trans("AllPublishers").']');
318 $arrayofwarnings = array(); // Array of warning each module want to show when activated
319 $arrayofwarningsext = array(); // Array of warning each module want to show when we activate an external module
320 $filename = array();
321 $modules = array();
322 $orders = array();
323 $categ = array();
324 
325 $i = 0; // is a sequencer of modules found
326 $j = 0; // j is module number. Automatically affected if module number not defined.
327 $modNameLoaded = array();
328 
329 foreach ($modulesdir as $dir) {
330  // Load modules attributes in arrays (name, numero, orders) from dir directory
331  //print $dir."\n<br>";
332  dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
333  $handle = @opendir($dir);
334  if (is_resource($handle)) {
335  while (($file = readdir($handle)) !== false) {
336  //print "$i ".$file."\n<br>";
337  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
338  $modName = substr($file, 0, dol_strlen($file) - 10);
339 
340  if ($modName) {
341  if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
342  $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
343  setEventMessages($mesg, null, 'warnings');
344  dol_syslog($mesg, LOG_ERR);
345  continue;
346  }
347 
348  try {
349  $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
350  if (class_exists($modName)) {
351  try {
352  $objMod = new $modName($db);
353  $modNameLoaded[$modName] = $dir;
354  if (!$objMod->numero > 0 && $modName != 'modUser') {
355  dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR);
356  }
357  $j = $objMod->numero;
358 
359  $modulequalified = 1;
360 
361  // We discard modules according to features level (PS: if module is activated we always show it)
362  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
363  if ($objMod->version == 'development' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 2))) {
364  $modulequalified = 0;
365  }
366  if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) {
367  $modulequalified = 0;
368  }
369  if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) {
370  $modulequalified = 0;
371  }
372 
373  // We discard modules according to property ->hidden
374  if (!empty($objMod->hidden)) {
375  $modulequalified = 0;
376  }
377 
378  if ($modulequalified > 0) {
379  $publisher = dol_escape_htmltag($objMod->getPublisher());
380  $external = ($objMod->isCoreOrExternalModule() == 'external');
381  if ($external) {
382  if ($publisher) {
383  $arrayofnatures['external_'.$publisher] = $langs->trans("External").' - '.$publisher;
384  } else {
385  $arrayofnatures['external_'] = $langs->trans("External").' - '.$langs->trans("UnknownPublishers");
386  }
387  }
388  ksort($arrayofnatures);
389 
390  // Define array $categ with categ with at least one qualified module
391  $filename[$i] = $modName;
392  $modules[$modName] = $objMod;
393 
394  // Gives the possibility to the module, to provide his own family info and position of this family
395  if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) {
396  $familyinfo = array_merge($familyinfo, $objMod->familyinfo);
397  $familykey = key($objMod->familyinfo);
398  } else {
399  $familykey = $objMod->family;
400  }
401 
402  $moduleposition = ($objMod->module_position ? $objMod->module_position : '50');
403  if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) {
404  // an external module should never return a value lower than '80'.
405  $moduleposition = '80'; // External modules at end by default
406  }
407 
408  // Add list of warnings to show into arrayofwarnings and arrayofwarningsext
409  if (!empty($objMod->warnings_activation)) {
410  $arrayofwarnings[$modName] = $objMod->warnings_activation;
411  }
412  if (!empty($objMod->warnings_activation_ext)) {
413  $arrayofwarningsext[$modName] = $objMod->warnings_activation_ext;
414  }
415 
416  $familyposition = (empty($familyinfo[$familykey]['position']) ? 0 : $familyinfo[$familykey]['position']);
417  $listOfOfficialModuleGroups = array('hr', 'technic', 'interface', 'technic', 'portal', 'financial', 'crm', 'base', 'products', 'srm', 'ecm', 'projects', 'other');
418  if ($external && !in_array($familykey, $listOfOfficialModuleGroups)) {
419  // If module is extern and into a custom group (not into an official predefined one), it must appear at end (custom groups should not be before official groups).
420  if (is_numeric($familyposition)) {
421  $familyposition = sprintf("%03d", (int) $familyposition + 100);
422  }
423  }
424 
425  $orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
426 
427  // Set categ[$i]
428  $specialstring = 'unknown';
429  if ($objMod->version == 'development' || $objMod->version == 'experimental') {
430  $specialstring = 'expdev';
431  }
432  if (isset($categ[$specialstring])) {
433  $categ[$specialstring]++; // Array of all different modules categories
434  } else {
435  $categ[$specialstring] = 1;
436  }
437  $j++;
438  $i++;
439  } else {
440  dol_syslog("Module ".get_class($objMod)." not qualified");
441  }
442  } catch (Exception $e) {
443  dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
444  }
445  } else {
446  print "admin/modules.php Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)<br>";
447  }
448  } catch (Exception $e) {
449  dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
450  }
451  }
452  }
453  }
454  closedir($handle);
455  } else {
456  dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
457  }
458 }
459 
460 if ($action == 'reset_confirm' && $user->admin) {
461  if (!empty($modules[$value])) {
462  $objMod = $modules[$value];
463 
464  if (!empty($objMod->langfiles)) {
465  $langs->loadLangs($objMod->langfiles);
466  }
467 
468  $form = new Form($db);
469  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmUnactivation'), $langs->trans(GETPOST('confirm_message_code')), 'reset', '', 'no', 1);
470  }
471 }
472 
473 print $formconfirm;
474 
475 asort($orders);
476 //var_dump($orders);
477 //var_dump($categ);
478 //var_dump($modules);
479 
480 $nbofactivatedmodules = count($conf->modules);
481 
482 //$conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING = 1000;
483 /*$moreinfo = $langs->trans("TitleNumberOfActivatedModules");
484 $moreinfo2 = '<b class="largenumber">'.($nbofactivatedmodules - 1).'</b> / <b class="largenumber">'.count($modules).'</b>';
485 if ($nbofactivatedmodules <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) {
486  $moreinfo2 .= ' '.img_warning($langs->trans("YouMustEnableOneModule"));
487 }*/
488 
489 print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup');
490 
491 // Start to show page
492 $deschelp = '';
493 if ($mode == 'common' || $mode == 'commonkanban') {
494  $desc = $langs->trans("ModulesDesc", '{picto}');
495  $desc .= ' '.$langs->trans("ModulesDesc2", '{picto2}');
496  $desc = str_replace('{picto}', img_picto('', 'switch_off', 'class="size15x"'), $desc);
497  $desc = str_replace('{picto2}', img_picto('', 'setup', 'class="size15x"'), $desc);
498  if (count($conf->modules) <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled
499  $deschelp .= '<div class="info hideonsmartphone">'.$desc."<br></div>\n";
500  }
501  if (!empty($conf->global->MAIN_SETUP_MODULES_INFO)) { // Show a custom message
502  $deschelp .= '<div class="info">'.$langs->trans($conf->global->MAIN_SETUP_MODULES_INFO)."<br></div>\n";
503  }
504  if ($deschelp) {
505  $deschelp .= '<br>';
506  }
507 }
508 if ($mode == 'marketplace') {
509  //$deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesMarketPlaceDesc")."<br></div><br>\n";
510 }
511 if ($mode == 'deploy') {
512  $deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."<br></div><br>\n";
513 }
514 if ($mode == 'develop') {
515  $deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDevelopDesc")."<br></div><br>\n";
516 }
517 
518 $head = modules_prepare_head($nbofactivatedmodules, count($modules));
519 
520 
521 if ($mode == 'common' || $mode == 'commonkanban') {
522  dol_set_focus('#search_keyword');
523 
524  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
525  print '<input type="hidden" name="token" value="'.newToken().'">';
526  if (isset($optioncss) && $optioncss != '') {
527  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
528  }
529  if (isset($sortfield) && $sortfield != '') {
530  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
531  }
532  if (isset($sortorder) && $sortorder != '') {
533  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
534  }
535  if (isset($page) && $page != '') {
536  print '<input type="hidden" name="page" value="'.$page.'">';
537  }
538  print '<input type="hidden" name="mode" value="'.$mode.'">';
539 
540  print dol_get_fiche_head($head, 'modules', '', -1);
541 
542  print $deschelp;
543 
544  $moreforfilter = '<div class="valignmiddle">';
545 
546  $moreforfilter .= '<div class="floatright right pagination paddingtop --module-list"><ul><li>';
547  $moreforfilter .= dolGetButtonTitle($langs->trans('CheckForModuleUpdate'), $langs->trans('CheckForModuleUpdate').'<br>'.$langs->trans('CheckForModuleUpdateHelp'), 'fa fa-sync', $_SERVER["PHP_SELF"].'?action=checklastversion&token='.newToken().'&mode='.$mode.$param, '', 1, array('morecss'=>'reposition'));
548  $moreforfilter .= dolGetButtonTitleSeparator();
549  $moreforfilter .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.$param, '', ($mode == 'common' ? 2 : 1), array('morecss'=>'reposition'));
550  $moreforfilter .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=commonkanban'.$param, '', ($mode == 'commonkanban' ? 2 : 1), array('morecss'=>'reposition'));
551  $moreforfilter .= '</li></ul></div>';
552 
553  //$moreforfilter .= '<div class="floatright center marginrightonly hideonsmartphone" style="padding-top: 3px"><span class="paddingright">'.$moreinfo.'</span> '.$moreinfo2.'</div>';
554 
555  $moreforfilter .= '<div class="divfilteralone colorbacktimesheet float valignmiddle">';
556  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
557  $moreforfilter .= img_picto($langs->trans("Filter"), 'filter', 'class="paddingright opacityhigh hideonsmartphone"').'<input type="text" id="search_keyword" name="search_keyword" class="maxwidth125" value="'.dol_escape_htmltag($search_keyword).'" placeholder="'.dol_escape_htmltag($langs->trans('Keyword')).'">';
558  $moreforfilter .= '</div>';
559  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
560  $moreforfilter .= $form->selectarray('search_nature', $arrayofnatures, dol_escape_htmltag($search_nature), $langs->trans('Origin'), 0, 0, '', 0, 0, 0, '', 'maxwidth250', 1);
561  $moreforfilter .= '</div>';
562  if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
563  $array_version = array('stable'=>$langs->transnoentitiesnoconv("Stable"));
564  if ($conf->global->MAIN_FEATURES_LEVEL < 0) {
565  $array_version['deprecated'] = $langs->trans("Deprecated");
566  }
567  if ($conf->global->MAIN_FEATURES_LEVEL > 0) {
568  $array_version['experimental'] = $langs->trans("Experimental");
569  }
570  if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
571  $array_version['development'] = $langs->trans("Development");
572  }
573  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
574  $moreforfilter .= $form->selectarray('search_version', $array_version, $search_version, $langs->trans('Version'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
575  $moreforfilter .= '</div>';
576  }
577  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
578  $moreforfilter .= $form->selectarray('search_status', array('active'=>$langs->transnoentitiesnoconv("Enabled"), 'disabled'=>$langs->transnoentitiesnoconv("Disabled")), $search_status, $langs->trans('Status'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
579  $moreforfilter .= '</div>';
580  $moreforfilter .= ' ';
581  $moreforfilter .= '<div class="divsearchfield valignmiddle inline-block">';
582  $moreforfilter .= '<input type="submit" name="buttonsubmit" class="button small" value="'.dol_escape_htmltag($langs->trans("Refresh")).'">';
583  if ($search_keyword || ($search_nature && $search_nature != '-1') || ($search_version && $search_version != '-1') || ($search_status && $search_status != '-1')) {
584  $moreforfilter .= ' ';
585  $moreforfilter .= '<input type="submit" name="buttonreset" class="buttonreset noborderbottom" value="'.dol_escape_htmltag($langs->trans("Reset")).'">';
586  }
587  $moreforfilter .= '</div>';
588  $moreforfilter .= '</div>';
589 
590  $moreforfilter .= '</div>';
591 
592  if (!empty($moreforfilter)) {
593  print $moreforfilter;
594  $parameters = array();
595  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
596  print $hookmanager->resPrint;
597  }
598 
599  $moreforfilter = '';
600 
601  print '<div class="clearboth"></div><br>';
602 
603  $object = new stdClass();
604  $parameters = array();
605  $reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
606  if ($reshook < 0) {
607  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
608  }
609 
610  $disabled_modules = array();
611  if (!empty($_SESSION["disablemodules"])) {
612  $disabled_modules = explode(',', $_SESSION["disablemodules"]);
613  }
614 
615  // Show list of modules
616  $oldfamily = '';
617  $foundoneexternalmodulewithupdate = 0;
618  $linenum = 0;
619  $atleastonequalified = 0;
620  $atleastoneforfamily = 0;
621 
622  foreach ($orders as $key => $value) {
623  $linenum++;
624  $tab = explode('_', $value);
625  $familykey = $tab[1];
626  $module_position = $tab[2];
627 
628  $modName = $filename[$key];
629 
631  $objMod = $modules[$modName];
632 
633  //print $objMod->name." - ".$key." - ".$objMod->version."<br>";
634  if ($mode == 'expdev' && $objMod->version != 'development' && $objMod->version != 'experimental') {
635  continue; // Discard if not for current tab
636  }
637 
638  if (!$objMod->getName()) {
639  dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
640  continue;
641  }
642 
643  $modulenameshort = strtolower(preg_replace('/^mod/i', '', get_class($objMod)));
644  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
645 
646  // Check filters
647  $modulename = $objMod->getName();
648  $moduletechnicalname = $objMod->name;
649  $moduledesc = $objMod->getDesc();
650  $moduledesclong = $objMod->getDescLong();
651  $moduleauthor = $objMod->getPublisher();
652 
653  // We discard showing according to filters
654  if ($search_keyword) {
655  $qualified = 0;
656  if (preg_match('/'.preg_quote($search_keyword, '/').'/i', $modulename)
657  || preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduletechnicalname)
658  || ($moduledesc && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesc))
659  || ($moduledesclong && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesclong))
660  || ($moduleauthor && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduleauthor))
661  ) {
662  $qualified = 1;
663  }
664  if (!$qualified) {
665  continue;
666  }
667  }
668  if ($search_status) {
669  if ($search_status == 'active' && empty($conf->global->$const_name)) {
670  continue;
671  }
672  if ($search_status == 'disabled' && !empty($conf->global->$const_name)) {
673  continue;
674  }
675  }
676  if ($search_nature) {
677  if (preg_match('/^external/', $search_nature) && $objMod->isCoreOrExternalModule() != 'external') {
678  continue;
679  }
680  $reg = array();
681  if (preg_match('/^external_(.*)$/', $search_nature, $reg)) {
682  //print $reg[1].'-'.dol_escape_htmltag($objMod->getPublisher());
683  $publisher = dol_escape_htmltag($objMod->getPublisher());
684  if ($reg[1] && dol_escape_htmltag($reg[1]) != $publisher) {
685  continue;
686  }
687  if (!$reg[1] && !empty($publisher)) {
688  continue;
689  }
690  }
691  if ($search_nature == 'core' && $objMod->isCoreOrExternalModule() == 'external') {
692  continue;
693  }
694  }
695  if ($search_version) {
696  if (($objMod->version == 'development' || $objMod->version == 'experimental' || preg_match('/deprecated/', $objMod->version)) && $search_version == 'stable') {
697  continue;
698  }
699  if ($objMod->version != 'development' && ($search_version == 'development')) {
700  continue;
701  }
702  if ($objMod->version != 'experimental' && ($search_version == 'experimental')) {
703  continue;
704  }
705  if (!preg_match('/deprecated/', $objMod->version) && ($search_version == 'deprecated')) {
706  continue;
707  }
708  }
709 
710  $atleastonequalified++;
711 
712  // Load all language files of the qualified module
713  if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
714  foreach ($objMod->langfiles as $domain) {
715  $langs->load($domain);
716  }
717  }
718 
719  // Print a separator if we change family
720  if ($familykey != $oldfamily) {
721  if ($oldfamily) {
722  print '</table></div><br>';
723  }
724 
725  $familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
726 
727  print load_fiche_titre($familytext, '', '', 0, '', 'modulefamilygroup');
728 
729  if ($mode == 'commonkanban') {
730  print '<div class="box-flex-container">';
731  } else {
732  print '<div class="div-table-responsive">';
733  print '<table class="tagtable liste" summary="list_of_modules">'."\n";
734  }
735 
736  $atleastoneforfamily = 0;
737  }
738 
739  $atleastoneforfamily++;
740 
741  if ($familykey != $oldfamily) {
742  $familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
743  $oldfamily = $familykey;
744  }
745 
746  // Version (with picto warning or not)
747  $version = $objMod->getVersion(0);
748  $versiontrans = '';
749  if (preg_match('/development/i', $version)) {
750  $versiontrans .= img_warning($langs->trans("Development"), '', 'floatleft paddingright');
751  }
752  if (preg_match('/experimental/i', $version)) {
753  $versiontrans .= img_warning($langs->trans("Experimental"), '', 'floatleft paddingright');
754  }
755  if (preg_match('/deprecated/i', $version)) {
756  $versiontrans .= img_warning($langs->trans("Deprecated"), '', 'floatleft paddingright');
757  }
758  if ($objMod->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
759  $versiontrans .= $objMod->getVersion(1);
760  }
761 
762  if ($objMod->isCoreOrExternalModule() == 'external'
763  && (
764  $action == 'checklastversion'
765  // This is a bad practice to activate a synch external access during building of a page. 1 external module can hang the application.
766  // Adding a cron job could be a good idea see DolibarrModules::checkForUpdate()
767  || !empty($conf->global->CHECKLASTVERSION_EXTERNALMODULE)
768  )
769  ) {
770  $checkRes = $objMod->checkForUpdate();
771  if ($checkRes > 0) {
772  setEventMessage($objMod->getName().' : '.$versiontrans.' -> '.$objMod->lastVersion);
773  } elseif ($checkRes < 0) {
774  setEventMessage($objMod->getName().' '.$langs->trans('CheckVersionFail'), 'warnings');
775  }
776  }
777 
778  // Define imginfo
779  $imginfo = "info";
780  if ($objMod->isCoreOrExternalModule() == 'external') {
781  $imginfo = "info_black";
782  }
783 
784  $codeenabledisable = '';
785  $codetoconfig = '';
786 
787  // Force disable of module disabled into session (for demo for example)
788  if (in_array($modulenameshort, $disabled_modules)) {
789  $objMod->disabled = true;
790  }
791 
792  // Activate/Disable and Setup (2 columns)
793  if (!empty($conf->global->$const_name)) { // If module is already activated
794  // Set $codeenabledisable
795  $disableSetup = 0;
796  if (!empty($arrayofwarnings[$modName])) {
797  $codeenabledisable .= '<!-- This module has a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\n";
798  }
799 
800  if (!empty($objMod->disabled)) {
801  $codeenabledisable .= $langs->trans("Disabled");
802  } elseif (!empty($objMod->always_enabled) || ((isModEnabled('multicompany') && $objMod->core_enabled) && ($user->entity || $conf->entity != 1))) {
803  if (method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
804  $codeenabledisable .= $langs->trans("Used");
805  } else {
806  $codeenabledisable .= img_picto($langs->trans("Required"), 'switch_on', '', false, 0, 0, '', 'opacitymedium valignmiddle');
807  //print $langs->trans("Required");
808  }
809  if (isModEnabled('multicompany') && $user->entity) {
810  $disableSetup++;
811  }
812  } else {
813  if (!empty($objMod->warnings_unactivation[$mysoc->country_code]) && method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
814  $codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reset_confirm&amp;confirm_message_code='.urlencode($objMod->warnings_unactivation[$mysoc->country_code]).'&amp;value='.$modName.'&amp;mode='.$mode.$param.'">';
815  $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
816  $codeenabledisable .= '</a>';
817  } else {
818  $codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reset&amp;value='.$modName.'&amp;mode='.$mode.'&amp;confirm=yes'.$param.'">';
819  $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
820  $codeenabledisable .= '</a>';
821  }
822  }
823 
824  // Set $codetoconfig
825  if (!empty($objMod->config_page_url) && !$disableSetup) {
826  $backtourlparam = '';
827  if ($search_keyword != '') {
828  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_keyword='.urlencode($search_keyword); // No urlencode here, done later
829  }
830  if ($search_nature > -1) {
831  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_nature='.urlencode($search_nature); // No urlencode here, done later
832  }
833  if ($search_version > -1) {
834  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_version='.urlencode($search_version); // No urlencode here, done later
835  }
836  if ($search_status > -1) {
837  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_status='.urlencode($search_status); // No urlencode here, done later
838  }
839  $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
840 
841  $regs = array();
842  if (is_array($objMod->config_page_url)) {
843  $i = 0;
844  foreach ($objMod->config_page_url as $page) {
845  $urlpage = $page;
846  if ($i++) {
847  $codetoconfig .= '<a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
848  // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
849  } else {
850  if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
851  $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
852  $codetoconfig .= '<a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
853  } else {
854  $urltouse = $urlpage;
855  $codetoconfig .= '<a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
856  }
857  }
858  }
859  } elseif (preg_match('/^([^@]+)@([^@]+)$/i', (string) $objMod->config_page_url, $regs)) {
860  $codetoconfig .= '<a class="valignmiddle" href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1).'?save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
861  } else {
862  $codetoconfig .= '<a class="valignmiddle" href="'.((string) $objMod->config_page_url).'?save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
863  }
864  } else {
865  $codetoconfig .= img_picto($langs->trans("NothingToSetup"), "setup", 'class="opacitytransp" style="padding-right: 6px"', false, 0, 0, '', 'fa-15');
866  }
867  } else { // Module not yet activated
868  // Set $codeenabledisable
869  if (!empty($objMod->always_enabled)) {
870  // Should never happened
871  } elseif (!empty($objMod->disabled)) {
872  $codeenabledisable .= $langs->trans("Disabled");
873  } else {
874  // Module qualified for activation
875  $warningmessage = '';
876  if (!empty($arrayofwarnings[$modName])) {
877  $codeenabledisable .= '<!-- This module is a core module and it may have a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\n";
878  foreach ($arrayofwarnings[$modName] as $keycountry => $cursorwarningmessage) {
879  if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
880  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code);
881  }
882  }
883  }
884  if ($objMod->isCoreOrExternalModule() == 'external' && !empty($arrayofwarningsext)) {
885  $codeenabledisable .= '<!-- This module is an external module and it may have a warning to show (note: your country is '.$mysoc->country_code.') -->'."\n";
886  foreach ($arrayofwarningsext as $keymodule => $arrayofwarningsextbycountry) {
887  $keymodulelowercase = strtolower(preg_replace('/^mod/', '', $keymodule));
888  if (in_array($keymodulelowercase, $conf->modules)) { // If module that request warning is on
889  foreach ($arrayofwarningsextbycountry as $keycountry => $cursorwarningmessage) {
890  if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
891  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code, $modules[$keymodule]->getName());
892  $warningmessage .= ($warningmessage ? "\n" : "").($warningmessage ? "\n" : "").$langs->trans("Module").' : '.$objMod->getName();
893  if (!empty($objMod->editor_name)) {
894  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("Publisher").' : '.$objMod->editor_name;
895  }
896  if (!empty($objMod->editor_name)) {
897  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("ModuleTriggeringThisWarning").' : '.$modules[$keymodule]->getName();
898  }
899  }
900  }
901  }
902  }
903  }
904  $codeenabledisable .= '<!-- Message to show: '.$warningmessage.' -->'."\n";
905  $codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=set&token='.newToken().'&value='.$modName.'&mode='.$mode.$param.'"';
906  if ($warningmessage) {
907  $codeenabledisable .= ' onclick="return confirm(\''.dol_escape_js($warningmessage).'\');"';
908  }
909  $codeenabledisable .= '>';
910  $codeenabledisable .= img_picto($langs->trans("Disabled"), 'switch_off');
911  $codeenabledisable .= "</a>\n";
912  }
913 
914  // Set $codetoconfig
915  $codetoconfig .= img_picto($langs->trans("NothingToSetup"), "setup", 'class="opacitytransp" style="padding-right: 6px"');
916  }
917 
918  if ($mode == 'commonkanban') {
919  // Output Kanban
920  print $objMod->getKanbanView($codeenabledisable, $codetoconfig);
921  } else {
922  print '<tr class="oddeven">'."\n";
923  if (!empty($conf->global->MAIN_MODULES_SHOW_LINENUMBERS)) {
924  print '<td class="width50">'.$linenum.'</td>';
925  }
926 
927  // Picto + Name of module
928  print ' <td class="tdoverflowmax300" title="'.dol_escape_htmltag($objMod->getName()).'">';
929  $alttext = '';
930  //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
931  //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
932  if (!empty($objMod->picto)) {
933  if (preg_match('/^\//i', $objMod->picto)) {
934  print img_picto($alttext, $objMod->picto, 'class="valignmiddle pictomodule paddingrightonly"', 1);
935  } else {
936  print img_object($alttext, $objMod->picto, 'class="valignmiddle pictomodule paddingrightonly"');
937  }
938  } else {
939  print img_object($alttext, 'generic', 'class="valignmiddle paddingrightonly"');
940  }
941  print ' <span class="valignmiddle">'.$objMod->getName().'</span>';
942  print "</td>\n";
943 
944  // Desc
945  print '<td class="valignmiddle tdoverflowmax300">';
946  print nl2br($objMod->getDesc());
947  print "</td>\n";
948 
949  // Help
950  print '<td class="center nowrap" style="width: 82px;">';
951  //print $form->textwithpicto('', $text, 1, $imginfo, 'minheight20', 0, 2, 1);
952  print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto(($objMod->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule").' - ' : '').$langs->trans("ClickToShowDescription"), $imginfo).'</a>';
953  print '</td>';
954 
955  // Version
956  print '<td class="center nowrap" width="120px">';
957  if ($objMod->needUpdate) {
958  $versionTitle = $langs->trans('ModuleUpdateAvailable').' : '.$objMod->lastVersion;
959  print '<span class="badge badge-warning classfortooltip" title="'.dol_escape_htmltag($versionTitle).'">'.$versiontrans.'</span>';
960  } else {
961  print $versiontrans;
962  }
963  print "</td>\n";
964 
965  // Link enable/disable
966  print '<td class="center valignmiddle" width="60px">';
967  print $codeenabledisable;
968  print "</td>\n";
969 
970  // Link config
971  print '<td class="tdsetuppicto right valignmiddle" width="60px">';
972  print $codetoconfig;
973  print '</td>';
974 
975  print "</tr>\n";
976  }
977  if ($objMod->needUpdate) {
978  $foundoneexternalmodulewithupdate++;
979  }
980  }
981 
982  if ($action == 'checklastversion') {
983  if ($foundoneexternalmodulewithupdate) {
984  setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'mesgs');
985  } else {
986  setEventMessages($langs->trans("NoExternalModuleWithUpdate"), null, 'mesgs');
987  }
988  }
989 
990  if ($oldfamily) {
991  if ($mode == 'commonkanban') {
992  print '</div>';
993  } else {
994  print "</table>\n";
995  print '</div>';
996  }
997  }
998 
999  if (!$atleastonequalified) {
1000  print '<br><span class="opacitymedium">'.$langs->trans("NoDeployedModulesFoundWithThisSearchCriteria").'</span><br><br>';
1001  }
1002 
1003  print dol_get_fiche_end();
1004 
1005  print '<br>';
1006 
1007  // Show warning about external users
1008  print info_admin(showModulesExludedForExternal($modules))."\n";
1009 
1010  print '</form>';
1011 }
1012 
1013 if ($mode == 'marketplace') {
1014  print dol_get_fiche_head($head, $mode, '', -1);
1015 
1016  print $deschelp;
1017 
1018  print '<br>';
1019 
1020  // Marketplace
1021  print '<div class="div-table-responsive-no-min">';
1022  print '<table summary="list_of_modules" class="noborder centpercent">'."\n";
1023  print '<tr class="liste_titre">'."\n";
1024  print '<td class="hideonsmartphone">'.$form->textwithpicto($langs->trans("Provider"), $langs->trans("WebSiteDesc")).'</td>';
1025  print '<td></td>';
1026  print '<td>'.$langs->trans("URL").'</td>';
1027  print '</tr>';
1028 
1029  print '<tr class="oddeven">'."\n";
1030  $url = 'https://www.dolistore.com';
1031  print '<td class="hideonsmartphone"><a href="'.$url.'" target="_blank" rel="noopener noreferrer external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolistore_logo.png"></a></td>';
1032  print '<td><span class="opacitymedium">'.$langs->trans("DoliStoreDesc").'</span></td>';
1033  print '<td><a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
1034  print '</tr>';
1035 
1036  print "</table>\n";
1037  print '</div>';
1038 
1039  print dol_get_fiche_end();
1040 
1041  print '<br>';
1042 
1043  if (empty($conf->global->MAIN_DISABLE_DOLISTORE_SEARCH) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
1044  // $options is array with filter criterias
1045  //var_dump($options);
1046  $dolistore->getRemoteCategories();
1047  $dolistore->getRemoteProducts($options);
1048 
1049  print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span><br><br>';
1050 
1051  $previouslink = $dolistore->get_previous_link();
1052  $nextlink = $dolistore->get_next_link();
1053 
1054  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1055 
1056  print '<form method="POST" class="centpercent" id="searchFormList" action="'.$dolistore->url.'">';
1057  ?>
1058  <input type="hidden" name="token" value="<?php echo newToken(); ?>">
1059  <input type="hidden" name="mode" value="marketplace">
1060  <div class="divsearchfield">
1061  <input name="search_keyword" placeholder="<?php echo $langs->trans('Keyword') ?>" id="search_keyword" type="text" class="minwidth200" value="<?php echo dol_escape_htmltag($options['search']) ?>"><br>
1062  </div>
1063  <div class="divsearchfield">
1064  <input class="button buttongen" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
1065  <a class="buttonreset" href="<?php echo urlencode($dolistore->url) ?>"><?php echo $langs->trans('Reset') ?></a>
1066 
1067  &nbsp;
1068  </div>
1069  <?php
1070  print $previouslink;
1071  print $nextlink;
1072  print '</form>';
1073 
1074 
1075  print '</div></div>';
1076  print '<div class="clearboth"></div>';
1077 
1078  ?>
1079 
1080  <div id="category-tree-left">
1081  <ul class="tree">
1082  <?php
1083  echo $dolistore->get_categories(); // Do not use dol_escape_htmltag here, it is already a structured content
1084  ?>
1085  </ul>
1086  </div>
1087  <div id="listing-content">
1088  <table summary="list_of_modules" id="list_of_modules" class="productlist centpercent">
1089  <tbody id="listOfModules">
1090  <?php echo $dolistore->get_products(); ?>
1091  </tbody>
1092  </table>
1093  </div>
1094 
1095  <?php
1096  }
1097 }
1098 
1099 
1100 // Install external module
1101 
1102 if ($mode == 'deploy') {
1103  print dol_get_fiche_head($head, $mode, '', -1);
1104 
1105  print $deschelp;
1106 
1107  $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
1108  $allowonlineinstall = true;
1109  $allowfromweb = 1;
1110  if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
1111  $allowonlineinstall = false;
1112  }
1113 
1114  $fullurl = '<a href="'.$urldolibarrmodules.'" target="_blank" rel="noopener noreferrer">'.$urldolibarrmodules.'</a>';
1115  $message = '';
1116  if ($allowonlineinstall) {
1117  if (!in_array('/custom', explode(',', $dolibarr_main_url_root_alt))) {
1118  $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
1119  $allowfromweb = -1;
1120  } else {
1121  if ($dirins_ok) {
1122  if (!is_writable(dol_osencode($dirins))) {
1123  $langs->load("errors");
1124  $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins), 0, 0, '1', 'warning');
1125  $allowfromweb = 0;
1126  }
1127  } else {
1128  $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
1129  $allowfromweb = 0;
1130  }
1131  }
1132  } else {
1133  if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
1134  // Show clean message
1135  if (!is_numeric(getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US'))) {
1136  $message = info_admin($langs->trans(getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')));
1137  } else {
1138  $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
1139  }
1140  } else {
1141  // Show technical message
1142  $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'));
1143  }
1144  $allowfromweb = 0;
1145  }
1146 
1147  if ($allowfromweb < 1) {
1148  print $langs->trans("SomethingMakeInstallFromWebNotPossible");
1149  print $message;
1150  //print $langs->trans("SomethingMakeInstallFromWebNotPossible2");
1151  print '<br>';
1152  }
1153 
1154  print '<br>';
1155 
1156  if ($allowfromweb >= 0) {
1157  if ($allowfromweb == 1) {
1158  //print $langs->trans("ThisIsProcessToFollow").'<br>';
1159  } else {
1160  print $langs->trans("ThisIsAlternativeProcessToFollow").'<br>';
1161  print '<b>'.$langs->trans("StepNb", 1).'</b>: ';
1162  print str_replace('{s1}', $fullurl, $langs->trans("FindPackageFromWebSite", '{s1}')).'<br>';
1163  print '<b>'.$langs->trans("StepNb", 2).'</b>: ';
1164  print str_replace('{s1}', $fullurl, $langs->trans("DownloadPackageFromWebSite", '{s1}')).'<br>';
1165  print '<b>'.$langs->trans("StepNb", 3).'</b>: ';
1166  }
1167 
1168  if ($allowfromweb == 1) {
1169  print '<span class="opacitymedium">'.$langs->trans("UnpackPackageInModulesRoot", $dirins).'</span><br>';
1170 
1171  print '<br>';
1172 
1173  print '<form enctype="multipart/form-data" method="POST" class="noborder" action="'.$_SERVER["PHP_SELF"].'" name="forminstall">';
1174  print '<input type="hidden" name="token" value="'.newToken().'">';
1175  print '<input type="hidden" name="action" value="install">';
1176  print '<input type="hidden" name="mode" value="deploy">';
1177 
1178  print $langs->trans("YouCanSubmitFile");
1179 
1180  $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
1181  $maxphp = @ini_get('upload_max_filesize'); // In unknown
1182  if (preg_match('/k$/i', $maxphp)) {
1183  $maxphp = preg_replace('/k$/i', '', $maxphp);
1184  $maxphp = $maxphp * 1;
1185  }
1186  if (preg_match('/m$/i', $maxphp)) {
1187  $maxphp = preg_replace('/m$/i', '', $maxphp);
1188  $maxphp = $maxphp * 1024;
1189  }
1190  if (preg_match('/g$/i', $maxphp)) {
1191  $maxphp = preg_replace('/g$/i', '', $maxphp);
1192  $maxphp = $maxphp * 1024 * 1024;
1193  }
1194  if (preg_match('/t$/i', $maxphp)) {
1195  $maxphp = preg_replace('/t$/i', '', $maxphp);
1196  $maxphp = $maxphp * 1024 * 1024 * 1024;
1197  }
1198  $maxphp2 = @ini_get('post_max_size'); // In unknown
1199  if (preg_match('/k$/i', $maxphp2)) {
1200  $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
1201  $maxphp2 = $maxphp2 * 1;
1202  }
1203  if (preg_match('/m$/i', $maxphp2)) {
1204  $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
1205  $maxphp2 = $maxphp2 * 1024;
1206  }
1207  if (preg_match('/g$/i', $maxphp2)) {
1208  $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
1209  $maxphp2 = $maxphp2 * 1024 * 1024;
1210  }
1211  if (preg_match('/t$/i', $maxphp2)) {
1212  $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
1213  $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1214  }
1215  // Now $max and $maxphp and $maxphp2 are in Kb
1216  $maxmin = $max;
1217  $maxphptoshow = $maxphptoshowparam = '';
1218  if ($maxphp > 0) {
1219  $maxmin = min($max, $maxphp);
1220  $maxphptoshow = $maxphp;
1221  $maxphptoshowparam = 'upload_max_filesize';
1222  }
1223  if ($maxphp2 > 0) {
1224  $maxmin = min($max, $maxphp2);
1225  if ($maxphp2 < $maxphp) {
1226  $maxphptoshow = $maxphp2;
1227  $maxphptoshowparam = 'post_max_size';
1228  }
1229  }
1230 
1231  if ($maxmin > 0) {
1232  print '<script type="text/javascript">
1233  $(document).ready(function() {
1234  jQuery("#fileinstall").on("change", function() {
1235  if(this.files[0].size > '.($maxmin * 1024).'){
1236  alert("'.dol_escape_js($langs->trans("ErrorFileSizeTooLarge")).'");
1237  this.value = "";
1238  };
1239  });
1240  });
1241  </script>'."\n";
1242  // MAX_FILE_SIZE doit précéder le champ input de type file
1243  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">';
1244  }
1245 
1246  print '<input class="flat minwidth400" type="file" name="fileinstall" id="fileinstall"> ';
1247 
1248  print '<input type="submit" name="send" value="'.dol_escape_htmltag($langs->trans("Upload")).'" class="button">';
1249 
1250  if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
1251  if ($user->admin) {
1252  $langs->load('other');
1253  print ' ';
1254  print info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphptoshow, $maxphptoshowparam), 1);
1255  }
1256  } else {
1257  print ' ('.$langs->trans("UploadDisabled").')';
1258  }
1259 
1260  print '</form>';
1261 
1262  print '<br>';
1263  print '<br>';
1264 
1265  print '<div class="center"><div class="logo_setup"></div></div>';
1266  } else {
1267  print $langs->trans("UnpackPackageInModulesRoot", $dirins).'<br>';
1268  print '<b>'.$langs->trans("StepNb", 4).'</b>: ';
1269  print $langs->trans("SetupIsReadyForUse").'<br>';
1270  }
1271  }
1272 
1273  if (!empty($result['return'])) {
1274  print '<br>';
1275 
1276  foreach ($result['return'] as $value) {
1277  echo $value.'<br>';
1278  }
1279  }
1280 
1281  print dol_get_fiche_end();
1282 }
1283 
1284 if ($mode == 'develop') {
1285  print dol_get_fiche_head($head, $mode, '', -1);
1286 
1287  print $deschelp;
1288 
1289  print '<br>';
1290 
1291  // Marketplace
1292  print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
1293  print "<tr class=\"liste_titre\">\n";
1294  //print '<td>'.$langs->trans("Logo").'</td>';
1295  print '<td colspan="2">'.$langs->trans("DevelopYourModuleDesc").'</td>';
1296  print '<td>'.$langs->trans("URL").'</td>';
1297  print '</tr>';
1298 
1299  print '<tr class="oddeven" height="80">'."\n";
1300  print '<td class="left">';
1301  print '<div class="imgmaxheight50 logo_setup"></div>';
1302  print '</td>';
1303  print '<td>'.$langs->trans("TryToUseTheModuleBuilder", $langs->transnoentitiesnoconv("ModuleBuilder")).'</td>';
1304  print '<td class="maxwidth300">';
1305  if (isModEnabled('modulebuilder')) {
1306  print $langs->trans("SeeTopRightMenu");
1307  } else {
1308  print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("ModuleBuilder")).'</span>';
1309  }
1310  print '</td>';
1311  print '</tr>';
1312 
1313  print '<tr class="oddeven" height="80">'."\n";
1314  $url = 'https://partners.dolibarr.org';
1315  print '<td class="left">';
1316  print'<a href="'.$url.'" target="_blank" rel="noopener noreferrer external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolibarr_preferred_partner.png"></a>';
1317  print '</td>';
1318  print '<td>'.$langs->trans("DoliPartnersDesc").'</td>';
1319  print '<td><a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
1320  print '</tr>';
1321 
1322  print "</table>\n";
1323 
1324  print dol_get_fiche_end();
1325 }
1326 
1327 // End of page
1328 llxFooter();
1329 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:632
unActivateModule($value, $requiredby=1)
Disable a module.
Definition: admin.lib.php:1220
activateModule($value, $withdeps=1)
Enable a module.
Definition: admin.lib.php:1091
modules_prepare_head($nbofactivatedmodules, $nboftotalmodules)
Prepare array with list of tabs.
Definition: admin.lib.php:703
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class Dolistore.
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1402
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1112
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
Definition: files.lib.php:2183
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:481
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
Definition: files.lib.php:773
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:451
dolGetModulesDirs($subdir='')
Return list of modules directories.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
document_preview(file, type, title)
Function show document preview.
$formconfirm
if ($action == 'delbookkeepingyear') {
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
Definition: style.css.php:843
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.