Allows users to add more than one entreprise at the same time (better version).
[platal.git] / include / validations / entreprises.inc.php
index 2e1cd9a..5f6e1be 100644 (file)
@@ -37,6 +37,7 @@ class EntrReq extends Validate
     public $tel;
     public $fax;
 
+    public $suggestions;
     //TODO: addresses
 
     // }}}
@@ -44,14 +45,36 @@ class EntrReq extends Validate
 
     public function __construct(User &$_user, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_stamp = 0)
     {
-        parent::__construct($_user, true, 'entreprise', $_stamp);
-        $this->id        = $_id;
-        $this->name      = $_name;
-        $this->acronym   = $_acronym;
-        $this->url       = $_url;
-        $this->email     = $_email;
-        $this->tel       = $_tel;
-        $this->fax       = $_fax;
+        parent::__construct($_user, false, 'entreprise', $_stamp);
+        $this->id       = $_id;
+        $this->name     = $_name;
+        $this->acronym  = $_acronym;
+        $this->url      = $_url;
+        $this->email    = $_email;
+        $this->tel      = $_tel;
+        $this->fax      = $_fax;
+
+        $_name       = preg_replace('/[^0-9a-z]/i', ' ', strtolower(replace_accent($_name)));
+        $name        = explode(" ", $_name);
+        $name_array  = array_map("trim", $name);
+        $length      = count($name_array);
+        $where       = "";
+        for ($i = 0; $i < $length; $i++) {
+            if (strlen($name_array[$i]) > 2) {
+                if ($where !== "") {
+                    $where .= " OR ";
+                }
+                $where .= "name LIKE '%" . $name_array[$i] . "%'";
+            }
+        }
+        $res = XDB::iterator("SELECT  name
+                             FROM  profile_job_enum
+                            WHERE  "
+                          . $where);
+        $this->suggestions = "| ";
+        while ($sug = $res->next()) {
+            $this->suggestions .= $sug['name'] . " | ";
+        }
     }
 
     // }}}