dolibarr 21.0.0-beta
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
49// Load translation files required by the page
50$langs->loadLangs(array("admin", "sendings", "deliveries", "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 // La constante qui a ete lue en avant du nouveau set
157 // on passe donc par une variable pour avoir un affichage coherent
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="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
182print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
183print '<br>';
185
186print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
187
188// Shipment numbering model
189
190print load_fiche_titre($langs->trans("SendingsNumberingModules"), '', '');
191
192print '<table class="noborder centpercent">';
193print '<tr class="liste_titre">';
194print '<td width="100">'.$langs->trans("Name").'</td>';
195print '<td>'.$langs->trans("Description").'</td>';
196print '<td>'.$langs->trans("Example").'</td>';
197print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
198print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
199print "</tr>\n";
200
201clearstatcache();
202
203foreach ($dirmodels as $reldir) {
204 $dir = dol_buildpath($reldir."core/modules/expedition/");
205
206 if (is_dir($dir)) {
207 $handle = opendir($dir);
208 if (is_resource($handle)) {
209 while (($file = readdir($handle)) !== false) {
210 if (preg_match('/^mod_expedition_([a-z0-9_]*)\.php$/', $file)) {
211 $file = substr($file, 0, dol_strlen($file) - 4);
212
213 require_once $dir.$file.'.php';
214
215 $module = new $file();
216 '@phan-var-force ModelNumRefExpedition $module';
217
218 if ($module->isEnabled()) {
219 // Show modules according to features level
220 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
221 continue;
222 }
223 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
224 continue;
225 }
226
227 print '<tr><td>'.$module->name."</td>\n";
228 print '<td>';
229 print $module->info($langs);
230 print '</td>';
231
232 // Show example of numbering module
233 print '<td class="nowrap">';
234 $tmp = $module->getExample();
235 if (preg_match('/^Error/', $tmp)) {
236 $langs->load("errors");
237 print '<div class="error">'.$langs->trans($tmp).'</div>';
238 } elseif ($tmp == 'NotConfigured') {
239 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
240 } else {
241 print $tmp;
242 }
243 print '</td>'."\n";
244
245 print '<td class="center">';
246 if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file") {
247 print img_picto($langs->trans("Activated"), 'switch_on');
248 } else {
249 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).'&label='.urlencode($module->name).'">';
250 print img_picto($langs->trans("Disabled"), 'switch_off');
251 print '</a>';
252 }
253 print '</td>';
254
255 $expedition = new Expedition($db);
256 $expedition->initAsSpecimen();
257
258 // Info
259 $htmltooltip = '';
260 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
261 $nextval = $module->getNextValue($mysoc, $expedition);
262 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
263 $htmltooltip .= ''.$langs->trans("NextValue").': ';
264 if ($nextval) {
265 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
266 $nextval = $langs->trans($nextval);
267 }
268 $htmltooltip .= $nextval.'<br>';
269 } else {
270 $htmltooltip .= $langs->trans($module->error).'<br>';
271 }
272 }
273
274 print '<td class="center">';
275 print $form->textwithpicto('', $htmltooltip, 1, 0);
276 print '</td>';
277
278 print '</tr>';
279 }
280 }
281 }
282 closedir($handle);
283 }
284 }
285}
286
287print '</table><br>';
288
289
290/*
291 * Documents models for Sendings Receipt
292 */
293print load_fiche_titre($langs->trans("SendingsReceiptModel"), '', '');
294
295// Defini tableau def de modele invoice
296$type = "shipping";
297$def = array();
298
299$sql = "SELECT nom";
300$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
301$sql .= " WHERE type = '".$db->escape($type)."'";
302$sql .= " AND entity = ".$conf->entity;
303
304$resql = $db->query($sql);
305if ($resql) {
306 $i = 0;
307 $num_rows = $db->num_rows($resql);
308 while ($i < $num_rows) {
309 $array = $db->fetch_array($resql);
310 if (is_array($array)) {
311 array_push($def, $array[0]);
312 }
313 $i++;
314 }
315} else {
316 dol_print_error($db);
317}
318
319print '<table class="noborder centpercent">';
320print '<tr class="liste_titre">';
321print '<td width="140">'.$langs->trans("Name").'</td>';
322print '<td>'.$langs->trans("Description").'</td>';
323print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
324print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
325print '<td class="nowrap center" width="80">'.$langs->trans("ShortInfo").'</td>';
326print '<td class="nowrap center" width="80" >'.$langs->trans("Preview").'</td>';
327print "</tr>\n";
328
329clearstatcache();
330
331foreach ($dirmodels as $reldir) {
332 foreach (array('', '/doc') as $valdir) {
333 $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
334
335 if (is_dir($dir)) {
336 $handle = opendir($dir);
337 if (is_resource($handle)) {
338 $filelist = array();
339 while (($file = readdir($handle)) !== false) {
340 $filelist[] = $file;
341 }
342 closedir($handle);
343 arsort($filelist);
344
345 foreach ($filelist as $file) {
346 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
347 if (file_exists($dir.'/'.$file)) {
348 $name = substr($file, 4, dol_strlen($file) - 16);
349 $classname = substr($file, 0, dol_strlen($file) - 12);
350
351 require_once $dir.'/'.$file;
352 $module = new $classname($db);
353
354 '@phan-var-force ModelePdfExpedition $module';
355
356 $modulequalified = 1;
357 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
358 $modulequalified = 0;
359 }
360 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
361 $modulequalified = 0;
362 }
363
364 if ($modulequalified) {
365 print '<tr><td width="100">';
366 print(empty($module->name) ? $name : $module->name);
367 print "</td><td>\n";
368 if (method_exists($module, 'info')) {
369 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
370 } else {
371 print $module->description;
372 }
373 print '</td>';
374
375 // Active
376 if (in_array($name, $def)) {
377 print '<td class="center">'."\n";
378 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
379 print img_picto($langs->trans("Enabled"), 'switch_on');
380 print '</a>';
381 print '</td>';
382 } else {
383 print '<td class="center">'."\n";
384 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>';
385 print "</td>";
386 }
387
388 // Default
389 print '<td class="center">';
390 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == $name) {
391 print img_picto($langs->trans("Default"), 'on');
392 } else {
393 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>';
394 }
395 print '</td>';
396
397 // Info
398 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
399 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
400 if ($module->type == 'pdf') {
401 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
402 }
403 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
404 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
405 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
406 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
407 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
408 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
409
410 print '<td class="center">';
411 print $form->textwithpicto('', $htmltooltip, 1, 0);
412 print '</td>';
413
414 // Preview
415 print '<td class="center">';
416 if ($module->type == 'pdf') {
417 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>';
418 } else {
419 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
420 }
421 print '</td>';
422
423 print "</tr>\n";
424 }
425 }
426 }
427 }
428 }
429 }
430 }
431}
432
433print '</table>';
434
435
436/*
437 * Other options
438 */
439
440print load_fiche_titre($langs->trans("OtherOptions"), '', '');
441
442print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
443print '<input type="hidden" name="token" value="'.newToken().'">';
444print '<input type="hidden" name="action" value="set_param">';
445
446print '<table class="noborder centpercent">';
447print '<tr class="liste_titre">';
448print "<td>".$langs->trans("Parameter")."</td>\n";
449print "<td></td>\n";
450print '</tr>';
451
452print '<tr class="oddeven">';
453print '<td>'.$langs->trans('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
454print '</td>';
455print '<td>';
456print ajax_constantonoff('SHIPPING_DISPLAY_STOCK_ENTRY_DATE');
457print '</td></tr>';
458
459$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
460$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
461$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
462foreach ($substitutionarray as $key => $val) {
463 $htmltext .= $key.'<br>';
464}
465$htmltext .= '</i>';
466
467print '<tr><td colspan="2">';
468print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
469$variablename = 'SHIPPING_FREE_TEXT';
470if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
471 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
472} else {
473 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
474 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
475 print $doleditor->Create();
476}
477print "</td></tr>\n";
478
479print '<tr><td>';
480print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip');
481print '</td><td>';
482print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
483print "</td></tr>\n";
484
485// Allow OnLine Sign
486print '<tr class="oddeven">';
487print '<td>'.$langs->trans("AllowOnLineSign");
488print '</td>';
489print '<td>';
490print ajax_constantonoff('EXPEDITION_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->trans("WarningOnlineSignature"));
491print '</td></tr>';
492
493print '</table>';
494
495print $form->buttonsSaveCancel("Modify", '');
496
497print '</form>';
498
499// End of page
500llxFooter();
501$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:71
Class to manage a WYSIWYG editor.
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:765
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.