From 3a373cd8ebf0b20b66bdda6c180c8937841350b9 Mon Sep 17 00:00:00 2001
From: goujonpa <goujonpa@gmail.com>
Date: Thu, 19 Jun 2014 01:59:04 +0200
Subject: [PATCH] fix + pricefields

---
 class/datefield.php  | 30 ++++++++++++++++++------------
 class/espece.php     | 12 ++++++++++++
 class/facture.php    |  3 ++-
 class/ordonnance.php |  3 ++-
 class/prestation.php |  3 ++-
 class/produit.php    |  1 +
 class/race.php       |  3 ++-
 7 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/class/datefield.php b/class/datefield.php
index 19667dc..07879d5 100644
--- a/class/datefield.php
+++ b/class/datefield.php
@@ -1,10 +1,12 @@
 <?php
+
+class DateField extends Field
 {
     public function html() {
-        $html = '<div class = "form-group">
-                    <label for = "form'.$this->name.'">
-                    <input type = "date" name = "'.$this->name.'" value ="'.$this->value.'"> '.$this->label.'
-                    </label>
+        // Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
+        $html = '<div class="form-group">
+                    <label for="form'.$this->name.'">'.$this->label.'</label>
+                    <input type="number" class="form-control" name="'.$this->name.'" value="'.$this->value.'"> 
                 </div>';
         return $html; 
     }
@@ -12,16 +14,20 @@
     public function validate()
     {
  
-        /*if (isset($_POST[$this->name]))
+        if (isset($_POST[$this->name]))
         {
-            $_POST[$this->name] = htmlspecialchars($_POST[$this->name]); 
-            if (preg_match("#^0[1-68]([-. ]?[0-9]{2}){4}$#", $_POST[$this->name]))
-                {
-                    $this->value = $_POST[$this->name];
-                    return true;
-                }
-        */
+            $this->value = $_POST[$this->name];
+            if ($this->value > -1) {
+                return true;
+            }
+        }
         return false;
     }
 
+    public function show() {
+        $prix = $this->value;
+        $html = (string)$prix;
+        $html .= "€";
+        return $html;
+    }
 }
diff --git a/class/espece.php b/class/espece.php
index 84205be..fcd2c9d 100644
--- a/class/espece.php
+++ b/class/espece.php
@@ -5,6 +5,18 @@ class Espece extends Objet
     protected $id;
     protected $nom;
     protected $prix_consultation;
+    public $_specialFields = array(
+        "id" => array(
+            "i" => 1
+        ),
+        "nom" => array(
+            "i" => 2
+        ),
+        "prix_consultation" => array(
+            "i" => 3,
+            "label" => "Prix de la consultation",
+            "t" => "PriceField"
+        ));
 
     public function id()
     {
diff --git a/class/facture.php b/class/facture.php
index 80d12d6..8171392 100644
--- a/class/facture.php
+++ b/class/facture.php
@@ -30,7 +30,8 @@ class Facture extends Objet
         ),
         "prix_total" => array(
             "label" => "Prix total",
-            "i" => 9
+            "i" => 9,
+            "t" => "PriceField"
         ));
 
     public function id()
diff --git a/class/ordonnance.php b/class/ordonnance.php
index 02e7f20..7ccc060 100644
--- a/class/ordonnance.php
+++ b/class/ordonnance.php
@@ -22,7 +22,8 @@ class Ordonnance extends Objet
             "t" => "ForeignField"
         ),
         "prix" => array(
-            "i" => 5
+            "i" => 5,
+            "t" => "PriceField"
         ));
 
     public function id()
diff --git a/class/prestation.php b/class/prestation.php
index 527c9ba..0459ddf 100644
--- a/class/prestation.php
+++ b/class/prestation.php
@@ -17,7 +17,8 @@ class Prestation extends Objet
             "i" => 1
         )
         "prix" => array(
-            "i" => 4
+            "i" => 4,
+            "t" => "PriceField"
         ));
 
     public function id()
diff --git a/class/produit.php b/class/produit.php
index 81b0452..a91e6ac 100644
--- a/class/produit.php
+++ b/class/produit.php
@@ -20,6 +20,7 @@ class Produit extends Objet
         ),
         "prix" => array(
             "i" => 4,
+            "t" => "PriceField"
         ));
     
     public function id()
diff --git a/class/race.php b/class/race.php
index 31e0681..fdd35fe 100644
--- a/class/race.php
+++ b/class/race.php
@@ -20,7 +20,8 @@ class Race extends Objet
         ),
         "prix_intervention" => array(
             "label" => "Prix de l'intervetion",
-            "i" => 4
+            "i" => 4,
+            "t" => "PriceField"
         ));
 
     public function id()
-- 
GitLab