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