Code

- Added a section how to report a bug
[gosa.git] / include / class_glpi.inc
index 544fd74630559b19ccaec84750389d6182ef1ca1..162e0fed6eab5f97e5e5e4e9d4fd7c1300d13381 100644 (file)
@@ -115,6 +115,7 @@ class glpiDB{
                        foreach($tmp as $t){
                                $ret[$t['ID']]=$t['name'];
                        }
+                       asort($ret);
                        return($ret);
                }else{
                        echo "not connected";
@@ -127,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])){
@@ -180,6 +180,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
        */      
@@ -187,10 +204,11 @@ class glpiDB{
        {
                if($this->is_connected){
                        $ret = array();
-                       $tmp = $this->query("SELECT * FROM glpi_enterprises;");
+                       $tmp = $this->query("SELECT * FROM glpi_enterprises ORDER BY name;");
                        foreach($tmp as $t){
                                $ret[$t['ID']]=$t['name'];
                        }
+                       
                        return($ret);
                }else{
                        echo "not connected";
@@ -303,24 +321,46 @@ 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);
+               }
+       }
 
+       /* Operating system is used ? */
+       function is_osUsed($ID){
+               if($this->is_connected){
+                       $ret = array();
+                       $qry="SELECT name,type FROM glpi_computers WHERE os=".$ID." LIMIT 3;";
+                       $res = $this->query($qry);
+                       foreach($res as $val){
+                               $ret[$val['name']] = $val['name'];
+                       }
                        return($ret);
-                               
                }else{
                        echo "not connected";
                        return(false);
                }
        }
 
+
        /*  Operating systems
                Add a new operating system to the dropdown menus   
         */
@@ -364,7 +404,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])){
@@ -584,19 +623,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);
@@ -997,8 +1044,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);
@@ -1094,6 +1146,23 @@ class glpiDB{
        /* Printer functions
      */
 
+       /* is printer type used ? 
+     */
+       function is_printerTypeUsed($id)
+       {
+               if($this->is_connected){
+                       $qry = "SELECT * FROM glpi_printers WHERE type=".$id.";";
+                       $res = $this->query( $qry);
+                       $ret =array();
+                       foreach($res as $entry){
+                               $ret[$entry['ID']] = $entry['name'];
+                       }
+                       return($ret);
+               }else{
+            echo "not connected";
+            return(false);
+        }
+       }
 
        /* This functions checks if the selected computer/network 
           device is already available in the db
@@ -1150,7 +1219,7 @@ class glpiDB{
        {
                if($this->is_connected){
                        $ret = array();
-                       $tmp = ($this->query("SELECT * FROM glpi_type_printers;"));
+                       $tmp = ($this->query("SELECT * FROM glpi_type_printers ORDER BY name; "));
                        foreach($tmp as $t){
                                $ret[$t['ID']]=$t['name'];
                        }
@@ -1334,7 +1403,6 @@ class glpiDB{
 
        /* Cartridges 
      */
-
        /* return all assigned cartridges */
        function getUsedCartridges($printerID)
        {
@@ -1424,6 +1492,21 @@ class glpiDB{
                }
        }
 
+       function is_cartridgeTypeUsed($id){
+               if($this->is_connected){
+                       $qry = "SELECT p.ID,p.name as name FROM glpi_cartridges as c,glpi_printers as p WHERE p.ID=c.FK_glpi_printers AND c.FK_glpi_cartridges_type=".$id.";";
+                       $res = $this->query($qry);
+                       $ret =array();
+                       foreach($res as $entry){
+                               $ret[$entry['ID']] = $entry['name'];
+                       }
+                       return($ret);
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
+
        function getCartridgeTypeInformations($id = "all"){
                if($this->is_connected){
                        $ret = array();                 
@@ -1462,6 +1545,41 @@ class glpiDB{
        }
 
 
+
+       /* check if given manufacturer ID ist still in use.
+          The problem is, that nearly every table uses manufacturers .... 
+     */
+       function is_manufacturerUsed($id)
+       {
+               if($this->is_connected){
+                       $tables = array();
+                       foreach($this->deviceMappingGOsaGlpi as $entry => $table){
+                               $tables[] = $entry;
+                       }
+                       $tables[] ="glpi_computers";
+                       $tables[] ="glpi_cartridges_type";
+                       $ret = array();
+                       $i = 3;
+                       foreach($tables as $tbl){
+                               if($i <= 0 ) continue;
+                               $qry = "SELECT * FROM ".$tbl." WHERE FK_glpi_enterprise = ".$id.";";
+                               $res = $this->query($qry);
+                               foreach($res as $entry){
+                                       if($i <= 0 ) continue;
+                                       if(isset($entry['designation'])){
+                                               $entry['name'] = $entry['designation'];
+                                       }
+                                       $i --;
+                                               $ret[] = $entry['name'];
+                               }
+                       }
+                       return($ret);
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
+
        /* Manufacturer 
           Updates already existing manufacturer
         */
@@ -1637,6 +1755,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");