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 if ($maskconstmrp && preg_match('/_MASK$/', $maskconstmrp)) {
61 $res = dolibarr_set_const($db, $maskconstmrp, $maskmrp, 'chaine', 0, '', $conf->entity);
62 }
63
64 if (!($res > 0)) {
65 $error++;
66 }
67
68 if (!$error) {
69 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
70 } else {
71 setEventMessages($langs->trans("Error"), null, 'errors');
72 }
73} elseif ($action == 'specimen') {
74 $modele = GETPOST('module', 'alpha');
75
76 $mo = new Mo($db);
77 $mo->initAsSpecimen();
78
79 // Search template files
80 $file = '';
81 $classname = '';
82 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
83 foreach ($dirmodels as $reldir) {
84 $file = dol_buildpath($reldir."core/modules/mrp/doc/pdf_".$modele.".modules.php", 0);
85 if (file_exists($file)) {
86 $classname = "pdf_".$modele;
87 break;
88 }
89 }
90
91 if ($classname !== '') {
92 require_once $file;
93
94 $module = new $classname($db);
95 '@phan-var-force ModelePDFMo $module';
96
97 if ($module->write_file($mo, $langs) > 0) {
98 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mrp&file=SPECIMEN.pdf");
99 return;
100 } else {
101 setEventMessages($module->error, null, 'errors');
102 dol_syslog($module->error, LOG_ERR);
103 }
104 } else {
105 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
106 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
107 }
108} elseif ($action == 'set') {
109 // Activate a model
110 $ret = addDocumentModel($value, $type, $label, $scandir);
111} elseif ($action == 'del') {
112 $ret = delDocumentModel($value, $type);
113 if ($ret > 0) {
114 if ($conf->global->MRP_MO_ADDON_PDF == "$value") {
115 dolibarr_del_const($db, 'MRP_MO_ADDON_PDF', $conf->entity);
116 }
117 }
118} elseif ($action == 'setdoc') {
119 // Set default model
120 if (dolibarr_set_const($db, "MRP_MO_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
121 // The constant that was read before the new set
122 // We therefore requires a variable to have a coherent view
123 $conf->global->MRP_MO_ADDON_PDF = $value;
124 }
125
126 // On active le modele
127 $ret = delDocumentModel($value, $type);
128 if ($ret > 0) {
129 $ret = addDocumentModel($value, $type, $label, $scandir);
130 }
131} elseif ($action == 'setmod') {
132 // TODO Check if numbering module chosen can be activated
133 // by calling method canBeActivated
134
135 dolibarr_set_const($db, "MRP_MO_ADDON", $value, 'chaine', 0, '', $conf->entity);
136} elseif ($action == 'set_MRP_MO_DRAFT_WATERMARK') {
137 $draft = GETPOST("MRP_MO_DRAFT_WATERMARK");
138 $res = dolibarr_set_const($db, "MRP_MO_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
139
140 if (!($res > 0)) {
141 $error++;
142 }
143
144 if (!$error) {
145 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
146 } else {
147 setEventMessages($langs->trans("Error"), null, 'errors');
148 }
149} elseif ($action == 'set_MRP_MO_FREE_TEXT') {
150 $freetext = GETPOST("MRP_MO_FREE_TEXT", 'restricthtml'); // No alpha here, we want exact string
151
152 $res = dolibarr_set_const($db, "MRP_MO_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
153
154 if (!($res > 0)) {
155 $error++;
156 }
157
158 if (!$error) {
159 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
160 } else {
161 setEventMessages($langs->trans("Error"), null, 'errors');
162 }
163}
164
165
166/*
167 * View
168 */
169
170$form = new Form($db);
171
172$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
173
174llxHeader("", $langs->trans("MrpSetupPage"), '', '', 0, 0, '', '', '', 'mod-admin page-mrp');
175
176$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
177print load_fiche_titre($langs->trans("MrpSetupPage"), $linkback, 'title_setup');
178
179$head = mrpAdminPrepareHead();
180
181print dol_get_fiche_head($head, 'settings', $langs->trans("MOs"), -1, 'mrp');
182
183/*
184 * MOs Numbering model
185 */
186
187print load_fiche_titre($langs->trans("MOsNumberingModules"), '', '');
188
189print '<table class="noborder centpercent">';
190print '<tr class="liste_titre">';
191print '<td>'.$langs->trans("Name").'</td>';
192print '<td>'.$langs->trans("Description").'</td>';
193print '<td class="nowrap">'.$langs->trans("Example").'</td>';
194print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
195print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
196print '</tr>'."\n";
197
198clearstatcache();
199
200foreach ($dirmodels as $reldir) {
201 $dir = dol_buildpath($reldir."core/modules/mrp/");
202
203 if (is_dir($dir)) {
204 $handle = opendir($dir);
205 if (is_resource($handle)) {
206 while (($file = readdir($handle)) !== false) {
207 if (substr($file, 0, 7) == 'mod_mo_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
208 $file = substr($file, 0, dol_strlen($file) - 4);
209
210 require_once $dir.$file.'.php';
211
212 $module = new $file($db);
213
214 '@phan-var-force ModeleNumRefMos $module';
215
216 // Show modules according to features level
217 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
218 continue;
219 }
220 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
221 continue;
222 }
223
224 if ($module->isEnabled()) {
225 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
226 print $module->info($langs);
227 print '</td>';
228
229 // Show example of numbering model
230 print '<td class="nowrap">';
231 $tmp = $module->getExample();
232 if (preg_match('/^Error/', $tmp)) {
233 $langs->load("errors");
234 print '<div class="error">'.$langs->trans($tmp).'</div>';
235 } elseif ($tmp == 'NotConfigured') {
236 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
237 } else {
238 print $tmp;
239 }
240 print '</td>'."\n";
241
242 print '<td class="center">';
243 if ($conf->global->MRP_MO_ADDON == $file) {
244 print img_picto($langs->trans("Activated"), 'switch_on');
245 } else {
246 print '<a class="reposition" 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 $mrp = new Mo($db);
253 $mrp->initAsSpecimen();
254
255 // Info
256 $htmltooltip = '';
257 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
258 $mrp->type = 0;
259 $nextval = $module->getNextValue($mysoc, $mrp);
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, 0);
274 print '</td>';
275
276 print "</tr>\n";
277 }
278 }
279 }
280 closedir($handle);
281 }
282 }
283}
284print "</table><br>\n";
285
286
287/*
288 * Document templates generators
289 */
290
291print load_fiche_titre($langs->trans("MOsModelModule"), '', '');
292
293// Load array def with activated templates
294$def = array();
295$sql = "SELECT nom";
296$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
297$sql .= " WHERE type = '".$db->escape($type)."'";
298$sql .= " AND entity = ".$conf->entity;
299$resql = $db->query($sql);
300if ($resql) {
301 $i = 0;
302 $num_rows = $db->num_rows($resql);
303 while ($i < $num_rows) {
304 $array = $db->fetch_array($resql);
305 if (is_array($array)) {
306 array_push($def, $array[0]);
307 }
308 $i++;
309 }
310} else {
311 dol_print_error($db);
312}
313
314
315print "<table class=\"noborder\" width=\"100%\">\n";
316print "<tr class=\"liste_titre\">\n";
317print '<td>'.$langs->trans("Name").'</td>';
318print '<td>'.$langs->trans("Description").'</td>';
319print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
320print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
321print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
322print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
323print "</tr>\n";
324
325clearstatcache();
326
327foreach ($dirmodels as $reldir) {
328 foreach (array('', '/doc') as $valdir) {
329 $realpath = $reldir."core/modules/mrp".$valdir;
330 $dir = dol_buildpath($realpath);
331
332 if (is_dir($dir)) {
333 $handle = opendir($dir);
334 if (is_resource($handle)) {
335 $filelist = array();
336 while (($file = readdir($handle)) !== false) {
337 $filelist[] = $file;
338 }
339 closedir($handle);
340 arsort($filelist);
341
342 foreach ($filelist as $file) {
343 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
344 if (file_exists($dir.'/'.$file)) {
345 $name = substr($file, 4, dol_strlen($file) - 16);
346 $classname = substr($file, 0, dol_strlen($file) - 12);
347
348 require_once $dir.'/'.$file;
349 $module = new $classname($db);
350
351 '@phan-var-force ModelePDFMo $module';
352
353 $modulequalified = 1;
354 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
355 $modulequalified = 0;
356 }
357 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
358 $modulequalified = 0;
359 }
360
361 if ($modulequalified) {
362 print '<tr class="oddeven"><td width="100">';
363 print(empty($module->name) ? $name : $module->name);
364 print "</td><td>\n";
365 if (method_exists($module, 'info')) {
366 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
367 } else {
368 print $module->description;
369 }
370 print '</td>';
371
372 // Active
373 if (in_array($name, $def)) {
374 print '<td class="center">'."\n";
375 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
376 print img_picto($langs->trans("Enabled"), 'switch_on');
377 print '</a>';
378 print '</td>';
379 } else {
380 print '<td class="center">'."\n";
381 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>';
382 print "</td>";
383 }
384
385 // Default
386 print '<td class="center">';
387 if ($conf->global->MRP_MO_ADDON_PDF == $name) {
388 print img_picto($langs->trans("Default"), 'on');
389 } else {
390 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>';
391 }
392 print '</td>';
393
394 // Info
395 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
396 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
397 if ($module->type == 'pdf') {
398 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
399 }
400 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
401
402 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
403 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
404 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftMOs").': '.yn($module->option_draft_watermark, 1, 1);
405
406
407 print '<td class="center">';
408 print $form->textwithpicto('', $htmltooltip, 1, 0);
409 print '</td>';
410
411 // Preview
412 print '<td class="center">';
413 if ($module->type == 'pdf') {
414 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
415 } else {
416 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
417 }
418 print '</td>';
419
420 print "</tr>\n";
421 }
422 }
423 }
424 }
425 }
426 }
427 }
428}
429
430print '</table>';
431print "<br>";
432
433/*
434 * Other options
435 */
436
437print load_fiche_titre($langs->trans("OtherOptions"), '', '');
438print '<table class="noborder centpercent">';
439print '<tr class="liste_titre">';
440print '<td>'.$langs->trans("Parameter").'</td>';
441print '<td class="center" width="60">'.$langs->trans("Value").'</td>';
442print "<td>&nbsp;</td>\n";
443print "</tr>\n";
444
445$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
446$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
447$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
448foreach ($substitutionarray as $key => $val) {
449 $htmltext .= $key.'<br>';
450}
451$htmltext .= '</i>';
452
453print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
454print '<input type="hidden" name="token" value="'.newToken().'">';
455print '<input type="hidden" name="action" value="set_MRP_MO_FREE_TEXT">';
456print '<tr class="oddeven"><td colspan="2">';
457print $form->textwithpicto($langs->trans("FreeLegalTextOnMOs"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
458$variablename = 'MRP_MO_FREE_TEXT';
459if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
460 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
461} else {
462 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
463 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
464 print $doleditor->Create();
465}
466print '</td><td class="right">';
467print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
468print "</td></tr>\n";
469print '</form>';
470
471//Use draft Watermark
472
473print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
474print '<input type="hidden" name="token" value="'.newToken().'">';
475print "<input type=\"hidden\" name=\"action\" value=\"set_MRP_MO_DRAFT_WATERMARK\">";
476print '<tr class="oddeven"><td>';
477print $form->textwithpicto($langs->trans("WatermarkOnDraftMOs"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
478print '</td><td>';
479print '<input class="flat minwidth200" type="text" name="MRP_MO_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('MRP_MO_DRAFT_WATERMARK')).'">';
480print '</td><td class="right">';
481print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
482print "</td></tr>\n";
483print '</form>';
484
485print '</table>';
486print '<br>';
487
488
489// End of page
490llxFooter();
491$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:36
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)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_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'.
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.
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:30
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:769
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.