ryxeo-glpi-git / inc / planning.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (27,4 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: planning.function.php 7881 2009-01-23 17:56:15Z 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 | |||
41 | // FUNCTIONS Planning
|
||
42 | |||
43 | |||
44 | /**
|
||
45 | * Show the planning
|
||
46 | *
|
||
47 | *
|
||
48 | * @param $who ID of the user (0 = undefined)
|
||
49 | * @param $who_group ID of the group of users (0 = undefined)
|
||
50 | * @param $when Date of the planning to display
|
||
51 | * @param $type type of planning to display (day, week, month)
|
||
52 | * @return Nothing (display function)
|
||
53 | *
|
||
54 | **/
|
||
55 | function showPlanning($who,$who_group,$when,$type){ |
||
56 | global $LANG,$CFG_GLPI,$DB; |
||
57 | |||
58 | if (!haveRight("show_planning","1")&&!haveRight("show_all_planning","1")) return false; |
||
59 | |||
60 | // Define some constants
|
||
61 | |||
62 | $date=split("-",$when); |
||
63 | $time=mktime(0,0,0,$date[1],$date[2],$date[0]); |
||
64 | |||
65 | // Check bisextile years
|
||
66 | list($current_year,$current_month,$current_day)=split("-",$when); |
||
67 | if (($current_year%4)==0) $feb=29; else $feb=28; |
||
68 | $nb_days= array(31,$feb,31,30,31,30,31,31,30,31,30,31); |
||
69 | // Begin of the month
|
||
70 | $begin_month_day=strftime("%w",mktime(0,0,0,$current_month,1,$current_year)); |
||
71 | if ($begin_month_day==0) $begin_month_day=7; |
||
72 | $end_month_day=strftime("%w",mktime(0,0,0,$current_month,$nb_days[$current_month-1],$current_year)); |
||
73 | // Day of the week
|
||
74 | $dayofweek=date("w",$time); |
||
75 | // Cas du dimanche
|
||
76 | if ($dayofweek==0) $dayofweek=7; |
||
77 | |||
78 | |||
79 | |||
80 | |||
81 | // Print Headers
|
||
82 | echo "<div class='center'><table class='tab_cadre_fixe'>"; |
||
83 | // Print Headers
|
||
84 | echo "<tr>"; |
||
85 | switch ($type){ |
||
86 | case "month": |
||
87 | case "week": |
||
88 | for ($i=1;$i<=7;$i++){ |
||
89 | echo "<th width='12%'>".$LANG["calendarDay"][$i%7]."</th>"; |
||
90 | } |
||
91 | break;
|
||
92 | case "day": |
||
93 | echo "<th width='12%'>".$LANG["calendarDay"][$dayofweek%7]."</th>"; |
||
94 | break;
|
||
95 | } |
||
96 | echo "</tr>"; |
||
97 | |||
98 | // Get begin and duration
|
||
99 | $begin=0; |
||
100 | $end=0; |
||
101 | switch ($type){ |
||
102 | case "month": |
||
103 | $begin=strtotime($current_year."-".$current_month."-01 00:00:00"); |
||
104 | $end=$begin+DAY_TIMESTAMP*$nb_days[$current_month-1]; |
||
105 | break;
|
||
106 | case "week": |
||
107 | $begin=$time+mktime(0,0,0,0,1,0)-mktime(0,0,0,0,$dayofweek,0); |
||
108 | $end=$begin+WEEK_TIMESTAMP; |
||
109 | break;
|
||
110 | case "day": |
||
111 | $add=""; |
||
112 | $begin=$time; |
||
113 | $end=$begin+DAY_TIMESTAMP; |
||
114 | break;
|
||
115 | } |
||
116 | $begin=date("Y-m-d H:i:s",$begin); |
||
117 | $end=date("Y-m-d H:i:s",$end); |
||
118 | |||
119 | // Get items to print
|
||
120 | $ASSIGN=""; |
||
121 | |||
122 | if ($who_group=="mine"){ |
||
123 | if (count($_SESSION["glpigroups"])){ |
||
124 | $first=true; |
||
125 | $groups=""; |
||
126 | foreach ($_SESSION['glpigroups'] as $val){ |
||
127 | if (!$first) $groups.=","; |
||
128 | else $first=false; |
||
129 | $groups.="'".$val."'"; |
||
130 | } |
||
131 | $ASSIGN="id_assign IN (SELECT DISTINCT FK_users FROM glpi_users_groups WHERE FK_groups IN ($groups)) AND"; |
||
132 | } else { // Only personal ones |
||
133 | $ASSIGN="id_assign='$who' AND "; |
||
134 | } |
||
135 | } else {
|
||
136 | |||
137 | if ($who>0){ |
||
138 | $ASSIGN="id_assign='$who' AND "; |
||
139 | } |
||
140 | |||
141 | if ($who_group>0){ |
||
142 | $ASSIGN="id_assign IN (SELECT FK_users FROM glpi_users_groups WHERE FK_groups = '$who_group') AND"; |
||
143 | } |
||
144 | } |
||
145 | if (empty($ASSIGN)){ |
||
146 | $ASSIGN=" id_assign IN (SELECT DISTINCT glpi_users_profiles.FK_users |
||
147 | FROM glpi_profiles
|
||
148 | LEFT JOIN glpi_users_profiles ON (glpi_profiles.ID = glpi_users_profiles.FK_profiles)
|
||
149 | WHERE glpi_profiles.interface='central' ";
|
||
150 | |||
151 | $ASSIGN.=getEntitiesRestrictRequest("AND","glpi_users_profiles", '',$_SESSION["glpiactive_entity"],1); |
||
152 | $ASSIGN.=") AND "; |
||
153 | |||
154 | |||
155 | } |
||
156 | // ---------------Tracking
|
||
157 | $query="SELECT * FROM glpi_tracking_planning WHERE $ASSIGN (('$begin' <= begin AND '$end' >= begin) OR ('$begin' < end AND '$end' >= end) OR (begin <= '$begin' AND end > '$begin') OR (begin <= '$end' AND end > '$end')) ORDER BY begin"; |
||
158 | |||
159 | $result=$DB->query($query); |
||
160 | |||
161 | $fup=new Followup(); |
||
162 | $job=new Job(); |
||
163 | |||
164 | $interv=array(); |
||
165 | $i=0; |
||
166 | if ($DB->numrows($result)>0) |
||
167 | while ($data=$DB->fetch_array($result)){ |
||
168 | $fup->getFromDB($data["id_followup"]); |
||
169 | $job->getFromDBwithData($fup->fields["tracking"],0); |
||
170 | if (haveAccessToEntity($job->fields["FK_entities"])){ |
||
171 | $interv[$data["begin"]."$$$".$i]["id_followup"]=$data["id_followup"]; |
||
172 | $interv[$data["begin"]."$$$".$i]["state"]=$data["state"]; |
||
173 | $interv[$data["begin"]."$$$".$i]["id_tracking"]=$fup->fields["tracking"]; |
||
174 | $interv[$data["begin"]."$$$".$i]["id_assign"]=$data["id_assign"]; |
||
175 | $interv[$data["begin"]."$$$".$i]["ID"]=$data["ID"]; |
||
176 | if (strcmp($begin,$data["begin"])>0){ |
||
177 | $interv[$data["begin"]."$$$".$i]["begin"]=$begin; |
||
178 | } else {
|
||
179 | $interv[$data["begin"]."$$$".$i]["begin"]=$data["begin"]; |
||
180 | } |
||
181 | if (strcmp($end,$data["end"])<0){ |
||
182 | $interv[$data["begin"]."$$$".$i]["end"]=$end; |
||
183 | } else {
|
||
184 | $interv[$data["begin"]."$$$".$i]["end"]=$data["end"]; |
||
185 | } |
||
186 | $interv[$data["begin"]."$$$".$i]["name"]=$job->fields["name"]; |
||
187 | $interv[$data["begin"]."$$$".$i]["content"]=resume_text($job->fields["contents"],$CFG_GLPI["cut"]); |
||
188 | $interv[$data["begin"]."$$$".$i]["device"]=$job->hardwaredatas->getName(); |
||
189 | $interv[$data["begin"]."$$$".$i]["status"]=$job->fields["status"]; |
||
190 | $interv[$data["begin"]."$$$".$i]["priority"]=$job->fields["priority"]; |
||
191 | $i++;
|
||
192 | } |
||
193 | } |
||
194 | |||
195 | // ---------------reminder
|
||
196 | $readpub=$readpriv=""; |
||
197 | |||
198 | // See public reminder ?
|
||
199 | if (haveRight("reminder_public","r")) { |
||
200 | $readpub="(private=0 AND".getEntitiesRestrictRequest("","glpi_reminder",'','',true).")"; |
||
201 | } |
||
202 | |||
203 | // See my private reminder ?
|
||
204 | if ($who_group=="mine" || $who==$_SESSION["glpiID"]){ |
||
205 | $readpriv="(private=1 AND FK_users='".$_SESSION["glpiID"]."')"; |
||
206 | } |
||
207 | |||
208 | if ($readpub && $readpriv) { |
||
209 | $ASSIGN = "($readpub OR $readpriv)"; |
||
210 | } else if ($readpub) { |
||
211 | $ASSIGN = $readpub; |
||
212 | } else {
|
||
213 | $ASSIGN = $readpriv; |
||
214 | } |
||
215 | if ($ASSIGN) { |
||
216 | $query2="SELECT * FROM glpi_reminder WHERE rv=1 AND $ASSIGN AND begin < '$end' AND end > '$begin' ORDER BY begin"; |
||
217 | $result2=$DB->query($query2); |
||
218 | |||
219 | if ($DB->numrows($result2)>0) { |
||
220 | while ($data=$DB->fetch_array($result2)){ |
||
221 | |||
222 | $interv[$data["begin"]."$$".$i]["id_reminder"]=$data["ID"]; |
||
223 | if (strcmp($begin,$data["begin"])>0) |
||
224 | $interv[$data["begin"]."$$".$i]["begin"]=$begin; |
||
225 | else $interv[$data["begin"]."$$".$i]["begin"]=$data["begin"]; |
||
226 | if (strcmp($end,$data["end"])<0) |
||
227 | $interv[$data["begin"]."$$".$i]["end"]=$end; |
||
228 | else $interv[$data["begin"]."$$".$i]["end"]=$data["end"]; |
||
229 | |||
230 | $interv[$data["begin"]."$$".$i]["name"]=resume_text($data["name"],$CFG_GLPI["cut"]); |
||
231 | $interv[$data["begin"]."$$".$i]["text"]=resume_text($data["text"],$CFG_GLPI["cut"]); |
||
232 | $interv[$data["begin"]."$$".$i]["FK_users"]=$data["FK_users"]; |
||
233 | $interv[$data["begin"]."$$".$i]["private"]=$data["private"]; |
||
234 | $interv[$data["begin"]."$$".$i]["state"]=$data["state"]; |
||
235 | |||
236 | $i++;
|
||
237 | } //
|
||
238 | } |
||
239 | } |
||
240 | |||
241 | // --------------- Plugins
|
||
242 | $data=doHookFunction("planning_populate",array("begin"=>$begin,"end"=>$end,"who"=>$who,"who_group"=>$who_group)); |
||
243 | |||
244 | if (isset($data["items"])&&count($data["items"])){ |
||
245 | $interv=array_merge($data["items"],$interv); |
||
246 | } |
||
247 | |||
248 | ksort($interv); |
||
249 | |||
250 | // Display Items
|
||
251 | $tmp=split(":",$CFG_GLPI["planning_begin"]); |
||
252 | $hour_begin=$tmp[0]; |
||
253 | $tmp=split(":",$CFG_GLPI["planning_end"]); |
||
254 | $hour_end=$tmp[0]; |
||
255 | |||
256 | switch ($type){ |
||
257 | case "week": |
||
258 | for ($hour=$hour_begin;$hour<=$hour_end;$hour++){ |
||
259 | echo "<tr>"; |
||
260 | for ($i=1;$i<=7;$i++){ |
||
261 | echo "<td class='tab_bg_3' width='12%' valign='top' >"; |
||
262 | echo "<strong>".displayUsingTwoDigits($hour).":00</strong><br>"; |
||
263 | |||
264 | // From midnight
|
||
265 | if ($hour==$hour_begin){ |
||
266 | $begin_time=date("Y-m-d H:i:s",strtotime($when)+($i-$dayofweek)*DAY_TIMESTAMP); |
||
267 | } else {
|
||
268 | $begin_time=date("Y-m-d H:i:s",strtotime($when)+($i-$dayofweek)*DAY_TIMESTAMP+$hour*HOUR_TIMESTAMP); |
||
269 | } |
||
270 | // To midnight
|
||
271 | if($hour==$hour_end){ |
||
272 | $end_time=date("Y-m-d H:i:s",strtotime($when)+($i-$dayofweek)*DAY_TIMESTAMP+24*HOUR_TIMESTAMP); |
||
273 | } else {
|
||
274 | $end_time=date("Y-m-d H:i:s",strtotime($when)+($i-$dayofweek)*DAY_TIMESTAMP+($hour+1)*HOUR_TIMESTAMP); |
||
275 | } |
||
276 | |||
277 | reset($interv); |
||
278 | while ($data=current($interv)){ |
||
279 | $type=""; |
||
280 | |||
281 | if ($data["begin"]>=$begin_time&&$data["end"]<=$end_time){ |
||
282 | $type="in"; |
||
283 | } else if ($data["begin"]<$begin_time&&$data["end"]>$end_time){ |
||
284 | $type="through"; |
||
285 | } else if ($data["begin"]>=$begin_time&&$data["begin"]<$end_time){ |
||
286 | $type="begin"; |
||
287 | } else if ($data["end"]>$begin_time&&$data["end"]<=$end_time){ |
||
288 | $type="end"; |
||
289 | } |
||
290 | |||
291 | if (empty($type)){ |
||
292 | next($interv); |
||
293 | } else {
|
||
294 | displayPlanningItem($data,$who,$type); |
||
295 | if ($type=="in"){ |
||
296 | unset($interv[key($interv)]); |
||
297 | } else {
|
||
298 | next($interv); |
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | echo "</td>"; |
||
303 | } |
||
304 | |||
305 | echo "</tr>\n"; |
||
306 | |||
307 | } |
||
308 | |||
309 | break;
|
||
310 | case "day": |
||
311 | for ($hour=$hour_begin;$hour<=$hour_end;$hour++){ |
||
312 | echo "<tr>"; |
||
313 | $begin_time=date("Y-m-d H:i:s",strtotime($when)+($hour)*HOUR_TIMESTAMP); |
||
314 | $end_time=date("Y-m-d H:i:s",strtotime($when)+($hour+1)*HOUR_TIMESTAMP); |
||
315 | echo "<td class='tab_bg_3' width='12%' valign='top' >"; |
||
316 | echo "<strong>".displayUsingTwoDigits($hour).":00</strong><br>"; |
||
317 | reset($interv); |
||
318 | while ($data=current($interv)){ |
||
319 | $type=""; |
||
320 | if ($data["begin"]>=$begin_time&&$data["end"]<=$end_time){ |
||
321 | $type="in"; |
||
322 | } else if ($data["begin"]<$begin_time&&$data["end"]>$end_time){ |
||
323 | $type="through"; |
||
324 | } else if ($data["begin"]>=$begin_time&&$data["begin"]<$end_time){ |
||
325 | $type="begin"; |
||
326 | } else if ($data["end"]>$begin_time&&$data["end"]<=$end_time){ |
||
327 | $type="end"; |
||
328 | } |
||
329 | |||
330 | if (empty($type)){ |
||
331 | next($interv); |
||
332 | } else {
|
||
333 | displayPlanningItem($data,$who,$type,1); |
||
334 | if ($type=="in"){ |
||
335 | unset($interv[key($interv)]); |
||
336 | } else {
|
||
337 | next($interv); |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | echo "</td>"; |
||
342 | echo "</tr>"; |
||
343 | } |
||
344 | break;
|
||
345 | case "month": |
||
346 | echo "<tr class='tab_bg_3'>"; |
||
347 | // Display first day out of the month
|
||
348 | for ($i=1;$i<$begin_month_day;$i++){ |
||
349 | echo "<td style='background-color:#ffffff'> </td>"; |
||
350 | } |
||
351 | // Print real days
|
||
352 | if ($current_month<10&&strlen($current_month)==1) $current_month="0".$current_month; |
||
353 | |||
354 | $begin_time=strtotime($begin); |
||
355 | $end_time=strtotime($end); |
||
356 | |||
357 | for ($time=$begin_time;$time<$end_time;$time+=DAY_TIMESTAMP){ |
||
358 | |||
359 | // Add 6 hours for midnight problem
|
||
360 | $day=date("d",$time+6*HOUR_TIMESTAMP); |
||
361 | |||
362 | echo "<td valign='top' height='100' class='tab_bg_3'>"; |
||
363 | echo "<table align='center' ><tr><td align='center' ><span style='font-family: arial,helvetica,sans-serif; font-size: 14px; color: black'>".$day."</span></td></tr>"; |
||
364 | |||
365 | echo "<tr class='tab_bg_3'>"; |
||
366 | echo "<td class='tab_bg_3' width='12%' valign='top' >"; |
||
367 | $begin_day=date("Y-m-d H:i:s",$time); |
||
368 | $end_day=date("Y-m-d H:i:s",$time+DAY_TIMESTAMP); |
||
369 | reset($interv); |
||
370 | while ($data=current($interv)){ |
||
371 | $type=""; |
||
372 | |||
373 | if ($data["begin"]>=$begin_day&&$data["end"]<=$end_day){ |
||
374 | $type="in"; |
||
375 | } else if ($data["begin"]<$begin_day&&$data["end"]>$end_day){ |
||
376 | $type="through"; |
||
377 | } else if ($data["begin"]>=$begin_day&&$data["begin"]<$end_day){ |
||
378 | $type="begin"; |
||
379 | } else if ($data["end"]>$begin_day&&$data["end"]<=$end_day){ |
||
380 | $type="end"; |
||
381 | } |
||
382 | |||
383 | if (empty($type)){ |
||
384 | next($interv); |
||
385 | } else {
|
||
386 | displayPlanningItem($data,$who,$type); |
||
387 | if ($type=="in"){ |
||
388 | unset($interv[key($interv)]); |
||
389 | } else {
|
||
390 | next($interv); |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | |||
395 | echo "</td>"; |
||
396 | |||
397 | echo "</tr>"; |
||
398 | echo "</table>"; |
||
399 | echo "</td>"; |
||
400 | |||
401 | // Add break line
|
||
402 | if (($day+$begin_month_day)%7==1) { |
||
403 | echo "</tr>"; |
||
404 | if ($day!=$nb_days[$current_month-1]){ |
||
405 | echo "<tr>"; |
||
406 | } |
||
407 | } |
||
408 | |||
409 | } |
||
410 | if ($end_month_day!=0){ |
||
411 | for ($i=0;$i<7-$end_month_day;$i++) { |
||
412 | echo "<td style='background-color:#ffffff'> </td>"; |
||
413 | } |
||
414 | } |
||
415 | echo "</tr>"; |
||
416 | |||
417 | |||
418 | break;
|
||
419 | |||
420 | } |
||
421 | |||
422 | echo "</table></div>"; |
||
423 | |||
424 | } |
||
425 | |||
426 | /**
|
||
427 | * Display a Planning Item
|
||
428 | *
|
||
429 | *
|
||
430 | * @param $val Array of the item to display
|
||
431 | * @param $who ID of the user (0 if all)
|
||
432 | * @param $type position of the item in the time block (in, through, begin or end)
|
||
433 | * @param $complete complete display (more details)
|
||
434 | * @return Nothing (display function)
|
||
435 | *
|
||
436 | **/
|
||
437 | function displayPlanningItem($val,$who,$type="",$complete=0){ |
||
438 | global $CFG_GLPI,$LANG,$PLUGIN_HOOKS; |
||
439 | |||
440 | $author=""; // show author reminder |
||
441 | $img="rdv_private.png"; // default icon for reminder |
||
442 | $color="#e4e4e4"; |
||
443 | $styleText=""; |
||
444 | if (isset($val["state"])){ |
||
445 | switch ($val["state"]){ |
||
446 | case 0: |
||
447 | $color="#efefe7"; // Information |
||
448 | break;
|
||
449 | case 1: |
||
450 | $color="#fbfbfb"; // TODO |
||
451 | break;
|
||
452 | case 2: |
||
453 | $color="#e7e7e2"; // Done |
||
454 | $styleText="color:#747474;"; |
||
455 | |||
456 | break;
|
||
457 | |||
458 | } |
||
459 | } |
||
460 | |||
461 | echo "<div style=' margin:auto; text-align:left; border:1px dashed #cccccc; background-color: $color; font-size:9px; width:98%; '>"; |
||
462 | $rand=mt_rand();
|
||
463 | |||
464 | // Plugins case
|
||
465 | if (isset($val["plugin"])&&isset($PLUGIN_HOOKS['display_planning'][$val["plugin"]])){ |
||
466 | $function=$PLUGIN_HOOKS['display_planning'][$val["plugin"]]; |
||
467 | if (function_exists($function)) { |
||
468 | $val["type"]=$type; |
||
469 | $function($val); |
||
470 | } |
||
471 | } else if(isset($val["id_tracking"])){ // show tracking |
||
472 | |||
473 | echo "<img src='".$CFG_GLPI["root_doc"]."/pics/rdv_interv.png' alt='' title='".$LANG["planning"][8]."'> "; |
||
474 | echo " <img src=\"".$CFG_GLPI["root_doc"]."/pics/".$val["status"].".png\" alt='".getStatusName($val["status"])."' title='".getStatusName($val["status"])."'> "; |
||
475 | |||
476 | echo "<a href='".$CFG_GLPI["root_doc"]."/front/tracking.form.php?ID=".$val["id_tracking"]."' style='$styleText'"; |
||
477 | if (!$complete){ |
||
478 | echo "onmouseout=\"cleanhide('content_tracking_".$val["ID"].$rand."')\" onmouseover=\"cleandisplay('content_tracking_".$val["ID"].$rand."')\""; |
||
479 | } |
||
480 | echo ">"; |
||
481 | switch ($type){ |
||
482 | case "in": |
||
483 | echo date("H:i",strtotime($val["begin"]))."/".date("H:i",strtotime($val["end"])).": "; |
||
484 | break;
|
||
485 | case "through": |
||
486 | break;
|
||
487 | case "begin"; |
||
488 | echo $LANG["buttons"][33]." ".date("H:i",strtotime($val["begin"])).": "; |
||
489 | break;
|
||
490 | case "end"; |
||
491 | echo $LANG["buttons"][32]." ".date("H:i",strtotime($val["end"])).": "; |
||
492 | break;
|
||
493 | |||
494 | } |
||
495 | echo "<br>- #".$val["id_tracking"]." "; |
||
496 | echo resume_text($val["name"],80). " "; |
||
497 | if (!empty($val["device"])){ |
||
498 | echo "<br>- ".$val["device"]; |
||
499 | } |
||
500 | |||
501 | if ($who<=0){ // show tech for "show all and show group" |
||
502 | echo "<br>- "; |
||
503 | echo $LANG["planning"][9]." ".getUserName($val["id_assign"]); |
||
504 | } |
||
505 | echo "</a>"; |
||
506 | if ($complete){ |
||
507 | echo "<br>"; |
||
508 | echo "<strong>".getPlanningState($val["state"])."</strong><br>"; |
||
509 | echo "<strong>".$LANG["joblist"][2].":</strong> ".getPriorityName($val["priority"])."<br>"; |
||
510 | echo "<strong>".$LANG["joblist"][6].":</strong><br>".$val["content"]; |
||
511 | } else {
|
||
512 | echo "<div class='over_link' id='content_tracking_".$val["ID"].$rand."'>"; |
||
513 | echo "<strong>".getPlanningState($val["state"])."</strong><br>"; |
||
514 | echo "<strong>".$LANG["joblist"][2].":</strong> ".getPriorityName($val["priority"])."<br>"; |
||
515 | echo "<strong>".$LANG["joblist"][6].":</strong><br>".$val["content"]."</div>"; |
||
516 | } |
||
517 | |||
518 | }else{ // show Reminder |
||
519 | if (!$val["private"]){ |
||
520 | $author="<br>".$LANG["planning"][9]." : ".getUserName($val["FK_users"]); |
||
521 | $img="rdv_public.png"; |
||
522 | } |
||
523 | echo "<img src='".$CFG_GLPI["root_doc"]."/pics/".$img."' alt='' title='".$LANG["title"][37]."'> "; |
||
524 | echo "<a href='".$CFG_GLPI["root_doc"]."/front/reminder.form.php?ID=".$val["id_reminder"]."'"; |
||
525 | if (!$complete){ |
||
526 | echo "onmouseout=\"cleanhide('content_reminder_".$val["id_reminder"].$rand."')\" onmouseover=\"cleandisplay('content_reminder_".$val["id_reminder"].$rand."')\""; |
||
527 | } |
||
528 | echo ">"; |
||
529 | |||
530 | switch ($type){ |
||
531 | case "in": |
||
532 | echo date("H:i",strtotime($val["begin"]))." -> ".date("H:i",strtotime($val["end"])).": "; |
||
533 | break;
|
||
534 | case "through": |
||
535 | break;
|
||
536 | case "begin"; |
||
537 | echo $LANG["buttons"][33]." ".date("H:i",strtotime($val["begin"])).": "; |
||
538 | break;
|
||
539 | case "end"; |
||
540 | echo $LANG["buttons"][32]." ".date("H:i",strtotime($val["end"])).": "; |
||
541 | break;
|
||
542 | |||
543 | } |
||
544 | echo $val["name"]; |
||
545 | echo $author; |
||
546 | echo "</a>"; |
||
547 | if ($complete){ |
||
548 | echo "<br><strong>".getPlanningState($val["state"])."</strong><br>"; |
||
549 | echo $val["text"]; |
||
550 | } else {
|
||
551 | echo "<div class='over_link' id='content_reminder_".$val["id_reminder"].$rand."'><strong>".getPlanningState($val["state"])."</strong><br>".$val["text"]."</div>"; |
||
552 | } |
||
553 | |||
554 | echo ""; |
||
555 | } |
||
556 | echo "</div><br>"; |
||
557 | |||
558 | } |
||
559 | |||
560 | |||
561 | /**
|
||
562 | * Display an integer using 2 digits
|
||
563 | *
|
||
564 | *
|
||
565 | * @param $time value to display
|
||
566 | * @return string return the 2 digits item
|
||
567 | *
|
||
568 | **/
|
||
569 | function displayUsingTwoDigits($time){ |
||
570 | |||
571 | $time=round($time); |
||
572 | if ($time<10&&strlen($time)) return "0".$time; |
||
573 | else return $time; |
||
574 | } |
||
575 | |||
576 | /**
|
||
577 | * Show the planning for the central page of a user
|
||
578 | *
|
||
579 | *
|
||
580 | * @param $who ID of the user
|
||
581 | * @return Nothing (display function)
|
||
582 | *
|
||
583 | **/
|
||
584 | function showPlanningCentral($who){ |
||
585 | |||
586 | global $DB,$CFG_GLPI,$LANG; |
||
587 | |||
588 | if (!haveRight("show_planning","1")) return false; |
||
589 | |||
590 | $when=strftime("%Y-%m-%d"); |
||
591 | $debut=$when; |
||
592 | |||
593 | // followup
|
||
594 | $ASSIGN=""; |
||
595 | if ($who!=0){ |
||
596 | $ASSIGN="id_assign='$who' AND"; |
||
597 | } else {
|
||
598 | return false; |
||
599 | } |
||
600 | |||
601 | |||
602 | $INTERVAL=" 1 DAY "; // we want to show planning of the day |
||
603 | |||
604 | $query="SELECT * FROM glpi_tracking_planning WHERE $ASSIGN (('".$debut."' <= begin AND adddate( '". $debut ."' , INTERVAL $INTERVAL ) >= begin) OR ('".$debut."' < end AND adddate( '". $debut ."' , INTERVAL $INTERVAL ) >= end) OR (begin <= '".$debut."' AND end > '".$debut."') OR (begin <= adddate( '". $debut ."' , INTERVAL $INTERVAL ) AND end > adddate( '". $debut ."' , INTERVAL $INTERVAL ))) ORDER BY begin"; |
||
605 | |||
606 | $result=$DB->query($query); |
||
607 | |||
608 | $fup=new Followup(); |
||
609 | $job=new Job(); |
||
610 | |||
611 | $interv=array(); |
||
612 | $i=0; |
||
613 | |||
614 | if ($DB->numrows($result)>0) |
||
615 | while ($data=$DB->fetch_array($result)){ |
||
616 | if ($fup->getFromDB($data["id_followup"])){ |
||
617 | if ($job->getFromDBwithData($fup->fields["tracking"],0)){ |
||
618 | if (haveAccessToEntity($job->fields["FK_entities"])){ |
||
619 | $interv[$data["begin"]."$$".$i]["id_followup"]=$data["id_followup"]; |
||
620 | $interv[$data["begin"]."$$".$i]["id_tracking"]=$fup->fields["tracking"]; |
||
621 | $interv[$data["begin"]."$$".$i]["begin"]=$data["begin"]; |
||
622 | $interv[$data["begin"]."$$".$i]["end"]=$data["end"]; |
||
623 | $interv[$data["begin"]."$$".$i]["state"]=$data["state"]; |
||
624 | $interv[$data["begin"]."$$".$i]["content"]=resume_text($job->fields["contents"],$CFG_GLPI["cut"]); |
||
625 | $interv[$data["begin"]."$$".$i]["device"]=$job->hardwaredatas->getName(); |
||
626 | $interv[$data["begin"]."$$".$i]["status"]=$job->fields['status']; |
||
627 | $interv[$data["begin"]."$$".$i]["id_assign"]=$data["id_assign"]; |
||
628 | $interv[$data["begin"]."$$".$i]["ID"]=$job->fields['ID']; |
||
629 | $interv[$data["begin"]."$$".$i]["name"]=$job->fields['name']; |
||
630 | $interv[$data["begin"]."$$".$i]["priority"]=$job->fields['priority']; |
||
631 | $i++;
|
||
632 | } |
||
633 | } |
||
634 | } |
||
635 | } |
||
636 | |||
637 | |||
638 | // reminder
|
||
639 | $read_public=""; |
||
640 | if (haveRight("reminder_public","r")) $read_public=" OR ( private=0 ".getEntitiesRestrictRequest("AND","glpi_reminder").") "; |
||
641 | |||
642 | $query2="SELECT * FROM glpi_reminder WHERE rv='1' AND (FK_users='$who' $read_public) AND (('".$debut."' <= begin AND adddate( '". $debut ."' , INTERVAL $INTERVAL ) >= begin) OR ('".$debut."' < end AND adddate( '". $debut ."' , INTERVAL $INTERVAL ) >= end) OR (begin <= '".$debut."' AND end > '".$debut."') OR (begin <= adddate( '". $debut ."' , INTERVAL $INTERVAL ) AND end > adddate( '". $debut ."' , INTERVAL $INTERVAL ))) ORDER BY begin"; |
||
643 | |||
644 | $result2=$DB->query($query2); |
||
645 | |||
646 | |||
647 | $remind=new Reminder(); |
||
648 | |||
649 | $i=0; |
||
650 | |||
651 | if ($DB->numrows($result2)>0) |
||
652 | while ($data=$DB->fetch_array($result2)){ |
||
653 | if ($remind->getFromDB($data["ID"])){ |
||
654 | $interv[$data["begin"]."$$".$i]["id_reminder"]=$data["ID"]; |
||
655 | $interv[$data["begin"]."$$".$i]["begin"]=$data["begin"]; |
||
656 | $interv[$data["begin"]."$$".$i]["end"]=$data["end"]; |
||
657 | $interv[$data["begin"]."$$".$i]["private"]=$data["private"]; |
||
658 | $interv[$data["begin"]."$$".$i]["state"]=$data["state"]; |
||
659 | $interv[$data["begin"]."$$".$i]["FK_users"]=$data["FK_users"]; |
||
660 | $interv[$data["begin"]."$$".$i]["name"]=resume_text($remind->fields["name"],$CFG_GLPI["cut"]); |
||
661 | $interv[$data["begin"]."$$".$i]["text"]=resume_text($remind->fields["text"],$CFG_GLPI["cut"]); |
||
662 | $i++;
|
||
663 | } |
||
664 | } |
||
665 | |||
666 | // Get begin and duration
|
||
667 | $date=split("-",$when); |
||
668 | $time=mktime(0,0,0,$date[1],$date[2],$date[0]); |
||
669 | $begin=$time; |
||
670 | $end=$begin+DAY_TIMESTAMP; |
||
671 | $begin=date("Y-m-d H:i:s",$begin); |
||
672 | $end=date("Y-m-d H:i:s",$end); |
||
673 | |||
674 | |||
675 | $data=doHookFunction("planning_populate",array("begin"=>$begin,"end"=>$end,"who"=>$who,"who_group"=>-1)); |
||
676 | |||
677 | if (isset($data["items"])&&count($data["items"])){ |
||
678 | $interv=array_merge($data["items"],$interv); |
||
679 | } |
||
680 | |||
681 | |||
682 | ksort($interv); |
||
683 | |||
684 | echo "<table class='tab_cadrehov'><tr><th><a href='".$CFG_GLPI["root_doc"]."/front/planning.php'>".$LANG["planning"][15]."</a></th></tr>"; |
||
685 | $type=''; |
||
686 | if (count($interv)>0){ |
||
687 | foreach ($interv as $key => $val){ |
||
688 | |||
689 | echo "<tr class='tab_bg_1'>"; |
||
690 | echo "<td>"; |
||
691 | |||
692 | if ($val["begin"]<$begin){ |
||
693 | $val["begin"]=$begin; |
||
694 | } |
||
695 | if ($val["end"]>$end){ |
||
696 | $val["end"]=$end; |
||
697 | } |
||
698 | |||
699 | displayPlanningItem($val,$who,'in'); |
||
700 | |||
701 | echo "</td></tr>"; |
||
702 | |||
703 | } |
||
704 | |||
705 | } |
||
706 | echo "</table>"; |
||
707 | |||
708 | } |
||
709 | |||
710 | |||
711 | |||
712 | |||
713 | |||
714 | |||
715 | |||
716 | |||
717 | |||
718 | |||
719 | |||
720 | |||
721 | |||
722 | |||
723 | |||
724 | |||
725 | //*******************************************************************************************************************************
|
||
726 | // *********************************** Implementation ICAL ***************************************************************
|
||
727 | //*******************************************************************************************************************************
|
||
728 | |||
729 | |||
730 | /**
|
||
731 | * Generate URL for ICAL
|
||
732 | *
|
||
733 | *
|
||
734 | * @param $who
|
||
735 | * @return Nothing (display function)
|
||
736 | *
|
||
737 | **/
|
||
738 | function urlIcal ($who) { |
||
739 | |||
740 | global $CFG_GLPI, $LANG; |
||
741 | |||
742 | echo "<a href=\"".$CFG_GLPI["root_doc"]."/front/planning.ical.php?uID=$who\"><span style='font-size:10px'>-".$LANG["planning"][12]."</span></a>"; |
||
743 | echo "<br>"; |
||
744 | |||
745 | // Todo recup l'url complete de glpi proprement, ? nouveau champs table config ?
|
||
746 | echo "<a href=\"webcal://".$_SERVER['HTTP_HOST'].$CFG_GLPI["root_doc"]."/front/planning.ical.php?uID=$who\"><span style='font-size:10px'>-".$LANG["planning"][13]."</span></a>"; |
||
747 | |||
748 | } |
||
749 | |||
750 | |||
751 | /**
|
||
752 | * Convert date mysql to timestamp
|
||
753 | *
|
||
754 | * @param $date date in mysql format
|
||
755 | * @return timestamp
|
||
756 | *
|
||
757 | **/
|
||
758 | function date_mysql_to_timestamp($date){ |
||
759 | if (!preg_match('/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/', $date, $r)){ |
||
760 | return false; |
||
761 | } |
||
762 | |||
763 | return mktime($r[4], $r[5], $r[6], $r[2], $r[3], $r[1] ); |
||
764 | } |
||
765 | |||
766 | |||
767 | /**
|
||
768 | * Convert timestamp to date in ical format
|
||
769 | *
|
||
770 | * @param $date timestamp
|
||
771 | * @return date in ical format
|
||
772 | *
|
||
773 | **/
|
||
774 | function date_ical($date) { |
||
775 | return date("Ymd\THis", date_mysql_to_timestamp($date)); |
||
776 | } |
||
777 | |||
778 | |||
779 | |||
780 | /**
|
||
781 | *
|
||
782 | * Generate header for ical file
|
||
783 | *
|
||
784 | * @param $name
|
||
785 | * @return $debut_cal
|
||
786 | *
|
||
787 | **/
|
||
788 | function debutIcal($name) { |
||
789 | |||
790 | global $CFG_GLPI, $LANG; |
||
791 | |||
792 | $debut_cal = "BEGIN:VCALENDAR\n"; |
||
793 | $debut_cal .= "VERSION:2.0\n"; |
||
794 | |||
795 | if ( ! empty ( $CFG_GLPI["version"]) ) { |
||
796 | $debut_cal.= "PRODID:-//GLPI-Planning-".$CFG_GLPI["version"]."\n"; |
||
797 | } else {
|
||
798 | $debut_cal.= "PRODID:-//GLPI-Planning-UnknownVersion\n"; |
||
799 | } |
||
800 | |||
801 | $debut_cal.= "METHOD:PUBLISH\n"; // Outlook want's this in the header, why I don't know... |
||
802 | $debut_cal .= "X-WR-CALNAME ;VALUE=TEXT:$name\n"; |
||
803 | |||
804 | // $debut_cal .= "X-WR-RELCALID:n";
|
||
805 | // $debut_cal .= "X-WR-TIMEZONE:US/Pacific\n";
|
||
806 | $debut_cal .= "CALSCALE:GREGORIAN\n\n"; |
||
807 | return (string) $debut_cal; |
||
808 | } |
||
809 | |||
810 | |||
811 | /**
|
||
812 | * Generate ical body file
|
||
813 | *
|
||
814 | * @param $who
|
||
815 | * @return $debutcal $event $fincal
|
||
816 | **/
|
||
817 | function generateIcal($who){ |
||
818 | |||
819 | global $DB,$CFG_GLPI, $LANG; |
||
820 | |||
821 | // export job
|
||
822 | $query="SELECT * FROM glpi_tracking_planning WHERE id_assign='$who'"; |
||
823 | |||
824 | $result=$DB->query($query); |
||
825 | |||
826 | $job=new Job(); |
||
827 | $fup=new Followup(); |
||
828 | $interv=array(); |
||
829 | $i=0; |
||
830 | if ($DB->numrows($result)>0) |
||
831 | while ($data=$DB->fetch_array($result)){ |
||
832 | |||
833 | if ($fup->getFromDB($data["id_followup"])){ |
||
834 | if ($job->getFromDBwithData($fup->fields["tracking"],0)){ |
||
835 | $interv[$data["begin"]."$$".$i]["content"]=substr($job->fields['contents'],0,$CFG_GLPI["cut"]); |
||
836 | $interv[$data["begin"]."$$".$i]["device"]=$job->hardwaredatas->getName(); |
||
837 | } |
||
838 | } |
||
839 | |||
840 | $interv[$data["begin"]."$$".$i]["id_tracking"]=$data['id_followup']; |
||
841 | $interv[$data["begin"]."$$".$i]["id_assign"]=$data['id_assign']; |
||
842 | $interv[$data["begin"]."$$".$i]["ID"]=$data['ID']; |
||
843 | $interv[$data["begin"]."$$".$i]["begin"]=$data['begin']; |
||
844 | $interv[$data["begin"]."$$".$i]["end"]=$data['end']; |
||
845 | $interv[$data["begin"]."$$".$i]["content"]=""; |
||
846 | $interv[$data["begin"]."$$".$i]["device"]=""; |
||
847 | //$interv[$i]["content"]=substr($job->contents,0,$CFG_GLPI["cut"]);
|
||
848 | if ($fup->getFromDB($data["id_followup"])){ |
||
849 | if ($job->getFromDBwithData($fup->fields["tracking"],0)){ |
||
850 | $interv[$data["begin"]."$$".$i]["content"]=substr($job->fields['contents'],0,$CFG_GLPI["cut"]); |
||
851 | $interv[$data["begin"]."$$".$i]["device"]=$job->hardwaredatas->getName(); |
||
852 | } |
||
853 | } |
||
854 | $i++;
|
||
855 | } |
||
856 | |||
857 | |||
858 | // reminder
|
||
859 | |||
860 | $query2="SELECT * FROM glpi_reminder WHERE rv='1' AND (FK_users='$who' OR private=0)"; |
||
861 | |||
862 | $result2=$DB->query($query2); |
||
863 | |||
864 | |||
865 | $remind=new Reminder(); |
||
866 | |||
867 | $i=0; |
||
868 | if ($DB->numrows($result2)>0) |
||
869 | while ($data=$DB->fetch_array($result2)){ |
||
870 | $remind->getFromDB($data["ID"]); |
||
871 | |||
872 | |||
873 | $interv[$data["begin"]."$$".$i]["id_reminder"]=$remind->fields["ID"]; |
||
874 | $interv[$data["begin"]."$$".$i]["begin"]=$data["begin"]; |
||
875 | $interv[$data["begin"]."$$".$i]["end"]=$data["end"]; |
||
876 | $interv[$data["begin"]."$$".$i]["name"]=$remind->fields["name"]; |
||
877 | $interv[$data["begin"]."$$".$i]["content"]=$remind->fields["text"]; |
||
878 | |||
879 | $i++;
|
||
880 | } |
||
881 | |||
882 | $debutcal=""; |
||
883 | $event=""; |
||
884 | $fincal=""; |
||
885 | |||
886 | //
|
||
887 | $begin=time()-MONTH_TIMESTAMP*12; |
||
888 | $end=time()+MONTH_TIMESTAMP*12; |
||
889 | $begin=date("Y-m-d H:i:s",$begin); |
||
890 | $end=date("Y-m-d H:i:s",$end); |
||
891 | |||
892 | |||
893 | $data=doHookFunction("planning_populate",array("begin"=>$begin,"end"=>$end,"who"=>$who)); |
||
894 | |||
895 | if (isset($data["items"])&&count($data["items"])){ |
||
896 | $interv=array_merge($data["items"],$interv); |
||
897 | } |
||
898 | |||
899 | |||
900 | |||
901 | ksort($interv); |
||
902 | |||
903 | if (count($interv)>0) { |
||
904 | |||
905 | $debutcal=debutIcal(getUserName($who)); |
||
906 | |||
907 | foreach ($interv as $key => $val){ |
||
908 | |||
909 | $event .= "BEGIN:VEVENT\n"; |
||
910 | |||
911 | if(isset($val["id_tracking"])){ |
||
912 | $event.="UID:Job#".$val["id_tracking"]."\n"; |
||
913 | }else if (isset($val["id_reminder"])){ |
||
914 | $event.="UID:Event#".$val["id_reminder"]."\n"; |
||
915 | } else {
|
||
916 | $event.="UID:Plugin#".$key."\n"; |
||
917 | } |
||
918 | |||
919 | $event.="DTSTAMP:".date_ical($val["begin"])."\n"; |
||
920 | |||
921 | $event .= "DTSTART:".date_ical($val["begin"])."\n"; |
||
922 | |||
923 | $event .= "DTEND:".date_ical($val["end"])."\n"; |
||
924 | |||
925 | if(isset($val["id_tracking"])){ |
||
926 | $event .= "SUMMARY:".$LANG["planning"][8]." # ".$val["id_tracking"]." ".$LANG["common"][1]." # ".$val["device"]."\n"; |
||
927 | }else if (isset($val["name"])){ |
||
928 | $event .= "SUMMARY:".$val["name"]."\n"; |
||
929 | } |
||
930 | |||
931 | if (isset($val["content"])){ |
||
932 | $event .= "DESCRIPTION:".$val["content"]."\n"; |
||
933 | } |
||
934 | |||
935 | //todo recup la cat�orie d'intervention.
|
||
936 | //$event .= "CATEGORIES:".$val["categorie"]."\n";
|
||
937 | if(isset($val["id_tracking"])){ |
||
938 | $event .= "URL:".$CFG_GLPI["url_base"]."/index.php?redirect=tracking_".$val["id_tracking"]."\n"; |
||
939 | } |
||
940 | |||
941 | $event .= "END:VEVENT\n\n"; |
||
942 | } |
||
943 | $fincal= "END:VCALENDAR\n"; |
||
944 | } |
||
945 | |||
946 | return $debutcal.$event.$fincal; |
||
947 | |||
948 | } |
||
949 | |||
950 | |||
951 | ?> |