dolibarr 21.0.0-beta
chequereceipts.php
1<?php
2/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
36
46// Load translation files required by the page
47$langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54$value = GETPOST('value', 'alpha');
55
56
57if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
58 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php';
59}
60
61
62
63/*
64 * Actions
65 */
66$error = 0;
67
68if ($action == 'updateMask') {
69 $maskconstchequereceipts = GETPOST('maskconstchequereceipts', 'aZ09');
70 $maskchequereceipts = GETPOST('maskchequereceipts', 'alpha');
71
72 $res = 0;
73
74 if ($maskconstchequereceipts && preg_match('/_MASK$/', $maskconstchequereceipts)) {
75 $res = dolibarr_set_const($db, $maskconstchequereceipts, $maskchequereceipts, 'chaine', 0, '', $conf->entity);
76 }
77
78 if (!($res > 0)) {
79 $error++;
80 }
81
82 if (!$error) {
83 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
84 } else {
85 setEventMessages($langs->trans("Error"), null, 'errors');
86 }
87}
88
89if ($action == 'setmod') {
90 dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON", $value, 'chaine', 0, '', $conf->entity);
91}
92
93if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT') {
94 $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
95
96 $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
97
98 if (!($res > 0)) {
99 $error++;
100 }
101
102 if (!$error) {
103 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
104 } else {
105 setEventMessages($langs->trans("Error"), null, 'errors');
106 }
107}
108
109/*
110 * View
111 */
112
113$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
114llxHeader("", $langs->trans("BankSetupModule"), '', '', 0, 0, '', '', '', 'mod-admin page-chequereceipts');
115
116$form = new Form($db);
117
118$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
119print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
120
121$head = bank_admin_prepare_head(null);
122print dol_get_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), -1, 'account');
123
124/*
125 * Numbering module
126 */
127
128print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', '');
129
130print '<div class="div-table-responsive-no-min">';
131print '<table class="noborder centpercent">';
132print '<tr class="liste_titre">';
133print '<td>'.$langs->trans("Name").'</td>';
134print '<td>'.$langs->trans("Description").'</td>';
135print '<td class="nowrap">'.$langs->trans("Example").'</td>';
136print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
137print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
138print '</tr>'."\n";
139
140clearstatcache();
141
142foreach ($dirmodels as $reldir) {
143 $dir = dol_buildpath($reldir."core/modules/cheque/");
144 if (is_dir($dir)) {
145 $handle = opendir($dir);
146 if (is_resource($handle)) {
147 while (($file = readdir($handle)) !== false) {
148 if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
149 $filebis = $file;
150 $name = substr($file, 4, dol_strlen($file) - 16);
151 $classname = preg_replace('/\.php$/', '', $file);
152 // For compatibility
153 if (!is_file($dir.$filebis)) {
154 $filebis = $file."/".$file.".modules.php";
155 $classname = "mod_chequereceipt_".$file;
156 }
157 // Check if there is a filter on country
158 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
159 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
160 continue;
161 }
162
163 $classname = preg_replace('/\-.*$/', '', $classname);
164 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
165 // Charging the numbering class
166 require_once $dir.$filebis;
167
168 $module = new $classname($db);
169 '@phan-var-force ModeleNumRefChequeReceipts $module';
170
171 // Show modules according to features level
172 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
173 continue;
174 }
175 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
176 continue;
177 }
178
179 if ($module->isEnabled()) {
180 print '<tr class="oddeven"><td width="100">';
181 print(empty($module->name) ? $name : $module->name);
182 print "</td><td>\n";
183
184 print $module->info($langs);
185
186 print '</td>';
187
188 // Show example of numbering module
189 print '<td class="nowrap">';
190 $tmp = $module->getExample();
191 if (preg_match('/^Error/', $tmp)) {
192 $langs->load("errors");
193 print '<div class="error">'.$langs->trans($tmp).'</div>';
194 } elseif ($tmp == 'NotConfigured') {
195 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
196 } else {
197 print $tmp;
198 }
199 print '</td>'."\n";
200
201 print '<td class="center">';
202 if ($conf->global->CHEQUERECEIPTS_ADDON == $file || getDolGlobalString('CHEQUERECEIPTS_ADDON') . '.php' == $file) {
203 print img_picto($langs->trans("Activated"), 'switch_on');
204 } else {
205 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
206 }
207 print '</td>';
208
209 $chequereceipts = new RemiseCheque($db);
210 $chequereceipts->initAsSpecimen();
211
212 // Example
213 $htmltooltip = '';
214 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
215 $nextval = $module->getNextValue($mysoc, $chequereceipts);
216 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
217 $htmltooltip .= $langs->trans("NextValue").': ';
218 if ($nextval) {
219 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
220 $nextval = $langs->trans($nextval);
221 }
222 $htmltooltip .= $nextval.'<br>';
223 } else {
224 $htmltooltip .= $langs->trans($module->error).'<br>';
225 }
226 }
227
228 print '<td class="center">';
229 print $form->textwithpicto('', $htmltooltip, 1, 0);
230
231 if (getDolGlobalString('CHEQUERECEIPTS_ADDON').'.php' == $file) { // If module is the one used, we show existing errors
232 if (!empty($module->error)) {
233 dol_htmloutput_mesg($module->error, array(), 'error', 1);
234 }
235 }
236
237 print '</td>';
238
239 print "</tr>\n";
240 }
241 }
242 }
243 }
244 closedir($handle);
245 }
246 }
247}
248
249print '</table>';
250print '</div>';
251
252print '<br>';
253
254
255/*
256 * Other options
257 */
258print load_fiche_titre($langs->trans("OtherOptions"), '', '');
259
260print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
261print '<input type="hidden" name="token" value="'.newToken().'">';
262print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
263
264print '<table class="noborder centpercent">';
265print '<tr class="liste_titre">';
266print '<td>'.$langs->trans("Parameters").'</td>';
267print '<td class="center" width="60">&nbsp;</td>';
268print '<td width="80">&nbsp;</td>';
269print "</tr>\n";
270
271$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
272$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
273$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
274foreach ($substitutionarray as $key => $val) {
275 $htmltext .= $key.'<br>';
276}
277$htmltext .= '</i>';
278
279print '<tr class="oddeven"><td colspan="2">';
280print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
281$variablename = 'BANK_CHEQUERECEIPT_FREE_TEXT';
282if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
283 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
284} else {
285 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
286 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
287 print $doleditor->Create();
288}
289print '</td><td class="right">';
290print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
291print "</td></tr>\n";
292print '</table>';
293print "<br>";
294
295print '</table>'."\n";
296
297print dol_get_fiche_end();
298
299print '</form>';
300
301// End of page
302llxFooter();
303$db->close();
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).
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
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition bank.lib.php:171
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage cheque delivery receipts.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:765
$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.