dolibarr  16.0.5
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
36 
37 if (!$user->admin) {
39 }
40 
41 $action = GETPOST('action', 'aZ09');
42 $value = GETPOST('value', 'alpha');
43 
44 
45 if (empty($conf->global->CHEQUERECEIPTS_ADDON)) {
46  $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php';
47 }
48 
49 
50 
51 /*
52  * Actions
53  */
54 
55 if ($action == 'updateMask') {
56  $maskconstchequereceipts = GETPOST('maskconstchequereceipts', 'alpha');
57  $maskchequereceipts = GETPOST('maskchequereceipts', 'alpha');
58  if ($maskconstchequereceipts) {
59  $res = dolibarr_set_const($db, $maskconstchequereceipts, $maskchequereceipts, 'chaine', 0, '', $conf->entity);
60  }
61 
62  if (!($res > 0)) {
63  $error++;
64  }
65 
66  if (!$error) {
67  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
68  } else {
69  setEventMessages($langs->trans("Error"), null, 'errors');
70  }
71 }
72 
73 if ($action == 'setmod') {
74  dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON", $value, 'chaine', 0, '', $conf->entity);
75 }
76 
77 if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT') {
78  $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
79 
80  $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
81 
82  if (!($res > 0)) {
83  $error++;
84  }
85 
86  if (!$error) {
87  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88  } else {
89  setEventMessages($langs->trans("Error"), null, 'errors');
90  }
91 }
92 
93 /*
94  * View
95  */
96 
97 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
98 llxHeader("", $langs->trans("BankSetupModule"));
99 
100 $form = new Form($db);
101 
102 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
103 print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
104 
105 $head = bank_admin_prepare_head(null);
106 print dol_get_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), -1, 'account');
107 
108 /*
109  * Numbering module
110  */
111 
112 print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', '');
113 
114 print '<table class="noborder centpercent">';
115 print '<tr class="liste_titre">';
116 print '<td>'.$langs->trans("Name").'</td>';
117 print '<td>'.$langs->trans("Description").'</td>';
118 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
119 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
120 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
121 print '</tr>'."\n";
122 
123 clearstatcache();
124 
125 foreach ($dirmodels as $reldir) {
126  $dir = dol_buildpath($reldir."core/modules/cheque/");
127  if (is_dir($dir)) {
128  $handle = opendir($dir);
129  if (is_resource($handle)) {
130  while (($file = readdir($handle)) !== false) {
131  if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
132  $filebis = $file;
133  $name = substr($file, 4, dol_strlen($file) - 16);
134  $classname = preg_replace('/\.php$/', '', $file);
135  // For compatibility
136  if (!is_file($dir.$filebis)) {
137  $filebis = $file."/".$file.".modules.php";
138  $classname = "mod_chequereceipt_".$file;
139  }
140  // Check if there is a filter on country
141  preg_match('/\-(.*)_(.*)$/', $classname, $reg);
142  if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
143  continue;
144  }
145 
146  $classname = preg_replace('/\-.*$/', '', $classname);
147  if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
148  // Charging the numbering class
149  require_once $dir.$filebis;
150 
151  $module = new $classname($db);
152 
153  // Show modules according to features level
154  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
155  continue;
156  }
157  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
158  continue;
159  }
160 
161  if ($module->isEnabled()) {
162  print '<tr class="oddeven"><td width="100">';
163  print (empty($module->name) ? $name : $module->name);
164  print "</td><td>\n";
165 
166  print $module->info();
167 
168  print '</td>';
169 
170  // Show example of numbering module
171  print '<td class="nowrap">';
172  $tmp = $module->getExample();
173  if (preg_match('/^Error/', $tmp)) {
174  $langs->load("errors");
175  print '<div class="error">'.$langs->trans($tmp).'</div>';
176  } elseif ($tmp == 'NotConfigured') {
177  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
178  } else {
179  print $tmp;
180  }
181  print '</td>'."\n";
182 
183  print '<td class="center">';
184  if ($conf->global->CHEQUERECEIPTS_ADDON == $file || $conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file) {
185  print img_picto($langs->trans("Activated"), 'switch_on');
186  } else {
187  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
188  }
189  print '</td>';
190 
191  $chequereceipts = new RemiseCheque($db);
192  $chequereceipts->initAsSpecimen();
193 
194  // Example
195  $htmltooltip = '';
196  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
197  $nextval = $module->getNextValue($mysoc, $chequereceipts);
198  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
199  $htmltooltip .= $langs->trans("NextValue").': ';
200  if ($nextval) {
201  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
202  $nextval = $langs->trans($nextval);
203  }
204  $htmltooltip .= $nextval.'<br>';
205  } else {
206  $htmltooltip .= $langs->trans($module->error).'<br>';
207  }
208  }
209 
210  print '<td class="center">';
211  print $form->textwithpicto('', $htmltooltip, 1, 0);
212 
213  if ($conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
214  if (!empty($module->error)) {
215  dol_htmloutput_mesg($module->error, '', 'error', 1);
216  }
217  }
218 
219  print '</td>';
220 
221  print "</tr>\n";
222  }
223  }
224  }
225  }
226  closedir($handle);
227  }
228  }
229 }
230 
231 print '</table>';
232 
233 print '<br>';
234 
235 
236 /*
237  * Other options
238  */
239 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
240 
241 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
242 print '<input type="hidden" name="token" value="'.newToken().'">';
243 print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
244 
245 print '<table class="noborder centpercent">';
246 print '<tr class="liste_titre">';
247 print '<td>'.$langs->trans("Parameters").'</td>';
248 print '<td class="center" width="60">&nbsp;</td>';
249 print '<td width="80">&nbsp;</td>';
250 print "</tr>\n";
251 
252 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
253 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
254 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
255 foreach ($substitutionarray as $key => $val) {
256  $htmltext .= $key.'<br>';
257 }
258 $htmltext .= '</i>';
259 
260 print '<tr class="oddeven"><td colspan="2">';
261 print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
262 $variablename = 'BANK_CHEQUERECEIPT_FREE_TEXT';
263 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
264  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
265 } else {
266  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
267  $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
268  print $doleditor->Create();
269 }
270 print '</td><td class="right">';
271 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
272 print "</td></tr>\n";
273 print '</table>';
274 print "<br>";
275 
276 print '</table>'."\n";
277 
278 print dol_get_fiche_end();
279 
280 print '</form>';
281 
282 // End of page
283 llxFooter();
284 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
bank_admin_prepare_head
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:132
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5190
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3866
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1808
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3733
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10864
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2004
dol_htmloutput_mesg
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
Definition: functions.lib.php:8285
dolibarr_set_const
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).
Definition: admin.lib.php:627
RemiseCheque
Class to manage cheque delivery receipts.
Definition: remisecheque.class.php:34
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:737
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8123
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30