setup_candidatures.php 18 KB

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