dolibarr 22.0.5
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';
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
45// Load translation files required by the page
46$langs->loadlangs(array('admin', 'exports', 'other', 'users', 'companies', 'projects', 'suppliers', 'products', 'bank', 'bills'));
47
48// Everybody should be able to go on this page
49//if (! $user->admin)
50// accessforbidden();
51
52// Map icons, array duplicated in import.php, was not synchronized, TODO put it somewhere only once
53$entitytoicon = array(
54 'invoice' => 'bill',
55 'invoice_line' => 'bill',
56 'order' => 'order',
57 'order_line' => 'order',
58 'propal' => 'propal',
59 'propal_line' => 'propal',
60 'intervention' => 'intervention',
61 'inter_line' => 'intervention',
62 'member' => 'user',
63 'member_type' => 'group',
64 'subscription' => 'payment',
65 'payment' => 'payment',
66 'tax' => 'generic',
67 'tax_type' => 'generic',
68 'other' => 'generic',
69 'account' => 'account',
70 'product' => 'product',
71 'virtualproduct' => 'product',
72 'subproduct' => 'product',
73 'product_supplier_ref' => 'product',
74 'stock' => 'stock',
75 'warehouse' => 'stock',
76 'batch' => 'stock',
77 'stockbatch' => 'stock',
78 'category' => 'category',
79 'securityevent' => 'generic',
80 'shipment' => 'sending',
81 'shipment_line' => 'sending',
82 'reception' => 'sending',
83 'reception_line' => 'sending',
84 'expensereport' => 'trip',
85 'expensereport_line' => 'trip',
86 'holiday' => 'holiday',
87 'contract_line' => 'contract',
88 'translation' => 'generic',
89 'bomm' => 'bom',
90 'bomline' => 'bom',
91 'conferenceorboothattendee' => 'contact',
92 'inventory_line' => 'inventory',
93 'mrp_line' => 'mrp'
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="nowrap">';
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> ";
670 if (isset($objexport->array_export_special[0][$code]['method'])) {
671 $htmltext .= $objexport->array_export_special[0][$code]['method'];
672 } elseif (!is_array($objexport->array_export_special[0][$code])) {
673 $htmltext .= $objexport->array_export_special[0][$code];
674 }
675 $htmltext .= "<br>";
676 } else {
677 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
678 }
679 if (!empty($objexport->array_export_examplevalues[0][$code])) {
680 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
681 }
682 if (!empty($objexport->array_export_TypeFields[0][$code])) {
683 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
684 }
685 if (!empty($objexport->array_export_help[0][$code])) {
686 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
687 }
688
689 if (isset($array_selected[$code]) && $array_selected[$code]) {
690 // Selected fields
691 print '<td>&nbsp;</td>';
692 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>';
693 print '<td>';
694 //print $text.'-'.$htmltext."<br>";
695 print $form->textwithpicto($text, $htmltext);
696 //print ' ('.$code.')';
697 print '</td>';
698 } else {
699 // Fields not selected
700 print '<td>';
701 //print $text.'-'.$htmltext."<br>";
702 print $form->textwithpicto($text, $htmltext);
703 //print ' ('.$code.')';
704 print '</td>';
705 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>';
706 print '<td>&nbsp;</td>';
707 }
708
709 print '</tr>';
710 }
711
712 print '</table>';
713 print '</div>';
714
715 /*
716 * Action bar
717 */
718 print '<div class="tabsAction tabsActionNoBottom">';
719
720 if (count($array_selected)) {
721 // If filters exist
722 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
723 print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
724 } else {
725 print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
726 }
727 } else {
728 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
729 }
730
731 print '</div>';
732}
733
734if ($step == 3 && $datatoexport) {
735 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
736 // Switch to step 2
737 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
738 exit;
739 }
740
741 // Check permission
742 if (empty($objexport->array_export_perms[0])) {
744 }
745
746 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step3');
747
748 $h = 0;
749
750 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
751 $head[$h][1] = $langs->trans("Step")." 1";
752 $h++;
753
754 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
755 $head[$h][1] = $langs->trans("Step")." 2";
756 $h++;
757
758 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
759 $head[$h][1] = $langs->trans("Step")." 3";
760 $hselected = (string) $h;
761 $h++;
762
763 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
764
765 print '<div class="fichecenter">';
766 print '<div class="underbanner clearboth"></div>';
767 print '<table class="border tableforfield centpercent">';
768
769 // Module
770 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
771 print '<td>';
772 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
773 print $objexport->array_export_module[0]->getName();
774 print '</td></tr>';
775
776 // Lot de donnees a exporter
777 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
778 print '<td>';
779 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
780 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
781 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
782 print $objexport->array_export_label[0];
783 print '</td></tr>';
784
785 // List of exported fields
786 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
787 $list = '';
788 foreach ($array_selected as $code => $value) {
789 if (isset($objexport->array_export_fields[0][$code])) {
790 $list .= (!empty($list) ? ', ' : '');
791
792 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
793 if (!empty($tmplabelarray[1])) {
794 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
795 } else {
796 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
797 }
798 }
799 }
800 print '<td>'.$list.'</td></tr>';
801
802 print '</table>';
803 print '</div>';
804
805 print '<br><br>';
806
807 // Combo list of export models
808 print '<span class="opacitymedium">'.$langs->trans("SelectFilterFields").'</span><br><br>';
809
810
811 // un formulaire en plus pour recuperer les filtres
812 print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
813 print '<input type="hidden" name="token" value="'.newToken().'">';
814
815 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
816
817 print '<table class="noborder centpercent">';
818 print '<tr class="liste_titre">';
819 print '<td>'.$langs->trans("Entities").'</td>';
820 //print '<td>'.$langs->trans("ExportableFields").'</td>';
821 //print '<td class="center"></td>';
822 print '<td>'.$langs->trans("ExportableFields").'</td>';
823 print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
824 print '</tr>';
825
826 // Champs exportables
827 $fieldsarray = $objexport->array_export_fields[0];
828 // Champs filtrable
829 $Typefieldsarray = $objexport->array_export_TypeFields[0];
830 // valeur des filtres
831 $ValueFiltersarray = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
832 // Select request if all fields are selected
833 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
834
835 $i = 0;
836 // on boucle sur les champs
837 foreach ($fieldsarray as $code => $label) {
838 print '<tr class="oddeven">';
839
840 $i++;
841 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
842 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
843 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
844
845 print '<td class="nowrap">';
846 // If value of entityicon=entitylang='icon:Label'
847 $tmparray = explode(':', $entityicon);
848 if (count($tmparray) >= 2) {
849 $entityicon = $tmparray[0];
850 $entitylang = $tmparray[1];
851 }
852 print img_object('', $entityicon).' '.$langs->trans((string) $entitylang);
853 print '</td>';
854
855 // Field name
856 $labelName = (!empty($fieldsarray[$code]) ? $fieldsarray[$code] : '');
857 $ValueFilter = (!empty($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
858
859 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>');
860 $tmplabelarray = explode(':', $label);
861 if (!empty($tmplabelarray[1])) {
862 $text .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
863 } else {
864 $text .= $langs->trans($label);
865 }
866 $text .= (empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
867
868 $tablename = getablenamefromfield($code, $sqlmaxforexport);
869 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
870 if (!empty($objexport->array_export_special[0][$code])) {
871 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ";
872 if (isset($objexport->array_export_special[0][$code]['method'])) {
873 $htmltext .= $objexport->array_export_special[0][$code]['method'];
874 } elseif (!is_array($objexport->array_export_special[0][$code])) {
875 $htmltext .= $objexport->array_export_special[0][$code];
876 }
877 $htmltext .= "<br>";
878 } else {
879 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
880 }
881 if (!empty($objexport->array_export_examplevalues[0][$code])) {
882 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
883 }
884 if (!empty($objexport->array_export_TypeFields[0][$code])) {
885 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
886 }
887 if (!empty($objexport->array_export_help[0][$code])) {
888 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
889 }
890
891 print '<td>';
892 print $form->textwithpicto($text, $htmltext);
893 print '</td>';
894
895 // Filter value
896 print '<td>';
897 if (!empty($Typefieldsarray[$code])) { // Example: Text, List:c_country:label:rowid, Number, Boolean
898 $szInfoFiltre = $objexport->genDocFilter($Typefieldsarray[$code]);
899 if ($szInfoFiltre) { // Is there an info help for this filter ?
900 $tmp = $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
901 print $form->textwithpicto($tmp, $szInfoFiltre);
902 } else {
903 print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
904 }
905 }
906 print '</td>';
907
908 print '</tr>';
909 }
910
911 print '</table>';
912 print '</div>';
913
914 print '</div>';
915
916 /*
917 * Action bar
918 */
919 print '<div class="tabsAction tabsActionNoBottom">';
920 // il n'est pas obligatoire de filtrer les champs
921 print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
922 print '</div>';
923}
924
925if ($step == 4 && $datatoexport) {
926 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
927 // Switch to step 2
928 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
929 exit;
930 }
931
932 // Check permission
933 if (empty($objexport->array_export_perms[0])) {
935 }
936
937 asort($array_selected);
938
939 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step4');
940
941 $stepoffset = 0;
942 $h = 0;
943
944 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
945 $head[$h][1] = $langs->trans("Step")." 1";
946 $h++;
947
948 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
949 $head[$h][1] = $langs->trans("Step")." 2";
950 $h++;
951
952 // If filters exist
953 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
954 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
955 $head[$h][1] = $langs->trans("Step")." 3";
956 $h++;
957 $stepoffset++;
958 }
959
960 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
961 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
962 $hselected = (string) $h;
963 $h++;
964
965 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
966
967 print '<div class="fichecenter">';
968 print '<div class="underbanner clearboth"></div>';
969 print '<table width="100%" class="border tableforfield">';
970
971 // Module
972 print '<tr><td class="titlefield tableforfield">'.$langs->trans("Module").'</td>';
973 print '<td>';
974 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
975 print $objexport->array_export_module[0]->getName();
976 print '</td></tr>';
977
978 // Lot de donnees a exporter
979 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
980 print '<td>';
981 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
982 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
983 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
984 print $objexport->array_export_label[0];
985 print '</td></tr>';
986
987 // List of exported fields
988 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
989 $list = '';
990 foreach ($array_selected as $code => $value) {
991 if (isset($objexport->array_export_fields[0][$code])) {
992 $list .= (!empty($list) ? ', ' : '');
993
994 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
995 if (!empty($tmplabelarray[1])) {
996 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
997 } else {
998 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
999 }
1000 }
1001 }
1002 print '<td>'.$list.'</td>';
1003 print '</tr>';
1004
1005 // List of filtered fields
1006 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1007 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1008 $list = '';
1009 if (!empty($array_filtervalue)) {
1010 foreach ($array_filtervalue as $code => $value) {
1011 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
1012 // We discard this filter if it is a FromSelect field with a value of -1.
1013 if ($value == -1) {
1014 continue;
1015 }
1016 }
1017 if (isset($objexport->array_export_fields[0][$code])) {
1018 $list .= ($list ? ', ' : '');
1019 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
1020 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1021 } else {
1022 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1023 }
1024 }
1025 }
1026 }
1027 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1028 print '</tr>';
1029 }
1030
1031 print '</table>';
1032 print '</div>';
1033
1034 print '<br>';
1035
1036 // Select request if all fields are selected
1037 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
1038
1039 print '<br>';
1040 print '<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans("ChooseFieldsOrdersAndTitle").'</span></div>';
1041
1042 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
1043 print '<table class="noborder centpercent">';
1044 print '<tr class="liste_titre">';
1045 print '<td>'.$langs->trans("Entities").'</td>';
1046 print '<td>'.$langs->trans("ExportedFields").'</td>';
1047 print '<td class="right" colspan="2">'.$langs->trans("Position").'</td>';
1048 //print '<td>&nbsp;</td>';
1049 //print '<td>'.$langs->trans("FieldsTitle").'</td>';
1050 print '</tr>';
1051
1052 foreach ($array_selected as $code => $value) {
1053 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)
1054 continue;
1055 }
1056
1057 print '<tr class="oddeven">';
1058
1059 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
1060 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1061 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
1062
1063 print '<td class="nowrap">';
1064 // If value of entityicon=entitylang='icon:Label'
1065 $tmparray = explode(':', $entityicon);
1066 if (count($tmparray) >= 2) {
1067 $entityicon = $tmparray[0];
1068 $entitylang = $tmparray[1];
1069 }
1070 print img_object('', $entityicon).' '.$langs->trans((string) $entitylang);
1071 print '</td>';
1072
1073 $labelName = $objexport->array_export_fields[0][$code];
1074
1075 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>');
1076 $tmplabelarray = explode(':', $labelName);
1077 if (!empty($tmplabelarray[1])) {
1078 $text .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
1079 } else {
1080 $text .= $langs->trans($labelName);
1081 }
1082 $text .= (empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
1083
1084 $tablename = getablenamefromfield($code, $sqlmaxforexport);
1085 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
1086 if (!empty($objexport->array_export_special[0][$code])) {
1087 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ";
1088 if (isset($objexport->array_export_special[0][$code]['method'])) {
1089 $htmltext .= $objexport->array_export_special[0][$code]['method'];
1090 } elseif (!is_array($objexport->array_export_special[0][$code])) {
1091 $htmltext .= $objexport->array_export_special[0][$code];
1092 }
1093 $htmltext .= "<br>";
1094 } else {
1095 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
1096 }
1097 if (!empty($objexport->array_export_examplevalues[0][$code])) {
1098 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
1099 }
1100 if (!empty($objexport->array_export_TypeFields[0][$code])) {
1101 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
1102 }
1103 if (!empty($objexport->array_export_help[0][$code])) {
1104 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
1105 }
1106
1107 print '<td>';
1108 print $form->textwithpicto($text, $htmltext);
1109 //print ' ('.$code.')';
1110 print '</td>';
1111
1112 print '<td class="right" width="100">';
1113 print $value.' ';
1114 print '</td><td class="center nowraponall" width="40">';
1115 if ($value < count($array_selected)) {
1116 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1117 }
1118 if ($value > 1) {
1119 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1120 }
1121 print '</td>';
1122
1123 //print '<td>&nbsp;</td>';
1124 //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
1125
1126 print '</tr>';
1127 }
1128
1129 print '</table>';
1130 print '</div>';
1131
1132 print '</div>';
1133
1134 /*
1135 * Action bar
1136 */
1137 print '<div class="tabsAction">';
1138
1139 if (count($array_selected)) {
1140 print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
1141 }
1142
1143 print '</div>';
1144
1145
1146 // Area for profils export
1147 if (count($array_selected)) {
1148 print '<br>';
1149
1150 print '<div class="marginbottomonly">';
1151 print '<span class="opacitymedium">'.$langs->trans("SaveExportModel").'</span>';
1152 print '</div>';
1153
1154 print '<form class="nocellnopadd" action="export.php" method="post">';
1155 print '<input type="hidden" name="token" value="'.newToken().'">';
1156 print '<input type="hidden" name="action" value="add_export_model">';
1157 print '<input type="hidden" name="step" value="'.$step.'">';
1158 print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1159 print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1160
1161 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
1162 print '<table class="noborder centpercent">';
1163 print '<tr class="liste_titre">';
1164 print '<td>'.$langs->trans("ExportModelName").'</td>';
1165 print '<td>'.$langs->trans("Visibility").'</td>';
1166 print '<td></td>';
1167 print '</tr>';
1168
1169 print '<tr class="oddeven">';
1170 print '<td><input name="export_name" value=""></td>';
1171 print '<td>';
1172 $arrayvisibility = array('private' => $langs->trans("Private"), 'all' => $langs->trans("Everybody"));
1173 print $form->selectarray('visibility', $arrayvisibility, 'private');
1174 print '</td>';
1175 print '<td class="right">';
1176 print '<input type="submit" class="button reposition button-save small" value="'.$langs->trans("Save").'">';
1177 print '</td></tr>';
1178
1179 $tmpuser = new User($db);
1180
1181 // List of existing export profils
1182 $sql = "SELECT rowid, label, fk_user, entity";
1183 $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
1184 $sql .= " WHERE type = '".$db->escape($datatoexport)."'";
1185 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
1186 $sql .= " AND fk_user IN (0, ".((int) $user->id).")";
1187 }
1188 $sql .= " ORDER BY rowid";
1189 $resql = $db->query($sql);
1190 if ($resql) {
1191 $num = $db->num_rows($resql);
1192 $i = 0;
1193 while ($i < $num) {
1194 $obj = $db->fetch_object($resql);
1195
1196 print '<tr class="oddeven"><td>';
1197 print $obj->label;
1198 print '</td>';
1199 print '<td>';
1200 if (empty($obj->fk_user)) {
1201 print $langs->trans("Everybody");
1202 } else {
1203 $tmpuser->fetch($obj->fk_user);
1204 print $tmpuser->getNomUrl(1);
1205 }
1206 print '</td>';
1207 print '<td class="right">';
1208 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&token='.newToken().'&id='.$obj->rowid.'">';
1209 print img_delete();
1210 print '</a>';
1211 print '</tr>';
1212 $i++;
1213 }
1214 } else {
1215 dol_print_error($db);
1216 }
1217
1218 print '</table>';
1219 print '</div>';
1220
1221 print '</form>';
1222 }
1223}
1224
1225if ($step == 5 && $datatoexport) {
1226 if (count($array_selected) < 1) { // This occurs when going back to page after session expired
1227 // Switch to step 2
1228 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1229 exit;
1230 }
1231
1232 // Check permission
1233 if (empty($objexport->array_export_perms[0])) {
1235 }
1236
1237 asort($array_selected);
1238
1239 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step5');
1240
1241 $h = 0;
1242 $stepoffset = 0;
1243
1244 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1245 $head[$h][1] = $langs->trans("Step")." 1";
1246 $h++;
1247
1248 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
1249 $head[$h][1] = $langs->trans("Step")." 2";
1250 $h++;
1251
1252 // si le filtrage est parameter pour l'export ou pas
1253 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1254 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1255 $head[$h][1] = $langs->trans("Step")." 3";
1256 $h++;
1257 $stepoffset++;
1258 }
1259
1260 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1261 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
1262 $h++;
1263
1264 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1265 $head[$h][1] = $langs->trans("Step")." ".(4 + $stepoffset);
1266 $hselected = (string) $h;
1267 $h++;
1268
1269 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
1270
1271 /*
1272 * Confirmation suppression fichier
1273 */
1274 if ($action == 'remove_file') {
1275 print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1276 }
1277
1278 print '<div class="fichecenter">';
1279 print '<div class="underbanner clearboth"></div>';
1280
1281 print '<table class="border tableforfield centpercent">';
1282
1283 // Module
1284 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
1285 print '<td>';
1286 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
1287 print $objexport->array_export_module[0]->getName();
1288 print '</td></tr>';
1289
1290 // Dataset to export
1291 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1292 print '<td>';
1293 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1294 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1295 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
1296 print $objexport->array_export_label[0];
1297 print '</td></tr>';
1298
1299 // List of exported fields
1300 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1301 $list = '';
1302 foreach ($array_selected as $code => $label) {
1303 if (isset($objexport->array_export_fields[0][$code])) {
1304 $list .= (!empty($list) ? ', ' : '');
1305
1306 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
1307 if (!empty($tmplabelarray[1])) {
1308 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
1309 } else {
1310 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1311 }
1312 }
1313 }
1314 print '<td>'.$list.'</td></tr>';
1315
1316 // List of filtered fields
1317 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1318 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1319 $list = '';
1320 if (!empty($array_filtervalue)) {
1321 foreach ($array_filtervalue as $code => $value) {
1322 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
1323 // We discard this filter if it is a FromSelect field with a value of -1.
1324 if ($value == -1) {
1325 continue;
1326 }
1327 }
1328 if (isset($objexport->array_export_fields[0][$code])) {
1329 $list .= ($list ? ', ' : '');
1330 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
1331 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1332 } else {
1333 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1334 }
1335 }
1336 }
1337 }
1338 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1339 print '</tr>';
1340 }
1341
1342 print '</table>';
1343 print '</div>';
1344
1345 print '<br>';
1346
1347 // List of available export formats
1348 $htmltabloflibs = '<!-- Table with available export formats --><br>';
1349 $htmltabloflibs .= '<table class="noborder centpercent nomarginbottom">';
1350 $htmltabloflibs .= '<tr class="liste_titre">';
1351 $htmltabloflibs .= '<td>'.$langs->trans("AvailableFormats").'</td>';
1352 $htmltabloflibs .= '<td>'.$langs->trans("LibraryUsed").'</td>';
1353 $htmltabloflibs .= '<td class="right">'.$langs->trans("LibraryVersion").'</td>';
1354 $htmltabloflibs .= '</tr>'."\n";
1355
1356 $liste = $objmodelexport->listOfAvailableExportFormat($db);
1357 $listeall = $liste;
1358 foreach ($listeall as $key => $val) {
1359 if (preg_match('/__\‍(Disabled\‍)__/', $listeall[$key])) {
1360 $listeall[$key] = preg_replace('/__\‍(Disabled\‍)__/', '('.$langs->transnoentitiesnoconv("Disabled").')', $listeall[$key]);
1361 unset($liste[$key]);
1362 }
1363
1364 $htmltabloflibs .= '<tr class="oddeven">';
1365 $htmltabloflibs .= '<td>'.img_picto_common($key, $objmodelexport->getPictoForKey($key)).' ';
1366 $text = $objmodelexport->getDriverDescForKey($key);
1367 $label = $listeall[$key];
1368 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1369 $htmltabloflibs .= $form->textwithpicto($label, $text).'</td>';
1370 $htmltabloflibs .= '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1371 $htmltabloflibs .= '<td class="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1372 $htmltabloflibs .= '</tr>'."\n";
1373 }
1374 $htmltabloflibs .= '</table><br>';
1375
1376 print '<br>';
1377 print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NowClickToGenerateToBuildExportFile"), $htmltabloflibs, 1, 'help', '', 0, 2, 'helphonformat').'</span>';
1378 //print $htmltabloflibs;
1379
1380 print '</div>';
1381
1382
1383 if ($sqlusedforexport && $user->admin) {
1384 print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport, 0, 0, '1', '', 'TechnicalInformation').'<br>';
1385 print '<br>';
1386 }
1387
1388
1389 if (!is_dir($conf->export->dir_temp)) {
1390 dol_mkdir($conf->export->dir_temp);
1391 }
1392
1393 // Show existing generated documents
1394 // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
1395 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', '', '', '');
1396}
1397
1398llxFooter();
1399
1400$db->close();
1401
1402exit; // 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
1403
1404
1412function getablenamefromfield($code, $sqlmaxforexport)
1413{
1414 $alias = preg_replace('/\.(.*)$/i', '', $code); // Keep only 'Alias' and remove '.Fieldname'
1415 $regexstring = '/([a-zA-Z_]+) as '.preg_quote($alias).'[, \‍)]/i';
1416
1417 $newsql = $sqlmaxforexport;
1418 $newsql = preg_replace('/^(.*) FROM /i', '', $newsql); // Remove part before the FROM
1419 $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
1420
1421 $reg = array();
1422 if (preg_match($regexstring, $newsql, $reg)) {
1423 return $reg[1]; // The tablename
1424 } else {
1425 return '';
1426 }
1427}
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:1412
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.