dolibarr 25.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-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 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';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array('admin', '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 $langs->load('errors');
118 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
119 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
120 }
121} elseif ($action == 'set') {
122 // Activate a model
123 $ret = addDocumentModel($value, $type, $label, $scandir);
124} elseif ($action == 'del') {
125 $ret = delDocumentModel($value, $type);
126 if ($ret > 0) {
127 if (getDolGlobalString('MRP_MO_ADDON_PDF') == "$value") {
128 dolibarr_del_const($db, 'MRP_MO_ADDON_PDF', $conf->entity);
129 }
130 }
131} elseif ($action == 'setdoc') {
132 // Set default model
133 if (dolibarr_set_const($db, "MRP_MO_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
134 // The constant that was read before the new set
135 // We therefore requires a variable to have a coherent view
136 $conf->global->MRP_MO_ADDON_PDF = $value;
137 }
138
139 // On active le modele
140 $ret = delDocumentModel($value, $type);
141 if ($ret > 0) {
142 $ret = addDocumentModel($value, $type, $label, $scandir);
143 }
144} elseif ($action == 'setmod') {
145 // TODO Check if numbering module chosen can be activated
146 // by calling method canBeActivated
147
148 dolibarr_set_const($db, "MRP_MO_ADDON", $value, 'chaine', 0, '', $conf->entity);
149} elseif ($action == 'set_MRP_MO_DRAFT_WATERMARK') {
150 $draft = GETPOST("MRP_MO_DRAFT_WATERMARK");
151 $res = dolibarr_set_const($db, "MRP_MO_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
152
153 if (!($res > 0)) {
154 $error++;
155 }
156
157 if (!$error) {
158 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
159 } else {
160 setEventMessages($langs->trans("Error"), null, 'errors');
161 }
162} elseif ($action == 'set_MRP_MO_FREE_TEXT') {
163 $freetext = GETPOST("MRP_MO_FREE_TEXT", 'restricthtml'); // No alpha here, we want exact string
164
165 $res = dolibarr_set_const($db, "MRP_MO_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
166
167 if (!($res > 0)) {
168 $error++;
169 }
170
171 if (!$error) {
172 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
173 } else {
174 setEventMessages($langs->trans("Error"), null, 'errors');
175 }
176}
177
178
179/*
180 * View
181 */
182
183$form = new Form($db);
184
185$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
186
187llxHeader("", $langs->trans("MrpSetupPage"), '', '', 0, 0, '', '', '', 'mod-admin page-mrp');
188
189$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
190
191print load_fiche_titre($langs->trans("MrpSetupPage"), $linkback, 'title_setup');
192
193$head = mrpAdminPrepareHead();
194
195print dol_get_fiche_head($head, 'settings', $langs->trans("MOs"), -1, 'mrp');
196
197/*
198 * MOs Numbering model
199 */
200
201print load_fiche_titre($langs->trans("MOsNumberingModules"), '', '');
202
203print '<table class="noborder centpercent">';
204print '<tr class="liste_titre">';
205print '<td>'.$langs->trans("Name").'</td>';
206print '<td>'.$langs->trans("Description").'</td>';
207print '<td class="nowrap">'.$langs->trans("Example").'</td>';
208print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
209print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
210print '</tr>'."\n";
211
212clearstatcache();
213
214foreach ($dirmodels as $reldir) {
215 $dir = dol_buildpath($reldir."core/modules/mrp/");
216
217 if (is_dir($dir)) {
218 $handle = opendir($dir);
219 if (is_resource($handle)) {
220 while (($file = readdir($handle)) !== false) {
221 if (dol_substr($file, 0, 7) == 'mod_mo_' && dol_substr($file, dol_strlen($file) - 3, 3) == 'php') {
222 $file = dol_substr($file, 0, dol_strlen($file) - 4);
223
224 require_once $dir.$file.'.php';
225
226 $module = new $file($db);
227
228 '@phan-var-force ModeleNumRefMos $module';
229
230 // Show modules according to features level
231 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
232 continue;
233 }
234 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
235 continue;
236 }
237
238 if ($module->isEnabled()) {
239 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
240 print $module->info($langs);
241 print '</td>';
242
243 // Show example of numbering model
244 print '<td class="nowrap">';
245 $tmp = $module->getExample();
246 if (preg_match('/^Error/', $tmp)) {
247 $langs->load("errors");
248 print '<div class="error">'.$langs->trans($tmp).'</div>';
249 } elseif ($tmp == 'NotConfigured') {
250 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
251 } else {
252 print $tmp;
253 }
254 print '</td>'."\n";
255
256 print '<td class="center">';
257 if (getDolGlobalString('MRP_MO_ADDON') == $file) {
258 print img_picto($langs->trans("Activated"), 'switch_on');
259 } else {
260 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'">';
261 print img_picto($langs->trans("Disabled"), 'switch_off');
262 print '</a>';
263 }
264 print '</td>';
265
266 $mrp = new Mo($db);
267 $mrp->initAsSpecimen();
268 $product = new Product($db);
269 $product->initAsSpecimen();
270
271 // Info
272 $htmltooltip = '';
273 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
274 $mrp->type = 0;
275 $nextval = $module->getNextValue($product, $mrp);
276 if ((string) $nextval != $langs->trans("NotAvailable")) {
277 $htmltooltip .= ''.$langs->trans("NextValue").': ';
278 if ($nextval) {
279 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
280 $langs->load('errors');
281 $nextval = $langs->trans($nextval);
282 }
283 $htmltooltip .= $nextval.'<br>';
284 } else {
285 $langs->load('errors');
286 $htmltooltip .= $langs->trans($module->error).'<br>';
287 }
288 }
289
290 print '<td class="center">';
291 print $form->textwithpicto('', $htmltooltip, 1, 'info');
292 print '</td>';
293
294 print "</tr>\n";
295 }
296 }
297 }
298 closedir($handle);
299 }
300 }
301}
302print "</table><br>\n";
303
304
305/*
306 * Document templates generators
307 */
308
309printDocumentModelList($type, 'mrp', 'MRP_MO_ADDON_PDF', $langs->trans("MOsModelModule"), array(
310 'MultiLanguage' => 'option_multilang',
311 'WatermarkOnDraftMOs' => 'option_draft_watermark',
312));
313print "<br>";
314
315/*
316 * Other options
317 */
318
319print load_fiche_titre($langs->trans("OtherOptions"), '', '');
320print '<table class="noborder centpercent">';
321print '<tr class="liste_titre">';
322print '<td>'.$langs->trans("Parameter").'</td>';
323print '<td class="center" width="60"></td>';
324print "<td>&nbsp;</td>\n";
325print "</tr>\n";
326
327$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
328$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
329$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
330foreach ($substitutionarray as $key => $val) {
331 $htmltext .= $key.'<br>';
332}
333$htmltext .= '</i>';
334
335print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
336print '<input type="hidden" name="token" value="'.newToken().'">';
337print '<input type="hidden" name="action" value="set_MRP_MO_FREE_TEXT">';
338print '<tr class="oddeven"><td colspan="2">';
339print $form->textwithpicto($langs->trans("FreeLegalTextOnMOs"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
340$variablename = 'MRP_MO_FREE_TEXT';
341if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
342 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
343} else {
344 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
345 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
346 print $doleditor->Create();
347}
348print '</td><td class="right">';
349print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
350print "</td></tr>\n";
351print '</form>';
352
353//Use draft Watermark
354
355print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">';
356print '<input type="hidden" name="token" value="'.newToken().'">';
357print "<input type=\"hidden\" name=\"action\" value=\"set_MRP_MO_DRAFT_WATERMARK\">";
358print '<tr class="oddeven"><td>';
359print $form->textwithpicto($langs->trans("WatermarkOnDraftMOs"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
360print '</td><td>';
361print '<input class="flat minwidth200" type="text" name="MRP_MO_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('MRP_MO_DRAFT_WATERMARK')).'">';
362print '</td><td class="right">';
363print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
364print "</td></tr>\n";
365print '</form>';
366
367print '</table>';
368print '<br>';
369
370
371// End of page
372llxFooter();
373$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:35
Class to manage products or services.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.