modules.php 46 KB

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