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