Code

Added check to avoid deleting dropdown_catrige types which are still in use
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 20 Jan 2006 09:36:16 +0000 (09:36 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 20 Jan 2006 09:36:16 +0000 (09:36 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2534 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index 544fd74630559b19ccaec84750389d6182ef1ca1..2148dd2f0962d84e6bd7f298aafc08637aa378c5 100644 (file)
@@ -1637,6 +1637,20 @@ class glpiDB{
                }
        }
 
+       function getUsedDropdownTypes($id=false)
+       {
+               if($this->is_connected){
+                       if($id){
+                               $qry = "SELECT distinct(type) FROM glpi_cartridges_type WHERE type = ".$id.";";
+                       }else{
+                               $qry = "SELECT distinct(type) FROM glpi_cartridges_type;";
+                       }
+                       return($this->query($qry));
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
 
 }
 //$s = new glpiDB("vserver-01","glpi","tester","glpi");
index 5607b5127e66c1add66af37005ed9c188652cc54..ff8d42751a43bb6f07cf7074028394c1686c49e3 100644 (file)
@@ -111,7 +111,12 @@ class glpiPrinterCartridgesEdit extends plugin
     /* Remove selected type from our printer types list
      */
     if((isset($_POST['del_cartridge_type']))&&(!empty($_POST['select_type_cartridge']))){
-      $this->parent->handle->removeCartridgeDropdownType($_POST['select_type_cartridge']);
+      $used = $this->parent->handle->getUsedDropdownTypes($_POST['select_type_cartridge']);
+      if(!count($used)){
+        $this->parent->handle->removeCartridgeDropdownType($_POST['select_type_cartridge']);
+      }else{
+        print_red(_("Can't delete this entry, it is still in use."));
+      }
     }
 
     /* Rename selected printer type to given string