dolibarr 18.0.6
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') && empty($conf->global->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 = ''; $classname = ''; $filefound = 0;
133 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
134 foreach ($dirmodels as $reldir) {
135 $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0);
136 if (file_exists($file)) {
137 $filefound = 1;
138 $classname = "pdf_".$modele;
139 break;
140 }
141 }
142
143 if ($filefound) {
144 require_once $file;
145
146 $module = new $classname($db);
147
148 if ($module->write_file($sending, $langs) > 0) {
149 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf");
150 return;
151 } else {
152 setEventMessages($module->error, $module->errors, 'errors');
153 dol_syslog($module->error, LOG_ERR);
154 }
155 } else {
156 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
157 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
158 }
159}
160
161if ($action == 'set') {
162 $ret = addDocumentModel($value, $type, $label, $scandir);
163}
164
165if ($action == 'del') {
166 $ret = delDocumentModel($value, $type);
167 if ($ret > 0) {
168 if (getDolGlobalString('DELIVERY_ADDON_PDF') == $value) {
169 dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity);
170 }
171 }
172}
173
174if ($action == 'setdoc') {
175 if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
176 // La constante qui a ete lue en avant du nouveau set
177 // on passe donc par une variable pour avoir un affichage coherent
178 $conf->global->DELIVERY_ADDON_PDF = $value;
179 }
180
181 // On active le modele
182 $ret = delDocumentModel($value, $type);
183 if ($ret > 0) {
184 $ret = addDocumentModel($value, $type, $label, $scandir);
185 }
186}
187
188if ($action == 'setmod') {
189 // TODO Verifier si module numerotation choisi peut etre active
190 // par appel methode canBeActivated
191
192 dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
193}
194
195
196
197/*
198 * View
199 */
200
201$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
202
203llxHeader("", "");
204
205$form = new Form($db);
206
207$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
208print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
209print '<br>';
211
212print dol_get_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
213
214
215print '<br>';
216print '<div class="inline-block valignmiddle">'.$langs->trans("DeliveriesOrderAbility").'</div>';
217if (empty($conf->global->MAIN_SUBMODULE_DELIVERY)) {
218 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=activate_delivery&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
219} else {
220 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=disable_delivery&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
221}
222
223print '<br><span class="opacitymedium">'.info_admin($langs->trans("NoNeedForDeliveryReceipts"), 0, 1).'</span>';
224print '<br>';
225print '<br>';
226
227
228
229if (!empty($conf->global->MAIN_SUBMODULE_DELIVERY)) {
230 // Delivery numbering model
231
232 print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"), '', '');
233
234 print '<table class="noborder centpercent">';
235 print '<tr class="liste_titre">';
236 print '<td width="100">'.$langs->trans("Name").'</td>';
237 print '<td>'.$langs->trans("Description").'</td>';
238 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
239 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
240 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
241 print '</tr>'."\n";
242
243 clearstatcache();
244
245 foreach ($dirmodels as $reldir) {
246 $dir = dol_buildpath($reldir."core/modules/delivery/");
247
248 if (is_dir($dir)) {
249 $handle = opendir($dir);
250 if (is_resource($handle)) {
251 while (($file = readdir($handle)) !== false) {
252 if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) {
253 $file = substr($file, 0, dol_strlen($file) - 4);
254
255 require_once $dir.$file.'.php';
256
257 $module = new $file;
258
259 if ($module->isEnabled()) {
260 // Show modules according to features level
261 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
262 continue;
263 }
264 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
265 continue;
266 }
267
268 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
269 print $module->info();
270 print '</td>';
271
272 // Show example of numbering module
273 print '<td class="nowrap">';
274 $tmp = $module->getExample();
275 if (preg_match('/^Error/', $tmp)) {
276 $langs->load("errors");
277 print '<div class="error">'.$langs->trans($tmp).'</div>';
278 } elseif ($tmp == 'NotConfigured') {
279 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
280 } else {
281 print $tmp;
282 }
283 print '</td>'."\n";
284
285 print '<td class="center">';
286 if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") {
287 print img_picto($langs->trans("Activated"), 'switch_on');
288 } else {
289 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>';
290 }
291 print '</td>';
292
293 $delivery = new Delivery($db);
294 $delivery->initAsSpecimen();
295
296 // Info
297 $htmltooltip = '';
298 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
299 $nextval = $module->getNextValue($mysoc, $delivery);
300 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
301 $htmltooltip .= ''.$langs->trans("NextValue").': ';
302 if ($nextval) {
303 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
304 $nextval = $langs->trans($nextval);
305 }
306 $htmltooltip .= $nextval.'<br>';
307 } else {
308 $htmltooltip .= $langs->trans($module->error).'<br>';
309 }
310 }
311
312 print '<td class="center">';
313 print $form->textwithpicto('', $htmltooltip, 1, 0);
314 print '</td>';
315
316 print '</tr>';
317 }
318 }
319 }
320 closedir($handle);
321 }
322 }
323 }
324
325 print '</table>';
326
327
328 /*
329 * Documents Models for delivery
330 */
331 print '<br>';
332 print load_fiche_titre($langs->trans("DeliveryOrderModel"), '', '');
333
334 // Defini tableau def de modele
335 $type = "delivery";
336 $def = array();
337
338 $sql = "SELECT nom";
339 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
340 $sql .= " WHERE type = '".$db->escape($type)."'";
341 $sql .= " AND entity = ".$conf->entity;
342
343 $resql = $db->query($sql);
344 if ($resql) {
345 $i = 0;
346 $num_rows = $db->num_rows($resql);
347 while ($i < $num_rows) {
348 $array = $db->fetch_array($resql);
349 array_push($def, $array[0]);
350 $i++;
351 }
352 } else {
353 dol_print_error($db);
354 }
355
356 print '<table class="noborder centpercent">';
357 print '<tr class="liste_titre">';
358 print '<td width="140">'.$langs->trans("Name").'</td>';
359 print '<td>'.$langs->trans("Description").'</td>';
360 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
361 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
362 print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
363 print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
364 print "</tr>\n";
365
366 clearstatcache();
367
368 foreach ($dirmodels as $reldir) {
369 $dir = dol_buildpath($reldir."core/modules/delivery/doc/");
370
371 if (is_dir($dir)) {
372 $handle = opendir($dir);
373 if (is_resource($handle)) {
374 while (($file = readdir($handle)) !== false) {
375 $filelist[] = $file;
376 }
377 closedir($handle);
378 arsort($filelist);
379
380 foreach ($filelist as $file) {
381 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
382 if (file_exists($dir.'/'.$file)) {
383 $name = substr($file, 4, dol_strlen($file) - 16);
384 $classname = substr($file, 0, dol_strlen($file) - 12);
385
386 require_once $dir.'/'.$file;
387 $module = new $classname($db);
388
389 $modulequalified = 1;
390 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
391 $modulequalified = 0;
392 }
393 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
394 $modulequalified = 0;
395 }
396
397 if ($modulequalified) {
398 print '<tr class="oddeven"><td width="100">';
399 print (empty($module->name) ? $name : $module->name);
400 print "</td><td>\n";
401 if (method_exists($module, 'info')) {
402 print $module->info($langs);
403 } else {
404 print $module->description;
405 }
406 print '</td>';
407
408 // Active
409 if (in_array($name, $def)) {
410 print "<td align=\"center\">\n";
411 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
412 print img_picto($langs->trans("Enabled"), 'switch_on');
413 print '</a>';
414 print "</td>";
415 } else {
416 print "<td align=\"center\">\n";
417 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>';
418 print "</td>";
419 }
420
421 // Default
422 print "<td align=\"center\">";
423 if (getDolGlobalString('DELIVERY_ADDON_PDF') == "$name") {
424 print img_picto($langs->trans("Default"), 'on');
425 } else {
426 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>';
427 }
428 print '</td>';
429
430 // Info
431 $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
432 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
433 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
434 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
435 print '<td class="center">';
436 print $form->textwithpicto('', $htmltooltip, 1, 0);
437 print '</td>';
438
439 // Preview
440 print '<td class="center">';
441 if ($module->type == 'pdf') {
442 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
443 } else {
444 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
445 }
446 print '</td>';
447
448 print '</tr>';
449 }
450 }
451 }
452 }
453 }
454 }
455 }
456
457 print '</table>';
458
459 // Other Options
460 print "<br>";
461 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
462
463 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
464 print '<input type="hidden" name="token" value="'.newToken().'">';
465 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
466
467 print '<table class="noborder centpercent">';
468 print '<tr class="liste_titre">';
469 print '<td>'.$langs->trans("Parameter").'</td>';
470 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
471 print '<td width="80">&nbsp;</td>';
472 print "</tr>\n";
473
474 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
475 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
476 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
477 foreach ($substitutionarray as $key => $val) {
478 $htmltext .= $key.'<br>';
479 }
480 $htmltext .= '</i>';
481
482 print '<tr class="oddeven"><td colspan="2">';
483 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
484 $variablename = 'DELIVERY_FREE_TEXT';
485 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
486 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
487 } else {
488 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
489 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
490 print $doleditor->Create();
491 }
492 print '</td><td class="right">';
493 print "</td></tr>\n";
494
495 print '</table>';
496
497 print '<div class="center">';
498 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
499 print '</div>';
500
501 print '</form>';
502}
503
504// End of page
505llxFooter();
506$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 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.
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: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.