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