export.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/accountancy/admin/export.php
  25. * \ingroup Advanced accountancy
  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. {
  37. accessforbidden();
  38. }
  39. $action = GETPOST('action', 'aZ09');
  40. // Parameters ACCOUNTING_EXPORT_*
  41. $main_option = array(
  42. 'ACCOUNTING_EXPORT_PREFIX_SPEC',
  43. );
  44. $configuration = AccountancyExport::getTypeConfig();
  45. $listparam = $configuration['param'];
  46. $listformat = $configuration['format'];
  47. $listcr = $configuration['cr'];
  48. $model_option = array (
  49. '1' => array(
  50. 'label' => 'ACCOUNTING_EXPORT_FORMAT',
  51. 'param' => $listformat,
  52. ),
  53. '2' => array(
  54. 'label' => 'ACCOUNTING_EXPORT_SEPARATORCSV',
  55. 'param' => '',
  56. ),
  57. '3' => array(
  58. 'label' => 'ACCOUNTING_EXPORT_ENDLINE',
  59. 'param' => $listcr,
  60. ),
  61. '4' => array(
  62. 'label' => 'ACCOUNTING_EXPORT_DATE',
  63. 'param' => '',
  64. ),
  65. );
  66. /*
  67. * Actions
  68. */
  69. if ($action == 'update') {
  70. $error = 0;
  71. $modelcsv = GETPOST('ACCOUNTING_EXPORT_MODELCSV', 'int');
  72. if (! empty($modelcsv)) {
  73. if (! dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) {
  74. $error ++;
  75. }
  76. //if ($modelcsv==AccountancyExport::$EXPORT_TYPE_QUADRATUS || $modelcsv==AccountancyExport::$EXPORT_TYPE_CIEL) {
  77. // dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', 'txt', 'chaine', 0, '', $conf->entity);
  78. //}
  79. } else {
  80. $error ++;
  81. }
  82. foreach ( $main_option as $constname ) {
  83. $constvalue = GETPOST($constname, 'alpha');
  84. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  85. $error ++;
  86. }
  87. }
  88. foreach ($listparam[$modelcsv] as $key => $value ) {
  89. $constante = $key;
  90. if (strpos($constante, 'ACCOUNTING')!==false) {
  91. $constvalue = GETPOST($key, 'alpha');
  92. if (! dolibarr_set_const($db, $constante, $constvalue, 'chaine', 0, '', $conf->entity)) {
  93. $error ++;
  94. }
  95. }
  96. }
  97. if (! $error) {
  98. // reload
  99. $configuration = AccountancyExport::getTypeConfig();
  100. $listparam = $configuration['param'];
  101. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  102. } else {
  103. setEventMessages($langs->trans("Error"), null, 'errors');
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. llxHeader();
  110. $form = new Form($db);
  111. // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  112. print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
  113. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  114. print 'jQuery(document).ready(function () {'."\n";
  115. print ' function initfields()'."\n";
  116. print ' {'."\n";
  117. foreach ($listparam as $key => $param) {
  118. print ' if (jQuery("#ACCOUNTING_EXPORT_MODELCSV").val()=="'.$key.'")'."\n";
  119. print ' {'."\n";
  120. print ' //console.log("'.$param['label'].'");'."\n";
  121. if (empty($param['ACCOUNTING_EXPORT_FORMAT'])) {
  122. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$conf->global->ACCOUNTING_EXPORT_FORMAT.'");'."\n";
  123. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").prop("disabled", true);'."\n";
  124. } else {
  125. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$param['ACCOUNTING_EXPORT_FORMAT'].'");'."\n";
  126. print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").removeAttr("disabled");'."\n";
  127. }
  128. if (empty($param['ACCOUNTING_EXPORT_SEPARATORCSV'])) {
  129. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("");'."\n";
  130. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").prop("disabled", true);'."\n";
  131. } else {
  132. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("'.$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV.'");'."\n";
  133. print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").removeAttr("disabled");'."\n";
  134. }
  135. if (empty($param['ACCOUNTING_EXPORT_ENDLINE'])) {
  136. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").prop("disabled", true);'."\n";
  137. } else {
  138. print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").removeAttr("disabled");'."\n";
  139. }
  140. if (empty($param['ACCOUNTING_EXPORT_DATE'])) {
  141. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("");'."\n";
  142. print ' jQuery("#ACCOUNTING_EXPORT_DATE").prop("disabled", true);'."\n";
  143. } else {
  144. print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("'.$conf->global->ACCOUNTING_EXPORT_DATE.'");'."\n";
  145. print ' jQuery("#ACCOUNTING_EXPORT_DATE").removeAttr("disabled");'."\n";
  146. }
  147. print ' }'."\n";
  148. }
  149. print ' }'."\n";
  150. print ' initfields();'."\n";
  151. print ' jQuery("#ACCOUNTING_EXPORT_MODELCSV").change(function() {'."\n";
  152. print ' initfields();'."\n";
  153. print ' });'."\n";
  154. print '})'."\n";
  155. print '</script>'."\n";
  156. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  157. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  158. print '<input type="hidden" name="action" value="update">';
  159. /*
  160. * Main Options
  161. */
  162. print '<table class="noborder" width="100%">';
  163. print '<tr class="liste_titre">';
  164. print '<td colspan="3">' . $langs->trans('Options') . '</td>';
  165. print "</tr>\n";
  166. $num = count($main_option);
  167. if ($num) {
  168. foreach ( $main_option as $key ) {
  169. print '<tr class="oddeven value">';
  170. // Param
  171. $label = $langs->trans($key);
  172. print '<td width="50%">' . $label . '</td>';
  173. // Value
  174. print '<td>';
  175. print '<input type="text" size="20" id="'.$key.'" name="' . $key . '" value="' . $conf->global->$key . '">';
  176. print '</td></tr>';
  177. }
  178. }
  179. print "</table>\n";
  180. print "<br>\n";
  181. /*
  182. * Export model
  183. */
  184. print '<table class="noborder" width="100%">';
  185. print '<tr class="liste_titre">';
  186. print '<td colspan="2">' . $langs->trans("Modelcsv") . '</td>';
  187. print '</tr>';
  188. print '<tr class="oddeven">';
  189. print '<td width="50%">' . $langs->trans("Selectmodelcsv") . '</td>';
  190. if (! $conf->use_javascript_ajax) {
  191. print '<td class="nowrap">';
  192. print $langs->trans("NotAvailableWhenAjaxDisabled");
  193. print "</td>";
  194. } else {
  195. print '<td>';
  196. $listmodelcsv = AccountancyExport::getType();
  197. print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0);
  198. print '</td>';
  199. }
  200. print "</td></tr>";
  201. print "</table>";
  202. print "<br>\n";
  203. /*
  204. * Parameters
  205. */
  206. $num2 = count($model_option);
  207. if ($num2) {
  208. print '<table class="noborder" width="100%">';
  209. print '<tr class="liste_titre">';
  210. print '<td colspan="3">' . $langs->trans('OtherOptions') . '</td>';
  211. print "</tr>\n";
  212. foreach ( $model_option as $key) {
  213. print '<tr class="oddeven value">';
  214. // Param
  215. $label = $key['label'];
  216. print '<td width="50%">' . $langs->trans($label) . '</td>';
  217. // Value
  218. print '<td>';
  219. if (is_array($key['param'])) {
  220. print $form->selectarray($label, $key['param'], $conf->global->$label, 0);
  221. } else {
  222. print '<input type="text" size="20" id="'. $label .'" name="' . $key['label'] . '" value="' . $conf->global->$label . '">';
  223. }
  224. print '</td></tr>';
  225. }
  226. print "</table>\n";
  227. }
  228. print '<div class="center"><input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans('Modify')) . '" name="button"></div>';
  229. print '</form>';
  230. // End of page
  231. llxFooter();
  232. $db->close();