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