knowledgemanagement.php 23 KB

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