dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 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
40// Load translation files required by the page
41$langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
42
43if (!$user->admin) {
45}
46
47$action = GETPOST('action', 'aZ09');
48$value = GETPOST('value', 'alpha');
49$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
50
51$label = GETPOST('label', 'alpha');
52$scandir = GETPOST('scan_dir', 'alpha');
53$type = 'shipping';
54
55if (!getDolGlobalString('EXPEDITION_ADDON_NUMBER')) {
56 $conf->global->EXPEDITION_ADDON_NUMBER = 'mod_expedition_safor';
57}
58
59
60/*
61 * Actions
62 */
63
64include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
65
66if ($action == 'updateMask') {
67 $maskconst = GETPOST('maskconstexpedition', 'aZ09');
68 $maskvalue = GETPOST('maskexpedition', 'alpha');
69 if (!empty($maskconst) && preg_match('/_MASK$/', $maskconst)) {
70 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
71 }
72
73 if (isset($res)) {
74 if ($res > 0) {
75 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
76 } else {
77 setEventMessages($langs->trans("Error"), null, 'errors');
78 }
79 }
80} elseif ($action == 'set_param') {
81 $freetext = GETPOST('SHIPPING_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
82 $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
83 if ($res <= 0) {
84 $error++;
85 setEventMessages($langs->trans("Error"), null, 'errors');
86 }
87
88 $draft = GETPOST('SHIPPING_DRAFT_WATERMARK', 'alpha');
89 $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
90 if ($res <= 0) {
91 $error++;
92 setEventMessages($langs->trans("Error"), null, 'errors');
93 }
94
95 if (!$error) {
96 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
97 }
98} elseif ($action == 'specimen') {
99 $modele = GETPOST('module', 'alpha');
100
101 $exp = new Expedition($db);
102 $exp->initAsSpecimen();
103
104 // Search template files
105 $file = '';
106 $classname = '';
107 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
108 foreach ($dirmodels as $reldir) {
109 $file = dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php", 0);
110 if (file_exists($file)) {
111 $classname = "pdf_".$modele;
112 break;
113 }
114 }
115
116 if ($classname !== '') {
117 require_once $file;
118
119 $module = new $classname($db);
120 '@phan-var-force ModelePdfExpedition $module';
121
122 if ($module->write_file($exp, $langs) > 0) {
123 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
124 return;
125 } else {
126 setEventMessages($module->error, $module->errors, 'errors');
127 dol_syslog($module->error, LOG_ERR);
128 }
129 } else {
130 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
131 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
132 }
133} elseif ($action == 'set') {
134 // Activate a model
135 $ret = addDocumentModel($value, $type, $label, $scandir);
136} elseif ($action == 'del') {
137 $ret = delDocumentModel($value, $type);
138 if ($ret > 0) {
139 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == "$value") {
140 dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF', $conf->entity);
141 }
142 }
143} elseif ($action == 'setdoc') {
144 // Set default model
145 if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
146 // La constante qui a ete lue en avant du nouveau set
147 // on passe donc par une variable pour avoir un affichage coherent
148 $conf->global->EXPEDITION_ADDON_PDF = $value;
149 }
150
151 // On active le modele
152 $ret = delDocumentModel($value, $type);
153 if ($ret > 0) {
154 $ret = addDocumentModel($value, $type, $label, $scandir);
155 }
156} elseif ($action == 'setmodel') {
157 dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
158}
159
160
161/*
162 * View
163 */
164
165$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
166
167$form = new Form($db);
168
169llxHeader("", $langs->trans("SendingsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expedition');
170
171$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
172print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
173print '<br>';
175
176print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
177
178// Shipment numbering model
179
180print load_fiche_titre($langs->trans("SendingsNumberingModules"), '', '');
181
182print '<table class="noborder centpercent">';
183print '<tr class="liste_titre">';
184print '<td width="100">'.$langs->trans("Name").'</td>';
185print '<td>'.$langs->trans("Description").'</td>';
186print '<td>'.$langs->trans("Example").'</td>';
187print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
188print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
189print "</tr>\n";
190
191clearstatcache();
192
193foreach ($dirmodels as $reldir) {
194 $dir = dol_buildpath($reldir."core/modules/expedition/");
195
196 if (is_dir($dir)) {
197 $handle = opendir($dir);
198 if (is_resource($handle)) {
199 while (($file = readdir($handle)) !== false) {
200 if (preg_match('/^mod_expedition_([a-z0-9_]*)\.php$/', $file)) {
201 $file = substr($file, 0, dol_strlen($file) - 4);
202
203 require_once $dir.$file.'.php';
204
205 $module = new $file();
206
207 if ($module->isEnabled()) {
208 // Show modules according to features level
209 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
210 continue;
211 }
212 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
213 continue;
214 }
215
216 print '<tr><td>'.$module->name."</td>\n";
217 print '<td>';
218 print $module->info($langs);
219 print '</td>';
220
221 // Show example of numbering module
222 print '<td class="nowrap">';
223 $tmp = $module->getExample();
224 if (preg_match('/^Error/', $tmp)) {
225 $langs->load("errors");
226 print '<div class="error">'.$langs->trans($tmp).'</div>';
227 } elseif ($tmp == 'NotConfigured') {
228 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
229 } else {
230 print $tmp;
231 }
232 print '</td>'."\n";
233
234 print '<td class="center">';
235 if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file") {
236 print img_picto($langs->trans("Activated"), 'switch_on');
237 } else {
238 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).'&label='.urlencode($module->name).'">';
239 print img_picto($langs->trans("Disabled"), 'switch_off');
240 print '</a>';
241 }
242 print '</td>';
243
244 $expedition = new Expedition($db);
245 $expedition->initAsSpecimen();
246
247 // Info
248 $htmltooltip = '';
249 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
250 $nextval = $module->getNextValue($mysoc, $expedition);
251 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
252 $htmltooltip .= ''.$langs->trans("NextValue").': ';
253 if ($nextval) {
254 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
255 $nextval = $langs->trans($nextval);
256 }
257 $htmltooltip .= $nextval.'<br>';
258 } else {
259 $htmltooltip .= $langs->trans($module->error).'<br>';
260 }
261 }
262
263 print '<td class="center">';
264 print $form->textwithpicto('', $htmltooltip, 1, 0);
265 print '</td>';
266
267 print '</tr>';
268 }
269 }
270 }
271 closedir($handle);
272 }
273 }
274}
275
276print '</table><br>';
277
278
279/*
280 * Documents models for Sendings Receipt
281 */
282print load_fiche_titre($langs->trans("SendingsReceiptModel"), '', '');
283
284// Defini tableau def de modele invoice
285$type = "shipping";
286$def = array();
287
288$sql = "SELECT nom";
289$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
290$sql .= " WHERE type = '".$db->escape($type)."'";
291$sql .= " AND entity = ".$conf->entity;
292
293$resql = $db->query($sql);
294if ($resql) {
295 $i = 0;
296 $num_rows = $db->num_rows($resql);
297 while ($i < $num_rows) {
298 $array = $db->fetch_array($resql);
299 if (is_array($array)) {
300 array_push($def, $array[0]);
301 }
302 $i++;
303 }
304} else {
305 dol_print_error($db);
306}
307
308print '<table class="noborder centpercent">';
309print '<tr class="liste_titre">';
310print '<td width="140">'.$langs->trans("Name").'</td>';
311print '<td>'.$langs->trans("Description").'</td>';
312print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
313print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
314print '<td class="nowrap center" width="80">'.$langs->trans("ShortInfo").'</td>';
315print '<td class="nowrap center" width="80" >'.$langs->trans("Preview").'</td>';
316print "</tr>\n";
317
318clearstatcache();
319
320foreach ($dirmodels as $reldir) {
321 foreach (array('', '/doc') as $valdir) {
322 $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
323
324 if (is_dir($dir)) {
325 $handle = opendir($dir);
326 if (is_resource($handle)) {
327 $filelist = array();
328 while (($file = readdir($handle)) !== false) {
329 $filelist[] = $file;
330 }
331 closedir($handle);
332 arsort($filelist);
333
334 foreach ($filelist as $file) {
335 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
336 if (file_exists($dir.'/'.$file)) {
337 $name = substr($file, 4, dol_strlen($file) - 16);
338 $classname = substr($file, 0, dol_strlen($file) - 12);
339
340 require_once $dir.'/'.$file;
341 $module = new $classname($db);
342
343 $modulequalified = 1;
344 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
345 $modulequalified = 0;
346 }
347 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
348 $modulequalified = 0;
349 }
350
351 if ($modulequalified) {
352 print '<tr><td width="100">';
353 print(empty($module->name) ? $name : $module->name);
354 print "</td><td>\n";
355 if (method_exists($module, 'info')) {
356 print $module->info($langs);
357 } else {
358 print $module->description;
359 }
360 print '</td>';
361
362 // Active
363 if (in_array($name, $def)) {
364 print '<td class="center">'."\n";
365 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
366 print img_picto($langs->trans("Enabled"), 'switch_on');
367 print '</a>';
368 print '</td>';
369 } else {
370 print '<td class="center">'."\n";
371 print '<a class="reposition" 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>';
372 print "</td>";
373 }
374
375 // Default
376 print '<td class="center">';
377 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == $name) {
378 print img_picto($langs->trans("Default"), 'on');
379 } else {
380 print '<a class="reposition" 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>';
381 }
382 print '</td>';
383
384 // Info
385 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
386 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
387 if ($module->type == 'pdf') {
388 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
389 }
390 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
391 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
392 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
393 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
394 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
395 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
396
397 print '<td class="center">';
398 print $form->textwithpicto('', $htmltooltip, 1, 0);
399 print '</td>';
400
401 // Preview
402 print '<td class="center">';
403 if ($module->type == 'pdf') {
404 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
405 } else {
406 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
407 }
408 print '</td>';
409
410 print "</tr>\n";
411 }
412 }
413 }
414 }
415 }
416 }
417 }
418}
419
420print '</table>';
421print load_fiche_titre($langs->trans('CreationOptions'), '', '');
422
423print '<table class="noborder centpercent">';
424print '<tr class="liste_titre">';
425print '<td width="100">'.$langs->trans('Name').'</td>';
426print '<td></td>';
427print '<td class="center" width="60">'.$langs->trans('Status').'</td>';
428
429print "</tr>\n";
430
431print '<tr class="oddeven">';
432print '<td>'.$langs->trans('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
433print '</td>';
434print '<td class="center" width="20">&nbsp;</td>';
435print '<td class="center" >';
436print ajax_constantonoff('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
437print '</td></tr>';
438
439print '</table><br>';
440print '<br>';
441
442
443/*
444 * Other options
445 *
446 */
447print load_fiche_titre($langs->trans("OtherOptions"), '', '');
448
449print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
450print '<input type="hidden" name="token" value="'.newToken().'">';
451print '<input type="hidden" name="action" value="set_param">';
452
453print "<table class=\"noborder\" width=\"100%\">";
454print "<tr class=\"liste_titre\">";
455print "<td>".$langs->trans("Parameter")."</td>\n";
456print "</tr>";
457
458$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
459$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
460$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
461foreach ($substitutionarray as $key => $val) {
462 $htmltext .= $key.'<br>';
463}
464$htmltext .= '</i>';
465
466print '<tr><td>';
467print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
468$variablename = 'SHIPPING_FREE_TEXT';
469if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
470 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
471} else {
472 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
473 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
474 print $doleditor->Create();
475}
476print "</td></tr>\n";
477
478print '<tr><td>';
479print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
480print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
481print "</td></tr>\n";
482
483// Allow OnLine Sign
484print '<tr class="oddeven">';
485print '<td>'.$langs->trans("AllowOnLineSign").'</td>';
486print '<td class="center">';
487print ajax_constantonoff('EXPEDITION_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1);
488print '</td></tr>';
489
490print '</table>';
491
492print $form->buttonsSaveCancel("Modify", '');
493
494print '</form>';
495
496// End of page
497llxFooter();
498$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage a WYSIWYG editor.
Class to manage shipments.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
expedition_admin_prepare_head()
Return array head with list of tabs to view object information.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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:769
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.