dolibarr 20.0.2
delivery.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
10 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
41
42if (!$user->admin) {
44}
45
46$action = GETPOST('action', 'alpha');
47$value = GETPOST('value', 'alpha');
48$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
49
50$label = GETPOST('label', 'alpha');
51$scandir = GETPOST('scan_dir', 'alpha');
52$type = 'delivery';
53
54
55/*
56 * Actions
57 */
58
59include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
60
61
62// Shipment note
63if (isModEnabled('shipping') && !getDolGlobalString('MAIN_SUBMODULE_EXPEDITION')) {
64 // This option should always be set to on when module is on.
65 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity);
66}
67/*
68 if ($action == 'activate_sending')
69 {
70 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1",'chaine',0,'',$conf->entity);
71 header("Location: confexped.php");
72 exit;
73 }
74 if ($action == 'disable_sending')
75 {
76 dolibarr_del_const($db, "MAIN_SUBMODULE_EXPEDITION",$conf->entity);
77 header("Location: confexped.php");
78 exit;
79 }
80 */
81
82// Delivery note
83if ($action == 'activate_delivery') {
84 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity); // We must also enable this
85 dolibarr_set_const($db, "MAIN_SUBMODULE_DELIVERY", "1", 'chaine', 0, '', $conf->entity);
86 header("Location: delivery.php");
87 exit;
88} elseif ($action == 'disable_delivery') {
89 dolibarr_del_const($db, "MAIN_SUBMODULE_DELIVERY", $conf->entity);
90 header("Location: delivery.php");
91 exit;
92}
93
94if ($action == 'updateMask') {
95 $maskconstdelivery = GETPOST('maskconstdelivery', 'aZ09');
96 $maskdelivery = GETPOST('maskdelivery', 'alpha');
97 if ($maskconstdelivery && preg_match('/_MASK$/', $maskconstdelivery)) {
98 $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity);
99 }
100
101 if (!($res > 0)) {
102 $error++;
103 }
104
105 if (!$error) {
106 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
107 } else {
108 setEventMessages($langs->trans("Error"), null, 'errors');
109 }
110}
111
112if ($action == 'set_DELIVERY_FREE_TEXT') {
113 $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
114 $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity);
115
116 if (!($res > 0)) {
117 $error++;
118 }
119
120 if (!$error) {
121 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
122 } else {
123 setEventMessages($langs->trans("Error"), null, 'errors');
124 }
125}
126
127if ($action == 'specimen') {
128 $modele = GETPOST('module', 'alpha');
129
130 $sending = new Delivery($db);
131 $sending->initAsSpecimen();
132
133 // Search template files
134 $file = '';
135 $classname = '';
136 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
137 foreach ($dirmodels as $reldir) {
138 $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0);
139 if (file_exists($file)) {
140 $classname = "pdf_".$modele;
141 break;
142 }
143 }
144
145 if ($classname !== '') {
146 require_once $file;
147
148 $module = new $classname($db);
149 '@phan-var-force ModelePDFDeliveryOrder $module';
150
151 if ($module->write_file($sending, $langs) > 0) {
152 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf");
153 return;
154 } else {
155 setEventMessages($module->error, $module->errors, 'errors');
156 dol_syslog($module->error, LOG_ERR);
157 }
158 } else {
159 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
160 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
161 }
162}
163
164if ($action == 'set') {
165 $ret = addDocumentModel($value, $type, $label, $scandir);
166}
167
168if ($action == 'del') {
169 $ret = delDocumentModel($value, $type);
170 if ($ret > 0) {
171 if (getDolGlobalString('DELIVERY_ADDON_PDF') == $value) {
172 dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity);
173 }
174 }
175}
176
177if ($action == 'setdoc') {
178 if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
179 // La constante qui a ete lue en avant du nouveau set
180 // on passe donc par une variable pour avoir un affichage coherent
181 $conf->global->DELIVERY_ADDON_PDF = $value;
182 }
183
184 // On active le modele
185 $ret = delDocumentModel($value, $type);
186 if ($ret > 0) {
187 $ret = addDocumentModel($value, $type, $label, $scandir);
188 }
189}
190
191if ($action == 'setmod') {
192 // TODO Verify if the chosen numbering module can be activated
193 // by calling method canBeActivated
194
195 dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
196}
197
198
199
200/*
201 * View
202 */
203
204$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
205
206llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-delivery');
207
208$form = new Form($db);
209
210$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
211print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
212print '<br>';
214
215print dol_get_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
216
217
218print '<br>';
219print '<div class="inline-block valignmiddle">'.$langs->trans("DeliveriesOrderAbility").'</div>';
220if (!getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
221 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=activate_delivery&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
222} else {
223 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=disable_delivery&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
224}
225
226print '<br><span class="opacitymedium">'.info_admin($langs->trans("NoNeedForDeliveryReceipts"), 0, 1).'</span>';
227print '<br>';
228print '<br>';
229
230
231
232if (getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
233 // Delivery numbering model
234
235 print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"), '', '');
236
237 print '<table class="noborder centpercent">';
238 print '<tr class="liste_titre">';
239 print '<td width="100">'.$langs->trans("Name").'</td>';
240 print '<td>'.$langs->trans("Description").'</td>';
241 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
242 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
243 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
244 print '</tr>'."\n";
245
246 clearstatcache();
247
248 foreach ($dirmodels as $reldir) {
249 $dir = dol_buildpath($reldir."core/modules/delivery/");
250
251 if (is_dir($dir)) {
252 $handle = opendir($dir);
253 if (is_resource($handle)) {
254 while (($file = readdir($handle)) !== false) {
255 if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) {
256 $file = substr($file, 0, dol_strlen($file) - 4);
257
258 require_once $dir.$file.'.php';
259
260 $module = new $file();
261
262 if ($module->isEnabled()) {
263 // Show modules according to features level
264 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
265 continue;
266 }
267 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
268 continue;
269 }
270
271 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
272 print $module->info($langs);
273 print '</td>';
274
275 // Show example of numbering module
276 print '<td class="nowrap">';
277 $tmp = $module->getExample();
278 if (preg_match('/^Error/', $tmp)) {
279 $langs->load("errors");
280 print '<div class="error">'.$langs->trans($tmp).'</div>';
281 } elseif ($tmp == 'NotConfigured') {
282 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
283 } else {
284 print $tmp;
285 }
286 print '</td>'."\n";
287
288 print '<td class="center">';
289 if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") {
290 print img_picto($langs->trans("Activated"), 'switch_on');
291 } else {
292 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
293 }
294 print '</td>';
295
296 $delivery = new Delivery($db);
297 $delivery->initAsSpecimen();
298
299 // Info
300 $htmltooltip = '';
301 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
302 $nextval = $module->getNextValue($mysoc, $delivery);
303 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
304 $htmltooltip .= ''.$langs->trans("NextValue").': ';
305 if ($nextval) {
306 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
307 $nextval = $langs->trans($nextval);
308 }
309 $htmltooltip .= $nextval.'<br>';
310 } else {
311 $htmltooltip .= $langs->trans($module->error).'<br>';
312 }
313 }
314
315 print '<td class="center">';
316 print $form->textwithpicto('', $htmltooltip, 1, 0);
317 print '</td>';
318
319 print '</tr>';
320 }
321 }
322 }
323 closedir($handle);
324 }
325 }
326 }
327
328 print '</table>';
329
330
331 /*
332 * Documents Models for delivery
333 */
334 print '<br>';
335 print load_fiche_titre($langs->trans("DeliveryOrderModel"), '', '');
336
337 // Defini tableau def de modele
338 $type = "delivery";
339 $def = array();
340
341 $sql = "SELECT nom";
342 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
343 $sql .= " WHERE type = '".$db->escape($type)."'";
344 $sql .= " AND entity = ".$conf->entity;
345
346 $resql = $db->query($sql);
347 if ($resql) {
348 $i = 0;
349 $num_rows = $db->num_rows($resql);
350 while ($i < $num_rows) {
351 $array = $db->fetch_array($resql);
352 if (is_array($array)) {
353 array_push($def, $array[0]);
354 }
355 $i++;
356 }
357 } else {
358 dol_print_error($db);
359 }
360
361 print '<table class="noborder centpercent">';
362 print '<tr class="liste_titre">';
363 print '<td width="140">'.$langs->trans("Name").'</td>';
364 print '<td>'.$langs->trans("Description").'</td>';
365 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
366 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
367 print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
368 print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
369 print "</tr>\n";
370
371 clearstatcache();
372
373 foreach ($dirmodels as $reldir) {
374 $dir = dol_buildpath($reldir."core/modules/delivery/doc/");
375
376 if (is_dir($dir)) {
377 $handle = opendir($dir);
378 if (is_resource($handle)) {
379 $filelist = array();
380 while (($file = readdir($handle)) !== false) {
381 $filelist[] = $file;
382 }
383 closedir($handle);
384 arsort($filelist);
385
386 foreach ($filelist as $file) {
387 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
388 if (file_exists($dir.'/'.$file)) {
389 $name = substr($file, 4, dol_strlen($file) - 16);
390 $classname = substr($file, 0, dol_strlen($file) - 12);
391
392 require_once $dir.'/'.$file;
393 $module = new $classname($db);
394
395 $modulequalified = 1;
396 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
397 $modulequalified = 0;
398 }
399 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
400 $modulequalified = 0;
401 }
402
403 if ($modulequalified) {
404 print '<tr class="oddeven"><td width="100">';
405 print(empty($module->name) ? $name : $module->name);
406 print "</td><td>\n";
407 if (method_exists($module, 'info')) {
408 print $module->info($langs);
409 } else {
410 print $module->description;
411 }
412 print '</td>';
413
414 // Active
415 if (in_array($name, $def)) {
416 print "<td align=\"center\">\n";
417 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
418 print img_picto($langs->trans("Enabled"), 'switch_on');
419 print '</a>';
420 print "</td>";
421 } else {
422 print "<td align=\"center\">\n";
423 print '<a 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>';
424 print "</td>";
425 }
426
427 // Default
428 print "<td align=\"center\">";
429 if (getDolGlobalString('DELIVERY_ADDON_PDF') == "$name") {
430 print img_picto($langs->trans("Default"), 'on');
431 } else {
432 print '<a 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>';
433 }
434 print '</td>';
435
436 // Info
437 $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
438 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
439 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
440 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
441 print '<td class="center">';
442 print $form->textwithpicto('', $htmltooltip, 1, 0);
443 print '</td>';
444
445 // Preview
446 print '<td class="center">';
447 if ($module->type == 'pdf') {
448 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
449 } else {
450 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
451 }
452 print '</td>';
453
454 print '</tr>';
455 }
456 }
457 }
458 }
459 }
460 }
461 }
462
463 print '</table>';
464
465 // Other Options
466 print "<br>";
467 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
468
469 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
470 print '<input type="hidden" name="token" value="'.newToken().'">';
471 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
472
473 print '<table class="noborder centpercent">';
474 print '<tr class="liste_titre">';
475 print '<td>'.$langs->trans("Parameter").'</td>';
476 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
477 print '<td width="80">&nbsp;</td>';
478 print "</tr>\n";
479
480 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
481 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
482 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
483 foreach ($substitutionarray as $key => $val) {
484 $htmltext .= $key.'<br>';
485 }
486 $htmltext .= '</i>';
487
488 print '<tr class="oddeven"><td colspan="2">';
489 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
490 $variablename = 'DELIVERY_FREE_TEXT';
491 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
492 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
493 } else {
494 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
495 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
496 print $doleditor->Create();
497 }
498 print '</td><td class="right">';
499 print "</td></tr>\n";
500
501 print '</table>';
502
503 print '<div class="center">';
504 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
505 print '</div>';
506
507 print '</form>';
508}
509
510// End of page
511llxFooter();
512$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 receptions.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
expedition_admin_prepare_head()
Return array head with list of tabs to view object information.
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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:140
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.