dolibarr 25.0.0-alpha
expedition.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2008 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-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
39
49// Load translation files required by the page
50$langs->loadLangs(array("admin", "sendings", "other"));
51
52if (!$user->admin) {
54}
55
56$action = GETPOST('action', 'aZ09');
57$value = GETPOST('value', 'alpha');
58$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
59
60$label = GETPOST('label', 'alpha');
61$scandir = GETPOST('scan_dir', 'alpha');
62$type = 'shipping';
63
64if (!getDolGlobalString('EXPEDITION_ADDON_NUMBER')) {
65 $conf->global->EXPEDITION_ADDON_NUMBER = 'mod_expedition_safor';
66}
67
68
69/*
70 * Actions
71 */
72$error = 0;
73
74include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
75
76if ($action == 'updateMask') {
77 $maskconst = GETPOST('maskconstexpedition', 'aZ09');
78 $maskvalue = GETPOST('maskexpedition', 'alpha');
79 if (!empty($maskconst) && preg_match('/_MASK$/', $maskconst)) {
80 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
81 }
82
83 if (isset($res)) {
84 if ($res > 0) {
85 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
86 } else {
87 setEventMessages($langs->trans("Error"), null, 'errors');
88 }
89 }
90} elseif ($action == 'set_param') {
91 $freetext = GETPOST('SHIPPING_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
92 $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
93 if ($res <= 0) {
94 $error++;
95 setEventMessages($langs->trans("Error"), null, 'errors');
96 }
97
98 $draft = GETPOST('SHIPPING_DRAFT_WATERMARK', 'alpha');
99 $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
100 if ($res <= 0) {
101 $error++;
102 setEventMessages($langs->trans("Error"), null, 'errors');
103 }
104
105 if (!$error) {
106 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
107 }
108} elseif ($action == 'specimen') {
109 $modele = GETPOST('module', 'alpha');
110
111 $exp = new Expedition($db);
112 $exp->initAsSpecimen();
113
114 // Search template files
115 $file = '';
116 $classname = '';
117 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
118 foreach ($dirmodels as $reldir) {
119 $file = dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php", 0);
120 if (file_exists($file)) {
121 $classname = "pdf_".$modele;
122 break;
123 }
124 }
125
126 if ($classname !== '') {
127 require_once $file;
128
129 $module = new $classname($db);
130 '@phan-var-force ModelePdfExpedition $module';
131
132 if ($module->write_file($exp, $langs) > 0) {
133 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
134 return;
135 } else {
136 setEventMessages($module->error, $module->errors, 'errors');
137 dol_syslog($module->error, LOG_ERR);
138 }
139 } else {
140 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
141 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
142 }
143} elseif ($action == 'set') {
144 // Activate a model
145 $ret = addDocumentModel($value, $type, $label, $scandir);
146} elseif ($action == 'del') {
147 $ret = delDocumentModel($value, $type);
148 if ($ret > 0) {
149 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == "$value") {
150 dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF', $conf->entity);
151 }
152 }
153} elseif ($action == 'setdoc') {
154 // Set default model
155 if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
156 // The constant that was read before the new set
157 // so we go through a variable to get a consistent display
158 $conf->global->EXPEDITION_ADDON_PDF = $value;
159 }
160
161 // On active le modele
162 $ret = delDocumentModel($value, $type);
163 if ($ret > 0) {
164 $ret = addDocumentModel($value, $type, $label, $scandir);
165 }
166} elseif ($action == 'setmodel') {
167 dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
168}
169
170
171/*
172 * View
173 */
174
175$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
176
177$form = new Form($db);
178
179llxHeader("", $langs->trans("SendingsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expedition');
180
181$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>';
182
183print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
184print '<br>';
186
187print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
188
189// Shipment numbering model
190
191$expedition = new Expedition($db);
192$expedition->initAsSpecimen();
193
194printNumberingModuleList('expedition', 'mod_expedition_', 'EXPEDITION_ADDON_NUMBER', $langs->trans("SendingsNumberingModules"), $expedition, 'setmodel');
195
196print '<br>';
197
198
199/*
200 * Documents models for Sendings Receipt
201 */
202printDocumentModelList('shipping', 'expedition', 'EXPEDITION_ADDON_PDF', $langs->trans("SendingsReceiptModel"), array(
203 'Logo' => 'option_logo',
204 'PaymentMode' => 'option_modereg',
205 'PaymentConditions' => 'option_condreg',
206 'MultiLanguage' => 'option_multilang',
207 'WatermarkOnDraftOrders' => 'option_draft_watermark',
208));
209
210
211/*
212 * Other options
213 */
214
215print load_fiche_titre($langs->trans("OtherOptions"), '', '');
216
217print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
218print '<input type="hidden" name="token" value="'.newToken().'">';
219print '<input type="hidden" name="action" value="set_param">';
220
221print '<table class="noborder centpercent">';
222print '<tr class="liste_titre">';
223print "<td>".$langs->trans("Parameter")."</td>\n";
224print "<td></td>\n";
225print '</tr>';
226
227print '<tr class="oddeven">';
228print '<td>'.$langs->trans('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
229print '</td>';
230print '<td>';
231print ajax_constantonoff('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
232print '</td></tr>';
233
234print '<tr class="oddeven">';
235print '<td>'.$langs->trans('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
236print '</td>';
237print '<td>';
238print ajax_constantonoff('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
239print '</td></tr>';
240
241$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
242$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
243$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
244foreach ($substitutionarray as $key => $val) {
245 $htmltext .= $key.'<br>';
246}
247$htmltext .= '</i>';
248
249print '<tr><td colspan="2">';
250print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
251$variablename = 'SHIPPING_FREE_TEXT';
252if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
253 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
254} else {
255 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
256 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
257 print $doleditor->Create();
258}
259print "</td></tr>\n";
260
261print '<tr><td>';
262print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip');
263print '</td><td>';
264print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
265print "</td></tr>\n";
266
267// Allow OnLine Sign
268print '<tr class="oddeven">';
269print '<td>'.$langs->trans("AllowOnLineSign");
270print '</td>';
271print '<td>';
272print ajax_constantonoff('EXPEDITION_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->transnoentitiesnoconv("WarningOnlineSignature", 'https://www.dolistore.com'));
273print '</td></tr>';
274
275// Pre fill shipment qty option
276print '<tr class="oddeven">';
277print '<td>'.$langs->trans("DontPrefillShipmentQty");
278print '</td>';
279print '<td>';
280print ajax_constantonoff('SHIPMENT_DONT_PREFILL_QTY', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, '');
281print '</td></tr>';
282
283
284// Notifications
285print '<tr class="oddeven">';
286print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
287print '<td>';
288print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
289print '</td></tr>';
290
291// More PDF options
292print '<tr class="oddeven">';
293print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
294print '<td>';
295print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
296print '</td></tr>';
297
298print '</table>';
299
300print $form->buttonsSaveCancel("Modify", '');
301
302print '</form>';
303
304// End of page
305llxFooter();
306$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 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.
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.
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.