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