dolibarr  20.0.0-beta
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  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
32 
33 $langs->loadLangs(array("admin", "receptions", 'other'));
34 
35 
36 if (!$user->admin) {
38 }
39 
40 $action = GETPOST('action', 'aZ09');
41 $value = GETPOST('value', 'alpha');
42 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
43 
44 $label = GETPOST('label', 'alpha');
45 $scandir = GETPOST('scan_dir', 'alpha');
46 $type = 'reception';
47 
48 
49 /*
50  * Actions
51  */
52 
53 if (isModEnabled('reception') && !getDolGlobalString('MAIN_SUBMODULE_RECEPTION')) {
54  // This option should always be set to on when module is on.
55  dolibarr_set_const($db, "MAIN_SUBMODULE_RECEPTION", "1", 'chaine', 0, '', $conf->entity);
56 }
57 
58 if (!getDolGlobalString('RECEPTION_ADDON_NUMBER')) {
59  $conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl';
60 }
61 
62 
63 /*
64  * Actions
65  */
66 
67 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
68 
69 if ($action == 'updateMask') {
70  $maskconst = GETPOST('maskconstreception', 'aZ09');
71  $maskvalue = GETPOST('maskreception', 'alpha');
72  if (!empty($maskconst) && preg_match('/_MASK$/', $maskconst)) {
73  $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
74  }
75 
76  if (isset($res)) {
77  if ($res > 0) {
78  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
79  } else {
80  setEventMessages($langs->trans("Error"), null, 'errors');
81  }
82  }
83 } elseif ($action == 'set_param') {
84  $freetext = GETPOST('RECEPTION_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
85  $res = dolibarr_set_const($db, "RECEPTION_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
86  if ($res <= 0) {
87  $error++;
88  setEventMessages($langs->trans("Error"), null, 'errors');
89  }
90 
91  $draft = GETPOST('RECEPTION_DRAFT_WATERMARK', 'alpha');
92  $res = dolibarr_set_const($db, "RECEPTION_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
93  if ($res <= 0) {
94  $error++;
95  setEventMessages($langs->trans("Error"), null, 'errors');
96  }
97 
98  if (!$error) {
99  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
100  }
101 } elseif ($action == 'specimen') {
102  $modele = GETPOST('module', 'alpha');
103 
104  $exp = new Reception($db);
105  $exp->initAsSpecimen();
106 
107  // Search template files
108  $file = '';
109  $classname = '';
110  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
111  foreach ($dirmodels as $reldir) {
112  $file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0);
113  if (file_exists($file)) {
114  $classname = "pdf_".$modele;
115  break;
116  }
117  }
118 
119  if ($classname !== '') {
120  require_once $file;
121 
122  $module = new $classname($db);
123  '@phan-var-force CommonDocGenerator $module';
124 
125  if ($module->write_file($exp, $langs) > 0) {
126  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf");
127  return;
128  } else {
129  setEventMessages($module->error, $module->errors, 'errors');
130  dol_syslog($module->error, LOG_ERR);
131  }
132  } else {
133  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
134  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
135  }
136 } elseif ($action == 'set') {
137  // Activate a model
138  $ret = addDocumentModel($value, $type, $label, $scandir);
139 } elseif ($action == 'del') {
140  $ret = delDocumentModel($value, $type);
141  if ($ret > 0) {
142  if ($conf->global->RECEPTION_ADDON_PDF == "$value") {
143  dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
144  }
145  }
146 } elseif ($action == 'setdoc') {
147  // Set default model
148  if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
149  // La constante qui a ete lue en avant du nouveau set
150  // on passe donc par une variable pour avoir un affichage coherent
151  $conf->global->RECEPTION_ADDON_PDF = $value;
152  }
153 
154  // On active le modele
155  $ret = delDocumentModel($value, $type);
156  if ($ret > 0) {
157  $ret = addDocumentModel($value, $type, $label, $scandir);
158  }
159 } elseif ($action == 'setmodel') {
160  dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
161 }
162 
163 
164 
165 
166 /*
167  * View
168  */
169 
170 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
171 
172 $form = new Form($db);
173 
174 llxHeader("", $langs->trans("ReceptionsSetup"));
175 
176 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
177 print load_fiche_titre($langs->trans("ReceptionsSetup"), $linkback, 'title_setup');
178 print '<br>';
180 
181 print dol_get_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'reception');
182 
183 // Reception numbering model
184 
185 print load_fiche_titre($langs->trans("ReceptionsNumberingModules"));
186 
187 print '<div class="div-table-responsive-no-min">';
188 print '<table class="noborder centpercent">';
189 print '<tr class="liste_titre">';
190 print '<td width="100">'.$langs->trans("Name").'</td>';
191 print '<td>'.$langs->trans("Description").'</td>';
192 print '<td>'.$langs->trans("Example").'</td>';
193 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
194 print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
195 print "</tr>\n";
196 
197 clearstatcache();
198 
199 foreach ($dirmodels as $reldir) {
200  $dir = dol_buildpath($reldir."core/modules/reception");
201 
202  if (is_dir($dir)) {
203  $handle = opendir($dir);
204  if (is_resource($handle)) {
205  while (($file = readdir($handle)) !== false) {
206  if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
207  $file = substr($file, 0, dol_strlen($file) - 4);
208 
209  require_once $dir.'/'.$file.'.php';
210 
211  $module = new $file();
212 
213  if ($module->isEnabled()) {
214  // Show modules according to features level
215  if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
216  continue;
217  }
218  if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
219  continue;
220  }
221 
222  print '<tr><td>'.$module->nom."</td>\n";
223  print '<td>';
224  print $module->info($langs);
225  print '</td>';
226 
227  // Show example of numbering module
228  print '<td class="nowrap">';
229  $tmp = $module->getExample();
230  if (preg_match('/^Error/', $tmp)) {
231  $langs->load("errors");
232  print '<div class="error">'.$langs->trans($tmp).'</div>';
233  } elseif ($tmp == 'NotConfigured') {
234  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
235  } else {
236  print $tmp;
237  }
238  print '</td>'."\n";
239 
240  print '<td class="center">';
241  if ($conf->global->RECEPTION_ADDON_NUMBER == "$file") {
242  print img_picto($langs->trans("Activated"), 'switch_on');
243  } else {
244  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).(!empty($module->scandir) ? '&scan_dir='.$module->scandir : '').(!empty($module->name) ? '&label='.urlencode($module->name) : '').'">';
245  print img_picto($langs->trans("Disabled"), 'switch_off');
246  print '</a>';
247  }
248  print '</td>';
249 
250  $reception = new Reception($db);
251  $reception->initAsSpecimen();
252 
253  // Info
254  $htmltooltip = '';
255  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
256  $nextval = $module->getNextValue($mysoc, $reception);
257  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
258  $htmltooltip .= ''.$langs->trans("NextValue").': ';
259  if ($nextval) {
260  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
261  $nextval = $langs->trans($nextval);
262  }
263  $htmltooltip .= $nextval.'<br>';
264  } else {
265  $htmltooltip .= $langs->trans($module->error).'<br>';
266  }
267  }
268 
269  print '<td class="center">';
270  print $form->textwithpicto('', $htmltooltip, 1, 0);
271  print '</td>';
272 
273  print '</tr>';
274  }
275  }
276  }
277  closedir($handle);
278  }
279  }
280 }
281 
282 print '</table>';
283 print '</div>';
284 
285 print '<br>';
286 
287 /*
288  * Documents models for Receptions Receipt
289  */
290 print load_fiche_titre($langs->trans("ReceptionsReceiptModel"));
291 
292 // Defini tableau def de modele invoice
293 $type = "reception";
294 $def = array();
295 
296 $sql = "SELECT nom";
297 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
298 $sql .= " WHERE type = '".$db->escape($type)."'";
299 $sql .= " AND entity = ".$conf->entity;
300 
301 $resql = $db->query($sql);
302 if ($resql) {
303  $i = 0;
304  $num_rows = $db->num_rows($resql);
305  while ($i < $num_rows) {
306  $array = $db->fetch_array($resql);
307  if (is_array($array)) {
308  array_push($def, $array[0]);
309  }
310  $i++;
311  }
312 } else {
313  dol_print_error($db);
314 }
315 
316 print '<div class="div-table-responsive-no-min">';
317 print '<table class="noborder centpercent">';
318 print '<tr class="liste_titre">';
319 print '<td width="140">'.$langs->trans("Name").'</td>';
320 print '<td>'.$langs->trans("Description").'</td>';
321 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
322 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
323 print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
324 print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
325 print "</tr>\n";
326 
327 clearstatcache();
328 
329 foreach ($dirmodels as $reldir) {
330  foreach (array('', '/doc') as $valdir) {
331  $realpath = $reldir."core/modules/reception".$valdir;
332  $dir = dol_buildpath($realpath);
333 
334  if (is_dir($dir)) {
335  $handle = opendir($dir);
336  if (is_resource($handle)) {
337  $filelist = array();
338  while (($file = readdir($handle)) !== false) {
339  $filelist[] = $file;
340  }
341  closedir($handle);
342  arsort($filelist);
343 
344  foreach ($filelist as $file) {
345  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
346  if (file_exists($dir.'/'.$file)) {
347  $name = substr($file, 4, dol_strlen($file) - 16);
348  $classname = substr($file, 0, dol_strlen($file) - 12);
349 
350  require_once $dir.'/'.$file;
351  $module = new $classname($db);
352 
353  $modulequalified = 1;
354  if (isset($module->version) && $module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
355  $modulequalified = 0;
356  }
357  if (isset($module->version) && $module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
358  $modulequalified = 0;
359  }
360 
361  if ($modulequalified) {
362  print '<tr><td width="100">';
363  print(empty($module->name) ? $name : $module->name);
364  print "</td><td>\n";
365  if (method_exists($module, 'info')) {
366  print $module->info($langs);
367  } else {
368  print $module->description;
369  }
370  print '</td>';
371 
372  // Active
373  if (in_array($name, $def)) {
374  print '<td class="center">'."\n";
375  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
376  print img_picto($langs->trans("Enabled"), 'switch_on');
377  print '</a>';
378  print '</td>';
379  } else {
380  print '<td class="center">'."\n";
381  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
382  print "</td>";
383  }
384 
385  // Default
386  print '<td class="center">';
387  if ($conf->global->RECEPTION_ADDON_PDF == $name) {
388  print img_picto($langs->trans("Default"), 'on');
389  } else {
390  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
391  }
392  print '</td>';
393 
394  // Info
395  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
396  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
397  if ($module->type == 'pdf') {
398  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
399  }
400  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
401 
402  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
403  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
404  $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
405  $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
406  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
407  $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
408 
409  print '<td class="center">';
410  print $form->textwithpicto('', $htmltooltip, 1, 0);
411  print '</td>';
412 
413  // Preview
414  print '<td class="center">';
415  if ($module->type == 'pdf') {
416  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>';
417  } else {
418  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
419  }
420  print '</td>';
421 
422  print "</tr>\n";
423  }
424  }
425  }
426  }
427  }
428  }
429  }
430 }
431 
432 print '</table>';
433 print '</div>';
434 
435 print '<br>';
436 
437 
438 /*
439  * Other options
440  *
441  */
442 /*
443 print load_fiche_titre($langs->trans("OtherOptions"));
444 
445 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
446 print '<input type="hidden" name="token" value="'.newToken().'">';
447 print '<input type="hidden" name="action" value="set_param">';
448 
449 print "<table class=\"noborder\" width=\"100%\">";
450 print "<tr class=\"liste_titre\">";
451 print "<td>".$langs->trans("Parameter")."</td>\n";
452 print "</tr>";
453 
454 $substitutionarray=pdf_getSubstitutionArray($langs);
455 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
456 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
457 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
458 $htmltext.='</i>';
459 
460 print '<tr><td>';
461 print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
462 $variablename='RECEPTION_FREE_TEXT';
463 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
464 {
465  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
466 }
467 else
468 {
469  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
470  $doleditor=new DolEditor($variablename, getDolGlobalString($variablename),'',80,'dolibarr_notes');
471  print $doleditor->Create();
472 }
473 print "</td></tr>\n";
474 
475 print '<tr><td>';
476 print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>';
477 print '<input class="flat minwidth200" type="text" name="RECEPTION_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('RECEPTION_DRAFT_WATERMARK')).'">';
478 print "</td></tr>\n";
479 */
480 print '</table>';
481 
482 //print $form->buttonsSaveCancel("Modify", '');
483 
484 print '</form>';
485 
486 llxFooter();
487 $db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1940
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:656
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:580
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1971
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
Class to manage receptions.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
reception_admin_prepare_head()
Return array head with list of tabs to view object information.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.