dolibarr 19.0.3
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
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
30
31$langs->loadLangs(array("admin", "receptions", 'other'));
32
33
34if (!$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
51if (isModEnabled('reception') && !getDolGlobalString('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
56if (!getDolGlobalString('RECEPTION_ADDON_NUMBER')) {
57 $conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl';
58}
59
60
61/*
62 * Actions
63 */
64
65include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
66
67if ($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 = '';
107 $classname = '';
108 $filefound = 0;
109 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
110 foreach ($dirmodels as $reldir) {
111 $file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0);
112 if (file_exists($file)) {
113 $filefound = 1;
114 $classname = "pdf_".$modele;
115 break;
116 }
117 }
118
119 if ($filefound) {
120 require_once $file;
121
122 $module = new $classname($db);
123
124 if ($module->write_file($exp, $langs) > 0) {
125 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf");
126 return;
127 } else {
128 setEventMessages($module->error, $module->errors, 'errors');
129 dol_syslog($module->error, LOG_ERR);
130 }
131 } else {
132 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
133 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
134 }
135} elseif ($action == 'set') {
136 // Activate a model
137 $ret = addDocumentModel($value, $type, $label, $scandir);
138} elseif ($action == 'del') {
139 $ret = delDocumentModel($value, $type);
140 if ($ret > 0) {
141 if ($conf->global->RECEPTION_ADDON_PDF == "$value") {
142 dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
143 }
144 }
145} elseif ($action == 'setdoc') {
146 // Set default model
147 if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
148 // La constante qui a ete lue en avant du nouveau set
149 // on passe donc par une variable pour avoir un affichage coherent
150 $conf->global->RECEPTION_ADDON_PDF = $value;
151 }
152
153 // On active le modele
154 $ret = delDocumentModel($value, $type);
155 if ($ret > 0) {
156 $ret = addDocumentModel($value, $type, $label, $scandir);
157 }
158} elseif ($action == 'setmodel') {
159 dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
160}
161
162
163
164
165/*
166 * View
167 */
168
169$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
170
171$form = new Form($db);
172
173llxHeader("", $langs->trans("ReceptionsSetup"));
174
175$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
176print load_fiche_titre($langs->trans("ReceptionsSetup"), $linkback, 'title_setup');
177print '<br>';
179
180print dol_get_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'reception');
181
182// Reception numbering model
183
184print load_fiche_titre($langs->trans("ReceptionsNumberingModules"));
185
186print '<div class="div-table-responsive-no-min">';
187print '<table class="noborder centpercent">';
188print '<tr class="liste_titre">';
189print '<td width="100">'.$langs->trans("Name").'</td>';
190print '<td>'.$langs->trans("Description").'</td>';
191print '<td>'.$langs->trans("Example").'</td>';
192print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
193print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
194print "</tr>\n";
195
196clearstatcache();
197
198foreach ($dirmodels as $reldir) {
199 $dir = dol_buildpath($reldir."core/modules/reception");
200
201 if (is_dir($dir)) {
202 $handle = opendir($dir);
203 if (is_resource($handle)) {
204 while (($file = readdir($handle)) !== false) {
205 if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
206 $file = substr($file, 0, dol_strlen($file) - 4);
207
208 require_once $dir.'/'.$file.'.php';
209
210 $module = new $file();
211
212 if ($module->isEnabled()) {
213 // Show modules according to features level
214 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
215 continue;
216 }
217 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
218 continue;
219 }
220
221 print '<tr><td>'.$module->nom."</td>\n";
222 print '<td>';
223 print $module->info($langs);
224 print '</td>';
225
226 // Show example of numbering module
227 print '<td class="nowrap">';
228 $tmp = $module->getExample();
229 if (preg_match('/^Error/', $tmp)) {
230 $langs->load("errors");
231 print '<div class="error">'.$langs->trans($tmp).'</div>';
232 } elseif ($tmp == 'NotConfigured') {
233 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
234 } else {
235 print $tmp;
236 }
237 print '</td>'."\n";
238
239 print '<td class="center">';
240 if ($conf->global->RECEPTION_ADDON_NUMBER == "$file") {
241 print img_picto($langs->trans("Activated"), 'switch_on');
242 } else {
243 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) : '').'">';
244 print img_picto($langs->trans("Disabled"), 'switch_off');
245 print '</a>';
246 }
247 print '</td>';
248
249 $reception = new Reception($db);
250 $reception->initAsSpecimen();
251
252 // Info
253 $htmltooltip = '';
254 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
255 $nextval = $module->getNextValue($mysoc, $reception);
256 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
257 $htmltooltip .= ''.$langs->trans("NextValue").': ';
258 if ($nextval) {
259 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
260 $nextval = $langs->trans($nextval);
261 }
262 $htmltooltip .= $nextval.'<br>';
263 } else {
264 $htmltooltip .= $langs->trans($module->error).'<br>';
265 }
266 }
267
268 print '<td class="center">';
269 print $form->textwithpicto('', $htmltooltip, 1, 0);
270 print '</td>';
271
272 print '</tr>';
273 }
274 }
275 }
276 closedir($handle);
277 }
278 }
279}
280
281print '</table>';
282print '</div>';
283
284print '<br>';
285
286/*
287 * Documents models for Receptions Receipt
288 */
289print load_fiche_titre($langs->trans("ReceptionsReceiptModel"));
290
291// Defini tableau def de modele invoice
292$type = "reception";
293$def = array();
294
295$sql = "SELECT nom";
296$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
297$sql .= " WHERE type = '".$db->escape($type)."'";
298$sql .= " AND entity = ".$conf->entity;
299
300$resql = $db->query($sql);
301if ($resql) {
302 $i = 0;
303 $num_rows = $db->num_rows($resql);
304 while ($i < $num_rows) {
305 $array = $db->fetch_array($resql);
306 array_push($def, $array[0]);
307 $i++;
308 }
309} else {
310 dol_print_error($db);
311}
312
313print '<div class="div-table-responsive-no-min">';
314print '<table class="noborder centpercent">';
315print '<tr class="liste_titre">';
316print '<td width="140">'.$langs->trans("Name").'</td>';
317print '<td>'.$langs->trans("Description").'</td>';
318print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
319print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
320print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
321print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
322print "</tr>\n";
323
324clearstatcache();
325
326foreach ($dirmodels as $reldir) {
327 foreach (array('', '/doc') as $valdir) {
328 $realpath = $reldir."core/modules/reception".$valdir;
329 $dir = dol_buildpath($realpath);
330
331 if (is_dir($dir)) {
332 $handle = opendir($dir);
333 if (is_resource($handle)) {
334 while (($file = readdir($handle)) !== false) {
335 $filelist[] = $file;
336 }
337 closedir($handle);
338 arsort($filelist);
339
340 foreach ($filelist as $file) {
341 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
342 if (file_exists($dir.'/'.$file)) {
343 $name = substr($file, 4, dol_strlen($file) - 16);
344 $classname = substr($file, 0, dol_strlen($file) - 12);
345
346 require_once $dir.'/'.$file;
347 $module = new $classname($db);
348
349 $modulequalified = 1;
350 if (isset($module->version) && $module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
351 $modulequalified = 0;
352 }
353 if (isset($module->version) && $module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
354 $modulequalified = 0;
355 }
356
357 if ($modulequalified) {
358 print '<tr><td width="100">';
359 print(empty($module->name) ? $name : $module->name);
360 print "</td><td>\n";
361 if (method_exists($module, 'info')) {
362 print $module->info($langs);
363 } else {
364 print $module->description;
365 }
366 print '</td>';
367
368 // Active
369 if (in_array($name, $def)) {
370 print '<td class="center">'."\n";
371 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
372 print img_picto($langs->trans("Enabled"), 'switch_on');
373 print '</a>';
374 print '</td>';
375 } else {
376 print '<td class="center">'."\n";
377 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>';
378 print "</td>";
379 }
380
381 // Defaut
382 print '<td class="center">';
383 if ($conf->global->RECEPTION_ADDON_PDF == $name) {
384 print img_picto($langs->trans("Default"), 'on');
385 } else {
386 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>';
387 }
388 print '</td>';
389
390 // Info
391 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
392 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
393 if ($module->type == 'pdf') {
394 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
395 }
396 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
397
398 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
399 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
400 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
401 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
402 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
403 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
404
405 print '<td class="center">';
406 print $form->textwithpicto('', $htmltooltip, 1, 0);
407 print '</td>';
408
409 // Preview
410 print '<td class="center">';
411 if ($module->type == 'pdf') {
412 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>';
413 } else {
414 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
415 }
416 print '</td>';
417
418 print "</tr>\n";
419 }
420 }
421 }
422 }
423 }
424 }
425 }
426}
427
428print '</table>';
429print '</div>';
430
431print '<br>';
432
433
434/*
435 * Other options
436 *
437 */
438/*
439print load_fiche_titre($langs->trans("OtherOptions"));
440
441print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
442print '<input type="hidden" name="token" value="'.newToken().'">';
443print '<input type="hidden" name="action" value="set_param">';
444
445print "<table class=\"noborder\" width=\"100%\">";
446print "<tr class=\"liste_titre\">";
447print "<td>".$langs->trans("Parameter")."</td>\n";
448print "</tr>";
449
450$substitutionarray=pdf_getSubstitutionArray($langs);
451$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
452$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
453foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
454$htmltext.='</i>';
455
456print '<tr><td>';
457print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
458$variablename='RECEPTION_FREE_TEXT';
459if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
460{
461 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
462}
463else
464{
465 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
466 $doleditor=new DolEditor($variablename, getDolGlobalString($variablename),'',80,'dolibarr_notes');
467 print $doleditor->Create();
468}
469print "</td></tr>\n";
470
471print '<tr><td>';
472print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>';
473print '<input class="flat minwidth200" type="text" name="RECEPTION_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('RECEPTION_DRAFT_WATERMARK')).'">';
474print "</td></tr>\n";
475*/
476print '</table>';
477
478//print $form->buttonsSaveCancel("Modify", '');
479
480print '</form>';
481
482llxFooter();
483$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()
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.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.