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 22/** 23 * \file htdocs/admin/bank.php 24 * \ingroup bank 25 * \brief Page to setup the bank module 26 */ 27 28require '../main.inc.php'; 29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; 32require_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 37if (!$user->admin) 38 accessforbidden(); 39 40$action = GETPOST('action', 'aZ09'); 41$value = GETPOST('value', 'alpha'); 42 43 44if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php'; 45 46 47 48/* 49 * Actions 50 */ 51 52if ($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 68if ($action == 'setmod') 69{ 70 dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON", $value, 'chaine', 0, '', $conf->entity); 71} 72 73if ($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']); 94llxHeader("", $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>'; 99print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup'); 100 101$head = bank_admin_prepare_head(null); 102print dol_get_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), -1, 'account'); 103 104/* 105 * Numbering module 106 */ 107 108print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', ''); 109 110print '<table class="noborder centpercent">'; 111print '<tr class="liste_titre">'; 112print '<td>'.$langs->trans("Name").'</td>'; 113print '<td>'.$langs->trans("Description").'</td>'; 114print '<td class="nowrap">'.$langs->trans("Example").'</td>'; 115print '<td class="center" width="60">'.$langs->trans("Status").'</td>'; 116print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>'; 117print '</tr>'."\n"; 118 119clearstatcache(); 120 121foreach ($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 225print '</table>'; 226 227print '<br>'; 228 229 230/* 231 * Other options 232 */ 233print load_fiche_titre($langs->trans("OtherOptions"), '', ''); 234 235print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 236print '<input type="hidden" name="token" value="'.newToken().'">'; 237print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">'; 238 239print '<table class="noborder centpercent">'; 240print '<tr class="liste_titre">'; 241print '<td>'.$langs->trans("Parameters").'</td>'; 242print '<td class="center" width="60"> </td>'; 243print '<td width="80"> </td>'; 244print "</tr>\n"; 245 246$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2); 247$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation"); 248$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>'; 249foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>'; 250$htmltext .= '</i>'; 251 252print '<tr class="oddeven"><td colspan="2">'; 253print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>'; 254$variablename = 'BANK_CHEQUERECEIPT_FREE_TEXT'; 255if (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} 263print '</td><td class="right">'; 264print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; 265print "</td></tr>\n"; 266print '</table>'; 267print "<br>"; 268 269print '</table>'."\n"; 270 271print dol_get_fiche_end(); 272 273print '</form>'; 274 275// End of page 276llxFooter(); 277$db->close(); 278