diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index ef197c5278f..b500e51f93c 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -41,6 +41,11 @@ class Export var $array_export_fields=array(); // Tableau des liste de champ+libellé à exporter var $array_export_alias=array(); // Tableau des liste de champ+alias à exporter + // Création des modéles d'export + var $hexa; + var $datatoexport; + var $model_name; + /** * \brief Constructeur de la classe @@ -205,6 +210,76 @@ class Export } } + /** + * \brief Créé un modéle d'export + * \param user Objet utilisateur qui crée + */ + function create($user) + { + global $conf; + + dolibarr_syslog("Export.class.php::create"); + + $this->db->begin(); + + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model ('; + $sql.= 'nom, type, field)'; + $sql.= " VALUES ('".$this->model_name."', '".$this->datatoexport."', '".$this->hexa."')"; + + dolibarr_syslog("Export.class.php::create sql=".$sql); + + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + + /** + * \brief Recupère de la base les caractéristiques d'un modele d'export + * \param rowid id du modéle à récupérer + */ + function fetch($id) + { + $sql = 'SELECT em.rowid, em.field, em.nom, em.type'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em'; + $sql.= ' WHERE em.rowid = '.$id; + + dolibarr_syslog("Export::fetch sql=$sql"); + + $result = $this->db->query($sql) ; + if ($result) + { + $obj = $this->db->fetch_object($result); + if ($obj) + { + $this->id = $obj->rowid; + $this->hexa = $obj->field; + $this->model_name = $obj->nom; + $this->datatoexport = $obj->type; + + return 1; + } + else + { + $this->error="Model not found"; + return -2; + } + } + else + { + dolibarr_print_error($this->db); + return -3; + } + } + } ?> diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 2d7986feec7..49653d53ae6 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -51,14 +51,18 @@ $entitytolang=array( 'member'=>'Member','member_type'=>'MemberType'); $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array(); -$datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:''; +$datatoexport=isset($_GET["datatoexport"])? $_GET["datatoexport"] : (isset($_POST["datatoexport"])?$_POST["datatoexport"]:''); $action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:''); -$step=isset($_GET["step"])?$_GET["step"]:'1'; +$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1); +$export_name=isset($_POST["export_name"])? $_POST["export_name"] : ''; +$hexa=isset($_POST["hexa"])? $_POST["hexa"] : ''; +$exportmodelid=isset($_POST["exportmodelid"])? $_POST["exportmodelid"] : ''; $objexport=new Export($db); $objexport->load_arrays($user,$datatoexport); $objmodelexport=new ModeleExports(); +$html = new Form($db); /* @@ -131,6 +135,26 @@ if ($action == 'builddoc') } } +if ($step == 2 && $action == 'add') +{ + $objexport->model_name = $export_name; + $objexport->datatoexport = $datatoexport; + $objexport->hexa = $hexa; + + $result = $objexport->create($user); +} + +if ($step == 2 && $action == 'select_model') +{ + $_SESSION["export_selected_fields"]=array(); + $array_selected=array(); + $result = $objexport->fetch($exportmodelid); + if ($result > 0) + { + $binaire = hexbin($objexport->hexa); + } +} + /* * Affichage Pages des Etapes @@ -229,6 +253,18 @@ if ($step == 2 && $datatoexport) // Lot de données à exporter print '