Code

Added some checks
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 10:32:30 +0000 (10:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 23 Jan 2006 10:32:30 +0000 (10:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2542 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index 6bfd37bc12552ae85211d3ea878a1fc738cd8e80..5760e984e156d6bd3fbf5d714a20aee4cf0e571d 100644 (file)
@@ -619,19 +619,27 @@ class glpiDB{
      */
        function is_deviceUsed($item)
        {
-
                $deviceMappingGOsaGlpi          = array_flip($this->deviceMappingGOsaGlpi);
                $deviceMappingTableNameID       = $this->deviceMappingTableNameID;
                if($this->is_connected){
                        $tablename =  $deviceMappingGOsaGlpi[$item['device_type']];
                        $type = $item['device_type'];
 
+                       $ret = array();
+
                        if($type=="monitor"){
-                               $str = "SELECT * FROM glpi_connect_wire WHERE end1=".$item['ID']." AND type=4;";
+                               $str = "SELECT c.name FROM glpi_connect_wire as w, glpi_computers as c WHERE w.end1=".$item['ID']." AND w.end2 = c.ID AND w.type=4;"; 
                        }else{
-                               $str = "SELECT * FROM glpi_computer_device WHERE device_type=".$deviceMappingTableNameID[$type]." AND FK_device=".$item['ID'].";";
+                               $str = "SELECT c.name FROM glpi_computer_device as d, glpi_computers as c WHERE d.FK_computers=c.ID AND FK_device=".$item['ID']." AND device_type=".$deviceMappingTableNameID[$type]." ;";
                        }
-                       return(count($this->query($str)));
+
+                       $res = $this->query($str);
+       
+                       foreach($res as $val){
+                               $ret[$val['name']] = $val['name'];
+                       }       
+
+                       return($ret);//count($this->query($str)));
                }else{
                        echo "not connected";
                        return(false);
@@ -1032,8 +1040,13 @@ class glpiDB{
        function is_attachmentUsed($id)
        {
                if($this->is_connected){
-                       $qry = "SELECT * FROM glpi_doc_device WHERE FK_doc =".$id." LIMIT 1; ";
-                       return(count($this->query($qry)));
+                       $ret = array();
+                       $qry = "SELECT t.name FROM glpi_computers as t, glpi_doc_device WHERE t.ID = glpi_doc_device.FK_device AND FK_doc =".$id." LIMIT 3;";
+                       $res = $this->query($qry);
+                       foreach($res as $val){
+                               $ret[$val['name']] = $val['name'];
+                       }
+                       return($ret);
                }else{
             echo "not connected";
             return(false);
index c10adddd88a516a0c513cec7e02a796ac385b344..643503a2fd6c4db528b82673baddbcfb7f20c8a2 100644 (file)
@@ -344,7 +344,6 @@ class glpiAccount extends plugin
         }
         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']);  
       }
index 3a8c3d9dede3074df5509ad320863d2ed430a7ff..40a7c3e13bad835e9e00768eb51a9d0bf88046a2 100644 (file)
@@ -98,7 +98,19 @@ class glpiAttachmentPool extends plugin
 
     if((isset($_POST['delete_glpi_confirm']))&&(isset($attach[$this->delAttach]))){
       if($this->parent->handle->is_attachmentUsed($this->delAttach)){
-        print_red(_("Can't delete this attachment, it is still in use."));
+        $tmp = $this->parent->handle->is_attachmentUsed($this->delAttach);
+        
+        $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 attachment, it is still in use by these system(s) '%s'"),$names));
+
       }else{
         $this->parent->handle->deleteAttachment($this->delAttach);
         $attach     = $this->parent->handle->getAttachments();
index e3a5497bc2f6a429ea1a62c3d565d22c170303f9..48062f056e62c9f8727c2a218151976026b51655 100644 (file)
@@ -122,8 +122,20 @@ class glpiDeviceManagement extends plugin
 
     /* Delete entry, but check if this device is in currently in use */
     if(isset($_POST['delete_glpi_confirm'])){
-      if($this->parent->handle->is_deviceUsed($this->delete)){
-        print_red(_("Can't delete this device, it is actually in use by some glpi accounts. Remove this relation first."));
+      if(count($this->parent->handle->is_deviceUsed($this->delete))){
+
+        $tmp = $this->parent->handle->is_deviceUsed($this->delete);    
+  
+        $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 device, it is still in use by these system(s) '%s'"),$names));
       }else{
         $this->parent->handle->deleteDevice($this->delete);
         $this->reload();