chequereceipts.php 9.2 KB

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