dolibarr  7.0.0-beta
export.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 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 
29 require '../../main.inc.php';
30 
31 // Class
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
34 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php';
35 
36 $langs->load("compta");
37 $langs->load("bills");
38 $langs->load("admin");
39 $langs->load("accountancy");
40 
41 // Security access
42 if (empty($user->rights->accounting->chartofaccount))
43 {
45 }
46 
47 $action = GETPOST('action', 'alpha');
48 
49 // Parameters ACCOUNTING_EXPORT_*
50 $main_option = array (
51  'ACCOUNTING_EXPORT_PREFIX_SPEC',
52 );
53 
54 $configuration = AccountancyExport::getTypeConfig();
55 
56 $listparam = $configuration[param];
57 
58 $listformat = $configuration[format];
59 
60 $listcr = $configuration[cr];
61 
62 
63 $model_option = array (
64  '1' => array(
65  'label' => 'ACCOUNTING_EXPORT_FORMAT',
66  'param' => $listformat,
67  ),
68  '2' => array(
69  'label' => 'ACCOUNTING_EXPORT_SEPARATORCSV',
70  'param' => '',
71  ),
72  '3' => array(
73  'label' => 'ACCOUNTING_EXPORT_ENDLINE',
74  'param' => $listcr,
75  ),
76  '4' => array(
77  'label' => 'ACCOUNTING_EXPORT_DATE',
78  'param' => '',
79  ),
80 );
81 
82 /*
83  * Actions
84  */
85 if ($action == 'update') {
86  $error = 0;
87 
88  $modelcsv = GETPOST('ACCOUNTING_EXPORT_MODELCSV', 'int');
89 
90  if (! empty($modelcsv)) {
91  if (! dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) {
92  $error ++;
93  }
94  //if ($modelcsv==AccountancyExport::$EXPORT_TYPE_QUADRATUS || $modelcsv==AccountancyExport::$EXPORT_TYPE_CIEL) {
95  // dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', 'txt', 'chaine', 0, '', $conf->entity);
96  //}
97  } else {
98  $error ++;
99  }
100 
101  foreach ( $main_option as $constname ) {
102  $constvalue = GETPOST($constname, 'alpha');
103 
104  if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
105  $error ++;
106  }
107  }
108 
109  foreach ($listparam[$modelcsv] as $key => $value ) {
110  $constante = $key;
111 
112  if (strpos($constante, 'ACCOUNTING')!==false) {
113  $constvalue = GETPOST($key, 'alpha');
114  if (! dolibarr_set_const($db, $constante, $constvalue, 'chaine', 0, '', $conf->entity)) {
115  $error ++;
116  }
117  }
118  }
119 
120  if (! $error) {
121  // reload
122  $configuration = AccountancyExport::getTypeConfig();
123  $listparam = $configuration[param];
124  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
125  } else {
126  setEventMessages($langs->trans("Error"), null, 'errors');
127  }
128 }
129 
130 /*
131  * View
132  */
133 
134 llxHeader();
135 
136 $form = new Form($db);
137 
138 // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
139 print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
140 
141 print "\n".'<script type="text/javascript" language="javascript">'."\n";
142 print 'jQuery(document).ready(function () {'."\n";
143 print ' function initfields()'."\n";
144 print ' {'."\n";
145 foreach ($listparam as $key => $param) {
146  print ' if (jQuery("#ACCOUNTING_EXPORT_MODELCSV").val()=="'.$key.'")'."\n";
147  print ' {'."\n";
148  print ' //console.log("'.$param[label].'");'."\n";
149  if (empty($param[ACCOUNTING_EXPORT_FORMAT])) {
150  print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$conf->global->ACCOUNTING_EXPORT_FORMAT.'");'."\n";
151  print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").prop("disabled", true);'."\n";
152  } else {
153  print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").val("'.$param[ACCOUNTING_EXPORT_FORMAT].'");'."\n";
154  print ' jQuery("#ACCOUNTING_EXPORT_FORMAT").removeAttr("disabled");'."\n";
155  }
156  if (empty($param[ACCOUNTING_EXPORT_SEPARATORCSV])) {
157  print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("");'."\n";
158  print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").prop("disabled", true);'."\n";
159  } else {
160  print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").val("'.$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV.'");'."\n";
161  print ' jQuery("#ACCOUNTING_EXPORT_SEPARATORCSV").removeAttr("disabled");'."\n";
162  }
163  if (empty($param[ACCOUNTING_EXPORT_ENDLINE])) {
164  print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").prop("disabled", true);'."\n";
165  } else {
166  print ' jQuery("#ACCOUNTING_EXPORT_ENDLINE").removeAttr("disabled");'."\n";
167  }
168  if (empty($param[ACCOUNTING_EXPORT_DATE])) {
169  print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("");'."\n";
170  print ' jQuery("#ACCOUNTING_EXPORT_DATE").prop("disabled", true);'."\n";
171  } else {
172  print ' jQuery("#ACCOUNTING_EXPORT_DATE").val("'.$conf->global->ACCOUNTING_EXPORT_DATE.'");'."\n";
173  print ' jQuery("#ACCOUNTING_EXPORT_DATE").removeAttr("disabled");'."\n";
174  }
175  print ' }'."\n";
176 }
177 print ' }'."\n";
178 print ' initfields();'."\n";
179 print ' jQuery("#ACCOUNTING_EXPORT_MODELCSV").change(function() {'."\n";
180 print ' initfields();'."\n";
181 print ' });'."\n";
182 print '})'."\n";
183 print '</script>'."\n";
184 
185 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
186 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
187 print '<input type="hidden" name="action" value="update">';
188 
189 /*
190  * Main Options
191  */
192 
193 print '<table class="noborder" width="100%">';
194 print '<tr class="liste_titre">';
195 print '<td colspan="3">' . $langs->trans('Options') . '</td>';
196 print "</tr>\n";
197 
198 
199 $num = count($main_option);
200 if ($num) {
201  foreach ( $main_option as $key ) {
202 
203  print '<tr class="oddeven value">';
204 
205  // Param
206  $label = $langs->trans($key);
207  print '<td width="50%">' . $label . '</td>';
208 
209  // Value
210  print '<td>';
211  print '<input type="text" size="20" id="'.$key.'" name="' . $key . '" value="' . $conf->global->$key . '">';
212  print '</td></tr>';
213  }
214 }
215 
216 print "</table>\n";
217 
218 print "<br>\n";
219 
220 /*
221  * Export model
222  */
223 print '<table class="noborder" width="100%">';
224 
225 print '<tr class="liste_titre">';
226 print '<td colspan="2">' . $langs->trans("Modelcsv") . '</td>';
227 print '</tr>';
228 
229 
230 print '<tr class="oddeven">';
231 print '<td width="50%">' . $langs->trans("Selectmodelcsv") . '</td>';
232 if (! $conf->use_javascript_ajax) {
233  print '<td class="nowrap">';
234  print $langs->trans("NotAvailableWhenAjaxDisabled");
235  print "</td>";
236 } else {
237  print '<td>';
238  $listmodelcsv = AccountancyExport::getType();
239  print $form->selectarray("ACCOUNTING_EXPORT_MODELCSV", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0);
240 
241  print '</td>';
242 }
243 print "</td></tr>";
244 print "</table>";
245 
246 print "<br>\n";
247 
248 /*
249  * Parameters
250  */
251 
252 $num2 = count($model_option);
253 if ($num2) {
254  print '<table class="noborder" width="100%">';
255  print '<tr class="liste_titre">';
256  print '<td colspan="3">' . $langs->trans('OtherOptions') . '</td>';
257  print "</tr>\n";
258 
259  foreach ( $model_option as $key) {
260  print '<tr class="oddeven value">';
261 
262  // Param
263  $label = $key[label];
264  print '<td width="50%">' . $langs->trans($label) . '</td>';
265 
266  // Value
267  print '<td>';
268  if (is_array($key[param])) {
269  print $form->selectarray($label, $key[param], $conf->global->$label, 0);
270  } else {
271  print '<input type="text" size="20" id="'. $label .'" name="' . $key[label] . '" value="' . $conf->global->$label . '">';
272  }
273 
274  print '</td></tr>';
275  }
276 
277  print "</table>\n";
278 }
279 
280 print '<div class="center"><input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans('Modify')) . '" name="button"></div>';
281 
282 print '</form>';
283 
284 llxFooter();
285 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
static getTypeConfig()
Array with all export type available (key + label) and parameters for config.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
static getType()
Array with all export type available (key + label)
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91