ryxeo-glpi-git / htdocs / inc / link.function.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (8,04 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: link.function.php 7875 2009-01-23 15:16:47Z 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: Julien Dombre
|
||
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 | // FUNCTIONS links
|
||
41 | |||
42 | |||
43 | |||
44 | /**
|
||
45 | * Print the HTML array for device on link
|
||
46 | *
|
||
47 | * Print the HTML array for device on link for link $instID
|
||
48 | *
|
||
49 | *@param $instID array : Link identifier.
|
||
50 | *
|
||
51 | *@return Nothing (display)
|
||
52 | *
|
||
53 | **/
|
||
54 | function showLinkDevice($instID) { |
||
55 | global $DB,$CFG_GLPI, $LANG; |
||
56 | |||
57 | if (!haveRight("link","r")) return false; |
||
58 | $canedit= haveRight("link","w"); |
||
59 | $ci = new CommonItem(); |
||
60 | $query = "SELECT * from glpi_links_device WHERE FK_links='$instID' ORDER BY device_type"; |
||
61 | $result = $DB->query($query); |
||
62 | $number = $DB->numrows($result); |
||
63 | $i = 0; |
||
64 | |||
65 | echo "<form method='post' action=\"".$CFG_GLPI["root_doc"]."/front/link.form.php\">"; |
||
66 | echo "<br><br><div class='center'><table class='tab_cadre_fixe'>"; |
||
67 | echo "<tr><th colspan='2'>".$LANG["links"][4].":</th></tr>"; |
||
68 | echo "<tr><th>".$LANG["common"][17]."</th>"; |
||
69 | echo "<th> </th></tr>"; |
||
70 | |||
71 | while ($i < $number) { |
||
72 | $ID=$DB->result($result, $i, "ID"); |
||
73 | $ci->setType($DB->result($result, $i, "device_type")); |
||
74 | echo "<tr class='tab_bg_1'>"; |
||
75 | echo "<td class='center'>".$ci->getType()."</td>"; |
||
76 | echo "<td align='center' class='tab_bg_2'><a href='".$_SERVER['PHP_SELF']."?deletedevice=deletedevice&ID=$ID'><strong>".$LANG["buttons"][6]."</strong></a></td></tr>"; |
||
77 | $i++;
|
||
78 | } |
||
79 | if ($canedit){ |
||
80 | echo "<tr class='tab_bg_1'><td> </td><td class='center'>"; |
||
81 | echo "<div class='software-instal'><input type='hidden' name='lID' value='$instID'>"; |
||
82 | |||
83 | $types=$CFG_GLPI["helpdesk_types"]; |
||
84 | $types[]=SOFTWARE_TYPE; |
||
85 | $types[]=CARTRIDGE_TYPE; |
||
86 | $types[]=CONSUMABLE_TYPE; |
||
87 | $types[]=ENTERPRISE_TYPE; |
||
88 | $types[]=CONTACT_TYPE; |
||
89 | $types[]=CONTRACT_TYPE; |
||
90 | dropdownDeviceTypes("device_type",0,$types); |
||
91 | |||
92 | echo " <input type='submit' name='adddevice' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
||
93 | echo "</div>"; |
||
94 | echo "</td>"; |
||
95 | |||
96 | echo "</tr>"; |
||
97 | } |
||
98 | |||
99 | echo "</table></div></form>" ; |
||
100 | |||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Delete an item type for a link
|
||
105 | *
|
||
106 | * @param $ID integer : glpi_links_device ID
|
||
107 | */
|
||
108 | function deleteLinkDevice($ID){ |
||
109 | |||
110 | global $DB; |
||
111 | $query="DELETE FROM glpi_links_device WHERE ID= '$ID';"; |
||
112 | $result = $DB->query($query); |
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * Add an item type to a link
|
||
117 | *
|
||
118 | * @param $tID integer : item type
|
||
119 | * @param $lID integer : link ID
|
||
120 | */
|
||
121 | function addLinkDevice($tID,$lID){ |
||
122 | global $DB; |
||
123 | if ($tID>0&&$lID>0){ |
||
124 | |||
125 | $query="INSERT INTO glpi_links_device (device_type,FK_links ) VALUES ('$tID','$lID');"; |
||
126 | $result = $DB->query($query); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * Show Links for an item
|
||
132 | *
|
||
133 | * @param $type integer : item type
|
||
134 | * @param $ID integer : item ID
|
||
135 | */
|
||
136 | function showLinkOnDevice($type,$ID){ |
||
137 | global $DB,$LANG,$CFG_GLPI; |
||
138 | |||
139 | if (!haveRight("link","r")) return false; |
||
140 | |||
141 | $query="SELECT glpi_links.ID as ID, glpi_links.link as link, glpi_links.name as name , glpi_links.data as data from glpi_links INNER JOIN glpi_links_device ON glpi_links.ID= glpi_links_device.FK_links WHERE glpi_links_device.device_type='$type' ORDER BY glpi_links.name"; |
||
142 | |||
143 | $result=$DB->query($query); |
||
144 | |||
145 | echo "<br>"; |
||
146 | |||
147 | $ci=new CommonItem; |
||
148 | if ($DB->numrows($result)>0){ |
||
149 | echo "<div class='center'><table class='tab_cadre'><tr><th>".$LANG["title"][33]."</th></tr>"; |
||
150 | |||
151 | while ($data=$DB->fetch_assoc($result)){ |
||
152 | |||
153 | $name=$data["name"]; |
||
154 | if (empty($name)) |
||
155 | $name=$data["link"]; |
||
156 | |||
157 | $link=$data["link"]; |
||
158 | $file=trim($data["data"]); |
||
159 | if (empty($file)){ |
||
160 | |||
161 | $ci->getFromDB($type,$ID); |
||
162 | if (ereg("\[NAME\]",$link)){ |
||
163 | $link=ereg_replace("\[NAME\]",$ci->getName(),$link); |
||
164 | } |
||
165 | if (ereg("\[ID\]",$link)){ |
||
166 | $link=ereg_replace("\[ID\]",$ID,$link); |
||
167 | } |
||
168 | |||
169 | if (ereg("\[SERIAL\]",$link)){ |
||
170 | if ($tmp=$ci->getField('serial')){ |
||
171 | $link=ereg_replace("\[SERIAL\]",$tmp,$link); |
||
172 | } |
||
173 | } |
||
174 | if (ereg("\[OTHERSERIAL\]",$link)){ |
||
175 | if ($tmp=$ci->getField('otherserial')){ |
||
176 | $link=ereg_replace("\[OTHERSERIAL\]",$tmp,$link); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | if (ereg("\[LOCATIONID\]",$link)){ |
||
181 | if ($tmp=$ci->getField('location')){ |
||
182 | $link=ereg_replace("\[LOCATIONID\]",$tmp,$link); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | if (ereg("\[LOCATION\]",$link)){ |
||
187 | if ($tmp=$ci->getField('location')){ |
||
188 | $link=ereg_replace("\[LOCATION\]",getDropdownName("glpi_dropdown_locations",$tmp),$link); |
||
189 | } |
||
190 | } |
||
191 | if (ereg("\[NETWORK\]",$link)){ |
||
192 | if ($tmp=$ci->getField('network')){ |
||
193 | $link=ereg_replace("\[NETWORK\]",getDropdownName("glpi_dropdown_network",$tmp),$link); |
||
194 | } |
||
195 | } |
||
196 | if (ereg("\[DOMAIN\]",$link)){ |
||
197 | if ($tmp=$ci->getField('domain')) |
||
198 | $link=ereg_replace("\[DOMAIN\]",getDropdownName("glpi_dropdown_domain",$tmp),$link); |
||
199 | } |
||
200 | $ipmac=array(); |
||
201 | $i=0; |
||
202 | if (ereg("\[IP\]",$link)||ereg("\[MAC\]",$link)){ |
||
203 | $query2 = "SELECT ifaddr,ifmac,logical_number FROM glpi_networking_ports WHERE (on_device = '$ID' AND device_type = '$type') ORDER BY logical_number"; |
||
204 | $result2=$DB->query($query2); |
||
205 | if ($DB->numrows($result2)>0) |
||
206 | while ($data2=$DB->fetch_array($result2)){ |
||
207 | $ipmac[$i]['ifaddr']=$data2["ifaddr"]; |
||
208 | $ipmac[$i]['ifmac']=$data2["ifmac"]; |
||
209 | $ipmac[$i]['number']=$data2["logical_number"]; |
||
210 | $i++;
|
||
211 | } |
||
212 | } |
||
213 | |||
214 | if (ereg("\[IP\]",$link)||ereg("\[MAC\]",$link)){ |
||
215 | // Add IP/MAC internal switch
|
||
216 | if ($type==NETWORKING_TYPE){ |
||
217 | $tmplink=$link; |
||
218 | $tmplink=ereg_replace("\[IP\]",$ci->getField('ifaddr'),$tmplink); |
||
219 | $tmplink=ereg_replace("\[MAC\]",$ci->getField('ifmac'),$tmplink); |
||
220 | echo "<tr class='tab_bg_2'><td><a target='_blank' href='$tmplink'>$name - $tmplink</a></td></tr>"; |
||
221 | } |
||
222 | |||
223 | if (count($ipmac)>0){ |
||
224 | foreach ($ipmac as $key => $val){ |
||
225 | $tmplink=$link; |
||
226 | $disp=1; |
||
227 | if (ereg("\[IP\]",$link)) { |
||
228 | if (empty($val['ifaddr'])) { |
||
229 | $disp=0; |
||
230 | } else {
|
||
231 | $tmplink=ereg_replace("\[IP\]",$val['ifaddr'],$tmplink); |
||
232 | } |
||
233 | } |
||
234 | if (ereg("\[MAC\]",$link)) { |
||
235 | if (empty($val['ifmac'])) { |
||
236 | $disp=0; |
||
237 | } else {
|
||
238 | $tmplink=ereg_replace("\[MAC\]",$val['ifmac'],$tmplink); |
||
239 | } |
||
240 | } |
||
241 | if ($disp) { |
||
242 | echo "<tr class='tab_bg_2'><td><a target='_blank' href='$tmplink'>$name #" . $val['number'] . " - $tmplink</a></td></tr>"; |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | } else
|
||
247 | echo "<tr class='tab_bg_2'><td><a target='_blank' href='$link'>$name</a></td></tr>"; |
||
248 | |||
249 | } else {// File Generated Link |
||
250 | $link=$data['name']; |
||
251 | $ci->getFromDB($type,$ID); |
||
252 | |||
253 | // Manage Filename
|
||
254 | if (ereg("\[NAME\]",$link)){ |
||
255 | $link=ereg_replace("\[NAME\]",$ci->getName(),$link); |
||
256 | } |
||
257 | |||
258 | if (ereg("\[ID\]",$link)){ |
||
259 | $link=ereg_replace("\[ID\]",$_GET["ID"],$link); |
||
260 | } |
||
261 | |||
262 | echo "<tr class='tab_bg_2'><td><a href='".$CFG_GLPI["root_doc"]."/front/link.send.php?lID=".$data['ID']."&type=$type&ID=$ID' target='_blank'>".$name."</a></td></tr>"; |
||
263 | } |
||
264 | |||
265 | |||
266 | } |
||
267 | echo "</table></div>"; |
||
268 | } else echo "<div class='center'><strong>".$LANG["links"][7]."</strong></div>"; |
||
269 | |||
270 | } |
||
271 | |||
272 | ?> |