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