export.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2017-2018 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/accountancy/admin/export.php
  25. * \ingroup Accountancy (Double entries)
  26. * \brief Setup page to configure accounting expert module
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("compta", "bills", "admin", "accountancy"));
  34. // Security access
  35. if (empty($user->rights->accounting->chartofaccount)) {
  36. accessforbidden();
  37. }
  38. $action = GETPOST('action', 'aZ09');
  39. // Parameters ACCOUNTING_EXPORT_*
  40. $main_option = array(
  41. 'ACCOUNTING_EXPORT_PREFIX_SPEC',
  42. );
  43. $configuration = AccountancyExport::getTypeConfig();
  44. $listparam = $configuration['param'];
  45. $listformat = $configuration['format'];
  46. $listcr = $configuration['cr'];
  47. $model_option = array(
  48. '1' => array(
  49. 'label' => 'ACCOUNTING_EXPORT_FORMAT',
  50. 'param' => $listformat,
  51. ),
  52. '2' => array(
  53. 'label' => 'ACCOUNTING_EXPORT_SEPARATORCSV',
  54. 'param' => '',
  55. ),
  56. '3' => array(
  57. 'label' => 'ACCOUNTING_EXPORT_ENDLINE',
  58. 'param' => $listcr,
  59. ),
  60. '4' => array(
  61. 'label' => 'ACCOUNTING_EXPORT_DATE',
  62. 'param' => '',
  63. ),
  64. );
  65. /*
  66. * Actions
  67. */
  68. if ($action == 'update') {
  69. $error = 0;
  70. $modelcsv = GETPOST('ACCOUNTING_EXPORT_MODELCSV', 'int');
  71. if (!empty($modelcsv)) {
  72. if (!dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) {
  73. $error++;
  74. }
  75. //if ($modelcsv==AccountancyExport::$EXPORT_TYPE_QUADRATUS || $modelcsv==AccountancyExport::$EXPORT_TYPE_CIEL) {
  76. // dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', 'txt', 'chaine', 0, '', $conf->entity);
  77. //}
  78. } else {
  79. $error++;
  80. }
  81. foreach ($main_option as $constname) {
  82. $constvalue = GETPOST($constname, 'alpha');
  83. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  84. $error++;
  85. }
  86. }
  87. foreach ($listparam[$modelcsv] as $key => $value) {
  88. $constante = $key;
  89. if (strpos($constante, 'ACCOUNTING') !== false) {
  90. $constvalue = GETPOST($key, 'alpha');
  91. if (!dolibarr_set_const($db, $constante, $constvalue, 'chaine', 0, '', $conf->entity)) {
  92. $error++;
  93. }
  94. }
  95. }
  96. if (!$error) {
  97. // reload
  98. $configuration = AccountancyExport::getTypeConfig();
  99. $listparam = $configuration['param'];
  100. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  101. } else {
  102. setEventMessages($langs->trans("Error"), null, 'errors');
  103. }
  104. }
  105. /*
  106. * View
  107. */
  108. $form = new Form($db);
  109. $title = $langs->trans('ExportOptions');
  110. llxHeader('', $title);
  111. $linkback = '';
  112. // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  113. print load_fiche_titre($langs->trans('ExportOptions'), $linkback, 'accountancy');
  114. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  115. print 'jQuery(document).ready(function () {'."\n";
  116. print ' function initfields()'."\n";
  117. print ' {'."\n";
  118. foreach ($listparam as $key => $param) {
  119. print ' if (jQuery("#ACCOUNTING_EXPORT_MODELCSV").val()=="'.$key.'")'."\n";
  120. print ' {'."\n";
  121. print ' //console.log("'.$param['label'].'");'."\n";
  122. if (empty($param['ACCOUNTING_EXPORT_FORMAT'])) {
  123. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$conf->global->ACCOUNTING_EXPORT_FORMAT.'");'."\n";
  124. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").prop("disabled", true);'."\n";
  125. } else {
  126. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$param['ACCOUNTING_EXPORT_FORMAT'].'");'."\n";
  127. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").removeAttr("disabled");'."\n";
  128. }
  129. if (empty($param['ACCOUNTING_EXPORT_SEPARATORCSV'])) {
  130. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("");'."\n";
  131. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").prop("disabled", true);'."\n";
  132. } else {
  133. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("'.$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV.'");'."\n";
  134. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").removeAttr("disabled");'."\n";
  135. }
  136. if (empty($param['ACCOUNTING_EXPORT_ENDLINE'])) {
  137. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").prop("disabled", true);'."\n";
  138. } else {
  139. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").removeAttr("disabled");'."\n";
  140. }
  141. if (empty($param['ACCOUNTING_EXPORT_DATE'])) {
  142. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("");'."\n";
  143. print ' jQuery("#ACCOUNTING_EXPORT_DATE").prop("disabled", true);'."\n";
  144. } else {
  145. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("'.$conf->global->ACCOUNTING_EXPORT_DATE.'");'."\n";
  146. print ' jQuery("#ACCOUNTING_EXPORT_DATE").removeAttr("disabled");'."\n";
  147. }
  148. print ' }'."\n";
  149. }
  150. print ' }'."\n";
  151. print ' initfields();'."\n";
  152. print ' jQuery("#ACCOUNTING_EXPORT_MODELCSV").change(function() {'."\n";
  153. print ' initfields();'."\n";
  154. print ' });'."\n";
  155. print '})'."\n";
  156. print '</script>'."\n";
  157. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  158. print '<input type="hidden" name="token" value="'.newToken().'">';
  159. print '<input type="hidden" name="action" value="update">';
  160. /*
  161. * Main Options
  162. */
  163. print '<table class="noborder centpercent">';
  164. print '<tr class="liste_titre">';
  165. print '<td colspan="3">'.$langs->trans('Options').'</td>';
  166. print "</tr>\n";
  167. $num = count($main_option);
  168. if ($num) {
  169. foreach ($main_option as $key) {
  170. print '<tr class="oddeven value">';
  171. // Param
  172. $label = $langs->trans($key);
  173. print '<td width="50%">'.$label.'</td>';
  174. // Value
  175. print '<td>';
  176. print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  177. print '</td></tr>';
  178. }
  179. }
  180. print "</table>\n";
  181. print "<br>\n";
  182. /*
  183. * Export model
  184. */
  185. print '<table class="noborder centpercent">';
  186. print '<tr class="liste_titre">';
  187. print '<td colspan="2">'.$langs->trans("Modelcsv").'</td>';
  188. print '</tr>';
  189. print '<tr class="oddeven">';
  190. print '<td width="50%">'.$langs->trans("Selectmodelcsv").'</td>';
  191. if (!$conf->use_javascript_ajax) {
  192. print '<td class="nowrap">';
  193. print $langs->trans("NotAvailableWhenAjaxDisabled");
  194. print "</td>";
  195. } else {
  196. print '<td>';
  197. $listmodelcsv = AccountancyExport::getType();
  198. print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  199. print '</td>';
  200. }
  201. print "</td></tr>";
  202. print "</table>";
  203. print "<br>\n";
  204. /*
  205. * Parameters
  206. */
  207. $num2 = count($model_option);
  208. if ($num2) {
  209. print '<table class="noborder centpercent">';
  210. print '<tr class="liste_titre">';
  211. print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
  212. print "</tr>\n";
  213. foreach ($model_option as $key) {
  214. print '<tr class="oddeven value">';
  215. // Param
  216. $label = $key['label'];
  217. print '<td width="50%">'.$langs->trans($label).'</td>';
  218. // Value
  219. print '<td>';
  220. if (is_array($key['param'])) {
  221. print $form->selectarray($label, $key['param'], $conf->global->$label, 0);
  222. } else {
  223. print '<input type="text" size="20" id="'.$label.'" name="'.$key['label'].'" value="'.$conf->global->$label.'">';
  224. }
  225. print '</td></tr>';
  226. }
  227. print "</table>\n";
  228. }
  229. print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Modify')).'" name="button"></div>';
  230. print '</form>';
  231. // End of page
  232. llxFooter();
  233. $db->close();