ryxeo-glpi-git / inc / reservation.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (27,2 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: reservation.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 |
// device_type
|
37 |
// 1 computers
|
38 |
// 2 networking
|
39 |
// 3 printers
|
40 |
// 4 monitors
|
41 |
// 5 peripherals
|
42 |
// 6
|
43 |
|
44 |
|
45 |
// FUNCTIONS Reservation
|
46 |
|
47 |
if (!defined('GLPI_ROOT')){ |
48 |
die("Sorry. You can't access directly to this file"); |
49 |
} |
50 |
|
51 |
function showReservationForm($device_type,$id_device){ |
52 |
|
53 |
global $CFG_GLPI,$LANG; |
54 |
|
55 |
if (!haveRight("reservation_central","w")) return false; |
56 |
|
57 |
|
58 |
if ($resaID=isReservable($device_type,$id_device)) { |
59 |
$ri=new ReservationItem; |
60 |
$ri->getFromDB($resaID); |
61 |
|
62 |
// Supprimer le materiel$LANG["reservation"][3]
|
63 |
echo "<br><div>"; |
64 |
if ($ri->fields["active"]){ |
65 |
echo "<a href=\"".$CFG_GLPI["root_doc"]."/front/reservation.php?ID=".$resaID."&active=0\" class='icon_consol'>".$LANG["reservation"][3]."</a>"; |
66 |
} else {
|
67 |
echo "<a href=\"".$CFG_GLPI["root_doc"]."/front/reservation.php?ID=".$resaID."&active=1\" class='icon_consol'>".$LANG["reservation"][5]."</a>"; |
68 |
} |
69 |
echo " <a href=\"javascript:confirmAction('".addslashes($LANG["reservation"][38])."\\n".addslashes($LANG["reservation"][39])."','".$CFG_GLPI["root_doc"]."/front/reservation.php?ID=".$resaID."&delete=delete')\" class='icon_consol'>".$LANG["reservation"][6]."</a></div>"; |
70 |
|
71 |
}else {
|
72 |
echo "<br><div><a href=\"".$CFG_GLPI["root_doc"]."/front/reservation.php?"; |
73 |
echo "id_device=$id_device&device_type=$device_type&comments=&add=add\" class='icon_consol' >".$LANG["reservation"][7]."</a></div>"; |
74 |
} |
75 |
} |
76 |
|
77 |
function printCalendrier($target,$ID=""){ |
78 |
global $LANG, $CFG_GLPI; |
79 |
|
80 |
if (!haveRight("reservation_helpdesk","1")) return false; |
81 |
|
82 |
if (!isset($_GET["mois_courant"])) |
83 |
$mois_courant=strftime("%m"); |
84 |
else $mois_courant=$_GET["mois_courant"]; |
85 |
if (!isset($_GET["annee_courante"])) |
86 |
$annee_courante=strftime("%Y"); |
87 |
else $annee_courante=$_GET["annee_courante"]; |
88 |
|
89 |
$mois_suivant=$mois_courant+1; |
90 |
$mois_precedent=$mois_courant-1; |
91 |
$annee_suivante=$annee_courante; |
92 |
$annee_precedente=$annee_courante; |
93 |
if ($mois_precedent==0){ |
94 |
$mois_precedent=12; |
95 |
$annee_precedente--;
|
96 |
} |
97 |
|
98 |
if ($mois_suivant==13){ |
99 |
$mois_suivant=1; |
100 |
$annee_suivante++;
|
101 |
} |
102 |
|
103 |
$str_suivant="?show=resa&ID=$ID&mois_courant=$mois_suivant&annee_courante=$annee_suivante"; |
104 |
$str_precedent="?show=resa&ID=$ID&mois_courant=$mois_precedent&annee_courante=$annee_precedente"; |
105 |
|
106 |
if (!empty($ID)){ |
107 |
$m=new ReservationItem; |
108 |
$m->getFromDB($ID); |
109 |
if (!$m->fields['active']){ |
110 |
echo "<div class='center'><strong>"; |
111 |
echo $LANG["reservation"][2]."<br>"; |
112 |
displayBackLink(); |
113 |
echo "</strong></div>"; |
114 |
return false; |
115 |
} |
116 |
$ci=new CommonItem(); |
117 |
$ci->getFromDB($m->fields["device_type"],$m->fields["id_device"]); |
118 |
|
119 |
if (!haveAccessToEntity($ci->getField('FK_entities'))){ |
120 |
echo "<div class='center'><strong>"; |
121 |
|
122 |
echo $LANG["common"][54]."<br>"; |
123 |
displayBackLink(); |
124 |
echo "</strong></div>"; |
125 |
return false; |
126 |
} |
127 |
$type=$ci->getType(); |
128 |
$name=$ci->getName(); |
129 |
$all="<a href='$target?show=resa&ID=&mois_courant=$mois_courant&annee_courante=$annee_courante'>".$LANG["reservation"][26]."</a>"; |
130 |
} else {
|
131 |
$type=""; |
132 |
$name=$LANG["reservation"][25]; |
133 |
$all=" "; |
134 |
} |
135 |
|
136 |
|
137 |
echo "<div class='center'><table><tr><td>"; |
138 |
echo "<img src=\"".$CFG_GLPI["root_doc"]."/pics/reservation.png\" alt='' title=''></td><td><strong><span class='icon_consol'>".$type." - ".$name."</span>"; |
139 |
echo "</strong></td></tr><tr><td colspan='2' align ='center'>$all</td></tr></table></div>"; |
140 |
|
141 |
|
142 |
|
143 |
// Check bisextile years
|
144 |
if (($annee_courante%4)==0) $fev=29; else $fev=28; |
145 |
$nb_jour= array(31,$fev,31,30,31,30,31,31,30,31,30,31); |
146 |
|
147 |
// Datas used to put right informations in columns
|
148 |
$jour_debut_mois=strftime("%w",mktime(0,0,0,$mois_courant,1,$annee_courante)); |
149 |
if ($jour_debut_mois==0) $jour_debut_mois=7; |
150 |
$jour_fin_mois=strftime("%w",mktime(0,0,0,$mois_courant,$nb_jour[$mois_courant-1],$annee_courante)); |
151 |
|
152 |
echo "<div class='center'>"; |
153 |
|
154 |
echo "<table cellpadding='20' ><tr><td><a href=\"".$target.$str_precedent."\"><img src=\"".$CFG_GLPI["root_doc"]."/pics/left.png\" alt='".$LANG["buttons"][12]."' title='".$LANG["buttons"][12]."'></a></td><td><strong>". |
155 |
$LANG["calendarM"][$mois_courant-1]." ".$annee_courante."</strong></td><td><a href=\"".$target.$str_suivant."\"><img src=\"".$CFG_GLPI["root_doc"]."/pics/right.png\" alt='".$LANG["buttons"][11]."' title='".$LANG["buttons"][11]."'></a></td></tr></table>"; |
156 |
// test
|
157 |
echo "<table width='90%'><tr><td class='top' width='100px'>"; |
158 |
|
159 |
echo "<table><tr><td width='100px' class='top'>"; |
160 |
|
161 |
// today date
|
162 |
$today=getdate(time()); |
163 |
$mois=$today["mon"]; |
164 |
$annee=$today["year"]; |
165 |
|
166 |
|
167 |
$annee_avant = $annee_courante - 1; |
168 |
$annee_apres = $annee_courante + 1; |
169 |
|
170 |
|
171 |
echo "<div class='calendrier_mois'>"; |
172 |
echo "<div class='center'><strong>$annee_avant</strong></div>"; |
173 |
for ($i=$mois_courant; $i < 13; $i++) { |
174 |
echo "<div class='calendrier_case2'><a href=\"".$target."?show=resa&ID=$ID&mois_courant=$i&annee_courante=$annee_avant\">". |
175 |
$LANG["calendarM"][$i-1]."</a></div>"; |
176 |
} |
177 |
|
178 |
echo "<div class='center'><strong>$annee_courante</strong></div>"; |
179 |
for ($i=1; $i < 13; $i++) { |
180 |
if ($i == $mois_courant) { |
181 |
echo "<div class='calendrier_case1'><strong>". |
182 |
$LANG["calendarM"][$i-1]."</strong></div>"; |
183 |
} |
184 |
else {
|
185 |
echo "<div class='calendrier_case2'><a href=\"".$target."?show=resa&ID=$ID&mois_courant=$i&annee_courante=$annee_courante\">". |
186 |
$LANG["calendarM"][$i-1]."</a></div>"; |
187 |
} |
188 |
} |
189 |
|
190 |
echo "<div class='center'><strong>$annee_apres</strong></div>"; |
191 |
for ($i=1; $i < $mois_courant+1; $i++) { |
192 |
echo "<div class='calendrier_case2'><a href=\"".$target."?show=resa&ID=$ID&mois_courant=$i&annee_courante=$annee_apres\">". |
193 |
$LANG["calendarM"][$i-1]."</a></div>"; |
194 |
} |
195 |
echo "</div>"; |
196 |
|
197 |
echo "</td></tr></table>"; |
198 |
|
199 |
echo "</td><td class='top' width='100%'>"; |
200 |
|
201 |
|
202 |
|
203 |
// test
|
204 |
|
205 |
|
206 |
echo "<table class='tab_cadre' width='100%'><tr>"; |
207 |
echo "<th width='14%'>".$LANG["calendarD"][1]."</th>"; |
208 |
echo "<th width='14%'>".$LANG["calendarD"][2]."</th>"; |
209 |
echo "<th width='14%'>".$LANG["calendarD"][3]."</th>"; |
210 |
echo "<th width='14%'>".$LANG["calendarD"][4]."</th>"; |
211 |
echo "<th width='14%'>".$LANG["calendarD"][5]."</th>"; |
212 |
echo "<th width='14%'>".$LANG["calendarD"][6]."</th>"; |
213 |
echo "<th width='14%'>".$LANG["calendarD"][0]."</th>"; |
214 |
echo "</tr>"; |
215 |
echo "<tr class='tab_bg_3' >"; |
216 |
|
217 |
// Insert blank cell before the first day of the month
|
218 |
for ($i=1;$i<$jour_debut_mois;$i++) |
219 |
echo "<td class='calendrier_case_white'> </td>"; |
220 |
|
221 |
// voici le remplissage proprement dit
|
222 |
if ($mois_courant<10&&strlen($mois_courant)==1) $mois_courant="0".$mois_courant; |
223 |
|
224 |
for ($i=1;$i<$nb_jour[$mois_courant-1]+1;$i++){ |
225 |
if ($i<10) $ii="0".$i; |
226 |
else $ii=$i; |
227 |
|
228 |
echo "<td class='top' height='100px'>"; |
229 |
|
230 |
echo "<table class='center' ><tr><td class='center' ><span class='calendrier_jour'>".$i."</span></td></tr>"; |
231 |
|
232 |
if (!empty($ID)){ |
233 |
echo "<tr><td class='center'><a href=\"".$target."?show=resa&add_resa_on_item=1&add_item[$ID]=$ID&date=".$annee_courante."-".$mois_courant."-".$ii."\"><img src=\"".$CFG_GLPI["root_doc"]."/pics/addresa.png\" alt='".$LANG["reservation"][8]."' title='".$LANG["reservation"][8]."'></a></td></tr>"; |
234 |
} |
235 |
//if (($i-1+$jour_debut_mois)%7!=6&&($i-1+$jour_debut_mois)%7!=0){
|
236 |
echo "<tr><td>"; |
237 |
printReservation($target,$ID,$annee_courante."-".$mois_courant."-".$ii); |
238 |
echo "</td></tr>"; |
239 |
//}
|
240 |
// echo $annee_courante."-".$mois_courant."-".$ii;
|
241 |
//if (($i-1+$jour_debut_mois)%7!=6&&($i-1+$jour_debut_mois)%7!=0)
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
echo "</table>"; |
247 |
echo "</td>"; |
248 |
|
249 |
// il ne faut pas oubli�d'aller �la ligne suivante enfin de semaine
|
250 |
if (($i+$jour_debut_mois)%7==1) |
251 |
{echo "</tr>"; |
252 |
if ($i!=$nb_jour[$mois_courant-1])echo "<tr class='tab_bg_3'>"; |
253 |
} |
254 |
} |
255 |
|
256 |
// on recommence pour finir le tableau proprement pour les m�es raisons
|
257 |
|
258 |
if ($jour_fin_mois!=0) |
259 |
for ($i=0;$i<7-$jour_fin_mois;$i++) echo "<td class='calendrier_case_white'> </td>"; |
260 |
|
261 |
echo "</tr></table>"; |
262 |
|
263 |
echo "</td></tr></table></div>"; |
264 |
|
265 |
} |
266 |
|
267 |
function showAddReservationForm($target,$items,$date,$resaID=-1){ |
268 |
global $LANG; |
269 |
|
270 |
if (!haveRight("reservation_helpdesk","1")) return false; |
271 |
if (count($items)==0) return false; |
272 |
|
273 |
$resa= new ReservationResa; |
274 |
|
275 |
if ($resaID!=-1){ |
276 |
if (!$resa->getFromDB($resaID)){ |
277 |
return false; |
278 |
} |
279 |
if (!haveRight("reservation_central","w")&&$resa->fields['id_user']!=$_SESSION['glpiID']) { |
280 |
return false; |
281 |
} |
282 |
|
283 |
} else {
|
284 |
$resa->getEmpty();
|
285 |
$resa->fields["begin"]=$date." 12:00:00"; |
286 |
$resa->fields["end"]=$date." 13:00:00"; |
287 |
} |
288 |
$begin=strtotime($resa->fields["begin"]); |
289 |
$end=strtotime($resa->fields["end"]); |
290 |
$begin_date=date("Y-m-d",$begin); |
291 |
$end_date=date("Y-m-d",$end); |
292 |
$begin_hour=date("H:i",$begin); |
293 |
$end_hour=date("H:i",$end); |
294 |
|
295 |
echo "<div class='center'><form method='post' name=form action=\"$target\">"; |
296 |
|
297 |
if ($resaID!=-1) |
298 |
echo "<input type='hidden' name='ID' value='$resaID'>"; |
299 |
|
300 |
echo "<table class='tab_cadre' cellpadding='2'>"; |
301 |
echo "<tr><th colspan='2'>"; |
302 |
echo $LANG["reservation"][9]; |
303 |
echo "</th></tr>"; |
304 |
|
305 |
// Add Hardware name
|
306 |
$r=new ReservationItem; |
307 |
$ci=new CommonItem(); |
308 |
|
309 |
echo "<tr class='tab_bg_1'><td>".$LANG["reservation"][4].": </td>"; |
310 |
echo "<td>"; |
311 |
foreach ($items as $ID){ |
312 |
$r->getFromDB($ID); |
313 |
$ci->getFromDB($r->fields["device_type"],$r->fields["id_device"]); |
314 |
echo "<strong>".$ci->getType()." - ".$ci->getName()."</strong><br>"; |
315 |
echo "<input type='hidden' name='items[$ID]' value='$ID'>"; |
316 |
} |
317 |
echo "</td></tr>"; |
318 |
if (!haveRight("reservation_central","w")) |
319 |
echo "<input type='hidden' name='id_user' value='".$_SESSION["glpiID"]."'>"; |
320 |
else {
|
321 |
echo "<tr class='tab_bg_2'><td>".$LANG["reservation"][31].": </td>"; |
322 |
echo "<td>"; |
323 |
if ($resaID==-1) |
324 |
dropdownAllUsers("id_user",$_SESSION["glpiID"],1,$ci->getField('FK_entities')); |
325 |
else dropdownAllUsers("id_user",$resa->fields["id_user"],1,$ci->getField('FK_entities')); |
326 |
echo "</td></tr>"; |
327 |
|
328 |
} |
329 |
|
330 |
|
331 |
echo "<tr class='tab_bg_2'><td>".$LANG["search"][8].": </td><td>"; |
332 |
showCalendarForm("form","begin_date",$begin_date); |
333 |
echo "</td></tr>"; |
334 |
|
335 |
echo "<tr class='tab_bg_2'><td>".$LANG["reservation"][12].": </td>"; |
336 |
echo "<td>"; |
337 |
|
338 |
dropdownHours("begin_hour",$begin_hour,1); |
339 |
echo "</td></tr>"; |
340 |
|
341 |
echo "<tr class='tab_bg_2'><td>".$LANG["search"][9].": </td><td>"; |
342 |
showCalendarForm("form","end_date",$end_date); |
343 |
echo "</td></tr>"; |
344 |
|
345 |
echo "<tr class='tab_bg_2'><td>".$LANG["reservation"][13].": </td>"; |
346 |
echo "<td>"; |
347 |
dropdownHours("end_hour",$end_hour,1); |
348 |
echo "</td></tr>"; |
349 |
|
350 |
if ($resaID==-1){ |
351 |
echo "<tr class='tab_bg_2'><td>".$LANG["reservation"][27].": </td>"; |
352 |
echo "<td>"; |
353 |
echo "<select name='periodicity'>"; |
354 |
echo "<option value='day'>".$LANG["reservation"][29]."</option>"; |
355 |
echo "<option value='week'>".$LANG["reservation"][28]."</option>"; |
356 |
echo "</select>"; |
357 |
dropdownInteger('periodicity_times',1,1,60); |
358 |
echo $LANG["reservation"][30]; |
359 |
echo "</td></tr>"; |
360 |
} |
361 |
|
362 |
echo "<tr class='tab_bg_2'><td>".$LANG["common"][25].": </td>"; |
363 |
echo "<td><textarea name='comment'rows='8' cols='30'>".$resa->fields["comment"]."</textarea>"; |
364 |
echo "</td></tr>"; |
365 |
|
366 |
if ($resaID==-1){ |
367 |
echo "<tr class='tab_bg_2'>"; |
368 |
echo "<td colspan='2' valign='top' align='center'>"; |
369 |
echo "<input type='submit' name='add_resa' value=\"".$LANG["buttons"][8]."\" class='submit'>"; |
370 |
echo "</td></tr>\n"; |
371 |
} else {
|
372 |
echo "<tr class='tab_bg_2'>"; |
373 |
echo "<td valign='top' align='center'>"; |
374 |
echo "<input type='submit' name='clear_resa' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
375 |
echo "</td><td valign='top' align='center'>"; |
376 |
echo "<input type='submit' name='edit_resa' value=\"".$LANG["buttons"][14]."\" class='submit'>"; |
377 |
echo "</td></tr>\n"; |
378 |
} |
379 |
|
380 |
echo "</table>"; |
381 |
echo "</form></div>"; |
382 |
} |
383 |
|
384 |
function printReservation($target,$ID,$date){ |
385 |
global $DB; |
386 |
if (!empty($ID)) |
387 |
printReservationItem($target,$ID,$date); |
388 |
else {
|
389 |
|
390 |
$debut=$date." 00:00:00"; |
391 |
$fin=$date." 23:59:59"; |
392 |
|
393 |
$query = "SELECT DISTINCT glpi_reservation_item.ID FROM glpi_reservation_item INNER JOIN glpi_reservation_resa ON (glpi_reservation_item.ID = glpi_reservation_resa.id_item )". |
394 |
" WHERE active='1' AND (('".$debut."' < begin AND '".$fin."' > begin) OR ('".$debut."' < end AND '".$fin."' > end) OR (begin < '".$debut."' AND end > '".$debut."') OR (begin < '".$fin."' AND end > '".$fin."')) ORDER BY begin"; |
395 |
// echo $query;
|
396 |
$result=$DB->query($query); |
397 |
|
398 |
if ($DB->numrows($result)>0){ |
399 |
$m=new ReservationItem; |
400 |
|
401 |
while ($data=$DB->fetch_array($result)){ |
402 |
|
403 |
$m->getFromDB($data['ID']); |
404 |
$ci=new CommonItem(); |
405 |
$ci->getFromDB($m->fields["device_type"],$m->fields["id_device"]); |
406 |
|
407 |
if (in_array($ci->obj->fields["FK_entities"],$_SESSION["glpiactiveentities"])){ |
408 |
list($annee,$mois,$jour)=split("-",$date); |
409 |
echo "<tr class='tab_bg_1'><td><a href='$target?show=resa&ID=".$data['ID']."&mois_courant=$mois&annee_courante=$annee'>".$ci->getType()." - ".$ci->getName()."</a></td></tr>"; |
410 |
echo "<tr><td>"; |
411 |
printReservationItem($target,$data['ID'],$date); |
412 |
echo "</td></tr>"; |
413 |
} |
414 |
} |
415 |
} |
416 |
} |
417 |
|
418 |
} |
419 |
|
420 |
|
421 |
function printReservationItem($target,$ID,$date){ |
422 |
global $DB,$LANG; |
423 |
|
424 |
$id_user=$_SESSION["glpiID"]; |
425 |
|
426 |
$user=new User; |
427 |
list($year,$month,$day)=split("-",$date); |
428 |
$debut=$date." 00:00:00"; |
429 |
$fin=$date." 23:59:59"; |
430 |
$query = "SELECT * FROM glpi_reservation_resa". |
431 |
" WHERE (('".$debut."' < begin AND '".$fin."' > begin) OR ('".$debut."' < end AND '".$fin."' > end) OR (begin < '".$debut."' AND end > '".$debut."') OR (begin < '".$fin."' AND end > '".$fin."')) AND id_item='$ID' ORDER BY begin"; |
432 |
// echo $query."<br>";
|
433 |
if ($result=$DB->query($query)){ |
434 |
if ($DB->numrows($result)>0){ |
435 |
echo "<table width='100%' >"; |
436 |
while ($row=$DB->fetch_array($result)){ |
437 |
echo "<tr>"; |
438 |
$user->getFromDB($row["id_user"]); |
439 |
$display=""; |
440 |
if ($debut>$row['begin']) $heure_debut="00:00"; |
441 |
else $heure_debut=get_hour_from_sql($row['begin']); |
442 |
|
443 |
if ($fin<$row['end']) $heure_fin="24:00"; |
444 |
else $heure_fin=get_hour_from_sql($row['end']); |
445 |
|
446 |
if (strcmp($heure_debut,"00:00")==0&&strcmp($heure_fin,"24:00")==0) |
447 |
$display=$LANG["planning"][5]; |
448 |
else if (strcmp($heure_debut,"00:00")==0) |
449 |
$display=$LANG["reservation"][16]." ".$heure_fin; |
450 |
else if (strcmp($heure_fin,"24:00")==0) |
451 |
$display=$LANG["reservation"][17]." ".$heure_debut; |
452 |
else $display=$heure_debut."-".$heure_fin; |
453 |
|
454 |
$rand=mt_rand();
|
455 |
$modif=$modif_end=""; |
456 |
if (haveRight("reservation_central","w")||$row['id_user']==$_SESSION['glpiID']) { |
457 |
$modif="<a onmouseout=\"cleanhide('content_".$ID.$rand."')\" onmouseover=\"cleandisplay('content_".$ID.$rand."')\" href=\"".$target."?show=resa&edit=".$row['ID']."&edit_item[$ID]=$ID&mois_courant=$month&annee_courante=$year\">"; |
458 |
$modif_end="</a>"; |
459 |
} |
460 |
$comment="<div class='over_link' id='content_".$ID.$rand."'>".nl2br($row["comment"])."</div>"; |
461 |
|
462 |
echo "<td align='center' class='tab_resa'>". $modif."<span>".$display."<br><strong>".formatUserName($user->fields["ID"],$user->fields["name"],$user->fields["realname"],$user->fields["firstname"])."</strong></span>"; |
463 |
|
464 |
echo $modif_end.$comment."</td></tr>"; |
465 |
|
466 |
} |
467 |
|
468 |
echo "</table>"; |
469 |
} |
470 |
} |
471 |
|
472 |
} |
473 |
|
474 |
|
475 |
function printReservationItems($target){ |
476 |
global $DB,$LANG,$LINK_ID_TABLE,$CFG_GLPI; |
477 |
|
478 |
if (!haveRight("reservation_helpdesk","1")) return false; |
479 |
|
480 |
$ri=new ReservationItem; |
481 |
$ci=new CommonItem(); |
482 |
$ok=false; |
483 |
$showentity=isMultiEntitiesMode();
|
484 |
|
485 |
echo "<div class='center'><form name='form' method='get' action='$target'><table class='tab_cadre' cellpadding='5'>"; |
486 |
echo "<tr><th colspan='".($showentity?"5":"4")."'>".$LANG["reservation"][1]."</th></tr>"; |
487 |
|
488 |
|
489 |
foreach ($CFG_GLPI["reservation_types"] as $type){ |
490 |
$ci->setType($type); |
491 |
$query="SELECT glpi_reservation_item.ID as ID, glpi_reservation_item.comments as comments, |
492 |
".$LINK_ID_TABLE[$type].".name as name, ".$LINK_ID_TABLE[$type].".FK_entities as FK_entities, glpi_dropdown_locations.completename as location, glpi_reservation_item.id_device as id_device |
493 |
FROM glpi_reservation_item
|
494 |
INNER JOIN ".$LINK_ID_TABLE[$type]." ON (glpi_reservation_item.device_type='$type' AND glpi_reservation_item.id_device=".$LINK_ID_TABLE[$type].".ID) |
495 |
LEFT JOIN glpi_dropdown_locations ON (".$LINK_ID_TABLE[$type].".location = glpi_dropdown_locations.ID) |
496 |
WHERE glpi_reservation_item.active='1' AND ".$LINK_ID_TABLE[$type].".deleted ='0' ".getEntitiesRestrictRequest("AND",$LINK_ID_TABLE[$type])." ORDER BY ".$LINK_ID_TABLE[$type].".FK_entities, ".$LINK_ID_TABLE[$type].".name"; |
497 |
|
498 |
|
499 |
if ($result = $DB->query($query)) { |
500 |
|
501 |
while ($row=$DB->fetch_array($result)){ |
502 |
echo "<tr class='tab_bg_2'>"; |
503 |
echo "<td><input type='checkbox' name='add_item[".$row["ID"]."]' value='".$row["ID"]."' ></td>"; |
504 |
|
505 |
$typename=$ci->getType(); |
506 |
if ($type==PERIPHERAL_TYPE){ |
507 |
$ci->getFromDB($type,$row['id_device']); |
508 |
if (isset($ci->obj->fields["type"])&&$ci->obj->fields["type"]!=0){ |
509 |
$typename=getDropdownName("glpi_type_peripherals",$ci->obj->fields["type"]); |
510 |
} |
511 |
} |
512 |
|
513 |
echo "<td><a href='".$target."?show=resa&ID=".$row['ID']."'>$typename - ".$row["name"]."</a></td>"; |
514 |
echo "<td>".$row["location"]."</td>"; |
515 |
echo "<td>".nl2br($row["comments"])."</td>"; |
516 |
if ($showentity){ |
517 |
echo "<td>".getDropdownName("glpi_entities",$row["FK_entities"])."</td>"; |
518 |
} |
519 |
echo "</tr>"; |
520 |
$ok=true; |
521 |
} |
522 |
} |
523 |
} |
524 |
if ($ok){ |
525 |
echo "<tr class='tab_bg_1' align='center'><td colspan='".($showentity?"5":"4")."'><input type='submit' value=\"".$LANG["buttons"][8]."\" class='submit' ></td></tr>"; |
526 |
} |
527 |
echo "</table>"; |
528 |
echo "<input type='hidden' name='show' value='resa'>"; |
529 |
echo "<input type='hidden' name='add_resa_on_item' value='resa'>"; |
530 |
echo "</form></div>"; |
531 |
|
532 |
|
533 |
} |
534 |
|
535 |
|
536 |
function showReservationCommentForm($target,$ID){ |
537 |
global $LANG; |
538 |
|
539 |
if (!haveRight("reservation_central","w")) return false; |
540 |
|
541 |
$r=new ReservationItem; |
542 |
if ($r->getFromDB($ID)){ |
543 |
$ci=new CommonItem(); |
544 |
$ci->getFromDB($r->fields["device_type"],$r->fields["id_device"]); |
545 |
|
546 |
echo "<div class='center'><form method='post' name=form action=\"$target\">"; |
547 |
echo "<input type='hidden' name='ID' value='$ID'>"; |
548 |
|
549 |
echo "<table class='tab_cadre' cellpadding='2'>"; |
550 |
echo "<tr><th colspan='2'>"; |
551 |
echo $LANG["reservation"][22]; |
552 |
echo "</th></tr>"; |
553 |
// Ajouter le nom du mat�iel
|
554 |
echo "<tr class='tab_bg_1'><td>".$LANG["reservation"][4].": </td>"; |
555 |
echo "<td>"; |
556 |
echo "<strong>".$ci->getType()." - ".$ci->getName()."</strong>"; |
557 |
echo "</td></tr>"; |
558 |
|
559 |
echo "<tr class='tab_bg_1'><td>".$LANG["common"][25].": </td>"; |
560 |
echo "<td>"; |
561 |
echo "<textarea name='comments' cols='30' rows='10' >".$r->fields["comments"]."</textarea>"; |
562 |
echo "</td></tr>"; |
563 |
|
564 |
|
565 |
echo "<tr class='tab_bg_2'>"; |
566 |
echo "<td colspan='2' valign='top' align='center'>"; |
567 |
echo "<input type='submit' name='updatecomment' value=\"".$LANG["buttons"][14]."\" class='submit'>"; |
568 |
echo "</td></tr>\n"; |
569 |
|
570 |
echo "</table>"; |
571 |
echo "</form></div>"; |
572 |
return true; |
573 |
} else return false; |
574 |
} |
575 |
|
576 |
function showDeviceReservations($target,$type,$ID){ |
577 |
global $DB,$LANG,$CFG_GLPI; |
578 |
$resaID=0; |
579 |
|
580 |
if (!haveRight("reservation_central","r")) return false; |
581 |
|
582 |
echo "<div class='center'>"; |
583 |
|
584 |
showReservationForm($type,$ID); |
585 |
echo "<br>"; |
586 |
|
587 |
if ($resaID=isReservable($type,$ID)){ |
588 |
$ri=new ReservationItem; |
589 |
$ri->getFromDB($resaID); |
590 |
|
591 |
$now=$_SESSION["glpi_currenttime"]; |
592 |
// Print reservation in progress
|
593 |
$query = "SELECT * FROM glpi_reservation_resa WHERE end > '".$now."' AND id_item='$resaID' ORDER BY begin"; |
594 |
$result=$DB->query($query); |
595 |
|
596 |
echo "<table class='tab_cadrehov'><tr><th colspan='5'>"; |
597 |
if ($ri->fields["active"]){ |
598 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=$resaID' >".$LANG["reservation"][35]."</a>"; |
599 |
} else {
|
600 |
echo $LANG["reservation"][35]; |
601 |
} |
602 |
echo "</th></tr>"; |
603 |
if ($DB->numrows($result)==0){ |
604 |
echo "<tr class='tab_bg_2'><td align='center' colspan='5'>".$LANG["reservation"][37]."</td></tr>"; |
605 |
} else {
|
606 |
echo "<tr><th>".$LANG["search"][8]."</th><th>".$LANG["search"][9]."</th><th>".$LANG["reservation"][31]."</th><th>".$LANG["common"][25]."</th><th> </th></tr>"; |
607 |
while ($data=$DB->fetch_assoc($result)){ |
608 |
echo "<tr class='tab_bg_2'>"; |
609 |
echo "<td class='center'>".convDateTime($data["begin"])."</td>"; |
610 |
echo "<td class='center'>".convDateTime($data["end"])."</td>"; |
611 |
echo "<td class='center'><a href='".$CFG_GLPI["root_doc"]."/front/user.form.php?ID=".$data["id_user"]."'>".getUserName($data["id_user"])."</a></td>"; |
612 |
echo "<td class='center'>".nl2br($data["comment"])."</td>"; |
613 |
echo "<td class='center'>"; |
614 |
|
615 |
list($annee,$mois,$jour)=split("-",$data["begin"]); |
616 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=".$resaID."&mois_courant=$mois&annee_courante=$annee' title='".$LANG["reservation"][21]."'><img src=\"".$CFG_GLPI["root_doc"]."/pics/reservation-3.png\" alt='' title=''></a>"; |
617 |
|
618 |
|
619 |
echo "</td>"; |
620 |
echo "</tr>"; |
621 |
} |
622 |
} |
623 |
echo "</table>"; |
624 |
echo "<br>"; |
625 |
// Print old reservations
|
626 |
|
627 |
$query = "SELECT * FROM glpi_reservation_resa WHERE end <= '".$now."' AND id_item='$resaID' ORDER BY begin DESC"; |
628 |
$result=$DB->query($query); |
629 |
|
630 |
echo "<table class='tab_cadrehov'><tr><th colspan='5'>"; |
631 |
|
632 |
if ($ri->fields["active"]){ |
633 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=$resaID' >".$LANG["reservation"][36]."</a>"; |
634 |
} else {
|
635 |
echo $LANG["reservation"][36]; |
636 |
} |
637 |
|
638 |
echo "</th></tr>"; |
639 |
if ($DB->numrows($result)==0){ |
640 |
echo "<tr class='tab_bg_2'><td align='center' colspan='5'>".$LANG["reservation"][37]."</td></tr>"; |
641 |
} else {
|
642 |
echo "<tr><th>".$LANG["search"][8]."</th><th>".$LANG["search"][9]."</th><th>".$LANG["reservation"][31]."</th><th>".$LANG["common"][25]."</th><th> </th></tr>"; |
643 |
while ($data=$DB->fetch_assoc($result)){ |
644 |
echo "<tr class='tab_bg_2'>"; |
645 |
echo "<td class='center'>".convDateTime($data["begin"])."</td>"; |
646 |
echo "<td class='center'>".convDateTime($data["end"])."</td>"; |
647 |
echo "<td class='center'><a href='".$CFG_GLPI["root_doc"]."/front/user.form.php?ID=".$data["id_user"]."'>".getUserName($data["id_user"])."</a></td>"; |
648 |
echo "<td class='center'>".nl2br($data["comment"])."</td>"; |
649 |
echo "<td class='center'>"; |
650 |
|
651 |
list($annee,$mois,$jour)=split("-",$data["begin"]); |
652 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=".$resaID."&mois_courant=$mois&annee_courante=$annee' title='".$LANG["reservation"][21]."'><img src=\"".$CFG_GLPI["root_doc"]."/pics/reservation-3.png\" alt='' title=''></a>"; |
653 |
|
654 |
echo "</td>"; |
655 |
echo "</tr>"; |
656 |
} |
657 |
} |
658 |
echo "</table>"; |
659 |
echo "<br>"; |
660 |
|
661 |
|
662 |
} else echo "<strong>".$LANG["reservation"][34]."</strong>"; |
663 |
echo "</div>"; |
664 |
|
665 |
} |
666 |
|
667 |
function showUserReservations($target,$ID){ |
668 |
global $DB,$LANG,$CFG_GLPI; |
669 |
$resaID=0; |
670 |
|
671 |
if (!haveRight("reservation_central","r")) return false; |
672 |
|
673 |
echo "<div class='center'>"; |
674 |
|
675 |
$now=$_SESSION["glpi_currenttime"]; |
676 |
|
677 |
// Print reservation in progress
|
678 |
$query = "SELECT * FROM glpi_reservation_resa WHERE end > '".$now."' AND id_user='$ID' ORDER BY begin"; |
679 |
$result=$DB->query($query); |
680 |
$ri=new ReservationItem(); |
681 |
$ci=new CommonItem(); |
682 |
echo "<table class='tab_cadrehov'><tr><th colspan='6'>".$LANG["reservation"][35]."</th></tr>"; |
683 |
if ($DB->numrows($result)==0){ |
684 |
echo "<tr class='tab_bg_2'><td align='center' colspan='6'>".$LANG["reservation"][37]."</td></tr>"; |
685 |
} else {
|
686 |
echo "<tr><th>".$LANG["search"][8]."</th><th>".$LANG["search"][9]."</th><th>".$LANG["common"][1]."</th><th>".$LANG["reservation"][31]."</th><th>".$LANG["common"][25]."</th><th> </th></tr>"; |
687 |
|
688 |
while ($data=$DB->fetch_assoc($result)){ |
689 |
echo "<tr class='tab_bg_2'>"; |
690 |
echo "<td class='center'>".convDateTime($data["begin"])."</td>"; |
691 |
echo "<td class='center'>".convDateTime($data["end"])."</td>"; |
692 |
if ($ri->getFromDB($data["id_item"])){ |
693 |
$ci->getFromDB($ri->fields['device_type'],$ri->fields['id_device']); |
694 |
echo "<td class='center'>".$ci->getLink()."</td>"; |
695 |
} else {
|
696 |
echo "<td class='center'> </td>"; |
697 |
} |
698 |
echo "<td class='center'>".getUserName($data["id_user"])."</td>"; |
699 |
echo "<td class='center'>".nl2br($data["comment"])."</td>"; |
700 |
echo "<td class='center'>"; |
701 |
|
702 |
list($annee,$mois,$jour)=split("-",$data["begin"]); |
703 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=".$data["id_item"]."&mois_courant=$mois&annee_courante=$annee' title='".$LANG["reservation"][21]."'><img src=\"".$CFG_GLPI["root_doc"]."/pics/reservation-3.png\" alt='' title=''></a>"; |
704 |
|
705 |
echo "</td>"; |
706 |
echo "</tr>"; |
707 |
} |
708 |
} |
709 |
echo "</table>"; |
710 |
echo "<br>"; |
711 |
// Print old reservations
|
712 |
|
713 |
$query = "SELECT * FROM glpi_reservation_resa WHERE end <= '".$now."' AND id_user='$ID' ORDER BY begin DESC"; |
714 |
$result=$DB->query($query); |
715 |
|
716 |
echo "<table class='tab_cadrehov'><tr><th colspan='6'>".$LANG["reservation"][36]."</th></tr>"; |
717 |
if ($DB->numrows($result)==0){ |
718 |
echo "<tr class='tab_bg_2'><td align='center' colspan='6'>".$LANG["reservation"][37]."</td></tr>"; |
719 |
} else {
|
720 |
echo "<tr><th>".$LANG["search"][8]."</th><th>".$LANG["search"][9]."</th><th>".$LANG["common"][1]."</th><th>".$LANG["reservation"][31]."</th><th>".$LANG["common"][25]."</th><th> </th></tr>"; |
721 |
while ($data=$DB->fetch_assoc($result)){ |
722 |
echo "<tr class='tab_bg_2'>"; |
723 |
echo "<td class='center'>".convDateTime($data["begin"])."</td>"; |
724 |
echo "<td class='center'>".convDateTime($data["end"])."</td>"; |
725 |
if ($ri->getFromDB($data["id_item"])){ |
726 |
$ci->getFromDB($ri->fields['device_type'],$ri->fields['id_device']); |
727 |
echo "<td class='center'>".$ci->getLink()."</td>"; |
728 |
} else {
|
729 |
echo "<td class='center'> </td>"; |
730 |
} |
731 |
echo "<td class='center'>".getUserName($data["id_user"])."</td>"; |
732 |
echo "<td class='center'>".nl2br($data["comment"])."</td>"; |
733 |
echo "<td class='center'>"; |
734 |
|
735 |
list($annee,$mois,$jour)=split("-",$data["begin"]); |
736 |
echo "<a href='".$CFG_GLPI["root_doc"]."/front/reservation.php?show=resa&ID=".$data["id_item"]."&mois_courant=$mois&annee_courante=$annee' title='".$LANG["reservation"][21]."'><img src=\"".$CFG_GLPI["root_doc"]."/pics/reservation-3.png\" alt='' title=''></a>"; |
737 |
|
738 |
echo "</td>"; |
739 |
echo "</tr>"; |
740 |
} |
741 |
} |
742 |
echo "</table>"; |
743 |
echo "<br>"; |
744 |
|
745 |
echo "</div>"; |
746 |
|
747 |
} |
748 |
|
749 |
function isReservable($type,$ID){ |
750 |
|
751 |
global $DB; |
752 |
$query="SELECT ID FROM glpi_reservation_item WHERE device_type='$type' AND id_device='$ID'"; |
753 |
$result=$DB->query($query); |
754 |
if ($DB->numrows($result)==0){ |
755 |
return false; |
756 |
} else return $DB->result($result,0,0); |
757 |
} |
758 |
|
759 |
?>
|