Code

Added check and sorting for system types
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 09:52:21 +0000 (09:52 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 09:52:21 +0000 (09:52 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2540 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_glpi.inc
plugins/admin/systems/class_glpiAccount.inc

index 2148dd2f0962d84e6bd7f298aafc08637aa378c5..5063a0007b3db6972ec1e9d73ef28d79f648f249 100644 (file)
@@ -115,6 +115,7 @@ class glpiDB{
                        foreach($tmp as $t){
                                $ret[$t['ID']]=$t['name'];
                        }
+                       sort($ret);
                        return($ret);
                }else{
                        echo "not connected";
@@ -180,6 +181,23 @@ class glpiDB{
                }
        }
 
+       /* System type is used */
+       function is_systemTypeUsed($ID){
+               if($this->is_connected){
+                       $ret = array();
+                       $qry="SELECT name,type FROM glpi_computers WHERE type=".$ID." LIMIT 3;";
+                       $res = $this->query($qry);
+                       foreach($res as $val){
+                               $ret[$val['name']] = $val['name'];
+                       }
+                       return($ret);
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
+
+
        /* Manufacturer 
           Returns all defined manufacturers
        */      
index 1f3cb999c205533381d04440a6c9d7ff676c7f96..f0340a059a20fbb6e83459fdc500e3edd1d72610 100644 (file)
@@ -273,7 +273,21 @@ class glpiAccount extends plugin
     /* 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