dolibarr  x.y.z
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 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'] = ((int) (GETPOST('categorie', 'int') ? GETPOST('categorie', 'int') : 0));
69 $options['start'] = ((int) (GETPOST('start', 'int') ?GETPOST('start', 'int') : 0));
70 $options['end'] = ((int) (GETPOST('end', 'int') ?GETPOST('end', 'int') : 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  $modulenamearrays = array();
209  if (dol_is_file($modulenamedir.'/metapackage.conf')) {
210  // This is a meta package
211  $metafile = file_get_contents($modulenamedir.'/metapackage.conf');
212  $modulenamearrays = explode("\n", $metafile);
213  }
214  $modulenamearrays[$modulename] = $modulename;
215  //var_dump($modulenamearrays);exit;
216 
217  foreach ($modulenamearrays as $modulenameval) {
218  if (strpos($modulenameval, '#') === 0) {
219  continue; // Discard comments
220  }
221  if (strpos($modulenameval, '//') === 0) {
222  continue; // Discard comments
223  }
224  if (!trim($modulenameval)) {
225  continue;
226  }
227 
228  // Now we install the module
229  if (!$error) {
230  @dol_delete_dir_recursive($dirins.'/'.$modulenameval); // delete the zip file
231  dol_syslog("We copy now directory ".$conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulenameval." into target dir ".$dirins.'/'.$modulenameval);
232  $result = dolCopyDir($modulenamedir, $dirins.'/'.$modulenameval, '0444', 1);
233  if ($result <= 0) {
234  dol_syslog('Failed to call dolCopyDir result='.$result." with param ".$modulenamedir." and ".$dirins.'/'.$modulenameval, LOG_WARNING);
235  $langs->load("errors");
236  setEventMessages($langs->trans("ErrorFailToCopyDir", $modulenamedir, $dirins.'/'.$modulenameval), null, 'errors');
237  $error++;
238  }
239  }
240  }
241  }
242  } else {
243  setEventMessages($langs->trans("ErrorFailToRenameFile", $_FILES['fileinstall']['tmp_name'], $newfile), null, 'errors');
244  $error++;
245  }
246  }
247 
248  if (!$error) {
249  setEventMessages($langs->trans("SetupIsReadyForUse", DOL_URL_ROOT.'/admin/modules.php?mainmenu=home', $langs->transnoentitiesnoconv("Home").' - '.$langs->transnoentitiesnoconv("Setup").' - '.$langs->transnoentitiesnoconv("Modules")), null, 'warnings');
250  }
251 }
252 
253 if ($action == 'set' && $user->admin) {
254  $resarray = activateModule($value);
255  dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
256  if (!empty($resarray['errors'])) {
257  setEventMessages('', $resarray['errors'], 'errors');
258  } else {
259  //var_dump($resarray);exit;
260  if ($resarray['nbperms'] > 0) {
261  $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
262  $resqltmp = $db->query($tmpsql);
263  if ($resqltmp) {
264  $obj = $db->fetch_object($resqltmp);
265  //var_dump($obj->nb);exit;
266  if ($obj && $obj->nb > 1) {
267  $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
268  setEventMessages($msg, null, 'warnings');
269  }
270  } else {
271  dol_print_error($db);
272  }
273  }
274  }
275  header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
276  exit;
277 } elseif ($action == 'reset' && $user->admin && GETPOST('confirm') == 'yes') {
278  $result = unActivateModule($value);
279  dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
280  if ($result) {
281  setEventMessages($result, null, 'errors');
282  }
283  header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
284  exit;
285 }
286 
287 
288 
289 /*
290  * View
291  */
292 
293 $form = new Form($db);
294 
295 $morejs = array();
296 $morecss = array("/admin/dolistore/css/dolistore.css");
297 
298 // Set dir where external modules are installed
299 if (!dol_is_dir($dirins)) {
300  dol_mkdir($dirins);
301 }
302 $dirins_ok = (dol_is_dir($dirins));
303 
304 $help_url = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
305 llxHeader('', $langs->trans("Setup"), $help_url, '', '', '', $morejs, $morecss, 0, 0);
306 
307 
308 // Search modules dirs
309 $modulesdir = dolGetModulesDirs();
310 
311 $arrayofnatures = array('core'=>$langs->transnoentitiesnoconv("NativeModules"), 'external'=>$langs->transnoentitiesnoconv("External").' - ['.$langs->trans("AllPublishers").']');
312 $arrayofwarnings = array(); // Array of warning each module want to show when activated
313 $arrayofwarningsext = array(); // Array of warning each module want to show when we activate an external module
314 $filename = array();
315 $modules = array();
316 $orders = array();
317 $categ = array();
318 
319 $i = 0; // is a sequencer of modules found
320 $j = 0; // j is module number. Automatically affected if module number not defined.
321 $modNameLoaded = array();
322 
323 foreach ($modulesdir as $dir) {
324  // Load modules attributes in arrays (name, numero, orders) from dir directory
325  //print $dir."\n<br>";
326  dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
327  $handle = @opendir($dir);
328  if (is_resource($handle)) {
329  while (($file = readdir($handle)) !== false) {
330  //print "$i ".$file."\n<br>";
331  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
332  $modName = substr($file, 0, dol_strlen($file) - 10);
333 
334  if ($modName) {
335  if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
336  $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
337  setEventMessages($mesg, null, 'warnings');
338  dol_syslog($mesg, LOG_ERR);
339  continue;
340  }
341 
342  try {
343  $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
344  if (class_exists($modName)) {
345  try {
346  $objMod = new $modName($db);
347  $modNameLoaded[$modName] = $dir;
348  if (!$objMod->numero > 0 && $modName != 'modUser') {
349  dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR);
350  }
351  $j = $objMod->numero;
352 
353  $modulequalified = 1;
354 
355  // We discard modules according to features level (PS: if module is activated we always show it)
356  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
357  if ($objMod->version == 'development' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 2))) {
358  $modulequalified = 0;
359  }
360  if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) {
361  $modulequalified = 0;
362  }
363  if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) {
364  $modulequalified = 0;
365  }
366 
367  // We discard modules according to property ->hidden
368  if (!empty($objMod->hidden)) {
369  $modulequalified = 0;
370  }
371 
372  if ($modulequalified > 0) {
373  $publisher = dol_escape_htmltag($objMod->getPublisher());
374  $external = ($objMod->isCoreOrExternalModule() == 'external');
375  if ($external) {
376  if ($publisher) {
377  $arrayofnatures['external_'.$publisher] = $langs->trans("External").' - '.$publisher;
378  } else {
379  $arrayofnatures['external_'] = $langs->trans("External").' - '.$langs->trans("UnknownPublishers");
380  }
381  }
382  ksort($arrayofnatures);
383 
384  // Define array $categ with categ with at least one qualified module
385  $filename[$i] = $modName;
386  $modules[$modName] = $objMod;
387 
388  // Gives the possibility to the module, to provide his own family info and position of this family
389  if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) {
390  $familyinfo = array_merge($familyinfo, $objMod->familyinfo);
391  $familykey = key($objMod->familyinfo);
392  } else {
393  $familykey = $objMod->family;
394  }
395 
396  $moduleposition = ($objMod->module_position ? $objMod->module_position : '50');
397  if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) {
398  // an external module should never return a value lower than '80'.
399  $moduleposition = '80'; // External modules at end by default
400  }
401 
402  // Add list of warnings to show into arrayofwarnings and arrayofwarningsext
403  if (!empty($objMod->warnings_activation)) {
404  $arrayofwarnings[$modName] = $objMod->warnings_activation;
405  }
406  if (!empty($objMod->warnings_activation_ext)) {
407  $arrayofwarningsext[$modName] = $objMod->warnings_activation_ext;
408  }
409 
410  $familyposition = (empty($familyinfo[$familykey]['position']) ? 0 : $familyinfo[$familykey]['position']);
411  $listOfOfficialModuleGroups = array('hr', 'technic', 'interface', 'technic', 'portal', 'financial', 'crm', 'base', 'products', 'srm', 'ecm', 'projects', 'other');
412  if ($external && !in_array($familykey, $listOfOfficialModuleGroups)) {
413  // 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).
414  if (is_numeric($familyposition)) {
415  $familyposition = sprintf("%03d", (int) $familyposition + 100);
416  }
417  }
418 
419  $orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
420 
421  // Set categ[$i]
422  $specialstring = 'unknown';
423  if ($objMod->version == 'development' || $objMod->version == 'experimental') {
424  $specialstring = 'expdev';
425  }
426  if (isset($categ[$specialstring])) {
427  $categ[$specialstring]++; // Array of all different modules categories
428  } else {
429  $categ[$specialstring] = 1;
430  }
431  $j++;
432  $i++;
433  } else {
434  dol_syslog("Module ".get_class($objMod)." not qualified");
435  }
436  } catch (Exception $e) {
437  dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
438  }
439  } else {
440  print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)<br>";
441  }
442  } catch (Exception $e) {
443  dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
444  }
445  }
446  }
447  }
448  closedir($handle);
449  } else {
450  dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
451  }
452 }
453 
454 if ($action == 'reset_confirm' && $user->admin) {
455  if (!empty($modules[$value])) {
456  $objMod = $modules[$value];
457 
458  if (!empty($objMod->langfiles)) {
459  $langs->loadLangs($objMod->langfiles);
460  }
461 
462  $form = new Form($db);
463  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmUnactivation'), $langs->trans(GETPOST('confirm_message_code')), 'reset', '', 'no', 1);
464  }
465 }
466 
467 print $formconfirm;
468 
469 asort($orders);
470 //var_dump($orders);
471 //var_dump($categ);
472 //var_dump($modules);
473 
474 $nbofactivatedmodules = count($conf->modules);
475 
476 //$conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING = 1000;
477 /*$moreinfo = $langs->trans("TitleNumberOfActivatedModules");
478 $moreinfo2 = '<b class="largenumber">'.($nbofactivatedmodules - 1).'</b> / <b class="largenumber">'.count($modules).'</b>';
479 if ($nbofactivatedmodules <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) {
480  $moreinfo2 .= ' '.img_warning($langs->trans("YouMustEnableOneModule"));
481 }*/
482 
483 print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup');
484 
485 // Start to show page
486 $deschelp = '';
487 if ($mode == 'common' || $mode == 'commonkanban') {
488  $desc = $langs->trans("ModulesDesc", '{picto}');
489  $desc .= ' '.$langs->trans("ModulesDesc2", '{picto2}');
490  $desc = str_replace('{picto}', img_picto('', 'switch_off', 'class="size15x"'), $desc);
491  $desc = str_replace('{picto2}', img_picto('', 'setup', 'class="size15x"'), $desc);
492  if (!count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only minimal initial modules enabled
493  $deschelp = '<div class="info hideonsmartphone">'.$desc."<br></div><br>\n";
494  }
495 }
496 if ($mode == 'marketplace') {
497  //$deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesMarketPlaceDesc")."<br></div><br>\n";
498 }
499 if ($mode == 'deploy') {
500  $deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."<br></div><br>\n";
501 }
502 if ($mode == 'develop') {
503  $deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDevelopDesc")."<br></div><br>\n";
504 }
505 
506 $head = modules_prepare_head($nbofactivatedmodules, count($modules));
507 
508 
509 if ($mode == 'common' || $mode == 'commonkanban') {
510  dol_set_focus('#search_keyword');
511 
512  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
513  print '<input type="hidden" name="token" value="'.newToken().'">';
514  if (isset($optioncss) && $optioncss != '') {
515  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
516  }
517  if (isset($sortfield) && $sortfield != '') {
518  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
519  }
520  if (isset($sortorder) && $sortorder != '') {
521  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
522  }
523  if (isset($page) && $page != '') {
524  print '<input type="hidden" name="page" value="'.$page.'">';
525  }
526  print '<input type="hidden" name="mode" value="'.$mode.'">';
527 
528  print dol_get_fiche_head($head, 'modules', '', -1);
529 
530  print $deschelp;
531 
532  $moreforfilter = '<div class="valignmiddle">';
533 
534  $moreforfilter .= '<div class="floatright right pagination paddingtop --module-list"><ul><li>';
535  $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'));
536  $moreforfilter .= dolGetButtonTitleSeparator();
537  $moreforfilter .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.$param, '', ($mode == 'common' ? 2 : 1), array('morecss'=>'reposition'));
538  $moreforfilter .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=commonkanban'.$param, '', ($mode == 'commonkanban' ? 2 : 1), array('morecss'=>'reposition'));
539  $moreforfilter .= '</li></ul></div>';
540 
541  //$moreforfilter .= '<div class="floatright center marginrightonly hideonsmartphone" style="padding-top: 3px"><span class="paddingright">'.$moreinfo.'</span> '.$moreinfo2.'</div>';
542 
543  $moreforfilter .= '<div class="divfilteralone colorbacktimesheet float valignmiddle">';
544  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
545  $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')).'">';
546  $moreforfilter .= '</div>';
547  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
548  $moreforfilter .= $form->selectarray('search_nature', $arrayofnatures, dol_escape_htmltag($search_nature), $langs->trans('Origin'), 0, 0, '', 0, 0, 0, '', 'maxwidth250', 1);
549  $moreforfilter .= '</div>';
550  if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
551  $array_version = array('stable'=>$langs->transnoentitiesnoconv("Stable"));
552  if ($conf->global->MAIN_FEATURES_LEVEL < 0) {
553  $array_version['deprecated'] = $langs->trans("Deprecated");
554  }
555  if ($conf->global->MAIN_FEATURES_LEVEL > 0) {
556  $array_version['experimental'] = $langs->trans("Experimental");
557  }
558  if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
559  $array_version['development'] = $langs->trans("Development");
560  }
561  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
562  $moreforfilter .= $form->selectarray('search_version', $array_version, $search_version, $langs->trans('Version'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
563  $moreforfilter .= '</div>';
564  }
565  $moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
566  $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);
567  $moreforfilter .= '</div>';
568  $moreforfilter .= ' ';
569  $moreforfilter .= '<div class="divsearchfield valignmiddle inline-block">';
570  $moreforfilter .= '<input type="submit" name="buttonsubmit" class="button small" value="'.dol_escape_htmltag($langs->trans("Refresh")).'">';
571  if ($search_keyword || ($search_nature && $search_nature != '-1') || ($search_version && $search_version != '-1') || ($search_status && $search_status != '-1')) {
572  $moreforfilter .= ' ';
573  $moreforfilter .= '<input type="submit" name="buttonreset" class="buttonreset noborderbottom" value="'.dol_escape_htmltag($langs->trans("Reset")).'">';
574  }
575  $moreforfilter .= '</div>';
576  $moreforfilter .= '</div>';
577 
578  $moreforfilter .= '</div>';
579 
580  if (!empty($moreforfilter)) {
581  print $moreforfilter;
582  $parameters = array();
583  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
584  print $hookmanager->resPrint;
585  }
586 
587  $moreforfilter = '';
588 
589  print '<div class="clearboth"></div><br>';
590 
591  $object = new stdClass();
592  $parameters = array();
593  $reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
594  if ($reshook < 0) {
595  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
596  }
597 
598  $disabled_modules = array();
599  if (!empty($_SESSION["disablemodules"])) {
600  $disabled_modules = explode(',', $_SESSION["disablemodules"]);
601  }
602 
603  // Show list of modules
604  $oldfamily = '';
605  $foundoneexternalmodulewithupdate = 0;
606  $linenum = 0;
607  $atleastonequalified = 0;
608  $atleastoneforfamily = 0;
609 
610  foreach ($orders as $key => $value) {
611  $linenum++;
612  $tab = explode('_', $value);
613  $familykey = $tab[1];
614  $module_position = $tab[2];
615 
616  $modName = $filename[$key];
617 
619  $objMod = $modules[$modName];
620 
621  //print $objMod->name." - ".$key." - ".$objMod->version."<br>";
622  if ($mode == 'expdev' && $objMod->version != 'development' && $objMod->version != 'experimental') {
623  continue; // Discard if not for current tab
624  }
625 
626  if (!$objMod->getName()) {
627  dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
628  continue;
629  }
630 
631  $modulenameshort = strtolower(preg_replace('/^mod/i', '', get_class($objMod)));
632  $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
633 
634  // Check filters
635  $modulename = $objMod->getName();
636  $moduletechnicalname = $objMod->name;
637  $moduledesc = $objMod->getDesc();
638  $moduledesclong = $objMod->getDescLong();
639  $moduleauthor = $objMod->getPublisher();
640 
641  // We discard showing according to filters
642  if ($search_keyword) {
643  $qualified = 0;
644  if (preg_match('/'.preg_quote($search_keyword, '/').'/i', $modulename)
645  || preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduletechnicalname)
646  || ($moduledesc && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesc))
647  || ($moduledesclong && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesclong))
648  || ($moduleauthor && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduleauthor))
649  ) {
650  $qualified = 1;
651  }
652  if (!$qualified) {
653  continue;
654  }
655  }
656  if ($search_status) {
657  if ($search_status == 'active' && empty($conf->global->$const_name)) {
658  continue;
659  }
660  if ($search_status == 'disabled' && !empty($conf->global->$const_name)) {
661  continue;
662  }
663  }
664  if ($search_nature) {
665  if (preg_match('/^external/', $search_nature) && $objMod->isCoreOrExternalModule() != 'external') {
666  continue;
667  }
668  $reg = array();
669  if (preg_match('/^external_(.*)$/', $search_nature, $reg)) {
670  //print $reg[1].'-'.dol_escape_htmltag($objMod->getPublisher());
671  $publisher = dol_escape_htmltag($objMod->getPublisher());
672  if ($reg[1] && dol_escape_htmltag($reg[1]) != $publisher) {
673  continue;
674  }
675  if (!$reg[1] && !empty($publisher)) {
676  continue;
677  }
678  }
679  if ($search_nature == 'core' && $objMod->isCoreOrExternalModule() == 'external') {
680  continue;
681  }
682  }
683  if ($search_version) {
684  if (($objMod->version == 'development' || $objMod->version == 'experimental' || preg_match('/deprecated/', $objMod->version)) && $search_version == 'stable') {
685  continue;
686  }
687  if ($objMod->version != 'development' && ($search_version == 'development')) {
688  continue;
689  }
690  if ($objMod->version != 'experimental' && ($search_version == 'experimental')) {
691  continue;
692  }
693  if (!preg_match('/deprecated/', $objMod->version) && ($search_version == 'deprecated')) {
694  continue;
695  }
696  }
697 
698  $atleastonequalified++;
699 
700  // Load all language files of the qualified module
701  if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
702  foreach ($objMod->langfiles as $domain) {
703  $langs->load($domain);
704  }
705  }
706 
707  // Print a separator if we change family
708  if ($familykey != $oldfamily) {
709  if ($oldfamily) {
710  print '</table></div><br>';
711  }
712 
713  $familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
714 
715  print load_fiche_titre($familytext, '', '', 0, '', 'modulefamilygroup');
716 
717  if ($mode == 'commonkanban') {
718  print '<div class="box-flex-container">';
719  } else {
720  print '<div class="div-table-responsive">';
721  print '<table class="tagtable liste" summary="list_of_modules">'."\n";
722  }
723 
724  $atleastoneforfamily = 0;
725  }
726 
727  $atleastoneforfamily++;
728 
729  if ($familykey != $oldfamily) {
730  $familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
731  $oldfamily = $familykey;
732  }
733 
734  // Version (with picto warning or not)
735  $version = $objMod->getVersion(0);
736  $versiontrans = '';
737  if (preg_match('/development/i', $version)) {
738  $versiontrans .= img_warning($langs->trans("Development"), '', 'floatleft paddingright');
739  }
740  if (preg_match('/experimental/i', $version)) {
741  $versiontrans .= img_warning($langs->trans("Experimental"), '', 'floatleft paddingright');
742  }
743  if (preg_match('/deprecated/i', $version)) {
744  $versiontrans .= img_warning($langs->trans("Deprecated"), '', 'floatleft paddingright');
745  }
746  if ($objMod->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
747  $versiontrans .= $objMod->getVersion(1);
748  }
749 
750  if ($objMod->isCoreOrExternalModule() == 'external'
751  && (
752  $action == 'checklastversion'
753  // This is a bad practice to activate a synch external access during building of a page. 1 external module can hang the application.
754  // Adding a cron job could be a good idea see DolibarrModules::checkForUpdate()
755  || !empty($conf->global->CHECKLASTVERSION_EXTERNALMODULE)
756  )
757  ) {
758  $checkRes = $objMod->checkForUpdate();
759  if ($checkRes > 0) {
760  setEventMessage($objMod->getName().' : '.$versiontrans.' -> '.$objMod->lastVersion);
761  } elseif ($checkRes < 0) {
762  setEventMessage($objMod->getName().' '.$langs->trans('CheckVersionFail'), 'warnings');
763  }
764  }
765 
766  // Define imginfo
767  $imginfo = "info";
768  if ($objMod->isCoreOrExternalModule() == 'external') {
769  $imginfo = "info_black";
770  }
771 
772  $codeenabledisable = '';
773  $codetoconfig = '';
774 
775  // Force disable of module disabled into session (for demo for example)
776  if (in_array($modulenameshort, $disabled_modules)) {
777  $objMod->disabled = true;
778  }
779 
780  // Activate/Disable and Setup (2 columns)
781  if (!empty($conf->global->$const_name)) { // If module is already activated
782  // Set $codeenabledisable
783  $disableSetup = 0;
784  if (!empty($arrayofwarnings[$modName])) {
785  $codeenabledisable .= '<!-- This module has a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\n";
786  }
787 
788  if (!empty($objMod->disabled)) {
789  $codeenabledisable .= $langs->trans("Disabled");
790  } elseif (!empty($objMod->always_enabled) || ((isModEnabled('multicompany') && $objMod->core_enabled) && ($user->entity || $conf->entity != 1))) {
791  if (method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
792  $codeenabledisable .= $langs->trans("Used");
793  } else {
794  $codeenabledisable .= img_picto($langs->trans("Required"), 'switch_on', '', false, 0, 0, '', 'opacitymedium valignmiddle');
795  //print $langs->trans("Required");
796  }
797  if (isModEnabled('multicompany') && $user->entity) {
798  $disableSetup++;
799  }
800  } else {
801  if (!empty($objMod->warnings_unactivation[$mysoc->country_code]) && method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
802  $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.'">';
803  $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
804  $codeenabledisable .= '</a>';
805  } else {
806  $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.'">';
807  $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
808  $codeenabledisable .= '</a>';
809  }
810  }
811 
812  // Set $codetoconfig
813  if (!empty($objMod->config_page_url) && !$disableSetup) {
814  $backtourlparam = '';
815  if ($search_keyword != '') {
816  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_keyword='.urlencode($search_keyword); // No urlencode here, done later
817  }
818  if ($search_nature > -1) {
819  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_nature='.urlencode($search_nature); // No urlencode here, done later
820  }
821  if ($search_version > -1) {
822  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_version='.urlencode($search_version); // No urlencode here, done later
823  }
824  if ($search_status > -1) {
825  $backtourlparam .= ($backtourlparam ? '&' : '?').'search_status='.urlencode($search_status); // No urlencode here, done later
826  }
827  $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
828 
829  $regs = array();
830  if (is_array($objMod->config_page_url)) {
831  $i = 0;
832  foreach ($objMod->config_page_url as $page) {
833  $urlpage = $page;
834  if ($i++) {
835  $codetoconfig .= '<a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
836  // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
837  } else {
838  if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
839  $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
840  $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>';
841  } else {
842  $urltouse = $urlpage;
843  $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>';
844  }
845  }
846  }
847  } elseif (preg_match('/^([^@]+)@([^@]+)$/i', (string) $objMod->config_page_url, $regs)) {
848  $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>';
849  } else {
850  $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>';
851  }
852  } else {
853  $codetoconfig .= img_picto($langs->trans("NothingToSetup"), "setup", 'class="opacitytransp" style="padding-right: 6px"', false, 0, 0, '', 'fa-15');
854  }
855  } else { // Module not yet activated
856  // Set $codeenabledisable
857  if (!empty($objMod->always_enabled)) {
858  // Should never happened
859  } elseif (!empty($objMod->disabled)) {
860  $codeenabledisable .= $langs->trans("Disabled");
861  } else {
862  // Module qualified for activation
863  $warningmessage = '';
864  if (!empty($arrayofwarnings[$modName])) {
865  $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";
866  foreach ($arrayofwarnings[$modName] as $keycountry => $cursorwarningmessage) {
867  if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
868  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code);
869  }
870  }
871  }
872  if ($objMod->isCoreOrExternalModule() == 'external' && !empty($arrayofwarningsext)) {
873  $codeenabledisable .= '<!-- This module is an external module and it may have a warning to show (note: your country is '.$mysoc->country_code.') -->'."\n";
874  foreach ($arrayofwarningsext as $keymodule => $arrayofwarningsextbycountry) {
875  $keymodulelowercase = strtolower(preg_replace('/^mod/', '', $keymodule));
876  if (in_array($keymodulelowercase, $conf->modules)) { // If module that request warning is on
877  foreach ($arrayofwarningsextbycountry as $keycountry => $cursorwarningmessage) {
878  if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
879  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code, $modules[$keymodule]->getName());
880  $warningmessage .= ($warningmessage ? "\n" : "").($warningmessage ? "\n" : "").$langs->trans("Module").' : '.$objMod->getName();
881  if (!empty($objMod->editor_name)) {
882  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("Publisher").' : '.$objMod->editor_name;
883  }
884  if (!empty($objMod->editor_name)) {
885  $warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("ModuleTriggeringThisWarning").' : '.$modules[$keymodule]->getName();
886  }
887  }
888  }
889  }
890  }
891  }
892  $codeenabledisable .= '<!-- Message to show: '.$warningmessage.' -->'."\n";
893  $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.'"';
894  if ($warningmessage) {
895  $codeenabledisable .= ' onclick="return confirm(\''.dol_escape_js($warningmessage).'\');"';
896  }
897  $codeenabledisable .= '>';
898  $codeenabledisable .= img_picto($langs->trans("Disabled"), 'switch_off');
899  $codeenabledisable .= "</a>\n";
900  }
901 
902  // Set $codetoconfig
903  $codetoconfig .= img_picto($langs->trans("NothingToSetup"), "setup", 'class="opacitytransp" style="padding-right: 6px"');
904  }
905 
906  if ($mode == 'commonkanban') {
907  // Output Kanban
908  print $objMod->getKanbanView($codeenabledisable, $codetoconfig);
909  } else {
910  print '<tr class="oddeven">'."\n";
911  if (!empty($conf->global->MAIN_MODULES_SHOW_LINENUMBERS)) {
912  print '<td class="width50">'.$linenum.'</td>';
913  }
914 
915  // Picto + Name of module
916  print ' <td class="tdoverflowmax300" title="'.dol_escape_htmltag($objMod->getName()).'">';
917  $alttext = '';
918  //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
919  //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
920  if (!empty($objMod->picto)) {
921  if (preg_match('/^\//i', $objMod->picto)) {
922  print img_picto($alttext, $objMod->picto, 'class="valignmiddle pictomodule paddingrightonly"', 1);
923  } else {
924  print img_object($alttext, $objMod->picto, 'class="valignmiddle pictomodule paddingrightonly"');
925  }
926  } else {
927  print img_object($alttext, 'generic', 'class="valignmiddle paddingrightonly"');
928  }
929  print ' <span class="valignmiddle">'.$objMod->getName().'</span>';
930  print "</td>\n";
931 
932  // Desc
933  print '<td class="valignmiddle tdoverflowmax300">';
934  print nl2br($objMod->getDesc());
935  print "</td>\n";
936 
937  // Help
938  print '<td class="center nowrap" style="width: 82px;">';
939  //print $form->textwithpicto('', $text, 1, $imginfo, 'minheight20', 0, 2, 1);
940  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>';
941  print '</td>';
942 
943  // Version
944  print '<td class="center nowrap" width="120px">';
945  if ($objMod->needUpdate) {
946  $versionTitle = $langs->trans('ModuleUpdateAvailable').' : '.$objMod->lastVersion;
947  print '<span class="badge badge-warning classfortooltip" title="'.dol_escape_htmltag($versionTitle).'">'.$versiontrans.'</span>';
948  } else {
949  print $versiontrans;
950  }
951  print "</td>\n";
952 
953  // Link enable/disable
954  print '<td class="center valignmiddle" width="60px">';
955  print $codeenabledisable;
956  print "</td>\n";
957 
958  // Link config
959  print '<td class="tdsetuppicto right valignmiddle" width="60px">';
960  print $codetoconfig;
961  print '</td>';
962 
963  print "</tr>\n";
964  }
965  if ($objMod->needUpdate) {
966  $foundoneexternalmodulewithupdate++;
967  }
968  }
969 
970  if ($action == 'checklastversion') {
971  if ($foundoneexternalmodulewithupdate) {
972  setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'mesgs');
973  } else {
974  setEventMessages($langs->trans("NoExternalModuleWithUpdate"), null, 'mesgs');
975  }
976  }
977 
978  if ($oldfamily) {
979  if ($mode == 'commonkanban') {
980  print '</div>';
981  } else {
982  print "</table>\n";
983  print '</div>';
984  }
985  }
986 
987  if (!$atleastonequalified) {
988  print '<br><span class="opacitymedium">'.$langs->trans("NoDeployedModulesFoundWithThisSearchCriteria").'</span><br><br>';
989  }
990 
991  print dol_get_fiche_end();
992 
993  print '<br>';
994 
995  // Show warning about external users
996  print info_admin(showModulesExludedForExternal($modules))."\n";
997 
998  print '</form>';
999 }
1000 
1001 if ($mode == 'marketplace') {
1002  print dol_get_fiche_head($head, $mode, '', -1);
1003 
1004  print $deschelp;
1005 
1006  print '<br>';
1007 
1008  // Marketplace
1009  print '<div class="div-table-responsive-no-min">';
1010  print '<table summary="list_of_modules" class="noborder centpercent">'."\n";
1011  print '<tr class="liste_titre">'."\n";
1012  print '<td class="hideonsmartphone">'.$form->textwithpicto($langs->trans("Provider"), $langs->trans("WebSiteDesc")).'</td>';
1013  print '<td></td>';
1014  print '<td>'.$langs->trans("URL").'</td>';
1015  print '</tr>';
1016 
1017  print '<tr class="oddeven">'."\n";
1018  $url = 'https://www.dolistore.com';
1019  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>';
1020  print '<td><span class="opacitymedium">'.$langs->trans("DoliStoreDesc").'</span></td>';
1021  print '<td><a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
1022  print '</tr>';
1023 
1024  print "</table>\n";
1025  print '</div>';
1026 
1027  print dol_get_fiche_end();
1028 
1029  print '<br>';
1030 
1031  if (empty($conf->global->MAIN_DISABLE_DOLISTORE_SEARCH) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
1032  // $options is array with filter criterias
1033  //var_dump($options);
1034  $dolistore->getRemoteCategories();
1035  $dolistore->getRemoteProducts($options);
1036 
1037  print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span><br><br>';
1038 
1039  $previouslink = $dolistore->get_previous_link();
1040  $nextlink = $dolistore->get_next_link();
1041 
1042  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1043 
1044  print '<form method="POST" class="centpercent" id="searchFormList" action="'.urlencode($dolistore->url).'">';
1045  ?>
1046  <input type="hidden" name="token" value="<?php echo newToken(); ?>">
1047  <input type="hidden" name="mode" value="marketplace">
1048  <div class="divsearchfield">
1049  <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>
1050  </div>
1051  <div class="divsearchfield">
1052  <input class="button buttongen" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
1053  <a class="buttonreset" href="<?php echo urlencode($dolistore->url) ?>"><?php echo $langs->trans('Reset') ?></a>
1054 
1055  &nbsp;
1056  </div>
1057  <?php
1058  print $previouslink;
1059  print $nextlink;
1060  print '</form>';
1061 
1062 
1063  print '</div></div>';
1064  print '<div class="clearboth"></div>';
1065 
1066  ?>
1067 
1068  <div id="category-tree-left">
1069  <ul class="tree">
1070  <?php
1071  echo $dolistore->get_categories(); // Do not use dol_escape_htmltag here, it is already a structured content
1072  ?>
1073  </ul>
1074  </div>
1075  <div id="listing-content">
1076  <table summary="list_of_modules" id="list_of_modules" class="productlist centpercent">
1077  <tbody id="listOfModules">
1078  <?php echo $dolistore->get_products(); ?>
1079  </tbody>
1080  </table>
1081  </div>
1082 
1083  <?php
1084  }
1085 }
1086 
1087 
1088 // Install external module
1089 
1090 if ($mode == 'deploy') {
1091  print dol_get_fiche_head($head, $mode, '', -1);
1092 
1093  print $deschelp;
1094 
1095  $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
1096  $allowonlineinstall = true;
1097  $allowfromweb = 1;
1098  if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
1099  $allowonlineinstall = false;
1100  }
1101 
1102  $fullurl = '<a href="'.$urldolibarrmodules.'" target="_blank" rel="noopener noreferrer">'.$urldolibarrmodules.'</a>';
1103  $message = '';
1104  if (!empty($allowonlineinstall)) {
1105  if (!in_array('/custom', explode(',', $dolibarr_main_url_root_alt))) {
1106  $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
1107  $allowfromweb = -1;
1108  } else {
1109  if ($dirins_ok) {
1110  if (!is_writable(dol_osencode($dirins))) {
1111  $langs->load("errors");
1112  $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins), 0, 0, '1', 'warning');
1113  $allowfromweb = 0;
1114  }
1115  } else {
1116  $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
1117  $allowfromweb = 0;
1118  }
1119  }
1120  } else {
1121  if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
1122  // Show clean message
1123  $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
1124  } else {
1125  // Show technical message
1126  $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'));
1127  }
1128  $allowfromweb = 0;
1129  }
1130 
1131  if ($allowfromweb < 1) {
1132  print $langs->trans("SomethingMakeInstallFromWebNotPossible");
1133  print $message;
1134  //print $langs->trans("SomethingMakeInstallFromWebNotPossible2");
1135  print '<br>';
1136  }
1137 
1138  print '<br>';
1139 
1140  if ($allowfromweb >= 0) {
1141  if ($allowfromweb == 1) {
1142  //print $langs->trans("ThisIsProcessToFollow").'<br>';
1143  } else {
1144  print $langs->trans("ThisIsAlternativeProcessToFollow").'<br>';
1145  print '<b>'.$langs->trans("StepNb", 1).'</b>: ';
1146  print str_replace('{s1}', $fullurl, $langs->trans("FindPackageFromWebSite", '{s1}')).'<br>';
1147  print '<b>'.$langs->trans("StepNb", 2).'</b>: ';
1148  print str_replace('{s1}', $fullurl, $langs->trans("DownloadPackageFromWebSite", '{s1}')).'<br>';
1149  print '<b>'.$langs->trans("StepNb", 3).'</b>: ';
1150  }
1151 
1152  if ($allowfromweb == 1) {
1153  print '<span class="opacitymedium">'.$langs->trans("UnpackPackageInModulesRoot", $dirins).'</span><br>';
1154 
1155  print '<br>';
1156 
1157  print '<form enctype="multipart/form-data" method="POST" class="noborder" action="'.$_SERVER["PHP_SELF"].'" name="forminstall">';
1158  print '<input type="hidden" name="token" value="'.newToken().'">';
1159  print '<input type="hidden" name="action" value="install">';
1160  print '<input type="hidden" name="mode" value="deploy">';
1161 
1162  print $langs->trans("YouCanSubmitFile");
1163 
1164  $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
1165  $maxphp = @ini_get('upload_max_filesize'); // In unknown
1166  if (preg_match('/k$/i', $maxphp)) {
1167  $maxphp = preg_replace('/k$/i', '', $maxphp);
1168  $maxphp = $maxphp * 1;
1169  }
1170  if (preg_match('/m$/i', $maxphp)) {
1171  $maxphp = preg_replace('/m$/i', '', $maxphp);
1172  $maxphp = $maxphp * 1024;
1173  }
1174  if (preg_match('/g$/i', $maxphp)) {
1175  $maxphp = preg_replace('/g$/i', '', $maxphp);
1176  $maxphp = $maxphp * 1024 * 1024;
1177  }
1178  if (preg_match('/t$/i', $maxphp)) {
1179  $maxphp = preg_replace('/t$/i', '', $maxphp);
1180  $maxphp = $maxphp * 1024 * 1024 * 1024;
1181  }
1182  $maxphp2 = @ini_get('post_max_size'); // In unknown
1183  if (preg_match('/k$/i', $maxphp2)) {
1184  $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
1185  $maxphp2 = $maxphp2 * 1;
1186  }
1187  if (preg_match('/m$/i', $maxphp2)) {
1188  $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
1189  $maxphp2 = $maxphp2 * 1024;
1190  }
1191  if (preg_match('/g$/i', $maxphp2)) {
1192  $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
1193  $maxphp2 = $maxphp2 * 1024 * 1024;
1194  }
1195  if (preg_match('/t$/i', $maxphp2)) {
1196  $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
1197  $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1198  }
1199  // Now $max and $maxphp and $maxphp2 are in Kb
1200  $maxmin = $max;
1201  $maxphptoshow = $maxphptoshowparam = '';
1202  if ($maxphp > 0) {
1203  $maxmin = min($max, $maxphp);
1204  $maxphptoshow = $maxphp;
1205  $maxphptoshowparam = 'upload_max_filesize';
1206  }
1207  if ($maxphp2 > 0) {
1208  $maxmin = min($max, $maxphp2);
1209  if ($maxphp2 < $maxphp) {
1210  $maxphptoshow = $maxphp2;
1211  $maxphptoshowparam = 'post_max_size';
1212  }
1213  }
1214 
1215  if ($maxmin > 0) {
1216  print '<script type="text/javascript">
1217  $(document).ready(function() {
1218  jQuery("#fileinstall").on("change", function() {
1219  if(this.files[0].size > '.($maxmin * 1024).') {
1220  alert("'.dol_escape_js($langs->trans("ErrorFileSizeTooLarge")).'");
1221  this.value = "";
1222  }
1223  });
1224  });
1225  </script>'."\n";
1226  // MAX_FILE_SIZE doit précéder le champ input de type file
1227  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">';
1228  }
1229 
1230  print '<input class="flat minwidth400" type="file" name="fileinstall" id="fileinstall"> ';
1231 
1232  print '<input type="submit" name="send" value="'.dol_escape_htmltag($langs->trans("Upload")).'" class="button">';
1233 
1234  if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
1235  if ($user->admin) {
1236  $langs->load('other');
1237  print ' ';
1238  print info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphptoshow, $maxphptoshowparam), 1);
1239  }
1240  } else {
1241  print ' ('.$langs->trans("UploadDisabled").')';
1242  }
1243 
1244  print '</form>';
1245 
1246  print '<br>';
1247  print '<br>';
1248 
1249  print '<div class="center"><div class="logo_setup"></div></div>';
1250  } else {
1251  print $langs->trans("UnpackPackageInModulesRoot", $dirins).'<br>';
1252  print '<b>'.$langs->trans("StepNb", 4).'</b>: ';
1253  print $langs->trans("SetupIsReadyForUse").'<br>';
1254  }
1255  }
1256 
1257  if (!empty($result['return'])) {
1258  print '<br>';
1259 
1260  foreach ($result['return'] as $value) {
1261  echo $value.'<br>';
1262  }
1263  }
1264 
1265  print dol_get_fiche_end();
1266 }
1267 
1268 if ($mode == 'develop') {
1269  print dol_get_fiche_head($head, $mode, '', -1);
1270 
1271  print $deschelp;
1272 
1273  print '<br>';
1274 
1275  // Marketplace
1276  print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
1277  print "<tr class=\"liste_titre\">\n";
1278  //print '<td>'.$langs->trans("Logo").'</td>';
1279  print '<td colspan="2">'.$langs->trans("DevelopYourModuleDesc").'</td>';
1280  print '<td>'.$langs->trans("URL").'</td>';
1281  print '</tr>';
1282 
1283  print '<tr class="oddeven" height="80">'."\n";
1284  print '<td class="left">';
1285  print '<div class="imgmaxheight50 logo_setup"></div>';
1286  print '</td>';
1287  print '<td>'.$langs->trans("TryToUseTheModuleBuilder", $langs->transnoentitiesnoconv("ModuleBuilder")).'</td>';
1288  print '<td class="maxwidth300">';
1289  if (isModEnabled('modulebuilder')) {
1290  print $langs->trans("SeeTopRightMenu");
1291  } else {
1292  print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("ModuleBuilder")).'</span>';
1293  }
1294  print '</td>';
1295  print '</tr>';
1296 
1297  print '<tr class="oddeven" height="80">'."\n";
1298  $url = 'https://partners.dolibarr.org';
1299  print '<td class="left">';
1300  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>';
1301  print '</td>';
1302  print '<td>'.$langs->trans("DoliPartnersDesc").'</td>';
1303  print '<td><a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
1304  print '</tr>';
1305 
1306  print "</table>\n";
1307 
1308  print dol_get_fiche_end();
1309 }
1310 
1311 // End of page
1312 llxFooter();
1313 $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:1401
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:1111
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
Definition: files.lib.php:2178
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:480
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
Definition: files.lib.php:772
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:450
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.