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