Calendar_Holiday::showForCalendar PHP Method

showForCalendar() static public method

Show holidays for 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 DISTINCT `glpi_calendars_holidays`.`id` AS linkID,\n                                `glpi_holidays`.*\n                FROM `glpi_calendars_holidays`\n                LEFT JOIN `glpi_holidays`\n                     ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`)\n                WHERE `glpi_calendars_holidays`.`calendars_id` = '{$ID}'\n                ORDER BY `glpi_holidays`.`name`";
        $result = $DB->query($query);
        $holidays = array();
        $used = array();
        if ($numrows = $DB->numrows($result)) {
            while ($data = $DB->fetch_assoc($result)) {
                $holidays[$data['id']] = $data;
                $used[$data['id']] = $data['id'];
            }
        }
        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 close time') . "</tr>";
            echo "<tr class='tab_bg_2'><td class='right'  colspan='4'>";
            echo "<input type='hidden' name='calendars_id' value='{$ID}'>";
            Holiday::dropdown(array('used' => $used, 'entity' => $calendar->fields["entities_id"]));
            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>" . __('Name') . "</th>";
        echo "<th>" . __('Start') . "</th>";
        echo "<th>" . __('End') . "</th>";
        echo "<th>" . __('Recurrent') . "</th>";
        echo "</tr>";
        $used = array();
        if ($numrows) {
            Session::initNavigateListItems('Holiday', sprintf(__('%1$s = %2$s'), Calendar::getTypeName(1), $calendar->fields["name"]));
            foreach ($holidays as $data) {
                Session::addToNavigateListItems('Holiday', $data["id"]);
                echo "<tr class='tab_bg_1'>";
                if ($canedit) {
                    echo "<td>";
                    Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                    echo "</td>";
                }
                echo "<td><a href='" . Toolbox::getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>";
                echo "<td>" . Html::convDate($data["begin_date"]) . "</td>";
                echo "<td>" . Html::convDate($data["end_date"]) . "</td>";
                echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</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;
 }