Code

Include personal title in cn/dn
[gosa.git] / plugins / personal / environment / class_hotplugDialog.inc
index dbb082141e3ea561f3e3306cfb14f04b2019527a..8bf8ae2980bec583493876f364ae755aef0f1a73 100644 (file)
@@ -92,18 +92,29 @@ class hotplugDialog extends plugin
   function save_object()
   {
     if(isset($_POST['dialogissubmitted'])){
+      plugin::save_object();
       foreach($this->attributes as $s_attr){
         if(isset($_POST[$s_attr])){
-          $this->$s_attr = stripslashes($_POST[$s_attr]);
+          if(in_array($s_attr,array("HOT_produkt","HOT_vendor"))){
+            $this->$s_attr = strtolower(stripslashes($_POST[$s_attr]));
+          }else{
+            $this->$s_attr = stripslashes($_POST[$s_attr]);
+          }
         }else{
           $this->$s_attr = false;
         }
       }
-      plugin::save_object();
     }
   }
 
 
+  /* check if given str in like this 0xffff*/
+  function is_2byteHex($str)
+  {
+    return !strlen($str) || preg_match("/^(0x|x|)[a-f0-9][a-f0-9][a-f0-9][a-f0-9]/i",$str);
+  }
+
+
   /* Check supplied data */
   function check()
   {
@@ -111,27 +122,28 @@ class hotplugDialog extends plugin
     $message= plugin::check();
 
     if(!$this->use_existing){
-      if((empty($this->HOT_name))||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
+
+      if(empty($this->HOT_name)||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
         $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
       }
-      if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
+      if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description)){
         $message[]=_("Invalid character in description. Please specify a valid description.");
       }
-      if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
+
+      if(empty($this->HOT_id) || preg_match("/[\|\*]/i",$this->HOT_id)){
         $message[]=_("Please specify a valid id.");
       }
-      if((empty($this->HOT_vendor))||(preg_match("/[\|]/i",$this->HOT_vendor))){
-        $message[]=_("Please specify a valid id.");
+      if(empty($this->HOT_vendor) || !$this->is_2byteHex($this->HOT_vendor)){
+        $message[]=_("Please specify a valid vendor id. (2 byte hex like '0xFFFF')");
       }
-      if((empty($this->HOT_produkt))||(preg_match("/[\|]/i",$this->HOT_produkt))){
-        $message[]=_("Please specify a valid id.");
+      if(empty($this->HOT_produkt) || !$this->is_2byteHex($this->HOT_produkt)){
+        $message[]=_("Please specify a valid product id. (2 byte hex like '0xFFFF')");
+      }
+      $ldap = $this->config->get_ldap_link();
+      $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
+      if($ldap->count()){
+        $message[]=_("An Entry with this name already exists.");
       }
-
-    $ldap = $this->config->get_ldap_link();
-    $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
-    if($ldap->count()){
-      $message[]=_("An Entry with this name already exists.");
-    }
 
     }else{
       if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
@@ -168,7 +180,14 @@ class hotplugDialog extends plugin
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->depselect);
 
-    $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
+    /* Set tag attribute if we've tagging activated */
+    $tag= "";
+    $ui= get_userinfo();
+    if ($ui->gosaUnitTag != "" && isset($this->config->current['STRICT_UNITS']) &&
+        preg_match('/TRUE/i', $this->config->current['STRICT_UNITS'])){
+      $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
+    }
+    $ldap->search("(&(objectClass=gotoEnvironment)$tag(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
 
     $a_return = array();  
     $this->hotplugDeviceList = array();