From 65e67d947d1badad99597d0e52ed78fa28445718 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 25 Jan 2006 07:12:01 +0000 Subject: [PATCH] Updated System type & os type management, can't create existing entries, can't delete used, can't rename to already used name git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2563 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_glpi.inc | 41 +++++++++++++++++---- plugins/admin/systems/class_glpiAccount.inc | 28 ++++++++++++-- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/include/class_glpi.inc b/include/class_glpi.inc index 08f94fad6..3c16b9fc1 100644 --- a/include/class_glpi.inc +++ b/include/class_glpi.inc @@ -128,7 +128,6 @@ class glpiDB{ */ function updateSystemType($name,$id) { - if($this->is_connected){ $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";"); if(isset($tmp[0])){ @@ -321,18 +320,23 @@ class glpiDB{ /* Operating systems Returns all OSs */ - function getOSTypes() + function getOSTypes($keys = false) { if($this->is_connected){ $ret = array(); - $tmp=($this->query("SELECT * FROM glpi_dropdown_os;")); + $tmp=($this->query("SELECT * FROM glpi_dropdown_os ORDER by name;")); - foreach($tmp as $t){ - $ret[$t['ID']]=$t['name']; + if($keys){ + foreach($tmp as $t){ + $ret[$t['name']]=$t['ID']; + } + }else{ + foreach($tmp as $t){ + $ret[$t['ID']]=$t['name']; + } } - return($ret); - + }else{ echo "not connected"; return(false); @@ -399,7 +403,6 @@ class glpiDB{ */ function updateOS($name,$id) { - if($this->is_connected){ $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";"); if(isset($tmp[0])){ @@ -1510,6 +1513,28 @@ class glpiDB{ } + + /* check if given manufacturer ID ist still in use. + The problem is, that nearly every table uses manufacturers .... + */ + function is_manufacturerUsed($id) + { + $tables = array(); + foreach($this->deviceMappingGOsaGlpi as $table => $entry){ + $tables[] = $entry; + } + $tables[] ="sdf"; + print_a($tables); + exit(); + + if($this->is_connected){ + $ret = array(); + }else{ + echo "not connected"; + return(false); + } + } + /* Manufacturer Updates already existing manufacturer */ diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc index 643503a2f..0f11882cd 100644 --- a/plugins/admin/systems/class_glpiAccount.inc +++ b/plugins/admin/systems/class_glpiAccount.inc @@ -267,7 +267,12 @@ class glpiAccount extends plugin /* This appends a new system to our sytem types */ if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){ - $this->handle->addSystemType($_POST['type_string']); + $attr = $this->handle->getSystemTypes(); + if(in_array(trim($_POST['type_string']),$attr)){ + print_red(_("Adding new sytem type failed, this system type name is already used.")) ; + }else{ + $this->handle->addSystemType(trim($_POST['type_string'])); + } } /* Remove selected type from our system types list @@ -293,7 +298,12 @@ class glpiAccount extends plugin /* Rename selected system type to given string */ if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){ - $this->handle->updateSystemType($_POST['type_string'],$_POST['select_type']); + $attr = $this->handle->getSystemTypes(); + if(in_array(trim($_POST['type_string']),$attr)){ + print_red(_("Rename failed, this system type name is already used.")) ; + }else{ + $this->handle->updateSystemType($_POST['type_string'],trim($_POST['select_type'])); + } } /* Someone wants to edit the system types ... @@ -323,7 +333,12 @@ class glpiAccount extends plugin /* Add new os to the db */ if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){ - $this->handle->addOS($_POST['is_string']); + $attr = $this->handle->getOSTypes(); + if(in_array(trim($_POST['is_string']),$attr)){ + print_red(_("Adding new operating system failed, specifed name is already used.")) ; + }else{ + $this->handle->addOS(trim($_POST['is_string'])); + } } /* Delete selected os from list and db @@ -352,7 +367,12 @@ class glpiAccount extends plugin /* Rename selected os to given string */ if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){ - $this->handle->updateOS($_POST['is_string'],$_POST['select_os']); + $attr = $this->handle->getOSTypes(); + if(in_array(trim($_POST['is_string']),$attr)){ + print_red(_("Updating operating system failed, specifed name is already used.")) ; + }else{ + $this->handle->updateOS($_POST['is_string'],$_POST['select_os']); + } } /* Open dialog to edit os types -- 2.30.2