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