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