hrm.php 24 KB

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