dolibarr  7.0.0-beta
export.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.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 $langs->load("exports");
36 $langs->load("other");
37 $langs->load("users");
38 $langs->load("companies");
39 $langs->load("projects");
40 
41 // Everybody should be able to go on this page
42 //if (! $user->admin)
43 // accessforbidden();
44 
45 $entitytoicon = array(
46  'invoice' => 'bill',
47  'invoice_line' => 'bill',
48  'order' => 'order',
49  'order_line' => 'order',
50  'propal' => 'propal',
51  'propal_line' => 'propal',
52  'intervention' => 'intervention',
53  'inter_line' => 'intervention',
54  'member' => 'user',
55  'member_type' => 'group',
56  'subscription' => 'payment',
57  'payment' => 'payment',
58  'tax' => 'generic',
59  'tax_type' => 'generic',
60  'stock' => 'generic',
61  'other' => 'generic',
62  'account' => 'account',
63  'product' => 'product',
64  'virtualproduct'=>'product',
65  'subproduct' => 'product',
66  'warehouse' => 'stock',
67  'batch' => 'stock',
68  'stockbatch' => 'stock',
69  'category' => 'category',
70  'shipment' => 'sending',
71  'shipment_line'=> 'sending',
72  'expensereport'=> 'trip',
73  'expensereport_line'=> 'trip',
74  'contract_line' => 'contract',
75  'translation' => 'generic'
76 );
77 
78 // Translation code
79 $entitytolang = array(
80  'user' => 'User',
81  'company' => 'Company',
82  'contact' => 'Contact',
83  'invoice' => 'Bill',
84  'invoice_line' => 'InvoiceLine',
85  'order' => 'Order',
86  'order_line' => 'OrderLine',
87  'propal' => 'Proposal',
88  'propal_line' => 'ProposalLine',
89  'intervention' => 'Intervention',
90  'inter_line' => 'InterLine',
91  'member' => 'Member',
92  'member_type' => 'MemberType',
93  'subscription' => 'Subscription',
94  'tax' => 'SocialContribution',
95  'tax_type' => 'DictionarySocialContributions',
96  'account' => 'BankTransactions',
97  'payment' => 'Payment',
98  'product' => 'Product',
99  'virtualproduct' => 'AssociatedProducts',
100  'subproduct' => 'SubProduct',
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  'contract' => 'Contract',
119  'contract_line'=> 'ContractLine',
120  'translation' => 'Translation'
121 );
122 
123 $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array();
124 $array_filtervalue=isset($_SESSION["export_filtered_fields"])?$_SESSION["export_filtered_fields"]:array();
125 $datatoexport=GETPOST("datatoexport");
126 $action=GETPOST('action', 'alpha');
127 $confirm=GETPOST('confirm', 'alpha');
128 $step=GETPOST("step")?GETPOST("step"):1;
129 $export_name=GETPOST("export_name");
130 $hexa=GETPOST("hexa");
131 $exportmodelid=GETPOST("exportmodelid");
132 $field=GETPOST("field");
133 
134 $objexport=new Export($db);
135 $objexport->load_arrays($user,$datatoexport);
136 
137 $objmodelexport=new ModeleExports($db);
138 $form = new Form($db);
139 $htmlother = new FormOther($db);
140 $formfile = new FormFile($db);
141 $sqlusedforexport='';
142 
143 $upload_dir = $conf->export->dir_temp.'/'.$user->id;
144 
145 //$usefilters=($conf->global->MAIN_FEATURES_LEVEL > 1);
146 $usefilters=1;
147 
148 
149 /*
150  * Actions
151  */
152 
153 if ($action=='selectfield') // Selection of field at step 2
154 {
155  $fieldsarray=$objexport->array_export_fields[0];
156  $fieldsentitiesarray=$objexport->array_export_entities[0];
157  $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
158 
159  if ($field=='all')
160  {
161  foreach($fieldsarray as $key=>$val)
162  {
163  if (! empty($array_selected[$key])) continue; // If already selected, check next
164  $array_selected[$key]=count($array_selected)+1;
165  //print_r($array_selected);
166  $_SESSION["export_selected_fields"]=$array_selected;
167  }
168  }
169  else
170  {
171  $warnings=array();
172 
173  $array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected"
174  // We check if there is a dependency to activate
175  /*var_dump($field);
176  var_dump($fieldsentitiesarray[$field]);
177  var_dump($fieldsdependenciesarray);*/
178  $listofdependencies=array();
179  if (! empty($fieldsentitiesarray[$field]) && ! empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]]))
180  {
181  // We found a dependency on the type of field
182  $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
183  if (is_array($tmp)) $listofdependencies=$tmp;
184  else $listofdependencies=array($tmp);
185  }
186  else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
187  {
188  // We found a dependency on a dedicated field
189  $tmp=$fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
190  if (is_array($tmp)) $listofdependencies=$tmp;
191  else $listofdependencies=array($tmp);
192  }
193 
194  if (count($listofdependencies))
195  {
196  foreach($listofdependencies as $fieldid)
197  {
198  if (empty($array_selected[$fieldid]))
199  {
200  $array_selected[$fieldid]=count($array_selected)+1; // We tag the key $fieldid as "selected"
201  $warnings[]=$langs->trans("ExportFieldAutomaticallyAdded",$langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
202  }
203  }
204  }
205  //print_r($array_selected);
206  $_SESSION["export_selected_fields"]=$array_selected;
207 
208  setEventMessages($warnings, null, 'warnings');
209  }
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  $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
555  print ' ';
556  print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
557  print '</td></tr></table>';
558  print '</form>';
559 
560 
561  print '<table class="noborder" width="100%">';
562  print '<tr class="liste_titre">';
563  print '<td>'.$langs->trans("Entities").'</td>';
564  print '<td>'.$langs->trans("ExportableFields").'</td>';
565  print '<td width="100" align="center">';
566  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>";
567  print ' / ';
568  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>";
569  print '</td>';
570  print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
571  print '</tr>';
572 
573  // Champs exportables
574  $fieldsarray=$objexport->array_export_fields[0];
575  // Select request if all fields are selected
576  $sqlmaxforexport=$objexport->build_sql(0, array(), array());
577 
578  // $this->array_export_module[0]=$module;
579  // $this->array_export_code[0]=$module->export_code[$r];
580  // $this->array_export_label[0]=$module->export_label[$r];
581  // $this->array_export_sql[0]=$module->export_sql[$r];
582  // $this->array_export_fields[0]=$module->export_fields_array[$r];
583  // $this->array_export_entities[0]=$module->export_fields_entities[$r];
584  // $this->array_export_alias[0]=$module->export_fields_alias[$r];
585 
586  $var=true;
587  $i = 0;
588 
589  foreach($fieldsarray as $code=>$label)
590  {
591 
592  print '<tr class="oddeven">';
593 
594  $i++;
595 
596  $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
597  $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
598  $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
599 
600  print '<td class="nowrap">';
601  // If value of entityicon=entitylang='icon:Label'
602  //print $code.'-'.$label.'-'.$entity;
603 
604  $tmparray=explode(':',$entityicon);
605  if (count($tmparray) >=2)
606  {
607  $entityicon=$tmparray[0];
608  $entitylang=$tmparray[1];
609  }
610  print img_object('',$entityicon).' '.$langs->trans($entitylang);
611  print '</td>';
612 
613  $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code])?'':'</i>');
614 
615  $tablename=getablenamefromfield($code,$sqlmaxforexport);
616  $htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
617  if (! empty($objexport->array_export_special[0][$code]))
618  {
619  $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
620  }
621  else
622  {
623  $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
624  }
625  if (! empty($objexport->array_export_examplevalues[0][$code]))
626  {
627  $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
628  }
629  if (! empty($objexport->array_export_TypeFields[0][$code]))
630  {
631  $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
632  }
633 
634  if (isset($array_selected[$code]) && $array_selected[$code])
635  {
636  // Selected fields
637  print '<td>&nbsp;</td>';
638  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>';
639  print '<td>';
640  //print $text.'-'.$htmltext."<br>";
641  print $form->textwithpicto($text,$htmltext);
642  //print ' ('.$code.')';
643  print '</td>';
644  }
645  else
646  {
647  // Fields not selected
648  print '<td>';
649  //print $text.'-'.$htmltext."<br>";
650  print $form->textwithpicto($text,$htmltext);
651  //print ' ('.$code.')';
652  print '</td>';
653  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>';
654  print '<td>&nbsp;</td>';
655  }
656 
657  print '</tr>';
658  }
659 
660  print '</table>';
661 
662 
663  /*
664  * Barre d'action
665  */
666  print '<div class="tabsAction tabsActionNoBottom">';
667 
668  if (count($array_selected))
669  {
670  // If filters exist
671  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
672  {
673  print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
674  }
675  else
676  {
677  print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
678  }
679  }
680  else
681  {
682  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
683  }
684 
685  print '</div>';
686 
687 }
688 
689 if ($step == 3 && $datatoexport)
690 {
691  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
692  {
693  // Switch to step 2
694  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
695  exit;
696  }
697 
698  llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
699 
700  /*
701  * Affichage onglets
702  */
703  $h = 0;
704 
705  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
706  $head[$h][1] = $langs->trans("Step")." 1";
707  $h++;
708 
709  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
710  $head[$h][1] = $langs->trans("Step")." 2";
711  $h++;
712 
713  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
714  $head[$h][1] = $langs->trans("Step")." 3";
715  $hselected=$h;
716  $h++;
717 
718  dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
719 
720  print '<div class="fichecenter">';
721  print '<div class="underbanner clearboth"></div>';
722  print '<table width="100%" class="border">';
723 
724  // Module
725  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
726  print '<td>';
727  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
728  print $objexport->array_export_module[0]->getName();
729  print '</td></tr>';
730 
731  // Lot de donnees a exporter
732  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
733  print '<td>';
734  $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
735  $label=$objexport->array_export_label[0];
736  //print $value.'-'.$icon.'-'.$label."<br>";
737  print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
738  print $label;
739  print '</td></tr>';
740 
741  // Nbre champs exportes
742  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
743  $list='';
744  foreach($array_selected as $code=>$value)
745  {
746  $list.=(! empty($list)?', ':'');
747  $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):'');
748  }
749  print '<td>'.$list.'</td></tr>';
750 
751  print '</table>';
752  print '</div>';
753 
754  print '<br>';
755 
756  // Combo list of export models
757  print $langs->trans("SelectFilterFields").'<br>';
758 
759 
760  // un formulaire en plus pour recuperer les filtres
761  print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
762  print '<table class="noborder" width="100%">';
763  print '<tr class="liste_titre">';
764  print '<td>'.$langs->trans("Entities").'</td>';
765  //print '<td>'.$langs->trans("ExportableFields").'</td>';
766  //print '<td align="center"></td>';
767  print '<td>'.$langs->trans("ExportableFields").'</td>';
768  print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
769  print '</tr>';
770 
771  // Champs exportables
772  $fieldsarray=$objexport->array_export_fields[0];
773  // Champs filtrable
774  $Typefieldsarray=$objexport->array_export_TypeFields[0];
775  // valeur des filtres
776  $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
777  // Select request if all fields are selected
778  $sqlmaxforexport=$objexport->build_sql(0, array(), array());
779 
780  $var=true;
781  $i = 0;
782  // on boucle sur les champs
783  foreach($fieldsarray as $code => $label)
784  {
785  print '<tr class="oddeven">';
786 
787  $i++;
788  $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
789  $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
790  $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
791 
792  print '<td class="nowrap">';
793  // If value of entityicon=entitylang='icon:Label'
794  $tmparray=explode(':',$entityicon);
795  if (count($tmparray) >=2)
796  {
797  $entityicon=$tmparray[0];
798  $entitylang=$tmparray[1];
799  }
800  print img_object('',$entityicon).' '.$langs->trans($entitylang);
801  print '</td>';
802 
803  // Field name
804  $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
805  $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
806  $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
807 
808  $tablename=getablenamefromfield($code,$sqlmaxforexport);
809  $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
810  if (! empty($objexport->array_export_special[0][$code]))
811  {
812  $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
813  }
814  else
815  {
816  $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
817  }
818  if (! empty($objexport->array_export_examplevalues[0][$code]))
819  {
820  $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
821  }
822  if (! empty($objexport->array_export_TypeFields[0][$code]))
823  {
824  $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
825  }
826 
827  print '<td>';
828  print $form->textwithpicto($text,$htmltext);
829  print '</td>';
830 
831  // Filter value
832  print '<td>';
833  if (! empty($Typefieldsarray[$code])) // Example: Text, List:c_country:label:rowid, Number, Boolean
834  {
835  $szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
836  if ($szInfoFiltre) // Is there an info help for this filter ?
837  {
838  $tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
839  print $form->textwithpicto($tmp, $szInfoFiltre);
840  }
841  else
842  {
843  print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
844  }
845  }
846  print '</td>';
847 
848  print '</tr>';
849  }
850 
851  print '</table>';
852 
853  print '</div>';
854 
855  /*
856  * Barre d'action
857  */
858  print '<div class="tabsAction tabsActionNoBottom">';
859  // il n'est pas obligatoire de filtrer les champs
860  print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
861  print '</div>';
862 
863 }
864 
865 if ($step == 4 && $datatoexport)
866 {
867  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
868  {
869  // Switch to step 2
870  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
871  exit;
872  }
873 
874  asort($array_selected);
875 
876  llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
877 
878  /*
879  * Affichage onglets
880  */
881  $stepoffset=0;
882  $h = 0;
883 
884  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
885  $head[$h][1] = $langs->trans("Step")." 1";
886  $h++;
887 
888  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
889  $head[$h][1] = $langs->trans("Step")." 2";
890  $h++;
891 
892  // If filters exist
893  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
894  {
895  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
896  $head[$h][1] = $langs->trans("Step")." 3";
897  $h++;
898  $stepoffset++;
899  }
900 
901  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
902  $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
903  $hselected=$h;
904  $h++;
905 
906  dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
907 
908  print '<div class="fichecenter">';
909  print '<div class="underbanner clearboth"></div>';
910  print '<table width="100%" class="border">';
911 
912  // Module
913  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
914  print '<td>';
915  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
916  print $objexport->array_export_module[0]->getName();
917  print '</td></tr>';
918 
919  // Lot de donnees a exporter
920  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
921  print '<td>';
922  $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
923  print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
924  print $objexport->array_export_label[0];
925  print '</td></tr>';
926 
927  // List of exported fields
928  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
929  $list='';
930  foreach($array_selected as $code=>$value)
931  {
932  $list.=(! empty($list)?', ':'');
933  $list.=$langs->trans($objexport->array_export_fields[0][$code]);
934  }
935  print '<td>'.$list.'</td>';
936  print '</tr>';
937 
938  // List of filtered fiels
939  if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
940  {
941  print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
942  $list='';
943  if (! empty($array_filtervalue))
944  {
945  foreach($array_filtervalue as $code=>$value)
946  {
947  if (isset($objexport->array_export_fields[0][$code]))
948  {
949  $list.=($list?', ':'');
950  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]:'');
951  else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
952  }
953  }
954  }
955  print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
956  print '</tr>';
957  }
958 
959  print '</table>';
960  print '</div>';
961 
962  print '<br>';
963 
964  // Select request if all fields are selected
965  $sqlmaxforexport=$objexport->build_sql(0, array(), array());
966 
967  print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
968 
969  print '<table class="noborder" width="100%">';
970  print '<tr class="liste_titre">';
971  print '<td>'.$langs->trans("Entities").'</td>';
972  print '<td>'.$langs->trans("ExportedFields").'</td>';
973  print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
974  //print '<td>&nbsp;</td>';
975  //print '<td>'.$langs->trans("FieldsTitle").'</td>';
976  print '</tr>';
977 
978  $var=true;
979  foreach($array_selected as $code=>$value)
980  {
981  print '<tr class="oddeven">';
982 
983  $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
984  $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
985  $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
986 
987  print '<td class="nowrap">';
988  // If value of entityicon=entitylang='icon:Label'
989  $tmparray=explode(':',$entityicon);
990  if (count($tmparray) >=2)
991  {
992  $entityicon=$tmparray[0];
993  $entitylang=$tmparray[1];
994  }
995  print img_object('',$entityicon).' '.$langs->trans($entitylang);
996  print '</td>';
997 
998  $labelName=$objexport->array_export_fields[0][$code];
999 
1000  $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
1001 
1002  $tablename=getablenamefromfield($code,$sqlmaxforexport);
1003  $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
1004  if (! empty($objexport->array_export_special[0][$code]))
1005  {
1006  $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
1007  }
1008  else
1009  {
1010  $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
1011  }
1012  if (! empty($objexport->array_export_examplevalues[0][$code]))
1013  {
1014  $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
1015  }
1016  if (! empty($objexport->array_export_TypeFields[0][$code]))
1017  {
1018  $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
1019  }
1020 
1021  print '<td>';
1022  print $form->textwithpicto($text,$htmltext);
1023  //print ' ('.$code.')';
1024  print '</td>';
1025 
1026  print '<td align="right" width="100">';
1027  print $value.' ';
1028  print '</td><td align="center" width="20">';
1029  if ($value < count($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1030  if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1031  print '</td>';
1032 
1033  //print '<td>&nbsp;</td>';
1034  //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
1035 
1036  print '</tr>';
1037  }
1038 
1039  print '</table>';
1040 
1041  print '</div>';
1042 
1043  /*
1044  * Barre d'action
1045  *
1046  */
1047  print '<div class="tabsAction">';
1048 
1049  if (count($array_selected))
1050  {
1051  print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
1052  }
1053 
1054  print '</div>';
1055 
1056 
1057  // Area for profils export
1058  if (count($array_selected))
1059  {
1060  print '<br>';
1061  print $langs->trans("SaveExportModel");
1062 
1063  print '<form class="nocellnopadd" action="export.php" method="post">';
1064  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1065  print '<input type="hidden" name="action" value="add_export_model">';
1066  print '<input type="hidden" name="step" value="'.$step.'">';
1067  print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1068  print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1069 
1070  print '<table class="noborder" width="100%">';
1071  print '<tr class="liste_titre">';
1072  print '<td>'.$langs->trans("ExportModelName").'</td>';
1073  print '<td>&nbsp;</td>';
1074  print '</tr>';
1075  $var=false;
1076  print '<tr class="oddeven">';
1077  print '<td><input name="export_name" size="32" value=""></td><td align="right">';
1078  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
1079  print '</td></tr>';
1080 
1081  // List of existing export profils
1082  $sql = "SELECT rowid, label";
1083  $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1084  $sql.= " WHERE type = '".$datatoexport."'";
1085  $sql.= " ORDER BY rowid";
1086  $resql = $db->query($sql);
1087  if ($resql)
1088  {
1089  $num = $db->num_rows($resql);
1090  $i = 0;
1091  $var=false;
1092  while ($i < $num)
1093  {
1094 
1095  $obj = $db->fetch_object($resql);
1096  print '<tr class="oddeven"><td>';
1097  print $obj->label;
1098  print '</td><td align="right">';
1099  print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">';
1100  print img_delete();
1101  print '</a>';
1102  print '</tr>';
1103  $i++;
1104  }
1105  }
1106  else {
1107  dol_print_error($this->db);
1108  }
1109 
1110  print '</table>';
1111  print '</form>';
1112  }
1113 }
1114 
1115 if ($step == 5 && $datatoexport)
1116 {
1117  if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
1118  {
1119  // Switch to step 2
1120  header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1121  exit;
1122  }
1123 
1124  asort($array_selected);
1125 
1126  llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1127 
1128  /*
1129  * Affichage onglets
1130  */
1131  $h = 0;
1132  $stepoffset=0;
1133 
1134  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1135  $head[$h][1] = $langs->trans("Step")." 1";
1136  $h++;
1137 
1138  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
1139  $head[$h][1] = $langs->trans("Step")." 2";
1140  $h++;
1141 
1142  // si le filtrage est parametre pour l'export ou pas
1143  if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1144  {
1145  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1146  $head[$h][1] = $langs->trans("Step")." 3";
1147  $h++;
1148  $stepoffset++;
1149  }
1150 
1151  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1152  $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
1153  $h++;
1154 
1155  $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1156  $head[$h][1] = $langs->trans("Step")." ".(4+$stepoffset);
1157  $hselected=$h;
1158  $h++;
1159 
1160  dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
1161 
1162  /*
1163  * Confirmation suppression fichier
1164  */
1165  if ($action == 'remove_file')
1166  {
1167  print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1168 
1169  }
1170 
1171  print '<div class="fichecenter">';
1172  print '<div class="underbanner clearboth"></div>';
1173 
1174  print '<table width="100%" class="border">';
1175 
1176  // Module
1177  print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
1178  print '<td>';
1179  //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
1180  print $objexport->array_export_module[0]->getName();
1181  print '</td></tr>';
1182 
1183  // Lot de donnees a exporter
1184  print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1185  print '<td>';
1186  $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
1187  print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
1188  print $objexport->array_export_label[0];
1189  print '</td></tr>';
1190 
1191  // List of exported fields
1192  print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1193  $list='';
1194  foreach($array_selected as $code=>$label)
1195  {
1196  $list.=(! empty($list)?', ':'');
1197  $list.=$langs->trans($objexport->array_export_fields[0][$code]);
1198  }
1199  print '<td>'.$list.'</td></tr>';
1200 
1201  // List of filtered fiels
1202  if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1203  {
1204  print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1205  $list='';
1206  if (! empty($array_filtervalue))
1207  {
1208  foreach($array_filtervalue as $code=>$value)
1209  {
1210  if (isset($objexport->array_export_fields[0][$code]))
1211  {
1212  $list.=($list?', ':'');
1213  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]:'');
1214  else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1215  }
1216  }
1217  }
1218  print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
1219  print '</tr>';
1220  }
1221 
1222  print '</table>';
1223  print '</div>';
1224 
1225  print '<br>';
1226 
1227  print $langs->trans("NowClickToGenerateToBuildExportFile").'<br>';
1228 
1229  // Liste des formats d'exports disponibles
1230  $var=true;
1231  print '<table class="noborder" width="100%">';
1232  print '<tr class="liste_titre">';
1233  print '<td class="titlefield">'.$langs->trans("AvailableFormats").'</td>';
1234  print '<td>'.$langs->trans("LibraryUsed").'</td>';
1235  print '<td align="right">'.$langs->trans("LibraryVersion").'</td>';
1236  print '</tr>'."\n";
1237 
1238  $liste=$objmodelexport->liste_modeles($db);
1239  $listeall=$liste;
1240  foreach($listeall as $key => $val)
1241  {
1242  if (preg_match('/__\(Disabled\)__/',$listeall[$key]))
1243  {
1244  $listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]);
1245  unset($liste[$key]);
1246  }
1247 
1248 
1249  print '<tr class="oddeven">';
1250  print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).' ';
1251  $text=$objmodelexport->getDriverDescForKey($key);
1252  $label=$listeall[$key];
1253  print $form->textwithpicto($label,$text).'</td>';
1254  print '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1255  print '<td align="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1256  print '</tr>'."\n";
1257  }
1258  print '</table>';
1259 
1260  print '</div>';
1261 
1262 
1263  print '<table width="100%">';
1264 
1265  if ($sqlusedforexport && $user->admin)
1266  {
1267  print '<tr><td>';
1268  print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport);
1269  print '</td></tr>';
1270  }
1271  print '</table>';
1272 
1273 
1274  print '<div class="fichecenter"><div class="fichehalfleft">';
1275 
1276  if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1277 
1278  // Affiche liste des documents
1279  // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
1280  print $formfile->showdocuments('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1);
1281 
1282  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1283 
1284  print '</div></div></div>';
1285 }
1286 
1287 llxFooter();
1288 
1289 $db->close();
1290 
1291 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
1292 
1293 
1301 function getablenamefromfield($code,$sqlmaxforexport)
1302 {
1303  $alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname'
1304  $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1305 
1306  $newsql=$sqlmaxforexport;
1307  $newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM
1308  $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
1309 
1310  if (preg_match($regexstring,$newsql,$reg))
1311  {
1312  return $reg[1]; // The tablename
1313  }
1314  else return '';
1315 }
Parent class for export modules.
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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_right($titlealt= 'default', $selected=0, $moreatt='')
Show right arrow logo.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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')
Show information for admin users or standard users.
img_up($titlealt= 'default', $selected=0, $moreclass='')
Show top arrow logo.
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:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
Class to offer components to list and upload files.
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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:1013
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null)
Remove a file or several files with a mask.
Definition: files.lib.php:1103
img_left($titlealt= 'default', $selected=0, $moreatt='')
Show left arrow logo.
getablenamefromfield($code, $sqlmaxforexport)
Return table name of an alias.
Definition: export.php:1301