dolibarr 23.0.3
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-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 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$label = GETPOST('label', 'alpha');
50$scandir = GETPOST('scan_dir', 'alpha');
51
52$value = GETPOST('value', 'alpha');
53
54$error = 0;
55
56$dirmodels = array_merge(['/'], (array) $conf->modules_parts['models']);
57
58// Access control
59if (!$user->admin) {
61}
62
63$type = 'workstation';
64$moduledir = 'workstation';
65
66/*
67 * Actions
68 */
69
70include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
71
72if ($action == 'updateMask') {
73 $maskconst = GETPOST('maskconstWorkstation', 'aZ09');
74 $maskorder = GETPOST('maskWorkstation', 'alpha');
75
76 $res = 0;
77
78 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
79 $res = dolibarr_set_const($db, $maskconst, $maskorder, 'chaine', 0, '', $conf->entity);
80 }
81
82 if (!($res > 0)) {
83 $error++;
84 }
85
86 if (!$error) {
87 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88 } else {
89 setEventMessages($langs->trans("Error"), null, 'errors');
90 }
91} elseif ($action == 'specimen') {
92 $modele = GETPOST('module', 'alpha');
93
94 $tmpobject = new Workstation($db);
95 $tmpobject->initAsSpecimen();
96
97 // Search template files
98 $file = '';
99 $classname = '';
100 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
101 foreach ($dirmodels as $reldir) {
102 $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_workstation.modules.php", 0);
103 if (file_exists($file)) {
104 $classname = "pdf_".$modele;
105 break;
106 }
107 }
108
109 if ($classname !== '') {
110 require_once $file;
111
112 $module = new $classname($db);
113 '@phan-var-force ModelePDFWorkstation $module';
116 if ($module->write_file($tmpobject, $langs) > 0) {
117 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=workstation&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 = 'WORKSTATION_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 = 'WORKSTATION_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_WORKSTATION_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').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></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
182// Orders Numbering model
183
184print load_fiche_titre($langs->trans("NumberingModules", 'Workstation'), '', '');
185
186print '<table class="noborder centpercent">';
187print '<tr class="liste_titre">';
188print '<td>'.$langs->trans("Name").'</td>';
189print '<td>'.$langs->trans("Description").'</td>';
190print '<td class="nowrap">'.$langs->trans("Example").'</td>';
191print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
192print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
193print '</tr>'."\n";
194
195clearstatcache();
196
197foreach ($dirmodels as $reldir) {
198 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
199
200 if (is_dir($dir)) {
201 $handle = opendir($dir);
202 if (is_resource($handle)) {
203 while (($file = readdir($handle)) !== false) {
204 if (strpos($file, 'mod_workstation_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
205 $file = substr($file, 0, dol_strlen($file) - 4);
206
207 require_once $dir.'/'.$file.'.php';
208
209 $module = new $file($db);
210 '@phan-var-force ModeleNumRefWorkstation $module';
213 // Show modules according to features level
214 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
215 continue;
216 }
217 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
218 continue;
219 }
220
221 if ($module->isEnabled()) {
222 dol_include_once('/workstation/class/workstation.class.php');
223
224 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
225 print $module->info($langs);
226 print '</td>';
227
228 // Show example of numbering model
229 print '<td class="nowrap">';
230 $tmp = $module->getExample();
231 if (preg_match('/^Error/', $tmp)) {
232 $langs->load("errors");
233 print '<div class="error">'.$langs->trans($tmp).'</div>';
234 } elseif ($tmp == 'NotConfigured') {
235 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
236 } else {
237 print $tmp;
238 }
239 print '</td>'."\n";
240
241 print '<td class="center">';
242 $constforvar = 'WORKSTATION_WORKSTATION_ADDON';
243 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $file) {
244 print img_picto($langs->trans("Activated"), 'switch_on');
245 } else {
246 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'">';
247 print img_picto($langs->trans("Disabled"), 'switch_off');
248 print '</a>';
249 }
250 print '</td>';
251
252 $mytmpinstance = new Workstation($db);
253 $mytmpinstance->initAsSpecimen();
254
255 // Info
256 $htmltooltip = '';
257 $htmltooltip .= $langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
258
259 $nextval = $module->getNextValue($mytmpinstance);
260 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
261 $htmltooltip .= ''.$langs->trans("NextValue").': ';
262 if ($nextval) {
263 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
264 $nextval = $langs->trans($nextval);
265 }
266 $htmltooltip .= $nextval.'<br>';
267 } else {
268 $htmltooltip .= $langs->trans($module->error).'<br>';
269 }
270 }
271
272 print '<td class="center">';
273 print $form->textwithpicto('', $htmltooltip, 1, 'info');
274 print '</td>';
275
276 print "</tr>\n";
277 }
278 }
279 }
280 closedir($handle);
281 }
282 }
283}
284print "</table><br>\n";
285
286
287if (getDolGlobalInt('WORKSTATION_INCLUDE_DOC_GENERATION')) {
288 // Document templates generators
289 print load_fiche_titre($langs->trans("DocumentModules", 'Workstation'), '', '');
290
291 // Load array def with activated templates
292 $def = array();
293 $sql = "SELECT nom";
294 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
295 $sql .= " WHERE type = '".$db->escape($type)."'";
296 $sql .= " AND entity = ".((int) $conf->entity);
297 $resql = $db->query($sql);
298 if ($resql) {
299 $i = 0;
300 $num_rows = $db->num_rows($resql);
301 while ($i < $num_rows) {
302 $array = $db->fetch_array($resql);
303 if (is_array($array)) {
304 array_push($def, $array[0]);
305 }
306 $i++;
307 }
308 } else {
309 dol_print_error($db);
310 }
311
312 print "<table class=\"noborder\" width=\"100%\">\n";
313 print "<tr class=\"liste_titre\">\n";
314 print '<td>'.$langs->trans("Name").'</td>';
315 print '<td>'.$langs->trans("Description").'</td>';
316 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
317 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
318 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
319 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
320 print "</tr>\n";
321
322 clearstatcache();
323
324 foreach ($dirmodels as $reldir) {
325 foreach (array('', '/doc') as $valdir) {
326 $realpath = $reldir."core/modules/".$moduledir.$valdir;
327 $dir = dol_buildpath($realpath);
328
329 if (is_dir($dir)) {
330 $handle = opendir($dir);
331 if (is_resource($handle)) {
332 $filelist = array();
333 while (($file = readdir($handle)) !== false) {
334 $filelist[] = $file;
335 }
336 closedir($handle);
337 arsort($filelist);
338
339 foreach ($filelist as $file) {
340 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
341 if (file_exists($dir.'/'.$file)) {
342 $name = substr($file, 4, dol_strlen($file) - 16);
343 $classname = substr($file, 0, dol_strlen($file) - 12);
344
345 require_once $dir.'/'.$file;
346 $module = new $classname($db);
347 '@phan-var-force ModelePDFWorkstation $module';
350 $modulequalified = 1;
351 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
352 $modulequalified = 0;
353 }
354 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
355 $modulequalified = 0;
356 }
357
358 if ($modulequalified) {
359 print '<tr class="oddeven"><td width="100">';
360 print(empty($module->name) ? $name : $module->name);
361 print "</td><td>\n";
362 if (method_exists($module, 'info')) {
363 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
364 } else {
365 print $module->description;
366 }
367 print '</td>';
368
369 // Active
370 if (in_array($name, $def)) {
371 print '<td class="center">'."\n";
372 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
373 print img_picto($langs->trans("Enabled"), 'switch_on');
374 print '</a>';
375 print '</td>';
376 } else {
377 print '<td class="center">'."\n";
378 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>';
379 print "</td>";
380 }
381
382 // Default
383 print '<td class="center">';
384 $constforvar = 'WORKSTATION_WORKSTATION_ADDON';
385 if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $name) {
386 print img_picto($langs->trans("Default"), 'on');
387 } else {
388 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>';
389 }
390 print '</td>';
391
392 // Info
393 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
394 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
395 if ($module->type == 'pdf') {
396 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
397 }
398 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
399
400 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
401 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
402 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
403
404 print '<td class="center">';
405 print $form->textwithpicto('', $htmltooltip, 1, 'info');
406 print '</td>';
407
408 // Preview
409 print '<td class="center">';
410 if ($module->type == 'pdf') {
411 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
412 } else {
413 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
414 }
415 print '</td>';
416
417 print "</tr>\n";
418 }
419 }
420 }
421 }
422 }
423 }
424 }
425 }
426
427 print '</table>';
428}
429
430
431// Page end
432print dol_get_fiche_end();
433
434llxFooter();
435$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
Class for Workstation.
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, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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:128
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.