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