Code

Attachmentpool dialog fixed
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
index 8a5f8d993908a31f4d8b82a171f6aaa354f92f5f..c6d3197b41bc4dd0f4016c60152874cc70a4a864 100644 (file)
@@ -225,8 +225,10 @@ class glpiAccount extends plugin
     /* Remove Attachment fro this tab 
      */
     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
-      if(isset($this->usedAttachments[$_POST['Attachments']])){
-        unset($this->usedAttachments[$_POST['Attachments']]);
+      foreach($_POST['Attachments'] as $entry){
+        if(isset($this->usedAttachments[$entry])){
+          unset($this->usedAttachments[$entry]);
+        }
       }
     }
 
@@ -265,19 +267,43 @@ class glpiAccount extends plugin
     /* This appends a new system to our sytem types
      */
     if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->addSystemType($_POST['type_string']);  
+      $attr = $this->handle->getSystemTypes();
+      if(in_array(trim($_POST['type_string']),$attr)){
+        print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
+      }else{
+        $this->handle->addSystemType(trim($_POST['type_string']));  
+      }
     }
 
     /* Remove selected type from our system types list
      */
     if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
-      $this->handle->removeSystemType($_POST['select_type']);  
+      $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
+      if(count($tmp)){
+        $names = "";
+        foreach($tmp as $name){
+          $names .= ", ".$name;
+        }
+        $names = preg_replace("/^, /","",$names); 
+        $names = trim($names);
+        if(count($tmp) == 3){
+          $names .= " ...";
+        }
+        print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
+      }else{
+        $this->handle->removeSystemType($_POST['select_type']); 
+      } 
     }
 
     /* Rename selected system type to given string
      */
     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->updateSystemType($_POST['type_string'],$_POST['select_type']);
+      $attr = $this->handle->getSystemTypes();
+      if(in_array(trim($_POST['type_string']),$attr)){
+        print_red(_("Rename failed, this system type name is already used.")) ;
+      }else{
+        $this->handle->updateSystemType($_POST['type_string'],trim($_POST['select_type']));
+      }
     }
 
     /* Someone wants to edit the system types ... 
@@ -307,19 +333,46 @@ class glpiAccount extends plugin
     /* Add new os to the db
      */
     if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){
-      $this->handle->addOS($_POST['is_string']);  
+      $attr = $this->handle->getOSTypes();
+      if(in_array(trim($_POST['is_string']),$attr)){
+        print_red(_("Adding new operating system failed, specifed name is already used.")) ;
+      }else{
+        $this->handle->addOS(trim($_POST['is_string']));  
+      }
     }
 
     /* Delete selected os from list and db
      */
     if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))){
-      $this->handle->removeOS_byID($_POST['select_os']);  
+      $tmp = $this->handle->is_osUsed($_POST['select_os']);
+  
+      if(count($tmp)){
+
+        $names = "";
+        foreach($tmp as $name){
+          $names .= ", ".$name;
+        }
+        $names = preg_replace("/^, /","",$names);
+        $names = trim($names);
+        if(count($tmp) == 3){
+          $names .= " ...";
+        }
+        print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
+
+      }else{
+        $this->handle->removeOS_byID($_POST['select_os']);  
+      }
     }
 
     /* Rename selected os to given string
      */
     if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){
-      $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+      $attr = $this->handle->getOSTypes();
+      if(in_array(trim($_POST['is_string']),$attr)){
+        print_red(_("Updating operating system failed, specifed name is already used.")) ;
+      }else{
+        $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+      }
     }
 
     /* Open dialog to edit os types 
@@ -336,7 +389,7 @@ class glpiAccount extends plugin
      */
     if(isset($_POST['SelectContactPerson'])){
       $this->addUser = "contact";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Open dialog which allows to edit the manufacturers
@@ -355,6 +408,7 @@ class glpiAccount extends plugin
 
     /* Abort user selection
      */
+    $smarty->assign("AbortSelectUser","SelectUserCancel");
     if(isset($_POST['SelectUserCancel'])){
       $this->dialog = false;
       $this->addUser ="";
@@ -365,7 +419,7 @@ class glpiAccount extends plugin
      */
     if(isset($_POST['SelectTechPerson'])){
       $this->addUser ="tech";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Technical responsible person selected*/
@@ -435,7 +489,7 @@ class glpiAccount extends plugin
 
     /* Assign some vars to smarty 
      */
-    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num") as $attr){
+    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
       $smarty->assign($attr,"");
       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
@@ -547,6 +601,9 @@ class glpiAccount extends plugin
   /* Save data to object */
   function save_object()
   {
+    if(!isset($_POST['glpi_tpl_posted'])) {
+      return ;
+    }
     plugin::save_object();
     foreach($this->attributes as $attrs){
       if(isset($_POST[$attrs])){