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