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