export.php 47 KB

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