modules.php 52 KB

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