dolibarr 21.0.0-alpha
mrp.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
31require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array('admin', 'errors', 'mrp', 'other'));
36
37if (!$user->admin) {
39}
40
41$action = GETPOST('action', 'aZ09');
42$value = GETPOST('value', 'alpha');
43$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
44
45$label = GETPOST('label', 'alpha');
46$scandir = GETPOST('scan_dir', 'alpha');
47$type = 'mrp';
48
49
50/*
51 * Actions
52 */
53
54include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
55
56if ($action == 'updateMask') {
57 $maskconstmrp = GETPOST('maskconstMo', 'aZ09');
58 $maskmrp = GETPOST('maskMo', 'alpha');
59
60 $res = 0;
61
62 if ($maskconstmrp && preg_match('/_MASK$/', $maskconstmrp)) {
63 $res = dolibarr_set_const($db, $maskconstmrp, $maskmrp, 'chaine', 0, '', $conf->entity);
64 }
65
66 if (!($res > 0)) {
67 $error++;
68 }
69
70 if (!$error) {
71 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
72 } else {
73 setEventMessages($langs->trans("Error"), null, 'errors');
74 }
75} elseif ($action == 'specimen') {
76 $modele = GETPOST('module', 'alpha');
77
78 $mo = new Mo($db);
79 $mo->initAsSpecimen();
80
81 // Search template files
82 $file = '';
83 $classname = '';
84 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
85 foreach ($dirmodels as $reldir) {
86 $file = dol_buildpath($reldir."core/modules/mrp/doc/pdf_".$modele.".modules.php", 0);
87 if (file_exists($file)) {
88 $classname = "pdf_".$modele;
89 break;
90 }
91 }
92
93 if ($classname !== '') {
94 require_once $file;
95
96 $module = new $classname($db);
97 '@phan-var-force ModelePDFMo $module';
98
99 if ($module->write_file($mo, $langs) > 0) {
100 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mrp&file=SPECIMEN.pdf");
101 return;
102 } else {
103 setEventMessages($module->error, null, 'errors');
104 dol_syslog($module->error, LOG_ERR);
105 }
106 } else {
107 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
108 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
109 }
110} elseif ($action == 'set') {
111 // Activate a model
112 $ret = addDocumentModel($value, $type, $label, $scandir);
113} elseif ($action == 'del') {
114 $ret = delDocumentModel($value, $type);
115 if ($ret > 0) {
116 if ($conf->global->MRP_MO_ADDON_PDF == "$value") {
117 dolibarr_del_const($db, 'MRP_MO_ADDON_PDF', $conf->entity);
118 }
119 }
120} elseif ($action == 'setdoc') {
121 // Set default model
122 if (dolibarr_set_const($db, "MRP_MO_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
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 $ret = addDocumentModel($value, $type, $label, $scandir);
132 }
133} elseif ($action == 'setmod') {
134 // TODO Check if numbering module chosen can be activated
135 // by calling method canBeActivated
136
137 dolibarr_set_const($db, "MRP_MO_ADDON", $value, 'chaine', 0, '', $conf->entity);
138} elseif ($action == 'set_MRP_MO_DRAFT_WATERMARK') {
139 $draft = GETPOST("MRP_MO_DRAFT_WATERMARK");
140 $res = dolibarr_set_const($db, "MRP_MO_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
141
142 if (!($res > 0)) {
143 $error++;
144 }
145
146 if (!$error) {
147 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
148 } else {
149 setEventMessages($langs->trans("Error"), null, 'errors');
150 }
151} elseif ($action == 'set_MRP_MO_FREE_TEXT') {
152 $freetext = GETPOST("MRP_MO_FREE_TEXT", 'restricthtml'); // No alpha here, we want exact string
153
154 $res = dolibarr_set_const($db, "MRP_MO_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
155
156 if (!($res > 0)) {
157 $error++;
158 }
159
160 if (!$error) {
161 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
162 } else {
163 setEventMessages($langs->trans("Error"), null, 'errors');
164 }
165}
166
167
168/*
169 * View
170 */
171
172$form = new Form($db);
173
174$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
175
176llxHeader("", $langs->trans("MrpSetupPage"), '', '', 0, 0, '', '', '', 'mod-admin page-mrp');
177
178$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
179print load_fiche_titre($langs->trans("MrpSetupPage"), $linkback, 'title_setup');
180
181$head = mrpAdminPrepareHead();
182
183print dol_get_fiche_head($head, 'settings', $langs->trans("MOs"), -1, 'mrp');
184
185/*
186 * MOs Numbering model
187 */
188
189print load_fiche_titre($langs->trans("MOsNumberingModules"), '', '');
190
191print '<table class="noborder centpercent">';
192print '<tr class="liste_titre">';
193print '<td>'.$langs->trans("Name").'</td>';
194print '<td>'.$langs->trans("Description").'</td>';
195print '<td class="nowrap">'.$langs->trans("Example").'</td>';
196print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
197print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
198print '</tr>'."\n";
199
200clearstatcache();
201
202foreach ($dirmodels as $reldir) {
203 $dir = dol_buildpath($reldir."core/modules/mrp/");
204
205 if (is_dir($dir)) {
206 $handle = opendir($dir);
207 if (is_resource($handle)) {
208 while (($file = readdir($handle)) !== false) {
209 if (substr($file, 0, 7) == 'mod_mo_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
210 $file = substr($file, 0, dol_strlen($file) - 4);
211
212 require_once $dir.$file.'.php';
213
214 $module = new $file($db);
215
216 '@phan-var-force ModeleNumRefMos $module';
217
218 // Show modules according to features level
219 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
220 continue;
221 }
222 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
223 continue;
224 }
225
226 if ($module->isEnabled()) {
227 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
228 print $module->info($langs);
229 print '</td>';
230
231 // Show example of numbering model
232 print '<td class="nowrap">';
233 $tmp = $module->getExample();
234 if (preg_match('/^Error/', $tmp)) {
235 $langs->load("errors");
236 print '<div class="error">'.$langs->trans($tmp).'</div>';
237 } elseif ($tmp == 'NotConfigured') {
238 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
239 } else {
240 print $tmp;
241 }
242 print '</td>'."\n";
243
244 print '<td class="center">';
245 if ($conf->global->MRP_MO_ADDON == $file) {
246 print img_picto($langs->trans("Activated"), 'switch_on');
247 } else {
248 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&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 }
268 $htmltooltip .= $nextval.'<br>';
269 } else {
270 $htmltooltip .= $langs->trans($module->error).'<br>';
271 }
272 }
273
274 print '<td class="center">';
275 print $form->textwithpicto('', $htmltooltip, 1, 0);
276 print '</td>';
277
278 print "</tr>\n";
279 }
280 }
281 }
282 closedir($handle);
283 }
284 }
285}
286print "</table><br>\n";
287
288
289/*
290 * Document templates generators
291 */
292
293print load_fiche_titre($langs->trans("MOsModelModule"), '', '');
294
295// Load array def with activated templates
296$def = array();
297$sql = "SELECT nom";
298$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
299$sql .= " WHERE type = '".$db->escape($type)."'";
300$sql .= " AND entity = ".$conf->entity;
301$resql = $db->query($sql);
302if ($resql) {
303 $i = 0;
304 $num_rows = $db->num_rows($resql);
305 while ($i < $num_rows) {
306 $array = $db->fetch_array($resql);
307 if (is_array($array)) {
308 array_push($def, $array[0]);
309 }
310 $i++;
311 }
312} else {
313 dol_print_error($db);
314}
315
316
317print "<table class=\"noborder\" width=\"100%\">\n";
318print "<tr class=\"liste_titre\">\n";
319print '<td>'.$langs->trans("Name").'</td>';
320print '<td>'.$langs->trans("Description").'</td>';
321print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
322print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
323print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
324print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
325print "</tr>\n";
326
327clearstatcache();
328
329foreach ($dirmodels as $reldir) {
330 foreach (array('', '/doc') as $valdir) {
331 $realpath = $reldir."core/modules/mrp".$valdir;
332 $dir = dol_buildpath($realpath);
333
334 if (is_dir($dir)) {
335 $handle = opendir($dir);
336 if (is_resource($handle)) {
337 $filelist = array();
338 while (($file = readdir($handle)) !== false) {
339 $filelist[] = $file;
340 }
341 closedir($handle);
342 arsort($filelist);
343
344 foreach ($filelist as $file) {
345 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
346 if (file_exists($dir.'/'.$file)) {
347 $name = substr($file, 4, dol_strlen($file) - 16);
348 $classname = substr($file, 0, dol_strlen($file) - 12);
349
350 require_once $dir.'/'.$file;
351 $module = new $classname($db);
352
353 '@phan-var-force ModelePDFMo $module';
354
355 $modulequalified = 1;
356 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
357 $modulequalified = 0;
358 }
359 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
360 $modulequalified = 0;
361 }
362
363 if ($modulequalified) {
364 print '<tr class="oddeven"><td width="100">';
365 print(empty($module->name) ? $name : $module->name);
366 print "</td><td>\n";
367 if (method_exists($module, 'info')) {
368 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
369 } else {
370 print $module->description;
371 }
372 print '</td>';
373
374 // Active
375 if (in_array($name, $def)) {
376 print '<td class="center">'."\n";
377 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
378 print img_picto($langs->trans("Enabled"), 'switch_on');
379 print '</a>';
380 print '</td>';
381 } else {
382 print '<td class="center">'."\n";
383 print '<a class="reposition" 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>';
384 print "</td>";
385 }
386
387 // Default
388 print '<td class="center">';
389 if ($conf->global->MRP_MO_ADDON_PDF == $name) {
390 print img_picto($langs->trans("Default"), 'on');
391 } else {
392 print '<a class="reposition" 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>';
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 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
401 }
402 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
403
404 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
405 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
406 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftMOs").': '.yn($module->option_draft_watermark, 1, 1);
407
408
409 print '<td class="center">';
410 print $form->textwithpicto('', $htmltooltip, 1, 0);
411 print '</td>';
412
413 // Preview
414 print '<td class="center">';
415 if ($module->type == 'pdf') {
416 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
417 } else {
418 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
419 }
420 print '</td>';
421
422 print "</tr>\n";
423 }
424 }
425 }
426 }
427 }
428 }
429 }
430}
431
432print '</table>';
433print "<br>";
434
435/*
436 * Other options
437 */
438
439print load_fiche_titre($langs->trans("OtherOptions"), '', '');
440print '<table class="noborder centpercent">';
441print '<tr class="liste_titre">';
442print '<td>'.$langs->trans("Parameter").'</td>';
443print '<td class="center" width="60">'.$langs->trans("Value").'</td>';
444print "<td>&nbsp;</td>\n";
445print "</tr>\n";
446
447$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
448$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
449$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
450foreach ($substitutionarray as $key => $val) {
451 $htmltext .= $key.'<br>';
452}
453$htmltext .= '</i>';
454
455print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
456print '<input type="hidden" name="token" value="'.newToken().'">';
457print '<input type="hidden" name="action" value="set_MRP_MO_FREE_TEXT">';
458print '<tr class="oddeven"><td colspan="2">';
459print $form->textwithpicto($langs->trans("FreeLegalTextOnMOs"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
460$variablename = 'MRP_MO_FREE_TEXT';
461if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
462 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
463} else {
464 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
465 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
466 print $doleditor->Create();
467}
468print '</td><td class="right">';
469print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
470print "</td></tr>\n";
471print '</form>';
472
473//Use draft Watermark
474
475print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
476print '<input type="hidden" name="token" value="'.newToken().'">';
477print "<input type=\"hidden\" name=\"action\" value=\"set_MRP_MO_DRAFT_WATERMARK\">";
478print '<tr class="oddeven"><td>';
479print $form->textwithpicto($langs->trans("WatermarkOnDraftMOs"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
480print '</td><td>';
481print '<input class="flat minwidth200" type="text" name="MRP_MO_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('MRP_MO_DRAFT_WATERMARK')).'">';
482print '</td><td class="right">';
483print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
484print "</td></tr>\n";
485print '</form>';
486
487print '</table>';
488print '<br>';
489
490
491// End of page
492llxFooter();
493$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 a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class for Mo.
Definition mo.class.php:34
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
mrpAdminPrepareHead()
Prepare admin pages header.
Definition mrp.lib.php:31
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:765
$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.