ryxeo-glpi-git / ajax / dropdownConnect.php @ b67d8923
Historique | Voir | Annoter | Télécharger (3,88 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: dropdownConnect.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: Julien Dombre
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
|
37 |
if(ereg("dropdownConnect.php",$_SERVER['PHP_SELF'])){ |
38 |
define('GLPI_ROOT','..'); |
39 |
$AJAX_INCLUDE=1; |
40 |
include (GLPI_ROOT."/inc/includes.php"); |
41 |
header("Content-Type: text/html; charset=UTF-8"); |
42 |
header_nocache(); |
43 |
}; |
44 |
|
45 |
if (!defined('GLPI_ROOT')){ |
46 |
die("Can not acces directly to this file"); |
47 |
} |
48 |
|
49 |
checkTypeRight($_POST["fromtype"],"w"); |
50 |
|
51 |
// Make a select box
|
52 |
|
53 |
$table=$LINK_ID_TABLE[$_POST["idtable"]]; |
54 |
|
55 |
$where=""; |
56 |
if (in_array($table,$CFG_GLPI["deleted_tables"])) |
57 |
$where.=" AND $table.deleted=0 "; |
58 |
if (in_array($table,$CFG_GLPI["template_tables"])) |
59 |
$where.=" AND $table.is_template='0' "; |
60 |
|
61 |
if (strlen($_POST['searchText'])>0&&$_POST['searchText']!=$CFG_GLPI["ajax_wildcard"]) |
62 |
$where.=" AND ( $table.name ".makeTextSearch($_POST['searchText'])." OR $table.serial ".makeTextSearch($_POST['searchText'])." )"; |
63 |
|
64 |
|
65 |
if (isset($_POST["entity_restrict"])&&$_POST["entity_restrict"]>=0){ |
66 |
$where.= " AND $table.FK_entities='".$_POST["entity_restrict"]."'"; |
67 |
} else {
|
68 |
$where.=getEntitiesRestrictRequest("AND",$table); |
69 |
} |
70 |
|
71 |
|
72 |
$NBMAX=$CFG_GLPI["dropdown_max"]; |
73 |
$LIMIT="LIMIT 0,$NBMAX"; |
74 |
|
75 |
if ($_POST['searchText']==$CFG_GLPI["ajax_wildcard"]) $LIMIT=""; |
76 |
|
77 |
|
78 |
if ($_POST["onlyglobal"]&&$_POST["idtable"]!=COMPUTER_TYPE){ |
79 |
$CONNECT_SEARCH=" WHERE ( $table.is_global='1' ) "; |
80 |
} else {
|
81 |
if ($_POST["idtable"]==COMPUTER_TYPE) |
82 |
$CONNECT_SEARCH=" WHERE 1 "; |
83 |
else {
|
84 |
$CONNECT_SEARCH=" WHERE (glpi_connect_wire.ID IS NULL OR $table.is_global='1' )"; |
85 |
} |
86 |
} |
87 |
|
88 |
$LEFTJOINCONNECT=""; |
89 |
if ($_POST["idtable"]!=COMPUTER_TYPE&&!$_POST["onlyglobal"]){ |
90 |
$LEFTJOINCONNECT="LEFT JOIN glpi_connect_wire on ($table.ID = glpi_connect_wire.end1 AND glpi_connect_wire.type = '".$_POST['idtable']."')"; |
91 |
} |
92 |
$query = "SELECT DISTINCT $table.ID AS ID,$table.name AS name,$table.serial AS serial,$table.otherserial AS otherserial FROM $table $LEFTJOINCONNECT $CONNECT_SEARCH $where ORDER BY name ASC"; |
93 |
|
94 |
|
95 |
|
96 |
$result = $DB->query($query); |
97 |
echo "<select name=\"".$_POST['myname']."\" size='1'>"; |
98 |
|
99 |
if ($_POST['searchText']!=$CFG_GLPI["ajax_wildcard"]&&$DB->numrows($result)==$NBMAX) |
100 |
echo "<option value=\"0\">--".$LANG["common"][11]."--</option>"; |
101 |
|
102 |
echo "<option value=\"0\">-----</option>"; |
103 |
if ($DB->numrows($result)) { |
104 |
while ($data = $DB->fetch_array($result)) { |
105 |
$output = $data['name']; |
106 |
if (!empty($data['serial'])) $output.=" - ".$data["serial"]; |
107 |
if (!empty($data['otherserial'])) $output.=" - ".$data["otherserial"]; |
108 |
$ID = $data['ID']; |
109 |
if (empty($output)) $output="($ID)"; |
110 |
|
111 |
echo "<option value=\"$ID\" title=\"".cleanInputText($output)."\">".substr($output,0,$CFG_GLPI["dropdown_limit"])."</option>"; |
112 |
} |
113 |
} |
114 |
echo "</select>"; |
115 |
|
116 |
|
117 |
?>
|