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