dolibarr 25.0.0-alpha
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-2026 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2024-2026 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';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
46
47// Load translation files required by the page
48$langs->loadLangs(array("admin", "sendings", "other"));
49
50if (!$user->admin) {
52}
53
54$action = GETPOST('action', 'alpha');
55$value = GETPOST('value', 'alpha');
56$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
57
58$label = GETPOST('label', 'alpha');
59$scandir = GETPOST('scan_dir', 'alpha');
60$type = 'delivery';
61
62
63/*
64 * Actions
65 */
66$error = 0;
67
68include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
69
70
71// Shipment note. We force MAIN_SUBMODULE_EXPEDITION to on because this var is still used. TODO We should remove it, only MAIN_SUBMODULE_DELIVERY must be used.
72if (isModEnabled('shipping') && !getDolGlobalString('MAIN_SUBMODULE_EXPEDITION')) {
73 // This option should always be set to on when module is on.
74 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity);
75}
76
77// Delivery note
78if ($action == 'activate_delivery') {
79 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity); // We must also enable this
80 dolibarr_set_const($db, "MAIN_SUBMODULE_DELIVERY", "1", 'chaine', 0, '', $conf->entity);
81 header("Location: delivery.php");
82 exit;
83} elseif ($action == 'disable_delivery') {
84 dolibarr_del_const($db, "MAIN_SUBMODULE_DELIVERY", $conf->entity);
85 header("Location: delivery.php");
86 exit;
87}
88
89if ($action == 'updateMask') {
90 $maskconstdelivery = GETPOST('maskconstdelivery', 'aZ09');
91 $maskdelivery = GETPOST('maskdelivery', 'alpha');
92
93 $res = 0;
94
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 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
135 foreach ($dirmodels as $reldir) {
136 $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0);
137 if (file_exists($file)) {
138 $classname = "pdf_".$modele;
139 break;
140 }
141 }
142
143 if ($classname !== '') {
144 require_once $file;
145
146 $module = new $classname($db);
147 '@phan-var-force ModelePDFDeliveryOrder $module';
148
149 if ($module->write_file($sending, $langs) > 0) {
150 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf");
151 return;
152 } else {
153 setEventMessages($module->error, $module->errors, 'errors');
154 dol_syslog($module->error, LOG_ERR);
155 }
156 } else {
157 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
158 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
159 }
160}
161
162if ($action == 'set') {
163 $ret = addDocumentModel($value, $type, $label, $scandir);
164}
165
166if ($action == 'del') {
167 $ret = delDocumentModel($value, $type);
168 if ($ret > 0) {
169 if (getDolGlobalString('DELIVERY_ADDON_PDF') == $value) {
170 dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity);
171 }
172 }
173}
174
175if ($action == 'setdoc') {
176 if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
177 // The constant that was read before the new set
178 // so we go through a variable to get a consistent display
179 $conf->global->DELIVERY_ADDON_PDF = $value;
180 }
181
182 // We activate the template
183 $ret = delDocumentModel($value, $type);
184 if ($ret > 0) {
185 $ret = addDocumentModel($value, $type, $label, $scandir);
186 }
187}
188if ($action == 'unsetdoc') {
189 if (dolibarr_del_const($db, "DELIVERY_ADDON_PDF")) {
190 // The constant that was read before the new set
191 // so we go through a variable to get a consistent display
192 $conf->global->DELIVERY_ADDON_PDF = '';
193 }
194}
195
196
197if ($action == 'setmod') {
198 // TODO Verify if the chosen numbering module can be activated
199 // by calling method canBeActivated
200
201 dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
202}
203
204
205
206/*
207 * View
208 */
209
210$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
211
212llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-delivery');
213
214$form = new Form($db);
215
216$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
217
218print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
219
221
222print dol_get_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
223
224
225print '<br>';
226print '<div class="inline-block valignmiddle">'.$langs->trans("DeliveriesOrderAbility").'</div>';
227if (!getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
228 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=activate_delivery&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
229} else {
230 print ' <a class="inline-block valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=disable_delivery&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
231}
232
233print '<br><br><span class="opacitymedium">'.info_admin($langs->trans("NoNeedForDeliveryReceipts"), 0, 1).'</span>';
234print '<br><br>';
235print '<br>';
236
237
238
239if (getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
240 // Delivery numbering model
241
242 $delivery = new Delivery($db);
243 $delivery->initAsSpecimen();
244
245 printNumberingModuleList('delivery', 'mod_delivery_', 'DELIVERY_ADDON_NUMBER', $langs->trans("DeliveryOrderNumberingModules"), $delivery);
246
247
248 /*
249 * Documents Models for delivery
250 */
251 print '<br>';
252 printDocumentModelList('delivery', 'delivery', 'DELIVERY_ADDON_PDF', $langs->trans("DeliveryOrderModel"), array('Logo' => 'option_logo'), false, '', 1, 'unsetdoc');
253
254 // Other Options
255 print "<br>";
256 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
257
258 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
259 print '<input type="hidden" name="token" value="'.newToken().'">';
260 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
261
262 print '<table class="noborder centpercent">';
263 print '<tr class="liste_titre">';
264 print '<td>'.$langs->trans("Parameter").'</td>';
265 print '<td align="center" width="60"></td>';
266 print '<td width="80">&nbsp;</td>';
267 print "</tr>\n";
268
269 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
270 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
271 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
272 foreach ($substitutionarray as $key => $val) {
273 $htmltext .= $key.'<br>';
274 }
275 $htmltext .= '</i>';
276
277 print '<tr class="oddeven"><td colspan="2">';
278 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
279 $variablename = 'DELIVERY_FREE_TEXT';
280 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
281 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
282 } else {
283 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
284 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
285 print $doleditor->Create();
286 }
287 print '</td><td class="right">';
288 print "</td></tr>\n";
289
290 print '</table>';
291
292 print '<div class="center">';
293 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
294 print '</div>';
295
296 print '</form>';
297}
298
299// End of page
300llxFooter();
301$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage receptions.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
expedition_admin_prepare_head()
Return array head with list of tabs to view object information.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.