dolibarr  16.0.5
delivery.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 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-2014 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
10  * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
39 
40 if (!$user->admin) {
42 }
43 
44 $action = GETPOST('action', 'alpha');
45 $value = GETPOST('value', 'alpha');
46 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
47 
48 $label = GETPOST('label', 'alpha');
49 $scandir = GETPOST('scan_dir', 'alpha');
50 $type = 'delivery';
51 
52 
53 /*
54  * Actions
55  */
56 
57 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
58 
59 if ($action == 'updateMask') {
60  $maskconstdelivery = GETPOST('maskconstdelivery', 'alpha');
61  $maskdelivery = GETPOST('maskdelivery', 'alpha');
62  if ($maskconstdelivery) {
63  $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity);
64  }
65 
66  if (!($res > 0)) {
67  $error++;
68  }
69 
70  if (!$error) {
71  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
72  } else {
73  setEventMessages($langs->trans("Error"), null, 'errors');
74  }
75 }
76 
77 if ($action == 'set_DELIVERY_FREE_TEXT') {
78  $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
79  $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity);
80 
81  if (!($res > 0)) {
82  $error++;
83  }
84 
85  if (!$error) {
86  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87  } else {
88  setEventMessages($langs->trans("Error"), null, 'errors');
89  }
90 }
91 
92 if ($action == 'specimen') {
93  $modele = GETPOST('module', 'alpha');
94 
95  $sending = new Delivery($db);
96  $sending->initAsSpecimen();
97 
98  // Search template files
99  $file = ''; $classname = ''; $filefound = 0;
100  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
101  foreach ($dirmodels as $reldir) {
102  $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0);
103  if (file_exists($file)) {
104  $filefound = 1;
105  $classname = "pdf_".$modele;
106  break;
107  }
108  }
109 
110  if ($filefound) {
111  require_once $file;
112 
113  $module = new $classname($db);
114 
115  if ($module->write_file($sending, $langs) > 0) {
116  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf");
117  return;
118  } else {
119  setEventMessages($module->error, $module->errors, 'errors');
120  dol_syslog($module->error, LOG_ERR);
121  }
122  } else {
123  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
124  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
125  }
126 }
127 
128 if ($action == 'set') {
129  $ret = addDocumentModel($value, $type, $label, $scandir);
130 }
131 
132 if ($action == 'del') {
133  $ret = delDocumentModel($value, $type);
134  if ($ret > 0) {
135  if ($conf->global->DELIVERY_ADDON_PDF == "$value") {
136  dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity);
137  }
138  }
139 }
140 
141 if ($action == 'setdoc') {
142  if (dolibarr_set_const($db, "DELIVERY_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->DELIVERY_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 }
154 
155 if ($action == 'setmod') {
156  // TODO Verifier si module numerotation choisi peut etre active
157  // par appel methode canBeActivated
158 
159  dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
160 }
161 
162 
163 /*
164  * View
165  */
166 
167 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
168 
169 llxHeader("", "");
170 
171 $form = new Form($db);
172 
173 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
174 print load_fiche_titre($langs->trans("SendingsSetup"), $linkback, 'title_setup');
175 print '<br>';
177 
178 print dol_get_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'shipment');
179 
180 
181 // Delivery numbering model
182 
183 print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"), '', '');
184 
185 print '<table class="noborder centpercent">';
186 print '<tr class="liste_titre">';
187 print '<td width="100">'.$langs->trans("Name").'</td>';
188 print '<td>'.$langs->trans("Description").'</td>';
189 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
190 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
191 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
192 print '</tr>'."\n";
193 
194 clearstatcache();
195 
196 foreach ($dirmodels as $reldir) {
197  $dir = dol_buildpath($reldir."core/modules/delivery/");
198 
199  if (is_dir($dir)) {
200  $handle = opendir($dir);
201  if (is_resource($handle)) {
202  while (($file = readdir($handle)) !== false) {
203  if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) {
204  $file = substr($file, 0, dol_strlen($file) - 4);
205 
206  require_once $dir.$file.'.php';
207 
208  $module = new $file;
209 
210  if ($module->isEnabled()) {
211  // Show modules according to features level
212  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
213  continue;
214  }
215  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
216  continue;
217  }
218 
219  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
220  print $module->info();
221  print '</td>';
222 
223  // Show example of numbering module
224  print '<td class="nowrap">';
225  $tmp = $module->getExample();
226  if (preg_match('/^Error/', $tmp)) {
227  $langs->load("errors");
228  print '<div class="error">'.$langs->trans($tmp).'</div>';
229  } elseif ($tmp == 'NotConfigured') {
230  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
231  } else {
232  print $tmp;
233  }
234  print '</td>'."\n";
235 
236  print '<td class="center">';
237  if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") {
238  print img_picto($langs->trans("Activated"), 'switch_on');
239  } else {
240  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
241  }
242  print '</td>';
243 
244  $delivery = new Delivery($db);
245  $delivery->initAsSpecimen();
246 
247  // Info
248  $htmltooltip = '';
249  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
250  $nextval = $module->getNextValue($mysoc, $delivery);
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 
276 print '</table>';
277 
278 
279 /*
280  * Documents Models for delivery
281  */
282 print '<br>';
283 print load_fiche_titre($langs->trans("DeliveryOrderModel"), '', '');
284 
285 // Defini tableau def de modele
286 $type = "delivery";
287 $def = array();
288 
289 $sql = "SELECT nom";
290 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
291 $sql .= " WHERE type = '".$db->escape($type)."'";
292 $sql .= " AND entity = ".$conf->entity;
293 
294 $resql = $db->query($sql);
295 if ($resql) {
296  $i = 0;
297  $num_rows = $db->num_rows($resql);
298  while ($i < $num_rows) {
299  $array = $db->fetch_array($resql);
300  array_push($def, $array[0]);
301  $i++;
302  }
303 } else {
304  dol_print_error($db);
305 }
306 
307 print '<table class="noborder centpercent">';
308 print '<tr class="liste_titre">';
309 print '<td width="140">'.$langs->trans("Name").'</td>';
310 print '<td>'.$langs->trans("Description").'</td>';
311 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
312 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
313 print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
314 print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
315 print "</tr>\n";
316 
317 clearstatcache();
318 
319 foreach ($dirmodels as $reldir) {
320  $dir = dol_buildpath($reldir."core/modules/delivery/doc/");
321 
322  if (is_dir($dir)) {
323  $handle = opendir($dir);
324  if (is_resource($handle)) {
325  while (($file = readdir($handle)) !== false) {
326  $filelist[] = $file;
327  }
328  closedir($handle);
329  arsort($filelist);
330 
331  foreach ($filelist as $file) {
332  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
333  if (file_exists($dir.'/'.$file)) {
334  $name = substr($file, 4, dol_strlen($file) - 16);
335  $classname = substr($file, 0, dol_strlen($file) - 12);
336 
337  require_once $dir.'/'.$file;
338  $module = new $classname($db);
339 
340  $modulequalified = 1;
341  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
342  $modulequalified = 0;
343  }
344  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
345  $modulequalified = 0;
346  }
347 
348  if ($modulequalified) {
349  print '<tr class="oddeven"><td width="100">';
350  print (empty($module->name) ? $name : $module->name);
351  print "</td><td>\n";
352  if (method_exists($module, 'info')) {
353  print $module->info($langs);
354  } else {
355  print $module->description;
356  }
357  print '</td>';
358 
359  // Active
360  if (in_array($name, $def)) {
361  print "<td align=\"center\">\n";
362  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
363  print img_picto($langs->trans("Enabled"), 'switch_on');
364  print '</a>';
365  print "</td>";
366  } else {
367  print "<td align=\"center\">\n";
368  print '<a 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>';
369  print "</td>";
370  }
371 
372  // Default
373  print "<td align=\"center\">";
374  if ($conf->global->DELIVERY_ADDON_PDF == "$name") {
375  print img_picto($langs->trans("Default"), 'on');
376  } else {
377  print '<a 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>';
378  }
379  print '</td>';
380 
381  // Info
382  $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
383  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
384  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
385  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
386  print '<td class="center">';
387  print $form->textwithpicto('', $htmltooltip, 1, 0);
388  print '</td>';
389 
390  // Preview
391  print '<td class="center">';
392  if ($module->type == 'pdf') {
393  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
394  } else {
395  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
396  }
397  print '</td>';
398 
399  print '</tr>';
400  }
401  }
402  }
403  }
404  }
405  }
406 }
407 
408 print '</table>';
409 /*
410  * Autres Options
411  */
412 print "<br>";
413 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
414 
415 print '<table class="noborder centpercent">';
416 print '<tr class="liste_titre">';
417 print '<td>'.$langs->trans("Parameter").'</td>';
418 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
419 print '<td width="80">&nbsp;</td>';
420 print "</tr>\n";
421 
422 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
423 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
424 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
425 foreach ($substitutionarray as $key => $val) {
426  $htmltext .= $key.'<br>';
427 }
428 $htmltext .= '</i>';
429 
430 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
431 print '<input type="hidden" name="token" value="'.newToken().'">';
432 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
433 print '<tr class="oddeven"><td colspan="2">';
434 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
435 $variablename = 'DELIVERY_FREE_TEXT';
436 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
437  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
438 } else {
439  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
440  $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
441  print $doleditor->Create();
442 }
443 print '</td><td class="right">';
444 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
445 print "</td></tr>\n";
446 print '</form>';
447 
448 print '</table>';
449 
450 // End of page
451 llxFooter();
452 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
expedition_admin_prepare_head
expedition_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: expedition.lib.php:74
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dolibarr_set_const
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).
Definition: admin.lib.php:627
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Delivery
Class to manage receptions.
Definition: delivery.class.php:45
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:737
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30