dolibarr 20.0.0
setup_candidatures.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28
29global $conf, $langs, $user;
30
31// Libraries
32require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
33require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment.lib.php';
34require_once DOL_DOCUMENT_ROOT."/recruitment/class/recruitmentjobposition.class.php";
35
36// Translations
37$langs->loadLangs(array("admin", "recruitment"));
38
39// Access control
40if (!$user->admin) {
42}
43
44// Parameters
45$action = GETPOST('action', 'aZ09');
46$backtopage = GETPOST('backtopage', 'alpha');
47$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
48
49$value = GETPOST('value', 'alpha');
50$label = GETPOST('label', 'alpha');
51$scandir = GETPOST('scan_dir', 'alpha');
52$type = 'recruitmentcandidature';
53
54$arrayofparameters = array(
55// 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
56// 'RECRUITMENT_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
57);
58
59$error = 0;
60$setupnotempty = 0;
61
62$tmpobjectkey = GETPOST('object', 'aZ09');
63$moduledir = 'recruitment';
64$myTmpObjects = array();
65$myTmpObjects['recruitmentcandidature'] = array('label' => 'RecruitmentCandidature', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'RecruitmentCandidature');
66
67
68/*
69 * Actions
70 */
71
72include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
73
74if ($action == 'updateMask') {
75 $maskconst = GETPOST('maskconstcand', 'aZ09');
76 $maskvalue = GETPOST('maskcand', 'alpha');
77
78 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
79 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
80 }
81
82 if (!($res > 0)) {
83 $error++;
84 }
85
86 if (!$error) {
87 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88 } else {
89 setEventMessages($langs->trans("Error"), null, 'errors');
90 }
91} elseif ($action == 'specimen' && $tmpobjectkey) {
92 $modele = GETPOST('module', 'alpha');
93
94 $className = $myTmpObjects[$tmpobjectkey]['class'];
95 $tmpobject = new $className($db);
96 $tmpobject->initAsSpecimen();
97
98 // Search template files
99 $file = '';
100 $classname = '';
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 $classname = "pdf_".$modele;
106 break;
107 }
108 }
109
110 if ($classname !== '') {
111 require_once $file;
112
113 $module = new $classname($db);
114
115 if ($module->write_file($tmpobject, $langs) > 0) {
116 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
117 return;
118 } else {
119 setEventMessages($module->error, null, 'errors');
120 dol_syslog($module->error, LOG_ERR);
121 }
122 } else {
123 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
124 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
125 }
126} elseif ($action == 'set') {
127 // Activate a model
128 $ret = addDocumentModel($value, $type, $label, $scandir);
129} elseif ($action == 'del') {
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 if (!empty($tmpobjectkey)) {
140 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
141
142 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
143 }
144} elseif ($action == 'setdoc') {
145 // Set default model
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
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 if (!empty($tmpobjectkey)) {
160 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
161 dolibarr_del_const($db, $constforval, $conf->entity);
162 }
163}
164
165
166
167/*
168 * View
169 */
170
171$form = new Form($db);
172
173$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
174
175$page_name = "RecruitmentSetup";
176llxHeader('', $langs->trans($page_name));
177
178// Subheader
179$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
180
181print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
182
183// Configuration header
185print dol_get_fiche_head($head, 'settings_candidatures', '', -1, '');
186
187// Setup page goes here
188//echo '<span class="opacitymedium">'.$langs->trans("RecruitmentSetupPage").'</span><br><br>';
189
190
191if ($action == 'edit') {
192 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
193 print '<input type="hidden" name="token" value="'.newToken().'">';
194 print '<input type="hidden" name="action" value="update">';
195
196 print '<table class="noborder centpercent">';
197 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
198
199 foreach ($arrayofparameters as $key => $val) {
200 print '<tr class="oddeven"><td>';
201 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
202 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
203 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
204 }
205 print '</table>';
206
207 print '<br><div class="center">';
208 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
209 print '</div>';
210
211 print '</form>';
212 print '<br>';
213} else {
214 if (!empty($arrayofparameters)) {
215 print '<table class="noborder centpercent">';
216 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
217
218 foreach ($arrayofparameters as $key => $val) {
219 $setupnotempty++;
220
221 print '<tr class="oddeven"><td>';
222 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
223 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
224 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
225 }
226
227 print '</table>';
228
229 print '<div class="tabsAction">';
230 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
231 print '</div>';
232 }
233}
234
235
236foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
237 if ($myTmpObjectArray['includerefgeneration']) {
238 /*
239 * Orders Numbering model
240 */
241 $setupnotempty++;
242
243 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
244
245 print '<table class="noborder centpercent">';
246 print '<tr class="liste_titre">';
247 print '<td>'.$langs->trans("Name").'</td>';
248 print '<td>'.$langs->trans("Description").'</td>';
249 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
250 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
251 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
252 print '</tr>'."\n";
253
254 clearstatcache();
255
256 foreach ($dirmodels as $reldir) {
257 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
258
259 if (is_dir($dir)) {
260 $handle = opendir($dir);
261 if (is_resource($handle)) {
262 while (($file = readdir($handle)) !== false) {
263 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
264 $file = substr($file, 0, dol_strlen($file) - 4);
265
266 require_once $dir.'/'.$file.'.php';
267
268 $module = new $file($db);
269
270 // Show modules according to features level
271 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
272 continue;
273 }
274 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
275 continue;
276 }
277
278 if ($module->isEnabled()) {
279 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
280
281 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
282 print $module->info($langs);
283 print '</td>';
284
285 // Show example of numbering model
286 print '<td class="nowrap">';
287 $tmp = $module->getExample();
288 if (preg_match('/^Error/', $tmp)) {
289 $langs->load("errors");
290 print '<div class="error">'.$langs->trans($tmp).'</div>';
291 } elseif ($tmp == 'NotConfigured') {
292 print $langs->trans($tmp);
293 } else {
294 print $tmp;
295 }
296 print '</td>'."\n";
297
298 print '<td class="center">';
299 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
300 if (getDolGlobalString($constforvar) == $file) {
301 print img_picto($langs->trans("Activated"), 'switch_on');
302 } else {
303 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
304 print img_picto($langs->trans("Disabled"), 'switch_off');
305 print '</a>';
306 }
307 print '</td>';
308
309 $className = $myTmpObjectArray['class'];
310 $mytmpinstance = new $className($db);
311 $mytmpinstance->initAsSpecimen();
312
313 // Info
314 $htmltooltip = '';
315 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
316
317 $nextval = $module->getNextValue($mytmpinstance);
318 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
319 $htmltooltip .= ''.$langs->trans("NextValue").': ';
320 if ($nextval) {
321 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
322 $nextval = $langs->trans($nextval);
323 }
324 $htmltooltip .= $nextval.'<br>';
325 } else {
326 $htmltooltip .= $langs->trans($module->error).'<br>';
327 }
328 }
329
330 print '<td class="center">';
331 print $form->textwithpicto('', $htmltooltip, 1, 0);
332 print '</td>';
333
334 print "</tr>\n";
335 }
336 }
337 }
338 closedir($handle);
339 }
340 }
341 }
342 print "</table><br>\n";
343 }
344
345 if ($myTmpObjectArray['includedocgeneration']) {
346 /*
347 * Document templates generators
348 */
349 $setupnotempty++;
350 $type = strtolower($myTmpObjectKey);
351
352 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
353
354 // Load array def with activated templates
355 $def = array();
356 $sql = "SELECT nom";
357 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
358 $sql .= " WHERE type = '".$db->escape($type)."'";
359 $sql .= " AND entity = ".$conf->entity;
360 $resql = $db->query($sql);
361 if ($resql) {
362 $i = 0;
363 $num_rows = $db->num_rows($resql);
364 while ($i < $num_rows) {
365 $array = $db->fetch_array($resql);
366 if (is_array($array)) {
367 array_push($def, $array[0]);
368 }
369 $i++;
370 }
371 } else {
372 dol_print_error($db);
373 }
374
375
376 print "<table class=\"noborder\" width=\"100%\">\n";
377 print "<tr class=\"liste_titre\">\n";
378 print '<td>'.$langs->trans("Name").'</td>';
379 print '<td>'.$langs->trans("Description").'</td>';
380 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
381 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
382 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
383 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
384 print "</tr>\n";
385
386 clearstatcache();
387 $filelist = array();
388
389 foreach ($dirmodels as $reldir) {
390 foreach (array('', '/doc') as $valdir) {
391 $realpath = $reldir."core/modules/".$moduledir.$valdir;
392 $dir = dol_buildpath($realpath);
393
394 if (is_dir($dir)) {
395 $handle = opendir($dir);
396 if (is_resource($handle)) {
397 while (($file = readdir($handle)) !== false) {
398 $filelist[] = $file;
399 }
400 closedir($handle);
401 arsort($filelist);
402
403 foreach ($filelist as $file) {
404 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
405 if (file_exists($dir.'/'.$file)) {
406 $name = substr($file, 4, dol_strlen($file) - 16);
407 $classname = substr($file, 0, dol_strlen($file) - 12);
408
409 require_once $dir.'/'.$file;
410 $module = new $classname($db);
411
412 $modulequalified = 1;
413 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
414 $modulequalified = 0;
415 }
416 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
417 $modulequalified = 0;
418 }
419
420 if ($modulequalified) {
421 print '<tr class="oddeven"><td width="100">';
422 print(empty($module->name) ? $name : $module->name);
423 print "</td><td>\n";
424 if (method_exists($module, 'info')) {
425 print $module->info($langs);
426 } else {
427 print $module->description;
428 }
429 print '</td>';
430
431 // Active
432 if (in_array($name, $def)) {
433 print '<td class="center">'."\n";
434 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
435 print img_picto($langs->trans("Enabled"), 'switch_on');
436 print '</a>';
437 print '</td>';
438 } else {
439 print '<td class="center">'."\n";
440 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>';
441 print "</td>";
442 }
443
444 // Default
445 print '<td class="center">';
446 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
447 if (getDolGlobalString($constforvar) == $name) {
448 //print img_picto($langs->trans("Default"), 'on');
449 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
450 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>';
451 } else {
452 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>';
453 }
454 print '</td>';
455
456 // Info
457 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
458 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
459 if ($module->type == 'pdf') {
460 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
461 }
462 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
463
464 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
465 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
466 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
467
468 print '<td class="center">';
469 print $form->textwithpicto('', $htmltooltip, 1, 0);
470 print '</td>';
471
472 // Preview
473 print '<td class="center">';
474 if ($module->type == 'pdf') {
475 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
476 } else {
477 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
478 }
479 print '</td>';
480
481 print "</tr>\n";
482 }
483 }
484 }
485 }
486 }
487 }
488 }
489 }
490
491 print '</table>';
492 }
493}
494
495if (empty($setupnotempty)) {
496 print '<br>'.$langs->trans("NothingToSetup");
497}
498
499// Page end
500print dol_get_fiche_end();
501
502llxFooter();
503$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
recruitmentAdminPrepareHead()
Prepare admin pages header.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.