setup_candidatures.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <?php
  2. /* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/recruitment/admin/setup_candidatures.php
  19. * \ingroup recruitment
  20. * \brief Recruitment setup page for candidatures.
  21. */
  22. // Load Dolibarr environment
  23. $res = 0;
  24. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  25. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  26. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  27. }
  28. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  29. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  30. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  31. $i--;
  32. $j--;
  33. }
  34. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  35. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  36. }
  37. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  38. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  39. }
  40. // Try main.inc.php using relative path
  41. if (!$res && file_exists("../../main.inc.php")) {
  42. $res = @include "../../main.inc.php";
  43. }
  44. if (!$res && file_exists("../../../main.inc.php")) {
  45. $res = @include "../../../main.inc.php";
  46. }
  47. if (!$res) {
  48. die("Include of main fails");
  49. }
  50. global $langs, $user;
  51. // Libraries
  52. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  53. require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment.lib.php';
  54. require_once DOL_DOCUMENT_ROOT."/recruitment/class/recruitmentjobposition.class.php";
  55. // Translations
  56. $langs->loadLangs(array("admin", "recruitment"));
  57. // Access control
  58. if (!$user->admin) {
  59. accessforbidden();
  60. }
  61. // Parameters
  62. $action = GETPOST('action', 'aZ09');
  63. $backtopage = GETPOST('backtopage', 'alpha');
  64. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  65. $value = GETPOST('value', 'alpha');
  66. $label = GETPOST('label', 'alpha');
  67. $scandir = GETPOST('scan_dir', 'alpha');
  68. $type = 'recruitmentcandidature';
  69. $arrayofparameters = array(
  70. // 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
  71. // 'RECRUITMENT_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
  72. );
  73. $error = 0;
  74. $setupnotempty = 0;
  75. /*
  76. * Actions
  77. */
  78. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  79. if ($action == 'updateMask') {
  80. $maskconst = GETPOST('maskconstcand', 'aZ09');
  81. $maskvalue = GETPOST('maskcand', 'alpha');
  82. if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
  83. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  84. }
  85. if (!($res > 0)) {
  86. $error++;
  87. }
  88. if (!$error) {
  89. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  90. } else {
  91. setEventMessages($langs->trans("Error"), null, 'errors');
  92. }
  93. } elseif ($action == 'specimen') {
  94. $modele = GETPOST('module', 'alpha');
  95. $tmpobjectkey = GETPOST('object');
  96. $tmpobject = new $tmpobjectkey($db);
  97. $tmpobject->initAsSpecimen();
  98. // Search template files
  99. $file = '';
  100. $classname = '';
  101. $filefound = 0;
  102. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  103. foreach ($dirmodels as $reldir) {
  104. $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  105. if (file_exists($file)) {
  106. $filefound = 1;
  107. $classname = "pdf_".$modele;
  108. break;
  109. }
  110. }
  111. if ($filefound) {
  112. require_once $file;
  113. $module = new $classname($db);
  114. if ($module->write_file($tmpobject, $langs) > 0) {
  115. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  116. return;
  117. } else {
  118. setEventMessages($module->error, null, 'errors');
  119. dol_syslog($module->error, LOG_ERR);
  120. }
  121. } else {
  122. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  123. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  124. }
  125. } elseif ($action == 'set') {
  126. // Activate a model
  127. $ret = addDocumentModel($value, $type, $label, $scandir);
  128. } elseif ($action == 'del') {
  129. $tmpobjectkey = GETPOST('object');
  130. $ret = delDocumentModel($value, $type);
  131. if ($ret > 0) {
  132. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  133. if (getDolGlobalString($constforval) == "$value") {
  134. dolibarr_del_const($db, $constforval, $conf->entity);
  135. }
  136. }
  137. } elseif ($action == 'setmod') {
  138. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  139. $tmpobjectkey = GETPOST('object');
  140. if (!empty($tmpobjectkey)) {
  141. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
  142. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  143. }
  144. } elseif ($action == 'setdoc') {
  145. // Set default model
  146. $tmpobjectkey = GETPOST('object');
  147. $constforval = 'RECRUITMENT_'.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. } elseif ($action == 'unsetdoc') {
  159. $tmpobjectkey = GETPOST('object');
  160. if (!empty($tmpobjectkey)) {
  161. $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  162. dolibarr_del_const($db, $constforval, $conf->entity);
  163. }
  164. }
  165. /*
  166. * View
  167. */
  168. $form = new Form($db);
  169. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  170. $page_name = "RecruitmentSetup";
  171. llxHeader('', $langs->trans($page_name));
  172. // Subheader
  173. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  174. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  175. // Configuration header
  176. $head = recruitmentAdminPrepareHead();
  177. print dol_get_fiche_head($head, 'settings_candidatures', '', -1, '');
  178. // Setup page goes here
  179. //echo '<span class="opacitymedium">'.$langs->trans("RecruitmentSetupPage").'</span><br><br>';
  180. if ($action == 'edit') {
  181. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  182. print '<input type="hidden" name="token" value="'.newToken().'">';
  183. print '<input type="hidden" name="action" value="update">';
  184. print '<table class="noborder centpercent">';
  185. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  186. foreach ($arrayofparameters as $key => $val) {
  187. print '<tr class="oddeven"><td>';
  188. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  189. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  190. print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
  191. }
  192. print '</table>';
  193. print '<br><div class="center">';
  194. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  195. print '</div>';
  196. print '</form>';
  197. print '<br>';
  198. } else {
  199. if (!empty($arrayofparameters)) {
  200. print '<table class="noborder centpercent">';
  201. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  202. foreach ($arrayofparameters as $key => $val) {
  203. $setupnotempty++;
  204. print '<tr class="oddeven"><td>';
  205. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  206. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  207. print '</td><td>'.getDolGlobalString($key).'</td></tr>';
  208. }
  209. print '</table>';
  210. print '<div class="tabsAction">';
  211. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  212. print '</div>';
  213. }
  214. }
  215. $moduledir = 'recruitment';
  216. $myTmpObjects = array();
  217. $myTmpObjects['RecruitmentCandidature'] = array('includerefgeneration'=>1, 'includedocgeneration'=>0);
  218. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  219. if ($myTmpObjectArray['includerefgeneration']) {
  220. /*
  221. * Orders Numbering model
  222. */
  223. $setupnotempty++;
  224. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  225. print '<table class="noborder centpercent">';
  226. print '<tr class="liste_titre">';
  227. print '<td>'.$langs->trans("Name").'</td>';
  228. print '<td>'.$langs->trans("Description").'</td>';
  229. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  230. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  231. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  232. print '</tr>'."\n";
  233. clearstatcache();
  234. foreach ($dirmodels as $reldir) {
  235. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  236. if (is_dir($dir)) {
  237. $handle = opendir($dir);
  238. if (is_resource($handle)) {
  239. while (($file = readdir($handle)) !== false) {
  240. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  241. $file = substr($file, 0, dol_strlen($file) - 4);
  242. require_once $dir.'/'.$file.'.php';
  243. $module = new $file($db);
  244. // Show modules according to features level
  245. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  246. continue;
  247. }
  248. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  249. continue;
  250. }
  251. if ($module->isEnabled()) {
  252. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  253. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  254. print $module->info($langs);
  255. print '</td>';
  256. // Show example of numbering model
  257. print '<td class="nowrap">';
  258. $tmp = $module->getExample();
  259. if (preg_match('/^Error/', $tmp)) {
  260. $langs->load("errors");
  261. print '<div class="error">'.$langs->trans($tmp).'</div>';
  262. } elseif ($tmp == 'NotConfigured') {
  263. print $langs->trans($tmp);
  264. } else {
  265. print $tmp;
  266. }
  267. print '</td>'."\n";
  268. print '<td class="center">';
  269. $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
  270. if (getDolGlobalString($constforvar) == $file) {
  271. print img_picto($langs->trans("Activated"), 'switch_on');
  272. } else {
  273. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  274. print img_picto($langs->trans("Disabled"), 'switch_off');
  275. print '</a>';
  276. }
  277. print '</td>';
  278. $mytmpinstance = new $myTmpObjectKey($db);
  279. $mytmpinstance->initAsSpecimen();
  280. // Info
  281. $htmltooltip = '';
  282. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  283. $nextval = $module->getNextValue($mytmpinstance);
  284. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  285. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  286. if ($nextval) {
  287. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  288. $nextval = $langs->trans($nextval);
  289. }
  290. $htmltooltip .= $nextval.'<br>';
  291. } else {
  292. $htmltooltip .= $langs->trans($module->error).'<br>';
  293. }
  294. }
  295. print '<td class="center">';
  296. print $form->textwithpicto('', $htmltooltip, 1, 0);
  297. print '</td>';
  298. print "</tr>\n";
  299. }
  300. }
  301. }
  302. closedir($handle);
  303. }
  304. }
  305. }
  306. print "</table><br>\n";
  307. }
  308. if ($myTmpObjectArray['includedocgeneration']) {
  309. /*
  310. * Document templates generators
  311. */
  312. $setupnotempty++;
  313. $type = strtolower($myTmpObjectKey);
  314. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  315. // Load array def with activated templates
  316. $def = array();
  317. $sql = "SELECT nom";
  318. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  319. $sql .= " WHERE type = '".$db->escape($type)."'";
  320. $sql .= " AND entity = ".$conf->entity;
  321. $resql = $db->query($sql);
  322. if ($resql) {
  323. $i = 0;
  324. $num_rows = $db->num_rows($resql);
  325. while ($i < $num_rows) {
  326. $array = $db->fetch_array($resql);
  327. array_push($def, $array[0]);
  328. $i++;
  329. }
  330. } else {
  331. dol_print_error($db);
  332. }
  333. print "<table class=\"noborder\" width=\"100%\">\n";
  334. print "<tr class=\"liste_titre\">\n";
  335. print '<td>'.$langs->trans("Name").'</td>';
  336. print '<td>'.$langs->trans("Description").'</td>';
  337. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  338. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  339. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  340. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  341. print "</tr>\n";
  342. clearstatcache();
  343. foreach ($dirmodels as $reldir) {
  344. foreach (array('', '/doc') as $valdir) {
  345. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  346. $dir = dol_buildpath($realpath);
  347. if (is_dir($dir)) {
  348. $handle = opendir($dir);
  349. if (is_resource($handle)) {
  350. while (($file = readdir($handle)) !== false) {
  351. $filelist[] = $file;
  352. }
  353. closedir($handle);
  354. arsort($filelist);
  355. foreach ($filelist as $file) {
  356. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  357. if (file_exists($dir.'/'.$file)) {
  358. $name = substr($file, 4, dol_strlen($file) - 16);
  359. $classname = substr($file, 0, dol_strlen($file) - 12);
  360. require_once $dir.'/'.$file;
  361. $module = new $classname($db);
  362. $modulequalified = 1;
  363. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  364. $modulequalified = 0;
  365. }
  366. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  367. $modulequalified = 0;
  368. }
  369. if ($modulequalified) {
  370. print '<tr class="oddeven"><td width="100">';
  371. print(empty($module->name) ? $name : $module->name);
  372. print "</td><td>\n";
  373. if (method_exists($module, 'info')) {
  374. print $module->info($langs);
  375. } else {
  376. print $module->description;
  377. }
  378. print '</td>';
  379. // Active
  380. if (in_array($name, $def)) {
  381. print '<td class="center">'."\n";
  382. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  383. print img_picto($langs->trans("Enabled"), 'switch_on');
  384. print '</a>';
  385. print '</td>';
  386. } else {
  387. print '<td class="center">'."\n";
  388. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  389. print "</td>";
  390. }
  391. // Default
  392. print '<td class="center">';
  393. $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
  394. if (getDolGlobalString($constforvar) == $name) {
  395. //print img_picto($langs->trans("Default"), 'on');
  396. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  397. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  398. } else {
  399. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  400. }
  401. print '</td>';
  402. // Info
  403. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  404. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  405. if ($module->type == 'pdf') {
  406. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  407. }
  408. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  409. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  410. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  411. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  412. print '<td class="center">';
  413. print $form->textwithpicto('', $htmltooltip, 1, 0);
  414. print '</td>';
  415. // Preview
  416. print '<td class="center">';
  417. if ($module->type == 'pdf') {
  418. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
  419. } else {
  420. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  421. }
  422. print '</td>';
  423. print "</tr>\n";
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. print '</table>';
  433. }
  434. }
  435. if (empty($setupnotempty)) {
  436. print '<br>'.$langs->trans("NothingToSetup");
  437. }
  438. // Page end
  439. print dol_get_fiche_end();
  440. llxFooter();
  441. $db->close();