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