dolibarr 20.0.2
workstation.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require "../main.inc.php";
29
30// Libraries
31require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
32require_once DOL_DOCUMENT_ROOT.'/workstation/lib/workstation.lib.php';
33//require_once "../class/myclass.class.php";
34
35// Translations
36$langs->loadLangs(array("admin", "workstation"));
37
38// Parameters
39$action = GETPOST('action', 'aZ09');
40$backtopage = GETPOST('backtopage', 'alpha');
41$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
42
43$value = GETPOST('value', 'alpha');
44
45$error = 0;
46$setupnotempty = 0;
47
48$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
49
50// Access control
51if (!$user->admin) {
53}
54
55$moduledir = 'workstation';
56$myTmpObjects = array();
57$myTmpObjects['workstation'] = array('label' => 'Workstation', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'Workstation');
58
59$tmpobjectkey = GETPOST('object', 'aZ09');
60if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
61 accessforbidden('Bad value for object. Hack attempt ?');
62}
63
64
65/*
66 * Actions
67 */
68
69include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
70
71if ($action == 'updateMask') {
72 $maskconst = GETPOST('maskconstWorkstation', 'aZ09');
73 $maskorder = GETPOST('maskWorkstation', 'alpha');
74
75 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
76 $res = dolibarr_set_const($db, $maskconst, $maskorder, 'chaine', 0, '', $conf->entity);
77 }
78
79 if (!($res > 0)) {
80 $error++;
81 }
82
83 if (!$error) {
84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
85 } else {
86 setEventMessages($langs->trans("Error"), null, 'errors');
87 }
88} elseif ($action == 'specimen') {
89 $modele = GETPOST('module', 'alpha');
90
91 $nameofclass = ucfirst($tmpobjectkey);
92 $tmpobject = new $nameofclass($db);
93 $tmpobject->initAsSpecimen();
94
95 // Search template files
96 $file = '';
97 $classname = '';
98 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
99 foreach ($dirmodels as $reldir) {
100 $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
101 if (file_exists($file)) {
102 $classname = "pdf_".$modele;
103 break;
104 }
105 }
106
107 if ($classname !== '') {
108 require_once $file;
109
110 $module = new $classname($db);
111 '@phan-var-force CommonDocGenerator $module';
112
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 $ret = delDocumentModel($value, $type);
129 if ($ret > 0) {
130 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
131 if (getDolGlobalString($constforval) == "$value") {
132 dolibarr_del_const($db, $constforval, $conf->entity);
133 }
134 }
135} elseif ($action == 'setdoc') {
136 // Set default model
137 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
138 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
139 // The constant that was read before the new set
140 // We therefore requires a variable to have a coherent view
141 $conf->global->$constforval = $value;
142 }
143
144 // On active le modele
145 $ret = delDocumentModel($value, $type);
146 if ($ret > 0) {
147 $ret = addDocumentModel($value, $type, $label, $scandir);
148 }
149} elseif ($action == 'setmod') {
150 // TODO Check if numbering module chosen can be activated
151 // by calling method canBeActivated
152 $constforval = 'WORKSTATION_'.strtoupper($tmpobjectkey)."_ADDON";
153 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
154}
155
156
157
158/*
159 * View
160 */
161
162$form = new Form($db);
163
164$help_url = '';
165$page_name = "WorkstationSetup";
166
167llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-admin page-workstation');
168
169// Subheader
170$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
171
172print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
173
174// Configuration header
176print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "workstation");
177
178// Setup page goes here
179//echo '<span class="opacitymedium">'.$langs->trans("WorkstationSetupPage").'</span><br><br>';
180
181
182if ($action == 'edit') {
183 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
184 print '<input type="hidden" name="token" value="'.newToken().'">';
185 print '<input type="hidden" name="action" value="update">';
186
187 print '<table class="noborder centpercent">';
188 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
189
190 foreach ($arrayofparameters as $key => $val) {
191 print '<tr class="oddeven"><td>';
192 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
193 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
194 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
195 }
196 print '</table>';
197
198 print '<br><div class="center">';
199 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
200 print '</div>';
201
202 print '</form>';
203 print '<br>';
204} else {
205 if (!empty($arrayofparameters)) {
206 print '<table class="noborder centpercent">';
207 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
208
209 foreach ($arrayofparameters as $key => $val) {
210 $setupnotempty++;
211
212 print '<tr class="oddeven"><td>';
213 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
214 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
215 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
216 }
217
218 print '</table>';
219
220 print '<div class="tabsAction">';
221 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
222 print '</div>';
223 }/* else {
224 print '<br>'.$langs->trans("NothingToSetup");
225 }*/
226}
227
228
229foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
230 if ($myTmpObjectKey == 'MyObject') {
231 continue;
232 }
233 if ($myTmpObjectArray['includerefgeneration']) {
234 /*
235 * Orders Numbering model
236 */
237 $setupnotempty++;
238
239 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
240
241 print '<table class="noborder centpercent">';
242 print '<tr class="liste_titre">';
243 print '<td>'.$langs->trans("Name").'</td>';
244 print '<td>'.$langs->trans("Description").'</td>';
245 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
246 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
247 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
248 print '</tr>'."\n";
249
250 clearstatcache();
251
252 foreach ($dirmodels as $reldir) {
253 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
254
255 if (is_dir($dir)) {
256 $handle = opendir($dir);
257 if (is_resource($handle)) {
258 while (($file = readdir($handle)) !== false) {
259 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
260 $file = substr($file, 0, dol_strlen($file) - 4);
261
262 require_once $dir.'/'.$file.'.php';
263
264 $module = new $file($db);
265 '@phan-var-force CommonNumRefGenerator $module';
266
267 // Show modules according to features level
268 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
269 continue;
270 }
271 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
272 continue;
273 }
274
275 if ($module->isEnabled()) {
276 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
277
278 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
279 print $module->info($langs);
280 print '</td>';
281
282 // Show example of numbering model
283 print '<td class="nowrap">';
284 $tmp = $module->getExample();
285 if (preg_match('/^Error/', $tmp)) {
286 $langs->load("errors");
287 print '<div class="error">'.$langs->trans($tmp).'</div>';
288 } elseif ($tmp == 'NotConfigured') {
289 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
290 } else {
291 print $tmp;
292 }
293 print '</td>'."\n";
294
295 print '<td class="center">';
296 $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
297 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $file) {
298 print img_picto($langs->trans("Activated"), 'switch_on');
299 } else {
300 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
301 print img_picto($langs->trans("Disabled"), 'switch_off');
302 print '</a>';
303 }
304 print '</td>';
305
306 $nameofclass = ucfirst($myTmpObjectKey);
307 $mytmpinstance = new $nameofclass($db);
308 $mytmpinstance->initAsSpecimen();
309
310 // Info
311 $htmltooltip = '';
312 $htmltooltip .= $langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
313
314 $nextval = $module->getNextValue($mytmpinstance);
315 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
316 $htmltooltip .= ''.$langs->trans("NextValue").': ';
317 if ($nextval) {
318 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
319 $nextval = $langs->trans($nextval);
320 }
321 $htmltooltip .= $nextval.'<br>';
322 } else {
323 $htmltooltip .= $langs->trans($module->error).'<br>';
324 }
325 }
326
327 print '<td class="center">';
328 print $form->textwithpicto('', $htmltooltip, 1, 0);
329 print '</td>';
330
331 print "</tr>\n";
332 }
333 }
334 }
335 closedir($handle);
336 }
337 }
338 }
339 print "</table><br>\n";
340 }
341
342 if ($myTmpObjectArray['includedocgeneration']) {
343 /*
344 * Document templates generators
345 */
346 $setupnotempty++;
347 $type = strtolower($myTmpObjectKey);
348
349 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
350
351 // Load array def with activated templates
352 $def = array();
353 $sql = "SELECT nom";
354 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
355 $sql .= " WHERE type = '".$db->escape($type)."'";
356 $sql .= " AND entity = ".$conf->entity;
357 $resql = $db->query($sql);
358 if ($resql) {
359 $i = 0;
360 $num_rows = $db->num_rows($resql);
361 while ($i < $num_rows) {
362 $array = $db->fetch_array($resql);
363 if (is_array($array)) {
364 array_push($def, $array[0]);
365 }
366 $i++;
367 }
368 } else {
369 dol_print_error($db);
370 }
371
372 print "<table class=\"noborder\" width=\"100%\">\n";
373 print "<tr class=\"liste_titre\">\n";
374 print '<td>'.$langs->trans("Name").'</td>';
375 print '<td>'.$langs->trans("Description").'</td>';
376 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
377 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
378 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
379 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
380 print "</tr>\n";
381
382 clearstatcache();
383
384 foreach ($dirmodels as $reldir) {
385 foreach (array('', '/doc') as $valdir) {
386 $realpath = $reldir."core/modules/".$moduledir.$valdir;
387 $dir = dol_buildpath($realpath);
388
389 if (is_dir($dir)) {
390 $handle = opendir($dir);
391 if (is_resource($handle)) {
392 $filelist = array();
393 while (($file = readdir($handle)) !== false) {
394 $filelist[] = $file;
395 }
396 closedir($handle);
397 arsort($filelist);
398
399 foreach ($filelist as $file) {
400 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
401 if (file_exists($dir.'/'.$file)) {
402 $name = substr($file, 4, dol_strlen($file) - 16);
403 $classname = substr($file, 0, dol_strlen($file) - 12);
404
405 require_once $dir.'/'.$file;
406 $module = new $classname($db);
407 '@phan-var-force CommonDocGenerator $module';
408
409 $modulequalified = 1;
410 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
411 $modulequalified = 0;
412 }
413 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
414 $modulequalified = 0;
415 }
416
417 if ($modulequalified) {
418 print '<tr class="oddeven"><td width="100">';
419 print(empty($module->name) ? $name : $module->name);
420 print "</td><td>\n";
421 if (method_exists($module, 'info')) {
422 print $module->info($langs);
423 } else {
424 print $module->description;
425 }
426 print '</td>';
427
428 // Active
429 if (in_array($name, $def)) {
430 print '<td class="center">'."\n";
431 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
432 print img_picto($langs->trans("Enabled"), 'switch_on');
433 print '</a>';
434 print '</td>';
435 } else {
436 print '<td class="center">'."\n";
437 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>';
438 print "</td>";
439 }
440
441 // Default
442 print '<td class="center">';
443 $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
444 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $name) {
445 print img_picto($langs->trans("Default"), 'on');
446 } else {
447 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
448 }
449 print '</td>';
450
451 // Info
452 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
453 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
454 if ($module->type == 'pdf') {
455 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
456 }
457 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
458
459 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
460 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
461 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
462
463 print '<td class="center">';
464 print $form->textwithpicto('', $htmltooltip, 1, 0);
465 print '</td>';
466
467 // Preview
468 print '<td class="center">';
469 if ($module->type == 'pdf') {
470 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
471 } else {
472 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
473 }
474 print '</td>';
475
476 print "</tr>\n";
477 }
478 }
479 }
480 }
481 }
482 }
483 }
484 }
485
486 print '</table>';
487 }
488}
489
490/*if (empty($setupnotempty)) {
491 print '<br>'.$langs->trans("NothingToSetup");
492}*/
493
494// Page end
495print dol_get_fiche_end();
496
497llxFooter();
498$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.
$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.
workstationAdminPrepareHead()
Prepare admin pages header.