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