modules.php 53 KB

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