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