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