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