hrm.php 24 KB

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