export.php 47 KB

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