CalendarSegment::showForCalendar PHP Method

showForCalendar() static public method

Show segments of a calendar
static public showForCalendar ( Calendar $calendar )
$calendar Calendar Calendar object
    static function showForCalendar(Calendar $calendar)
    {
        global $DB, $CFG_GLPI;
        $ID = $calendar->getField('id');
        if (!$calendar->can($ID, READ)) {
            return false;
        }
        $canedit = $calendar->can($ID, UPDATE);
        $rand = mt_rand();
        $query = "SELECT *\n                FROM `glpi_calendarsegments`\n                WHERE `calendars_id` = '{$ID}'\n                ORDER BY `day`, `begin`, `end`";
        $result = $DB->query($query);
        $numrows = $DB->numrows($result);
        if ($canedit) {
            echo "<div class='firstbloc'>";
            echo "<form name='calendarsegment_form{$rand}' id='calendarsegment_form{$rand}' method='post'\n                action='";
            echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_1'><th colspan='7'>" . __('Add a schedule') . "</tr>";
            echo "<tr class='tab_bg_2'><td class='center'>" . __('Day') . "</td><td>";
            echo "<input type='hidden' name='calendars_id' value='{$ID}'>";
            Dropdown::showFromArray('day', Toolbox::getDaysOfWeekArray());
            echo "</td><td class='center'>" . __('Start') . '</td><td>';
            Dropdown::showHours("begin", array('value' => date('H') . ":00"));
            echo "</td><td class='center'>" . __('End') . '</td><td>';
            Dropdown::showHours("end", array('value' => date('H') + 1 . ":00"));
            echo "</td><td class='center'>";
            echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
            echo "</td></tr>";
            echo "</table>";
            Html::closeForm();
            echo "</div>";
        }
        echo "<div class='spaced'>";
        if ($canedit && $numrows) {
            Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
            $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
            Html::showMassiveActions($massiveactionparams);
        }
        echo "<table class='tab_cadre_fixehov'>";
        echo "<tr>";
        if ($canedit && $numrows) {
            echo "<th width='10'>";
            Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
            echo "</th>";
        }
        echo "<th>" . __('Day') . "</th>";
        echo "<th>" . __('Start') . "</th>";
        echo "<th>" . __('End') . "</th>";
        echo "</tr>";
        $daysofweek = Toolbox::getDaysOfWeekArray();
        if ($numrows) {
            while ($data = $DB->fetch_assoc($result)) {
                echo "<tr class='tab_bg_1'>";
                if ($canedit) {
                    echo "<td>";
                    Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                    echo "</td>";
                }
                echo "<td>";
                echo $daysofweek[$data['day']];
                echo "</td>";
                echo "<td>" . $data["begin"] . "</td>";
                echo "<td>" . $data["end"] . "</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
        if ($canedit && $numrows) {
            $massiveactionparams['ontop'] = false;
            Html::showMassiveActions($massiveactionparams);
            Html::closeForm();
        }
        echo "</div>";
    }

Usage Example

 /**
  * Display content of Tab
  *
  * @param $ID of the item
  * @param $tab number of the tab
  *
  * @return true if handled (for class stack)
  **/
 function showTabContent($ID, $tab)
 {
     if ($ID > 0 && !parent::showTabContent($ID, $tab)) {
         switch ($tab) {
             case 1:
                 CalendarSegment::showForCalendar($this);
                 return true;
             case 2:
                 Calendar_Holiday::showForCalendar($this);
                 return true;
             case -1:
                 CalendarSegment::showForCalendar($this);
                 Calendar_Holiday::showForCalendar($this);
                 return false;
         }
     }
     return false;
 }