dolibarr 21.0.0-alpha
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 $res = 0;
76
77 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
78 $res = dolibarr_set_const($db, $maskconst, $maskorder, 'chaine', 0, '', $conf->entity);
79 }
80
81 if (!($res > 0)) {
82 $error++;
83 }
84
85 if (!$error) {
86 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87 } else {
88 setEventMessages($langs->trans("Error"), null, 'errors');
89 }
90} elseif ($action == 'specimen') {
91 $modele = GETPOST('module', 'alpha');
92
93 $nameofclass = ucfirst($tmpobjectkey);
94 $tmpobject = new $nameofclass($db);
95 '@phan-var-force Workstation $tmpobject';
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/workstation/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 '@phan-var-force ModelePDFWorkstation $module';
115
116 if ($module->write_file($tmpobject, $langs) > 0) {
117 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
118 return;
119 } else {
120 setEventMessages($module->error, null, 'errors');
121 dol_syslog($module->error, LOG_ERR);
122 }
123 } else {
124 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
125 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
126 }
127} elseif ($action == 'set') {
128 // Activate a model
129 $ret = addDocumentModel($value, $type, $label, $scandir);
130} elseif ($action == 'del') {
131 $ret = delDocumentModel($value, $type);
132 if ($ret > 0) {
133 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
134 if (getDolGlobalString($constforval) == "$value") {
135 dolibarr_del_const($db, $constforval, $conf->entity);
136 }
137 }
138} elseif ($action == 'setdoc') {
139 // Set default model
140 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
141 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
142 // The constant that was read before the new set
143 // We therefore requires a variable to have a coherent view
144 $conf->global->$constforval = $value;
145 }
146
147 // On active le modele
148 $ret = delDocumentModel($value, $type);
149 if ($ret > 0) {
150 $ret = addDocumentModel($value, $type, $label, $scandir);
151 }
152} elseif ($action == 'setmod') {
153 // TODO Check if numbering module chosen can be activated
154 // by calling method canBeActivated
155 $constforval = 'WORKSTATION_'.strtoupper($tmpobjectkey)."_ADDON";
156 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
157}
158
159
160
161/*
162 * View
163 */
164
165$form = new Form($db);
166
167$help_url = '';
168$page_name = "WorkstationSetup";
169
170llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-admin page-workstation');
171
172// Subheader
173$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
174
175print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
176
177// Configuration header
179print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "workstation");
180
181// Setup page goes here
182//echo '<span class="opacitymedium">'.$langs->trans("WorkstationSetupPage").'</span><br><br>';
183
184
185if ($action == 'edit') {
186 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
187 print '<input type="hidden" name="token" value="'.newToken().'">';
188 print '<input type="hidden" name="action" value="update">';
189
190 print '<table class="noborder centpercent">';
191 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
192
193 // @phan-suppress-next-line PhanEmptyForeach
194 foreach ($arrayofparameters as $key => $val) {
195 print '<tr class="oddeven"><td>';
196 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
197 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
198 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
199 }
200 print '</table>';
201
202 print '<br><div class="center">';
203 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
204 print '</div>';
205
206 print '</form>';
207 print '<br>';
208} else {
209 if (!empty($arrayofparameters)) {
210 print '<table class="noborder centpercent">';
211 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
212
213 foreach ($arrayofparameters as $key => $val) {
214 $setupnotempty++;
215
216 print '<tr class="oddeven"><td>';
217 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
218 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
219 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
220 }
221
222 print '</table>';
223
224 print '<div class="tabsAction">';
225 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
226 print '</div>';
227 }/* else {
228 print '<br>'.$langs->trans("NothingToSetup");
229 }*/
230}
231
232
233foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
234 if ($myTmpObjectArray['includerefgeneration']) {
235 // Orders Numbering model
236 $setupnotempty++;
237
238 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
239
240 print '<table class="noborder centpercent">';
241 print '<tr class="liste_titre">';
242 print '<td>'.$langs->trans("Name").'</td>';
243 print '<td>'.$langs->trans("Description").'</td>';
244 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
245 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
246 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
247 print '</tr>'."\n";
248
249 clearstatcache();
250
251 foreach ($dirmodels as $reldir) {
252 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
253
254 if (is_dir($dir)) {
255 $handle = opendir($dir);
256 if (is_resource($handle)) {
257 while (($file = readdir($handle)) !== false) {
258 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
259 $file = substr($file, 0, dol_strlen($file) - 4);
260
261 require_once $dir.'/'.$file.'.php';
262
263 $module = new $file($db);
264 '@phan-var-force ModeleNumRefWorkstation $module';
265
266 // Show modules according to features level
267 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
268 continue;
269 }
270 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
271 continue;
272 }
273
274 if ($module->isEnabled()) {
275 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
276
277 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
278 print $module->info($langs);
279 print '</td>';
280
281 // Show example of numbering model
282 print '<td class="nowrap">';
283 $tmp = $module->getExample();
284 if (preg_match('/^Error/', $tmp)) {
285 $langs->load("errors");
286 print '<div class="error">'.$langs->trans($tmp).'</div>';
287 } elseif ($tmp == 'NotConfigured') {
288 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
289 } else {
290 print $tmp;
291 }
292 print '</td>'."\n";
293
294 print '<td class="center">';
295 $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
296 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $file) {
297 print img_picto($langs->trans("Activated"), 'switch_on');
298 } else {
299 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
300 print img_picto($langs->trans("Disabled"), 'switch_off');
301 print '</a>';
302 }
303 print '</td>';
304
305 $nameofclass = ucfirst($myTmpObjectKey);
306 $mytmpinstance = new $nameofclass($db);
307 '@phan-var-force Workstation $mytmpinstance';
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 // Document templates generators
344 $setupnotempty++;
345 $type = strtolower($myTmpObjectKey);
346
347 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
348
349 // Load array def with activated templates
350 $def = array();
351 $sql = "SELECT nom";
352 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
353 $sql .= " WHERE type = '".$db->escape($type)."'";
354 $sql .= " AND entity = ".$conf->entity;
355 $resql = $db->query($sql);
356 if ($resql) {
357 $i = 0;
358 $num_rows = $db->num_rows($resql);
359 while ($i < $num_rows) {
360 $array = $db->fetch_array($resql);
361 if (is_array($array)) {
362 array_push($def, $array[0]);
363 }
364 $i++;
365 }
366 } else {
367 dol_print_error($db);
368 }
369
370 print "<table class=\"noborder\" width=\"100%\">\n";
371 print "<tr class=\"liste_titre\">\n";
372 print '<td>'.$langs->trans("Name").'</td>';
373 print '<td>'.$langs->trans("Description").'</td>';
374 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
375 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
376 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
377 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
378 print "</tr>\n";
379
380 clearstatcache();
381
382 foreach ($dirmodels as $reldir) {
383 foreach (array('', '/doc') as $valdir) {
384 $realpath = $reldir."core/modules/".$moduledir.$valdir;
385 $dir = dol_buildpath($realpath);
386
387 if (is_dir($dir)) {
388 $handle = opendir($dir);
389 if (is_resource($handle)) {
390 $filelist = array();
391 while (($file = readdir($handle)) !== false) {
392 $filelist[] = $file;
393 }
394 closedir($handle);
395 arsort($filelist);
396
397 foreach ($filelist as $file) {
398 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
399 if (file_exists($dir.'/'.$file)) {
400 $name = substr($file, 4, dol_strlen($file) - 16);
401 $classname = substr($file, 0, dol_strlen($file) - 12);
402
403 require_once $dir.'/'.$file;
404 $module = new $classname($db);
405 '@phan-var-force ModelePDFWorkstation $module';
406
407 $modulequalified = 1;
408 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
409 $modulequalified = 0;
410 }
411 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
412 $modulequalified = 0;
413 }
414
415 if ($modulequalified) {
416 print '<tr class="oddeven"><td width="100">';
417 print(empty($module->name) ? $name : $module->name);
418 print "</td><td>\n";
419 if (method_exists($module, 'info')) {
420 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
421 } else {
422 print $module->description;
423 }
424 print '</td>';
425
426 // Active
427 if (in_array($name, $def)) {
428 print '<td class="center">'."\n";
429 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
430 print img_picto($langs->trans("Enabled"), 'switch_on');
431 print '</a>';
432 print '</td>';
433 } else {
434 print '<td class="center">'."\n";
435 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>';
436 print "</td>";
437 }
438
439 // Default
440 print '<td class="center">';
441 $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
442 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $name) {
443 print img_picto($langs->trans("Default"), 'on');
444 } else {
445 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>';
446 }
447 print '</td>';
448
449 // Info
450 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
451 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
452 if ($module->type == 'pdf') {
453 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
454 }
455 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
456
457 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
458 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
459 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
460
461 print '<td class="center">';
462 print $form->textwithpicto('', $htmltooltip, 1, 0);
463 print '</td>';
464
465 // Preview
466 print '<td class="center">';
467 if ($module->type == 'pdf') {
468 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
469 } else {
470 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
471 }
472 print '</td>';
473
474 print "</tr>\n";
475 }
476 }
477 }
478 }
479 }
480 }
481 }
482 }
483
484 print '</table>';
485 }
486}
487
488/*if (empty($setupnotempty)) {
489 print '<br>'.$langs->trans("NothingToSetup");
490}*/
491
492// Page end
493print dol_get_fiche_end();
494
495llxFooter();
496$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.
$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.