chequereceipts.php 9.1 KB

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