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