dolibarr  9.0.0
livraison.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 <http://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.'/livraison/class/livraison.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("admin", "sendings", "deliveries", "other"));
39 
40 if (!$user->admin) accessforbidden();
41 
42 $action = GETPOST('action','alpha');
43 $value = GETPOST('value','alpha');
44 $label = GETPOST('label','alpha');
45 $scandir = GETPOST('scan_dir','alpha');
46 $type='delivery';
47 
48 
49 /*
50  * Actions
51  */
52 
53 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
54 
55 if ($action == 'updateMask')
56 {
57  $maskconstdelivery=GETPOST('maskconstdelivery','alpha');
58  $maskdelivery=GETPOST('maskdelivery','alpha');
59  if ($maskconstdelivery) $res = dolibarr_set_const($db,$maskconstdelivery,$maskdelivery,'chaine',0,'',$conf->entity);
60 
61  if (! $res > 0) $error++;
62 
63  if (! $error)
64  {
65  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
66  }
67  else
68  {
69  setEventMessages($langs->trans("Error"), null, 'errors');
70  }
71 }
72 
73 if ($action == 'set_DELIVERY_FREE_TEXT')
74 {
75  $free=GETPOST('DELIVERY_FREE_TEXT','none'); // No alpha here, we want exact string
76  $res=dolibarr_set_const($db, "DELIVERY_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
77 
78  if (! $res > 0) $error++;
79 
80  if (! $error)
81  {
82  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
83  }
84  else
85  {
86  setEventMessages($langs->trans("Error"), null, 'errors');
87  }
88 }
89 
90 if ($action == 'specimen')
91 {
92  $modele=GETPOST('module','alpha');
93 
94  $sending = new Livraison($db);
95  $sending->initAsSpecimen();
96 
97  // Search template files
98  $file=''; $classname=''; $filefound=0;
99  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
100  foreach($dirmodels as $reldir)
101  {
102  $file=dol_buildpath($reldir."core/modules/livraison/doc/pdf_".$modele.".modules.php",0);
103  if (file_exists($file))
104  {
105  $filefound=1;
106  $classname = "pdf_".$modele;
107  break;
108  }
109  }
110 
111  if ($filefound)
112  {
113  require_once $file;
114 
115  $module = new $classname($db);
116 
117  if ($module->write_file($sending,$langs) > 0)
118  {
119  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf");
120  return;
121  }
122  else
123  {
124  setEventMessages($module->error, $module->errors, 'errors');
125  dol_syslog($module->error, LOG_ERR);
126  }
127  }
128  else
129  {
130  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
131  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
132  }
133 }
134 
135 if ($action == 'set')
136 {
137  $ret = addDocumentModel($value, $type, $label, $scandir);
138 }
139 
140 if ($action == 'del')
141 {
142  $ret = delDocumentModel($value, $type);
143  if ($ret > 0)
144  {
145  if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF',$conf->entity);
146  }
147 }
148 
149 if ($action == 'setdoc')
150 {
151  if (dolibarr_set_const($db, "LIVRAISON_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
152  {
153  // La constante qui a ete lue en avant du nouveau set
154  // on passe donc par une variable pour avoir un affichage coherent
155  $conf->global->LIVRAISON_ADDON_PDF = $value;
156  }
157 
158  // On active le modele
159  $ret = delDocumentModel($value, $type);
160  if ($ret > 0)
161  {
162  $ret = addDocumentModel($value, $type, $label, $scandir);
163  }
164 }
165 
166 if ($action == 'setmod')
167 {
168  // TODO Verifier si module numerotation choisi peut etre active
169  // par appel methode canBeActivated
170 
171  dolibarr_set_const($db, "LIVRAISON_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
172 }
173 
174 
175 /*
176  * View
177  */
178 
179 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
180 
181 llxHeader("","");
182 
183 $form=new Form($db);
184 
185 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
186 print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
187 print '<br>';
189 
190 dol_fiche_head($head, 'receivings', $langs->trans("Receivings"), -1, 'sending');
191 
192 
193 // Delivery numbering model
194 
195 print load_fiche_titre($langs->trans("DeliveryOrderNumberingModules"),'','');
196 
197 print '<table class="noborder" width="100%">';
198 print '<tr class="liste_titre">';
199 print '<td width="100">'.$langs->trans("Name").'</td>';
200 print '<td>'.$langs->trans("Description").'</td>';
201 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
202 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
203 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
204 print '</tr>'."\n";
205 
206 clearstatcache();
207 
208 foreach ($dirmodels as $reldir)
209 {
210  $dir = dol_buildpath($reldir."core/modules/livraison/");
211 
212  if (is_dir($dir))
213  {
214  $handle = opendir($dir);
215  if (is_resource($handle))
216  {
217  while (($file = readdir($handle))!==false)
218  {
219  if (substr($file, 0, 14) == 'mod_livraison_' && substr($file, dol_strlen($file)-3, 3) == 'php')
220  {
221  $file = substr($file, 0, dol_strlen($file)-4);
222 
223  require_once $dir.$file.'.php';
224 
225  $module = new $file;
226 
227  if ($module->isEnabled())
228  {
229  // Show modules according to features level
230  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
231  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
232 
233 
234  print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
235  print $module->info();
236  print '</td>';
237 
238  // Show example of numbering module
239  print '<td class="nowrap">';
240  $tmp=$module->getExample();
241  if (preg_match('/^Error/',$tmp)) {
242  $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
243  }
244  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
245  else print $tmp;
246  print '</td>'."\n";
247 
248  print '<td align="center">';
249  if ($conf->global->LIVRAISON_ADDON_NUMBER == "$file")
250  {
251  print img_picto($langs->trans("Activated"),'switch_on');
252  }
253  else
254  {
255  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
256  }
257  print '</td>';
258 
259  $livraison=new Livraison($db);
260  $livraison->initAsSpecimen();
261 
262  // Info
263  $htmltooltip='';
264  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
265  $nextval=$module->getNextValue($mysoc,$livraison);
266  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
267  $htmltooltip.=''.$langs->trans("NextValue").': ';
268  if ($nextval) {
269  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
270  $nextval = $langs->trans($nextval);
271  $htmltooltip.=$nextval.'<br>';
272  } else {
273  $htmltooltip.=$langs->trans($module->error).'<br>';
274  }
275  }
276 
277  print '<td align="center">';
278  print $form->textwithpicto('',$htmltooltip,1,0);
279  print '</td>';
280 
281  print '</tr>';
282  }
283  }
284  }
285  closedir($handle);
286  }
287  }
288 }
289 
290 print '</table>';
291 
292 
293 /*
294  * Documents Models for delivery
295  */
296 print '<br>';
297 print load_fiche_titre($langs->trans("DeliveryOrderModel"),'','');
298 
299 // Defini tableau def de modele
300 $type="delivery";
301 $def = array();
302 
303 $sql = "SELECT nom";
304 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
305 $sql.= " WHERE type = '".$type."'";
306 $sql.= " AND entity = ".$conf->entity;
307 
308 $resql=$db->query($sql);
309 if ($resql)
310 {
311  $i = 0;
312  $num_rows=$db->num_rows($resql);
313  while ($i < $num_rows)
314  {
315  $array = $db->fetch_array($resql);
316  array_push($def, $array[0]);
317  $i++;
318  }
319 }
320 else
321 {
322  dol_print_error($db);
323 }
324 
325 print '<table class="noborder" width="100%">';
326 print '<tr class="liste_titre">';
327 print '<td width="140">'.$langs->trans("Name").'</td>';
328 print '<td>'.$langs->trans("Description").'</td>';
329 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
330 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
331 print '<td align="center" width="32">'.$langs->trans("ShortInfo").'</td>';
332 print '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
333 print "</tr>\n";
334 
335 clearstatcache();
336 
337 foreach ($dirmodels as $reldir)
338 {
339  $dir = dol_buildpath($reldir."core/modules/livraison/doc/");
340 
341  if (is_dir($dir))
342  {
343  $handle = opendir($dir);
344  if (is_resource($handle))
345  {
346  while (($file = readdir($handle))!==false)
347  {
348  $filelist[]=$file;
349  }
350  closedir($handle);
351  arsort($filelist);
352 
353  foreach($filelist as $file)
354  {
355  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
356  {
357  if (file_exists($dir.'/'.$file))
358  {
359 
360 
361  $name = substr($file, 4, dol_strlen($file) -16);
362  $classname = substr($file, 0, dol_strlen($file) -12);
363 
364  require_once $dir.'/'.$file;
365  $module = new $classname($db);
366 
367  $modulequalified=1;
368  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
369  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
370 
371  if ($modulequalified)
372  {
373  print '<tr class="oddeven"><td width="100">';
374  print (empty($module->name)?$name:$module->name);
375  print "</td><td>\n";
376  if (method_exists($module,'info')) print $module->info($langs);
377  else print $module->description;
378  print '</td>';
379 
380  // Active
381  if (in_array($name, $def))
382  {
383  print "<td align=\"center\">\n";
384  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
385  print img_picto($langs->trans("Enabled"),'switch_on');
386  print '</a>';
387  print "</td>";
388  }
389  else
390  {
391  print "<td align=\"center\">\n";
392  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
393  print "</td>";
394  }
395 
396  // Default
397  print "<td align=\"center\">";
398  if ($conf->global->LIVRAISON_ADDON_PDF == "$name")
399  {
400  print img_picto($langs->trans("Default"),'on');
401  }
402  else
403  {
404  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
405  }
406  print '</td>';
407 
408  // Info
409  $htmltooltip = ''.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
410  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
411  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").'</u>:';
412  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
413  print '<td align="center">';
414  print $form->textwithpicto('',$htmltooltip,1,0);
415  print '</td>';
416 
417  // Preview
418  print '<td align="center">';
419  if ($module->type == 'pdf')
420  {
421  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'sending').'</a>';
422  }
423  else
424  {
425  print img_object($langs->trans("PreviewNotAvailable"),'generic');
426  }
427  print '</td>';
428 
429  print '</tr>';
430  }
431  }
432  }
433  }
434  }
435  }
436 }
437 
438 print '</table>';
439 /*
440  * Autres Options
441  */
442 print "<br>";
443 print load_fiche_titre($langs->trans("OtherOptions"),'','');
444 
445 print '<table class="noborder" width="100%">';
446 print '<tr class="liste_titre">';
447 print '<td>'.$langs->trans("Parameter").'</td>';
448 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
449 print '<td width="80">&nbsp;</td>';
450 print "</tr>\n";
451 
452 $substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
453 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
454 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
455 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
456 $htmltext.='</i>';
457 
458 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
459 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
460 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
461 print '<tr class="oddeven"><td colspan="2">';
462 print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
463 $variablename='DELIVERY_FREE_TEXT';
464 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
465 {
466  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
467 }
468 else
469 {
470  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
471  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
472  print $doleditor->Create();
473 }
474 print '</td><td align="right">';
475 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
476 print "</td></tr>\n";
477 print '</form>';
478 
479 print '</table>';
480 
481 // End of page
482 llxFooter();
483 $db->close();
484 
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1643
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage receptions.
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:510
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1609
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
expedition_admin_prepare_head()
Return array head with list of tabs to view object informations.
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
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:623
Class to manage a WYSIWYG editor.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)