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