* Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos GarcĂ­a * Copyright (C) 2012 Charles-Fr BENKE * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/exports/export.php * \ingroup export * \brief Pages of export Wizard */ require_once '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/exports/class/export.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $langs->load("exports"); // Everybody should be able to go on this page //if (! $user->admin) // accessforbidden(); $entitytoicon = array( 'invoice' => 'bill', 'invoice_line' => 'bill', 'order' => 'order', 'order_line' => 'order', 'propal' => 'propal', 'propal_line' => 'propal', 'intervention' => 'intervention', 'inter_line' => 'intervention', 'member' => 'user', 'member_type' => 'group', 'subscription' => 'payment', 'payment' => 'payment', 'tax' => 'generic', 'tax_type' => 'generic', 'stock' => 'generic', 'other' => 'generic', 'account' => 'account', 'product' => 'product', 'warehouse' => 'stock', 'category' => 'category', ); // Translation code $entitytolang = array( 'user' => 'User', 'company' => 'Company', 'contact' => 'Contact', 'invoice' => 'Bill', 'invoice_line' => 'InvoiceLine', 'order' => 'Order', 'order_line' => 'OrderLine', 'propal' => 'Proposal', 'propal_line' => 'ProposalLine', 'intervention' => 'Intervention', 'inter_line' => 'InterLine', 'member' => 'Member', 'member_type' => 'MemberType', 'subscription' => 'Subscription', 'tax' => 'SocialContribution', 'tax_type' => 'DictionnarySocialContributions', 'account' => 'BankTransactions', 'payment' => 'Payment', 'product' => 'Product', 'service' => 'Service', 'stock' => 'Stock', 'warehouse' => 'Warehouse', 'category' => 'Category', 'other' => 'Other', 'trip' => 'TripsAndExpenses' ); $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array(); $array_filtered=isset($_SESSION["export_filtered_fields"])?$_SESSION["export_filtered_fields"]:array(); $array_filtervalue=isset($_SESSION["export_FilterValue_fields"])?$_SESSION["export_FilterValue_fields"]:array(); $datatoexport=GETPOST("datatoexport"); $action=GETPOST('action', 'alpha'); $confirm=GETPOST('confirm', 'alpha'); $step=GETPOST("step")?GETPOST("step"):1; $export_name=GETPOST("export_name"); $hexa=GETPOST("hexa"); $exportmodelid=GETPOST("exportmodelid"); $field=GETPOST("field"); $objexport=new Export($db); $objexport->load_arrays($user,$datatoexport); $objmodelexport=new ModeleExports(); $form = new Form($db); $htmlother = new FormOther($db); $formfile = new FormFile($db); $sqlusedforexport=''; $upload_dir = $conf->export->dir_temp.'/'.$user->id; /* * Actions */ if ($action=='selectfield') { $fieldsarray=$objexport->array_export_fields[0]; $fieldsentitiesarray=$objexport->array_export_entities[0]; $fieldsdependenciesarray=$objexport->array_export_dependencies[0]; if ($field=='all') { foreach($fieldsarray as $key=>$val) { if (! empty($array_selected[$key])) continue; // If already selected, check next $array_selected[$key]=count($array_selected)+1; //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; } } else { $warnings=array(); $array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected" // We check if there is a dependency if (! empty($fieldsentitiesarray[$field]) && ! empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]])) { $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid')) if (is_array($tmp)) $listofdependencies=$tmp; else $listofdependencies=array($tmp); foreach($listofdependencies as $fieldid) { if (empty($array_selected[$fieldid])) { $array_selected[$fieldid]=count($array_selected)+1; // We tag the key $fieldid as "selected" $warnings[]=$langs->trans("ExportFieldAutomaticallyAdded",$langs->transnoentitiesnoconv($fieldsarray[$fieldid])); } } } //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; } } if ($action=='unselectfield') { if ($_GET["field"]=='all') { $array_selected=array(); $_SESSION["export_selected_fields"]=$array_selected; } else { unset($array_selected[$_GET["field"]]); // Renumber fields of array_selected (from 1 to nb_elements) asort($array_selected); $i=0; $array_selected_save=$array_selected; foreach($array_selected as $code=>$value) { $i++; $array_selected[$code]=$i; //print "x $code x $i y
"; } $_SESSION["export_selected_fields"]=$array_selected; } } if ($action=='selectFilterfield') { if ($_GET["field"]=='all') { $fieldsarray=$objexport->array_export_TypeFields[0]; foreach($fieldsarray as $key=>$val) { if (! empty($array_filtered[$key])) continue; // If already selected, select next $array_filtered[$key]=count($array_filtered)+1; //print_r($array_selected); $_SESSION["export_filtered_fields"]=$array_filtered; } } else { $array_filtered[$_GET["field"]]=count($array_filtered)+1; //print_r($array_selected); $_SESSION["export_filtered_fields"]=$array_filtered; } } if ($action=='unselectFilterfield') { if ($_GET["field"]=='all') { $array_filtered=array(); $_SESSION["export_filtered_fields"]=$array_filtered; } else { unset($array_filtered[$_GET["field"]]); // Renumber fields of array_selected (from 1 to nb_elements) asort($array_filtered); $i=0; $array_filterted_save=$array_filtered; foreach($array_filtered as $code=>$value) { $i++; $array_filtered[$code]=$i; //print "x $code x $i y
"; } $_SESSION["export_filtered_fields"]=$array_filtered; } } if ($action=='downfield' || $action=='upfield') { $pos=$array_selected[$_GET["field"]]; if ($action=='downfield') $newpos=$pos+1; if ($action=='upfield') $newpos=$pos-1; // Recherche code avec qui switcher $newcode=""; foreach($array_selected as $code=>$value) { if ($value == $newpos) { $newcode=$code; break; } } //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)"); if ($newcode) // Si newcode trouve (protection contre resoumission de page) { $array_selected[$_GET["field"]]=$newpos; $array_selected[$newcode]=$pos; $_SESSION["export_selected_fields"]=$array_selected; } } if ($step == 1 || $action == 'cleanselect') { $_SESSION["export_selected_fields"]=array(); $_SESSION["export_FilterValue_fields"]=array(); $_SESSION["export_filtered_fields"]=array(); $array_selected=array(); $array_filtervalue=array(); $array_filtered=array(); } if ($action == 'builddoc') { // Build export file $result=$objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected, $array_filtervalue, $array_filtered); if ($result < 0) { $mesg='
'.$objexport->error.'
'; } else { $mesg='
'.$langs->trans("FileSuccessfullyBuilt").'
'; $sqlusedforexport=$objexport->sqlusedforexport; } } // Delete file if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes') { $file = $upload_dir . "/" . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). $ret=dol_delete_file($file); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport); exit; } if ($action == 'deleteprof') { if ($_GET["id"]) { $objexport->fetch($_GET["id"]); $result=$objexport->delete($user); } } if ($action == 'add_export_model') { if ($export_name) { asort($array_selected); // Set save string $hexa=''; foreach($array_selected as $key=>$val) { if ($hexa) $hexa.=','; $hexa.=$key; } $hexafilter=''; $hexafiltervalue=''; foreach($array_filtered as $key=>$val) { if ($hexafilter) $hexafilter.=','; if ($hexafilter) $hexafiltervalue.=','; $hexafilter.=$key; $hexafiltervalue.=$array_filtervalue[$key]; } $objexport->model_name = $export_name; $objexport->datatoexport = $datatoexport; $objexport->hexa = $hexa; $objexport->hexafilter = $hexafilter; $objexport->hexafiltervalue = $hexafiltervalue; $result = $objexport->create($user); if ($result >= 0) { $mesg='
'.$langs->trans("ExportModelSaved",$objexport->model_name).'
'; } else { $langs->load("errors"); if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $mesg='
'.$langs->trans("ErrorExportDuplicateProfil").'
'; } else $mesg='
'.$objexport->error.'
'; } } else { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("ExportModelName")).'
'; } } if ($step == 2 && $action == 'select_model') { $_SESSION["export_selected_fields"]=array(); $_SESSION["export_filtered_fields"]=array(); $_SESSION["export_FilterValue_fields"]=array(); $array_selected=array(); $array_filtered=array(); $array_filtervalue=array(); $result = $objexport->fetch($exportmodelid); if ($result > 0) { $fieldsarray=explode(',',$objexport->hexa); $i=1; foreach($fieldsarray as $val) { $array_selected[$val]=$i; $i++; } $_SESSION["export_selected_fields"]=$array_selected; $fieldsarray=explode(',',$objexport->hexafilter); $fieldsarrayvalue=explode(',',$objexport->hexafiltervalue); $i=1; foreach($fieldsarray as $val) { $array_filtered[$val]=$i; $array_filtervalue[$val]=$fieldsarrayvalue[$i-1]; $i++; } $_SESSION["export_filtered_fields"]=$array_filtered; $_SESSION["export_FilterValue_fields"]=$array_filtervalue; } } // recuperation du filtrage issu du formulaire if ($step == 4 && $action == 'submitFormField') { // on boucle sur les champs selectionne pour recuperer la valeur if (is_array($objexport->array_export_TypeFields[0])) { $_SESSION["export_FilterValue_fields"]=array(); foreach($array_filtered as $code=>$value) { //print $code."=".$_POST[$objexport->array_export_fields[0][$code]]; $objexport->array_export_FilterValue[0][$code] = (isset($objexport->array_export_fields[0][$code])?$_POST[$objexport->array_export_fields[0][$code]]:''); } $_SESSION["export_FilterValue_fields"]=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); $array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); } } /* * View */ if ($step == 1 || ! $datatoexport) { llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; $head[$h][1] = $langs->trans("Step")." 1"; $hselected=$h; $h++; /* $head[$h][0] = ''; $head[$h][1] = $langs->trans("Step")." 2"; $h++; */ dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; print $langs->trans("SelectExportDataSet").'
'; // Affiche les modules d'exports print '
'; print ''; print ''; print ''; print ''; print ''; $val=true; if (count($objexport->array_export_code)) { foreach ($objexport->array_export_code as $key => $value) { $val=!$val; print ''; } } else { print ''; } print '
'.$langs->trans("Module").''.$langs->trans("ExportableDatas").' 
'; //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' '; print $objexport->array_export_module[$key]->getName(); print ''; $icon=$objexport->array_export_icon[$key]; $label=$objexport->array_export_label[$key]; //print $value.'-'.$icon.'-'.$label."
"; print img_object($objexport->array_export_module[$key]->getName(),$icon).' '; print $label; print '
'; if ($objexport->array_export_perms[$key]) { print ''.img_picto($langs->trans("NewExport"),'filenew').''; } else { print $langs->trans("NotEnoughPermissions"); } print '
'.$langs->trans("NoExportableData").'
'; print ''; print ''; if ($mesg) print $mesg; } if ($step == 2 && $datatoexport) { llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; $head[$h][1] = $langs->trans("Step")." 1"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 2"; $hselected=$h; $h++; dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; // Module print ''; print ''; // Lot de donnees a exporter print ''; print ''; print '
'.$langs->trans("Module").''; //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; print $objexport->array_export_module[0]->getName(); print '
'.$langs->trans("DatasetToExport").''; $icon=$objexport->array_export_icon[0]; $label=$objexport->array_export_label[0]; //print $value.'-'.$icon.'-'.$label."
"; print img_object($objexport->array_export_module[0]->getName(),$icon).' '; print $label; print '
'; print '
'; if ($warnings) dol_htmloutput_mesg('',$warnings,'warning'); // Combo list of export models print '
'; print ''; print ''; print ''; print ''; print '
'; print $langs->trans("SelectExportFields").' '; $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); print ''; print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Champs exportables $fieldsarray=$objexport->array_export_fields[0]; // Select request if all fields are selected $sqlmaxforexport=$objexport->build_sql(0, array(), array(), array()); // $this->array_export_module[0]=$module; // $this->array_export_code[0]=$module->export_code[$r]; // $this->array_export_label[0]=$module->export_label[$r]; // $this->array_export_sql[0]=$module->export_sql[$r]; // $this->array_export_fields[0]=$module->export_fields_array[$r]; // $this->array_export_entities[0]=$module->export_fields_entities[$r]; // $this->array_export_alias[0]=$module->export_fields_alias[$r]; $var=true; $i = 0; foreach($fieldsarray as $code=>$label) { $var=!$var; print ""; $i++; $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity); $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity); print ''; $text=$langs->trans($label); $tablename=getablenamefromfield($code,$sqlmaxforexport); $htmltext =''.$langs->trans("Name").": ".$text.'
'; $htmltext.=''.$langs->trans("Table")." -> ".$langs->trans("Field").": ".$tablename." -> ".preg_replace('/^.*\./','',$code)."
"; if (isset($array_selected[$code]) && $array_selected[$code]) { // Selected fields print ''; print ''; print ''; //$bit=1; FIXME not used ? } else { // Fields not selected print ''; print ''; print ''; //$bit=0; FIXME not used ? } print ''; //$save_select.=$bit; FIXME not used ? } print '
'.$langs->trans("Entities").''.$langs->trans("ExportableFields").''; print ''.$langs->trans("All").""; print '/'; print ''.$langs->trans("None").""; print ''.$langs->trans("ExportedFields").'
'; // If value of entityicon=entitylang='icon:Label' $tmparray=explode(':',$entityicon); if (count($tmparray) >=2) { $entityicon=$tmparray[0]; $entitylang=$tmparray[1]; } print img_object('',$entityicon).' '.$langs->trans($entitylang); print ' '.img_left().''; //print $text.'-'.$htmltext."
"; print $form->textwithpicto($text,$htmltext); //print ' ('.$code.')'; print '
'; //print $text.'-'.$htmltext."
"; print $form->textwithpicto($text,$htmltext); //print ' ('.$code.')'; print '
'.img_right().' 
'; print ''; if ($mesg) print $mesg; /* * Barre d'action * */ print '
'; if (count($array_selected)) { // If filters exist if ($conf->global->MAIN_FEATURES_LEVEL > 1 && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) { print ''.$langs->trans("NextStep").''; } else { print ''.$langs->trans("NextStep").''; } } else { print ''.$langs->trans("NextStep").''; } print '
'; } if ($step == 3 && $datatoexport) { llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; $head[$h][1] = $langs->trans("Step")." 1"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 2"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 3"; $hselected=$h; $h++; dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; // Module print ''; print ''; // Lot de donnees a exporter print ''; print ''; // Nbre champs exportes print ''; $list=''; foreach($array_selected as $code=>$value) { $list.=(! empty($list)?', ':''); $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):''); } print ''; print '
'.$langs->trans("Module").''; //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; print $objexport->array_export_module[0]->getName(); print '
'.$langs->trans("DatasetToExport").''; $icon=$objexport->array_export_icon[0]; $label=$objexport->array_export_label[0]; //print $value.'-'.$icon.'-'.$label."
"; print img_object($objexport->array_export_module[0]->getName(),$icon).' '; print $label; print '
'.$langs->trans("ExportedFields").''.$list.'
'; print '
'; // Combo list of export models print '
'; print ''; print ''; print ''; print ''; print '
'; print $langs->trans("SelectExportFields").' '; $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); print ''; print '
'; print '
'; // un formulaire en plus pour recuperer les filtres print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Champs exportables $fieldsarray=$objexport->array_export_fields[0]; // Champs filtrable $Typefieldsarray=$objexport->array_export_TypeFields[0]; // valeur des filtres $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); // Select request if all fields are selected $sqlmaxforexport=$objexport->build_sql(0, array(), array(), array()); $var=true; $i = 0; // on boucle sur les champs filtrable foreach($Typefieldsarray as $code=>$label) { $var=!$var; print ""; $i++; $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity); $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity); print ''; $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:''); $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:''); $text=$langs->trans($labelName); $tablename=getablenamefromfield($code,$sqlmaxforexport); $htmltext =''.$langs->trans("Name").': '.$text.' ('.$label.')
'; $htmltext.=''.$langs->trans("Table")." -> ".$langs->trans("Field").": ".$tablename." -> ".preg_replace('/^.*\./','',$code)."
"; if (isset($array_filtered[$code]) && $array_filtered[$code]) { // Selected fields print ''; print ''; print ''; //$bit=1; FIXME not used? // ici le filtre print ''; } else { // Fields not selected print ''; print ''; print ''; //$bit=0; FIXME not used? } print ''; //$save_selectFilter.=$bit; FIXME not used? } print '
'.$langs->trans("Entities").''.$langs->trans("FilterableFields").''.$langs->trans("FilteredFields").''.$langs->trans("FilteredFieldsValues").'
'; // If value of entityicon=entitylang='icon:Label' $tmparray=explode(':',$entityicon); if (count($tmparray) >=2) { $entityicon=$tmparray[0]; $entitylang=$tmparray[1]; } print img_object('',$entityicon).' '.$langs->trans($entitylang); print ' '.img_left().''; print $form->textwithpicto($text,$htmltext); print ''; $szInfoFiltre=$objexport->genDocFilter($label); if ($szInfoFiltre) print $form->textwithpicto($objexport->build_filterField($label, $labelName, $ValueFilter), $szInfoFiltre); else print $objexport->build_filterField($label, $labelName, $ValueFilter); print ''; //print $text.'-'.$htmltext."
"; print $form->textwithpicto($text,$htmltext); //print ' ('.$code.')'; print '
'.img_right().' 
'; print ''; if ($mesg) print $mesg; /* * Barre d'action * */ print '
'; // il n'est pas obligatoire de filtrer les champs print ''.$langs->trans("NextStep").''; print '
'; } if ($step == 4 && $datatoexport) { asort($array_selected); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; $head[$h][1] = $langs->trans("Step")." 1"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 2"; $h++; // If filters exist if ($conf->global->MAIN_FEATURES_LEVEL > 1 && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) { $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 3"; $h++; } $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 4"; $hselected=$h; $h++; dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; // Module print ''; print ''; // Lot de donnees a exporter print ''; print ''; // Nbre champs exportes print ''; $list=''; foreach($array_selected as $code=>$value) { $list.=($list?', ':''); $list.=$langs->trans($objexport->array_export_fields[0][$code]); } print ''; // Number of filtered fields if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) { print ''; $list=''; foreach($array_filtered as $code=>$value) { if (isset($objexport->array_export_fields[0][$code])) { $list.=($list?', ':''); $list.="[".$langs->trans($objexport->array_export_fields[0][$code])."]='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; } } print ''; } print '
'.$langs->trans("Module").''; //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; print $objexport->array_export_module[0]->getName(); print '
'.$langs->trans("DatasetToExport").''; print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_icon[0]).' '; print $objexport->array_export_label[0]; print '
'.$langs->trans("ExportedFields").''.$list.'
'.$langs->trans("FilteredFields").''.$list.'
'; print '
'; // Select request if all fields are selected $sqlmaxforexport=$objexport->build_sql(0, array(), array(), array()); print $langs->trans("ChooseFieldsOrdersAndTitle").'
'; print ''; print ''; print ''; print ''; print ''; //print ''; //print ''; print ''; $var=true; foreach($array_selected as $code=>$value) { $var=!$var; print ""; $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); $entityicon=(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity); $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity); print ''; print ''; print ''; //print ''; //print ''; print ''; } print '
'.$langs->trans("Entities").''.$langs->trans("ExportedFields").''.$langs->trans("Position").' '.$langs->trans("FieldsTitle").'
'; // If value of entityicon=entitylang='icon:Label' $tmparray=explode(':',$entityicon); if (count($tmparray) >=2) { $entityicon=$tmparray[0]; $entitylang=$tmparray[1]; } print img_object('',$entityicon).' '.$langs->trans($entitylang); print ''; $text=$langs->trans($objexport->array_export_fields[0][$code]); $tablename=getablenamefromfield($code,$sqlmaxforexport); $htmltext =''.$langs->trans("Name").": ".$text.'
'; $htmltext.=''.$langs->trans("Table")." -> ".$langs->trans("Field").": ".$tablename." -> ".preg_replace('/^.*\./','',$code)."
"; print $form->textwithpicto($text,$htmltext); //print ' ('.$code.')'; print '
'; print $value.' '; print ''; if ($value < count($array_selected)) print ''.img_down().''; if ($value > 1) print ''.img_up().''; print ' '.$langs->trans($objexport->array_export_fields[0][$code]).'
'; print ''; if ($mesg) print $mesg; /* * Barre d'action * */ print '
'; if (count($array_selected)) { print ''.$langs->trans("NextStep").''; } print '
'; // Area for profils export if (count($array_selected)) { print '
'; print $langs->trans("SaveExportModel"); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=false; print ''; print ''; // List of existing export profils $sql = "SELECT rowid, label"; $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; $sql.= " WHERE type = '".$datatoexport."'"; $sql.= " ORDER BY rowid"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $var=false; while ($i < $num) { $var=!$var; $obj = $db->fetch_object($resql); print ''; $i++; } } else { dol_print_error($this->db); } print '
'.$langs->trans("ExportModelName").' 
'; print ''; print '
'; print $obj->label; print ''; print 'rowid.'">'; print img_delete(); print ''; print '
'; print '
'; } } if ($step == 5 && $datatoexport) { asort($array_selected); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; $head[$h][1] = $langs->trans("Step")." 1"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 2"; $h++; // si le filtrage est parametre pour l'export ou pas if ($conf->global->MAIN_FEATURES_LEVEL > 1 && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) { $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 3"; $h++; } $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 4"; $h++; $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport; $head[$h][1] = $langs->trans("Step")." 5"; $hselected=$h; $h++; dol_fiche_head($head, $hselected, $langs->trans("NewExport")); /* * Confirmation suppression fichier */ if ($action == 'remove_file') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); if ($ret == 'html') print '
'; } print ''; // Module print ''; print ''; // Lot de donnees a exporter print ''; print ''; // Nbre champs exportes print ''; $list=''; foreach($array_selected as $code=>$label) { $list.=($list?', ':''); $list.=$langs->trans($objexport->array_export_fields[0][$code]); } print ''; // Nbre champs filtres if (is_array($objexport->array_export_TypeFields[0])) { print ''; $list=''; foreach($array_filtered as $code=>$value) { if (isset($objexport->array_export_fields[0][$code])) { $list.=($list?', ':''); $list.="[".$langs->trans($objexport->array_export_fields[0][$code])."]='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; } } print ''; } print '
'.$langs->trans("Module").''; //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; print $objexport->array_export_module[0]->getName(); print '
'.$langs->trans("DatasetToExport").''; print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_icon[0]).' '; print $objexport->array_export_label[0]; print '
'.$langs->trans("ExportedFields").''.$list.'
'.$langs->trans("FilteredFields").''.$list.'
'; print '
'; print $langs->trans("NowClickToGenerateToBuildExportFile").'
'; // Liste des formats d'exports disponibles $var=true; print ''; print ''; print ''; print ''; print ''; print ''."\n"; $liste=$objmodelexport->liste_modeles($db); foreach($liste as $key => $val) { $var=!$var; print ''; print ''; $text=$objmodelexport->getDriverDesc($key); print ''; print ''."\n"; } print '
'.$langs->trans("AvailableFormats").''.$langs->trans("LibraryUsed").''.$langs->trans("LibraryVersion").'
'.img_picto_common($key,$objmodelexport->getPicto($key)).''.$form->textwithpicto($objmodelexport->getDriverLabel($key),$text).''.$objmodelexport->getLibLabel($key).''.$objmodelexport->getLibVersion($key).'
'; print ''; print ''; if ($mesg) { print ''; } if ($sqlusedforexport && $user->admin) { print ''; } print '
'; print $mesg; print '
'; print info_admin($langs->trans("SQLUsedForExport").':
'.$sqlusedforexport); print '
'; print ''; print '
'; if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp); // Affiche liste des documents // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste $formfile->show_documents('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1); print ' 
'; } print '
'; $db->close(); llxFooter(); /** * Return table name of an alias. For this, we look for the "tablename as alias" in sql string. * * @param string $code Alias.Fieldname * @param string $sqlmaxforexport SQL request to parse * @return string Table name of field */ function getablenamefromfield($code,$sqlmaxforexport) { $newsql=$sqlmaxforexport; $newsql=preg_replace('/^(.*) FROM /i','',$newsql); $newsql=preg_replace('/WHERE (.*)$/i','',$newsql); // We must keep the ' ' before WHERE $alias=preg_replace('/\.(.*)$/i','',$code); //print $newsql.' '.$alias; $regexstring='/([a-zA-Z_]+) as '.$alias.'[, \)]/i'; if (preg_match($regexstring,$newsql,$reg)) { return $reg[1]; } else return ''; } ?>