dolibarr  13.0.2
reception_setup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
29 
30 $langs->loadLangs(array("admin", "receptions", 'other'));
31 
32 
33 if (!$user->admin) accessforbidden();
34 
35 $action = GETPOST('action', 'aZ09');
36 $value = GETPOST('value', 'alpha');
37 $label = GETPOST('label', 'alpha');
38 $scandir = GETPOST('scan_dir', 'alpha');
39 $type = 'reception';
40 
41 
42 /*
43  * Actions
44  */
45 
46 if (!empty($conf->reception->enabled) && empty($conf->global->MAIN_SUBMODULE_RECEPTION))
47 {
48  // This option should always be set to on when module is on.
49  dolibarr_set_const($db, "MAIN_SUBMODULE_RECEPTION", "1", 'chaine', 0, '', $conf->entity);
50 }
51 
52 if (empty($conf->global->RECEPTION_ADDON_NUMBER))
53 {
54  $conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl';
55 }
56 
57 
58 /*
59  * Actions
60  */
61 
62 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
63 
64 if ($action == 'updateMask')
65 {
66  $maskconst = GETPOST('maskconstreception', 'alpha');
67  $maskvalue = GETPOST('maskreception', 'alpha');
68  if (!empty($maskconst))
69  $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
70 
71  if (isset($res))
72  {
73  if ($res > 0)
74  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
75  else setEventMessages($langs->trans("Error"), null, 'errors');
76  }
77 } elseif ($action == 'set_param')
78 {
79  $freetext = GETPOST('RECEPTION_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
80  $res = dolibarr_set_const($db, "RECEPTION_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('RECEPTION_DRAFT_WATERMARK', 'alpha');
88  $res = dolibarr_set_const($db, "RECEPTION_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 } elseif ($action == 'specimen')
100 {
101  $modele = GETPOST('module', 'alpha');
102 
103  $exp = new Reception($db);
104  $exp->initAsSpecimen();
105 
106  // Search template files
107  $file = ''; $classname = ''; $filefound = 0;
108  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
109  foreach ($dirmodels as $reldir)
110  {
111  $file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0);
112  if (file_exists($file))
113  {
114  $filefound = 1;
115  $classname = "pdf_".$modele;
116  break;
117  }
118  }
119 
120  if ($filefound)
121  {
122  require_once $file;
123 
124  $module = new $classname($db);
125 
126  if ($module->write_file($exp, $langs) > 0)
127  {
128  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf");
129  return;
130  } else {
131  setEventMessages($module->error, $module->errors, 'errors');
132  dol_syslog($module->error, LOG_ERR);
133  }
134  } else {
135  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
136  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
137  }
138 }
139 
140 // Activate a model
141 elseif ($action == 'set')
142 {
143  $ret = addDocumentModel($value, $type, $label, $scandir);
144 } elseif ($action == 'del')
145 {
146  $ret = delDocumentModel($value, $type);
147  if ($ret > 0)
148  {
149  if ($conf->global->RECEPTION_ADDON_PDF == "$value") dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
150  }
151 }
152 
153 // Set default model
154 elseif ($action == 'setdoc')
155 {
156  if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
157  {
158  // La constante qui a ete lue en avant du nouveau set
159  // on passe donc par une variable pour avoir un affichage coherent
160  $conf->global->RECEPTION_ADDON_PDF = $value;
161  }
162 
163  // On active le modele
164  $ret = delDocumentModel($value, $type);
165  if ($ret > 0)
166  {
167  $ret = addDocumentModel($value, $type, $label, $scandir);
168  }
169 } elseif ($action == 'setmodel')
170 {
171  dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
172 }
173 
174 
175 
176 
177 /*
178  * View
179  */
180 
181 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
182 
183 $form = new Form($db);
184 
185 llxHeader("", $langs->trans("ReceptionsSetup"));
186 
187 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
188 print load_fiche_titre($langs->trans("ReceptionsSetup"), $linkback, 'title_setup');
189 print '<br>';
191 
192 print dol_get_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'sending');
193 
194 // Reception numbering model
195 
196 print load_fiche_titre($langs->trans("ReceptionsNumberingModules"));
197 
198 print '<table class="noborder centpercent">';
199 print '<tr class="liste_titre">';
200 print '<td width="100">'.$langs->trans("Name").'</td>';
201 print '<td>'.$langs->trans("Description").'</td>';
202 print '<td>'.$langs->trans("Example").'</td>';
203 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
204 print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
205 print "</tr>\n";
206 
207 clearstatcache();
208 
209 foreach ($dirmodels as $reldir)
210 {
211  $dir = dol_buildpath($reldir."core/modules/reception");
212 
213  if (is_dir($dir))
214  {
215  $handle = opendir($dir);
216  if (is_resource($handle))
217  {
218  while (($file = readdir($handle)) !== false)
219  {
220  if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
221  {
222  $file = substr($file, 0, dol_strlen($file) - 4);
223 
224  require_once $dir.'/'.$file.'.php';
225 
226  $module = new $file;
227 
228  if ($module->isEnabled())
229  {
230  // Show modules according to features level
231  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
232  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
233 
234  print '<tr><td>'.$module->nom."</td>\n";
235  print '<td>';
236  print $module->info();
237  print '</td>';
238 
239  // Show example of numbering module
240  print '<td class="nowrap">';
241  $tmp = $module->getExample();
242  if (preg_match('/^Error/', $tmp)) {
243  $langs->load("errors");
244  print '<div class="error">'.$langs->trans($tmp).'</div>';
245  } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
246  else print $tmp;
247  print '</td>'."\n";
248 
249  print '<td class="center">';
250  if ($conf->global->RECEPTION_ADDON_NUMBER == "$file")
251  {
252  print img_picto($langs->trans("Activated"), 'switch_on');
253  } else {
254  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;token='.newToken().'&amp;value='.urlencode($file).'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
255  print img_picto($langs->trans("Disabled"), 'switch_off');
256  print '</a>';
257  }
258  print '</td>';
259 
260  $reception = new Reception($db);
261  $reception->initAsSpecimen();
262 
263  // Info
264  $htmltooltip = '';
265  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
266  $nextval = $module->getNextValue($mysoc, $reception);
267  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
268  $htmltooltip .= ''.$langs->trans("NextValue").': ';
269  if ($nextval) {
270  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
271  $nextval = $langs->trans($nextval);
272  $htmltooltip .= $nextval.'<br>';
273  } else {
274  $htmltooltip .= $langs->trans($module->error).'<br>';
275  }
276  }
277 
278  print '<td class="center">';
279  print $form->textwithpicto('', $htmltooltip, 1, 0);
280  print '</td>';
281 
282  print '</tr>';
283  }
284  }
285  }
286  closedir($handle);
287  }
288  }
289 }
290 
291 print '</table><br>';
292 
293 
294 /*
295  * Documents models for Receptions Receipt
296  */
297 print load_fiche_titre($langs->trans("ReceptionsReceiptModel"));
298 
299 // Defini tableau def de modele invoice
300 $type = "reception";
301 $def = array();
302 
303 $sql = "SELECT nom";
304 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
305 $sql .= " WHERE type = '".$db->escape($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 } else {
320  dol_print_error($db);
321 }
322 
323 print '<table class="noborder centpercent">';
324 print '<tr class="liste_titre">';
325 print '<td width="140">'.$langs->trans("Name").'</td>';
326 print '<td>'.$langs->trans("Description").'</td>';
327 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
328 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
329 print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
330 print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
331 print "</tr>\n";
332 
333 clearstatcache();
334 
335 foreach ($dirmodels as $reldir)
336 {
337  foreach (array('', '/doc') as $valdir)
338  {
339  $realpath = $reldir."core/modules/reception".$valdir;
340  $dir = dol_buildpath($realpath);
341 
342  if (is_dir($dir))
343  {
344  $handle = opendir($dir);
345  if (is_resource($handle))
346  {
347  while (($file = readdir($handle)) !== false)
348  {
349  $filelist[] = $file;
350  }
351  closedir($handle);
352  arsort($filelist);
353 
354  foreach ($filelist as $file)
355  {
356  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
357  {
358  if (file_exists($dir.'/'.$file))
359  {
360  $name = substr($file, 4, dol_strlen($file) - 16);
361  $classname = substr($file, 0, dol_strlen($file) - 12);
362 
363  require_once $dir.'/'.$file;
364  $module = new $classname($db);
365 
366  $modulequalified = 1;
367  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
368  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
369 
370  if ($modulequalified)
371  {
372  print '<tr><td width="100">';
373  print (empty($module->name) ? $name : $module->name);
374  print "</td><td>\n";
375  if (method_exists($module, 'info')) print $module->info($langs);
376  else print $module->description;
377  print '</td>';
378 
379  // Active
380  if (in_array($name, $def))
381  {
382  print '<td class="center">'."\n";
383  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
384  print img_picto($langs->trans("Enabled"), 'switch_on');
385  print '</a>';
386  print '</td>';
387  } else {
388  print '<td class="center">'."\n";
389  print '<a class="reposition" 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>';
390  print "</td>";
391  }
392 
393  // Defaut
394  print '<td class="center">';
395  if ($conf->global->RECEPTION_ADDON_PDF == $name)
396  {
397  print img_picto($langs->trans("Default"), 'on');
398  } else {
399  print '<a class="reposition" 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>';
400  }
401  print '</td>';
402 
403  // Info
404  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
405  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
406  if ($module->type == 'pdf')
407  {
408  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
409  }
410  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
411 
412  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
413  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
414  $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
415  $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
416  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
417  $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
418 
419  print '<td class="center">';
420  print $form->textwithpicto('', $htmltooltip, 1, 0);
421  print '</td>';
422 
423  // Preview
424  print '<td class="center">';
425  if ($module->type == 'pdf')
426  {
427  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"), 'pdf').'</a>';
428  } else {
429  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
430  }
431  print '</td>';
432 
433  print "</tr>\n";
434  }
435  }
436  }
437  }
438  }
439  }
440  }
441 }
442 
443 print '</table>';
444 print '<br>';
445 
446 
447 /*
448  * Other options
449  *
450  */
451 /*
452 print load_fiche_titre($langs->trans("OtherOptions"));
453 
454 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
455 print '<input type="hidden" name="token" value="'.newToken().'">';
456 print '<input type="hidden" name="action" value="set_param">';
457 
458 print "<table class=\"noborder\" width=\"100%\">";
459 print "<tr class=\"liste_titre\">";
460 print "<td>".$langs->trans("Parameter")."</td>\n";
461 print "</tr>";
462 
463 $substitutionarray=pdf_getSubstitutionArray($langs);
464 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
465 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
466 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
467 $htmltext.='</i>';
468 
469 print '<tr><td>';
470 print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
471 $variablename='RECEPTION_FREE_TEXT';
472 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
473 {
474  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
475 }
476 else
477 {
478  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
479  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
480  print $doleditor->Create();
481 }
482 print "</td></tr>\n";
483 
484 print '<tr><td>';
485 print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>';
486 print '<input size="50" class="flat" type="text" name="RECEPTION_DRAFT_WATERMARK" value="'.$conf->global->RECEPTION_DRAFT_WATERMARK.'">';
487 print "</td></tr>\n";
488 */
489 print '</table>';
490 
491 //print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
492 
493 print '</form>';
494 
495 llxFooter();
496 $db->close();
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.
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)
Class to manage receptions.
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 ...
reception_admin_prepare_head()
Return array head with list of tabs to view object informations.
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
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.