dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
23  */
24 
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.'/expedition/class/expedition.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 $action=GETPOST('action','alpha');
44 $value=GETPOST('value','alpha');
45 $label = GETPOST('label','alpha');
46 $scandir = GETPOST('scan_dir','alpha');
47 $type='shipping';
48 
49 if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
50 {
51  $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor';
52 }
53 
54 
55 /*
56  * Actions
57  */
58 
59 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
60 
61 if ($action == 'updateMask')
62 {
63  $maskconst=GETPOST('maskconstexpedition','alpha');
64  $maskvalue=GETPOST('maskexpedition','alpha');
65  if (! empty($maskconst))
66  $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
67 
68  if (isset($res))
69  {
70  if ($res > 0)
71  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
72  else
73  setEventMessages($langs->trans("Error"), null, 'errors');
74  }
75 }
76 
77 else if ($action == 'set_param')
78 {
79  $freetext=GETPOST('SHIPPING_FREE_TEXT','none'); // 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  {
83  $error++;
84  setEventMessages($langs->trans("Error"), null, 'errors');
85  }
86 
87  $draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
88  $res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
89  if ($res <= 0)
90  {
91  $error++;
92  setEventMessages($langs->trans("Error"), null, 'errors');
93  }
94 
95  if (! $error)
96  {
97  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
98  }
99 }
100 
101 else if ($action == 'specimen')
102 {
103  $modele=GETPOST('module','alpha');
104 
105  $exp = new Expedition($db);
106  $exp->initAsSpecimen();
107 
108  // Search template files
109  $file=''; $classname=''; $filefound=0;
110  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
111  foreach($dirmodels as $reldir)
112  {
113  $file=dol_buildpath($reldir."core/modules/expedition/doc/pdf_".$modele.".modules.php",0);
114  if (file_exists($file))
115  {
116  $filefound=1;
117  $classname = "pdf_".$modele;
118  break;
119  }
120  }
121 
122  if ($filefound)
123  {
124  require_once $file;
125 
126  $module = new $classname($db);
127 
128  if ($module->write_file($exp,$langs) > 0)
129  {
130  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expedition&file=SPECIMEN.pdf");
131  return;
132  }
133  else
134  {
135  setEventMessages($module->error, $module->errors, 'errors');
136  dol_syslog($module->error, LOG_ERR);
137  }
138  }
139  else
140  {
141  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
142  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
143  }
144 }
145 
146 // Activate a model
147 else if ($action == 'set')
148 {
149  $ret = addDocumentModel($value, $type, $label, $scandir);
150 }
151 
152 else if ($action == 'del')
153 {
154  $ret = delDocumentModel($value, $type);
155  if ($ret > 0)
156  {
157  if ($conf->global->EXPEDITION_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF',$conf->entity);
158  }
159 }
160 
161 // Set default model
162 else if ($action == 'setdoc')
163 {
164  if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
165  {
166  // La constante qui a ete lue en avant du nouveau set
167  // on passe donc par une variable pour avoir un affichage coherent
168  $conf->global->EXPEDITION_ADDON_PDF = $value;
169  }
170 
171  // On active le modele
172  $ret = delDocumentModel($value, $type);
173  if ($ret > 0)
174  {
175  $ret = addDocumentModel($value, $type, $label, $scandir);
176  }
177 }
178 
179 else if ($action == 'setmodel')
180 {
181  dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
182 }
183 
184 
185 /*
186  * View
187  */
188 
189 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
190 
191 $form=new Form($db);
192 
193 llxHeader("",$langs->trans("SendingsSetup"));
194 
195 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
196 print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
197 print '<br>';
199 
200 dol_fiche_head($head, 'shipment', $langs->trans("Sendings"), -1, 'sending');
201 
202 // Shipment numbering model
203 
204 print load_fiche_titre($langs->trans("SendingsNumberingModules"));
205 
206 print '<table class="noborder" width="100%">';
207 print '<tr class="liste_titre">';
208 print '<td width="100">'.$langs->trans("Name").'</td>';
209 print '<td>'.$langs->trans("Description").'</td>';
210 print '<td>'.$langs->trans("Example").'</td>';
211 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
212 print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
213 print "</tr>\n";
214 
215 clearstatcache();
216 
217 foreach ($dirmodels as $reldir)
218 {
219  $dir = dol_buildpath($reldir."core/modules/expedition/");
220 
221  if (is_dir($dir))
222  {
223  $handle = opendir($dir);
224  if (is_resource($handle))
225  {
226  while (($file = readdir($handle))!==false)
227  {
228  if (substr($file, 0, 15) == 'mod_expedition_' && substr($file, dol_strlen($file)-3, 3) == 'php')
229  {
230  $file = substr($file, 0, dol_strlen($file)-4);
231 
232  require_once $dir.$file.'.php';
233 
234  $module = new $file;
235 
236  if ($module->isEnabled())
237  {
238  // Show modules according to features level
239  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
240  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
241 
242  print '<tr><td>'.$module->nom."</td>\n";
243  print '<td>';
244  print $module->info();
245  print '</td>';
246 
247  // Show example of numbering module
248  print '<td class="nowrap">';
249  $tmp=$module->getExample();
250  if (preg_match('/^Error/',$tmp)) {
251  $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
252  }
253  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
254  else print $tmp;
255  print '</td>'."\n";
256 
257  print '<td align="center">';
258  if ($conf->global->EXPEDITION_ADDON_NUMBER == "$file")
259  {
260  print img_picto($langs->trans("Activated"),'switch_on');
261  }
262  else
263  {
264  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$file.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
265  print img_picto($langs->trans("Disabled"),'switch_off');
266  print '</a>';
267  }
268  print '</td>';
269 
270  $expedition=new Expedition($db);
271  $expedition->initAsSpecimen();
272 
273  // Info
274  $htmltooltip='';
275  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
276  $nextval=$module->getNextValue($mysoc,$expedition);
277  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
278  $htmltooltip.=''.$langs->trans("NextValue").': ';
279  if ($nextval) {
280  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
281  $nextval = $langs->trans($nextval);
282  $htmltooltip.=$nextval.'<br>';
283  } else {
284  $htmltooltip.=$langs->trans($module->error).'<br>';
285  }
286  }
287 
288  print '<td align="center">';
289  print $form->textwithpicto('',$htmltooltip,1,0);
290  print '</td>';
291 
292  print '</tr>';
293  }
294  }
295  }
296  closedir($handle);
297  }
298  }
299 }
300 
301 print '</table><br>';
302 
303 
304 /*
305  * Documents models for Sendings Receipt
306  */
307 print load_fiche_titre($langs->trans("SendingsReceiptModel"));
308 
309 // Defini tableau def de modele invoice
310 $type="shipping";
311 $def = array();
312 
313 $sql = "SELECT nom";
314 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
315 $sql.= " WHERE type = '".$type."'";
316 $sql.= " AND entity = ".$conf->entity;
317 
318 $resql=$db->query($sql);
319 if ($resql)
320 {
321  $i = 0;
322  $num_rows=$db->num_rows($resql);
323  while ($i < $num_rows)
324  {
325  $array = $db->fetch_array($resql);
326  array_push($def, $array[0]);
327  $i++;
328  }
329 }
330 else
331 {
332  dol_print_error($db);
333 }
334 
335 print '<table class="noborder" width="100%">';
336 print '<tr class="liste_titre">';
337 print '<td width="140">'.$langs->trans("Name").'</td>';
338 print '<td>'.$langs->trans("Description").'</td>';
339 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
340 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
341 print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
342 print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
343 print "</tr>\n";
344 
345 clearstatcache();
346 
347 foreach ($dirmodels as $reldir)
348 {
349  foreach (array('','/doc') as $valdir)
350  {
351  $dir = dol_buildpath($reldir."core/modules/expedition".$valdir);
352 
353  if (is_dir($dir))
354  {
355  $handle=opendir($dir);
356  if (is_resource($handle))
357  {
358  while (($file = readdir($handle))!==false)
359  {
360  $filelist[]=$file;
361  }
362  closedir($handle);
363  arsort($filelist);
364 
365  foreach($filelist as $file)
366  {
367  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
368  {
369 
370  if (file_exists($dir.'/'.$file))
371  {
372  $name = substr($file, 4, dol_strlen($file) -16);
373  $classname = substr($file, 0, dol_strlen($file) -12);
374 
375  require_once $dir.'/'.$file;
376  $module = new $classname($db);
377 
378  $modulequalified=1;
379  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
380  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
381 
382  if ($modulequalified)
383  {
384  print '<tr><td width="100">';
385  print (empty($module->name)?$name:$module->name);
386  print "</td><td>\n";
387  if (method_exists($module,'info')) print $module->info($langs);
388  else print $module->description;
389  print '</td>';
390 
391  // Active
392  if (in_array($name, $def))
393  {
394  print '<td align="center">'."\n";
395  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
396  print img_picto($langs->trans("Enabled"),'switch_on');
397  print '</a>';
398  print '</td>';
399  }
400  else
401  {
402  print '<td align="center">'."\n";
403  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
404  print "</td>";
405  }
406 
407  // Defaut
408  print '<td align="center">';
409  if ($conf->global->EXPEDITION_ADDON_PDF == $name)
410  {
411  print img_picto($langs->trans("Default"),'on');
412  }
413  else
414  {
415  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
416  }
417  print '</td>';
418 
419  // Info
420  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
421  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
422  if ($module->type == 'pdf')
423  {
424  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
425  }
426  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
427  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
428  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
429  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
430  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
431  $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
432 
433  print '<td align="center">';
434  print $form->textwithpicto('',$htmltooltip,1,0);
435  print '</td>';
436 
437  // Preview
438  print '<td align="center">';
439  if ($module->type == 'pdf')
440  {
441  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"),'sending').'</a>';
442  }
443  else
444  {
445  print img_object($langs->trans("PreviewNotAvailable"),'generic');
446  }
447  print '</td>';
448 
449  print "</tr>\n";
450  }
451  }
452  }
453  }
454  }
455  }
456  }
457 }
458 
459 print '</table>';
460 print '<br>';
461 
462 
463 /*
464  * Other options
465  *
466  */
467 print load_fiche_titre($langs->trans("OtherOptions"));
468 
469 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
470 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
471 print '<input type="hidden" name="action" value="set_param">';
472 
473 print "<table class=\"noborder\" width=\"100%\">";
474 print "<tr class=\"liste_titre\">";
475 print "<td>".$langs->trans("Parameter")."</td>\n";
476 print "</tr>";
477 
478 $substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
479 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
480 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
481 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
482 $htmltext.='</i>';
483 
484 print '<tr><td>';
485 print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
486 $variablename='SHIPPING_FREE_TEXT';
487 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
488 {
489  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
490 }
491 else
492 {
493  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
494  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
495  print $doleditor->Create();
496 }
497 print "</td></tr>\n";
498 
499 print '<tr><td>';
500 print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
501 print '<input size="50" class="flat" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.$conf->global->SHIPPING_DRAFT_WATERMARK.'">';
502 print "</td></tr>\n";
503 
504 print '</table>';
505 
506 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
507 
508 print '</form>';
509 
510 // End of page
511 llxFooter();
512 $db->close();
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
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
Class to manage shipments.
llxHeader()
Empty header.
Definition: wrapper.php:44
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)