chequereceipts.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 (!getDolGlobalString('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 '<div class="div-table-responsive-no-min">';
  89. print '<table class="noborder centpercent">';
  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 class="center" width="60">'.$langs->trans("Status").'</td>';
  95. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  96. print '</tr>'."\n";
  97. clearstatcache();
  98. foreach ($dirmodels as $reldir) {
  99. $dir = dol_buildpath($reldir."core/modules/cheque/");
  100. if (is_dir($dir)) {
  101. $handle = opendir($dir);
  102. if (is_resource($handle)) {
  103. while (($file = readdir($handle)) !== false) {
  104. if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
  105. $filebis = $file;
  106. $name = substr($file, 4, dol_strlen($file) - 16);
  107. $classname = preg_replace('/\.php$/', '', $file);
  108. // For compatibility
  109. if (!is_file($dir.$filebis)) {
  110. $filebis = $file."/".$file.".modules.php";
  111. $classname = "mod_chequereceipt_".$file;
  112. }
  113. // Check if there is a filter on country
  114. preg_match('/\-(.*)_(.*)$/', $classname, $reg);
  115. if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
  116. continue;
  117. }
  118. $classname = preg_replace('/\-.*$/', '', $classname);
  119. if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
  120. // Charging the numbering class
  121. require_once $dir.$filebis;
  122. $module = new $classname($db);
  123. // Show modules according to features level
  124. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  125. continue;
  126. }
  127. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  128. continue;
  129. }
  130. if ($module->isEnabled()) {
  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($langs);
  135. print '</td>';
  136. // Show example of numbering module
  137. print '<td class="nowrap">';
  138. $tmp = $module->getExample();
  139. if (preg_match('/^Error/', $tmp)) {
  140. $langs->load("errors");
  141. print '<div class="error">'.$langs->trans($tmp).'</div>';
  142. } elseif ($tmp == 'NotConfigured') {
  143. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  144. } else {
  145. print $tmp;
  146. }
  147. print '</td>'."\n";
  148. print '<td class="center">';
  149. if ($conf->global->CHEQUERECEIPTS_ADDON == $file || getDolGlobalString('CHEQUERECEIPTS_ADDON') . '.php' == $file) {
  150. print img_picto($langs->trans("Activated"), 'switch_on');
  151. } else {
  152. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  153. }
  154. print '</td>';
  155. $chequereceipts = new RemiseCheque($db);
  156. $chequereceipts->initAsSpecimen();
  157. // Example
  158. $htmltooltip = '';
  159. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  160. $nextval = $module->getNextValue($mysoc, $chequereceipts);
  161. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  162. $htmltooltip .= $langs->trans("NextValue").': ';
  163. if ($nextval) {
  164. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  165. $nextval = $langs->trans($nextval);
  166. }
  167. $htmltooltip .= $nextval.'<br>';
  168. } else {
  169. $htmltooltip .= $langs->trans($module->error).'<br>';
  170. }
  171. }
  172. print '<td class="center">';
  173. print $form->textwithpicto('', $htmltooltip, 1, 0);
  174. if (getDolGlobalString('CHEQUERECEIPTS_ADDON').'.php' == $file) { // If module is the one used, we show existing errors
  175. if (!empty($module->error)) {
  176. dol_htmloutput_mesg($module->error, '', 'error', 1);
  177. }
  178. }
  179. print '</td>';
  180. print "</tr>\n";
  181. }
  182. }
  183. }
  184. }
  185. closedir($handle);
  186. }
  187. }
  188. }
  189. print '</table>';
  190. print '</div>';
  191. print '<br>';
  192. /*
  193. * Other options
  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="'.newToken().'">';
  198. print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
  199. print '<table class="noborder centpercent">';
  200. print '<tr class="liste_titre">';
  201. print '<td>'.$langs->trans("Parameters").'</td>';
  202. print '<td class="center" width="60">&nbsp;</td>';
  203. print '<td width="80">&nbsp;</td>';
  204. print "</tr>\n";
  205. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  206. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  207. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  208. foreach ($substitutionarray as $key => $val) {
  209. $htmltext .= $key.'<br>';
  210. }
  211. $htmltext .= '</i>';
  212. print '<tr class="oddeven"><td colspan="2">';
  213. print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  214. $variablename = 'BANK_CHEQUERECEIPT_FREE_TEXT';
  215. if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
  216. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  217. } else {
  218. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  219. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  220. print $doleditor->Create();
  221. }
  222. print '</td><td class="right">';
  223. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  224. print "</td></tr>\n";
  225. print '</table>';
  226. print "<br>";
  227. print '</table>'."\n";
  228. print dol_get_fiche_end();
  229. print '</form>';
  230. // End of page
  231. llxFooter();
  232. $db->close();