hrm.php 24 KB

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