chequereceipts.php 9.5 KB

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