dolibarr 18.0.6
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 (empty($conf->global->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 = ''; $classname = ''; $filefound = 0;
104 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
105 foreach ($dirmodels as $reldir) {
106 $file = dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php", 0);
107 if (file_exists($file)) {
108 $filefound = 1;
109 $classname = "pdf_".$modele;
110 break;
111 }
112 }
113
114 if ($filefound) {
115 require_once $file;
116
117 $module = new $classname($db);
118
119 if ($module->write_file($exp, $langs) > 0) {
120 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
121 return;
122 } else {
123 setEventMessages($module->error, $module->errors, 'errors');
124 dol_syslog($module->error, LOG_ERR);
125 }
126 } else {
127 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
128 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
129 }
130} elseif ($action == 'set') {
131 // Activate a model
132 $ret = addDocumentModel($value, $type, $label, $scandir);
133} elseif ($action == 'del') {
134 $ret = delDocumentModel($value, $type);
135 if ($ret > 0) {
136 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == "$value") {
137 dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF', $conf->entity);
138 }
139 }
140} elseif ($action == 'setdoc') {
141 // Set default model
142 if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
143 // La constante qui a ete lue en avant du nouveau set
144 // on passe donc par une variable pour avoir un affichage coherent
145 $conf->global->EXPEDITION_ADDON_PDF = $value;
146 }
147
148 // On active le modele
149 $ret = delDocumentModel($value, $type);
150 if ($ret > 0) {
151 $ret = addDocumentModel($value, $type, $label, $scandir);
152 }
153} elseif ($action == 'setmodel') {
154 dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
155}
156
157
158/*
159 * View
160 */
161
162$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
163
164$form = new Form($db);
165
166llxHeader("", $langs->trans("SendingsSetup"));
167
168$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
169print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
170print '<br>';
172
173print dol_get_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'shipment');
174
175// Shipment numbering model
176
177print load_fiche_titre($langs->trans("SendingsNumberingModules"), '', '');
178
179print '<table class="noborder centpercent">';
180print '<tr class="liste_titre">';
181print '<td width="100">'.$langs->trans("Name").'</td>';
182print '<td>'.$langs->trans("Description").'</td>';
183print '<td>'.$langs->trans("Example").'</td>';
184print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
185print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
186print "</tr>\n";
187
188clearstatcache();
189
190foreach ($dirmodels as $reldir) {
191 $dir = dol_buildpath($reldir."core/modules/expedition/");
192
193 if (is_dir($dir)) {
194 $handle = opendir($dir);
195 if (is_resource($handle)) {
196 while (($file = readdir($handle)) !== false) {
197 if (preg_match('/^mod_expedition_([a-z0-9_]*)\.php$/', $file)) {
198 $file = substr($file, 0, dol_strlen($file) - 4);
199
200 require_once $dir.$file.'.php';
201
202 $module = new $file;
203
204 if ($module->isEnabled()) {
205 // Show modules according to features level
206 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
207 continue;
208 }
209 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
210 continue;
211 }
212
213 print '<tr><td>'.$module->name."</td>\n";
214 print '<td>';
215 print $module->info();
216 print '</td>';
217
218 // Show example of numbering module
219 print '<td class="nowrap">';
220 $tmp = $module->getExample();
221 if (preg_match('/^Error/', $tmp)) {
222 $langs->load("errors");
223 print '<div class="error">'.$langs->trans($tmp).'</div>';
224 } elseif ($tmp == 'NotConfigured') {
225 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
226 } else {
227 print $tmp;
228 }
229 print '</td>'."\n";
230
231 print '<td class="center">';
232 if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file") {
233 print img_picto($langs->trans("Activated"), 'switch_on');
234 } else {
235 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).'&label='.urlencode($module->name).'">';
236 print img_picto($langs->trans("Disabled"), 'switch_off');
237 print '</a>';
238 }
239 print '</td>';
240
241 $expedition = new Expedition($db);
242 $expedition->initAsSpecimen();
243
244 // Info
245 $htmltooltip = '';
246 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
247 $nextval = $module->getNextValue($mysoc, $expedition);
248 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
249 $htmltooltip .= ''.$langs->trans("NextValue").': ';
250 if ($nextval) {
251 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
252 $nextval = $langs->trans($nextval);
253 }
254 $htmltooltip .= $nextval.'<br>';
255 } else {
256 $htmltooltip .= $langs->trans($module->error).'<br>';
257 }
258 }
259
260 print '<td class="center">';
261 print $form->textwithpicto('', $htmltooltip, 1, 0);
262 print '</td>';
263
264 print '</tr>';
265 }
266 }
267 }
268 closedir($handle);
269 }
270 }
271}
272
273print '</table><br>';
274
275
276/*
277 * Documents models for Sendings Receipt
278 */
279print load_fiche_titre($langs->trans("SendingsReceiptModel"), '', '');
280
281// Defini tableau def de modele invoice
282$type = "shipping";
283$def = array();
284
285$sql = "SELECT nom";
286$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
287$sql .= " WHERE type = '".$db->escape($type)."'";
288$sql .= " AND entity = ".$conf->entity;
289
290$resql = $db->query($sql);
291if ($resql) {
292 $i = 0;
293 $num_rows = $db->num_rows($resql);
294 while ($i < $num_rows) {
295 $array = $db->fetch_array($resql);
296 array_push($def, $array[0]);
297 $i++;
298 }
299} else {
300 dol_print_error($db);
301}
302
303print '<table class="noborder centpercent">';
304print '<tr class="liste_titre">';
305print '<td width="140">'.$langs->trans("Name").'</td>';
306print '<td>'.$langs->trans("Description").'</td>';
307print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
308print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
309print '<td class="nowrap center" width="80">'.$langs->trans("ShortInfo").'</td>';
310print '<td class="nowrap center" width="80" >'.$langs->trans("Preview").'</td>';
311print "</tr>\n";
312
313clearstatcache();
314
315foreach ($dirmodels as $reldir) {
316 foreach (array('', '/doc') as $valdir) {
317 $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
318
319 if (is_dir($dir)) {
320 $handle = opendir($dir);
321 if (is_resource($handle)) {
322 while (($file = readdir($handle)) !== false) {
323 $filelist[] = $file;
324 }
325 closedir($handle);
326 arsort($filelist);
327
328 foreach ($filelist as $file) {
329 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
330 if (file_exists($dir.'/'.$file)) {
331 $name = substr($file, 4, dol_strlen($file) - 16);
332 $classname = substr($file, 0, dol_strlen($file) - 12);
333
334 require_once $dir.'/'.$file;
335 $module = new $classname($db);
336
337 $modulequalified = 1;
338 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
339 $modulequalified = 0;
340 }
341 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
342 $modulequalified = 0;
343 }
344
345 if ($modulequalified) {
346 print '<tr><td width="100">';
347 print (empty($module->name) ? $name : $module->name);
348 print "</td><td>\n";
349 if (method_exists($module, 'info')) {
350 print $module->info($langs);
351 } else {
352 print $module->description;
353 }
354 print '</td>';
355
356 // Active
357 if (in_array($name, $def)) {
358 print '<td class="center">'."\n";
359 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
360 print img_picto($langs->trans("Enabled"), 'switch_on');
361 print '</a>';
362 print '</td>';
363 } else {
364 print '<td class="center">'."\n";
365 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>';
366 print "</td>";
367 }
368
369 // Defaut
370 print '<td class="center">';
371 if (getDolGlobalString('EXPEDITION_ADDON_PDF') == $name) {
372 print img_picto($langs->trans("Default"), 'on');
373 } else {
374 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>';
375 }
376 print '</td>';
377
378 // Info
379 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
380 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
381 if ($module->type == 'pdf') {
382 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
383 }
384 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
385 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
386 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
387 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
388 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
389 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
390
391 print '<td class="center">';
392 print $form->textwithpicto('', $htmltooltip, 1, 0);
393 print '</td>';
394
395 // Preview
396 print '<td class="center">';
397 if ($module->type == 'pdf') {
398 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>';
399 } else {
400 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
401 }
402 print '</td>';
403
404 print "</tr>\n";
405 }
406 }
407 }
408 }
409 }
410 }
411 }
412}
413
414print '</table>';
415print '<br>';
416
417
418/*
419 * Other options
420 *
421 */
422print load_fiche_titre($langs->trans("OtherOptions"), '', '');
423
424print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
425print '<input type="hidden" name="token" value="'.newToken().'">';
426print '<input type="hidden" name="action" value="set_param">';
427
428print "<table class=\"noborder\" width=\"100%\">";
429print "<tr class=\"liste_titre\">";
430print "<td>".$langs->trans("Parameter")."</td>\n";
431print "</tr>";
432
433$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
434$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
435$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
436foreach ($substitutionarray as $key => $val) {
437 $htmltext .= $key.'<br>';
438}
439$htmltext .= '</i>';
440
441print '<tr><td>';
442print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
443$variablename = 'SHIPPING_FREE_TEXT';
444if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
445 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
446} else {
447 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
448 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
449 print $doleditor->Create();
450}
451print "</td></tr>\n";
452
453print '<tr><td>';
454print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
455print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
456print "</td></tr>\n";
457
458print '</table>';
459
460print $form->buttonsSaveCancel("Modify", '');
461
462print '</form>';
463
464// End of page
465llxFooter();
466$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:56
llxFooter()
Empty footer.
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.
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.
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:758
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.