dolibarr  13.0.2
mrp.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('admin', 'errors', 'mrp', 'other'));
33 
34 if (!$user->admin) accessforbidden();
35 
36 $action = GETPOST('action', 'aZ09');
37 $value = GETPOST('value', 'alpha');
38 $label = GETPOST('label', 'alpha');
39 $scandir = GETPOST('scan_dir', 'alpha');
40 $type = 'mrp';
41 
42 
43 /*
44  * Actions
45  */
46 
47 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
48 
49 if ($action == 'updateMask')
50 {
51  $maskconstmrp = GETPOST('maskconstMo', 'alpha');
52  $maskmrp = GETPOST('maskMo', 'alpha');
53 
54  if ($maskconstmrp) $res = dolibarr_set_const($db, $maskconstmrp, $maskmrp, 'chaine', 0, '', $conf->entity);
55 
56  if (!($res > 0)) $error++;
57 
58  if (!$error)
59  {
60  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
61  } else {
62  setEventMessages($langs->trans("Error"), null, 'errors');
63  }
64 } elseif ($action == 'specimen')
65 {
66  $modele = GETPOST('module', 'alpha');
67 
68  $mo = new MO($db);
69  $mrp->initAsSpecimen();
70 
71  // Search template files
72  $file = ''; $classname = ''; $filefound = 0;
73  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
74  foreach ($dirmodels as $reldir)
75  {
76  $file = dol_buildpath($reldir."core/modules/mrp/doc/pdf_".$modele.".modules.php", 0);
77  if (file_exists($file))
78  {
79  $filefound = 1;
80  $classname = "pdf_".$modele;
81  break;
82  }
83  }
84 
85  if ($filefound)
86  {
87  require_once $file;
88 
89  $module = new $classname($db);
90 
91  if ($module->write_file($mrp, $langs) > 0)
92  {
93  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mrp&file=SPECIMEN.pdf");
94  return;
95  } else {
96  setEventMessages($module->error, null, 'errors');
97  dol_syslog($module->error, LOG_ERR);
98  }
99  } else {
100  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
101  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
102  }
103 }
104 
105 // Activate a model
106 elseif ($action == 'set')
107 {
108  $ret = addDocumentModel($value, $type, $label, $scandir);
109 } elseif ($action == 'del')
110 {
111  $ret = delDocumentModel($value, $type);
112  if ($ret > 0)
113  {
114  if ($conf->global->MRP_MO_ADDON_PDF == "$value") dolibarr_del_const($db, 'MRP_MO_ADDON_PDF', $conf->entity);
115  }
116 }
117 
118 // Set default model
119 elseif ($action == 'setdoc')
120 {
121  if (dolibarr_set_const($db, "MRP_MO_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
122  {
123  // The constant that was read before the new set
124  // We therefore requires a variable to have a coherent view
125  $conf->global->MRP_MO_ADDON_PDF = $value;
126  }
127 
128  // On active le modele
129  $ret = delDocumentModel($value, $type);
130  if ($ret > 0)
131  {
132  $ret = addDocumentModel($value, $type, $label, $scandir);
133  }
134 } elseif ($action == 'setmod')
135 {
136  // TODO Check if numbering module chosen can be activated
137  // by calling method canBeActivated
138 
139  dolibarr_set_const($db, "MRP_MO_ADDON", $value, 'chaine', 0, '', $conf->entity);
140 } elseif ($action == 'set_MRP_MO_DRAFT_WATERMARK')
141 {
142  $draft = GETPOST("MRP_MO_DRAFT_WATERMARK");
143  $res = dolibarr_set_const($db, "MRP_MO_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
144 
145  if (!($res > 0)) $error++;
146 
147  if (!$error)
148  {
149  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
150  } else {
151  setEventMessages($langs->trans("Error"), null, 'errors');
152  }
153 } elseif ($action == 'set_MRP_MO_FREE_TEXT')
154 {
155  $freetext = GETPOST("MRP_MO_FREE_TEXT", 'restricthtml'); // No alpha here, we want exact string
156 
157  $res = dolibarr_set_const($db, "MRP_MO_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
158 
159  if (!($res > 0)) $error++;
160 
161  if (!$error)
162  {
163  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
164  } else {
165  setEventMessages($langs->trans("Error"), null, 'errors');
166  }
167 }
168 
169 
170 /*
171  * View
172  */
173 
174 $form = new Form($db);
175 
176 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
177 
178 llxHeader("", $langs->trans("MrpSetupPage"));
179 
180 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
181 print load_fiche_titre($langs->trans("MrpSetupPage"), $linkback, 'title_setup');
182 
183 $head = mrpAdminPrepareHead();
184 
185 print dol_get_fiche_head($head, 'settings', $langs->trans("MOs"), -1, 'mrp');
186 
187 /*
188  * MOs Numbering model
189  */
190 
191 print load_fiche_titre($langs->trans("MOsNumberingModules"), '', '');
192 
193 print '<table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print '<td>'.$langs->trans("Name").'</td>';
196 print '<td>'.$langs->trans("Description").'</td>';
197 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
198 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
199 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
200 print '</tr>'."\n";
201 
202 clearstatcache();
203 
204 foreach ($dirmodels as $reldir)
205 {
206  $dir = dol_buildpath($reldir."core/modules/mrp/");
207 
208  if (is_dir($dir))
209  {
210  $handle = opendir($dir);
211  if (is_resource($handle))
212  {
213  while (($file = readdir($handle)) !== false)
214  {
215  if (substr($file, 0, 7) == 'mod_mo_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
216  {
217  $file = substr($file, 0, dol_strlen($file) - 4);
218 
219  require_once $dir.$file.'.php';
220 
221  $module = new $file($db);
222 
223  // Show modules according to features level
224  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
225  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
226 
227  if ($module->isEnabled())
228  {
229  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
230  print $module->info();
231  print '</td>';
232 
233  // Show example of numbering model
234  print '<td class="nowrap">';
235  $tmp = $module->getExample();
236  if (preg_match('/^Error/', $tmp)) {
237  $langs->load("errors");
238  print '<div class="error">'.$langs->trans($tmp).'</div>';
239  } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
240  else print $tmp;
241  print '</td>'."\n";
242 
243  print '<td class="center">';
244  if ($conf->global->MRP_MO_ADDON == $file)
245  {
246  print img_picto($langs->trans("Activated"), 'switch_on');
247  } else {
248  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;token='.newToken().'&amp;value='.urlencode($file).'">';
249  print img_picto($langs->trans("Disabled"), 'switch_off');
250  print '</a>';
251  }
252  print '</td>';
253 
254  $mrp = new MO($db);
255  $mrp->initAsSpecimen();
256 
257  // Info
258  $htmltooltip = '';
259  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
260  $mrp->type = 0;
261  $nextval = $module->getNextValue($mysoc, $mrp);
262  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
263  $htmltooltip .= ''.$langs->trans("NextValue").': ';
264  if ($nextval) {
265  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
266  $nextval = $langs->trans($nextval);
267  $htmltooltip .= $nextval.'<br>';
268  } else {
269  $htmltooltip .= $langs->trans($module->error).'<br>';
270  }
271  }
272 
273  print '<td class="center">';
274  print $form->textwithpicto('', $htmltooltip, 1, 0);
275  print '</td>';
276 
277  print "</tr>\n";
278  }
279  }
280  }
281  closedir($handle);
282  }
283  }
284 }
285 print "</table><br>\n";
286 
287 
288 /*
289  * Document templates generators
290  */
291 
292 print load_fiche_titre($langs->trans("MOsModelModule"), '', '');
293 
294 // Load array def with activated templates
295 $def = array();
296 $sql = "SELECT nom";
297 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
298 $sql .= " WHERE type = '".$db->escape($type)."'";
299 $sql .= " AND entity = ".$conf->entity;
300 $resql = $db->query($sql);
301 if ($resql)
302 {
303  $i = 0;
304  $num_rows = $db->num_rows($resql);
305  while ($i < $num_rows)
306  {
307  $array = $db->fetch_array($resql);
308  array_push($def, $array[0]);
309  $i++;
310  }
311 } else {
312  dol_print_error($db);
313 }
314 
315 
316 print "<table class=\"noborder\" width=\"100%\">\n";
317 print "<tr class=\"liste_titre\">\n";
318 print '<td>'.$langs->trans("Name").'</td>';
319 print '<td>'.$langs->trans("Description").'</td>';
320 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
321 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
322 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
323 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
324 print "</tr>\n";
325 
326 clearstatcache();
327 
328 foreach ($dirmodels as $reldir)
329 {
330  foreach (array('', '/doc') as $valdir)
331  {
332  $realpath = $reldir."core/modules/mrp".$valdir;
333  $dir = dol_buildpath($realpath);
334 
335  if (is_dir($dir))
336  {
337  $handle = opendir($dir);
338  if (is_resource($handle))
339  {
340  while (($file = readdir($handle)) !== false)
341  {
342  $filelist[] = $file;
343  }
344  closedir($handle);
345  arsort($filelist);
346 
347  foreach ($filelist as $file)
348  {
349  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
350  {
351  if (file_exists($dir.'/'.$file))
352  {
353  $name = substr($file, 4, dol_strlen($file) - 16);
354  $classname = substr($file, 0, dol_strlen($file) - 12);
355 
356  require_once $dir.'/'.$file;
357  $module = new $classname($db);
358 
359  $modulequalified = 1;
360  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
361  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
362 
363  if ($modulequalified)
364  {
365  print '<tr class="oddeven"><td width="100">';
366  print (empty($module->name) ? $name : $module->name);
367  print "</td><td>\n";
368  if (method_exists($module, 'info')) print $module->info($langs);
369  else print $module->description;
370  print '</td>';
371 
372  // Active
373  if (in_array($name, $def))
374  {
375  print '<td class="center">'."\n";
376  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
377  print img_picto($langs->trans("Enabled"), 'switch_on');
378  print '</a>';
379  print '</td>';
380  } else {
381  print '<td class="center">'."\n";
382  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
383  print "</td>";
384  }
385 
386  // Default
387  print '<td class="center">';
388  if ($conf->global->MRP_MO_ADDON_PDF == $name)
389  {
390  print img_picto($langs->trans("Default"), 'on');
391  } else {
392  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
393  }
394  print '</td>';
395 
396  // Info
397  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
398  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
399  if ($module->type == 'pdf')
400  {
401  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
402  }
403  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
404 
405  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
406  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
407  $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftMOs").': '.yn($module->option_draft_watermark, 1, 1);
408 
409 
410  print '<td class="center">';
411  print $form->textwithpicto('', $htmltooltip, 1, 0);
412  print '</td>';
413 
414  // Preview
415  print '<td class="center">';
416  if ($module->type == 'pdf')
417  {
418  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
419  } else {
420  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
421  }
422  print '</td>';
423 
424  print "</tr>\n";
425  }
426  }
427  }
428  }
429  }
430  }
431  }
432 }
433 
434 print '</table>';
435 print "<br>";
436 
437 /*
438  * Other options
439  */
440 
441 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
442 print '<table class="noborder centpercent">';
443 print '<tr class="liste_titre">';
444 print '<td>'.$langs->trans("Parameter").'</td>';
445 print '<td class="center" width="60">'.$langs->trans("Value").'</td>';
446 print "<td>&nbsp;</td>\n";
447 print "</tr>\n";
448 
449 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
450 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
451 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
452 foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
453 $htmltext .= '</i>';
454 
455 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
456 print '<input type="hidden" name="token" value="'.newToken().'">';
457 print '<input type="hidden" name="action" value="set_MRP_MO_FREE_TEXT">';
458 print '<tr class="oddeven"><td colspan="2">';
459 print $form->textwithpicto($langs->trans("FreeLegalTextOnMOs"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
460 $variablename = 'MRP_MO_FREE_TEXT';
461 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
462 {
463  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
464 } else {
465  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
466  $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
467  print $doleditor->Create();
468 }
469 print '</td><td class="right">';
470 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
471 print "</td></tr>\n";
472 print '</form>';
473 
474 //Use draft Watermark
475 
476 print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
477 print '<input type="hidden" name="token" value="'.newToken().'">';
478 print "<input type=\"hidden\" name=\"action\" value=\"set_MRP_MO_DRAFT_WATERMARK\">";
479 print '<tr class="oddeven"><td>';
480 print $form->textwithpicto($langs->trans("WatermarkOnDraftMOs"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
481 print '</td><td>';
482 print '<input class="flat minwidth200" type="text" name="MRP_MO_DRAFT_WATERMARK" value="'.$conf->global->MRP_MO_DRAFT_WATERMARK.'">';
483 print '</td><td class="right">';
484 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
485 print "</td></tr>\n";
486 print '</form>';
487 
488 print '</table>';
489 print '<br>';
490 
491 
492 // End of page
493 llxFooter();
494 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1748
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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:575
addDocumentModel($name, $type, $label= '', $description= '')
Add document model used by doc generator.
Definition: admin.lib.php:1717
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:499
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:643
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
mrpAdminPrepareHead()
Prepare admin pages header.
Definition: mrp.lib.php:29
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.