hrm.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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($langs);
  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. $nameofclass = ucfirst($myTmpObjectKey);
  242. $mytmpinstance = new $nameofclass($db);
  243. $mytmpinstance->initAsSpecimen();
  244. // Info
  245. $htmltooltip = '';
  246. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  247. $nextval = $module->getNextValue($mytmpinstance);
  248. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  249. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  250. if ($nextval) {
  251. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  252. $nextval = $langs->trans($nextval);
  253. }
  254. $htmltooltip .= $nextval.'<br>';
  255. } else {
  256. $htmltooltip .= $langs->trans($module->error).'<br>';
  257. }
  258. }
  259. print '<td class="center">';
  260. print $form->textwithpicto('', $htmltooltip, 1, 0);
  261. print '</td>';
  262. print "</tr>\n";
  263. }
  264. }
  265. }
  266. closedir($handle);
  267. }
  268. }
  269. }
  270. print "</table>\n";
  271. }
  272. if ($myTmpObjectArray['includedocgeneration']) {
  273. /*
  274. * Document templates generators
  275. */
  276. $setupnotempty++;
  277. $type = strtolower($myTmpObjectKey);
  278. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  279. // Load array def with activated templates
  280. $def = array();
  281. $sql = "SELECT nom";
  282. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  283. $sql .= " WHERE type = '".$db->escape($type)."'";
  284. $sql .= " AND entity = ".$conf->entity;
  285. $resql = $db->query($sql);
  286. if ($resql) {
  287. $i = 0;
  288. $num_rows = $db->num_rows($resql);
  289. while ($i < $num_rows) {
  290. $array = $db->fetch_array($resql);
  291. array_push($def, $array[0]);
  292. $i++;
  293. }
  294. } else {
  295. dol_print_error($db);
  296. }
  297. print "<table class=\"noborder\" width=\"100%\">\n";
  298. print "<tr class=\"liste_titre\">\n";
  299. print '<td>'.$langs->trans("Name").'</td>';
  300. print '<td>'.$langs->trans("Description").'</td>';
  301. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  302. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  303. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  304. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  305. print "</tr>\n";
  306. clearstatcache();
  307. foreach ($dirmodels as $reldir) {
  308. foreach (array('', '/doc') as $valdir) {
  309. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  310. $dir = dol_buildpath($realpath);
  311. if (is_dir($dir)) {
  312. $handle = opendir($dir);
  313. if (is_resource($handle)) {
  314. while (($file = readdir($handle)) !== false) {
  315. $filelist[] = $file;
  316. }
  317. closedir($handle);
  318. arsort($filelist);
  319. foreach ($filelist as $file) {
  320. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  321. if (file_exists($dir.'/'.$file)) {
  322. $name = substr($file, 4, dol_strlen($file) - 16);
  323. $classname = substr($file, 0, dol_strlen($file) - 12);
  324. require_once $dir.'/'.$file;
  325. $module = new $classname($db);
  326. $modulequalified = 1;
  327. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  328. $modulequalified = 0;
  329. }
  330. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  331. $modulequalified = 0;
  332. }
  333. if ($modulequalified) {
  334. print '<tr class="oddeven"><td width="100">';
  335. print (empty($module->name) ? $name : $module->name);
  336. print "</td><td>\n";
  337. if (method_exists($module, 'info')) {
  338. print $module->info($langs);
  339. } else {
  340. print $module->description;
  341. }
  342. print '</td>';
  343. // Active
  344. if (in_array($name, $def)) {
  345. print '<td class="center">'."\n";
  346. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
  347. print img_picto($langs->trans("Enabled"), 'switch_on');
  348. print '</a>';
  349. print '</td>';
  350. } else {
  351. print '<td class="center">'."\n";
  352. 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>';
  353. print "</td>";
  354. }
  355. // Default
  356. print '<td class="center">';
  357. $constforvar = 'HRMTEST_'.strtoupper($myTmpObjectKey).'_ADDON';
  358. if (getDolGlobalString($constforvar) == $name) {
  359. //print img_picto($langs->trans("Default"), 'on');
  360. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  361. 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>';
  362. } else {
  363. 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>';
  364. }
  365. print '</td>';
  366. // Info
  367. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  368. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  369. if ($module->type == 'pdf') {
  370. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  371. }
  372. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  373. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  374. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  375. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  376. print '<td class="center">';
  377. print $form->textwithpicto('', $htmltooltip, 1, 0);
  378. print '</td>';
  379. // Preview
  380. print '<td class="center">';
  381. if ($module->type == 'pdf') {
  382. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  383. } else {
  384. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  385. }
  386. print '</td>';
  387. print "</tr>\n";
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. print '</table>';
  397. }
  398. }
  399. print load_fiche_titre($langs->trans('OtherOptions'), '', '');
  400. if (empty($conf->global->HRM_MAXRANK)) {
  401. $conf->global->HRM_MAXRANK = Skill::DEFAULT_MAX_RANK_PER_SKILL;
  402. }
  403. if ($action == 'edit') {
  404. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  405. print '<input type="hidden" name="token" value="'.newToken().'">';
  406. print '<input type="hidden" name="action" value="update">';
  407. print '<table class="noborder centpercent">';
  408. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  409. foreach ($arrayofparameters as $constname => $val) {
  410. if ($val['enabled']==1) {
  411. $setupnotempty++;
  412. print '<tr class="oddeven"><td>';
  413. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  414. print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
  415. print '</td><td>';
  416. if ($val['type'] == 'textarea') {
  417. print '<textarea class="flat" name="' . $constname . '" id="' . $constname . '" cols="50" rows="5" wrap="soft">' . "\n";
  418. print getDolGlobalString($constname);
  419. print "</textarea>\n";
  420. } elseif ($val['type'] == 'integer') {
  421. print '<input class="flat" name="' . $constname . '" id="' . $constname . '" value="' . getDolGlobalString($constname) . '" type="number" step="1" min="0" max="50" >' . "\n";
  422. } elseif ($val['type'] == 'html') {
  423. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  424. $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
  425. $doleditor->Create();
  426. } elseif ($val['type'] == 'yesno') {
  427. print $form->selectyesno($constname, getDolGlobalString($constname), 1);
  428. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  429. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  430. $formmail = new FormMail($db);
  431. $tmp = explode(':', $val['type']);
  432. $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
  433. //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
  434. $arrayofmessagename = array();
  435. if (is_array($formmail->lines_model)) {
  436. foreach ($formmail->lines_model as $modelmail) {
  437. //var_dump($modelmail);
  438. $moreonlabel = '';
  439. if (!empty($arrayofmessagename[$modelmail->label])) {
  440. $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
  441. }
  442. // The 'label' is the key that is unique if we exclude the language
  443. $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
  444. }
  445. }
  446. print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
  447. } elseif (preg_match('/category:/', $val['type'])) {
  448. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  449. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  450. $formother = new FormOther($db);
  451. $tmp = explode(':', $val['type']);
  452. print img_picto('', 'category', 'class="pictofixedwidth"');
  453. print $formother->select_categories($tmp[1], getDolGlobalString($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
  454. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  455. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  456. $formcompany = new FormCompany($db);
  457. print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
  458. } elseif ($val['type'] == 'securekey') {
  459. print '<input required="required" type="text" class="flat" id="' . $constname . '" name="' . $constname . '" value="' . (GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)) . '" size="40">';
  460. if (!empty($conf->use_javascript_ajax)) {
  461. print '&nbsp;' . img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token' . $constname . '" class="linkobject"');
  462. }
  463. // Add button to autosuggest a key
  464. include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
  465. print dolJSToSetRandomPassword($constname, 'generate_token' . $constname);
  466. } elseif ($val['type'] == 'product') {
  467. if (isModEnabled('product') || isModEnabled('service')) {
  468. $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
  469. $form->select_produits($selected, $constname, '', 0);
  470. }
  471. } else {
  472. print '<input name="' . $constname . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '" value="' . getDolGlobalString($constname) . '">';
  473. }
  474. print '</td></tr>';
  475. }
  476. }
  477. print '</table>';
  478. print '<br><div class="center">';
  479. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  480. print '</div>';
  481. print '</form>';
  482. print '<br>';
  483. } else {
  484. if (!empty($arrayofparameters)) {
  485. print '<table class="noborder centpercent">';
  486. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  487. foreach ($arrayofparameters as $constname => $val) {
  488. if ($val['enabled']==1) {
  489. $setupnotempty++;
  490. print '<tr class="oddeven"><td>';
  491. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  492. print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
  493. print '</td><td>';
  494. if ($val['type'] == 'textarea') {
  495. print dol_nl2br(getDolGlobalString($constname));
  496. } elseif ($val['type']== 'html') {
  497. print getDolGlobalString($constname);
  498. } elseif ($val['type'] == 'yesno') {
  499. print ajax_constantonoff($constname);
  500. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  501. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  502. $formmail = new FormMail($db);
  503. $tmp = explode(':', $val['type']);
  504. $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalString($constname));
  505. if ($template<0) {
  506. setEventMessages(null, $formmail->errors, 'errors');
  507. }
  508. print $langs->trans($template->label);
  509. } elseif (preg_match('/category:/', $val['type'])) {
  510. $c = new Categorie($db);
  511. $result = $c->fetch(getDolGlobalString($constname));
  512. if ($result < 0) {
  513. setEventMessages(null, $c->errors, 'errors');
  514. }
  515. $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
  516. $toprint = array();
  517. foreach ($ways as $way) {
  518. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
  519. }
  520. print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  521. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  522. if (getDolGlobalString($constname) == 2) {
  523. print $langs->trans("Prospect");
  524. } elseif (getDolGlobalString($constname) == 3) {
  525. print $langs->trans("ProspectCustomer");
  526. } elseif (getDolGlobalString($constname) == 1) {
  527. print $langs->trans("Customer");
  528. } elseif (getDolGlobalString($constname) == 0) {
  529. print $langs->trans("NorProspectNorCustomer");
  530. }
  531. } elseif ($val['type'] == 'product') {
  532. $product = new Product($db);
  533. $resprod = $product->fetch(getDolGlobalString($constname));
  534. if ($resprod > 0) {
  535. print $product->ref;
  536. } elseif ($resprod < 0) {
  537. setEventMessages(null, $object->errors, "errors");
  538. }
  539. } else {
  540. print getDolGlobalString($constname);
  541. }
  542. print '</td></tr>';
  543. }
  544. }
  545. print '</table>';
  546. print '<div class="tabsAction">';
  547. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  548. print '</div>';
  549. } else {
  550. print '<br>'.$langs->trans("NothingToSetup");
  551. }
  552. }
  553. if (empty($setupnotempty)) {
  554. print '<br>'.$langs->trans("NothingToSetup");
  555. }
  556. // Page end
  557. print dol_get_fiche_end();
  558. llxFooter();
  559. $db->close();