';
+ $szFilterField='';
$szFilterField.=' ';
$szFilterField.=''.yn(1).' ';
+ if ($ValueField=='yes') $szFilterField.=' selected ';
+ $szFilterField.=' value="yes">'.yn(1).'';
$szFilterField.=''.yn(0).' ';
+ if ($ValueField=='no') $szFilterField.=' selected ';
+ $szFilterField.=' value="no">'.yn(0).'';
$szFilterField.=" ";
break;
case 'List':
@@ -466,11 +464,10 @@ class Export
* @param string $datatoexport Name of dataset to export
* @param array $array_selected Filter on array of fields to export
* @param array $array_filterValue Filter on array of fields with a filter
- * @param array $array_filtered Values of filters
* @param string $sqlquery If set, transmit a sql query instead of building it from arrays
* @return int <0 if KO, >0 if OK
*/
- function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $array_filtered, $sqlquery = '')
+ function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
{
global $conf,$langs;
@@ -494,7 +491,7 @@ class Export
$objmodel = new $classname($this->db);
if (! empty($sqlquery)) $sql = $sqlquery;
- else $sql=$this->build_sql($indice, $array_selected, $array_filterValue, $array_filtered);
+ else $sql=$this->build_sql($indice, $array_selected, $array_filterValue);
// Run the sql
$this->sqlusedforexport=$sql;
diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php
index 8ec3e73f425..f96eb57d648 100644
--- a/htdocs/exports/export.php
+++ b/htdocs/exports/export.php
@@ -94,7 +94,7 @@ $entitytolang = array(
);
$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_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');
@@ -116,8 +116,8 @@ $sqlusedforexport='';
$upload_dir = $conf->export->dir_temp.'/'.$user->id;
-$usefilters=($conf->global->MAIN_FEATURES_LEVEL > 1);
-//$usefilters=1;
+//$usefilters=($conf->global->MAIN_FEATURES_LEVEL > 1);
+$usefilters=1;
/*
@@ -189,53 +189,6 @@ if ($action=='unselectfield')
}
}
-/*
-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"]];
@@ -263,7 +216,7 @@ if ($action=='downfield' || $action=='upfield')
if ($step == 1 || $action == 'cleanselect')
{
$_SESSION["export_selected_fields"]=array();
- $_SESSION["export_FilterValue_fields"]=array();
+ //$_SESSION["export_FilterValue_fields"]=array();
$_SESSION["export_filtered_fields"]=array();
$array_selected=array();
$array_filtervalue=array();
@@ -273,7 +226,7 @@ if ($step == 1 || $action == 'cleanselect')
if ($action == 'builddoc')
{
// Build export file
- $result=$objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected, $array_filtervalue, $array_filtered);
+ $result=$objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected, $array_filtervalue);
if ($result < 0)
{
$mesg=''.$objexport->error.'
';
@@ -360,7 +313,7 @@ if ($action == 'add_export_model')
if ($step == 2 && $action == 'select_model')
{
$_SESSION["export_selected_fields"]=array();
- $_SESSION["export_filtered_fields"]=array();
+ //$_SESSION["export_filtered_fields"]=array();
$_SESSION["export_FilterValue_fields"]=array();
$array_selected=array();
@@ -388,25 +341,34 @@ if ($step == 2 && $action == 'select_model')
$array_filtervalue[$val]=$fieldsarrayvalue[$i-1];
$i++;
}
- $_SESSION["export_filtered_fields"]=$array_filtered;
+ //$_SESSION["export_filtered_fields"]=$array_filtered;
$_SESSION["export_FilterValue_fields"]=$array_filtervalue;
}
}
-// recuperation du filtrage issu du formulaire
+// Get form with filters
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)
+ var_dump($_POST);
+ foreach($objexport->array_export_TypeFields[0] as $code => $type) // $code: s.fieldname $value: Text|Boolean|List:ccc
{
- //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]]:'');
+ $newcode=(string) preg_replace('/\./','_',$code);
+ //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n ";
+ $filterqualified=1;
+ if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
+ elseif (preg_match('/^List/',$type) && $_POST[$newcode] <= 0) $filterqualified=0;
+ if ($filterqualified)
+ {
+ //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
+ $objexport->array_export_FilterValue[0][$code] = $_POST[$newcode];
+ }
}
- $_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]:'');
+ $_SESSION["export_FilterValue_fields"]=$array_filtervalue;
}
}
@@ -415,7 +377,6 @@ if ($step == 4 && $action == 'submitFormField')
* View
*/
-
if ($step == 1 || ! $datatoexport)
{
llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones');
@@ -566,7 +527,7 @@ if ($step == 2 && $datatoexport)
// Champs exportables
$fieldsarray=$objexport->array_export_fields[0];
// Select request if all fields are selected
- $sqlmaxforexport=$objexport->build_sql(0, array(), array(), array());
+ $sqlmaxforexport=$objexport->build_sql(0, array(), array());
// $this->array_export_module[0]=$module;
// $this->array_export_code[0]=$module->export_code[$r];
@@ -741,7 +702,7 @@ if ($step == 3 && $datatoexport)
// 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());
+ $sqlmaxforexport=$objexport->build_sql(0, array(), array());
$var=true;
$i = 0;
@@ -868,7 +829,7 @@ if ($step == 4 && $datatoexport)
print $objexport->array_export_label[0];
print '';
- // Nbre champs exportes
+ // List of exported fields
print ''.$langs->trans("ExportedFields").' ';
$list='';
foreach($array_selected as $code=>$value)
@@ -876,28 +837,31 @@ if ($step == 4 && $datatoexport)
$list.=($list?', ':'');
$list.=$langs->trans($objexport->array_export_fields[0][$code]);
}
- print ''.$list.' ';
+ print ''.$list.' ';
+ print '';
- // Number of filtered fields
+ // List of filtered fiels
if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
{
print ''.$langs->trans("FilteredFields").' ';
$list='';
- foreach($array_filtered as $code=>$value)
+ foreach($array_filtervalue as $code=>$value)
{
- if (isset($objexport->array_export_fields[0][$code])) {
+ 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]:'')."'";
+ $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
}
}
- print ''.$list.' ';
+ print ''.($list?$list:$langs->trans("None")).' ';
+ print '';
}
print '';
print ' ';
// Select request if all fields are selected
- $sqlmaxforexport=$objexport->build_sql(0, array(), array(), array());
+ $sqlmaxforexport=$objexport->build_sql(0, array(), array());
print $langs->trans("ChooseFieldsOrdersAndTitle").' ';
@@ -1098,7 +1062,7 @@ if ($step == 5 && $datatoexport)
print $objexport->array_export_label[0];
print '';
- // Nbre champs exportes
+ // List of exported fields
print ''.$langs->trans("ExportedFields").' ';
$list='';
foreach($array_selected as $code=>$label)
@@ -1108,19 +1072,21 @@ if ($step == 5 && $datatoexport)
}
print ''.$list.' ';
- // Nbre champs filtres
- if (is_array($objexport->array_export_TypeFields[0]))
+ // List of filtered fiels
+ if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
{
print ''.$langs->trans("FilteredFields").' ';
$list='';
- foreach($array_filtered as $code=>$value)
+ foreach($array_filtervalue as $code=>$value)
{
- if (isset($objexport->array_export_fields[0][$code])) {
+ 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]:'')."'";
+ $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
}
}
- print ''.$list.' ';
+ print ''.($list?$list:$langs->trans("None")).' ';
+ print '';
}
print '';
@@ -1182,10 +1148,10 @@ if ($step == 5 && $datatoexport)
print ' ';
-$db->close();
-
llxFooter();
+$db->close();
+
/**
* Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php
index 860e6cc09e6..103869e1850 100755
--- a/test/phpunit/ExportTest.php
+++ b/test/phpunit/ExportTest.php
@@ -144,21 +144,21 @@ class ExportTest extends PHPUnit_Framework_TestCase
$model='csv';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
$model='tsv';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
$model='excel';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
@@ -195,21 +195,21 @@ class ExportTest extends PHPUnit_Framework_TestCase
$model='csv';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
$model='tsv';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
$model='excel';
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);
@@ -234,7 +234,7 @@ class ExportTest extends PHPUnit_Framework_TestCase
$result=$objexport->load_arrays($user,$datatoexport);
// Build export file
- $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql);
+ $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql);
$expectedresult=1;
$this->assertEquals($result,$expectedresult);