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