knowledgemanagement.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 SuperAdmin
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/knowledgemanagement.php
  20. * \ingroup knowledgemanagement
  21. * \brief KnowledgeManagement setup page.
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. global $langs, $user;
  26. // Libraries
  27. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  28. require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/lib/knowledgemanagement.lib.php";
  29. // Translations
  30. $langs->loadLangs(array("admin", "knowledgemanagement"));
  31. // Parameters
  32. $action = GETPOST('action', 'aZ09');
  33. $backtopage = GETPOST('backtopage', 'alpha');
  34. $value = GETPOST('value', 'alpha');
  35. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  36. $label = GETPOST('label', 'alpha');
  37. $scandir = GETPOST('scan_dir', 'alpha');
  38. $type = 'knowledgemanagement';
  39. $arrayofparameters = array(
  40. 'KNOWLEDGEMANAGEMENT_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>0),
  41. //'KNOWLEDGEMANAGEMENT_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
  42. //'KNOWLEDGEMANAGEMENT_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
  43. //'KNOWLEDGEMANAGEMENT_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
  44. //'KNOWLEDGEMANAGEMENT_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
  45. //'KNOWLEDGEMANAGEMENT_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
  46. );
  47. $error = 0;
  48. $setupnotempty = 0;
  49. // Access control
  50. if (!$user->admin) {
  51. accessforbidden();
  52. }
  53. /*
  54. * Actions
  55. */
  56. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  57. if ($action == 'updateMask') {
  58. $maskconst = GETPOST('maskconst', 'aZ09');
  59. $maskorder = GETPOST('maskorder', 'alpha');
  60. if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
  61. $res = dolibarr_set_const($db, $maskconst, $maskorder, 'chaine', 0, '', $conf->entity);
  62. if (!($res > 0)) {
  63. $error++;
  64. }
  65. }
  66. if (!$error) {
  67. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  68. } else {
  69. setEventMessages($langs->trans("Error"), null, 'errors');
  70. }
  71. } elseif ($action == 'specimen') {
  72. $modele = GETPOST('module', 'alpha');
  73. $tmpobjectkey = GETPOST('object');
  74. $tmpobject = new $tmpobjectkey($db);
  75. $tmpobject->initAsSpecimen();
  76. // Search template files
  77. $file = '';
  78. $classname = '';
  79. $filefound = 0;
  80. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  81. foreach ($dirmodels as $reldir) {
  82. $file = dol_buildpath($reldir."core/modules/knowledgemanagement/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  83. if (file_exists($file)) {
  84. $filefound = 1;
  85. $classname = "pdf_".$modele;
  86. break;
  87. }
  88. }
  89. if ($filefound) {
  90. require_once $file;
  91. $module = new $classname($db);
  92. if ($module->write_file($tmpobject, $langs) > 0) {
  93. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  94. return;
  95. } else {
  96. setEventMessages($module->error, null, 'errors');
  97. dol_syslog($module->error, LOG_ERR);
  98. }
  99. } else {
  100. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  101. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  102. }
  103. } elseif ($action == 'setmod') {
  104. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  105. $tmpobjectkey = GETPOST('object');
  106. if (!empty($tmpobjectkey)) {
  107. $constforval = 'KNOWLEDGEMANAGEMENT_'.strtoupper($tmpobjectkey)."_ADDON";
  108. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  109. }
  110. } elseif ($action == 'set') {
  111. // Activate a model
  112. $ret = addDocumentModel($value, $type, $label, $scandir);
  113. } elseif ($action == 'del') {
  114. $ret = delDocumentModel($value, $type);
  115. if ($ret > 0) {
  116. $tmpobjectkey = GETPOST('object');
  117. if (!empty($tmpobjectkey)) {
  118. $constforval = 'KNOWLEDGEMANAGEMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  119. if (getDolGlobalString($constforval) == "$value") {
  120. dolibarr_del_const($db, $constforval, $conf->entity);
  121. }
  122. }
  123. }
  124. } elseif ($action == 'setdoc') {
  125. // Set or unset default model
  126. $tmpobjectkey = GETPOST('object');
  127. if (!empty($tmpobjectkey)) {
  128. $constforval = 'KNOWLEDGEMANAGEMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  129. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  130. // The constant that was read before the new set
  131. // We therefore requires a variable to have a coherent view
  132. $conf->global->$constforval = $value;
  133. }
  134. // We disable/enable the document template (into llx_document_model table)
  135. $ret = delDocumentModel($value, $type);
  136. if ($ret > 0) {
  137. $ret = addDocumentModel($value, $type, $label, $scandir);
  138. }
  139. }
  140. } elseif ($action == 'unsetdoc') {
  141. $tmpobjectkey = GETPOST('object');
  142. if (!empty($tmpobjectkey)) {
  143. $constforval = 'KNOWLEDGEMANAGEMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  144. dolibarr_del_const($db, $constforval, $conf->entity);
  145. }
  146. }
  147. /*
  148. * View
  149. */
  150. $form = new Form($db);
  151. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  152. $page_name = "KnowledgeManagementSetup";
  153. llxHeader('', $langs->trans($page_name));
  154. // Subheader
  155. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  156. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  157. // Configuration header
  158. $head = knowledgemanagementAdminPrepareHead();
  159. print dol_get_fiche_head($head, 'setup', $langs->trans('ModuleKnowledgeManagementName'), -1, "knowledgemanagement");
  160. // Setup page goes here
  161. echo '<span class="opacitymedium">'.$langs->trans("KnowledgeManagementSetupPage").'</span><br><br>';
  162. if ($action == 'edit') {
  163. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  164. print '<input type="hidden" name="token" value="'.newToken().'">';
  165. print '<input type="hidden" name="action" value="update">';
  166. print '<table class="noborder centpercent">';
  167. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  168. foreach ($arrayofparameters as $constname => $val) {
  169. if ($val['enabled']==1) {
  170. $setupnotempty++;
  171. print '<tr class="oddeven"><td>';
  172. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  173. print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
  174. print '</td><td>';
  175. if ($val['type'] == 'textarea') {
  176. print '<textarea class="flat" name="' . $constname . '" id="' . $constname . '" cols="50" rows="5" wrap="soft">' . "\n";
  177. print getDolGlobalString($constname);
  178. print "</textarea>\n";
  179. } elseif ($val['type'] == 'html') {
  180. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  181. $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
  182. $doleditor->Create();
  183. } elseif ($val['type'] == 'yesno') {
  184. print $form->selectyesno($constname, getDolGlobalString($constname), 1);
  185. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  186. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  187. $formmail = new FormMail($db);
  188. $tmp = explode(':', $val['type']);
  189. $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
  190. //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
  191. $arrayofmessagename = array();
  192. if (is_array($formmail->lines_model)) {
  193. foreach ($formmail->lines_model as $modelmail) {
  194. //var_dump($modelmail);
  195. $moreonlabel = '';
  196. if (!empty($arrayofmessagename[$modelmail->label])) {
  197. $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
  198. }
  199. // The 'label' is the key that is unique if we exclude the language
  200. $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
  201. }
  202. }
  203. print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
  204. } elseif (preg_match('/category:/', $val['type'])) {
  205. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  206. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  207. $formother = new FormOther($db);
  208. $tmp = explode(':', $val['type']);
  209. print img_picto('', 'category', 'class="pictofixedwidth"');
  210. print $formother->select_categories($tmp[1], getDolGlobalString($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
  211. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  212. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  213. $formcompany = new FormCompany($db);
  214. print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
  215. } else {
  216. print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
  217. }
  218. print '</td></tr>';
  219. }
  220. }
  221. print '</table>';
  222. print $form->buttonsSaveCancel("Save", '');
  223. print '</form>';
  224. print '<br>';
  225. } else {
  226. if (!empty($arrayofparameters)) {
  227. print '<table class="noborder centpercent">';
  228. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  229. foreach ($arrayofparameters as $constname => $val) {
  230. if ($val['enabled']==1) {
  231. $setupnotempty++;
  232. print '<tr class="oddeven"><td>';
  233. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  234. print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
  235. print '</td><td>';
  236. if ($val['type'] == 'textarea') {
  237. print dol_nl2br(getDolGlobalString($constname));
  238. } elseif ($val['type']== 'html') {
  239. print getDolGlobalString($constname);
  240. } elseif ($val['type'] == 'yesno') {
  241. print ajax_constantonoff($constname);
  242. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  243. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  244. $formmail = new FormMail($db);
  245. $tmp = explode(':', $val['type']);
  246. $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalString($constname));
  247. if ($template<0) {
  248. setEventMessages(null, $formmail->errors, 'errors');
  249. }
  250. print $langs->trans($template->label);
  251. } elseif (preg_match('/category:/', $val['type'])) {
  252. $c = new Categorie($db);
  253. $result = $c->fetch(getDolGlobalInt($constname));
  254. if ($result < 0) {
  255. setEventMessages(null, $c->errors, 'errors');
  256. }
  257. $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
  258. $toprint = array();
  259. foreach ($ways as $way) {
  260. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
  261. }
  262. print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  263. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  264. if (getDolGlobalString($constname)==2) {
  265. print $langs->trans("Prospect");
  266. } elseif (getDolGlobalString($constname)==3) {
  267. print $langs->trans("ProspectCustomer");
  268. } elseif (getDolGlobalInt($constname)==1) {
  269. print $langs->trans("Customer");
  270. } elseif (getDolGlobalInt($constname)==0) {
  271. print $langs->trans("NorProspectNorCustomer");
  272. }
  273. } else {
  274. print getDolGlobalString($constname);
  275. }
  276. print '</td></tr>';
  277. }
  278. }
  279. print '</table>';
  280. print '<div class="tabsAction">';
  281. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  282. print '</div>';
  283. } else {
  284. //print '<br>'.$langs->trans("NothingToSetup");
  285. }
  286. }
  287. $moduledir = 'knowledgemanagement';
  288. $myTmpObjects = array();
  289. $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
  290. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  291. if ($myTmpObjectKey == 'MyObject') {
  292. continue;
  293. }
  294. if ($myTmpObjectArray['includerefgeneration']) {
  295. /*
  296. * Orders Numbering model
  297. */
  298. $setupnotempty++;
  299. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  300. print '<table class="noborder centpercent">';
  301. print '<tr class="liste_titre">';
  302. print '<td>'.$langs->trans("Name").'</td>';
  303. print '<td>'.$langs->trans("Description").'</td>';
  304. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  305. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  306. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  307. print '</tr>'."\n";
  308. clearstatcache();
  309. foreach ($dirmodels as $reldir) {
  310. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  311. if (is_dir($dir)) {
  312. $handle = opendir($dir);
  313. if (is_resource($handle)) {
  314. while (($file = readdir($handle)) !== false) {
  315. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  316. $file = substr($file, 0, dol_strlen($file) - 4);
  317. require_once $dir.'/'.$file.'.php';
  318. $module = new $file($db);
  319. // Show modules according to features level
  320. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  321. continue;
  322. }
  323. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  324. continue;
  325. }
  326. if ($module->isEnabled()) {
  327. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  328. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  329. print $module->info($langs);
  330. print '</td>';
  331. // Show example of numbering model
  332. print '<td class="nowrap">';
  333. $tmp = $module->getExample();
  334. if (preg_match('/^Error/', $tmp)) {
  335. $langs->load("errors");
  336. print '<div class="error">'.$langs->trans($tmp).'</div>';
  337. } elseif ($tmp == 'NotConfigured') {
  338. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  339. } else {
  340. print $tmp;
  341. }
  342. print '</td>'."\n";
  343. print '<td class="center">';
  344. $constforvar = 'KNOWLEDGEMANAGEMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
  345. if (getDolGlobalString($constforvar) == $file) {
  346. print img_picto($langs->trans("Activated"), 'switch_on');
  347. } else {
  348. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  349. print img_picto($langs->trans("Disabled"), 'switch_off');
  350. print '</a>';
  351. }
  352. print '</td>';
  353. $mytmpinstance = new $myTmpObjectKey($db);
  354. $mytmpinstance->initAsSpecimen();
  355. // Info
  356. $htmltooltip = '';
  357. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  358. $nextval = $module->getNextValue($mytmpinstance);
  359. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  360. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  361. if ($nextval) {
  362. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  363. $nextval = $langs->trans($nextval);
  364. }
  365. $htmltooltip .= $nextval.'<br>';
  366. } else {
  367. $htmltooltip .= $langs->trans($module->error).'<br>';
  368. }
  369. }
  370. print '<td class="center">';
  371. print $form->textwithpicto('', $htmltooltip, 1, 0);
  372. print '</td>';
  373. print "</tr>\n";
  374. }
  375. }
  376. }
  377. closedir($handle);
  378. }
  379. }
  380. }
  381. print "</table><br>\n";
  382. }
  383. if ($myTmpObjectArray['includedocgeneration']) {
  384. /*
  385. * Document templates generators
  386. */
  387. $setupnotempty++;
  388. $type = strtolower($myTmpObjectKey);
  389. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  390. // Load array def with activated templates
  391. $def = array();
  392. $sql = "SELECT nom";
  393. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  394. $sql .= " WHERE type = '".$db->escape($type)."'";
  395. $sql .= " AND entity = ".$conf->entity;
  396. $resql = $db->query($sql);
  397. if ($resql) {
  398. $i = 0;
  399. $num_rows = $db->num_rows($resql);
  400. while ($i < $num_rows) {
  401. $array = $db->fetch_array($resql);
  402. array_push($def, $array[0]);
  403. $i++;
  404. }
  405. } else {
  406. dol_print_error($db);
  407. }
  408. print "<table class=\"noborder\" width=\"100%\">\n";
  409. print "<tr class=\"liste_titre\">\n";
  410. print '<td>'.$langs->trans("Name").'</td>';
  411. print '<td>'.$langs->trans("Description").'</td>';
  412. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  413. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  414. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  415. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  416. print "</tr>\n";
  417. clearstatcache();
  418. foreach ($dirmodels as $reldir) {
  419. foreach (array('', '/doc') as $valdir) {
  420. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  421. $dir = dol_buildpath($realpath);
  422. if (is_dir($dir)) {
  423. $handle = opendir($dir);
  424. if (is_resource($handle)) {
  425. while (($file = readdir($handle)) !== false) {
  426. $filelist[] = $file;
  427. }
  428. closedir($handle);
  429. arsort($filelist);
  430. foreach ($filelist as $file) {
  431. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  432. if (file_exists($dir.'/'.$file)) {
  433. $name = substr($file, 4, dol_strlen($file) - 16);
  434. $classname = substr($file, 0, dol_strlen($file) - 12);
  435. require_once $dir.'/'.$file;
  436. $module = new $classname($db);
  437. $modulequalified = 1;
  438. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  439. $modulequalified = 0;
  440. }
  441. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  442. $modulequalified = 0;
  443. }
  444. if ($modulequalified) {
  445. print '<tr class="oddeven"><td width="100">';
  446. print(empty($module->name) ? $name : $module->name);
  447. print "</td><td>\n";
  448. if (method_exists($module, 'info')) {
  449. print $module->info($langs);
  450. } else {
  451. print $module->description;
  452. }
  453. print '</td>';
  454. // Active
  455. if (in_array($name, $def)) {
  456. print '<td class="center">'."\n";
  457. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  458. print img_picto($langs->trans("Enabled"), 'switch_on');
  459. print '</a>';
  460. print '</td>';
  461. } else {
  462. print '<td class="center">'."\n";
  463. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  464. print "</td>";
  465. }
  466. // Default
  467. print '<td class="center">';
  468. $constforvar = 'KNOWLEDGEMANAGEMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
  469. if (getDolGlobalString($constforvar) == $name) {
  470. //print img_picto($langs->trans("Default"), 'on');
  471. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  472. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&amp;token='.newToken().'&amp;object='.urlencode(strtolower($myTmpObjectKey)).'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  473. } else {
  474. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;object='.urlencode(strtolower($myTmpObjectKey)).'&amp;value='.$name.'&amp;scan_dir='.urlencode($module->scandir).'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  475. }
  476. print '</td>';
  477. // Info
  478. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  479. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  480. if ($module->type == 'pdf') {
  481. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  482. }
  483. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  484. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  485. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  486. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  487. print '<td class="center">';
  488. print $form->textwithpicto('', $htmltooltip, 1, 0);
  489. print '</td>';
  490. // Preview
  491. print '<td class="center">';
  492. if ($module->type == 'pdf') {
  493. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  494. } else {
  495. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  496. }
  497. print '</td>';
  498. print "</tr>\n";
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. print '</table>';
  508. }
  509. }
  510. if (empty($setupnotempty)) {
  511. print '<br>'.$langs->trans("NothingToSetup");
  512. }
  513. // Page end
  514. print dol_get_fiche_end();
  515. llxFooter();
  516. $db->close();