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 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 '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')) { // Select 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 // Found a dependency on the field type
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 // Found a dependency on a specific 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, 1);
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 // loop over selected fields to retrieve the value
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 // Dataset to export
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> ";
696 if (isset($objexport->array_export_special[0][$code]['method'])) {
697 $htmltext .= $objexport->array_export_special[0][$code]['method'];
698 } elseif (!is_array($objexport->array_export_special[0][$code])) {
699 $htmltext .= $objexport->array_export_special[0][$code];
700 }
701 $htmltext .= "<br>";
702 } else {
703 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
704 }
705 if (!empty($objexport->array_export_examplevalues[0][$code])) {
706 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
707 }
708 if (!empty($objexport->array_export_TypeFields[0][$code])) {
709 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
710 }
711 if (!empty($objexport->array_export_help[0][$code])) {
712 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
713 }
714
715 if (isset($array_selected[$code]) && $array_selected[$code]) {
716 // Selected fields
717 print '<td>&nbsp;</td>';
718 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>';
719 print '<td>';
720 //print $text.'-'.$htmltext."<br>";
721 print $form->textwithpicto($text, $htmltext);
722 //print ' ('.$code.')';
723 print '</td>';
724 } else {
725 // Fields not selected
726 print '<td>';
727 //print $text.'-'.$htmltext."<br>";
728 print $form->textwithpicto($text, $htmltext);
729 //print ' ('.$code.')';
730 print '</td>';
731 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>';
732 print '<td>&nbsp;</td>';
733 }
734
735 print '</tr>';
736 }
737
738 print '</table>';
739 print '</div>';
740
741 /*
742 * Action bar
743 */
744 print '<div class="tabsAction tabsActionNoBottom">';
745
746 if (count($array_selected)) {
747 // If filters exist
748 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
749 print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
750 } else {
751 print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
752 }
753 } else {
754 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
755 }
756
757 print '</div>';
758}
759
760if ($step == 3 && $datatoexport) {
761 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
762 // Switch to step 2
763 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
764 exit;
765 }
766
767 // Check permission
768 if (empty($objexport->array_export_perms[0])) {
770 }
771
772 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step3');
773
774 $h = 0;
775
776 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
777 $head[$h][1] = $langs->trans("Step")." 1";
778 $h++;
779
780 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
781 $head[$h][1] = $langs->trans("Step")." 2";
782 $h++;
783
784 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
785 $head[$h][1] = $langs->trans("Step")." 3";
786 $hselected = (string) $h;
787 $h++;
788
789 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
790
791 print '<div class="fichecenter">';
792 print '<div class="underbanner clearboth"></div>';
793 print '<table class="border tableforfield centpercent">';
794
795 // Module
796 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
797 print '<td>';
798 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
799 print $objexport->array_export_module[0]->getName();
800 print '</td></tr>';
801
802 // Dataset to export
803 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
804 print '<td>';
805 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
806 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
807 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
808 print $objexport->array_export_label[0];
809 print '</td></tr>';
810
811 // List of exported fields
812 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
813 $list = '';
814 foreach ($array_selected as $code => $value) {
815 if (isset($objexport->array_export_fields[0][$code])) {
816 $list .= (!empty($list) ? ', ' : '');
817
818 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
819 if (!empty($tmplabelarray[1])) {
820 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
821 } else {
822 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
823 }
824 }
825 }
826 print '<td><span class="small">'.$list.'</span></td>';
827 print '</tr>';
828
829 print '</table>';
830 print '</div>';
831
832 print '<br><br>';
833
834 // Combo list of export models
835 print '<span class="opacitymedium">'.$langs->trans("SelectFilterFields").'...</span><br><br>';
836
837
838 // An extra form to get the filters
839 print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
840 print '<input type="hidden" name="token" value="'.newToken().'">';
841
842 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
843
844 print '<table class="noborder centpercent">';
845 print '<tr class="liste_titre">';
846 print '<td>'.$langs->trans("Entities").'</td>';
847 print '<td>'.$langs->trans("ExportableFields").'</td>';
848 print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
849 print '</tr>';
850
851 // Field we can export
852 $fieldsarray = $objexport->array_export_fields[0];
853 // Field that can be filtered
854 $Typefieldsarray = $objexport->array_export_TypeFields[0];
855 // Value of filters
856 $ValueFiltersarray = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
857 // Select request if all fields are selected
858 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
859
860 $i = 0;
861 // We loop on fields
862 foreach ($fieldsarray as $code => $label) {
863 print '<tr class="oddeven">';
864
865 $i++;
866 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
867 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
868 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
869
870 print '<td class="nowrap">';
871 // If value of entityicon=entitylang='icon:Label'
872 $tmparray = explode(':', $entityicon);
873 if (count($tmparray) >= 2) {
874 $entityicon = $tmparray[0];
875 $entitylang = $tmparray[1];
876 }
877 print img_object('', $entityicon).' '.$langs->trans((string) $entitylang);
878 print '</td>';
879
880 // Field name
881 $labelName = (!empty($fieldsarray[$code]) ? $fieldsarray[$code] : '');
882 $ValueFilter = (!empty($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
883
884 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>');
885 $tmplabelarray = explode(':', $label);
886 if (!empty($tmplabelarray[1])) {
887 $text .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
888 } else {
889 $text .= $langs->trans($label);
890 }
891 $text .= (empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
892
893 $tablename = getablenamefromfield($code, $sqlmaxforexport);
894 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
895 if (!empty($objexport->array_export_special[0][$code])) {
896 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ";
897 if (isset($objexport->array_export_special[0][$code]['method'])) {
898 $htmltext .= $objexport->array_export_special[0][$code]['method'];
899 } elseif (!is_array($objexport->array_export_special[0][$code])) {
900 $htmltext .= $objexport->array_export_special[0][$code];
901 }
902 $htmltext .= "<br>";
903 } else {
904 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
905 }
906 if (!empty($objexport->array_export_examplevalues[0][$code])) {
907 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
908 }
909 if (!empty($objexport->array_export_TypeFields[0][$code])) {
910 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
911 }
912 if (!empty($objexport->array_export_help[0][$code])) {
913 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
914 }
915
916 print '<td>';
917 print $form->textwithpicto($text, $htmltext);
918 print '</td>';
919
920 // Filter value
921 print '<td>';
922 if (!empty($Typefieldsarray[$code])) { // Example: Text, List:c_country:label:rowid, Number, Boolean
923 $szInfoFiltre = $objexport->genDocFilter($Typefieldsarray[$code]);
924 if ($szInfoFiltre) { // Is there an info help for this filter ?
925 $tmp = $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
926 print $form->textwithpicto($tmp, $szInfoFiltre);
927 } else {
928 print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
929 }
930 }
931 print '</td>';
932
933 print '</tr>';
934 }
935
936 print '</table>';
937 print '</div>';
938
939 print '</div>';
940
941 /*
942 * Action bar
943 */
944 print '<div class="tabsAction tabsActionNoBottom">';
945 // il n'est pas obligatoire de filtrer les champs
946 print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
947 print '</div>';
948}
949
950if ($step == 4 && $datatoexport) {
951 if (count($array_selected) < 1) { // This occurs when going back to page after sessecion expired
952 // Switch to step 2
953 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
954 exit;
955 }
956
957 // Check permission
958 if (empty($objexport->array_export_perms[0])) {
960 }
961
962 asort($array_selected);
963
964 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step4');
965
966 $stepoffset = 0;
967 $h = 0;
968
969 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
970 $head[$h][1] = $langs->trans("Step")." 1";
971 $h++;
972
973 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
974 $head[$h][1] = $langs->trans("Step")." 2";
975 $h++;
976
977 // If filters exist
978 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
979 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
980 $head[$h][1] = $langs->trans("Step")." 3";
981 $h++;
982 $stepoffset++;
983 }
984
985 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
986 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
987 $hselected = (string) $h;
988 $h++;
989
990 $titleofmodule = $objexport->array_export_module[0]->getName();
991
992 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
993
994 print '<div class="fichecenter">';
995 print '<div class="underbanner clearboth"></div>';
996 print '<table width="100%" class="border tableforfield">';
997
998 // Module
999 print '<tr><td class="titlefield tableforfield">'.$langs->trans("Module").'</td>';
1000 print '<td>';
1001 print dolPrintHTML($titleofmodule);
1002 print '</td></tr>';
1003
1004 // Dataset to export
1005 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1006 print '<td>';
1007 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1008 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1009 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
1010 print $objexport->array_export_label[0];
1011 print '</td></tr>';
1012
1013 // List of exported fields
1014 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1015 $list = '';
1016 foreach ($array_selected as $code => $value) {
1017 if (isset($objexport->array_export_fields[0][$code])) {
1018 $list .= (!empty($list) ? ', ' : '');
1019
1020 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
1021 if (!empty($tmplabelarray[1])) {
1022 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
1023 } else {
1024 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1025 }
1026 }
1027 }
1028 print '<td><span class="small">'.$list.'</span></td>';
1029 print '</tr>';
1030
1031 // List of filtered fields
1032 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1033 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1034 $list = '';
1035 if (!empty($array_filtervalue)) {
1036 foreach ($array_filtervalue as $code => $value) {
1037 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
1038 // We discard this filter if it is a FromSelect field with a value of -1.
1039 if ($value == -1) {
1040 continue;
1041 }
1042 }
1043 if (isset($objexport->array_export_fields[0][$code])) {
1044 $list .= ($list ? ', ' : '');
1045 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
1046 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1047 } else {
1048 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1049 }
1050 }
1051 }
1052 }
1053 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1054 print '</tr>';
1055 }
1056
1057 print '</table>';
1058 print '</div>';
1059
1060 print '<br>';
1061
1062 // Select request if all fields are selected
1063 $sqlmaxforexport = $objexport->build_sql(0, array(), array());
1064
1065 print '<br>';
1066 print '<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans("ChooseFieldsOrdersAndTitle").'</span></div>';
1067
1068 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
1069 print '<table class="noborder centpercent">';
1070 print '<tr class="liste_titre">';
1071 print '<td>'.$langs->trans("Entities").'</td>';
1072 print '<td>'.$langs->trans("ExportedFields").'</td>';
1073 print '<td class="right" colspan="2">'.$langs->trans("Position").'</td>';
1074 //print '<td>&nbsp;</td>';
1075 //print '<td>'.$langs->trans("FieldsTitle").'</td>';
1076 print '</tr>';
1077
1078 foreach ($array_selected as $code => $value) {
1079 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)
1080 continue;
1081 }
1082
1083 print '<tr class="oddeven">';
1084
1085 $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
1086 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1087 $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
1088
1089 print '<td class="nowrap">';
1090 // If value of entityicon=entitylang='icon:Label'
1091 $tmparray = explode(':', $entityicon);
1092 if (count($tmparray) >= 2) {
1093 $entityicon = $tmparray[0];
1094 $entitylang = $tmparray[1];
1095 }
1096 print img_object('', $entityicon).' '.$langs->trans((string) $entitylang);
1097 print '</td>';
1098
1099 $labelName = $objexport->array_export_fields[0][$code];
1100
1101 $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>');
1102 $tmplabelarray = explode(':', $labelName);
1103 if (!empty($tmplabelarray[1])) {
1104 $text .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
1105 } else {
1106 $text .= $langs->trans($labelName);
1107 }
1108 $text .= (empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
1109
1110 $tablename = getablenamefromfield($code, $sqlmaxforexport);
1111 $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
1112 if (!empty($objexport->array_export_special[0][$code])) {
1113 $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ";
1114 if (isset($objexport->array_export_special[0][$code]['method'])) {
1115 $htmltext .= $objexport->array_export_special[0][$code]['method'];
1116 } elseif (!is_array($objexport->array_export_special[0][$code])) {
1117 $htmltext .= $objexport->array_export_special[0][$code];
1118 }
1119 $htmltext .= "<br>";
1120 } else {
1121 $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
1122 }
1123 if (!empty($objexport->array_export_examplevalues[0][$code])) {
1124 $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
1125 }
1126 if (!empty($objexport->array_export_TypeFields[0][$code])) {
1127 $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
1128 }
1129 if (!empty($objexport->array_export_help[0][$code])) {
1130 $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
1131 }
1132
1133 print '<td>';
1134 print $form->textwithpicto($text, $htmltext);
1135 //print ' ('.$code.')';
1136 print '</td>';
1137
1138 print '<td class="right" width="100">';
1139 print $value.' ';
1140 print '</td><td class="center nowraponall" width="40">';
1141 if ($value < count($array_selected)) {
1142 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'" class="paddingleft paddingright">'.img_down().'</a>';
1143 }
1144 if ($value > 1) {
1145 print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'" class="paddingleft paddingright">'.img_up().'</a>';
1146 }
1147 print '</td>';
1148
1149 //print '<td>&nbsp;</td>';
1150 //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
1151
1152 print '</tr>';
1153 }
1154
1155 print '</table>';
1156 print '</div>';
1157
1158 print '</div>';
1159
1160 /*
1161 * Action bar
1162 */
1163 print '<div class="tabsAction">';
1164
1165 if (count($array_selected)) {
1166 print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
1167 }
1168
1169 print '</div>';
1170
1171
1172 // Area for profils export
1173 if (count($array_selected)) {
1174 print '<br>';
1175
1176 print '<div class="marginbottomonly">';
1177 print '<span class="opacitymedium">'.$langs->trans("SaveExportModel").'</span>';
1178 print '</div>';
1179
1180 print '<form class="nocellnopadd" action="export.php" method="post">';
1181 print '<input type="hidden" name="token" value="'.newToken().'">';
1182 print '<input type="hidden" name="action" value="add_export_model">';
1183 print '<input type="hidden" name="step" value="'.$step.'">';
1184 print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1185 print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1186 print '<input type="hidden" name="page_y" value="">';
1187
1188 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
1189 print '<table class="noborder centpercent">';
1190 print '<tr class="liste_titre">';
1191 print '<td>'.$langs->trans("ExportModelName").'</td>';
1192 print '<td>'.$langs->trans("Visibility").'</td>';
1193 print '<td></td>';
1194 print '</tr>';
1195
1196 $nameofexportprofile = str_replace(' ', '-', $langs->trans("ExportProfile").' '.$titleofmodule.' '.dol_print_date(dol_now('gmt'), 'dayxcard'));
1197 if (GETPOST('export_name')) { // If we have submitted a form, we take value used for the update try
1198 $nameofexportprofile = $export_name;
1199 }
1200
1201
1202 print '<tr class="oddeven">';
1203 print '<td><input name="export_name" class="minwidth300" value="'.$nameofexportprofile.'"></td>';
1204 print '<td>';
1205 $arrayvisibility = array('private' => $langs->trans("Private"), 'all' => $langs->trans("Everybody"));
1206 print $form->selectarray('visibility', $arrayvisibility, 'private');
1207 print '</td>';
1208 print '<td class="right">';
1209 print '<input type="submit" class="button reposition button-save smallpaddingimp" value="'.$langs->trans("Save").'">';
1210 print '</td></tr>';
1211
1212 $tmpuser = new User($db);
1213
1214 // List of existing export profils
1215 $sql = "SELECT rowid, label, fk_user, entity";
1216 $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
1217 $sql .= " WHERE type = '".$db->escape($datatoexport)."'";
1218 if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
1219 $sql .= " AND fk_user IN (0, ".((int) $user->id).")";
1220 }
1221 $sql .= " ORDER BY rowid";
1222 $resql = $db->query($sql);
1223 if ($resql) {
1224 $num = $db->num_rows($resql);
1225 $i = 0;
1226 while ($i < $num) {
1227 $obj = $db->fetch_object($resql);
1228
1229 print '<tr class="oddeven"><td>';
1230 print $obj->label;
1231 print '</td>';
1232 print '<td>';
1233 if (empty($obj->fk_user)) {
1234 print $langs->trans("Everybody");
1235 } else {
1236 $tmpuser->fetch($obj->fk_user);
1237 print $tmpuser->getNomUrl(-1);
1238 }
1239 print '</td>';
1240 print '<td class="right">';
1241 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&token='.newToken().'&id='.$obj->rowid.'">';
1242 print img_delete();
1243 print '</a>';
1244 print '</tr>';
1245 $i++;
1246 }
1247 } else {
1249 }
1250
1251 print '</table>';
1252 print '</div>';
1253
1254 print '</form>';
1255 }
1256}
1257
1258if ($step == 5 && $datatoexport) {
1259 if (count($array_selected) < 1) { // This occurs when going back to page after session expired
1260 // Switch to step 2
1261 header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1262 exit;
1263 }
1264
1265 // Check permission
1266 if (empty($objexport->array_export_perms[0])) {
1268 }
1269
1270 asort($array_selected);
1271
1272 llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones', '', 0, 0, '', '', '', 'mod-exports page-export action-step5');
1273
1274 $h = 0;
1275 $stepoffset = 0;
1276
1277 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1278 $head[$h][1] = $langs->trans("Step")." 1";
1279 $h++;
1280
1281 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
1282 $head[$h][1] = $langs->trans("Step")." 2";
1283 $h++;
1284
1285 // whether filtering is a parameter for the export or not
1286 if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1287 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1288 $head[$h][1] = $langs->trans("Step")." 3";
1289 $h++;
1290 $stepoffset++;
1291 }
1292
1293 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1294 $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
1295 $h++;
1296
1297 $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1298 $head[$h][1] = $langs->trans("Step")." ".(4 + $stepoffset);
1299 $hselected = (string) $h;
1300 $h++;
1301
1302 print dol_get_fiche_head($head, $hselected, 'Export', -2, 'download');
1303
1304 /*
1305 * Confirmation of deletion of file
1306 */
1307 if ($action == 'remove_file') {
1308 print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1309 }
1310
1311 print '<div class="fichecenter">';
1312 print '<div class="underbanner clearboth"></div>';
1313
1314 print '<table class="border tableforfield centpercent">';
1315
1316 // Module
1317 print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
1318 print '<td>';
1319 //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
1320 print $objexport->array_export_module[0]->getName();
1321 print '</td></tr>';
1322
1323 // Dataset to export
1324 print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1325 print '<td>';
1326 $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1327 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1328 print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
1329 print $objexport->array_export_label[0];
1330 print '</td></tr>';
1331
1332 // List of exported fields
1333 print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1334 $list = '';
1335 foreach ($array_selected as $code => $value) {
1336 if (isset($objexport->array_export_fields[0][$code])) {
1337 $list .= (!empty($list) ? ', ' : '');
1338
1339 $tmplabelarray = explode(':', $objexport->array_export_fields[0][$code]);
1340 if (!empty($tmplabelarray[1])) {
1341 $list .= $langs->trans($tmplabelarray[0]).' - '.$langs->trans($tmplabelarray[1]);
1342 } else {
1343 $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1344 }
1345 }
1346 }
1347 print '<td><span class="small">'.$list.'</span></td>';
1348 print '</tr>';
1349
1350 // List of filtered fields
1351 if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) {
1352 print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1353 $list = '';
1354 if (!empty($array_filtervalue)) {
1355 foreach ($array_filtervalue as $code => $value) {
1356 if (preg_match('/^FormSelect:/', $objexport->array_export_TypeFields[0][$code])) {
1357 // We discard this filter if it is a FromSelect field with a value of -1.
1358 if ($value == -1) {
1359 continue;
1360 }
1361 }
1362 if (isset($objexport->array_export_fields[0][$code])) {
1363 $list .= ($list ? ', ' : '');
1364 if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) {
1365 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code]).'</span>'.(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1366 } else {
1367 $list .= '<span class="opacitymedium">'.$langs->trans($objexport->array_export_fields[0][$code])."</span>='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1368 }
1369 }
1370 }
1371 }
1372 print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1373 print '</tr>';
1374 }
1375
1376 print '</table>';
1377 print '</div>';
1378
1379 print '<br>';
1380
1381 // List of available export formats
1382 $htmltabloflibs = '<!-- Table with available export formats --><br>';
1383 $htmltabloflibs .= '<table class="noborder centpercent nomarginbottom">';
1384 $htmltabloflibs .= '<tr class="liste_titre">';
1385 $htmltabloflibs .= '<td>'.$langs->trans("AvailableFormats").'</td>';
1386 $htmltabloflibs .= '<td>'.$langs->trans("LibraryUsed").'</td>';
1387 $htmltabloflibs .= '<td class="right">'.$langs->trans("LibraryVersion").'</td>';
1388 $htmltabloflibs .= '</tr>'."\n";
1389
1390 $liste = $objmodelexport->listOfAvailableExportFormat($db);
1391 $listeall = $liste;
1392 foreach ($listeall as $key => $val) {
1393 if (preg_match('/__\‍(Disabled\‍)__/', $listeall[$key])) {
1394 $listeall[$key] = preg_replace('/__\‍(Disabled\‍)__/', '('.$langs->transnoentitiesnoconv("Disabled").')', $listeall[$key]);
1395 unset($liste[$key]);
1396 }
1397
1398 $htmltabloflibs .= '<tr class="oddeven">';
1399 $htmltabloflibs .= '<td>'.img_picto_common($key, $objmodelexport->getPictoForKey($key)).' ';
1400 $text = $objmodelexport->getDriverDescForKey($key);
1401 $label = $listeall[$key];
1402 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1403 $htmltabloflibs .= $form->textwithpicto($label, $text).'</td>';
1404 $htmltabloflibs .= '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1405 $htmltabloflibs .= '<td class="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1406 $htmltabloflibs .= '</tr>'."\n";
1407 }
1408 $htmltabloflibs .= '</table><br>';
1409
1410 print '<br>';
1411 print '<div class="info"><span class="">'.$form->textwithpicto($langs->trans("NowClickToGenerateToBuildExportFile"), $htmltabloflibs, 1, 'help', '', 0, 2, 'helphonformat').'</span></div>';
1412 //print $htmltabloflibs;
1413
1414 print '</div>';
1415
1416
1417 if ($sqlusedforexport && $user->admin) {
1418 print info_admin($langs->trans("SQLUsedForExport").':<br><span class="small">'.$sqlusedforexport.'</span>', 0, 0, 'info', '', 'TechnicalInformation').'<br>';
1419 print '<br>';
1420 }
1421
1422
1423 if (!is_dir($conf->export->dir_temp)) {
1424 dol_mkdir($conf->export->dir_temp);
1425 }
1426
1427 // Show existing generated documents
1428 // NB: The function show_documents rescan all modules when genallowed=1, else we take $liste
1429 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', '', '', '');
1430}
1431
1432llxFooter();
1433
1434$db->close();
1435
1436exit; // 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
1437
1438
1446function getablenamefromfield($code, $sqlmaxforexport)
1447{
1448 $alias = preg_replace('/\.(.*)$/i', '', $code); // Keep only 'Alias' and remove '.Fieldname'
1449 $regexstring = '/([a-zA-Z_]+) as '.preg_quote($alias).'[, \‍)]/i';
1450
1451 $newsql = $sqlmaxforexport;
1452 $newsql = preg_replace('/^(.*) FROM /i', '', $newsql); // Remove part before the FROM
1453 $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
1454
1455 $reg = array();
1456 if (preg_match($regexstring, $newsql, $reg)) {
1457 return $reg[1]; // The tablename
1458 } else {
1459 return '';
1460 }
1461}
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:1446
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.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.
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.