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