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