From 25b7f24a9db591f8ca28f32b0a62f80aa804d6e7 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 23 Jan 2006 10:32:30 +0000 Subject: [PATCH] Added some checks git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2542 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_glpi.inc | 25 ++++++++++++++----- plugins/admin/systems/class_glpiAccount.inc | 1 - .../systems/class_glpiAttachmentPool.inc | 14 ++++++++++- .../systems/class_glpiDeviceManagement.inc | 16 ++++++++++-- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/include/class_glpi.inc b/include/class_glpi.inc index 6bfd37bc1..5760e984e 100644 --- a/include/class_glpi.inc +++ b/include/class_glpi.inc @@ -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); diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc index c10adddd8..643503a2f 100644 --- a/plugins/admin/systems/class_glpiAccount.inc +++ b/plugins/admin/systems/class_glpiAccount.inc @@ -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']); } diff --git a/plugins/admin/systems/class_glpiAttachmentPool.inc b/plugins/admin/systems/class_glpiAttachmentPool.inc index 3a8c3d9de..40a7c3e13 100644 --- a/plugins/admin/systems/class_glpiAttachmentPool.inc +++ b/plugins/admin/systems/class_glpiAttachmentPool.inc @@ -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(); diff --git a/plugins/admin/systems/class_glpiDeviceManagement.inc b/plugins/admin/systems/class_glpiDeviceManagement.inc index e3a5497bc..48062f056 100644 --- a/plugins/admin/systems/class_glpiDeviceManagement.inc +++ b/plugins/admin/systems/class_glpiDeviceManagement.inc @@ -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(); -- 2.30.2