dolibarr  19.0.0-dev
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
26 require "../main.inc.php";
27 
28 // Libraries
29 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
30 require_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
49 if (!$user->admin) {
51 }
52 
53 
54 /*
55  * Actions
56  */
57 
58 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
59 
60 if ($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 = ''; $classname = ''; $filefound = 0;
86  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
87  foreach ($dirmodels as $reldir) {
88  $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
89  if (file_exists($file)) {
90  $filefound = 1;
91  $classname = "pdf_".$modele;
92  break;
93  }
94  }
95 
96  if ($filefound) {
97  require_once $file;
98 
99  $module = new $classname($db);
100 
101  if ($module->write_file($tmpobject, $langs) > 0) {
102  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
103  return;
104  } else {
105  setEventMessages($module->error, null, 'errors');
106  dol_syslog($module->error, LOG_ERR);
107  }
108  } else {
109  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
110  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
111  }
112 } elseif ($action == 'set') {
113  // Activate a model
114  $ret = addDocumentModel($value, $type, $label, $scandir);
115 } elseif ($action == 'del') {
116  $tmpobjectkey = GETPOST('object');
117 
118  $ret = delDocumentModel($value, $type);
119  if ($ret > 0) {
120  $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
121  if ($conf->global->$constforval == "$value") {
122  dolibarr_del_const($db, $constforval, $conf->entity);
123  }
124  }
125 } elseif ($action == 'setdoc') {
126  // Set default model
127  $tmpobjectkey = GETPOST('object');
128  $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
129  if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
130  // The constant that was read before the new set
131  // We therefore requires a variable to have a coherent view
132  $conf->global->$constforval = $value;
133  }
134 
135  // On active le modele
136  $ret = delDocumentModel($value, $type);
137  if ($ret > 0) {
138  $ret = addDocumentModel($value, $type, $label, $scandir);
139  }
140 } elseif ($action == 'setmod') {
141  // TODO Check if numbering module chosen can be activated
142  // by calling method canBeActivated
143  $tmpobjectkey = GETPOST('object');
144  $constforval = 'WORKSTATION_'.strtoupper($tmpobjectkey)."_ADDON";
145  dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
146 }
147 
148 
149 
150 /*
151  * View
152  */
153 
154 $form = new Form($db);
155 
156 $help_url = '';
157 $page_name = "WorkstationSetup";
158 
159 llxHeader('', $langs->trans($page_name), $help_url);
160 
161 // Subheader
162 $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
163 
164 print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
165 
166 // Configuration header
168 print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "workstation");
169 
170 // Setup page goes here
171 //echo '<span class="opacitymedium">'.$langs->trans("WorkstationSetupPage").'</span><br><br>';
172 
173 
174 if ($action == 'edit') {
175  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
176  print '<input type="hidden" name="token" value="'.newToken().'">';
177  print '<input type="hidden" name="action" value="update">';
178 
179  print '<table class="noborder centpercent">';
180  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
181 
182  foreach ($arrayofparameters as $key => $val) {
183  print '<tr class="oddeven"><td>';
184  $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
185  print $form->textwithpicto($langs->trans($key), $tooltiphelp);
186  print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
187  }
188  print '</table>';
189 
190  print '<br><div class="center">';
191  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
192  print '</div>';
193 
194  print '</form>';
195  print '<br>';
196 } else {
197  if (!empty($arrayofparameters)) {
198  print '<table class="noborder centpercent">';
199  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
200 
201  foreach ($arrayofparameters as $key => $val) {
202  $setupnotempty++;
203 
204  print '<tr class="oddeven"><td>';
205  $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
206  print $form->textwithpicto($langs->trans($key), $tooltiphelp);
207  print '</td><td>'.getDolGlobalString($key).'</td></tr>';
208  }
209 
210  print '</table>';
211 
212  print '<div class="tabsAction">';
213  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
214  print '</div>';
215  }/* else {
216  print '<br>'.$langs->trans("NothingToSetup");
217  }*/
218 }
219 
220 
221 $moduledir = 'workstation';
222 $myTmpObjects = array();
223 $myTmpObjects['workstation'] = array('includerefgeneration'=>1, 'includedocgeneration'=>0);
224 
225 
226 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
227  if ($myTmpObjectKey == 'MyObject') {
228  continue;
229  }
230  if ($myTmpObjectArray['includerefgeneration']) {
231  /*
232  * Orders Numbering model
233  */
234  $setupnotempty++;
235 
236  print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
237 
238  print '<table class="noborder centpercent">';
239  print '<tr class="liste_titre">';
240  print '<td>'.$langs->trans("Name").'</td>';
241  print '<td>'.$langs->trans("Description").'</td>';
242  print '<td class="nowrap">'.$langs->trans("Example").'</td>';
243  print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
244  print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
245  print '</tr>'."\n";
246 
247  clearstatcache();
248 
249  foreach ($dirmodels as $reldir) {
250  $dir = dol_buildpath($reldir."core/modules/".$moduledir);
251 
252  if (is_dir($dir)) {
253  $handle = opendir($dir);
254  if (is_resource($handle)) {
255  while (($file = readdir($handle)) !== false) {
256  if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
257  $file = substr($file, 0, dol_strlen($file) - 4);
258 
259  require_once $dir.'/'.$file.'.php';
260 
261  $module = new $file($db);
262 
263  // Show modules according to features level
264  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
265  continue;
266  }
267  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
268  continue;
269  }
270 
271  if ($module->isEnabled()) {
272  dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
273 
274  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
275  print $module->info();
276  print '</td>';
277 
278  // Show example of numbering model
279  print '<td class="nowrap">';
280  $tmp = $module->getExample();
281  if (preg_match('/^Error/', $tmp)) {
282  $langs->load("errors");
283  print '<div class="error">'.$langs->trans($tmp).'</div>';
284  } elseif ($tmp == 'NotConfigured') {
285  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
286  } else {
287  print $tmp;
288  }
289  print '</td>'."\n";
290 
291  print '<td class="center">';
292  $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
293  if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $file) {
294  print img_picto($langs->trans("Activated"), 'switch_on');
295  } else {
296  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
297  print img_picto($langs->trans("Disabled"), 'switch_off');
298  print '</a>';
299  }
300  print '</td>';
301 
302  $nameofclass = ucfirst($myTmpObjectKey);
303  $mytmpinstance = new $nameofclass($db);
304  $mytmpinstance->initAsSpecimen();
305 
306  // Info
307  $htmltooltip = '';
308  $htmltooltip .= $langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
309 
310  $nextval = $module->getNextValue($mytmpinstance);
311  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
312  $htmltooltip .= ''.$langs->trans("NextValue").': ';
313  if ($nextval) {
314  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
315  $nextval = $langs->trans($nextval);
316  }
317  $htmltooltip .= $nextval.'<br>';
318  } else {
319  $htmltooltip .= $langs->trans($module->error).'<br>';
320  }
321  }
322 
323  print '<td class="center">';
324  print $form->textwithpicto('', $htmltooltip, 1, 0);
325  print '</td>';
326 
327  print "</tr>\n";
328  }
329  }
330  }
331  closedir($handle);
332  }
333  }
334  }
335  print "</table><br>\n";
336  }
337 
338  if ($myTmpObjectArray['includedocgeneration']) {
339  /*
340  * Document templates generators
341  */
342  $setupnotempty++;
343  $type = strtolower($myTmpObjectKey);
344 
345  print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
346 
347  // Load array def with activated templates
348  $def = array();
349  $sql = "SELECT nom";
350  $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
351  $sql .= " WHERE type = '".$db->escape($type)."'";
352  $sql .= " AND entity = ".$conf->entity;
353  $resql = $db->query($sql);
354  if ($resql) {
355  $i = 0;
356  $num_rows = $db->num_rows($resql);
357  while ($i < $num_rows) {
358  $array = $db->fetch_array($resql);
359  array_push($def, $array[0]);
360  $i++;
361  }
362  } else {
363  dol_print_error($db);
364  }
365 
366  print "<table class=\"noborder\" width=\"100%\">\n";
367  print "<tr class=\"liste_titre\">\n";
368  print '<td>'.$langs->trans("Name").'</td>';
369  print '<td>'.$langs->trans("Description").'</td>';
370  print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
371  print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
372  print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
373  print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
374  print "</tr>\n";
375 
376  clearstatcache();
377 
378  foreach ($dirmodels as $reldir) {
379  foreach (array('', '/doc') as $valdir) {
380  $realpath = $reldir."core/modules/".$moduledir.$valdir;
381  $dir = dol_buildpath($realpath);
382 
383  if (is_dir($dir)) {
384  $handle = opendir($dir);
385  if (is_resource($handle)) {
386  while (($file = readdir($handle)) !== false) {
387  $filelist[] = $file;
388  }
389  closedir($handle);
390  arsort($filelist);
391 
392  foreach ($filelist as $file) {
393  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
394  if (file_exists($dir.'/'.$file)) {
395  $name = substr($file, 4, dol_strlen($file) - 16);
396  $classname = substr($file, 0, dol_strlen($file) - 12);
397 
398  require_once $dir.'/'.$file;
399  $module = new $classname($db);
400 
401  $modulequalified = 1;
402  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
403  $modulequalified = 0;
404  }
405  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
406  $modulequalified = 0;
407  }
408 
409  if ($modulequalified) {
410  print '<tr class="oddeven"><td width="100">';
411  print (empty($module->name) ? $name : $module->name);
412  print "</td><td>\n";
413  if (method_exists($module, 'info')) {
414  print $module->info($langs);
415  } else {
416  print $module->description;
417  }
418  print '</td>';
419 
420  // Active
421  if (in_array($name, $def)) {
422  print '<td class="center">'."\n";
423  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
424  print img_picto($langs->trans("Enabled"), 'switch_on');
425  print '</a>';
426  print '</td>';
427  } else {
428  print '<td class="center">'."\n";
429  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>';
430  print "</td>";
431  }
432 
433  // Default
434  print '<td class="center">';
435  $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
436  if (getDolGlobalString($constforvar, 'mod_workstation_standard') == $name) {
437  print img_picto($langs->trans("Default"), 'on');
438  } else {
439  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>';
440  }
441  print '</td>';
442 
443  // Info
444  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
445  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
446  if ($module->type == 'pdf') {
447  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
448  }
449  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
450 
451  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
452  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
453  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
454 
455  print '<td class="center">';
456  print $form->textwithpicto('', $htmltooltip, 1, 0);
457  print '</td>';
458 
459  // Preview
460  print '<td class="center">';
461  if ($module->type == 'pdf') {
462  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
463  } else {
464  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
465  }
466  print '</td>';
467 
468  print "</tr>\n";
469  }
470  }
471  }
472  }
473  }
474  }
475  }
476  }
477 
478  print '</table>';
479  }
480 }
481 
482 /*if (empty($setupnotempty)) {
483  print '<br>'.$langs->trans("NothingToSetup");
484 }*/
485 
486 // Page end
487 print dol_get_fiche_end();
488 
489 llxFooter();
490 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1918
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).
Definition: admin.lib.php:638
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:562
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1949
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.
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.