displayPlanningItem() static public method

Display a Planning Item
static public displayPlanningItem ( array $val, $who, $type = "", $complete ) : Nothing
$val array Array of the item to display
$who ID of the user (0 if all)
$type position of the item in the time block (in, through, begin or end) (default '')
$complete complete display (more details) (default 0)
return Nothing (display function)
示例#1
0
 /**
  * Prepare a set of events for jquery fullcalendar.
  * Call populatePlanning functions for all $CFG_GLPI['planning_types'] types
  *
  * @since 9.1
  *
  * @param array $options: must contains this keys :
  *  - begin : planning start .
  *       (should be an ISO_8601 date, but could be anything wo can be parsed by strtotime)
  *  - end : planning end .
  *       (should be an ISO_8601 date, but could be anything wo can be parsed by strtotime)
  * @return array $events : array with events in fullcalendar.io format
  */
 static function constructEventsArray($options = array())
 {
     global $CFG_GLPI;
     $param['start'] = '';
     $param['end'] = '';
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $param[$key] = $val;
         }
     }
     $param['begin'] = date("Y-m-d H:i:s", strtotime($param['start']));
     $param['end'] = date("Y-m-d H:i:s", strtotime($param['end']));
     $raw_events = array();
     foreach ($CFG_GLPI['planning_types'] as $planning_type) {
         if ($_SESSION['glpi_plannings']['filters'][$planning_type]['display']) {
             $event_type_color = $_SESSION['glpi_plannings']['filters'][$planning_type]['color'];
             foreach ($_SESSION['glpi_plannings']['plannings'] as $actor => $actor_params) {
                 $actor_params['event_type_color'] = $event_type_color;
                 $actor_params['planning_type'] = $planning_type;
                 self::constructEventsArraySingleLine($actor, array_merge($param, $actor_params), $raw_events);
             }
         }
     }
     // construct events (in fullcalendar format)
     $events = array();
     foreach ($raw_events as $event) {
         $users_id = isset($event['users_id_tech']) && !empty($event['users_id_tech']) ? $event['users_id_tech'] : $event['users_id'];
         $content = Planning::displayPlanningItem($event, $users_id, 'in', true);
         $begin = date('c', strtotime($event['begin']));
         $end = date('c', strtotime($event['end']));
         // retreive all day events
         if (strpos($event['begin'], "00:00:00") != false && (strtotime($event['end']) - strtotime($event['begin'])) % DAY_TIMESTAMP == 0) {
             $begin = date('Y-m-d', strtotime($event['begin']));
             $end = date('Y-m-d', strtotime($event['end']));
         }
         $index_color = array_search("user_{$users_id}", array_keys($_SESSION['glpi_plannings']));
         $events[] = array('title' => $event['name'], 'content' => $content, 'start' => $begin, 'end' => $end, 'editable' => isset($event['editable']) ? $event['editable'] : false, 'color' => empty($event['color']) ? Planning::$palette_bg[$index_color] : $event['color'], 'borderColor' => empty($event['event_type_color']) ? self::$event_type_color[$event['itemtype']] : $event['event_type_color'], 'textColor' => Planning::$palette_fg[$index_color], 'typeColor' => empty($event['event_type_color']) ? self::$event_type_color[$event['itemtype']] : $event['event_type_color'], 'url' => isset($event['url']) ? $event['url'] : "", 'ajaxurl' => isset($event['ajaxurl']) ? $event['ajaxurl'] : "", 'itemtype' => $event['itemtype'], 'parentitemtype' => isset($event['parentitemtype']) ? $event['parentitemtype'] : "", 'items_id' => $event['id'], 'priority' => isset($event['priority']) ? $event['priority'] : "");
     }
     return $events;
 }
示例#2
0
 public function show($when, $type, $who, $who_group)
 {
     global $LANG, $CFG_GLPI, $DB;
     // if (!haveRight("show_planning",READ) && !haveRight("show_all_planning",UPDATE)) {
     if (!haveRight("planning", CREATE) || !haveRight("planning", Ticket::READALL)) {
         return false;
     }
     // Define some constants
     $date = explode("-", $when);
     $time = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
     // Check bisextile years
     list($current_year, $current_month, $current_day) = explode("-", $when);
     if ($current_year % 4 == 0) {
         $feb = 29;
     } else {
         $feb = 28;
     }
     $nb_days = array(31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     // Begin of the month
     $begin_month_day = strftime("%w", mktime(0, 0, 0, $current_month, 1, $current_year));
     if ($begin_month_day == 0) {
         $begin_month_day = 7;
     }
     $end_month_day = strftime("%w", mktime(0, 0, 0, $current_month, $nb_days[$current_month - 1], $current_year));
     // Day of the week
     $dayofweek = date("w", $time);
     // Cas du dimanche
     if ($dayofweek == 0) {
         $dayofweek = 7;
     }
     // Get begin and duration
     $begin = 0;
     $end = 0;
     switch ($type) {
         case "month":
             $begin = strtotime($current_year . "-" . $current_month . "-01 00:00:00");
             $end = $begin + DAY_TIMESTAMP * $nb_days[$current_month - 1];
             $year_next = $date[0];
             $month_next = $date[1] + 1;
             if ($month_next > 12) {
                 $year_next++;
                 $month_next -= 12;
             }
             $year_prev = $date[0];
             $month_prev = $date[1] - 1;
             if ($month_prev == 0) {
                 $year_prev--;
                 $month_prev += 12;
             }
             $next = $year_next . "-" . sprintf("%02u", $month_next) . "-" . $date[2];
             $prev = $year_prev . "-" . sprintf("%02u", $month_prev) . "-" . $date[2];
             break;
         case "week":
             $tbegin = $begin = $time + mktime(0, 0, 0, 0, 1, 0) - mktime(0, 0, 0, 0, $dayofweek, 0);
             $end = $begin + WEEK_TIMESTAMP;
             break;
         case "day":
             $add = "";
             $begin = $time;
             $end = $begin + DAY_TIMESTAMP;
             break;
     }
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     //construct navigation intervals
     if (in_array($type, array('week', 'day'))) {
         $time = strtotime($when);
         $step = 0;
         switch ($type) {
             case "week":
                 $step = WEEK_TIMESTAMP;
                 break;
             case "day":
                 $step = DAY_TIMESTAMP;
                 break;
         }
         $next = $time + $step + 10;
         $prev = $time - $step;
         $next = strftime("%Y-%m-%d", $next);
         $prev = strftime("%Y-%m-%d", $prev);
     }
     $navBar = self::showNavBar($next, $prev, $type, $who, $who_group);
     // Print Headers
     echo "<div class='center'><table class='tab_cadre_fixe mobile_calendar'>";
     // Print Headers
     echo "<tr class='tab_bg_1'>";
     switch ($type) {
         case "month":
             for ($i = 1; $i <= 7; $i++) {
                 echo "<th width='12%'>" . $LANG['calendarD'][$i % 7] . "</th>";
             }
             break;
         case "week":
             echo "<th />";
             for ($i = 1; $i <= 7; $i++, $tbegin += DAY_TIMESTAMP) {
                 echo "<th width='12%'>" . $LANG['calendarD'][$i % 7] . " " . date('d', $tbegin) . "</th>";
             }
             break;
         case "day":
             echo "<th />";
             echo "<th width='12%'>" . $LANG['calendarDay'][$dayofweek % 7] . " " . date('d', $tbegin) . "</th>";
             break;
     }
     echo "</tr>\n";
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning($who, $who_group, $begin, $end);
     // ---------------reminder
     $datareminders = Reminder::populatePlanning($who, $who_group, $begin, $end);
     $interv = array_merge($interv, $datareminders);
     // --------------- Plugins
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     // Display Items
     $tmp = explode(":", $CFG_GLPI["planning_begin"]);
     $hour_begin = $tmp[0];
     $tmp = explode(":", $CFG_GLPI["planning_end"]);
     $hour_end = $tmp[0];
     if ($tmp[1] > 0) {
         $hour_end++;
     }
     switch ($type) {
         case "week":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 echo "<td class='td_hour'>" . self::displayUsingTwoDigits($hour) . "</td>";
                 for ($i = 1; $i <= 7; $i++) {
                     echo "<td class='tab_bg_3 top' width='12%'>";
                     // From midnight
                     if ($hour == $hour_begin) {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP);
                     } else {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + $hour * HOUR_TIMESTAMP);
                     }
                     // To midnight
                     if ($hour == $hour_end) {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + 24 * HOUR_TIMESTAMP);
                     } else {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + ($hour + 1) * HOUR_TIMESTAMP);
                     }
                     reset($interv);
                     while ($data = current($interv)) {
                         $type = "";
                         if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                             $type = "in";
                         } else {
                             if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                                 $type = "through";
                             } else {
                                 if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                     $type = "begin";
                                 } else {
                                     if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                         $type = "end";
                                     }
                                 }
                             }
                         }
                         if (empty($type)) {
                             next($interv);
                         } else {
                             self::displayPlanningItem($data, $who);
                             if ($type == "in") {
                                 unset($interv[key($interv)]);
                             } else {
                                 next($interv);
                             }
                         }
                     }
                     echo "</td>";
                 }
                 echo "</tr>\n";
             }
             break;
         case "day":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 $begin_time = date("Y-m-d H:i:s", strtotime($when) + $hour * HOUR_TIMESTAMP);
                 $end_time = date("Y-m-d H:i:s", strtotime($when) + ($hour + 1) * HOUR_TIMESTAMP);
                 echo "<td class='td_hour'>" . self::displayUsingTwoDigits($hour) . ":00</td>";
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         Planning::displayPlanningItem($data, $who, $type, 1);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr>";
             }
             break;
         case "month":
             echo "<tr class='tab_bg_3'>";
             // Display first day out of the month
             for ($i = 1; $i < $begin_month_day; $i++) {
                 echo "<td style='background-color:#ffffff'>&nbsp;</td>";
             }
             // Print real days
             if ($current_month < 10 && strlen($current_month) == 1) {
                 $current_month = "0" . $current_month;
             }
             $begin_time = strtotime($begin);
             $end_time = strtotime($end);
             for ($time = $begin_time; $time < $end_time; $time += DAY_TIMESTAMP) {
                 // Add 6 hours for midnight problem
                 $day = date("d", $time + 6 * HOUR_TIMESTAMP);
                 echo "<td height='100' class='tab_bg_3 top'>";
                 echo "<table><tr><td style='text-align:left'>";
                 echo "<span class='month_day'>" . $day . "</span></td></tr>";
                 echo "<tr class='tab_bg_3 center'>";
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 $begin_day = date("Y-m-d H:i:s", $time);
                 $end_day = date("Y-m-d H:i:s", $time + DAY_TIMESTAMP);
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_day && $data["end"] <= $end_day) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_day && $data["end"] > $end_day) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_day && $data["begin"] < $end_day) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_day && $data["end"] <= $end_day) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         self::displayPlanningItem($data, $who);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr></table>";
                 echo "</td>";
                 // Add break line
                 if (($day + $begin_month_day) % 7 == 1) {
                     echo "</tr>\n";
                     if ($day != $nb_days[$current_month - 1]) {
                         echo "<tr>";
                     }
                 }
             }
             if ($end_month_day != 0) {
                 for ($i = 0; $i < 7 - $end_month_day; $i++) {
                     echo "<td style='background-color:#ffffff'>&nbsp;</td>";
                 }
             }
             echo "</tr>";
             break;
     }
     echo "</table></div>";
     echo $navBar;
 }