From b5f0217615179c8d6ff65d665b3d2e072652c883 Mon Sep 17 00:00:00 2001
From: Sofian pujo <sofian.pujo@veremes.com>
Date: Tue, 13 Nov 2018 15:04:34 +0100
Subject: [PATCH] =?UTF-8?q?D=C3=A9placement=20du=20fichier=20et=20r=C3=A9c?=
 =?UTF-8?q?up=C3=A9ration=20du=20format=20pour=20le=20contr=C3=B4le?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../web_service/ws/Extraction.class.inc       |  2 +-
 .../ws/ExtractionExtraction.class.sql.inc     |  3 +-
 .../ws/Extraction_depots.class.inc            | 21 +++++++-
 .../web_service/ws/Extractions.class.inc      | 52 +++++++++++++------
 4 files changed, 57 insertions(+), 21 deletions(-)

diff --git a/src/module_extraction/web_service/ws/Extraction.class.inc b/src/module_extraction/web_service/ws/Extraction.class.inc
index 67c18dc9..f1c76f9d 100755
--- a/src/module_extraction/web_service/ws/Extraction.class.inc
+++ b/src/module_extraction/web_service/ws/Extraction.class.inc
@@ -9,7 +9,7 @@ require_once __DIR__. '/../../class/vitis_lib/Connection.class.inc';
  *
  * \author WAB <support.wab@veremes.com>.
  *
- *     \brief This file contains the Extraction php class
+ * \brief This file contains the Extraction php class
  *
  * This class defines operation for one Extraction
  *
diff --git a/src/module_extraction/web_service/ws/ExtractionExtraction.class.sql.inc b/src/module_extraction/web_service/ws/ExtractionExtraction.class.sql.inc
index ae9cf0a2..bf92c6ac 100755
--- a/src/module_extraction/web_service/ws/ExtractionExtraction.class.sql.inc
+++ b/src/module_extraction/web_service/ws/ExtractionExtraction.class.sql.inc
@@ -18,6 +18,5 @@ $aSql['getRtLayer'] = 'SELECT distinct layer_id, layer, category, mutualized, st
 
 $aSql['getUserGroups'] = 'SELECT name FROM [schema_framework]."group",[schema_framework].user_group WHERE "group".group_id = user_group.group_id AND user_group.user_id = [user_id]';
 
-$aSql['getDepositFile'] = 'SELECT wk_params FROM [schema_gtf]."order" WHERE "order".order_id = [bo_id]';
-$aSql['getFormat'] = 'SELECT format FROM [schema_gtf]."order" WHERE "order".order_id = [bo_id]';
+$aSql['getFormat'] = 'SELECT id_format FROM q_control."format" WHERE "format".extensions like [extension]';
 ?>
\ No newline at end of file
diff --git a/src/module_extraction/web_service/ws/Extraction_depots.class.inc b/src/module_extraction/web_service/ws/Extraction_depots.class.inc
index 412f3ddd..cd39173e 100755
--- a/src/module_extraction/web_service/ws/Extraction_depots.class.inc
+++ b/src/module_extraction/web_service/ws/Extraction_depots.class.inc
@@ -400,8 +400,27 @@ class Extraction_depots extends ExtractionExtraction
                     } elseif (in_array($sExtension, explode("|", $this->aProperties['dao']))) {
                         $sSchemaContrainte = $this->aProperties["schema_dao"];
                     }
+
+                    $this->sRessourcesFile = "ExtractionExtraction.class.sql.inc";
+                    require $this->sRessourcesFile;
+                    $sSql       = $aSql['getFormat'];
+                    $aSQLParams = array(
+                        'extension' => array('type' => 'quoted_string', 'value' => '%' . $sExtension . '%'),
+                    );
+
+                    $oPDOresult = $this->oConnection->oBd->executeWithParams($sSql, $aSQLParams);
+                    $sFormat    = "";
+                    if (!$this->oConnection->oBd->enErreur()) {
+                        $aResult = $this->oConnection->oBd->getResultTableAssoc($oPDOresult);
+                        foreach ($aResult as $sFormats) {
+                            $sFormat = $sFormats['id_format'];
+                        }
+                    }
+
                     $this->oBO = new WabBusinessObject($this->oConnection->oBd, array(), $this->aValues, $this->aProperties, 'extraction', $this->aValues['bo_id']);
-                    $this->oBO->insertOrder('EM0160AYYTK48', 'bo_id=' . $this->aValues["bo_id"]  . '|sourceDir=' . end(explode("/", $sDirPath)) . '/' . $this->aValues["control_file_name"] . '|sourceMotif=' . $sExtension . '|schema=' . $sSchemaContrainte . '|format=ACAD');
+                    //$this->oBO->insertOrder('EM0160AYYTK48', 'bo_id=' . $this->aValues["bo_id"]  . '|sourceDir=' . end(explode("/", $sDirPath)) . '/' . $this->aValues["control_file_name"] . '|sourceMotif=' . $sExtension . '|schema=' . $sSchemaContrainte . '|format=ACAD|destDir=' . $this->aProperties['ws_data_dir'] . '/extraction/extraction_depot/' . $_SERVER["REMOTE_ADDR"] . "/Fichiers déposés");
+                    $this->oBO->insertOrder('EM0160AYYTK48', 'bo_id=' . $this->aValues["bo_id"] . '|sourceDir=' . $sDirPath . '/' . $this->aValues["control_file_name"] . '|sourceMotif=' . $sExtension . '|schema=' . $sSchemaContrainte . '|format='.$sFormat.'|depotDir=' . $this->aProperties['ws_data_dir'] . '/extraction/extraction_depot/' . $_SERVER["REMOTE_ADDR"] . '/Fichiers déposés/' . $this->aValues["control_file_name"]);
+                    error_log(print_r($this, true));
                 } else {
                     //Si l'extension n'est pas bonne
                     $error_message .= $this->aValues["control_file_name"] . " format is not authaurized (" . $sExtension . ")";
diff --git a/src/module_extraction/web_service/ws/Extractions.class.inc b/src/module_extraction/web_service/ws/Extractions.class.inc
index 3b51292a..b6de8c2f 100755
--- a/src/module_extraction/web_service/ws/Extractions.class.inc
+++ b/src/module_extraction/web_service/ws/Extractions.class.inc
@@ -225,6 +225,7 @@ class Extractions extends ExtractionExtraction
      */
     public function PUT()
     {
+        $this->test = 1234;
         // Upload l'acte d'engagement.
         $this->uploadDocument('ae', 'extraction_extraction_extraction');
         //
@@ -245,16 +246,17 @@ class Extractions extends ExtractionExtraction
             //Si l'extension est autorisée
             if (in_array($sExtension, explode("|", $this->aProperties['sig'])) || in_array($sExtension, explode("|", $this->aProperties['dao']))) {
 
+                // Méthode de transition.
+                if (!empty($this->aValues['tr_status_method'])) {
+                    eval('$this->' . $this->aValues['tr_status_method'] . '();');
+                }
+
                 $sSchemaContrainte = "";
                 if (in_array($sExtension, explode("|", $this->aProperties['sig']))) {
                     $sSchemaContrainte = $this->aProperties["schema_sig"];
                 } elseif (in_array($sExtension, explode("|", $this->aProperties['dao']))) {
                     $sSchemaContrainte = $this->aProperties["schema_dao"];
                 }
-                // Méthode de transition.
-                if (!empty($this->aValues['tr_status_method'])) {
-                    eval('$this->' . $this->aValues['tr_status_method'] . '();');
-                }
 
                 while (is_dir($sDirPath)) {
                     $sDirPath = $this->aProperties["upload_dir"] . "/" . getUniqRandomId();
@@ -266,9 +268,25 @@ class Extractions extends ExtractionExtraction
                 $fp = fopen($sDirPath . '/' . utf8_decode($this->aValues["input_deposit_name"]), "w");
                 fwrite($fp, $this->aValues["input_deposit_file"]);
                 fclose($fp);
-                error_log($this->aValues["bo_id"]);
+
+                $this->sRessourcesFile = "ExtractionExtraction.class.sql.inc";
+                require $this->sRessourcesFile;
+                $sSql       = $aSql['getFormat'];
+                $aSQLParams = array(
+                    'extension' => array('type' => 'quoted_string', 'value' => '%' . $sExtension . '%'),
+                );
+
+                $oPDOresult = $this->oConnection->oBd->executeWithParams($sSql, $aSQLParams);
+                $sFormat = "";
+                if (!$this->oConnection->oBd->enErreur()) {
+                    $aResult = $this->oConnection->oBd->getResultTableAssoc($oPDOresult);
+                    foreach ($aResult as $sFormats) {
+                        $sFormat = $sFormats['id_format'];
+                    }
+                }
+
                 //Demande GTF
-                $this->oBO->insertOrder('EM0160AYYTK48', 'bo_id=' . $this->aValues["bo_id"]  . '|sourceDir=' . end(explode("/", $sDirPath)) . '/' . $this->aValues["input_deposit_name"] . '|sourceMotif=' . $sExtension . '|schema=' . $sSchemaContrainte . '|format=ACAD');
+                $this->oBO->insertOrder('EM0160AYYTK48', 'bo_id=' . $this->aValues["bo_id"] . '|sourceDir=' . end(explode("/", $sDirPath)) . '/' . $this->aValues["input_deposit_name"] . '|sourceMotif=' . $sExtension . '|depotDir=' . $sSchemaContrainte . '|format=' . $sFormat . '|depotDir=' . $this->aProperties['ws_data_dir'] . '/extraction/extraction_depot/' . $_SERVER["REMOTE_ADDR"] . "/Fichiers déposés/" . $this->aValues["input_deposit_name"]);
             } else {
                 //Si l'extension n'est pas bonne
                 $error_message .= $this->aValues["input_deposit_name"] . " format is not authaurized (" . $sExtension . ")";
@@ -574,24 +592,25 @@ class Extractions extends ExtractionExtraction
         $this->oBO = new WabBusinessObject($this->oConnection->oBd, array(), $this->aValues, $this->aProperties, 'extraction', $this->aValues['bo_id']);
         // Check si la table existe si oui change l'état
         $this->oBO->wabSetStatus($this->aProperties["schema_extraction"], "extraction", "bo_id", $this->aValues["bo_id"], "Fichier accepté");
-
+        //error_log(print_r($this->order_id, true));
         $this->sRessourcesFile = "ExtractionExtraction.class.sql.inc";
         require $this->sRessourcesFile;
-        $sSql       = $aSql['getDepositFile'];
-        $aSQLParams = array(
-            'schema_gtf' => array('value' => $this->aProperties['schema_gtf'], 'type' => 'schema_name'),
-            'bo_id'      => array('value' => $this->aValues['bo_id'], 'type' => 'number'),
+        $sSql = $aSql['getDepositFile'];
+        //error_log(print_r($this, true));
+        /*$aSQLParams = array(
+        'schema_gtf' => array('value' => $this->aProperties['schema_gtf'], 'type' => 'schema_name'),
+        'order_id'      => array('value' => $this->aValues['order_id'], 'type' => 'number'),
         );
 
         $oPDOresult = $this->oConnection->oBd->executeWithParams($sSql, $aSQLParams);
         if (!$this->oConnection->oBd->enErreur()) {
-            $aResult = $this->oConnection->oBd->getResultTableAssoc($oPDOresult);
-            foreach ($aResult as $sWkParams) {
-                $sParams[] = $sWkParams['wk_params'];
-            }
+        $aResult = $this->oConnection->oBd->getResultTableAssoc($oPDOresult);
+        foreach ($aResult as $sWkParams) {
+        $sParams[] = $sWkParams['wk_params'];
+        }
         }
 
-        $sDirPath = $this->aProperties["upload_dir"] . $sParams[0];
+        $sDirPath = $this->aProperties["upload_dir"] . $sParams[0];*/
 
         //$this->oBO->sendmail(id_du_mail_pour_dire_que_le_fichier_est_accepté);
         $this->trReception();
@@ -603,7 +622,6 @@ class Extractions extends ExtractionExtraction
      */
     public function trInvalider()
     {
-        error_log("Invalidé");
         $this->oBO = new WabBusinessObject($this->oConnection->oBd, array(), $this->aValues, $this->aProperties, 'extraction', $this->aValues['bo_id']);
 
         // Check si la table existe si oui change l'état
-- 
GitLab