117 lines
2.3 KiB
PHP
117 lines
2.3 KiB
PHP
<?php
|
|
// Include XML_Serializer
|
|
require_once 'XML/Serializer.php';
|
|
|
|
/**
|
|
* Export - Gère les différents format d'exportation
|
|
* @package export
|
|
* @author Michael RICOIS
|
|
* @copyright Scores&Decisions
|
|
*/
|
|
class array2xml {
|
|
public $fileName = '';
|
|
public $rootName = 'page';
|
|
public $records = array();
|
|
public $encoding = 'UTF-8';
|
|
public $serializer_options = array();
|
|
|
|
function __construct() {}
|
|
|
|
function setXMLOptions(){
|
|
// An array of serializer options
|
|
$this->serializer_options = array (
|
|
'addDecl' => TRUE,
|
|
'encoding' => $this->encoding,
|
|
'indent' => ' ',
|
|
'rootName' => $this->rootName,
|
|
);
|
|
}
|
|
|
|
function serialize(){
|
|
$this->setXMLOptions();
|
|
// Instantiate the serializer with the options
|
|
$Serializer = &new XML_Serializer($this->serializer_options);
|
|
// Serialize the data structure
|
|
$status = $Serializer->serialize($this->records);
|
|
// Check whether serialization worked
|
|
if (PEAR::isError($status)) {
|
|
//$status->getMessage()
|
|
}
|
|
$xml = $Serializer->getSerializedData();
|
|
}
|
|
|
|
function writeXML(){
|
|
$fp = fopen($this->fileName, 'w');
|
|
if ($fp != FALSE){
|
|
|
|
fclose($fp);
|
|
}else{
|
|
//Erreur
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class array2csv {
|
|
|
|
public $fileName = '';
|
|
public $encoding = 'UTF-8';
|
|
public $delimiter = ';';
|
|
public $records = array();
|
|
|
|
function __construct() {}
|
|
|
|
/**
|
|
* Ecrit un fichier csv à partir d'un tableau.
|
|
* @param string $fileName
|
|
* @param array $records
|
|
* @param string $delimiter
|
|
* @return void
|
|
*/
|
|
function writeCSV()
|
|
{
|
|
$newRecords=array();
|
|
$this->array_flatten($this->records,$newRecords);
|
|
|
|
$headerKeys = array_keys($newRecords);
|
|
$values = array_values($newRecords);
|
|
|
|
//Ecriture du fichier
|
|
$fp = fopen($this->fileName, 'w');
|
|
if ($fp != FALSE){
|
|
//Header du fichier csv
|
|
fputcsv($fp, $headerKeys, $this->delimiter);
|
|
//Contenu du fichier
|
|
fputcsv($fp, $values, $this->delimiter);
|
|
fclose($fp);
|
|
}else{
|
|
//Erreur
|
|
}
|
|
|
|
}
|
|
|
|
function array_flatten($array, &$newArray = Array() ,$prefix='',$delimiter='|') {
|
|
foreach ($array as $key => $child) {
|
|
if (is_array($child)) {
|
|
$newPrefix = $prefix.$key.$delimiter;
|
|
$newArray =& $this->array_flatten($child, $newArray ,$newPrefix, $delimiter);
|
|
} else {
|
|
$newArray[$prefix.$key] = $child;
|
|
}
|
|
}
|
|
return $newArray;
|
|
}
|
|
|
|
}
|
|
|
|
class content2pdf {
|
|
|
|
function __construct(){}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|