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';
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
48// Load translation files required by the page
49$langs->loadLangs(array("admin", "sendings", "other"));
50
51if (!$user->admin) {
53}
54
55$action = GETPOST('action', 'alpha');
56$value = GETPOST('value', 'alpha');
57$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
58
59$label = GETPOST('label', 'alpha');
60$scandir = GETPOST('scan_dir', 'alpha');
61$type = 'delivery';
62
63
64/*
65 * Actions
66 */
67$error = 0;
68
69include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
70
71
72// 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.
73if (isModEnabled('shipping') && !getDolGlobalString('MAIN_SUBMODULE_EXPEDITION')) {
74 // This option should always be set to on when module is on.
75 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity);
76}
77
78// Delivery note
79if ($action == 'activate_delivery') {
80 dolibarr_set_const($db, "MAIN_SUBMODULE_EXPEDITION", "1", 'chaine', 0, '', $conf->entity); // We must also enable this
81 dolibarr_set_const($db, "MAIN_SUBMODULE_DELIVERY", "1", 'chaine', 0, '', $conf->entity);
82 header("Location: delivery.php");
83 exit;
84} elseif ($action == 'disable_delivery') {
85 dolibarr_del_const($db, "MAIN_SUBMODULE_DELIVERY", $conf->entity);
86 header("Location: delivery.php");
87 exit;
88}
89
90if ($action == 'updateMask') {
91 $maskconstdelivery = GETPOST('maskconstdelivery', 'aZ09');
92 $maskdelivery = GETPOST('maskdelivery', 'alpha');
93
94 $res = 0;
95
96 if ($maskconstdelivery && preg_match('/_MASK$/', $maskconstdelivery)) {
97 $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity);
98 }
99
100 if (!($res > 0)) {
101 $error++;
102 }
103
104 if (!$error) {
105 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
106 } else {
107 setEventMessages($langs->trans("Error"), null, 'errors');
108 }
109}
110
111if ($action == 'set_DELIVERY_FREE_TEXT') {
112 $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
113 $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity);
114
115 if (!($res > 0)) {
116 $error++;
117 }
118
119 if (!$error) {
120 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
121 } else {
122 setEventMessages($langs->trans("Error"), null, 'errors');
123 }
124}
125
126if ($action == 'specimen') {
127 $modele = GETPOST('module', 'alpha');
128
129 $sending = new Delivery($db);
130 $sending->initAsSpecimen();
131
132 // Search template files
133 $file = '';
134 $classname = '';
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 $classname = "pdf_".$modele;
140 break;
141 }
142 }
143
144 if ($classname !== '') {
145 require_once $file;
146
147 $module = new $classname($db);
148 '@phan-var-force ModelePDFDeliveryOrder $module';
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 // The constant that was read before the new set
179 // so we go through a variable to get a consistent display
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 Verify if the chosen numbering module can be activated
192 // by calling method 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('', '', '', '', 0, 0, '', '', '', 'mod-admin page-delivery');
206
207$form = new Form($db);
208
209$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>';
210
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><br><span class="opacitymedium">'.info_admin($langs->trans("NoNeedForDeliveryReceipts"), 0, 1).'</span>';
227print '<br><br>';
228print '<br>';
229
230
231
232if (getDolGlobalString('MAIN_SUBMODULE_DELIVERY')) {
233 // Delivery numbering model
234
235 $delivery = new Delivery($db);
236 $delivery->initAsSpecimen();
237
238 printNumberingModuleList('delivery', 'mod_delivery_', 'DELIVERY_ADDON_NUMBER', $langs->trans("DeliveryOrderNumberingModules"), $delivery);
239
240
241 /*
242 * Documents Models for delivery
243 */
244 print '<br>';
245 printDocumentModelList('delivery', 'delivery', 'DELIVERY_ADDON_PDF', $langs->trans("DeliveryOrderModel"), array(
246 'Logo' => 'option_logo',
247 ));
248
249 // Other Options
250 print "<br>";
251 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
252
253 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
254 print '<input type="hidden" name="token" value="'.newToken().'">';
255 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
256
257 print '<table class="noborder centpercent">';
258 print '<tr class="liste_titre">';
259 print '<td>'.$langs->trans("Parameter").'</td>';
260 print '<td align="center" width="60"></td>';
261 print '<td width="80">&nbsp;</td>';
262 print "</tr>\n";
263
264 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
265 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
266 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
267 foreach ($substitutionarray as $key => $val) {
268 $htmltext .= $key.'<br>';
269 }
270 $htmltext .= '</i>';
271
272 print '<tr class="oddeven"><td colspan="2">';
273 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
274 $variablename = 'DELIVERY_FREE_TEXT';
275 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
276 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
277 } else {
278 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
279 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
280 print $doleditor->Create();
281 }
282 print '</td><td class="right">';
283 print "</td></tr>\n";
284
285 print '</table>';
286
287 print '<div class="center">';
288 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
289 print '</div>';
290
291 print '</form>';
292}
293
294// End of page
295llxFooter();
296$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
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:540
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.