Code

Added check for os removement
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 10:04:47 +0000 (10:04 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 10:04:47 +0000 (10:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2541 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index 5063a0007b3db6972ec1e9d73ef28d79f648f249..6bfd37bc12552ae85211d3ea878a1fc738cd8e80 100644 (file)
@@ -339,6 +339,23 @@ class glpiDB{
                }
        }
 
+       /* Operating system is used ? */
+       function is_osUsed($ID){
+               if($this->is_connected){
+                       $ret = array();
+                       $qry="SELECT name,type FROM glpi_computers WHERE os=".$ID." LIMIT 3;";
+                       $res = $this->query($qry);
+                       foreach($res as $val){
+                               $ret[$val['name']] = $val['name'];
+                       }
+                       return($ret);
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
+
+
        /*  Operating systems
                Add a new operating system to the dropdown menus   
         */
index f0340a059a20fbb6e83459fdc500e3edd1d72610..c10adddd88a516a0c513cec7e02a796ac385b344 100644 (file)
@@ -329,7 +329,25 @@ class glpiAccount extends plugin
     /* 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