dolibarr 21.0.0-beta
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
29// Libraries
30require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
31require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment.lib.php';
32require_once DOL_DOCUMENT_ROOT."/recruitment/class/recruitmentjobposition.class.php";
33
42// Translations
43$langs->loadLangs(array("admin", "recruitment"));
44
45// Access control
46if (!$user->admin) {
48}
49
50// Parameters
51$action = GETPOST('action', 'aZ09');
52$backtopage = GETPOST('backtopage', 'alpha');
53$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
54
55$value = GETPOST('value', 'alpha');
56$label = GETPOST('label', 'alpha');
57$scandir = GETPOST('scan_dir', 'alpha');
58$type = 'recruitmentcandidature';
59
60$arrayofparameters = array(
61// 'RECRUITMENT_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
62// 'RECRUITMENT_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
63);
64
65$error = 0;
66$setupnotempty = 0;
67
68$tmpobjectkey = GETPOST('object', 'aZ09');
69$moduledir = 'recruitment';
70$myTmpObjects = array();
71$myTmpObjects['recruitmentcandidature'] = array('label' => 'RecruitmentCandidature', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'RecruitmentCandidature');
72
73
74/*
75 * Actions
76 */
77
78include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
79
80if ($action == 'updateMask') {
81 $maskconst = GETPOST('maskconstcand', 'aZ09');
82 $maskvalue = GETPOST('maskcand', 'alpha');
83
84 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
85 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
86 }
87
88 if (!($res > 0)) {
89 $error++;
90 }
91
92 if (!$error) {
93 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
94 } else {
95 setEventMessages($langs->trans("Error"), null, 'errors');
96 }
97} elseif ($action == 'specimen' && $tmpobjectkey) {
98 $modele = GETPOST('module', 'alpha');
99
100 $className = $myTmpObjects[$tmpobjectkey]['class'];
101 $tmpobject = new $className($db);
102 $tmpobject->initAsSpecimen();
103
104 // Search template files
105 $file = '';
106 $classname = '';
107 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
108 foreach ($dirmodels as $reldir) {
109 $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
110 if (file_exists($file)) {
111 $classname = "pdf_".$modele;
112 break;
113 }
114 }
115
116 if ($classname !== '') {
117 require_once $file;
118
119 $module = new $classname($db);
120
121 '@phan-var-force ModelePDFRecruitmentCandidature $module';
122
123 if ($module->write_file($tmpobject, $langs) > 0) {
124 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
125 return;
126 } else {
127 setEventMessages($module->error, null, 'errors');
128 dol_syslog($module->error, LOG_ERR);
129 }
130 } else {
131 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
132 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
133 }
134} elseif ($action == 'set') {
135 // Activate a model
136 $ret = addDocumentModel($value, $type, $label, $scandir);
137} elseif ($action == 'del') {
138 $ret = delDocumentModel($value, $type);
139 if ($ret > 0) {
140 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
141 if (getDolGlobalString($constforval) == "$value") {
142 dolibarr_del_const($db, $constforval, $conf->entity);
143 }
144 }
145} elseif ($action == 'setmod') {
146 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
147 if (!empty($tmpobjectkey)) {
148 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
149
150 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
151 }
152} elseif ($action == 'setdoc') {
153 // Set default model
154 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
155 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
156 // The constant that was read before the new set
157 // We therefore requires a variable to have a coherent view
158 $conf->global->$constforval = $value;
159 }
160
161 // We disable/enable the document template (into llx_document_model table)
162 $ret = delDocumentModel($value, $type);
163 if ($ret > 0) {
164 $ret = addDocumentModel($value, $type, $label, $scandir);
165 }
166} elseif ($action == 'unsetdoc') {
167 if (!empty($tmpobjectkey)) {
168 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
169 dolibarr_del_const($db, $constforval, $conf->entity);
170 }
171}
172
173
174
175/*
176 * View
177 */
178
179$form = new Form($db);
180
181$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
182
183$page_name = "RecruitmentSetup";
184llxHeader('', $langs->trans($page_name));
185
186// Subheader
187$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
188
189print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
190
191// Configuration header
193print dol_get_fiche_head($head, 'settings_candidatures', '', -1, '');
194
195// Setup page goes here
196//echo '<span class="opacitymedium">'.$langs->trans("RecruitmentSetupPage").'</span><br><br>';
197
198
199if ($action == 'edit') {
200 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
201 print '<input type="hidden" name="token" value="'.newToken().'">';
202 print '<input type="hidden" name="action" value="update">';
203
204 print '<table class="noborder centpercent">';
205 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
206
207 foreach ($arrayofparameters as $key => $val) {
208 print '<tr class="oddeven"><td>';
209 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
210 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
211 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
212 }
213 print '</table>';
214
215 print '<br><div class="center">';
216 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
217 print '</div>';
218
219 print '</form>';
220 print '<br>';
221} else {
222 if (!empty($arrayofparameters)) {
223 print '<table class="noborder centpercent">';
224 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
225
226 foreach ($arrayofparameters as $key => $val) {
227 $setupnotempty++;
228
229 print '<tr class="oddeven"><td>';
230 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
231 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
232 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
233 }
234
235 print '</table>';
236
237 print '<div class="tabsAction">';
238 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
239 print '</div>';
240 }
241}
242
243
244foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
245 if ($myTmpObjectArray['includerefgeneration']) {
246 /*
247 * Orders Numbering model
248 */
249 $setupnotempty++;
250
251 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
252
253 print '<table class="noborder centpercent">';
254 print '<tr class="liste_titre">';
255 print '<td>'.$langs->trans("Name").'</td>';
256 print '<td>'.$langs->trans("Description").'</td>';
257 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
258 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
259 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
260 print '</tr>'."\n";
261
262 clearstatcache();
263
264 foreach ($dirmodels as $reldir) {
265 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
266
267 if (is_dir($dir)) {
268 $handle = opendir($dir);
269 if (is_resource($handle)) {
270 while (($file = readdir($handle)) !== false) {
271 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
272 $file = substr($file, 0, dol_strlen($file) - 4);
273
274 require_once $dir.'/'.$file.'.php';
275
276 $module = new $file($db);
277 '@phan-var-force ModeleNumRefRecruitmentCandidature $module';
278
279 // Show modules according to features level
280 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
281 continue;
282 }
283 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
284 continue;
285 }
286
287 if ($module->isEnabled()) {
288 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
289
290 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
291 print $module->info($langs);
292 print '</td>';
293
294 // Show example of numbering model
295 print '<td class="nowrap">';
296 $tmp = $module->getExample();
297 if (preg_match('/^Error/', $tmp)) {
298 $langs->load("errors");
299 print '<div class="error">'.$langs->trans($tmp).'</div>';
300 } elseif ($tmp == 'NotConfigured') {
301 print $langs->trans($tmp);
302 } else {
303 print $tmp;
304 }
305 print '</td>'."\n";
306
307 print '<td class="center">';
308 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
309 if (getDolGlobalString($constforvar) == $file) {
310 print img_picto($langs->trans("Activated"), 'switch_on');
311 } else {
312 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
313 print img_picto($langs->trans("Disabled"), 'switch_off');
314 print '</a>';
315 }
316 print '</td>';
317
318 $className = $myTmpObjectArray['class'];
319 $mytmpinstance = new $className($db);
320 $mytmpinstance->initAsSpecimen();
321
322 // Info
323 $htmltooltip = '';
324 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
325
326 $nextval = $module->getNextValue($mytmpinstance);
327 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
328 $htmltooltip .= ''.$langs->trans("NextValue").': ';
329 if ($nextval) {
330 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
331 $nextval = $langs->trans($nextval);
332 }
333 $htmltooltip .= $nextval.'<br>';
334 } else {
335 $htmltooltip .= $langs->trans($module->error).'<br>';
336 }
337 }
338
339 print '<td class="center">';
340 print $form->textwithpicto('', $htmltooltip, 1, 0);
341 print '</td>';
342
343 print "</tr>\n";
344 }
345 }
346 }
347 closedir($handle);
348 }
349 }
350 }
351 print "</table><br>\n";
352 }
353
354 if ($myTmpObjectArray['includedocgeneration']) {
355 /*
356 * Document templates generators
357 */
358 $setupnotempty++;
359 $type = strtolower($myTmpObjectKey);
360
361 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
362
363 // Load array def with activated templates
364 $def = array();
365 $sql = "SELECT nom";
366 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
367 $sql .= " WHERE type = '".$db->escape($type)."'";
368 $sql .= " AND entity = ".$conf->entity;
369 $resql = $db->query($sql);
370 if ($resql) {
371 $i = 0;
372 $num_rows = $db->num_rows($resql);
373 while ($i < $num_rows) {
374 $array = $db->fetch_array($resql);
375 if (is_array($array)) {
376 array_push($def, $array[0]);
377 }
378 $i++;
379 }
380 } else {
381 dol_print_error($db);
382 }
383
384
385 print "<table class=\"noborder\" width=\"100%\">\n";
386 print "<tr class=\"liste_titre\">\n";
387 print '<td>'.$langs->trans("Name").'</td>';
388 print '<td>'.$langs->trans("Description").'</td>';
389 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
390 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
391 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
392 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
393 print "</tr>\n";
394
395 clearstatcache();
396 $filelist = array();
397
398 foreach ($dirmodels as $reldir) {
399 foreach (array('', '/doc') as $valdir) {
400 $realpath = $reldir."core/modules/".$moduledir.$valdir;
401 $dir = dol_buildpath($realpath);
402
403 if (is_dir($dir)) {
404 $handle = opendir($dir);
405 if (is_resource($handle)) {
406 while (($file = readdir($handle)) !== false) {
407 $filelist[] = $file;
408 }
409 closedir($handle);
410 arsort($filelist);
411
412 foreach ($filelist as $file) {
413 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
414 if (file_exists($dir.'/'.$file)) {
415 $name = substr($file, 4, dol_strlen($file) - 16);
416 $classname = substr($file, 0, dol_strlen($file) - 12);
417
418 require_once $dir.'/'.$file;
419 $module = new $classname($db);
420 '@phan-var-force ModelePDFRecruitmentJobPosition $module';
421
422 $modulequalified = 1;
423 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
424 $modulequalified = 0;
425 }
426 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
427 $modulequalified = 0;
428 }
429
430 if ($modulequalified) {
431 print '<tr class="oddeven"><td width="100">';
432 print(empty($module->name) ? $name : $module->name);
433 print "</td><td>\n";
434 if (method_exists($module, 'info')) {
435 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
436 } else {
437 print $module->description;
438 }
439 print '</td>';
440
441 // Active
442 if (in_array($name, $def)) {
443 print '<td class="center">'."\n";
444 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
445 print img_picto($langs->trans("Enabled"), 'switch_on');
446 print '</a>';
447 print '</td>';
448 } else {
449 print '<td class="center">'."\n";
450 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>';
451 print "</td>";
452 }
453
454 // Default
455 print '<td class="center">';
456 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
457 if (getDolGlobalString($constforvar) == $name) {
458 //print img_picto($langs->trans("Default"), 'on');
459 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
460 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>';
461 } else {
462 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>';
463 }
464 print '</td>';
465
466 // Info
467 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
468 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
469 if ($module->type == 'pdf') {
470 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
471 }
472 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
473
474 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
475 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
476 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
477
478 print '<td class="center">';
479 print $form->textwithpicto('', $htmltooltip, 1, 0);
480 print '</td>';
481
482 // Preview
483 print '<td class="center">';
484 if ($module->type == 'pdf') {
485 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
486 } else {
487 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
488 }
489 print '</td>';
490
491 print "</tr>\n";
492 }
493 }
494 }
495 }
496 }
497 }
498 }
499 }
500
501 print '</table>';
502 }
503}
504
505if (empty($setupnotempty)) {
506 print '<br>'.$langs->trans("NothingToSetup");
507}
508
509// Page end
510print dol_get_fiche_end();
511
512llxFooter();
513$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:71
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
recruitmentAdminPrepareHead()
Prepare admin pages header.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.