dolibarr 21.0.0-alpha
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 '@phan-var-force ModeleNumRefRecruitmentCandidature $module';
270
271 // Show modules according to features level
272 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
273 continue;
274 }
275 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
276 continue;
277 }
278
279 if ($module->isEnabled()) {
280 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
281
282 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
283 print $module->info($langs);
284 print '</td>';
285
286 // Show example of numbering model
287 print '<td class="nowrap">';
288 $tmp = $module->getExample();
289 if (preg_match('/^Error/', $tmp)) {
290 $langs->load("errors");
291 print '<div class="error">'.$langs->trans($tmp).'</div>';
292 } elseif ($tmp == 'NotConfigured') {
293 print $langs->trans($tmp);
294 } else {
295 print $tmp;
296 }
297 print '</td>'."\n";
298
299 print '<td class="center">';
300 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
301 if (getDolGlobalString($constforvar) == $file) {
302 print img_picto($langs->trans("Activated"), 'switch_on');
303 } else {
304 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
305 print img_picto($langs->trans("Disabled"), 'switch_off');
306 print '</a>';
307 }
308 print '</td>';
309
310 $className = $myTmpObjectArray['class'];
311 $mytmpinstance = new $className($db);
312 $mytmpinstance->initAsSpecimen();
313
314 // Info
315 $htmltooltip = '';
316 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
317
318 $nextval = $module->getNextValue($mytmpinstance);
319 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
320 $htmltooltip .= ''.$langs->trans("NextValue").': ';
321 if ($nextval) {
322 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
323 $nextval = $langs->trans($nextval);
324 }
325 $htmltooltip .= $nextval.'<br>';
326 } else {
327 $htmltooltip .= $langs->trans($module->error).'<br>';
328 }
329 }
330
331 print '<td class="center">';
332 print $form->textwithpicto('', $htmltooltip, 1, 0);
333 print '</td>';
334
335 print "</tr>\n";
336 }
337 }
338 }
339 closedir($handle);
340 }
341 }
342 }
343 print "</table><br>\n";
344 }
345
346 if ($myTmpObjectArray['includedocgeneration']) {
347 /*
348 * Document templates generators
349 */
350 $setupnotempty++;
351 $type = strtolower($myTmpObjectKey);
352
353 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
354
355 // Load array def with activated templates
356 $def = array();
357 $sql = "SELECT nom";
358 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
359 $sql .= " WHERE type = '".$db->escape($type)."'";
360 $sql .= " AND entity = ".$conf->entity;
361 $resql = $db->query($sql);
362 if ($resql) {
363 $i = 0;
364 $num_rows = $db->num_rows($resql);
365 while ($i < $num_rows) {
366 $array = $db->fetch_array($resql);
367 if (is_array($array)) {
368 array_push($def, $array[0]);
369 }
370 $i++;
371 }
372 } else {
373 dol_print_error($db);
374 }
375
376
377 print "<table class=\"noborder\" width=\"100%\">\n";
378 print "<tr class=\"liste_titre\">\n";
379 print '<td>'.$langs->trans("Name").'</td>';
380 print '<td>'.$langs->trans("Description").'</td>';
381 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
382 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
383 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
384 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
385 print "</tr>\n";
386
387 clearstatcache();
388 $filelist = array();
389
390 foreach ($dirmodels as $reldir) {
391 foreach (array('', '/doc') as $valdir) {
392 $realpath = $reldir."core/modules/".$moduledir.$valdir;
393 $dir = dol_buildpath($realpath);
394
395 if (is_dir($dir)) {
396 $handle = opendir($dir);
397 if (is_resource($handle)) {
398 while (($file = readdir($handle)) !== false) {
399 $filelist[] = $file;
400 }
401 closedir($handle);
402 arsort($filelist);
403
404 foreach ($filelist as $file) {
405 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
406 if (file_exists($dir.'/'.$file)) {
407 $name = substr($file, 4, dol_strlen($file) - 16);
408 $classname = substr($file, 0, dol_strlen($file) - 12);
409
410 require_once $dir.'/'.$file;
411 $module = new $classname($db);
412 '@phan-var-force ModelePDFRecruitmentJobPosition $module';
413
414 $modulequalified = 1;
415 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
416 $modulequalified = 0;
417 }
418 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
419 $modulequalified = 0;
420 }
421
422 if ($modulequalified) {
423 print '<tr class="oddeven"><td width="100">';
424 print(empty($module->name) ? $name : $module->name);
425 print "</td><td>\n";
426 if (method_exists($module, 'info')) {
427 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
428 } else {
429 print $module->description;
430 }
431 print '</td>';
432
433 // Active
434 if (in_array($name, $def)) {
435 print '<td class="center">'."\n";
436 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
437 print img_picto($langs->trans("Enabled"), 'switch_on');
438 print '</a>';
439 print '</td>';
440 } else {
441 print '<td class="center">'."\n";
442 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>';
443 print "</td>";
444 }
445
446 // Default
447 print '<td class="center">';
448 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
449 if (getDolGlobalString($constforvar) == $name) {
450 //print img_picto($langs->trans("Default"), 'on');
451 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
452 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>';
453 } else {
454 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>';
455 }
456 print '</td>';
457
458 // Info
459 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
460 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
461 if ($module->type == 'pdf') {
462 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
463 }
464 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
465
466 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
467 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
468 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
469
470 print '<td class="center">';
471 print $form->textwithpicto('', $htmltooltip, 1, 0);
472 print '</td>';
473
474 // Preview
475 print '<td class="center">';
476 if ($module->type == 'pdf') {
477 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
478 } else {
479 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
480 }
481 print '</td>';
482
483 print "</tr>\n";
484 }
485 }
486 }
487 }
488 }
489 }
490 }
491 }
492
493 print '</table>';
494 }
495}
496
497if (empty($setupnotempty)) {
498 print '<br>'.$langs->trans("NothingToSetup");
499}
500
501// Page end
502print dol_get_fiche_end();
503
504llxFooter();
505$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a 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:140
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.