Skip to content
Snippets Groups Projects
Commit 4002fe87 authored by Giovannoni Laurent's avatar Giovannoni Laurent
Browse files

fix: UTF-8 csv

parent 801af679
No related branches found
No related tags found
Loading
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
*/ */
/** /**
* @brief Contains the ExportControler Object * @brief Contains the ExportControler Object
* *
* *
* @file * @file
...@@ -40,15 +40,15 @@ try { ...@@ -40,15 +40,15 @@ try {
} }
class ExportControler class ExportControler
{ {
private static $db; private static $db;
private static $db2; private static $db2;
private static $db3; private static $db3;
private static $coll; private static $coll;
private static $functions; private static $functions;
private static $return_loadXMLConf; private static $return_loadXMLConf;
function __construct() function __construct()
{ {
$this->coll = $_SESSION['collection_id_choice']; $this->coll = $_SESSION['collection_id_choice'];
$this->functions = new functions(); $this->functions = new functions();
...@@ -61,8 +61,8 @@ class ExportControler ...@@ -61,8 +61,8 @@ class ExportControler
$this->db3->connect(); $this->db3->connect();
$this->export(); $this->export();
} }
private function export() private function export()
{ {
$return_createQuery = $this->createQuery(); $return_createQuery = $this->createQuery();
//echo $return_createQuery;exit; //echo $return_createQuery;exit;
...@@ -72,24 +72,25 @@ class ExportControler ...@@ -72,24 +72,25 @@ class ExportControler
$resultQuery[0] = $this->getHeaderOfCsv(); $resultQuery[0] = $this->getHeaderOfCsv();
$cpt = 1; $cpt = 1;
while ($return_dbQuery = $this->db->fetch_object()) { while ($return_dbQuery = $this->db->fetch_object()) {
foreach($return_dbQuery as $key => $value) {
$return_dbQuery->subject = utf8_decode($return_dbQuery->subject); $return_dbQuery->$key = utf8_decode($return_dbQuery->$key);
}
$resultQuery[$cpt] = $this->functions->object2array($return_dbQuery); $resultQuery[$cpt] = $this->functions->object2array($return_dbQuery);
if ( isset($this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES']) if ( isset($this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES'])
&& !empty($this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES'])) { && !empty($this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES'])) {
$resultQuery[$cpt][$this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES']] = substr($this->functions_copies($return_dbQuery->res_id), 0, -2); $resultQuery[$cpt][$this->return_loadXMLConf[$this->coll]['FUNCTIONS']['COPIES']] = substr($this->functions_copies($return_dbQuery->res_id), 0, -2);
} }
$resultQuery[$cpt]['commentaire'] = ''; $resultQuery[$cpt]['commentaire'] = '';
$cpt++; $cpt++;
} }
$return_array2CSV = $this->array2CSV($resultQuery); $return_array2CSV = $this->array2CSV($resultQuery);
$_SESSION['export']['filename'] = $return_array2CSV; $_SESSION['export']['filename'] = $return_array2CSV;
} }
private function createQuery() private function createQuery()
{ {
$query = 'SELECT '; $query = 'SELECT ';
for ($i=0; $i<count($this->return_loadXMLConf[$this->coll]['FIELD']); $i++) { for ($i=0; $i<count($this->return_loadXMLConf[$this->coll]['FIELD']); $i++) {
$query .= $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['DATABASE_FIELD']; $query .= $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['DATABASE_FIELD'];
...@@ -97,13 +98,13 @@ class ExportControler ...@@ -97,13 +98,13 @@ class ExportControler
$query .= ', '; $query .= ', ';
} }
} }
$query .= ' '.substr($_SESSION['last_select_query'], stripos($_SESSION['last_select_query'], 'FROM')); $query .= ' '.substr($_SESSION['last_select_query'], stripos($_SESSION['last_select_query'], 'FROM'));
return $query; return $query;
} }
private function array2CSV($resultQuery) private function array2CSV($resultQuery)
{ {
do { do {
$csvName = $_SESSION['user']['UserId'] . '-' . md5(date('Y-m-d H:i:s')) . '.csv'; $csvName = $_SESSION['user']['UserId'] . '-' . md5(date('Y-m-d H:i:s')) . '.csv';
...@@ -112,30 +113,30 @@ class ExportControler ...@@ -112,30 +113,30 @@ class ExportControler
} }
$pathToCsv = $_SESSION['config']['tmppath'] . $csvName; $pathToCsv = $_SESSION['config']['tmppath'] . $csvName;
} while (file_exists($pathToCsv)); } while (file_exists($pathToCsv));
$csvFile = fopen($pathToCsv, 'a+'); $csvFile = fopen($pathToCsv, 'a+');
foreach ($resultQuery as $fields) { foreach ($resultQuery as $fields) {
fputcsv($csvFile, $fields, ';'); fputcsv($csvFile, $fields, ';');
} }
fclose($csvFile); fclose($csvFile);
return $csvName; return $csvName;
} }
private function getHeaderOfCsv() private function getHeaderOfCsv()
{ {
//echo '<pre>'.print_r($loadXMLConf, true).'</pre>';exit; //echo '<pre>'.print_r($loadXMLConf, true).'</pre>';exit;
for($i=0; $i < count($this->return_loadXMLConf[$this->coll]['FIELD']); $i++) { for($i=0; $i < count($this->return_loadXMLConf[$this->coll]['FIELD']); $i++) {
if (!empty($this->return_loadXMLConf[$this->coll]['FIELD'][$i]['LIBELLE'])) { if (!empty($this->return_loadXMLConf[$this->coll]['FIELD'][$i]['LIBELLE'])) {
$tabToReturn[$i] = $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['LIBELLE']; $tabToReturn[$i] = $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['LIBELLE'];
} else { } else {
$tabToReturn[$i] = $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['DATABASE_FIELD']; $tabToReturn[$i] = $this->return_loadXMLConf[$this->coll]['FIELD'][$i]['DATABASE_FIELD'];
} }
} }
$temp = array_keys($this->return_loadXMLConf[$this->coll]['FUNCTIONS']); $temp = array_keys($this->return_loadXMLConf[$this->coll]['FUNCTIONS']);
for ($k=0; $k<count($temp); $k++) { for ($k=0; $k<count($temp); $k++) {
$j = $i+$k; $j = $i+$k;
...@@ -144,12 +145,12 @@ class ExportControler ...@@ -144,12 +145,12 @@ class ExportControler
if ($k == 0) { if ($k == 0) {
$j = $i; $j = $i;
} }
$tabToReturn[$j+1] = $this->return_loadXMLConf[$this->coll]['FIXE']; $tabToReturn[$j+1] = $this->return_loadXMLConf[$this->coll]['FIXE'];
return $tabToReturn; return $tabToReturn;
} }
private function loadXMLConf() private function loadXMLConf()
{ {
$path = 'apps/maarch_entreprise/xml/export.xml'; $path = 'apps/maarch_entreprise/xml/export.xml';
...@@ -159,7 +160,7 @@ class ExportControler ...@@ -159,7 +160,7 @@ class ExportControler
$exportConf = simplexml_load_file($path); $exportConf = simplexml_load_file($path);
return $exportConf; return $exportConf;
} }
private function functions_copies($res_id) private function functions_copies($res_id)
{ {
$return_functionsCopies = ''; $return_functionsCopies = '';
...@@ -180,11 +181,11 @@ class ExportControler ...@@ -180,11 +181,11 @@ class ExportControler
} else { } else {
$usersEntities = $return_dbQueryListinstance->item_id; $usersEntities = $return_dbQueryListinstance->item_id;
} }
$return_functionsCopies .= $usersEntities . ' | '; $return_functionsCopies .= $usersEntities . ' | ';
$j++; $j++;
} }
return $return_functionsCopies; return $return_functionsCopies;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment