dolibarr  13.0.2
export.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
5  * Copyright (C) 2012 Charles-Fr BENKE <charles.fr@benke.fr>
6  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
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=($conf->global->MAIN_FEATURES_LEVEL > 1);
155 $usefilters = 1;
156 
157 
158 /*
159  * Actions
160  */
161 
162 if ($action == 'selectfield') // Selection of field at step 2
163 {
164  $fieldsarray = $objexport->array_export_fields[0];
165  $fieldsentitiesarray = $objexport->array_export_entities[0];
166  $fieldsdependenciesarray = $objexport->array_export_dependencies[0];
167 
168  if ($field == 'all')
169  {
170  foreach ($fieldsarray as $key=>$val)
171  {
172  if (!empty($array_selected[$key])) continue; // If already selected, check next
173  $array_selected[$key] = count($array_selected) + 1;
174  //print_r($array_selected);
175  $_SESSION["export_selected_fields"] = $array_selected;
176  }
177  } else {
178  $warnings = array();
179 
180  $array_selected[$field] = count($array_selected) + 1; // We tag the key $field as "selected"
181  // We check if there is a dependency to activate
182  /*var_dump($field);
183  var_dump($fieldsentitiesarray[$field]);
184  var_dump($fieldsdependenciesarray);*/
185  $listofdependencies = array();
186  if (!empty($fieldsentitiesarray[$field]) && !empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]]))
187  {
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)) $listofdependencies = $tmp;
191  else $listofdependencies = array($tmp);
192  } elseif (!empty($field) && !empty($fieldsdependenciesarray[$field]))
193  {
194  // We found a dependency on a dedicated field
195  $tmp = $fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
196  if (is_array($tmp)) $listofdependencies = $tmp;
197  else $listofdependencies = array($tmp);
198  }
199 
200  if (count($listofdependencies))
201  {
202  foreach ($listofdependencies as $fieldid)
203  {
204  if (empty($array_selected[$fieldid]))
205  {
206  $array_selected[$fieldid] = count($array_selected) + 1; // We tag the key $fieldid as "selected"
207  $warnings[] = $langs->trans("ExportFieldAutomaticallyAdded", $langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
208  }
209  }
210  }
211  //print_r($array_selected);
212  $_SESSION["export_selected_fields"] = $array_selected;
213 
214  setEventMessages($warnings, null, 'warnings');
215  }
216 }
217 if ($action == 'unselectfield')
218 {
219  if ($_GET["field"] == 'all')
220  {
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  {
231  $i++;
232  $array_selected[$code] = $i;
233  //print "x $code x $i y<br>";
234  }
235  $_SESSION["export_selected_fields"] = $array_selected;
236  }
237 }
238 
239 if ($action == 'downfield' || $action == 'upfield')
240 {
241  $pos = $array_selected[$_GET["field"]];
242  if ($action == 'downfield') $newpos = $pos + 1;
243  if ($action == 'upfield') $newpos = $pos - 1;
244  // Recherche code avec qui switcher
245  $newcode = "";
246  foreach ($array_selected as $code=>$value)
247  {
248  if ($value == $newpos)
249  {
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  {
257  $array_selected[$_GET["field"]] = $newpos;
258  $array_selected[$newcode] = $pos;
259  $_SESSION["export_selected_fields"] = $array_selected;
260  }
261 }
262 
263 if ($step == 1 || $action == 'cleanselect')
264 {
265  $_SESSION["export_selected_fields"] = array();
266  $_SESSION["export_filtered_fields"] = array();
267  $array_selected = array();
268  $array_filtervalue = array();
269 }
270 
271 if ($action == 'builddoc')
272 {
273  $max_execution_time_for_importexport = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
274  $max_time = @ini_get("max_execution_time");
275  if ($max_time && $max_time < $max_execution_time_for_importexport)
276  {
277  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.");
278  @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
279  }
280 
281  // Build export file
282  $result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue);
283  if ($result < 0)
284  {
285  setEventMessages($objexport->error, $objexport->errors, 'errors');
286  $sqlusedforexport = $objexport->sqlusedforexport;
287  } else {
288  setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
289  $sqlusedforexport = $objexport->sqlusedforexport;
290  }
291 }
292 
293 // Delete file
294 if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes')
295 {
296  $file = $upload_dir."/".GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
297 
298  $ret = dol_delete_file($file);
299  if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
300  else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
301  header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
302  exit;
303 }
304 
305 if ($action == 'deleteprof')
306 {
307  if (GETPOST("id", 'int'))
308  {
309  $objexport->fetch(GETPOST('id', 'int'));
310  $result = $objexport->delete($user);
311  }
312 }
313 
314 // 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.
315 if ($action == 'add_export_model')
316 {
317  if ($export_name)
318  {
319  asort($array_selected);
320 
321  // Set save string
322  $hexa = '';
323  foreach ($array_selected as $key=>$val)
324  {
325  if ($hexa) $hexa .= ',';
326  $hexa .= $key;
327  }
328 
329  $hexafiltervalue = '';
330  if (!empty($array_filtervalue) && is_array($array_filtervalue))
331  {
332  foreach ($array_filtervalue as $key=>$val)
333  {
334  if ($hexafiltervalue) $hexafiltervalue .= ',';
335  $hexafiltervalue .= $key.'='.$val;
336  }
337  }
338 
339  $objexport->model_name = $export_name;
340  $objexport->datatoexport = $datatoexport;
341  $objexport->hexa = $hexa;
342  $objexport->hexafiltervalue = $hexafiltervalue;
343 
344  $result = $objexport->create($user);
345  if ($result >= 0)
346  {
347  setEventMessages($langs->trans("ExportModelSaved", $objexport->model_name), null, 'mesgs');
348  } else {
349  $langs->load("errors");
350  if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
351  setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
352  else setEventMessages($objexport->error, $objexport->errors, 'errors');
353  }
354  } else {
355  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
356  }
357 }
358 
359 // Reload a predefined export model
360 if ($step == 2 && $action == 'select_model')
361 {
362  $_SESSION["export_selected_fields"] = array();
363  $_SESSION["export_filtered_fields"] = array();
364 
365  $array_selected = array();
366  $array_filtervalue = array();
367 
368  $result = $objexport->fetch($exportmodelid);
369  if ($result > 0)
370  {
371  $fieldsarray = preg_split("/,(?! [^(]*\))/", $objexport->hexa);
372  $i = 1;
373  foreach ($fieldsarray as $val)
374  {
375  $array_selected[$val] = $i;
376  $i++;
377  }
378  $_SESSION["export_selected_fields"] = $array_selected;
379 
380  $fieldsarrayvalue = explode(',', $objexport->hexafiltervalue);
381  $i = 1;
382  foreach ($fieldsarrayvalue as $val)
383  {
384  $tmp = explode('=', $val);
385  $array_filtervalue[$tmp[0]] = $tmp[1];
386  $i++;
387  }
388  $_SESSION["export_filtered_fields"] = $array_filtervalue;
389  }
390 }
391 
392 // Get form with filters
393 if ($step == 4 && $action == 'submitFormField')
394 {
395  // on boucle sur les champs selectionne pour recuperer la valeur
396  if (is_array($objexport->array_export_TypeFields[0]))
397  {
398  $_SESSION["export_filtered_fields"] = array();
399  foreach ($objexport->array_export_TypeFields[0] as $code => $type) // $code: s.fieldname $value: Text|Boolean|List:ccc
400  {
401  $newcode = (string) preg_replace('/\./', '_', $code);
402  //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
403  $filterqualified = 1;
404  if (!GETPOSTISSET($newcode) || GETPOST($newcode, 'restricthtml') == '') $filterqualified = 0;
405  elseif (preg_match('/^List/', $type) && (is_numeric(GETPOST($newcode, 'restricthtml')) && GETPOST($newcode, 'restricthtml') <= 0)) $filterqualified = 0;
406  if ($filterqualified)
407  {
408  //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
409  $objexport->array_export_FilterValue[0][$code] = GETPOST($newcode, 'restricthtml');
410  }
411  }
412  $array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
413  $_SESSION["export_filtered_fields"] = $array_filtervalue;
414  }
415 }
416 
417 
418 /*
419  * View
420  */
421 
422 if ($step == 1 || !$datatoexport)
423 {
424  llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
425 
426  $h = 0;
427 
428  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
429  $head[$h][1] = $langs->trans("Step")." 1";
430  $hselected = $h;
431  $h++;
432 
433  print dol_get_fiche_head($head, $hselected, '', -1);
434 
435  print '<div class="opacitymedium">'.$langs->trans("SelectExportDataSet").'</div><br>';
436 
437  // Affiche les modules d'exports
438  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
439  print '<table class="noborder centpercent">';
440  print '<tr class="liste_titre">';
441  print '<td>'.$langs->trans("Module").'</td>';
442  print '<td>'.$langs->trans("ExportableDatas").'</td>';
443  print '<td>&nbsp;</td>';
444  print '</tr>';
445 
446  if (count($objexport->array_export_module))
447  {
448  asort($objexport->array_export_code_for_sort);
449  //var_dump($objexport->array_export_code_for_sort);
450  //$sortedarrayofmodules = dol_sort_array($objexport->array_export_module, 'module_position', 'asc', 0, 0, 1);
451  foreach ($objexport->array_export_code_for_sort as $key => $value)
452  {
453  print '<tr class="oddeven"><td nospan="nospan">';
454  //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
455  print $objexport->array_export_module[$key]->getName();
456  print '</td><td>';
457  $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[$key]);
458  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
459  $label = $objexport->array_export_label[$key];
460  //print $value.'-'.$icon.'-'.$label."<br>";
461  print img_object($objexport->array_export_module[$key]->getName(), $entityicon).' ';
462  print $label;
463  print '</td><td class="right">';
464  if ($objexport->array_export_perms[$key]) {
465  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-15x"').'</a>';
466  } else {
467  print $langs->trans("NotEnoughPermissions");
468  }
469  print '</td></tr>';
470  }
471  } else {
472  print '<tr><td class="oddeven" colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
473  }
474  print '</table>';
475  print '</div>';
476 
477  print '</div>';
478 }
479 
480 if ($step == 2 && $datatoexport)
481 {
482  llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
483 
484  $h = 0;
485 
486  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
487  $head[$h][1] = $langs->trans("Step")." 1";
488  $h++;
489 
490  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
491  $head[$h][1] = $langs->trans("Step")." 2";
492  $hselected = $h;
493  $h++;
494 
495  print dol_get_fiche_head($head, $hselected, '', -2);
496 
497  print '<div class="fichecenter">';
498  print '<div class="underbanner clearboth"></div>';
499 
500  print '<table width="100%" class="border tableforfield">';
501 
502  // Module
503  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
504  print '<td>';
505  print $objexport->array_export_module[0]->getName();
506  print '</td></tr>';
507 
508  // Lot de donnees a exporter
509  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
510  print '<td>';
511  $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
512  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
513  print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
514  print $objexport->array_export_label[0];
515  print '</td></tr>';
516 
517  print '</table>';
518  print '</div>';
519 
521 
522  print '<br>';
523 
524  // Combo list of export models
525  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
526  print '<input type="hidden" name="token" value="'.newToken().'">';
527  print '<input type="hidden" name="action" value="select_model">';
528  print '<input type="hidden" name="step" value="2">';
529  print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
530  print '<div class="valignmiddle marginbottomonly">';
531  print '<span class="opacitymedium">'.$langs->trans("SelectExportFields").'</span> ';
532  if (empty($conf->global->EXPORTS_SHARE_MODELS)) {
533  $htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1, $user->id);
534  } else {
535  $htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1);
536  }
537  print ' ';
538  print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
539  print '</div>';
540  print '</form>';
541 
542 
543  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
544  print '<table class="noborder centpercent">';
545  print '<tr class="liste_titre">';
546  print '<td>'.$langs->trans("Entities").'</td>';
547  print '<td>'.$langs->trans("ExportableFields").'</td>';
548  print '<td width="100" class="center">';
549  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>";
550  print ' / ';
551  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>";
552  print '</td>';
553  print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
554  print '</tr>';
555 
556  // Champs exportables
557  $fieldsarray = $objexport->array_export_fields[0];
558  // Select request if all fields are selected
559  $sqlmaxforexport = $objexport->build_sql(0, array(), array());
560 
561  // $this->array_export_module[0]=$module;
562  // $this->array_export_code[0]=$module->export_code[$r];
563  // $this->array_export_label[0]=$module->export_label[$r];
564  // $this->array_export_sql[0]=$module->export_sql[$r];
565  // $this->array_export_fields[0]=$module->export_fields_array[$r];
566  // $this->array_export_entities[0]=$module->export_fields_entities[$r];
567  // $this->array_export_alias[0]=$module->export_fields_alias[$r];
568 
569  $i = 0;
570 
571  foreach ($fieldsarray as $code=>$label)
572  {
573  print '<tr class="oddeven">';
574 
575  $i++;
576 
577  $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
578  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
579  $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
580 
581  print '<td class="nowrap">';
582  // If value of entityicon=entitylang='icon:Label'
583  //print $code.'-'.$label.'-'.$entity;
584 
585  $tmparray = explode(':', $entityicon);
586  if (count($tmparray) >= 2)
587  {
588  $entityicon = $tmparray[0];
589  $entitylang = $tmparray[1];
590  }
591  print img_object('', $entityicon).' '.$langs->trans($entitylang);
592  print '</td>';
593 
594  $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
595 
596  $tablename = getablenamefromfield($code, $sqlmaxforexport);
597  $htmltext = '<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
598  if (!empty($objexport->array_export_special[0][$code]))
599  {
600  $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
601  } else {
602  $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
603  }
604  if (!empty($objexport->array_export_examplevalues[0][$code]))
605  {
606  $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
607  }
608  if (!empty($objexport->array_export_TypeFields[0][$code]))
609  {
610  $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
611  }
612  if (!empty($objexport->array_export_help[0][$code]))
613  {
614  $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
615  }
616 
617  if (isset($array_selected[$code]) && $array_selected[$code])
618  {
619  // Selected fields
620  print '<td>&nbsp;</td>';
621  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>';
622  print '<td>';
623  //print $text.'-'.$htmltext."<br>";
624  print $form->textwithpicto($text, $htmltext);
625  //print ' ('.$code.')';
626  print '</td>';
627  } else {
628  // Fields not selected
629  print '<td>';
630  //print $text.'-'.$htmltext."<br>";
631  print $form->textwithpicto($text, $htmltext);
632  //print ' ('.$code.')';
633  print '</td>';
634  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>';
635  print '<td>&nbsp;</td>';
636  }
637 
638  print '</tr>';
639  }
640 
641  print '</table>';
642  print '</div>';
643 
644  /*
645  * Barre d'action
646  */
647  print '<div class="tabsAction tabsActionNoBottom">';
648 
649  if (count($array_selected))
650  {
651  // If filters exist
652  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
653  {
654  print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
655  } else {
656  print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
657  }
658  } else {
659  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
660  }
661 
662  print '</div>';
663 }
664 
665 if ($step == 3 && $datatoexport)
666 {
667  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
668  {
669  // Switch to step 2
670  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
671  exit;
672  }
673 
674  llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
675 
676  $h = 0;
677 
678  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
679  $head[$h][1] = $langs->trans("Step")." 1";
680  $h++;
681 
682  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
683  $head[$h][1] = $langs->trans("Step")." 2";
684  $h++;
685 
686  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
687  $head[$h][1] = $langs->trans("Step")." 3";
688  $hselected = $h;
689  $h++;
690 
691  print dol_get_fiche_head($head, $hselected, '', -2);
692 
693  print '<div class="fichecenter">';
694  print '<div class="underbanner clearboth"></div>';
695  print '<table width="100%" class="border tableforfield">';
696 
697  // Module
698  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
699  print '<td>';
700  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
701  print $objexport->array_export_module[0]->getName();
702  print '</td></tr>';
703 
704  // Lot de donnees a exporter
705  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
706  print '<td>';
707  $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
708  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
709  print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
710  print $objexport->array_export_label[0];
711  print '</td></tr>';
712 
713  // Nbre champs exportes
714  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
715  $list = '';
716  foreach ($array_selected as $code=>$value)
717  {
718  $list .= (!empty($list) ? ', ' : '');
719  $list .= (isset($objexport->array_export_fields[0][$code]) ? $langs->trans($objexport->array_export_fields[0][$code]) : '');
720  }
721  print '<td>'.$list.'</td></tr>';
722 
723  print '</table>';
724  print '</div>';
725 
726  print '<br>';
727 
728  // Combo list of export models
729  print '<span class="opacitymedium">'.$langs->trans("SelectFilterFields").'</span><br><br>';
730 
731 
732  // un formulaire en plus pour recuperer les filtres
733  print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
734  print '<input type="hidden" name="token" value="'.newToken().'">';
735 
736  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
737 
738  print '<table class="noborder centpercent">';
739  print '<tr class="liste_titre">';
740  print '<td>'.$langs->trans("Entities").'</td>';
741  //print '<td>'.$langs->trans("ExportableFields").'</td>';
742  //print '<td class="center"></td>';
743  print '<td>'.$langs->trans("ExportableFields").'</td>';
744  print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
745  print '</tr>';
746 
747  // Champs exportables
748  $fieldsarray = $objexport->array_export_fields[0];
749  // Champs filtrable
750  $Typefieldsarray = $objexport->array_export_TypeFields[0];
751  // valeur des filtres
752  $ValueFiltersarray = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
753  // Select request if all fields are selected
754  $sqlmaxforexport = $objexport->build_sql(0, array(), array());
755 
756  $i = 0;
757  // on boucle sur les champs
758  foreach ($fieldsarray as $code => $label)
759  {
760  print '<tr class="oddeven">';
761 
762  $i++;
763  $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
764  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
765  $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
766 
767  print '<td class="nowrap">';
768  // If value of entityicon=entitylang='icon:Label'
769  $tmparray = explode(':', $entityicon);
770  if (count($tmparray) >= 2)
771  {
772  $entityicon = $tmparray[0];
773  $entitylang = $tmparray[1];
774  }
775  print img_object('', $entityicon).' '.$langs->trans($entitylang);
776  print '</td>';
777 
778  // Field name
779  $labelName = (!empty($fieldsarray[$code]) ? $fieldsarray[$code] : '');
780  $ValueFilter = (!empty($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
781  $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
782 
783  $tablename = getablenamefromfield($code, $sqlmaxforexport);
784  $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
785  if (!empty($objexport->array_export_special[0][$code]))
786  {
787  $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
788  } else {
789  $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
790  }
791  if (!empty($objexport->array_export_examplevalues[0][$code]))
792  {
793  $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
794  }
795  if (!empty($objexport->array_export_TypeFields[0][$code]))
796  {
797  $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
798  }
799  if (!empty($objexport->array_export_help[0][$code]))
800  {
801  $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
802  }
803 
804  print '<td>';
805  print $form->textwithpicto($text, $htmltext);
806  print '</td>';
807 
808  // Filter value
809  print '<td>';
810  if (!empty($Typefieldsarray[$code])) // Example: Text, List:c_country:label:rowid, Number, Boolean
811  {
812  $szInfoFiltre = $objexport->genDocFilter($Typefieldsarray[$code]);
813  if ($szInfoFiltre) // Is there an info help for this filter ?
814  {
815  $tmp = $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
816  print $form->textwithpicto($tmp, $szInfoFiltre);
817  } else {
818  print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
819  }
820  }
821  print '</td>';
822 
823  print '</tr>';
824  }
825 
826  print '</table>';
827  print '</div>';
828 
829  print '</div>';
830 
831  /*
832  * Barre d'action
833  */
834  print '<div class="tabsAction tabsActionNoBottom">';
835  // il n'est pas obligatoire de filtrer les champs
836  print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
837  print '</div>';
838 }
839 
840 if ($step == 4 && $datatoexport)
841 {
842  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
843  {
844  // Switch to step 2
845  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
846  exit;
847  }
848 
849  asort($array_selected);
850 
851  llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
852 
853  $stepoffset = 0;
854  $h = 0;
855 
856  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
857  $head[$h][1] = $langs->trans("Step")." 1";
858  $h++;
859 
860  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
861  $head[$h][1] = $langs->trans("Step")." 2";
862  $h++;
863 
864  // If filters exist
865  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
866  {
867  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
868  $head[$h][1] = $langs->trans("Step")." 3";
869  $h++;
870  $stepoffset++;
871  }
872 
873  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
874  $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
875  $hselected = $h;
876  $h++;
877 
878  print dol_get_fiche_head($head, $hselected, '', -2);
879 
880  print '<div class="fichecenter">';
881  print '<div class="underbanner clearboth"></div>';
882  print '<table width="100%" class="border tableforfield">';
883 
884  // Module
885  print '<tr><td class="titlefield tableforfield">'.$langs->trans("Module").'</td>';
886  print '<td>';
887  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
888  print $objexport->array_export_module[0]->getName();
889  print '</td></tr>';
890 
891  // Lot de donnees a exporter
892  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
893  print '<td>';
894  $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
895  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
896  print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
897  print $objexport->array_export_label[0];
898  print '</td></tr>';
899 
900  // List of exported fields
901  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
902  $list = '';
903  foreach ($array_selected as $code=>$value)
904  {
905  $list .= (!empty($list) ? ', ' : '');
906  $list .= $langs->trans($objexport->array_export_fields[0][$code]);
907  }
908  print '<td>'.$list.'</td>';
909  print '</tr>';
910 
911  // List of filtered fiels
912  if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
913  {
914  print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
915  $list = '';
916  if (!empty($array_filtervalue))
917  {
918  foreach ($array_filtervalue as $code=>$value)
919  {
920  if (isset($objexport->array_export_fields[0][$code]))
921  {
922  $list .= ($list ? ', ' : '');
923  if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) $list .= $langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
924  else $list .= $langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
925  }
926  }
927  }
928  print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
929  print '</tr>';
930  }
931 
932  print '</table>';
933  print '</div>';
934 
935  print '<br>';
936 
937  // Select request if all fields are selected
938  $sqlmaxforexport = $objexport->build_sql(0, array(), array());
939 
940  print '<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans("ChooseFieldsOrdersAndTitle").'</span></div>';
941 
942  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
943  print '<table class="noborder centpercent">';
944  print '<tr class="liste_titre">';
945  print '<td>'.$langs->trans("Entities").'</td>';
946  print '<td>'.$langs->trans("ExportedFields").'</td>';
947  print '<td class="right" colspan="2">'.$langs->trans("Position").'</td>';
948  //print '<td>&nbsp;</td>';
949  //print '<td>'.$langs->trans("FieldsTitle").'</td>';
950  print '</tr>';
951 
952  foreach ($array_selected as $code=>$value)
953  {
954  print '<tr class="oddeven">';
955 
956  $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
957  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
958  $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
959 
960  print '<td class="nowrap">';
961  // If value of entityicon=entitylang='icon:Label'
962  $tmparray = explode(':', $entityicon);
963  if (count($tmparray) >= 2)
964  {
965  $entityicon = $tmparray[0];
966  $entitylang = $tmparray[1];
967  }
968  print img_object('', $entityicon).' '.$langs->trans($entitylang);
969  print '</td>';
970 
971  $labelName = $objexport->array_export_fields[0][$code];
972 
973  $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
974 
975  $tablename = getablenamefromfield($code, $sqlmaxforexport);
976  $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
977  if (!empty($objexport->array_export_special[0][$code]))
978  {
979  $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
980  } else {
981  $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
982  }
983  if (!empty($objexport->array_export_examplevalues[0][$code]))
984  {
985  $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
986  }
987  if (!empty($objexport->array_export_TypeFields[0][$code]))
988  {
989  $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
990  }
991  if (!empty($objexport->array_export_help[0][$code]))
992  {
993  $htmltext .= '<b>'.$langs->trans("Help").':</b> '.$langs->trans($objexport->array_export_help[0][$code]).'<br>';
994  }
995 
996  print '<td>';
997  print $form->textwithpicto($text, $htmltext);
998  //print ' ('.$code.')';
999  print '</td>';
1000 
1001  print '<td class="right" width="100">';
1002  print $value.' ';
1003  print '</td><td class="center nowraponall" width="40">';
1004  if ($value < count($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1005  if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1006  print '</td>';
1007 
1008  //print '<td>&nbsp;</td>';
1009  //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
1010 
1011  print '</tr>';
1012  }
1013 
1014  print '</table>';
1015  print '</div>';
1016 
1017  print '</div>';
1018 
1019  /*
1020  * Barre d'action
1021  *
1022  */
1023  print '<div class="tabsAction">';
1024 
1025  if (count($array_selected))
1026  {
1027  print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
1028  }
1029 
1030  print '</div>';
1031 
1032 
1033  // Area for profils export
1034  if (count($array_selected))
1035  {
1036  print '<br>';
1037 
1038  print '<div class="marginbottomonly">';
1039  print '<span class="opacitymedium">'.$langs->trans("SaveExportModel").'</span>';
1040  print '</div>';
1041 
1042  print '<form class="nocellnopadd" action="export.php" method="post">';
1043  print '<input type="hidden" name="token" value="'.newToken().'">';
1044  print '<input type="hidden" name="action" value="add_export_model">';
1045  print '<input type="hidden" name="step" value="'.$step.'">';
1046  print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1047  print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1048 
1049  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
1050  print '<table class="noborder centpercent">';
1051  print '<tr class="liste_titre">';
1052  print '<td>'.$langs->trans("ExportModelName").'</td>';
1053  print '<td>&nbsp;</td>';
1054  print '</tr>';
1055 
1056  print '<tr class="oddeven">';
1057  print '<td><input name="export_name" size="32" value=""></td><td class="right">';
1058  print '<input type="submit" class="button reposition button-save" value="'.$langs->trans("Save").'">';
1059  print '</td></tr>';
1060 
1061  // List of existing export profils
1062  $sql = "SELECT rowid, label";
1063  $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
1064  $sql .= " WHERE type = '".$db->escape($datatoexport)."'";
1065  if (empty($conf->global->EXPORTS_SHARE_MODELS))$sql .= " AND fk_user=".$user->id;
1066  $sql .= " ORDER BY rowid";
1067  $resql = $db->query($sql);
1068  if ($resql)
1069  {
1070  $num = $db->num_rows($resql);
1071  $i = 0;
1072  while ($i < $num)
1073  {
1074  $obj = $db->fetch_object($resql);
1075  print '<tr class="oddeven"><td>';
1076  print $obj->label;
1077  print '</td><td class="right">';
1078  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&token='.newToken().'&id='.$obj->rowid.'">';
1079  print img_delete();
1080  print '</a>';
1081  print '</tr>';
1082  $i++;
1083  }
1084  } else {
1085  dol_print_error($db);
1086  }
1087 
1088  print '</table>';
1089  print '</div>';
1090 
1091  print '</form>';
1092  }
1093 }
1094 
1095 if ($step == 5 && $datatoexport)
1096 {
1097  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
1098  {
1099  // Switch to step 2
1100  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1101  exit;
1102  }
1103 
1104  asort($array_selected);
1105 
1106  llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1107 
1108  $h = 0;
1109  $stepoffset = 0;
1110 
1111  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1112  $head[$h][1] = $langs->trans("Step")." 1";
1113  $h++;
1114 
1115  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
1116  $head[$h][1] = $langs->trans("Step")." 2";
1117  $h++;
1118 
1119  // si le filtrage est parametre pour l'export ou pas
1120  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1121  {
1122  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1123  $head[$h][1] = $langs->trans("Step")." 3";
1124  $h++;
1125  $stepoffset++;
1126  }
1127 
1128  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1129  $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
1130  $h++;
1131 
1132  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1133  $head[$h][1] = $langs->trans("Step")." ".(4 + $stepoffset);
1134  $hselected = $h;
1135  $h++;
1136 
1137  print dol_get_fiche_head($head, $hselected, '', -2);
1138 
1139  /*
1140  * Confirmation suppression fichier
1141  */
1142  if ($action == 'remove_file')
1143  {
1144  print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1145  }
1146 
1147  print '<div class="fichecenter">';
1148  print '<div class="underbanner clearboth"></div>';
1149 
1150  print '<table width="100%" class="border tableforfield">';
1151 
1152  // Module
1153  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
1154  print '<td>';
1155  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
1156  print $objexport->array_export_module[0]->getName();
1157  print '</td></tr>';
1158 
1159  // Dataset to export
1160  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1161  print '<td>';
1162  $entity = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1163  $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1164  print img_object($objexport->array_export_module[0]->getName(), $entityicon).' ';
1165  print $objexport->array_export_label[0];
1166  print '</td></tr>';
1167 
1168  // List of exported fields
1169  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1170  $list = '';
1171  foreach ($array_selected as $code=>$label)
1172  {
1173  $list .= (!empty($list) ? ', ' : '');
1174  $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1175  }
1176  print '<td>'.$list.'</td></tr>';
1177 
1178  // List of filtered fields
1179  if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1180  {
1181  print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1182  $list = '';
1183  if (!empty($array_filtervalue))
1184  {
1185  foreach ($array_filtervalue as $code=>$value)
1186  {
1187  if (isset($objexport->array_export_fields[0][$code]))
1188  {
1189  $list .= ($list ? ', ' : '');
1190  if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) $list .= $langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1191  else $list .= $langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1192  }
1193  }
1194  }
1195  print '<td>'.(!empty($list) ? $list : '<span class="opacitymedium">'.$langs->trans("None").'</span>').'</td>';
1196  print '</tr>';
1197  }
1198 
1199  print '</table>';
1200  print '</div>';
1201 
1202  print '<br>';
1203 
1204  // List of available export formats
1205  $htmltabloflibs = '<table class="noborder centpercent">';
1206  $htmltabloflibs .= '<tr class="liste_titre">';
1207  $htmltabloflibs .= '<td>'.$langs->trans("AvailableFormats").'</td>';
1208  $htmltabloflibs .= '<td>'.$langs->trans("LibraryUsed").'</td>';
1209  $htmltabloflibs .= '<td class="right">'.$langs->trans("LibraryVersion").'</td>';
1210  $htmltabloflibs .= '</tr>'."\n";
1211 
1212  $liste = $objmodelexport->liste_modeles($db);
1213  $listeall = $liste;
1214  foreach ($listeall as $key => $val)
1215  {
1216  if (preg_match('/__\(Disabled\)__/', $listeall[$key]))
1217  {
1218  $listeall[$key] = preg_replace('/__\(Disabled\)__/', '('.$langs->transnoentitiesnoconv("Disabled").')', $listeall[$key]);
1219  unset($liste[$key]);
1220  }
1221 
1222  $htmltabloflibs .= '<tr class="oddeven">';
1223  $htmltabloflibs .= '<td>'.img_picto_common($key, $objmodelexport->getPictoForKey($key)).' ';
1224  $text = $objmodelexport->getDriverDescForKey($key);
1225  $label = $listeall[$key];
1226  $htmltabloflibs .= $form->textwithpicto($label, $text).'</td>';
1227  $htmltabloflibs .= '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1228  $htmltabloflibs .= '<td class="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1229  $htmltabloflibs .= '</tr>'."\n";
1230  }
1231  $htmltabloflibs .= '</table>';
1232 
1233  print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NowClickToGenerateToBuildExportFile"), $htmltabloflibs, 1, 'help', '', 0, 2, 'helphonformat').'</span>';
1234  //print $htmltabloflibs;
1235  print '<br>';
1236 
1237  print '</div>';
1238 
1239 
1240  if ($sqlusedforexport && $user->admin)
1241  {
1242  print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport, 0, 0, 1, '', 'TechnicalInformation');
1243  }
1244 
1245 
1246  if (!is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1247 
1248  // Show existing generated documents
1249  // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
1250  print $formfile->showdocuments('export', '', $upload_dir, $_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport, $liste, 1, (!empty($_POST['model']) ? $_POST['model'] : 'csv'), 1, 1, 0, 0, 0, '', 'none', '', '', '');
1251 }
1252 
1253 llxFooter();
1254 
1255 $db->close();
1256 
1257 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
1258 
1259 
1267 function getablenamefromfield($code, $sqlmaxforexport)
1268 {
1269  $alias = preg_replace('/\.(.*)$/i', '', $code); // Keep only 'Alias' and remove '.Fieldname'
1270  $regexstring = '/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1271 
1272  $newsql = $sqlmaxforexport;
1273  $newsql = preg_replace('/^(.*) FROM /i', '', $newsql); // Remove part before the FROM
1274  $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
1275 
1276  if (preg_match($regexstring, $newsql, $reg))
1277  {
1278  return $reg[1]; // The tablename
1279  } else return '';
1280 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Parent class for export modules.
Class to manage exports.
img_left($titlealt= 'default', $selected=0, $moreatt= '')
Show left arrow logo.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
img_down($titlealt= 'default', $selected=0, $moreclass= '')
Show down arrow logo.
img_up($titlealt= 'default', $selected=0, $moreclass= '')
Show top arrow logo.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1144
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to offer components to list and upload files.
img_right($titlealt= 'default', $selected=0, $moreatt= '')
Show right arrow logo.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
getablenamefromfield($code, $sqlmaxforexport)
Return table name of an alias.
Definition: export.php:1267
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)