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