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