From: hickert Date: Mon, 23 Jan 2006 09:52:21 +0000 (+0000) Subject: Added check and sorting for system types X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c36e7d4430b6d86bcd4aeb0b860e62322b41cb1e;p=gosa.git Added check and sorting for system types git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2540 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_glpi.inc b/include/class_glpi.inc index 2148dd2f0..5063a0007 100644 --- a/include/class_glpi.inc +++ b/include/class_glpi.inc @@ -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 */ diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc index 1f3cb999c..f0340a059 100644 --- a/plugins/admin/systems/class_glpiAccount.inc +++ b/plugins/admin/systems/class_glpiAccount.inc @@ -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