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