export.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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. /**
  22. * \file htdocs/exports/export.php
  23. * \ingroup export
  24. * \brief Pages of export Wizard
  25. */
  26. require_once '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/exports/class/export.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. $langs->load("exports");
  33. $langs->load("users");
  34. $langs->load("companies");
  35. $langs->load("projects");
  36. // Everybody should be able to go on this page
  37. //if (! $user->admin)
  38. // accessforbidden();
  39. $entitytoicon = array(
  40. 'invoice' => 'bill',
  41. 'invoice_line' => 'bill',
  42. 'order' => 'order',
  43. 'order_line' => 'order',
  44. 'propal' => 'propal',
  45. 'propal_line' => 'propal',
  46. 'intervention' => 'intervention',
  47. 'inter_line' => 'intervention',
  48. 'member' => 'user',
  49. 'member_type' => 'group',
  50. 'subscription' => 'payment',
  51. 'payment' => 'payment',
  52. 'tax' => 'generic',
  53. 'tax_type' => 'generic',
  54. 'stock' => 'generic',
  55. 'other' => 'generic',
  56. 'account' => 'account',
  57. 'product' => 'product',
  58. 'warehouse' => 'stock',
  59. 'batch' => 'stock',
  60. 'category' => 'category',
  61. 'shipment' => 'sending',
  62. 'shipment_line'=> 'sending',
  63. 'expensereport'=> 'trip',
  64. 'expensereport_line'=> 'trip',
  65. 'contract_line' => 'contract',
  66. 'translation' => 'generic'
  67. );
  68. // Translation code
  69. $entitytolang = array(
  70. 'user' => 'User',
  71. 'company' => 'Company',
  72. 'contact' => 'Contact',
  73. 'invoice' => 'Bill',
  74. 'invoice_line' => 'InvoiceLine',
  75. 'order' => 'Order',
  76. 'order_line' => 'OrderLine',
  77. 'propal' => 'Proposal',
  78. 'propal_line' => 'ProposalLine',
  79. 'intervention' => 'Intervention',
  80. 'inter_line' => 'InterLine',
  81. 'member' => 'Member',
  82. 'member_type' => 'MemberType',
  83. 'subscription' => 'Subscription',
  84. 'tax' => 'SocialContribution',
  85. 'tax_type' => 'DictionarySocialContributions',
  86. 'account' => 'BankTransactions',
  87. 'payment' => 'Payment',
  88. 'product' => 'Product',
  89. 'service' => 'Service',
  90. 'stock' => 'Stock',
  91. 'batch' => 'Batch',
  92. 'warehouse' => 'Warehouse',
  93. 'category' => 'Category',
  94. 'other' => 'Other',
  95. 'trip' => 'TripsAndExpenses',
  96. 'shipment' => 'Shipments',
  97. 'shipment_line'=> 'ShipmentLine',
  98. 'project' => 'Projects',
  99. 'projecttask' => 'Tasks',
  100. 'task_time' => 'TaskTimeSpent',
  101. 'action' => 'Event',
  102. 'expensereport'=> 'ExpenseReport',
  103. 'expensereport_line'=> 'ExpenseReportLine',
  104. 'contract' => 'Contract',
  105. 'contract_line'=> 'ContractLine',
  106. 'translation' => 'Translation'
  107. );
  108. $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array();
  109. $array_filtervalue=isset($_SESSION["export_filtered_fields"])?$_SESSION["export_filtered_fields"]:array();
  110. $datatoexport=GETPOST("datatoexport");
  111. $action=GETPOST('action', 'alpha');
  112. $confirm=GETPOST('confirm', 'alpha');
  113. $step=GETPOST("step")?GETPOST("step"):1;
  114. $export_name=GETPOST("export_name");
  115. $hexa=GETPOST("hexa");
  116. $exportmodelid=GETPOST("exportmodelid");
  117. $field=GETPOST("field");
  118. $objexport=new Export($db);
  119. $objexport->load_arrays($user,$datatoexport);
  120. $objmodelexport=new ModeleExports($db);
  121. $form = new Form($db);
  122. $htmlother = new FormOther($db);
  123. $formfile = new FormFile($db);
  124. $sqlusedforexport='';
  125. $upload_dir = $conf->export->dir_temp.'/'.$user->id;
  126. //$usefilters=($conf->global->MAIN_FEATURES_LEVEL > 1);
  127. $usefilters=1;
  128. /*
  129. * Actions
  130. */
  131. if ($action=='selectfield')
  132. {
  133. $fieldsarray=$objexport->array_export_fields[0];
  134. $fieldsentitiesarray=$objexport->array_export_entities[0];
  135. $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
  136. if ($field=='all')
  137. {
  138. foreach($fieldsarray as $key=>$val)
  139. {
  140. if (! empty($array_selected[$key])) continue; // If already selected, check next
  141. $array_selected[$key]=count($array_selected)+1;
  142. //print_r($array_selected);
  143. $_SESSION["export_selected_fields"]=$array_selected;
  144. }
  145. }
  146. else
  147. {
  148. $warnings=array();
  149. $array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected"
  150. // We check if there is a dependency
  151. if (! empty($fieldsentitiesarray[$field]) && ! empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]]))
  152. {
  153. $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
  154. if (is_array($tmp)) $listofdependencies=$tmp;
  155. else $listofdependencies=array($tmp);
  156. foreach($listofdependencies as $fieldid)
  157. {
  158. if (empty($array_selected[$fieldid]))
  159. {
  160. $array_selected[$fieldid]=count($array_selected)+1; // We tag the key $fieldid as "selected"
  161. $warnings[]=$langs->trans("ExportFieldAutomaticallyAdded",$langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
  162. }
  163. }
  164. }
  165. //print_r($array_selected);
  166. $_SESSION["export_selected_fields"]=$array_selected;
  167. setEventMessages($warnings, null, 'warnings');
  168. }
  169. }
  170. if ($action=='unselectfield')
  171. {
  172. if ($_GET["field"]=='all')
  173. {
  174. $array_selected=array();
  175. $_SESSION["export_selected_fields"]=$array_selected;
  176. }
  177. else
  178. {
  179. unset($array_selected[$_GET["field"]]);
  180. // Renumber fields of array_selected (from 1 to nb_elements)
  181. asort($array_selected);
  182. $i=0;
  183. $array_selected_save=$array_selected;
  184. foreach($array_selected as $code=>$value)
  185. {
  186. $i++;
  187. $array_selected[$code]=$i;
  188. //print "x $code x $i y<br>";
  189. }
  190. $_SESSION["export_selected_fields"]=$array_selected;
  191. }
  192. }
  193. if ($action=='downfield' || $action=='upfield')
  194. {
  195. $pos=$array_selected[$_GET["field"]];
  196. if ($action=='downfield') $newpos=$pos+1;
  197. if ($action=='upfield') $newpos=$pos-1;
  198. // Recherche code avec qui switcher
  199. $newcode="";
  200. foreach($array_selected as $code=>$value)
  201. {
  202. if ($value == $newpos)
  203. {
  204. $newcode=$code;
  205. break;
  206. }
  207. }
  208. //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
  209. if ($newcode) // Si newcode trouve (protection contre resoumission de page)
  210. {
  211. $array_selected[$_GET["field"]]=$newpos;
  212. $array_selected[$newcode]=$pos;
  213. $_SESSION["export_selected_fields"]=$array_selected;
  214. }
  215. }
  216. if ($step == 1 || $action == 'cleanselect')
  217. {
  218. $_SESSION["export_selected_fields"]=array();
  219. $_SESSION["export_filtered_fields"]=array();
  220. $array_selected=array();
  221. $array_filtervalue=array();
  222. }
  223. if ($action == 'builddoc')
  224. {
  225. // Build export file
  226. $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue);
  227. if ($result < 0)
  228. {
  229. setEventMessages($objexport->error, $objexport->errors, 'errors');
  230. $sqlusedforexport=$objexport->sqlusedforexport;
  231. }
  232. else
  233. {
  234. setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
  235. $sqlusedforexport=$objexport->sqlusedforexport;
  236. }
  237. }
  238. // Delete file
  239. if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes')
  240. {
  241. $file = $upload_dir . "/" . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  242. $ret=dol_delete_file($file);
  243. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  244. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  245. header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
  246. exit;
  247. }
  248. if ($action == 'deleteprof')
  249. {
  250. if ($_GET["id"])
  251. {
  252. $objexport->fetch($_GET["id"]);
  253. $result=$objexport->delete($user);
  254. }
  255. }
  256. // 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.
  257. if ($action == 'add_export_model')
  258. {
  259. if ($export_name)
  260. {
  261. asort($array_selected);
  262. // Set save string
  263. $hexa='';
  264. foreach($array_selected as $key=>$val)
  265. {
  266. if ($hexa) $hexa.=',';
  267. $hexa.=$key;
  268. }
  269. $hexafiltervalue='';
  270. if (! empty($array_filtervalue) && is_array($array_filtervalue))
  271. {
  272. foreach($array_filtervalue as $key=>$val)
  273. {
  274. if ($hexafiltervalue) $hexafiltervalue.=',';
  275. $hexafiltervalue.=$key.'='.$val;
  276. }
  277. }
  278. $objexport->model_name = $export_name;
  279. $objexport->datatoexport = $datatoexport;
  280. $objexport->hexa = $hexa;
  281. $objexport->hexafiltervalue = $hexafiltervalue;
  282. $result = $objexport->create($user);
  283. if ($result >= 0)
  284. {
  285. setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
  286. }
  287. else
  288. {
  289. $langs->load("errors");
  290. if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  291. setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
  292. else
  293. setEventMessages($objexport->error, $objexport->errors, 'errors');
  294. }
  295. }
  296. else
  297. {
  298. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
  299. }
  300. }
  301. // Reload an predefined export model
  302. if ($step == 2 && $action == 'select_model')
  303. {
  304. $_SESSION["export_selected_fields"]=array();
  305. $_SESSION["export_filtered_fields"]=array();
  306. $array_selected=array();
  307. $array_filtervalue=array();
  308. $result = $objexport->fetch($exportmodelid);
  309. if ($result > 0)
  310. {
  311. $fieldsarray=explode(',',$objexport->hexa);
  312. $i=1;
  313. foreach($fieldsarray as $val)
  314. {
  315. $array_selected[$val]=$i;
  316. $i++;
  317. }
  318. $_SESSION["export_selected_fields"]=$array_selected;
  319. $fieldsarrayvalue=explode(',',$objexport->hexafiltervalue);
  320. $i=1;
  321. foreach($fieldsarrayvalue as $val)
  322. {
  323. $tmp=explode('=',$val);
  324. $array_filtervalue[$tmp[0]]=$tmp[1];
  325. $i++;
  326. }
  327. $_SESSION["export_filtered_fields"]=$array_filtervalue;
  328. }
  329. }
  330. // Get form with filters
  331. if ($step == 4 && $action == 'submitFormField')
  332. {
  333. // on boucle sur les champs selectionne pour recuperer la valeur
  334. if (is_array($objexport->array_export_TypeFields[0]))
  335. {
  336. $_SESSION["export_filtered_fields"]=array();
  337. foreach($objexport->array_export_TypeFields[0] as $code => $type) // $code: s.fieldname $value: Text|Boolean|List:ccc
  338. {
  339. $newcode=(string) preg_replace('/\./','_',$code);
  340. //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
  341. $filterqualified=1;
  342. if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
  343. elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
  344. if ($filterqualified)
  345. {
  346. //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
  347. $objexport->array_export_FilterValue[0][$code] = $_POST[$newcode];
  348. }
  349. }
  350. $array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
  351. $_SESSION["export_filtered_fields"]=$array_filtervalue;
  352. }
  353. }
  354. /*
  355. * View
  356. */
  357. if ($step == 1 || ! $datatoexport)
  358. {
  359. llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  360. /*
  361. * Affichage onglets
  362. */
  363. $h = 0;
  364. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
  365. $head[$h][1] = $langs->trans("Step")." 1";
  366. $hselected=$h;
  367. $h++;
  368. /*
  369. $head[$h][0] = '';
  370. $head[$h][1] = $langs->trans("Step")." 2";
  371. $h++;
  372. */
  373. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  374. print '<table class="notopnoleftnoright" width="100%">';
  375. print $langs->trans("SelectExportDataSet").'<br>';
  376. // Affiche les modules d'exports
  377. print '<table class="noborder" width="100%">';
  378. print '<tr class="liste_titre">';
  379. print '<td>'.$langs->trans("Module").'</td>';
  380. print '<td>'.$langs->trans("ExportableDatas").'</td>';
  381. print '<td>&nbsp;</td>';
  382. print '</tr>';
  383. $val=true;
  384. if (count($objexport->array_export_code))
  385. {
  386. foreach ($objexport->array_export_code as $key => $value)
  387. {
  388. $val=!$val;
  389. print '<tr '.$bc[$val].'><td nospan="nospan">';
  390. //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
  391. print $objexport->array_export_module[$key]->getName();
  392. print '</td><td>';
  393. $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]);
  394. $label=$objexport->array_export_label[$key];
  395. //print $value.'-'.$icon.'-'.$label."<br>";
  396. print img_object($objexport->array_export_module[$key]->getName(), $icon).' ';
  397. print $label;
  398. print '</td><td align="right">';
  399. if ($objexport->array_export_perms[$key])
  400. {
  401. print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
  402. }
  403. else
  404. {
  405. print $langs->trans("NotEnoughPermissions");
  406. }
  407. print '</td></tr>';
  408. }
  409. }
  410. else
  411. {
  412. print '<tr><td '.$bc[false].' colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
  413. }
  414. print '</table>';
  415. print '</table>';
  416. print '</div>';
  417. }
  418. if ($step == 2 && $datatoexport)
  419. {
  420. llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  421. /*
  422. * Affichage onglets
  423. */
  424. $h = 0;
  425. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
  426. $head[$h][1] = $langs->trans("Step")." 1";
  427. $h++;
  428. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
  429. $head[$h][1] = $langs->trans("Step")." 2";
  430. $hselected=$h;
  431. $h++;
  432. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  433. print '<table width="100%" class="border">';
  434. // Module
  435. print '<tr><td width="25%">'.$langs->trans("Module").'</td>';
  436. print '<td>';
  437. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  438. print $objexport->array_export_module[0]->getName();
  439. print '</td></tr>';
  440. // Lot de donnees a exporter
  441. print '<tr><td width="25%">'.$langs->trans("DatasetToExport").'</td>';
  442. print '<td>';
  443. $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
  444. $label=$objexport->array_export_label[0];
  445. //print $value.'-'.$icon.'-'.$label."<br>";
  446. print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
  447. print $label;
  448. print '</td></tr>';
  449. print '</table>';
  450. print '<br>';
  451. // Combo list of export models
  452. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  453. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  454. print '<input type="hidden" name="action" value="select_model">';
  455. print '<input type="hidden" name="step" value="2">';
  456. print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
  457. print '<table><tr><td colspan="2">';
  458. print $langs->trans("SelectExportFields").' ';
  459. $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
  460. print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
  461. print '</td></tr></table>';
  462. print '</form>';
  463. print '<table class="noborder" width="100%">';
  464. print '<tr class="liste_titre">';
  465. print '<td>'.$langs->trans("Entities").'</td>';
  466. print '<td>'.$langs->trans("ExportableFields").'</td>';
  467. print '<td width="100" align="center">';
  468. 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>";
  469. print '/';
  470. 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>";
  471. print '</td>';
  472. print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
  473. print '</tr>';
  474. // Champs exportables
  475. $fieldsarray=$objexport->array_export_fields[0];
  476. // Select request if all fields are selected
  477. $sqlmaxforexport=$objexport->build_sql(0, array(), array());
  478. // $this->array_export_module[0]=$module;
  479. // $this->array_export_code[0]=$module->export_code[$r];
  480. // $this->array_export_label[0]=$module->export_label[$r];
  481. // $this->array_export_sql[0]=$module->export_sql[$r];
  482. // $this->array_export_fields[0]=$module->export_fields_array[$r];
  483. // $this->array_export_entities[0]=$module->export_fields_entities[$r];
  484. // $this->array_export_alias[0]=$module->export_fields_alias[$r];
  485. $var=true;
  486. $i = 0;
  487. foreach($fieldsarray as $code=>$label)
  488. {
  489. $var=!$var;
  490. print "<tr ".$bc[$var].">";
  491. $i++;
  492. $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
  493. $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
  494. $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
  495. print '<td class="nowrap">';
  496. // If value of entityicon=entitylang='icon:Label'
  497. //print $code.'-'.$label.'-'.$entity;
  498. $tmparray=explode(':',$entityicon);
  499. if (count($tmparray) >=2)
  500. {
  501. $entityicon=$tmparray[0];
  502. $entitylang=$tmparray[1];
  503. }
  504. print img_object('',$entityicon).' '.$langs->trans($entitylang);
  505. print '</td>';
  506. $text=$langs->trans($label);
  507. $tablename=getablenamefromfield($code,$sqlmaxforexport);
  508. $htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
  509. $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
  510. if (! empty($objexport->array_export_examplevalues[0][$code]))
  511. {
  512. $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
  513. }
  514. if (isset($array_selected[$code]) && $array_selected[$code])
  515. {
  516. // Selected fields
  517. print '<td>&nbsp;</td>';
  518. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left('default', 0, 'style="max-width: 20px"').'</a></td>';
  519. print '<td>';
  520. //print $text.'-'.$htmltext."<br>";
  521. print $form->textwithpicto($text,$htmltext);
  522. //print ' ('.$code.')';
  523. print '</td>';
  524. }
  525. else
  526. {
  527. // Fields not selected
  528. print '<td>';
  529. //print $text.'-'.$htmltext."<br>";
  530. print $form->textwithpicto($text,$htmltext);
  531. //print ' ('.$code.')';
  532. print '</td>';
  533. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right('default', 0, 'style="max-width: 20px"').'</a></td>';
  534. print '<td>&nbsp;</td>';
  535. }
  536. print '</tr>';
  537. }
  538. print '</table>';
  539. print '</div>';
  540. /*
  541. * Barre d'action
  542. *
  543. */
  544. print '<div class="tabsAction">';
  545. if (count($array_selected))
  546. {
  547. // If filters exist
  548. if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
  549. {
  550. print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
  551. }
  552. else
  553. {
  554. print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
  555. }
  556. }
  557. else
  558. {
  559. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
  560. }
  561. print '</div>';
  562. }
  563. if ($step == 3 && $datatoexport)
  564. {
  565. if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
  566. {
  567. // Switch to step 2
  568. header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
  569. exit;
  570. }
  571. llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  572. /*
  573. * Affichage onglets
  574. */
  575. $h = 0;
  576. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
  577. $head[$h][1] = $langs->trans("Step")." 1";
  578. $h++;
  579. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
  580. $head[$h][1] = $langs->trans("Step")." 2";
  581. $h++;
  582. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
  583. $head[$h][1] = $langs->trans("Step")." 3";
  584. $hselected=$h;
  585. $h++;
  586. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  587. print '<table width="100%" class="border">';
  588. // Module
  589. print '<tr><td width="25%">'.$langs->trans("Module").'</td>';
  590. print '<td>';
  591. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  592. print $objexport->array_export_module[0]->getName();
  593. print '</td></tr>';
  594. // Lot de donnees a exporter
  595. print '<tr><td width="25%">'.$langs->trans("DatasetToExport").'</td>';
  596. print '<td>';
  597. $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
  598. $label=$objexport->array_export_label[0];
  599. //print $value.'-'.$icon.'-'.$label."<br>";
  600. print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
  601. print $label;
  602. print '</td></tr>';
  603. // Nbre champs exportes
  604. print '<tr><td width="25%">'.$langs->trans("ExportedFields").'</td>';
  605. $list='';
  606. foreach($array_selected as $code=>$value)
  607. {
  608. $list.=(! empty($list)?', ':'');
  609. $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):'');
  610. }
  611. print '<td>'.$list.'</td></tr>';
  612. print '</table>';
  613. print '<br>';
  614. // Combo list of export models
  615. print $langs->trans("SelectFilterFields").'<br>';
  616. // un formulaire en plus pour recuperer les filtres
  617. print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
  618. print '<table class="noborder" width="100%">';
  619. print '<tr class="liste_titre">';
  620. print '<td>'.$langs->trans("Entities").'</td>';
  621. //print '<td>'.$langs->trans("ExportableFields").'</td>';
  622. //print '<td align="center"></td>';
  623. print '<td>'.$langs->trans("ExportableFields").'</td>';
  624. print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
  625. print '</tr>';
  626. // Champs exportables
  627. $fieldsarray=$objexport->array_export_fields[0];
  628. // Champs filtrable
  629. $Typefieldsarray=$objexport->array_export_TypeFields[0];
  630. // valeur des filtres
  631. $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
  632. // Select request if all fields are selected
  633. $sqlmaxforexport=$objexport->build_sql(0, array(), array());
  634. $var=true;
  635. $i = 0;
  636. // on boucle sur les champs
  637. foreach($fieldsarray as $code => $label)
  638. {
  639. $var=!$var;
  640. print "<tr ".$bc[$var].">";
  641. $i++;
  642. $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
  643. $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
  644. $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
  645. print '<td class="nowrap">';
  646. // If value of entityicon=entitylang='icon:Label'
  647. $tmparray=explode(':',$entityicon);
  648. if (count($tmparray) >=2)
  649. {
  650. $entityicon=$tmparray[0];
  651. $entitylang=$tmparray[1];
  652. }
  653. print img_object('',$entityicon).' '.$langs->trans($entitylang);
  654. print '</td>';
  655. // Field name
  656. $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
  657. $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
  658. $text=$langs->trans($labelName);
  659. $tablename=getablenamefromfield($code,$sqlmaxforexport);
  660. $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
  661. $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
  662. if (! empty($objexport->array_export_examplevalues[0][$code]))
  663. {
  664. $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
  665. }
  666. print '<td>';
  667. print $form->textwithpicto($text,$htmltext);
  668. print '</td>';
  669. // Filter value
  670. print '<td>';
  671. if (! empty($Typefieldsarray[$code])) // Example: Text, List:c_country:label:rowid, Number, Boolean
  672. {
  673. $szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
  674. if ($szInfoFiltre) // Is there an info help for this filter ?
  675. {
  676. $tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
  677. print $form->textwithpicto($tmp, $szInfoFiltre);
  678. }
  679. else
  680. {
  681. print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
  682. }
  683. }
  684. print '</td>';
  685. print '</tr>';
  686. }
  687. print '</table>';
  688. print '</div>';
  689. /*
  690. * Barre d'action
  691. */
  692. print '<div class="tabsAction">';
  693. // il n'est pas obligatoire de filtrer les champs
  694. print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
  695. print '</div>';
  696. }
  697. if ($step == 4 && $datatoexport)
  698. {
  699. if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
  700. {
  701. // Switch to step 2
  702. header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
  703. exit;
  704. }
  705. asort($array_selected);
  706. llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  707. /*
  708. * Affichage onglets
  709. */
  710. $stepoffset=0;
  711. $h = 0;
  712. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
  713. $head[$h][1] = $langs->trans("Step")." 1";
  714. $h++;
  715. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
  716. $head[$h][1] = $langs->trans("Step")." 2";
  717. $h++;
  718. // If filters exist
  719. if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
  720. {
  721. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
  722. $head[$h][1] = $langs->trans("Step")." 3";
  723. $h++;
  724. $stepoffset++;
  725. }
  726. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
  727. $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
  728. $hselected=$h;
  729. $h++;
  730. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  731. print '<table width="100%" class="border">';
  732. // Module
  733. print '<tr><td width="25%">'.$langs->trans("Module").'</td>';
  734. print '<td>';
  735. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  736. print $objexport->array_export_module[0]->getName();
  737. print '</td></tr>';
  738. // Lot de donnees a exporter
  739. print '<tr><td width="25%">'.$langs->trans("DatasetToExport").'</td>';
  740. print '<td>';
  741. $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
  742. print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
  743. print $objexport->array_export_label[0];
  744. print '</td></tr>';
  745. // List of exported fields
  746. print '<tr><td width="25%">'.$langs->trans("ExportedFields").'</td>';
  747. $list='';
  748. foreach($array_selected as $code=>$value)
  749. {
  750. $list.=(! empty($list)?', ':'');
  751. $list.=$langs->trans($objexport->array_export_fields[0][$code]);
  752. }
  753. print '<td>'.$list.'</td>';
  754. print '</tr>';
  755. // List of filtered fiels
  756. if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
  757. {
  758. print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
  759. $list='';
  760. if (! empty($array_filtervalue))
  761. {
  762. foreach($array_filtervalue as $code=>$value)
  763. {
  764. if (isset($objexport->array_export_fields[0][$code]))
  765. {
  766. $list.=($list?', ':'');
  767. 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]:'');
  768. else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
  769. }
  770. }
  771. }
  772. print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
  773. print '</tr>';
  774. }
  775. print '</table>';
  776. print '<br>';
  777. // Select request if all fields are selected
  778. $sqlmaxforexport=$objexport->build_sql(0, array(), array());
  779. print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
  780. print '<table class="noborder" width="100%">';
  781. print '<tr class="liste_titre">';
  782. print '<td>'.$langs->trans("Entities").'</td>';
  783. print '<td>'.$langs->trans("ExportedFields").'</td>';
  784. print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
  785. //print '<td>&nbsp;</td>';
  786. //print '<td>'.$langs->trans("FieldsTitle").'</td>';
  787. print '</tr>';
  788. $var=true;
  789. foreach($array_selected as $code=>$value)
  790. {
  791. $var=!$var;
  792. print "<tr ".$bc[$var].">";
  793. $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
  794. $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
  795. $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
  796. print '<td class="nowrap">';
  797. // If value of entityicon=entitylang='icon:Label'
  798. $tmparray=explode(':',$entityicon);
  799. if (count($tmparray) >=2)
  800. {
  801. $entityicon=$tmparray[0];
  802. $entitylang=$tmparray[1];
  803. }
  804. print img_object('',$entityicon).' '.$langs->trans($entitylang);
  805. print '</td>';
  806. print '<td>';
  807. $text=$langs->trans($objexport->array_export_fields[0][$code]);
  808. $tablename=getablenamefromfield($code,$sqlmaxforexport);
  809. $htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
  810. $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
  811. if (! empty($objexport->array_export_examplevalues[0][$code]))
  812. {
  813. $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
  814. }
  815. print $form->textwithpicto($text,$htmltext);
  816. //print ' ('.$code.')';
  817. print '</td>';
  818. print '<td align="right" width="100">';
  819. print $value.' ';
  820. print '</td><td align="center" width="20">';
  821. if ($value < count($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
  822. if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
  823. print '</td>';
  824. //print '<td>&nbsp;</td>';
  825. //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
  826. print '</tr>';
  827. }
  828. print '</table>';
  829. print '</div>';
  830. /*
  831. * Barre d'action
  832. *
  833. */
  834. print '<div class="tabsAction">';
  835. if (count($array_selected))
  836. {
  837. print '<a class="butAction" href="export.php?step='.($step + 1).'&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
  838. }
  839. print '</div>';
  840. // Area for profils export
  841. if (count($array_selected))
  842. {
  843. print '<br>';
  844. print $langs->trans("SaveExportModel");
  845. print '<form class="nocellnopadd" action="export.php" method="post">';
  846. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  847. print '<input type="hidden" name="action" value="add_export_model">';
  848. print '<input type="hidden" name="step" value="'.$step.'">';
  849. print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
  850. print '<input type="hidden" name="hexa" value="'.$hexa.'">';
  851. print '<table class="noborder" width="100%">';
  852. print '<tr class="liste_titre">';
  853. print '<td>'.$langs->trans("ExportModelName").'</td>';
  854. print '<td>&nbsp;</td>';
  855. print '</tr>';
  856. $var=false;
  857. print '<tr '.$bc[$var].'>';
  858. print '<td><input name="export_name" size="32" value=""></td><td align="right">';
  859. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  860. print '</td></tr>';
  861. // List of existing export profils
  862. $sql = "SELECT rowid, label";
  863. $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
  864. $sql.= " WHERE type = '".$datatoexport."'";
  865. $sql.= " ORDER BY rowid";
  866. $resql = $db->query($sql);
  867. if ($resql)
  868. {
  869. $num = $db->num_rows($resql);
  870. $i = 0;
  871. $var=false;
  872. while ($i < $num)
  873. {
  874. $var=!$var;
  875. $obj = $db->fetch_object($resql);
  876. print '<tr '.$bc[$var].'><td>';
  877. print $obj->label;
  878. print '</td><td align="right">';
  879. print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">';
  880. print img_delete();
  881. print '</a>';
  882. print '</tr>';
  883. $i++;
  884. }
  885. }
  886. else {
  887. dol_print_error($this->db);
  888. }
  889. print '</table>';
  890. print '</form>';
  891. }
  892. }
  893. if ($step == 5 && $datatoexport)
  894. {
  895. if (count($array_selected) < 1) // This occurs when going back to page after sessecion expired
  896. {
  897. // Switch to step 2
  898. header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
  899. exit;
  900. }
  901. asort($array_selected);
  902. llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  903. /*
  904. * Affichage onglets
  905. */
  906. $h = 0;
  907. $stepoffset=0;
  908. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
  909. $head[$h][1] = $langs->trans("Step")." 1";
  910. $h++;
  911. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
  912. $head[$h][1] = $langs->trans("Step")." 2";
  913. $h++;
  914. // si le filtrage est parametre pour l'export ou pas
  915. if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
  916. {
  917. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
  918. $head[$h][1] = $langs->trans("Step")." 3";
  919. $h++;
  920. $stepoffset++;
  921. }
  922. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
  923. $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
  924. $h++;
  925. $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
  926. $head[$h][1] = $langs->trans("Step")." ".(4+$stepoffset);
  927. $hselected=$h;
  928. $h++;
  929. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  930. /*
  931. * Confirmation suppression fichier
  932. */
  933. if ($action == 'remove_file')
  934. {
  935. print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  936. }
  937. print '<table width="100%" class="border">';
  938. // Module
  939. print '<tr><td width="25%">'.$langs->trans("Module").'</td>';
  940. print '<td>';
  941. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  942. print $objexport->array_export_module[0]->getName();
  943. print '</td></tr>';
  944. // Lot de donnees a exporter
  945. print '<tr><td width="25%">'.$langs->trans("DatasetToExport").'</td>';
  946. print '<td>';
  947. $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
  948. print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
  949. print $objexport->array_export_label[0];
  950. print '</td></tr>';
  951. // List of exported fields
  952. print '<tr><td width="25%">'.$langs->trans("ExportedFields").'</td>';
  953. $list='';
  954. foreach($array_selected as $code=>$label)
  955. {
  956. $list.=(! empty($list)?', ':'');
  957. $list.=$langs->trans($objexport->array_export_fields[0][$code]);
  958. }
  959. print '<td>'.$list.'</td></tr>';
  960. // List of filtered fiels
  961. if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
  962. {
  963. print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
  964. $list='';
  965. if (! empty($array_filtervalue))
  966. {
  967. foreach($array_filtervalue as $code=>$value)
  968. {
  969. if (isset($objexport->array_export_fields[0][$code]))
  970. {
  971. $list.=($list?', ':'');
  972. 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]:'');
  973. else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
  974. }
  975. }
  976. }
  977. print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
  978. print '</tr>';
  979. }
  980. print '</table>';
  981. print '<br>';
  982. print $langs->trans("NowClickToGenerateToBuildExportFile").'<br>';
  983. // Liste des formats d'exports disponibles
  984. $var=true;
  985. print '<table class="noborder" width="100%">';
  986. print '<tr class="liste_titre">';
  987. print '<td colspan="2">'.$langs->trans("AvailableFormats").'</td>';
  988. print '<td>'.$langs->trans("LibraryUsed").'</td>';
  989. print '<td align="right">'.$langs->trans("LibraryVersion").'</td>';
  990. print '</tr>'."\n";
  991. $liste=$objmodelexport->liste_modeles($db);
  992. $listeall=$liste;
  993. foreach($listeall as $key => $val)
  994. {
  995. if (preg_match('/__\(Disabled\)__/',$listeall[$key]))
  996. {
  997. $listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]);
  998. unset($liste[$key]);
  999. }
  1000. $var=!$var;
  1001. print '<tr '.$bc[$var].'>';
  1002. print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).'</td>';
  1003. $text=$objmodelexport->getDriverDescForKey($key);
  1004. $label=$listeall[$key];
  1005. print '<td>'.$form->textwithpicto($label,$text).'</td>';
  1006. print '<td>'.$objmodelexport->getLibLabelForKey($key).'</td><td align="right">'.$objmodelexport->getLibVersionForKey($key).'</td></tr>'."\n";
  1007. }
  1008. print '</table>';
  1009. print '</div>';
  1010. print '<table width="100%">';
  1011. if ($sqlusedforexport && $user->admin)
  1012. {
  1013. print '<tr><td>';
  1014. print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport);
  1015. print '</td></tr>';
  1016. }
  1017. print '</table>';
  1018. print '<table width="100%"><tr><td width="50%">';
  1019. if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
  1020. // Affiche liste des documents
  1021. // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
  1022. $formfile->show_documents('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1);
  1023. print '</td><td width="50%">&nbsp;</td></tr>';
  1024. print '</table>';
  1025. }
  1026. print '<br>';
  1027. llxFooter();
  1028. $db->close();
  1029. 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
  1030. /**
  1031. * Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
  1032. *
  1033. * @param string $code Alias.Fieldname
  1034. * @param string $sqlmaxforexport SQL request to parse
  1035. * @return string Table name of field
  1036. */
  1037. function getablenamefromfield($code,$sqlmaxforexport)
  1038. {
  1039. $alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname'
  1040. $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
  1041. $newsql=$sqlmaxforexport;
  1042. $newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM
  1043. $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
  1044. if (preg_match($regexstring,$newsql,$reg))
  1045. {
  1046. return $reg[1]; // The tablename
  1047. }
  1048. else return '';
  1049. }