1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
<?php
/*
* @version $Id: connection.class.php 3798 2006-08-22 15:12:55Z moyo $
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2006 by the INDEPNET Development Team.
http://indepnet.net/ http://glpi-project.org
-------------------------------------------------------------------------
LICENSE
This file is part of GLPI.
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
/**
* Connection class used to connect computer to peripherals, printers and monitors
*/
class Connection {
//! Connection ID
var $ID = 0;
//! Computer ID
var $end1 = 0;
//! Connected Item ID
var $end2 = 0;
//! Connected Item Type
var $type = 0;
//! Name of the computer
var $device_name = "";
//! ID of the computer
var $device_ID = 0;
//! Is the computer Deleted
var $deleted ='N';
/**
* Get items connected to a computer
*
* $type must set before
*
* @param $ID ID of the computer
* @return array of ID of connected items
*/
function getComputerContact ($type,$ID) {
global $db;
$query = "SELECT * FROM glpi_connect_wire WHERE (end1 = '$ID' AND type = '$type')";
if ($result=$db->query($query)) {
if ($db->numrows($result)==0) return false;
$ret=array();
while ($data = $db->fetch_array($result)){
if (isset($data["end2"])) {
$ret[$data["ID"]] = $data["end2"];
}
}
return $ret;
} else {
return false;
}
}
/**
* Get computer Data
*
* Set device_name, device_ID and deleted
*
* @param $ID ID of the computer
* @return boolean : computer found
*/
function getComputerData($ID) {
global $db;
$query = "SELECT * FROM glpi_computers WHERE (ID = '$ID')";
if ($result=$db->query($query)) {
if ($db->numrows($result)==0) return false;
$data = $db->fetch_array($result);
$this->device_name = $data["name"];
$this->deleted = $data["deleted"];
$this->device_ID = $ID;
return true;
} else {
return false;
}
}
/**
* Delete connection
*
* @param $ID Connection ID
* @return boolean
*/
function deleteFromDB($ID) {
global $db;
$query = "DELETE from glpi_connect_wire WHERE (ID = '$ID')";
if ($result = $db->query($query)) {
return true;
} else {
return false;
}
}
/**
* Add a connection
*
* end1, end2 and type must be set
*
* @return integer : ID of added connection
*/
function addToDB() {
global $db;
// Build query
$query = "INSERT INTO glpi_connect_wire (end1,end2,type) VALUES ('$this->end1','$this->end2','$this->type')";
$result=$db->query($query);
return $db->insert_id();
}
}
?>
|