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