PageRenderTime 99ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/export/export.php

https://bitbucket.org/speedealing/speedealing
PHP | 852 lines | 594 code | 140 blank | 118 comment | 93 complexity | dada2dffb0c45f2f8a4c748e9e0e2fc1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/exports/export.php
  21. * \ingroup export
  22. * \brief Pages of export Wizard
  23. */
  24. require_once '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/export/class/export.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/export/core/modules/export/modules_export.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  30. $langs->load("exports");
  31. // Everybody should be able to go on this page
  32. //if (! $user->admin)
  33. // accessforbidden();
  34. $entitytoicon = array(
  35. 'invoice' => 'bill',
  36. 'invoice_line' => 'bill',
  37. 'order' => 'order',
  38. 'order_line' => 'order',
  39. 'propal' => 'propal',
  40. 'propal_line' => 'propal',
  41. 'intervention' => 'intervention',
  42. 'inter_line' => 'intervention',
  43. 'member' => 'user',
  44. 'member_type' => 'group',
  45. 'subscription' => 'payment',
  46. 'payment' => 'payment',
  47. 'tax' => 'generic',
  48. 'tax_type' => 'generic',
  49. 'stock' => 'generic',
  50. 'other' => 'generic',
  51. 'account' => 'account',
  52. 'product' => 'product',
  53. 'warehouse' => 'stock',
  54. 'category' => 'category',
  55. );
  56. // Translation code
  57. $entitytolang = array(
  58. 'user' => 'User',
  59. 'company' => 'Company',
  60. 'contact' => 'Contact',
  61. 'invoice' => 'Bill',
  62. 'invoice_line' => 'InvoiceLine',
  63. 'order' => 'Order',
  64. 'order_line' => 'OrderLine',
  65. 'propal' => 'Proposal',
  66. 'propal_line' => 'ProposalLine',
  67. 'intervention' => 'Intervention',
  68. 'inter_line' => 'InterLine',
  69. 'member' => 'Member',
  70. 'member_type' => 'MemberType',
  71. 'subscription' => 'Subscription',
  72. 'tax' => 'SocialContribution',
  73. 'tax_type' => 'DictionnarySocialContributions',
  74. 'account' => 'BankTransactions',
  75. 'payment' => 'Payment',
  76. 'product' => 'Product',
  77. 'service' => 'Service',
  78. 'stock' => 'Stock',
  79. 'warehouse' => 'Warehouse',
  80. 'category' => 'Category',
  81. 'other' => 'Other',
  82. 'trip' => 'TripsAndExpenses'
  83. );
  84. $array_selected = dol_getcache("export_selected_fields");
  85. $datatoexport = GETPOST("datatoexport");
  86. $action = GETPOST("action");
  87. $step = GETPOST("step") ? GETPOST("step") : 1;
  88. $export_name = GETPOST("export_name");
  89. $hexa = GETPOST("hexa");
  90. $exportmodelid = GETPOST("exportmodelid");
  91. $field = GETPOST("field");
  92. $objexport = new Export($db);
  93. $objexport->load_arrays($user, $datatoexport);
  94. $objmodelexport = new ModeleExports();
  95. $form = new Form($db);
  96. $htmlother = new FormOther($db);
  97. $formfile = new FormFile($db);
  98. $sqlusedforexport = '';
  99. /*
  100. * Actions
  101. */
  102. if ($action == 'selectfield') {
  103. $fieldsarray = $objexport->array_export_fields[0];
  104. $fieldsentitiesarray = $objexport->array_export_entities[0];
  105. $fieldsdependenciesarray = $objexport->array_export_dependencies[0];
  106. if ($field == 'all') {
  107. foreach ($fieldsarray as $key => $val) {
  108. if (!empty($array_selected[$key]))
  109. continue; // If already selected, check next
  110. $array_selected[$key] = count($array_selected) + 1;
  111. //print_r($array_selected);
  112. dol_setcache("export_selected_fields",$array_selected);
  113. }
  114. }
  115. else {
  116. $warnings = array();
  117. $array_selected[$field] = count($array_selected) + 1; // We tag the key $field as "selected"
  118. // We check if there is a dependency
  119. if (!empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]])) {
  120. $tmp = $fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
  121. if (is_array($tmp))
  122. $listofdependencies = $tmp;
  123. else
  124. $listofdependencies = array($tmp);
  125. foreach ($listofdependencies as $fieldid) {
  126. if (empty($array_selected[$fieldid])) {
  127. $array_selected[$fieldid] = count($array_selected) + 1; // We tag the key $fieldid as "selected"
  128. $warnings[] = $langs->trans("ExportFieldAutomaticallyAdded", $langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
  129. }
  130. }
  131. }
  132. //print_r($array_selected);
  133. dol_setcache("export_selected_fields",$array_selected);
  134. }
  135. }
  136. if ($action == 'unselectfield') {
  137. if ($_GET["field"] == 'all') {
  138. $array_selected = array();
  139. dol_setcache("export_selected_fields",$array_selected);
  140. } else {
  141. unset($array_selected[$_GET["field"]]);
  142. // Renumber fields of array_selected (from 1 to nb_elements)
  143. asort($array_selected);
  144. $i = 0;
  145. $array_selected_save = $array_selected;
  146. foreach ($array_selected as $code => $value) {
  147. $i++;
  148. $array_selected[$code] = $i;
  149. //print "x $code x $i y<br>";
  150. }
  151. dol_setcache("export_selected_fields",$array_selected);
  152. }
  153. }
  154. if ($action == 'downfield' || $action == 'upfield') {
  155. $pos = $array_selected[$_GET["field"]];
  156. if ($action == 'downfield')
  157. $newpos = $pos + 1;
  158. if ($action == 'upfield')
  159. $newpos = $pos - 1;
  160. // Recherche code avec qui switcher
  161. $newcode = "";
  162. foreach ($array_selected as $code => $value) {
  163. if ($value == $newpos) {
  164. $newcode = $code;
  165. break;
  166. }
  167. }
  168. //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
  169. if ($newcode) { // Si newcode trouve (protection contre resoumission de page)
  170. $array_selected[$_GET["field"]] = $newpos;
  171. $array_selected[$newcode] = $pos;
  172. dol_setcache("export_selected_fields",$array_selected);
  173. }
  174. }
  175. if ($step == 1 || $action == 'cleanselect') {
  176. dol_setcache("export_selected_fields",array());
  177. $array_selected = array();
  178. }
  179. if ($action == 'remove_file') {
  180. $langs->load("other");
  181. $file = $conf->export->dir_temp . '/' . $user->id. '/' . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  182. $ret = dol_delete_file($file);
  183. }
  184. if ($action == 'builddoc') {
  185. // Build export file
  186. $result = $objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected);
  187. if ($result < 0) {
  188. $mesg = '<div class="error">' . $objexport->error . '</div>';
  189. } else {
  190. $mesg = '<div class="ok">' . $langs->trans("FileSuccessfullyBuilt") . '</div>';
  191. $sqlusedforexport = $objexport->sqlusedforexport;
  192. }
  193. }
  194. if ($action == 'deleteprof') {
  195. if ($_GET["id"]) {
  196. $objexport->fetch($_GET["id"]);
  197. $result = $objexport->delete($user);
  198. }
  199. }
  200. if ($action == 'add_export_model') {
  201. if ($export_name) {
  202. asort($array_selected);
  203. // Set save string
  204. $hexa = '';
  205. foreach ($array_selected as $key => $val) {
  206. if ($hexa)
  207. $hexa.=',';
  208. $hexa.=$key;
  209. }
  210. $objexport->model_name = $export_name;
  211. $objexport->datatoexport = $datatoexport;
  212. $objexport->hexa = $hexa;
  213. $result = $objexport->create($user);
  214. if ($result >= 0) {
  215. $mesg = '<div class="ok">' . $langs->trans("ExportModelSaved", $objexport->model_name) . '</div>';
  216. } else {
  217. $langs->load("errors");
  218. if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  219. $mesg = '<div class="error">' . $langs->trans("ErrorExportDuplicateProfil") . '</div>';
  220. }
  221. else
  222. $mesg = '<div class="error">' . $objexport->error . '</div>';
  223. }
  224. }
  225. else {
  226. $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")) . '</div>';
  227. }
  228. }
  229. if ($step == 2 && $action == 'select_model') {
  230. dol_setcache("export_selected_fields",array());
  231. $array_selected = array();
  232. $result = $objexport->fetch($exportmodelid);
  233. if ($result > 0) {
  234. $fieldsarray = explode(',', $objexport->hexa);
  235. $i = 1;
  236. foreach ($fieldsarray as $val) {
  237. $array_selected[$val] = $i;
  238. $i++;
  239. }
  240. dol_setcache("export_selected_fields",$array_selected);
  241. }
  242. }
  243. /*
  244. * View
  245. */
  246. if ($step == 1 || !$datatoexport) {
  247. llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  248. /*
  249. * Affichage onglets
  250. */
  251. $h = 0;
  252. $head[$h][0] = DOL_URL_ROOT . '/exports/export.php?step=1';
  253. $head[$h][1] = $langs->trans("Step") . " 1";
  254. $hselected = $h;
  255. $h++;
  256. /*
  257. $head[$h][0] = '';
  258. $head[$h][1] = $langs->trans("Step")." 2";
  259. $h++;
  260. */
  261. print_fiche_titre($langs->trans("Export"));
  262. print '<div class="with-padding">';
  263. print '<div class="columns">';
  264. print column_start();
  265. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  266. print '<table class="notopnoleftnoright" width="100%">';
  267. print $langs->trans("SelectExportDataSet") . '<br>';
  268. // Affiche les modules d'exports
  269. print '<table class="noborder" width="100%">';
  270. print '<tr class="liste_titre">';
  271. print '<td>' . $langs->trans("Module") . '</td>';
  272. print '<td>' . $langs->trans("ExportableDatas") . '</td>';
  273. print '<td>&nbsp;</td>';
  274. print '</tr>';
  275. $val = true;
  276. if (count($objexport->array_export_code)) {
  277. foreach ($objexport->array_export_code as $key => $value) {
  278. $val = !$val;
  279. print '<tr ' . $bc[$val] . '><td nospan="nospan">';
  280. //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
  281. print $objexport->array_export_module[$key]->getName();
  282. print '</td><td>';
  283. $icon = $objexport->array_export_icon[$key];
  284. $label = $objexport->array_export_label[$key];
  285. //print $value.'-'.$icon.'-'.$label."<br>";
  286. print img_object($objexport->array_export_module[$key]->getName(), $icon) . ' ';
  287. print $label;
  288. print '</td><td align="right">';
  289. if ($objexport->array_export_perms[$key]) {
  290. print '<a href="' . $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $objexport->array_export_code[$key] . '">' . img_picto($langs->trans("NewExport"), 'filenew') . '</a>';
  291. } else {
  292. print $langs->trans("NotEnoughPermissions");
  293. }
  294. print '</td></tr>';
  295. }
  296. } else {
  297. print '<tr><td ' . $bc[false] . ' colspan="3">' . $langs->trans("NoExportableData") . '</td></tr>';
  298. }
  299. print '</table>';
  300. print '</table>';
  301. print '</div>';
  302. print column_end();
  303. print '</div></div>';
  304. if ($mesg)
  305. print $mesg;
  306. }
  307. if ($step == 2 && $datatoexport) {
  308. llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  309. /*
  310. * Affichage onglets
  311. */
  312. $h = 0;
  313. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=1';
  314. $head[$h][1] = $langs->trans("Step") . " 1";
  315. $h++;
  316. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport;
  317. $head[$h][1] = $langs->trans("Step") . " 2";
  318. $hselected = $h;
  319. $h++;
  320. print_fiche_titre($langs->trans("Export"));
  321. print '<div class="with-padding">';
  322. print '<div class="columns">';
  323. print column_start();
  324. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  325. print '<table width="100%" class="border">';
  326. // Module
  327. print '<tr><td width="25%">' . $langs->trans("Module") . '</td>';
  328. print '<td>';
  329. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  330. print $objexport->array_export_module[0]->getName();
  331. print '</td></tr>';
  332. // Lot de donnees a exporter
  333. print '<tr><td width="25%">' . $langs->trans("DatasetToExport") . '</td>';
  334. print '<td>';
  335. $icon = $objexport->array_export_icon[0];
  336. $label = $objexport->array_export_label[0];
  337. //print $value.'-'.$icon.'-'.$label."<br>";
  338. print img_object($objexport->array_export_module[0]->getName(), $icon) . ' ';
  339. print $label;
  340. print '</td></tr>';
  341. print '</table>';
  342. print '<br>';
  343. if ($warnings)
  344. dol_htmloutput_mesg('', $warnings, 'warning');
  345. // Combo list of export models
  346. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  347. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  348. print '<input type="hidden" name="action" value="select_model">';
  349. print '<input type="hidden" name="step" value="2">';
  350. print '<input type="hidden" name="datatoexport" value="' . $datatoexport . '">';
  351. print '<table><tr><td colspan="2">';
  352. print $langs->trans("SelectExportFields") . ' ';
  353. $htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1);
  354. print '<input type="submit" class="button" value="' . $langs->trans("Select") . '">';
  355. print '</td></tr></table>';
  356. print '</form>';
  357. print '<table class="noborder" width="100%">';
  358. print '<tr class="liste_titre">';
  359. print '<td>' . $langs->trans("Entities") . '</td>';
  360. print '<td>' . $langs->trans("ExportableFields") . '</td>';
  361. print '<td width="100" align="center">';
  362. print '<a title=' . $langs->trans("All") . ' alt=' . $langs->trans("All") . ' href="' . $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport . '&action=selectfield&field=all">' . $langs->trans("All") . "</a>";
  363. print '/';
  364. print '<a title=' . $langs->trans("None") . ' alt=' . $langs->trans("None") . ' href="' . $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport . '&action=unselectfield&field=all">' . $langs->trans("None") . "</a>";
  365. print '</td>';
  366. print '<td width="44%">' . $langs->trans("ExportedFields") . '</td>';
  367. print '</tr>';
  368. // Champs exportables
  369. $fieldsarray = $objexport->array_export_fields[0];
  370. // Select request if all fields are selected
  371. $sqlmaxforexport = $objexport->build_sql(0, array());
  372. // $this->array_export_module[0]=$module;
  373. // $this->array_export_code[0]=$module->export_code[$r];
  374. // $this->array_export_label[0]=$module->export_label[$r];
  375. // $this->array_export_sql[0]=$module->export_sql[$r];
  376. // $this->array_export_fields[0]=$module->export_fields_array[$r];
  377. // $this->array_export_entities[0]=$module->export_fields_entities[$r];
  378. // $this->array_export_alias[0]=$module->export_fields_alias[$r];
  379. $var = true;
  380. $i = 0;
  381. foreach ($fieldsarray as $code => $label) {
  382. $var = !$var;
  383. print "<tr $bc[$var]>";
  384. $i++;
  385. $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
  386. $entityicon = $entitytoicon[$entity] ? $entitytoicon[$entity] : $entity;
  387. $entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $entity;
  388. print '<td nowrap="nowrap">';
  389. // If value of entityicon=entitylang='icon:Label'
  390. $tmparray = explode(':', $entityicon);
  391. if (count($tmparray) >= 2) {
  392. $entityicon = $tmparray[0];
  393. $entitylang = $tmparray[1];
  394. }
  395. print img_object('', $entityicon) . ' ' . $langs->trans($entitylang);
  396. print '</td>';
  397. $text = $langs->trans($label);
  398. $tablename = getablenamefromfield($code, $sqlmaxforexport);
  399. $htmltext = '<b>' . $langs->trans("Name") . ":</b> " . $text . '<br>';
  400. $htmltext.='<b>' . $langs->trans("Table") . " -> " . $langs->trans("Field") . ":</b> " . $tablename . " -> " . preg_replace('/^.*\./', '', $code) . "<br>";
  401. if ((isset($array_selected[$code]) && $array_selected[$code]) || $modelchoice == 1) {
  402. // Selected fields
  403. print '<td>&nbsp;</td>';
  404. print '<td align="center"><a href="' . $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport . '&action=unselectfield&field=' . $code . '">' . img_left() . '</a></td>';
  405. print '<td>';
  406. //print $text.'-'.$htmltext."<br>";
  407. print $form->textwithpicto($text, $htmltext);
  408. //print ' ('.$code.')';
  409. print '</td>';
  410. $bit = 1;
  411. } else {
  412. // Fields not selected
  413. print '<td>';
  414. //print $text.'-'.$htmltext."<br>";
  415. print $form->textwithpicto($text, $htmltext);
  416. //print ' ('.$code.')';
  417. print '</td>';
  418. print '<td align="center"><a href="' . $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport . '&action=selectfield&field=' . $code . '">' . img_right() . '</a></td>';
  419. print '<td>&nbsp;</td>';
  420. $bit = 0;
  421. }
  422. print '</tr>';
  423. $save_select.=$bit;
  424. }
  425. print '</table>';
  426. print '</div>';
  427. if ($mesg)
  428. print $mesg;
  429. /*
  430. * Barre d'action
  431. *
  432. */
  433. print '<div class="tabsAction">';
  434. if (count($array_selected)) {
  435. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?step=3&datatoexport=' . $datatoexport . '">' . $langs->trans("NextStep") . '</a>';
  436. } else {
  437. print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("SelectAtLeastOneField")) . '">' . $langs->trans("NextStep") . '</a>';
  438. }
  439. print '</div>';
  440. print column_end();
  441. print '</div></div>';
  442. }
  443. if ($step == 3 && $datatoexport) {
  444. asort($array_selected);
  445. llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  446. /*
  447. * Affichage onglets
  448. */
  449. $h = 0;
  450. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=1';
  451. $head[$h][1] = $langs->trans("Step") . " 1";
  452. $h++;
  453. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport;
  454. $head[$h][1] = $langs->trans("Step") . " 2";
  455. $h++;
  456. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=3&datatoexport=' . $datatoexport;
  457. $head[$h][1] = $langs->trans("Step") . " 3";
  458. $hselected = $h;
  459. $h++;
  460. print_fiche_titre($langs->trans("Export"));
  461. print '<div class="with-padding">';
  462. print '<div class="columns">';
  463. print column_start();
  464. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  465. print '<table width="100%" class="border">';
  466. // Module
  467. print '<tr><td width="25%">' . $langs->trans("Module") . '</td>';
  468. print '<td>';
  469. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  470. print $objexport->array_export_module[0]->getName();
  471. print '</td></tr>';
  472. // Lot de donnees a exporter
  473. print '<tr><td width="25%">' . $langs->trans("DatasetToExport") . '</td>';
  474. print '<td>';
  475. print img_object($objexport->array_export_module[0]->getName(), $objexport->array_export_icon[0]) . ' ';
  476. print $objexport->array_export_label[0];
  477. print '</td></tr>';
  478. // Nbre champs exportes
  479. print '<tr><td width="25%">' . $langs->trans("ExportedFields") . '</td>';
  480. $list = '';
  481. foreach ($array_selected as $code => $value) {
  482. $list.=($list ? ', ' : '');
  483. $list.=$langs->trans($objexport->array_export_fields[0][$code]);
  484. }
  485. print '<td>' . $list . '</td></tr>';
  486. print '</table>';
  487. print '<br>';
  488. // Select request if all fields are selected
  489. $sqlmaxforexport = $objexport->build_sql(0, array());
  490. print $langs->trans("ChooseFieldsOrdersAndTitle") . '<br>';
  491. print '<table class="noborder" width="100%">';
  492. print '<tr class="liste_titre">';
  493. print '<td>' . $langs->trans("Entities") . '</td>';
  494. print '<td>' . $langs->trans("ExportedFields") . '</td>';
  495. print '<td align="right" colspan="2">' . $langs->trans("Position") . '</td>';
  496. //print '<td>&nbsp;</td>';
  497. //print '<td>'.$langs->trans("FieldsTitle").'</td>';
  498. print '</tr>';
  499. $var = true;
  500. foreach ($array_selected as $code => $value) {
  501. $var = !$var;
  502. print "<tr $bc[$var]>";
  503. $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
  504. $entityicon = $entitytoicon[$entity] ? $entitytoicon[$entity] : $entity;
  505. $entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $entity;
  506. print '<td nowrap="nowrap">';
  507. // If value of entityicon=entitylang='icon:Label'
  508. $tmparray = explode(':', $entityicon);
  509. if (count($tmparray) >= 2) {
  510. $entityicon = $tmparray[0];
  511. $entitylang = $tmparray[1];
  512. }
  513. print img_object('', $entityicon) . ' ' . $langs->trans($entitylang);
  514. print '</td>';
  515. print '<td>';
  516. $text = $langs->trans($objexport->array_export_fields[0][$code]);
  517. $tablename = getablenamefromfield($code, $sqlmaxforexport);
  518. $htmltext = '<b>' . $langs->trans("Name") . ":</b> " . $text . '<br>';
  519. $htmltext.='<b>' . $langs->trans("Table") . " -> " . $langs->trans("Field") . ":</b> " . $tablename . " -> " . preg_replace('/^.*\./', '', $code) . "<br>";
  520. print $form->textwithpicto($text, $htmltext);
  521. //print ' ('.$code.')';
  522. print '</td>';
  523. print '<td align="right" width="100">';
  524. print $value . ' ';
  525. print '</td><td align="center" width="20">';
  526. if ($value < count($array_selected))
  527. print '<a href="' . $_SERVER["PHP_SELF"] . '?step=3&datatoexport=' . $datatoexport . '&action=downfield&field=' . $code . '">' . img_down() . '</a>';
  528. if ($value > 1)
  529. print '<a href="' . $_SERVER["PHP_SELF"] . '?step=3&datatoexport=' . $datatoexport . '&action=upfield&field=' . $code . '">' . img_up() . '</a>';
  530. print '</td>';
  531. //print '<td>&nbsp;</td>';
  532. //print '<td>'.$langs->trans($objexport->array_export_fields[0][$code]).'</td>';
  533. print '</tr>';
  534. }
  535. print '</table>';
  536. print '</div>';
  537. if ($mesg)
  538. print $mesg;
  539. /*
  540. * Barre d'action
  541. *
  542. */
  543. print '<div class="tabsAction">';
  544. if (count($array_selected)) {
  545. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?step=4&datatoexport=' . $datatoexport . '">' . $langs->trans("NextStep") . '</a>';
  546. }
  547. print '</div>';
  548. // Area for profils export
  549. if (count($array_selected)) {
  550. print '<br>';
  551. print $langs->trans("SaveExportModel");
  552. print '<form class="nocellnopadd" action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  553. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  554. print '<input type="hidden" name="action" value="add_export_model">';
  555. print '<input type="hidden" name="step" value="' . $step . '">';
  556. print '<input type="hidden" name="datatoexport" value="' . $datatoexport . '">';
  557. print '<input type="hidden" name="hexa" value="' . $hexa . '">';
  558. print '<table class="noborder" width="100%">';
  559. print '<tr class="liste_titre">';
  560. print '<td>' . $langs->trans("ExportModelName") . '</td>';
  561. print '<td>&nbsp;</td>';
  562. print '</tr>';
  563. $var = false;
  564. print '<tr ' . $bc[$var] . '>';
  565. print '<td><input name="export_name" size="32" value=""></td><td align="right">';
  566. print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
  567. print '</td></tr>';
  568. // List of existing export profils
  569. $sql = "SELECT rowid, label";
  570. $sql.= " FROM " . MAIN_DB_PREFIX . "export_model";
  571. $sql.= " WHERE type = '" . $datatoexport . "'";
  572. $sql.= " ORDER BY rowid";
  573. $resql = $db->query($sql);
  574. if ($resql) {
  575. $num = $db->num_rows($resql);
  576. $i = 0;
  577. $var = false;
  578. while ($i < $num) {
  579. $var = !$var;
  580. $obj = $db->fetch_object($resql);
  581. print '<tr ' . $bc[$var] . '><td>';
  582. print $obj->label;
  583. print '</td><td align="right">';
  584. print '<a href="' . $_SERVER["PHP_SELF"] . '?step=' . $step . '&datatoexport=' . $datatoexport . '&action=deleteprof&id=' . $obj->rowid . '">';
  585. print img_delete();
  586. print '</a>';
  587. print '</tr>';
  588. $i++;
  589. }
  590. } else {
  591. dol_print_error($this->db);
  592. }
  593. print '</table>';
  594. print '</form>';
  595. }
  596. print column_end();
  597. print '</div></div>';
  598. }
  599. if ($step == 4 && $datatoexport) {
  600. asort($array_selected);
  601. llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
  602. /*
  603. * Affichage onglets
  604. */
  605. $h = 0;
  606. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=1';
  607. $head[$h][1] = $langs->trans("Step") . " 1";
  608. $h++;
  609. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=2&datatoexport=' . $datatoexport;
  610. $head[$h][1] = $langs->trans("Step") . " 2";
  611. $h++;
  612. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=3&datatoexport=' . $datatoexport;
  613. $head[$h][1] = $langs->trans("Step") . " 3";
  614. $h++;
  615. $head[$h][0] = $_SERVER["PHP_SELF"] . '?step=4&datatoexport=' . $datatoexport;
  616. $head[$h][1] = $langs->trans("Step") . " 4";
  617. $hselected = $h;
  618. $h++;
  619. print_fiche_titre($langs->trans("Export"));
  620. print '<div class="with-padding">';
  621. print '<div class="columns">';
  622. print column_start();
  623. dol_fiche_head($head, $hselected, $langs->trans("NewExport"));
  624. print '<table width="100%" class="border">';
  625. // Module
  626. print '<tr><td width="25%">' . $langs->trans("Module") . '</td>';
  627. print '<td>';
  628. //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
  629. print $objexport->array_export_module[0]->getName();
  630. print '</td></tr>';
  631. // Lot de donnees a exporter
  632. print '<tr><td width="25%">' . $langs->trans("DatasetToExport") . '</td>';
  633. print '<td>';
  634. print img_object($objexport->array_export_module[0]->getName(), $objexport->array_export_icon[0]) . ' ';
  635. print $objexport->array_export_label[0];
  636. print '</td></tr>';
  637. // Nbre champs exportes
  638. print '<tr><td width="25%">' . $langs->trans("ExportedFields") . '</td>';
  639. $list = '';
  640. foreach ($array_selected as $code => $label) {
  641. $list.=($list ? ', ' : '');
  642. $list.=$langs->trans($objexport->array_export_fields[0][$code]);
  643. }
  644. print '<td>' . $list . '</td></tr>';
  645. print '</table>';
  646. print '<br>';
  647. print $langs->trans("NowClickToGenerateToBuildExportFile") . '<br>';
  648. // Liste des formats d'exports disponibles
  649. $var = true;
  650. print '<table class="noborder" width="100%">';
  651. print '<tr class="liste_titre">';
  652. print '<td colspan="2">' . $langs->trans("AvailableFormats") . '</td>';
  653. print '<td>' . $langs->trans("LibraryUsed") . '</td>';
  654. print '<td align="right">' . $langs->trans("LibraryVersion") . '</td>';
  655. print '</tr>' . "\n";
  656. $liste = $objmodelexport->liste_modeles($db);
  657. foreach ($liste as $key => $val) {
  658. $var = !$var;
  659. print '<tr ' . $bc[$var] . '>';
  660. print '<td width="16">' . img_picto_common($key, $objmodelexport->getPicto($key)) . '</td>';
  661. $text = $objmodelexport->getDriverDesc($key);
  662. print '<td>' . $form->textwithpicto($objmodelexport->getDriverLabel($key), $text) . '</td>';
  663. print '<td>' . $objmodelexport->getLibLabel($key) . '</td><td align="right">' . $objmodelexport->getLibVersion($key) . '</td></tr>' . "\n";
  664. }
  665. print '</table>';
  666. print '</div>';
  667. print '<table width="100%">';
  668. if ($mesg) {
  669. print '<tr><td colspan="2">';
  670. print $mesg;
  671. print '</td></tr>';
  672. }
  673. if ($sqlusedforexport && $user->admin) {
  674. print '<tr><td>';
  675. print info_admin($langs->trans("SQLUsedForExport") . ':<br> ' . $sqlusedforexport);
  676. print '</td></tr>';
  677. }
  678. print '</table>';
  679. print column_end();
  680. if (!is_dir($conf->export->dir_temp))
  681. dol_mkdir($conf->export->dir_temp);
  682. // Affiche liste des documents
  683. // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
  684. print column_start("six");
  685. $formfile->show_documents('export', '', $conf->export->dir_temp . '/' . $user->id, $_SERVER["PHP_SELF"] . '?step=4&datatoexport=' . $datatoexport, $liste, 1, (!empty($_POST['model']) ? $_POST['model'] : 'csv'), 1, 1);
  686. print column_end();
  687. print '</div></div>';
  688. }
  689. print '<br>';
  690. $db->close();
  691. llxFooter();
  692. /**
  693. * Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
  694. *
  695. * @param string $code Alias.Fieldname
  696. * @param string $sqlmaxforexport SQL request to parse
  697. * @return string Table name of field
  698. */
  699. function getablenamefromfield($code, $sqlmaxforexport) {
  700. $newsql = $sqlmaxforexport;
  701. $newsql = preg_replace('/^(.*) FROM /i', '', $newsql);
  702. $newsql = preg_replace('/WHERE (.*)$/i', '', $newsql); // We must keep the ' ' before WHERE
  703. $alias = preg_replace('/\.(.*)$/i', '', $code);
  704. //print $newsql.' '.$alias;
  705. $regexstring = '/([a-zA-Z_]+) as ' . $alias . '[, \)]/i';
  706. if (preg_match($regexstring, $newsql, $reg)) {
  707. return $reg[1];
  708. }
  709. else
  710. return '';
  711. }
  712. ?>