ryxeo-glpi-git / inc / setup.class.php @ b67d8923
Historique | Voir | Annoter | Télécharger (9,31 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: setup.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 |
class SetupSearchDisplay extends CommonDBTM{ |
41 |
|
42 |
/**
|
43 |
* Constructor
|
44 |
**/
|
45 |
function SetupSearchDisplay () { |
46 |
$this->table="glpi_display"; |
47 |
$this->type=-1; |
48 |
} |
49 |
|
50 |
function prepareInputForAdd($input) { |
51 |
global $DB; |
52 |
$query="SELECT MAX(rank) FROM glpi_display WHERE type='".$input["type"]."' AND FK_users='".$input["FK_users"]."'"; |
53 |
$result=$DB->query($query); |
54 |
$input["rank"]=$DB->result($result,0,0)+1; |
55 |
|
56 |
return $input; |
57 |
} |
58 |
|
59 |
/**
|
60 |
* Active personal config based on global one
|
61 |
*
|
62 |
*@param $input parameter array (type,FK_users)
|
63 |
*
|
64 |
**/
|
65 |
function activatePerso($input){ |
66 |
global $DB,$SEARCH_OPTION; |
67 |
|
68 |
if (!haveRight("search_config","w")) return false; |
69 |
|
70 |
$query="SELECT * FROM glpi_display WHERE type='".$input["type"]."' AND FK_users='0'"; |
71 |
$result=$DB->query($query); |
72 |
if ($DB->numrows($result)){ |
73 |
while ($data=$DB->fetch_assoc($result)){ |
74 |
unset($data["ID"]); |
75 |
$data["FK_users"]=$input["FK_users"]; |
76 |
$this->fields=$data; |
77 |
$this->addToDB();
|
78 |
} |
79 |
} else {
|
80 |
// No items in the global config
|
81 |
if (count($SEARCH_OPTION[$input["type"]])>1){ |
82 |
$done=false; |
83 |
foreach($SEARCH_OPTION[$input["type"]] as $key => $val) |
84 |
if (is_array($val)&&$key!=1&&!$done){ |
85 |
$data["FK_users"]=$input["FK_users"]; |
86 |
$data["type"]=$input["type"]; |
87 |
$data["type"]=$input["type"]; |
88 |
$data["rank"]=1; |
89 |
$data["num"]=$key; |
90 |
$this->fields=$data; |
91 |
$this->addToDB();
|
92 |
$done=true; |
93 |
} |
94 |
|
95 |
|
96 |
} |
97 |
|
98 |
} |
99 |
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Move up an item
|
104 |
*
|
105 |
*@param $input parameter array (ID,type,FK_users)
|
106 |
*
|
107 |
**/
|
108 |
function up($input){ |
109 |
global $DB; |
110 |
// Get current item
|
111 |
$query="SELECT rank FROM glpi_display WHERE ID='".$input['ID']."';"; |
112 |
$result=$DB->query($query); |
113 |
$rank1=$DB->result($result,0,0); |
114 |
// Get previous item
|
115 |
$query="SELECT ID,rank FROM glpi_display WHERE type='".$input['type']."' AND FK_users='".$input["FK_users"]."' AND rank<'$rank1' ORDER BY rank DESC;"; |
116 |
$result=$DB->query($query); |
117 |
$rank2=$DB->result($result,0,"rank"); |
118 |
$ID2=$DB->result($result,0,"ID"); |
119 |
// Update items
|
120 |
$query="UPDATE glpi_display SET rank='$rank2' WHERE ID ='".$input['ID']."'"; |
121 |
$DB->query($query); |
122 |
$query="UPDATE glpi_display SET rank='$rank1' WHERE ID ='$ID2'"; |
123 |
$DB->query($query); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Move down an item
|
128 |
*
|
129 |
*@param $input parameter array (ID,type,FK_users)
|
130 |
*
|
131 |
**/
|
132 |
function down($input){ |
133 |
global $DB; |
134 |
|
135 |
// Get current item
|
136 |
$query="SELECT rank FROM glpi_display WHERE ID='".$input['ID']."';"; |
137 |
$result=$DB->query($query); |
138 |
$rank1=$DB->result($result,0,0); |
139 |
// Get next item
|
140 |
$query="SELECT ID,rank FROM glpi_display WHERE type='".$input['type']."' AND FK_users='".$input["FK_users"]."' AND rank>'$rank1' ORDER BY rank ASC;"; |
141 |
$result=$DB->query($query); |
142 |
$rank2=$DB->result($result,0,"rank"); |
143 |
$ID2=$DB->result($result,0,"ID"); |
144 |
// Update items
|
145 |
$query="UPDATE glpi_display SET rank='$rank2' WHERE ID ='".$input['ID']."'"; |
146 |
$DB->query($query); |
147 |
$query="UPDATE glpi_display SET rank='$rank1' WHERE ID ='$ID2'"; |
148 |
$DB->query($query); |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Print the search config form
|
153 |
*
|
154 |
*@param $target form target
|
155 |
*@param $type item type
|
156 |
*
|
157 |
*@return nothing
|
158 |
**/
|
159 |
function showForm($target,$type){ |
160 |
global $SEARCH_OPTION,$CFG_GLPI,$LANG,$DB; |
161 |
|
162 |
if (!isset($SEARCH_OPTION[$type])) { |
163 |
return false; |
164 |
} |
165 |
$is_global=($_SESSION['glpi_searchconfig']==1); |
166 |
if ($is_global) $IDuser=0; |
167 |
else $IDuser=$_SESSION["glpiID"]; |
168 |
|
169 |
$global_write=haveRight("search_config_global","w"); |
170 |
|
171 |
echo "<div id='barre_onglets'><ul id='onglet'>"; |
172 |
echo "<li "; if ($_SESSION['glpi_searchconfig']==1){ echo "class='actif'";} echo "><a href='$target?onglet=1&type=$type'>".$LANG["central"][13]."</a></li>"; |
173 |
if (haveRight("search_config","w")){ |
174 |
echo "<li "; if ($_SESSION['glpi_searchconfig']==2){ echo "class='actif'";} echo "><a href='$target?onglet=2&type=$type'>".$LANG["central"][12]."</a></li>"; |
175 |
} |
176 |
echo "</ul></div>"; |
177 |
|
178 |
echo "<div class='center'>"; |
179 |
// Defined items
|
180 |
$query="SELECT * from glpi_display WHERE type='$type' AND FK_users='$IDuser' order by rank"; |
181 |
|
182 |
$result=$DB->query($query); |
183 |
$numrows=0; |
184 |
$numrows=$DB->numrows($result); |
185 |
if ($numrows==0&&!$is_global){ |
186 |
checkRight("search_config","w"); |
187 |
echo "<table class='tab_cadre_fixe' cellpadding='2' ><tr><th colspan='4'>"; |
188 |
echo "<form method='post' action=\"$target\">"; |
189 |
echo "<input type='hidden' name='type' value='$type'>"; |
190 |
echo "<input type='hidden' name='FK_users' value='$IDuser'>"; |
191 |
|
192 |
echo $LANG["setup"][241]; |
193 |
echo " <input type='submit' name='activate' value=\"".$LANG["buttons"][2]."\" class='submit' >"; |
194 |
echo "</form></th></tr></table>"; |
195 |
|
196 |
} else {
|
197 |
|
198 |
echo "<table class='tab_cadre_fixe' cellpadding='2' ><tr><th colspan='4'>"; |
199 |
echo $LANG["setup"][252].": </th></tr>"; |
200 |
if (!$is_global||$global_write){ |
201 |
echo "<tr class='tab_bg_1'><td colspan='4' align='center'>"; |
202 |
echo "<form method='post' action=\"$target\">"; |
203 |
echo "<input type='hidden' name='type' value='$type'>"; |
204 |
echo "<input type='hidden' name='FK_users' value='$IDuser'>"; |
205 |
echo "<select name='num'>"; |
206 |
$first_group=true; |
207 |
$searchopt=cleanSearchOption($type); |
208 |
foreach ($searchopt as $key => $val) |
209 |
if (!is_array($val)){ |
210 |
if (!$first_group) echo "</optgroup>"; |
211 |
else $first_group=false; |
212 |
echo "<optgroup label=\"".$val."\">"; |
213 |
} else if ($key!=1){ |
214 |
echo "<option value='$key'>".$val["name"]."</option>"; |
215 |
} |
216 |
if (!$first_group) echo "</optgroup>"; |
217 |
|
218 |
echo "</select>"; |
219 |
echo " <input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit' >"; |
220 |
echo "</form>"; |
221 |
echo "</td></tr>"; |
222 |
} |
223 |
|
224 |
|
225 |
// print first element
|
226 |
echo "<tr class='tab_bg_2'><td align='center' width='50%'>"; |
227 |
echo $SEARCH_OPTION[$type][1]["name"]; |
228 |
|
229 |
|
230 |
if (!$is_global||$global_write) |
231 |
echo "</td><td colspan='3'> </td>"; |
232 |
echo "</tr>"; |
233 |
$i=0; |
234 |
if ($numrows){ |
235 |
while ($data=$DB->fetch_array($result)){ |
236 |
if ($data["num"]!=1){ |
237 |
echo "<tr class='tab_bg_2'><td align='center' width='50%' >"; |
238 |
echo $SEARCH_OPTION[$type][$data["num"]]["name"]; |
239 |
echo "</td>"; |
240 |
if (!$is_global||$global_write){ |
241 |
if ($i!=0){ |
242 |
echo "<td align='center' valign='middle'>"; |
243 |
echo "<form method='post' action=\"$target\">"; |
244 |
echo "<input type='hidden' name='ID' value='".$data["ID"]."'>"; |
245 |
echo "<input type='hidden' name='FK_users' value='$IDuser'>"; |
246 |
|
247 |
echo "<input type='hidden' name='type' value='$type'>"; |
248 |
echo "<input type='image' name='up' value=\"".$LANG["buttons"][24]."\" src=\"".$CFG_GLPI["root_doc"]."/pics/puce-up2.png\" alt=\"".$LANG["buttons"][24]."\" title=\"".$LANG["buttons"][24]."\" >"; |
249 |
echo "</form>"; |
250 |
echo "</td>"; |
251 |
} else echo "<td> </td>"; |
252 |
if ($i!=$numrows-1){ |
253 |
echo "<td align='center' valign='middle'>"; |
254 |
echo "<form method='post' action=\"$target\">"; |
255 |
echo "<input type='hidden' name='ID' value='".$data["ID"]."'>"; |
256 |
echo "<input type='hidden' name='FK_users' value='$IDuser'>"; |
257 |
|
258 |
echo "<input type='hidden' name='type' value='$type'>"; |
259 |
echo "<input type='image' name='down' value=\"".$LANG["buttons"][25]."\" src=\"".$CFG_GLPI["root_doc"]."/pics/puce-down2.png\" alt=\"".$LANG["buttons"][25]."\" title=\"".$LANG["buttons"][25]."\" >"; |
260 |
echo "</form>"; |
261 |
echo "</td>"; |
262 |
} else echo "<td> </td>"; |
263 |
|
264 |
echo "<td align='center' valign='middle'>"; |
265 |
echo "<form method='post' action=\"$target\">"; |
266 |
echo "<input type='hidden' name='ID' value='".$data["ID"]."'>"; |
267 |
echo "<input type='hidden' name='FK_users' value='$IDuser'>"; |
268 |
|
269 |
echo "<input type='hidden' name='type' value='$type'>"; |
270 |
echo "<input type='image' name='delete' value=\"".$LANG["buttons"][6]."\"src=\"".$CFG_GLPI["root_doc"]."/pics/puce-delete2.png\" alt=\"".$LANG["buttons"][6]."\" title=\"".$LANG["buttons"][6]."\" >"; |
271 |
echo "</form>"; |
272 |
echo "</td>"; |
273 |
} |
274 |
echo "</tr>"; |
275 |
$i++;
|
276 |
} |
277 |
} |
278 |
} |
279 |
echo "</table>"; |
280 |
} |
281 |
echo "</div>"; |
282 |
} |
283 |
} |
284 |
|
285 |
?>
|