dolibarr 20.0.0
setup.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 = 'recruitmentjobposition';
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$moduledir = 'recruitment';
63$myTmpObjects = array();
64$myTmpObjects['recruitmentjobposition'] = array('label' => 'RecruitmentJobPosition', 'includerefgeneration' => 1, 'includedocgeneration' => 1, 'class' => 'RecruitmentJobPosition');
65
66$tmpobjectkey = GETPOST('object', 'aZ09');
67if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
68 accessforbidden('Bad value for object. Hack attempt ?');
69}
70
71
72/*
73 * Actions
74 */
75
76include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
77
78if ($action == 'updateMask') {
79 $maskconst = GETPOST('maskconstjob', 'alpha');
80 $maskvalue = GETPOST('maskjob', 'alpha');
81
82 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
83 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
84 }
85
86 if (!($res > 0)) {
87 $error++;
88 }
89
90 if (!$error) {
91 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
92 } else {
93 setEventMessages($langs->trans("Error"), null, 'errors');
94 }
95} elseif ($action == 'specimen' && $tmpobjectkey) {
96 $modele = GETPOST('module', 'alpha');
97
98 $className = $myTmpObjects[$tmpobjectkey]['class'];
99 $tmpobject = new $className($db);
100 $tmpobject->initAsSpecimen();
101
102 // Search template files
103 $file = '';
104 $classname = '';
105 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
106 foreach ($dirmodels as $reldir) {
107 $file = dol_buildpath($reldir."core/modules/recruitment/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
108 if (file_exists($file)) {
109 $classname = "pdf_".$modele."_".strtolower($tmpobjectkey);
110 break;
111 }
112 }
113
114 if ($classname !== '') {
115 require_once $file;
116
117 $module = new $classname($db);
118
119 if ($module->write_file($tmpobject, $langs) > 0) {
120 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=recruitment-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
121 return;
122 } else {
123 setEventMessages($module->error, null, 'errors');
124 dol_syslog($module->error, LOG_ERR);
125 }
126 } else {
127 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
128 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
129 }
130} elseif ($action == 'set') {
131 // Activate a model
132 $ret = addDocumentModel($value, $type, $label, $scandir);
133} elseif ($action == 'del') {
134 $ret = delDocumentModel($value, $type);
135 if ($ret > 0) {
136 if (!empty($tmpobjectkey)) {
137 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
138 if (getDolGlobalString($constforval) == "$value") {
139 dolibarr_del_const($db, $constforval, $conf->entity);
140 }
141 }
142 }
143} elseif ($action == 'setmod') {
144 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
145 if (!empty($tmpobjectkey)) {
146 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey)."_ADDON";
147
148 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
149 }
150} elseif ($action == 'setdoc') {
151 // Set default model
152 if (!empty($tmpobjectkey)) {
153 $constforval = 'RECRUITMENT_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
154 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
155 // The constant that was read before the new set
156 // We therefore requires a variable to have a coherent view
157 $conf->global->$constforval = $value;
158 }
159
160 // We disable/enable the document template (into llx_document_model table)
161 $ret = delDocumentModel($value, $type);
162 if ($ret > 0) {
163 $ret = addDocumentModel($value, $type, $label, $scandir);
164 }
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', '', -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 require_once $dir.'/'.$file.'.php';
274
275 $module = new $file($db);
276
277 // Show modules according to features level
278 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
279 continue;
280 }
281 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
282 continue;
283 }
284
285 if ($module->isEnabled()) {
286 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
287
288 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
289 print $module->info($langs);
290 print '</td>';
291
292 // Show example of numbering model
293 print '<td class="nowrap">';
294 $tmp = $module->getExample();
295 if (preg_match('/^Error/', $tmp)) {
296 $langs->load("errors");
297 print '<div class="error">'.$langs->trans($tmp).'</div>';
298 } elseif ($tmp == 'NotConfigured') {
299 print $langs->trans($tmp);
300 } else {
301 print $tmp;
302 }
303 print '</td>'."\n";
304
305 print '<td class="center">';
306 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON';
307 if (getDolGlobalString($constforvar) == $file) {
308 print img_picto($langs->trans("Activated"), 'switch_on');
309 } else {
310 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
311 print img_picto($langs->trans("Disabled"), 'switch_off');
312 print '</a>';
313 }
314 print '</td>';
315
316 $className = $myTmpObjectArray['class'];
317 $mytmpinstance = new $className($db);
318 $mytmpinstance->initAsSpecimen();
319
320 // Info
321 $htmltooltip = '';
322 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
323
324 $nextval = $module->getNextValue($mytmpinstance);
325 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
326 $htmltooltip .= ''.$langs->trans("NextValue").': ';
327 if ($nextval) {
328 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
329 $nextval = $langs->trans($nextval);
330 }
331 $htmltooltip .= $nextval.'<br>';
332 } else {
333 $htmltooltip .= $langs->trans($module->error).'<br>';
334 }
335 }
336
337 print '<td class="center">';
338 print $form->textwithpicto('', $htmltooltip, 1, 0);
339 print '</td>';
340
341 print "</tr>\n";
342 }
343 }
344 }
345 closedir($handle);
346 }
347 }
348 }
349 print "</table><br>\n";
350 }
351
352 if ($myTmpObjectArray['includedocgeneration']) {
353 /*
354 * Document templates generators
355 */
356 $setupnotempty++;
357 $type = strtolower($myTmpObjectKey);
358
359 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
360
361 // Load array def with activated templates
362 $def = array();
363 $sql = "SELECT nom";
364 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
365 $sql .= " WHERE type = '".$db->escape($type)."'";
366 $sql .= " AND entity = ".$conf->entity;
367 $resql = $db->query($sql);
368 if ($resql) {
369 $i = 0;
370 $num_rows = $db->num_rows($resql);
371 while ($i < $num_rows) {
372 $array = $db->fetch_array($resql);
373 if (is_array($array)) {
374 array_push($def, $array[0]);
375 }
376 $i++;
377 }
378 } else {
379 dol_print_error($db);
380 }
381
382
383 print "<table class=\"noborder\" width=\"100%\">\n";
384 print "<tr class=\"liste_titre\">\n";
385 print '<td>'.$langs->trans("Name").'</td>';
386 print '<td>'.$langs->trans("Description").'</td>';
387 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
388 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
389 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
390 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
391 print "</tr>\n";
392
393 clearstatcache();
394 $filelist = array();
395
396 foreach ($dirmodels as $reldir) {
397 foreach (array('', '/doc') as $valdir) {
398 $realpath = $reldir."core/modules/".$moduledir.$valdir;
399 $dir = dol_buildpath($realpath);
400
401 if (is_dir($dir)) {
402 $handle = opendir($dir);
403 if (is_resource($handle)) {
404 while (($file = readdir($handle)) !== false) {
405 $filelist[] = $file;
406 }
407 closedir($handle);
408 arsort($filelist);
409
410 foreach ($filelist as $file) {
411 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
412 if (file_exists($dir.'/'.$file)) {
413 $name = substr($file, 4, dol_strlen($file) - 16);
414 $classname = substr($file, 0, dol_strlen($file) - 12);
415
416 require_once $dir.'/'.$file;
417 $module = new $classname($db);
418
419 $modulequalified = 1;
420 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
421 $modulequalified = 0;
422 }
423 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
424 $modulequalified = 0;
425 }
426
427 if ($modulequalified) {
428 print '<tr class="oddeven"><td width="100">';
429 print(empty($module->name) ? $name : $module->name);
430 print "</td><td>\n";
431 if (method_exists($module, 'info')) {
432 print $module->info($langs);
433 } else {
434 print $module->description;
435 }
436 print '</td>';
437
438 // Active
439 if (in_array($name, $def)) {
440 print '<td class="center">'."\n";
441 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
442 print img_picto($langs->trans("Enabled"), 'switch_on');
443 print '</a>';
444 print '</td>';
445 } else {
446 print '<td class="center">'."\n";
447 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>';
448 print "</td>";
449 }
450
451 // Default
452 print '<td class="center">';
453 $constforvar = 'RECRUITMENT_'.strtoupper($myTmpObjectKey).'_ADDON_PDF';
454 if (getDolGlobalString($constforvar) == $name) {
455 //print img_picto($langs->trans("Default"), 'on');
456 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
457 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>';
458 } else {
459 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&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>';
460 }
461 print '</td>';
462
463 // Info
464 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
465 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
466 if ($module->type == 'pdf') {
467 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
468 }
469 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
470
471 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
472 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
473 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
474
475 print '<td class="center">';
476 print $form->textwithpicto('', $htmltooltip, 1, 0);
477 print '</td>';
478
479 // Preview
480 print '<td class="center">';
481 if ($module->type == 'pdf') {
482 $newname = preg_replace('/_'.preg_quote(strtolower($myTmpObjectKey), '/').'/', '', $name);
483 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($newname).'&object='.urlencode($myTmpObjectKey).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
484 } else {
485 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
486 }
487 print '</td>';
488
489 print "</tr>\n";
490 }
491 }
492 }
493 }
494 }
495 }
496 }
497 }
498
499 print '</table>';
500 }
501}
502
503if (empty($setupnotempty)) {
504 print '<br>'.$langs->trans("NothingToSetup");
505}
506
507// Page end
508print dol_get_fiche_end();
509
510llxFooter();
511$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:140
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.