dolibarr 21.0.0-beta
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
42// Translations
43$langs->loadLangs(array("admin", "workstation"));
44
45// Parameters
46$action = GETPOST('action', 'aZ09');
47$backtopage = GETPOST('backtopage', 'alpha');
48$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
49
50$value = GETPOST('value', 'alpha');
51
52$error = 0;
53$setupnotempty = 0;
54
55$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
56
57// Access control
58if (!$user->admin) {
60}
61
62$moduledir = 'workstation';
63$myTmpObjects = array();
64$myTmpObjects['workstation'] = array('label' => 'Workstation', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'Workstation');
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('maskconstWorkstation', 'aZ09');
80 $maskorder = GETPOST('maskWorkstation', 'alpha');
81
82 $res = 0;
83
84 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
85 $res = dolibarr_set_const($db, $maskconst, $maskorder, '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') {
98 $modele = GETPOST('module', 'alpha');
99
100 $nameofclass = ucfirst($tmpobjectkey);
101 $tmpobject = new $nameofclass($db);
102 '@phan-var-force Workstation $tmpobject';
103 $tmpobject->initAsSpecimen();
104
105 // Search template files
106 $file = '';
107 $classname = '';
108 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
109 foreach ($dirmodels as $reldir) {
110 $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
111 if (file_exists($file)) {
112 $classname = "pdf_".$modele;
113 break;
114 }
115 }
116
117 if ($classname !== '') {
118 require_once $file;
119
120 $module = new $classname($db);
121 '@phan-var-force ModelePDFWorkstation $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 = strtoupper($tmpobjectkey).'_ADDON_PDF';
141 if (getDolGlobalString($constforval) == "$value") {
142 dolibarr_del_const($db, $constforval, $conf->entity);
143 }
144 }
145} elseif ($action == 'setdoc') {
146 // Set default model
147 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
148 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
149 // The constant that was read before the new set
150 // We therefore requires a variable to have a coherent view
151 $conf->global->$constforval = $value;
152 }
153
154 // On active le modele
155 $ret = delDocumentModel($value, $type);
156 if ($ret > 0) {
157 $ret = addDocumentModel($value, $type, $label, $scandir);
158 }
159} elseif ($action == 'setmod') {
160 // TODO Check if numbering module chosen can be activated
161 // by calling method canBeActivated
162 $constforval = 'WORKSTATION_'.strtoupper($tmpobjectkey)."_ADDON";
163 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
164}
165
166
167
168/*
169 * View
170 */
171
172$form = new Form($db);
173
174$help_url = '';
175$page_name = "WorkstationSetup";
176
177llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-admin page-workstation');
178
179// Subheader
180$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
181
182print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
183
184// Configuration header
186print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "workstation");
187
188// Setup page goes here
189//echo '<span class="opacitymedium">'.$langs->trans("WorkstationSetupPage").'</span><br><br>';
190
191
192if ($action == 'edit') {
193 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
194 print '<input type="hidden" name="token" value="'.newToken().'">';
195 print '<input type="hidden" name="action" value="update">';
196
197 print '<table class="noborder centpercent">';
198 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
199
200 // @phan-suppress-next-line PhanEmptyForeach
201 foreach ($arrayofparameters as $key => $val) {
202 print '<tr class="oddeven"><td>';
203 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
204 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
205 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
206 }
207 print '</table>';
208
209 print '<br><div class="center">';
210 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
211 print '</div>';
212
213 print '</form>';
214 print '<br>';
215} else {
216 if (!empty($arrayofparameters)) {
217 print '<table class="noborder centpercent">';
218 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
219
220 foreach ($arrayofparameters as $key => $val) {
221 $setupnotempty++;
222
223 print '<tr class="oddeven"><td>';
224 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
225 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
226 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
227 }
228
229 print '</table>';
230
231 print '<div class="tabsAction">';
232 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
233 print '</div>';
234 }/* else {
235 print '<br>'.$langs->trans("NothingToSetup");
236 }*/
237}
238
239
240foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
241 if ($myTmpObjectArray['includerefgeneration']) {
242 // Orders Numbering model
243 $setupnotempty++;
244
245 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
246
247 print '<table class="noborder centpercent">';
248 print '<tr class="liste_titre">';
249 print '<td>'.$langs->trans("Name").'</td>';
250 print '<td>'.$langs->trans("Description").'</td>';
251 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
252 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
253 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
254 print '</tr>'."\n";
255
256 clearstatcache();
257
258 foreach ($dirmodels as $reldir) {
259 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
260
261 if (is_dir($dir)) {
262 $handle = opendir($dir);
263 if (is_resource($handle)) {
264 while (($file = readdir($handle)) !== false) {
265 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
266 $file = substr($file, 0, dol_strlen($file) - 4);
267
268 require_once $dir.'/'.$file.'.php';
269
270 $module = new $file($db);
271 '@phan-var-force ModeleNumRefWorkstation $module';
272
273 // Show modules according to features level
274 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
275 continue;
276 }
277 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
278 continue;
279 }
280
281 if ($module->isEnabled()) {
282 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
283
284 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
285 print $module->info($langs);
286 print '</td>';
287
288 // Show example of numbering model
289 print '<td class="nowrap">';
290 $tmp = $module->getExample();
291 if (preg_match('/^Error/', $tmp)) {
292 $langs->load("errors");
293 print '<div class="error">'.$langs->trans($tmp).'</div>';
294 } elseif ($tmp == 'NotConfigured') {
295 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
296 } else {
297 print $tmp;
298 }
299 print '</td>'."\n";
300
301 print '<td class="center">';
302 $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
303 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $file) {
304 print img_picto($langs->trans("Activated"), 'switch_on');
305 } else {
306 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
307 print img_picto($langs->trans("Disabled"), 'switch_off');
308 print '</a>';
309 }
310 print '</td>';
311
312 $nameofclass = ucfirst($myTmpObjectKey);
313 $mytmpinstance = new $nameofclass($db);
314 '@phan-var-force Workstation $mytmpinstance';
315 $mytmpinstance->initAsSpecimen();
316
317 // Info
318 $htmltooltip = '';
319 $htmltooltip .= $langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
320
321 $nextval = $module->getNextValue($mytmpinstance);
322 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
323 $htmltooltip .= ''.$langs->trans("NextValue").': ';
324 if ($nextval) {
325 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
326 $nextval = $langs->trans($nextval);
327 }
328 $htmltooltip .= $nextval.'<br>';
329 } else {
330 $htmltooltip .= $langs->trans($module->error).'<br>';
331 }
332 }
333
334 print '<td class="center">';
335 print $form->textwithpicto('', $htmltooltip, 1, 0);
336 print '</td>';
337
338 print "</tr>\n";
339 }
340 }
341 }
342 closedir($handle);
343 }
344 }
345 }
346 print "</table><br>\n";
347 }
348
349 if ($myTmpObjectArray['includedocgeneration']) {
350 // Document templates generators
351 $setupnotempty++;
352 $type = strtolower($myTmpObjectKey);
353
354 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
355
356 // Load array def with activated templates
357 $def = array();
358 $sql = "SELECT nom";
359 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
360 $sql .= " WHERE type = '".$db->escape($type)."'";
361 $sql .= " AND entity = ".$conf->entity;
362 $resql = $db->query($sql);
363 if ($resql) {
364 $i = 0;
365 $num_rows = $db->num_rows($resql);
366 while ($i < $num_rows) {
367 $array = $db->fetch_array($resql);
368 if (is_array($array)) {
369 array_push($def, $array[0]);
370 }
371 $i++;
372 }
373 } else {
374 dol_print_error($db);
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
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 $filelist = array();
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 ModelePDFWorkstation $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 = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
449 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $name) {
450 print img_picto($langs->trans("Default"), 'on');
451 } else {
452 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>';
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
495/*if (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($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
$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.
workstationAdminPrepareHead()
Prepare admin pages header.