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