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