dolibarr 18.0.6
export.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
5 * Copyright (C) 2012 Charles-Fr BENKE <charles.fr@benke.fr>
6 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28require_once '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31require_once DOL_DOCUMENT_ROOT.'/exports/class/export.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34
35// Load translation files required by the page
36$langs->loadlangs(array('admin', 'exports', 'other', 'users', 'companies', 'projects', 'suppliers', 'products', 'bank', 'bills'));
37
38// Everybody should be able to go on this page
39//if (! $user->admin)
40// accessforbidden();
41
42// Map icons, array duplicated in import.php, was not synchronized, TODO put it somewhere only once
43$entitytoicon = array(
44 'invoice' => 'bill',
45 'invoice_line' => 'bill',
46 'order' => 'order',
47 'order_line' => 'order',
48 'propal' => 'propal',
49 'propal_line' => 'propal',
50 'intervention' => 'intervention',
51 'inter_line' => 'intervention',
52 'member' => 'user',
53 'member_type' => 'group',
54 'subscription' => 'payment',
55 'payment' => 'payment',
56 'tax' => 'generic',
57 'tax_type' => 'generic',
58 'other' => 'generic',
59 'account' => 'account',
60 'product' => 'product',
61 'virtualproduct'=>'product',
62 'subproduct' => 'product',
63 'product_supplier_ref' => 'product',
64 'stock' => 'stock',
65 'warehouse' => 'stock',
66 'batch' => 'stock',
67 'stockbatch' => 'stock',
68 'category' => 'category',
69 'shipment' => 'sending',
70 'shipment_line'=> 'sending',
71 'reception'=> 'sending',
72 'reception_line'=> 'sending',
73 'expensereport'=> 'trip',
74 'expensereport_line'=> 'trip',
75 'holiday' => 'holiday',
76 'contract_line' => 'contract',
77 'translation' => 'generic',
78 'bomm' => 'bom',
79 'bomline' => 'bom',
80 'conferenceorboothattendee' => 'contact'
81);
82
83// Translation code, array duplicated in import.php, was not synchronized, TODO put it somewhere only once
84$entitytolang = array(
85 'user' => 'User',
86 'company' => 'Company',
87 'contact' => 'Contact',
88 'invoice' => 'Bill',
89 'invoice_line' => 'InvoiceLine',
90 'order' => 'Order',
91 'order_line' => 'OrderLine',
92 'propal' => 'Proposal',
93 'propal_line' => 'ProposalLine',
94 'intervention' => 'Intervention',
95 'inter_line' => 'InterLine',
96 'member' => 'Member',
97 'member_type' => 'MemberType',
98 'subscription' => 'Subscription',
99 'tax' => 'SocialContribution',
100 'tax_type' => 'DictionarySocialContributions',
101 'account' => 'BankTransactions',
102 'payment' => 'Payment',
103 'product' => 'Product',
104 'virtualproduct' => 'AssociatedProducts',
105 'subproduct' => 'SubProduct',
106 'product_supplier_ref' => 'SupplierPrices',
107 'service' => 'Service',
108 'stock' => 'Stock',
109 'movement' => 'StockMovement',
110 'batch' => 'Batch',
111 'stockbatch' => 'StockDetailPerBatch',
112 'warehouse' => 'Warehouse',
113 'category' => 'Category',
114 'other' => 'Other',
115 'trip' => 'TripsAndExpenses',
116 'shipment' => 'Shipments',
117 'shipment_line'=> 'ShipmentLine',
118 'project' => 'Projects',
119 'projecttask' => 'Tasks',
120 'task_time' => 'TaskTimeSpent',
121 'action' => 'Event',
122 'expensereport'=> 'ExpenseReport',
123 'expensereport_line'=> 'ExpenseReportLine',
124 'holiday' => 'TitreRequestCP',
125 'contract' => 'Contract',
126 'contract_line'=> 'ContractLine',
127 'translation' => 'Translation',
128 'bom' => 'BOM',
129 'bomline' => 'BOMLine',
130 'conferenceorboothattendee' => 'Attendee'
131);
132
133$array_selected = isset($_SESSION["export_selected_fields"]) ? $_SESSION["export_selected_fields"] : array();
134$array_filtervalue = isset($_SESSION["export_filtered_fields"]) ? $_SESSION["export_filtered_fields"] : array();
135$datatoexport = GETPOST("datatoexport", "aZ09");
136$action = GETPOST('action', 'aZ09');
137$confirm = GETPOST('confirm', 'alpha');
138$step = GETPOST("step", "int") ?GETPOST("step", "int") : 1;
139$export_name = GETPOST("export_name", "alphanohtml");
140$hexa = GETPOST("hexa", "alpha");
141$exportmodelid = GETPOST("exportmodelid", "int");
142$field = GETPOST("field", "alpa");
143
144$objexport = new Export($db);
145$objexport->load_arrays($user, $datatoexport);
146
147$objmodelexport = new ModeleExports($db);
148$form = new Form($db);
149$htmlother = new FormOther($db);
150$formfile = new FormFile($db);
151$sqlusedforexport = '';
152
153$head = array();
154$upload_dir = $conf->export->dir_temp.'/'.$user->id;
155
156$usefilters = 1;
157
158// Security check
159$result = restrictedArea($user, 'export');
160
161
162/*
163 * Actions
164 */
165
166if ($action == 'selectfield') { // Selection of field at step 2
167 $fieldsarray = $objexport->array_export_fields[0];
168 $fieldsentitiesarray = $objexport->array_export_entities[0];
169 $fieldsdependenciesarray = $objexport->array_export_dependencies[0];
170
171 if ($field == 'all') {
172 foreach ($fieldsarray as $key => $val) {
173 if (!empty($array_selected[$key])) {
174 continue; // If already selected, check next
175 }
176 $array_selected[$key] = count($array_selected) + 1;
177 //print_r($array_selected);
178 $_SESSION["export_selected_fields"] = $array_selected;
179 }
180 } else {
181 $warnings = array();
182
183 $array_selected[$field] = count($array_selected) + 1; // We tag the key $field as "selected"
184 // We check if there is a dependency to activate
185 /*var_dump($field);
186 var_dump($fieldsentitiesarray[$field]);
187 var_dump($fieldsdependenciesarray);*/
188 $listofdependencies = array();
189 if (!empty($fieldsentitiesarray[$field]) && !empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]])) {
190 // We found a dependency on the type of field
191 $tmp = $fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
192 if (is_array($tmp)) {
193 $listofdependencies = $tmp;
194 } else {
195 $listofdependencies = array($tmp);
196 }
197 } elseif (!empty($field) && !empty($fieldsdependenciesarray[$field])) {
198 // We found a dependency on a dedicated field
199 $tmp = $fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
200 if (is_array($tmp)) {
201 $listofdependencies = $tmp;
202 } else {
203 $listofdependencies = array($tmp);
204 }
205 }
206
207 if (count($listofdependencies)) {
208 foreach ($listofdependencies as $fieldid) {
209 if (empty($array_selected[$fieldid])) {
210 $array_selected[$fieldid] = count($array_selected) + 1; // We tag the key $fieldid as "selected"
211 $warnings[] = $langs->trans("ExportFieldAutomaticallyAdded", $langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
212 }
213 }
214 }
215 //print_r($array_selected);
216 $_SESSION["export_selected_fields"] = $array_selected;
217
218 setEventMessages($warnings, null, 'warnings');
219 }
220}
221if ($action == 'unselectfield') {
222 if ($_GET["field"] == 'all') {
223 $array_selected = array();
224 $_SESSION["export_selected_fields"] = $array_selected;
225 } else {
226 unset($array_selected[$_GET["field"]]);
227 // Renumber fields of array_selected (from 1 to nb_elements)
228 asort($array_selected);
229 $i = 0;
230 $array_selected_save = $array_selected;
231 foreach ($array_selected as $code => $value) {
232 $i++;
233 $array_selected[$code] = $i;
234 //print "x $code x $i y<br>";
235 }
236 $_SESSION["export_selected_fields"] = $array_selected;
237 }
238}
239
240if ($action == 'downfield' || $action == 'upfield') {
241 $pos = $array_selected[$_GET["field"]];
242 if ($action == 'downfield') {
243 $newpos = $pos + 1;
244 }
245 if ($action == 'upfield') {
246 $newpos = $pos - 1;
247 }
248 // Recherche code avec qui switcher
249 $newcode = "";
250 foreach ($array_selected as $code => $value) {
251 if ($value == $newpos) {
252 $newcode = $code;
253 break;
254 }
255 }
256 //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
257 if ($newcode) { // Si newcode trouve (protection contre resoumission de page)
258 $array_selected[$_GET["field"]] = $newpos;
259 $array_selected[$newcode] = $pos;
260 $_SESSION["export_selected_fields"] = $array_selected;
261 }
262}
263
264if ($step == 1 || $action == 'cleanselect') {
265 $_SESSION["export_selected_fields"] = array();
266 $_SESSION["export_filtered_fields"] = array();
267 $array_selected = array();
268 $array_filtervalue = array();
269}
270
271if ($action == 'builddoc') {
272 $max_execution_time_for_importexport = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
273 $max_time = @ini_get("max_execution_time");
274 if ($max_time && $max_time < $max_execution_time_for_importexport) {
275 dol_syslog("max_execution_time=".$max_time." is lower than max_execution_time_for_importexport=".$max_execution_time_for_importexport.". We try to increase it dynamically.");
276 @ini_set("max_execution_time", $max_execution_time_for_importexport); // This work only if safe mode is off. also web servers has timeout of 300
277 }
278
279 // Build export file
280 $result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue);
281 if ($result < 0) {
282 setEventMessages($objexport->error, $objexport->errors, 'errors');
283 $sqlusedforexport = $objexport->sqlusedforexport;
284 } else {
285 setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
286 $sqlusedforexport = $objexport->sqlusedforexport;
287 }
288}
289
290// Delete file
291if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes') {
292 $file = $upload_dir."/".GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
293
294 $ret = dol_delete_file($file);
295 if ($ret) {
296 setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
297 } else {
298 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
299 }
300 header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
301 exit;
302}
303
304if ($action == 'deleteprof') {
305 if (GETPOST("id", 'int')) {
306 $objexport->fetch(GETPOST('id', 'int'));
307 $result = $objexport->delete($user);
308 }
309}
310
311// TODO The export for filter is not yet implemented (old code created conflicts with step 2). We must use same way of working and same combo list of predefined export than step 2.
312if ($action == 'add_export_model') {
313 if ($export_name) {
314 asort($array_selected);
315
316 // Set save string
317 $hexa = '';
318 foreach ($array_selected as $key => $val) {
319 if ($hexa) {
320 $hexa .= ',';
321 }
322 $hexa .= $key;
323 }
324
325 $hexafiltervalue = '';
326 if (!empty($array_filtervalue) && is_array($array_filtervalue)) {
327 foreach ($array_filtervalue as $key => $val) {
328 if ($hexafiltervalue) {
329 $hexafiltervalue .= ',';
330 }
331 $hexafiltervalue .= $key.'='.$val;
332 }
333 }
334
335 $objexport->model_name = $export_name;
336 $objexport->datatoexport = $datatoexport;
337 $objexport->hexa = $hexa;
338 $objexport->hexafiltervalue = $hexafiltervalue;
339 $objexport->fk_user = (GETPOST('visibility', 'aZ09') == 'all' ? 0 : $user->id);
340
341 $result = $objexport->create($user);
342 if ($result >= 0) {
343 setEventMessages($langs->trans("ExportModelSaved", $objexport->model_name), null, 'mesgs');
344 } else {
345 $langs->load("errors");
346 if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
347 setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
348 } else {
349 setEventMessages($objexport->error, $objexport->errors, 'errors');
350 }
351 }
352 } else {
353 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
354 }
355}
356
357// Reload a predefined export model
358if ($step == 2 && $action == 'select_model') {
359 $_SESSION["export_selected_fields"] = array();
360 $_SESSION["export_filtered_fields"] = array();
361
362 $array_selected = array();
363 $array_filtervalue = array();
364
365 $result = $objexport->fetch($exportmodelid);
366 if ($result > 0) {
367 $fieldsarray = preg_split("/,(?! [^(]*\‍))/", $objexport->hexa);
368 $i = 1;
369 foreach ($fieldsarray as $val) {
370 $array_selected[$val] = $i;
371 $i++;
372 }
373 $_SESSION["export_selected_fields"] = $array_selected;
374
375 $fieldsarrayvalue = explode(',', $objexport->hexafiltervalue);
376 $i = 1;
377 foreach ($fieldsarrayvalue as $val) {
378 $tmp = explode('=', $val);
379 $array_filtervalue[$tmp[0]] = $tmp[1];
380 $i++;
381 }
382 $_SESSION["export_filtered_fields"] = $array_filtervalue;
383 }
384}
385
386// Get form with filters
387if ($step == 4 && $action == 'submitFormField') {
388 // on boucle sur les champs selectionne pour recuperer la valeur
389 if (is_array($objexport->array_export_TypeFields[0])) {
390 $_SESSION["export_filtered_fields"] = array();
391 foreach ($objexport->array_export_TypeFields[0] as $code => $type) { // $code: s.fieldname $value: Text|Boolean|List:ccc
392 $newcode = (string) preg_replace('/\./', '_', $code);
393 //print 'xxx '.$code."=".$newcode."=".$type."=".GETPOST($newcode)."\n<br>";
394 $check = 'alphanohtml';
395 $filterqualified = 1;
396 if (!GETPOSTISSET($newcode) || GETPOST($newcode, $check) == '') {
397 $filterqualified = 0;
398 } elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, $check)) && GETPOST($newcode, $check) <= 0)) {
399 $filterqualified = 0;
400 }
401 if ($filterqualified) {
402 //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
403 $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, $check);
404 }
405 }
406 $array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
407 $_SESSION["export_filtered_fields"] = $array_filtervalue;
408 }
409}
410
411
412/*
413 * View
414 */
415
416if ($step == 1 || !$datatoexport) {
417 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
418
419 $h = 0;
420
421 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
422 $head[$h][1] = $langs->trans("Step")." 1";
423 $hselected = $h;
424 $h++;
425
426 print dol_get_fiche_head($head, $hselected, '', -1);
427
428 print '<div class="opacitymedium">'.$langs->trans("SelectExportDataSet").'</div><br>';
429
430 // Affiche les modules d'exports
431 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
432 print '<table class="noborder centpercent">';
433 print '<tr class="liste_titre">';
434 print '<td>'.$langs->trans("Module").'</td>';
435 print '<td>'.$langs->trans("ExportableDatas").'</td>';
436 print '<td>&nbsp;</td>';
437 print '</tr>';
438
439 if (count($objexport->array_export_module)) {
440 asort($objexport->array_export_code_for_sort);
441 //var_dump($objexport->array_export_code_for_sort);
442 //$sortedarrayofmodules = dol_sort_array($objexport->array_export_module, 'module_position', 'asc', 0, 0, 1);
443 foreach ($objexport->array_export_code_for_sort as $key => $value) {
444 print '<tr class="oddeven"><td nospan="nospan">';
445 //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
446 print $objexport->array_export_module[$key]->getName();
447 print '</td><td>';
448 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[$key]);
449 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
450 $label = $objexport->array_export_label[$key];
451 //print $value.'-'.$icon.'-'.$label."<br>";
452 print img_object($objexport->array_export_module[$key]->getName(), $entityicon).' ';
453 print $label;
454 print '</td><td class="right">';
455 if ($objexport->array_export_perms[$key]) {
456 print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&module_position='.$objexport->array_export_module[$key]->module_position.'&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"), 'next', 'class="fa-15"').'</a>';
457 } else {
458 print '<span class="opacitymedium">'.$langs->trans("NotEnoughPermissions").'</span>';
459 }
460 print '</td></tr>';
461 }
462 } else {
463 print '<tr><td class="oddeven" colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
464 }
465 print '</table>';
466 print '</div>';
467
468 print '</div>';
469}
470
471if ($step == 2 && $datatoexport) {
472 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
473
474 $h = 0;
475
476 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
477 $head[$h][1] = $langs->trans("Step")." 1";
478 $h++;
479
480 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
481 $head[$h][1] = $langs->trans("Step")." 2";
482 $hselected = $h;
483 $h++;
484
485 print dol_get_fiche_head($head, $hselected, '', -2);
486
487 print '<div class="fichecenter">';
488 print '<div class="underbanner clearboth"></div>';
489
490 print '<table width="100%" class="border tableforfield">';
491
492 // Module
493 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
494 print '<td>';
495 print $objexport->array_export_module[0]->getName();
496 print '</td></tr>';
497
498 // Lot de donnees a exporter
499 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
500 print '<td>';
501 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
502 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
503 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
504 print $objexport->array_export_label[0];
505 print '</td></tr>';
506
507 print '</table>';
508 print '</div>';
509
510 print dol_get_fiche_end();
511
512 print '<br>';
513
514 // Combo list of export models
515 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
516 print '<input type="hidden" name="token" value="'.newToken().'">';
517 print '<input type="hidden" name="action" value="select_model">';
518 print '<input type="hidden" name="step" value="2">';
519 print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
520 print '<div class="valignmiddle marginbottomonly">';
521 print '<span class="opacitymedium">'.$langs->trans("SelectExportFields").'</span> ';
522 $htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1, $user->id);
523 print ' ';
524 print '<input type="submit" class="button small" value="'.$langs->trans("Select").'">';
525 print '</div>';
526 print '</form>';
527
528
529 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
530 print '<table class="noborder centpercent">';
531 print '<tr class="liste_titre">';
532 print '<td>'.$langs->trans("Object").'</td>';
533 print '<td>'.$langs->trans("ExportableFields").'</td>';
534 print '<td width="100" class="center">';
535 print '<a class="liste_titre commonlink" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
536 print ' / ';
537 print '<a class="liste_titre commonlink" title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>";
538 print '</td>';
539 print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
540 print '</tr>';
541
542 // Champs exportables
543 $fieldsarray = $objexport->array_export_fields[0];
544 // Select request if all fields are selected
545 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
546
547 // $this->array_export_module[0]=$module;
548 // $this->array_export_code[0]=$module->export_code[$r];
549 // $this->array_export_label[0]=$module->export_label[$r];
550 // $this->array_export_sql[0]=$module->export_sql[$r];
551 // $this->array_export_fields[0]=$module->export_fields_array[$r];
552 // $this->array_export_entities[0]=$module->export_fields_entities[$r];
553 // $this->array_export_alias[0]=$module->export_fields_alias[$r];
554
555 $i = 0;
556
557 foreach ($fieldsarray as $code => $label) {
558 print '<tr class="oddeven">';
559
560 $i++;
561
562 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
563 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
564 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
565
566 print '<td class="nowrap">';
567 // If value of entityicon=entitylang='icon:Label'
568 //print $code.'-'.$label.'-'.$entity;
569
570 $tmparray = explode(':', $entityicon);
571 if (count($tmparray) >= 2) {
572 $entityicon = $tmparray[0];
573 $entitylang = $tmparray[1];
574 }
575 print img_object('', $entityicon).' '.$langs->trans($entitylang);
576 print '</td>';
577
578 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
579
580 $tablename = getablenamefromfield($code, $sqlmaxforexport);
581 $htmltext = '<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
582 if (!empty($objexport->array_export_special[0][$code])) {
583 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
584 } else {
585 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
586 }
587 if (!empty($objexport->array_export_examplevalues[0][$code])) {
588 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
589 }
590 if (!empty($objexport->array_export_TypeFields[0][$code])) {
591 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
592 }
593 if (!empty($objexport->array_export_help[0][$code])) {
594 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
595 }
596
597 if (isset($array_selected[$code]) && $array_selected[$code]) {
598 // Selected fields
599 print '<td>&nbsp;</td>';
600 print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left('default', 0, 'style="max-width: 20px"').'</a></td>';
601 print '<td>';
602 //print $text.'-'.$htmltext."<br>";
603 print $form->textwithpicto($text, $htmltext);
604 //print ' ('.$code.')';
605 print '</td>';
606 } else {
607 // Fields not selected
608 print '<td>';
609 //print $text.'-'.$htmltext."<br>";
610 print $form->textwithpicto($text, $htmltext);
611 //print ' ('.$code.')';
612 print '</td>';
613 print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right('default', 0, 'style="max-width: 20px"').'</a></td>';
614 print '<td>&nbsp;</td>';
615 }
616
617 print '</tr>';
618 }
619
620 print '</table>';
621 print '</div>';
622
623 /*
624 * Action bar
625 */
626 print '<div class="tabsAction tabsActionNoBottom">';
627
628 if (count($array_selected)) {
629 // If filters exist
630 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
631 print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
632 } else {
633 print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
634 }
635 } else {
636 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
637 }
638
639 print '</div>';
640}
641
642if ($step == 3 && $datatoexport) {
643 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
644 // Switch to step 2
645 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
646 exit;
647 }
648
649 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
650
651 $h = 0;
652
653 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
654 $head[$h][1] = $langs->trans("Step")." 1";
655 $h++;
656
657 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
658 $head[$h][1] = $langs->trans("Step")." 2";
659 $h++;
660
661 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
662 $head[$h][1] = $langs->trans("Step")." 3";
663 $hselected = $h;
664 $h++;
665
666 print dol_get_fiche_head($head, $hselected, '', -2);
667
668 print '<div class="fichecenter">';
669 print '<div class="underbanner clearboth"></div>';
670 print '<table width="100%" class="border tableforfield">';
671
672 // Module
673 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
674 print '<td>';
675 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
676 print $objexport->array_export_module[0]->getName();
677 print '</td></tr>';
678
679 // Lot de donnees a exporter
680 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
681 print '<td>';
682 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
683 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
684 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
685 print $objexport->array_export_label[0];
686 print '</td></tr>';
687
688 // Nbre champs exportes
689 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
690 $list = '';
691 foreach ($array_selected as $code => $value) {
692 $list .= (!empty($list) ? ', ' : '');
693 $list .= (isset($objexport->array_export_fields[0][$code]) ? $langs->trans($objexport->array_export_fields[0][$code]) : '');
694 }
695 print '<td>'.$list.'</td></tr>';
696
697 print '</table>';
698 print '</div>';
699
700 print '<br>';
701
702 // Combo list of export models
703 print '<span class="opacitymedium">'.$langs->trans("SelectFilterFields").'</span><br><br>';
704
705
706 // un formulaire en plus pour recuperer les filtres
707 print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
708 print '<input type="hidden" name="token" value="'.newToken().'">';
709
710 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
711
712 print '<table class="noborder centpercent">';
713 print '<tr class="liste_titre">';
714 print '<td>'.$langs->trans("Entities").'</td>';
715 //print '<td>'.$langs->trans("ExportableFields").'</td>';
716 //print '<td class="center"></td>';
717 print '<td>'.$langs->trans("ExportableFields").'</td>';
718 print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
719 print '</tr>';
720
721 // Champs exportables
722 $fieldsarray = $objexport->array_export_fields[0];
723 // Champs filtrable
724 $Typefieldsarray = $objexport->array_export_TypeFields[0];
725 // valeur des filtres
726 $ValueFiltersarray = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
727 // Select request if all fields are selected
728 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
729
730 $i = 0;
731 // on boucle sur les champs
732 foreach ($fieldsarray as $code => $label) {
733 print '<tr class="oddeven">';
734
735 $i++;
736 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
737 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
738 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
739
740 print '<td class="nowrap">';
741 // If value of entityicon=entitylang='icon:Label'
742 $tmparray = explode(':', $entityicon);
743 if (count($tmparray) >= 2) {
744 $entityicon = $tmparray[0];
745 $entitylang = $tmparray[1];
746 }
747 print img_object('', $entityicon).' '.$langs->trans($entitylang);
748 print '</td>';
749
750 // Field name
751 $labelName = (!empty($fieldsarray[$code]) ? $fieldsarray[$code] : '');
752 $ValueFilter = (!empty($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
753 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
754
755 $tablename = getablenamefromfield($code, $sqlmaxforexport);
756 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
757 if (!empty($objexport->array_export_special[0][$code])) {
758 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
759 } else {
760 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
761 }
762 if (!empty($objexport->array_export_examplevalues[0][$code])) {
763 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
764 }
765 if (!empty($objexport->array_export_TypeFields[0][$code])) {
766 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
767 }
768 if (!empty($objexport->array_export_help[0][$code])) {
769 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
770 }
771
772 print '<td>';
773 print $form->textwithpicto($text, $htmltext);
774 print '</td>';
775
776 // Filter value
777 print '<td>';
778 if (!empty($Typefieldsarray[$code])) { // Example: Text, List:c_country:label:rowid, Number, Boolean
779 $szInfoFiltre = $objexport->genDocFilter($Typefieldsarray[$code]);
780 if ($szInfoFiltre) { // Is there an info help for this filter ?
781 $tmp = $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
782 print $form->textwithpicto($tmp, $szInfoFiltre);
783 } else {
784 print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
785 }
786 }
787 print '</td>';
788
789 print '</tr>';
790 }
791
792 print '</table>';
793 print '</div>';
794
795 print '</div>';
796
797 /*
798 * Action bar
799 */
800 print '<div class="tabsAction tabsActionNoBottom">';
801 // il n'est pas obligatoire de filtrer les champs
802 print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
803 print '</div>';
804}
805
806if ($step == 4 && $datatoexport) {
807 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
808 // Switch to step 2
809 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
810 exit;
811 }
812
813 asort($array_selected);
814
815 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
816
817 $stepoffset = 0;
818 $h = 0;
819
820 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
821 $head[$h][1] = $langs->trans("Step")." 1";
822 $h++;
823
824 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
825 $head[$h][1] = $langs->trans("Step")." 2";
826 $h++;
827
828 // If filters exist
829 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
830 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
831 $head[$h][1] = $langs->trans("Step")." 3";
832 $h++;
833 $stepoffset++;
834 }
835
836 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
837 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
838 $hselected = $h;
839 $h++;
840
841 print dol_get_fiche_head($head, $hselected, '', -2);
842
843 print '<div class="fichecenter">';
844 print '<div class="underbanner clearboth"></div>';
845 print '<table width="100%" class="border tableforfield">';
846
847 // Module
848 print '<tr><td class="titlefield tableforfield">'.$langs->trans("Module").'</td>';
849 print '<td>';
850 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
851 print $objexport->array_export_module[0]->getName();
852 print '</td></tr>';
853
854 // Lot de donnees a exporter
855 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
856 print '<td>';
857 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
858 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
859 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
860 print $objexport->array_export_label[0];
861 print '</td></tr>';
862
863 // List of exported fields
864 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
865 $list = '';
866 foreach ($array_selected as $code => $value) {
867 $list .= (!empty($list) ? ', ' : '');
868 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
869 }
870 print '<td>'.$list.'</td>';
871 print '</tr>';
872
873 // List of filtered fields
874 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
875 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
876 $list = '';
877 if (!empty($array_filtervalue)) {
878 foreach ($array_filtervalue as $code => $value) {
879 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
880 // We discard this filter if it is a FromSelect field with a value of -1.
881 if ($value == -1) {
882 continue;
883 }
884 }
885 if (isset($objexport->array_export_fields[0][$code])) {
886 $list .= ($list ? ', ' : '');
887 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
888 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
889 } else {
890 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
891 }
892 }
893 }
894 }
895 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
896 print '</tr>';
897 }
898
899 print '</table>';
900 print '</div>';
901
902 print '<br>';
903
904 // Select request if all fields are selected
905 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
906
907 print '<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans("ChooseFieldsOrdersAndTitle").'</span></div>';
908
909 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
910 print '<table class="noborder centpercent">';
911 print '<tr class="liste_titre">';
912 print '<td>'.$langs->trans("Entities").'</td>';
913 print '<td>'.$langs->trans("ExportedFields").'</td>';
914 print '<td class="right" colspan="2">'.$langs->trans("Position").'</td>';
915 //print '<td>&nbsp;</td>';
916 //print '<td>'.$langs->trans("FieldsTitle").'</td>';
917 print '</tr>';
918
919 foreach ($array_selected as $code => $value) {
920 print '<tr class="oddeven">';
921
922 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
923 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
924 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
925
926 print '<td class="nowrap">';
927 // If value of entityicon=entitylang='icon:Label'
928 $tmparray = explode(':', $entityicon);
929 if (count($tmparray) >= 2) {
930 $entityicon = $tmparray[0];
931 $entitylang = $tmparray[1];
932 }
933 print img_object('', $entityicon).' '.$langs->trans($entitylang);
934 print '</td>';
935
936 $labelName = $objexport->array_export_fields[0][$code];
937
938 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
939
940 $tablename = getablenamefromfield($code, $sqlmaxforexport);
941 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
942 if (!empty($objexport->array_export_special[0][$code])) {
943 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
944 } else {
945 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
946 }
947 if (!empty($objexport->array_export_examplevalues[0][$code])) {
948 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
949 }
950 if (!empty($objexport->array_export_TypeFields[0][$code])) {
951 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
952 }
953 if (!empty($objexport->array_export_help[0][$code])) {
954 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
955 }
956
957 print '<td>';
958 print $form->textwithpicto($text, $htmltext);
959 //print ' ('.$code.')';
960 print '</td>';
961
962 print '<td class="right" width="100">';
963 print $value.' ';
964 print '</td><td class="center nowraponall" width="40">';
965 if ($value < count($array_selected)) {
966 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
967 }
968 if ($value > 1) {
969 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
970 }
971 print '</td>';
972
973 //print '<td>&nbsp;</td>';
974 //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
975
976 print '</tr>';
977 }
978
979 print '</table>';
980 print '</div>';
981
982 print '</div>';
983
984 /*
985 * Action bar
986 */
987 print '<div class="tabsAction">';
988
989 if (count($array_selected)) {
990 print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
991 }
992
993 print '</div>';
994
995
996 // Area for profils export
997 if (count($array_selected)) {
998 print '<br>';
999
1000 print '<div class="marginbottomonly">';
1001 print '<span class="opacitymedium">'.$langs->trans("SaveExportModel").'</span>';
1002 print '</div>';
1003
1004 print '<form class="nocellnopadd" action="export.php" method="post">';
1005 print '<input type="hidden" name="token" value="'.newToken().'">';
1006 print '<input type="hidden" name="action" value="add_export_model">';
1007 print '<input type="hidden" name="step" value="'.$step.'">';
1008 print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1009 print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1010
1011 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1012 print '<table class="noborder centpercent">';
1013 print '<tr class="liste_titre">';
1014 print '<td>'.$langs->trans("ExportModelName").'</td>';
1015 print '<td>'.$langs->trans("Visibility").'</td>';
1016 print '<td></td>';
1017 print '</tr>';
1018
1019 print '<tr class="oddeven">';
1020 print '<td><input name="export_name" value=""></td>';
1021 print '<td>';
1022 $arrayvisibility = array('private'=>$langs->trans("Private"), 'all'=>$langs->trans("Everybody"));
1023 print $form->selectarray('visibility', $arrayvisibility, 'private');
1024 print '</td>';
1025 print '<td class="right">';
1026 print '<input type="submit" class="button reposition button-save small" value="'.$langs->trans("Save").'">';
1027 print '</td></tr>';
1028
1029 $tmpuser = new User($db);
1030
1031 // List of existing export profils
1032 $sql = "SELECT rowid, label, fk_user, entity";
1033 $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
1034 $sql .= " WHERE type = '".$db->escape($datatoexport)."'";
1035 if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
1036 $sql .= " AND fk_user IN (0, ".((int) $user->id).")";
1037 }
1038 $sql .= " ORDER BY rowid";
1039 $resql = $db->query($sql);
1040 if ($resql) {
1041 $num = $db->num_rows($resql);
1042 $i = 0;
1043 while ($i < $num) {
1044 $obj = $db->fetch_object($resql);
1045
1046 print '<tr class="oddeven"><td>';
1047 print $obj->label;
1048 print '</td>';
1049 print '<td>';
1050 if (empty($obj->fk_user)) {
1051 print $langs->trans("Everybody");
1052 } else {
1053 $tmpuser->fetch($obj->fk_user);
1054 print $tmpuser->getNomUrl(1);
1055 }
1056 print '</td>';
1057 print '<td class="right">';
1058 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&token='.newToken().'&id='.$obj->rowid.'">';
1059 print img_delete();
1060 print '</a>';
1061 print '</tr>';
1062 $i++;
1063 }
1064 } else {
1065 dol_print_error($db);
1066 }
1067
1068 print '</table>';
1069 print '</div>';
1070
1071 print '</form>';
1072 }
1073}
1074
1075if ($step == 5 && $datatoexport) {
1076 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
1077 // Switch to step 2
1078 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1079 exit;
1080 }
1081
1082 asort($array_selected);
1083
1084 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1085
1086 $h = 0;
1087 $stepoffset = 0;
1088
1089 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1090 $head[$h][1] = $langs->trans("Step")." 1";
1091 $h++;
1092
1093 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
1094 $head[$h][1] = $langs->trans("Step")." 2";
1095 $h++;
1096
1097 // si le filtrage est parametre pour l'export ou pas
1098 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1099 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1100 $head[$h][1] = $langs->trans("Step")." 3";
1101 $h++;
1102 $stepoffset++;
1103 }
1104
1105 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1106 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
1107 $h++;
1108
1109 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1110 $head[$h][1] = $langs->trans("Step")." ".(4 + $stepoffset);
1111 $hselected = $h;
1112 $h++;
1113
1114 print dol_get_fiche_head($head, $hselected, '', -2);
1115
1116 /*
1117 * Confirmation suppression fichier
1118 */
1119 if ($action == 'remove_file') {
1120 print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1121 }
1122
1123 print '<div class="fichecenter">';
1124 print '<div class="underbanner clearboth"></div>';
1125
1126 print '<table width="100%" class="border tableforfield">';
1127
1128 // Module
1129 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
1130 print '<td>';
1131 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
1132 print $objexport->array_export_module[0]->getName();
1133 print '</td></tr>';
1134
1135 // Dataset to export
1136 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1137 print '<td>';
1138 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1139 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1140 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
1141 print $objexport->array_export_label[0];
1142 print '</td></tr>';
1143
1144 // List of exported fields
1145 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1146 $list = '';
1147 foreach ($array_selected as $code => $label) {
1148 $list .= (!empty($list) ? ', ' : '');
1149 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1150 }
1151 print '<td>'.$list.'</td></tr>';
1152
1153 // List of filtered fields
1154 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1155 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1156 $list = '';
1157 if (!empty($array_filtervalue)) {
1158 foreach ($array_filtervalue as $code => $value) {
1159 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
1160 // We discard this filter if it is a FromSelect field with a value of -1.
1161 if ($value == -1) {
1162 continue;
1163 }
1164 }
1165 if (isset($objexport->array_export_fields[0][$code])) {
1166 $list .= ($list ? ', ' : '');
1167 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
1168 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1169 } else {
1170 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1171 }
1172 }
1173 }
1174 }
1175 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1176 print '</tr>';
1177 }
1178
1179 print '</table>';
1180 print '</div>';
1181
1182 print '<br>';
1183
1184 // List of available export formats
1185 $htmltabloflibs = '<!-- Table with available export formats --><br>';
1186 $htmltabloflibs .= '<table class="noborder centpercent nomarginbottom">';
1187 $htmltabloflibs .= '<tr class="liste_titre">';
1188 $htmltabloflibs .= '<td>'.$langs->trans("AvailableFormats").'</td>';
1189 $htmltabloflibs .= '<td>'.$langs->trans("LibraryUsed").'</td>';
1190 $htmltabloflibs .= '<td class="right">'.$langs->trans("LibraryVersion").'</td>';
1191 $htmltabloflibs .= '</tr>'."\n";
1192
1193 $liste = $objmodelexport->listOfAvailableExportFormat($db);
1194 $listeall = $liste;
1195 foreach ($listeall as $key => $val) {
1196 if (preg_match('/__\‍(Disabled\‍)__/', $listeall[$key])) {
1197 $listeall[$key] = preg_replace('/__\‍(Disabled\‍)__/', '('.$langs->transnoentitiesnoconv("Disabled").')', $listeall[$key]);
1198 unset($liste[$key]);
1199 }
1200
1201 $htmltabloflibs .= '<tr class="oddeven">';
1202 $htmltabloflibs .= '<td>'.img_picto_common($key, $objmodelexport->getPictoForKey($key)).' ';
1203 $text = $objmodelexport->getDriverDescForKey($key);
1204 $label = $listeall[$key];
1205 $htmltabloflibs .= $form->textwithpicto($label, $text).'</td>';
1206 $htmltabloflibs .= '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1207 $htmltabloflibs .= '<td class="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1208 $htmltabloflibs .= '</tr>'."\n";
1209 }
1210 $htmltabloflibs .= '</table><br>';
1211
1212 print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NowClickToGenerateToBuildExportFile"), $htmltabloflibs, 1, 'help', '', 0, 2, 'helphonformat').'</span>';
1213 //print $htmltabloflibs;
1214 print '<br>';
1215
1216 print '</div>';
1217
1218
1219 if ($sqlusedforexport && $user->admin) {
1220 print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport, 0, 0, 1, '', 'TechnicalInformation');
1221 }
1222
1223
1224 if (!is_dir($conf->export->dir_temp)) {
1225 dol_mkdir($conf->export->dir_temp);
1226 }
1227
1228 // Show existing generated documents
1229 // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
1230 print $formfile->showdocuments('export', '', $upload_dir, $_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport, $liste, 1, (GETPOST('model') ? GETPOST('model') : 'csv'), 1, 1, 0, 0, 0, '', 'none', '', '', '');
1231}
1232
1233llxFooter();
1234
1235$db->close();
1236
1237exit; // don't know why but apache hangs with php 5.3.10-1ubuntu3.12 and apache 2.2.2 if i remove this exit or replace with return
1238
1239
1247function getablenamefromfield($code, $sqlmaxforexport)
1248{
1249 $alias = preg_replace('/\.(.*)$/i', '', $code); // Keep only 'Alias' and remove '.Fieldname'
1250 $regexstring = '/([a-zA-Z_]+) as '.preg_quote($alias).'[, \‍)]/i';
1251
1252 $newsql = $sqlmaxforexport;
1253 $newsql = preg_replace('/^(.*) FROM /i', '', $newsql); // Remove part before the FROM
1254 $newsql = preg_replace('/WHERE (.*)$/i', '', $newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
1255
1256 if (preg_match($regexstring, $newsql, $reg)) {
1257 return $reg[1]; // The tablename
1258 } else {
1259 return '';
1260 }
1261}
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage exports.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Parent class for export modules.
Class to manage Dolibarr users.
getablenamefromfield($code, $sqlmaxforexport)
Return table name of an alias.
Definition export.php:1247
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
img_right($titlealt='default', $selected=0, $moreatt='')
Show right arrow logo.
img_left($titlealt='default', $selected=0, $moreatt='')
Show left arrow logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.