chequereceipts.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. * \file htdocs/admin/bank.php
  22. * \ingroup bank
  23. * \brief Page to setup the bank module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  29. $langs->load("admin");
  30. $langs->load("companies");
  31. $langs->load("bills");
  32. $langs->load("other");
  33. $langs->load("banks");
  34. if (!$user->admin)
  35. accessforbidden();
  36. $action = GETPOST('action','alpha');
  37. $value = GETPOST('value','alpha');
  38. if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php';
  39. /*
  40. * Actions
  41. */
  42. if ($action == 'updateMask')
  43. {
  44. $maskconstchequereceipts=GETPOST('maskconstchequereceipts','alpha');
  45. $maskchequereceipts=GETPOST('maskchequereceipts','alpha');
  46. if ($maskconstchequereceipts) $res = dolibarr_set_const($db,$maskconstchequereceipts,$maskchequereceipts,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. if (! $error)
  49. {
  50. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  51. }
  52. else
  53. {
  54. setEventMessages($langs->trans("Error"), null, 'errors');
  55. }
  56. }
  57. if ($action == 'setmod')
  58. {
  59. dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON",$value,'chaine',0,'',$conf->entity);
  60. }
  61. if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT')
  62. {
  63. $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT'); // No alpha here, we want exact string
  64. $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  65. if (! $res > 0) $error++;
  66. if (! $error)
  67. {
  68. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  69. }
  70. else
  71. {
  72. setEventMessages($langs->trans("Error"), null, 'errors');
  73. }
  74. }
  75. /*
  76. * view
  77. */
  78. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  79. llxHeader("",$langs->trans("BankSetupModule"));
  80. $form=new Form($db);
  81. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  82. print load_fiche_titre($langs->trans("BankSetupModule"),$linkback,'title_setup');
  83. $head = bank_admin_prepare_head(null);
  84. dol_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), 0, 'account');
  85. /*
  86. * Numbering module
  87. */
  88. print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', '');
  89. print '<table class="noborder" width="100%">';
  90. print '<tr class="liste_titre">';
  91. print '<td>'.$langs->trans("Name").'</td>';
  92. print '<td>'.$langs->trans("Description").'</td>';
  93. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  94. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  95. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  96. print '</tr>'."\n";
  97. clearstatcache();
  98. foreach ($dirmodels as $reldir)
  99. {
  100. $dir = dol_buildpath($reldir."core/modules/cheque/");
  101. if (is_dir($dir))
  102. {
  103. $handle = opendir($dir);
  104. if (is_resource($handle))
  105. {
  106. $var=true;
  107. while (($file = readdir($handle))!==false)
  108. {
  109. if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
  110. {
  111. $filebis = $file;
  112. $name = substr($file, 4, dol_strlen($file) -16);
  113. $classname = preg_replace('/\.php$/','',$file);
  114. // For compatibility
  115. if (! is_file($dir.$filebis))
  116. {
  117. $filebis = $file."/".$file.".modules.php";
  118. $classname = "mod_chequereceipt_".$file;
  119. }
  120. // Check if there is a filter on country
  121. preg_match('/\-(.*)_(.*)$/',$classname,$reg);
  122. if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
  123. $classname = preg_replace('/\-.*$/','',$classname);
  124. if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
  125. {
  126. // Charging the numbering class
  127. require_once $dir.$filebis;
  128. $module = new $classname($db);
  129. // Show modules according to features level
  130. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  131. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  132. if ($module->isEnabled())
  133. {
  134. $var = !$var;
  135. print '<tr class="oddeven"><td width="100">';
  136. print (empty($module->name)?$name:$module->name);
  137. print "</td><td>\n";
  138. print $module->info();
  139. print '</td>';
  140. // Show example of numbering module
  141. print '<td class="nowrap">';
  142. $tmp=$module->getExample();
  143. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  144. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  145. else print $tmp;
  146. print '</td>'."\n";
  147. print '<td align="center">';
  148. if ($conf->global->CHEQUERECEIPTS_ADDON == $file || $conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file)
  149. {
  150. print img_picto($langs->trans("Activated"),'switch_on');
  151. }
  152. else
  153. {
  154. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scandir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  155. }
  156. print '</td>';
  157. $chequereceipts=new RemiseCheque($db);
  158. $chequereceipts->initAsSpecimen();
  159. // Example
  160. $htmltooltip='';
  161. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  162. $nextval=$module->getNextValue($mysoc,$chequereceipts);
  163. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  164. $htmltooltip.=$langs->trans("NextValue").': ';
  165. if ($nextval) {
  166. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  167. $nextval = $langs->trans($nextval);
  168. $htmltooltip.=$nextval.'<br>';
  169. } else {
  170. $htmltooltip.=$langs->trans($module->error).'<br>';
  171. }
  172. }
  173. print '<td align="center">';
  174. print $form->textwithpicto('',$htmltooltip,1,0);
  175. if ($conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file) // If module is the one used, we show existing errors
  176. {
  177. if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
  178. }
  179. print '</td>';
  180. print "</tr>\n";
  181. }
  182. }
  183. }
  184. }
  185. closedir($handle);
  186. }
  187. }
  188. }
  189. print '</table>';
  190. print '<br>';
  191. /*
  192. * Other options
  193. *
  194. */
  195. print load_fiche_titre($langs->trans("OtherOptions"),'','');
  196. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  197. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  198. print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
  199. print '<table class="noborder" width="100%">';
  200. print '<tr class="liste_titre">';
  201. print '<td>'.$langs->trans("Parameters").'</td>';
  202. print '<td align="center" width="60">&nbsp;</td>';
  203. print '<td width="80">&nbsp;</td>';
  204. print "</tr>\n";
  205. $var=true;
  206. $var=! $var;
  207. $substitutionarray=pdf_getSubstitutionArray($langs);
  208. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  209. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  210. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  211. $htmltext.='</i>';
  212. print '<tr class="oddeven"><td colspan="2">';
  213. print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
  214. $variablename='BANK_CHEQUERECEIPT_FREE_TEXT';
  215. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  216. {
  217. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  218. }
  219. else
  220. {
  221. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  222. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_details');
  223. print $doleditor->Create();
  224. }
  225. print '</td><td align="right">';
  226. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  227. print "</td></tr>\n";
  228. print '</table>';
  229. print "<br>";
  230. print '</table>'."\n";
  231. dol_fiche_end();
  232. print '</form>';
  233. llxFooter();
  234. $db->close();