/**
  * Show holidays for a calendar
  *
  * @param $calendar Calendar object
  **/
 static function showForCalendar(Calendar $calendar)
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $calendar->getField('id');
     if (!$calendar->can($ID, 'r')) {
         return false;
     }
     $canedit = $calendar->can($ID, 'w');
     $rand = mt_rand();
     echo "<form name='calendarholiday_form{$rand}' id='calendarholiday_form{$rand}' method='post'\n             action='";
     echo getItemTypeFormURL(__CLASS__) . "'>";
     echo "<div class='center'><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='2'>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['buttons'][33] . "</th>";
     echo "<th>" . $LANG['buttons'][32] . "</th>";
     echo "<th>" . $LANG['calendar'][3] . "</th>";
     echo "</tr>";
     $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);
     $used = array();
     if ($DB->numrows($result) > 0) {
         initNavigateListItems('Holiday', $LANG['buttons'][15] . " = " . $calendar->fields["name"]);
         while ($data = $DB->fetch_array($result)) {
             addToNavigateListItems('Holiday', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             echo "<td width='10'>";
             if ($canedit) {
                 echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>";
             } else {
                 echo "&nbsp;";
             }
             echo "</td>";
             $used[] = $data['id'];
             echo "<td><a href='" . getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>";
             echo "<td>" . convDate($data["begin_date"]) . "</td>";
             echo "<td>" . convDate($data["end_date"]) . "</td>";
             echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</td>";
             echo "</tr>";
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_2'><td class='right'  colspan='4'>";
         echo "<input type='hidden' name='calendars_id' value='{$ID}'>";
         Dropdown::show('Holiday', array('used' => $used, 'entity' => $calendar->fields["entities_id"]));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
     }
     echo "</table></div>";
     if ($canedit) {
         openArrowMassive("calendarholiday_form{$rand}", true);
         closeArrowMassive('delete', $LANG['buttons'][6]);
     }
     echo "</form>";
 }
Ejemplo n.º 2
0
 /**
  * Show segments of a calendar
  *
  * @param $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>";
 }
Ejemplo n.º 3
0
 /**
  * Show holidays for a calendar
  *
  * @param $calendar Calendar object
  **/
 static function showForCalendar(Calendar $calendar)
 {
     global $DB, $CFG_GLPI;
     $ID = $calendar->getField('id');
     if (!$calendar->can($ID, 'r')) {
         return false;
     }
     $canedit = $calendar->can($ID, 'w');
     $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);
         $paramsma = array('num_displayed' => $numrows);
         Html::showMassiveActions(__CLASS__, $paramsma);
     }
     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) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Show segments of a calendar
  *
  * @param $calendar Calendar object
  **/
 static function showForCalendar(Calendar $calendar)
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $calendar->getField('id');
     if (!$calendar->can($ID, 'r')) {
         return false;
     }
     $canedit = $calendar->can($ID, 'w');
     $rand = mt_rand();
     echo "<form name='calendarsegment_form{$rand}' id='calendarsegment_form{$rand}' method='post'\n             action='";
     echo getItemTypeFormURL(__CLASS__) . "'>";
     if ($canedit) {
         echo "<div class='spaced'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['calendar'][6] . "</tr>";
         echo "<tr class='tab_bg_2'><td class='center'>" . $LANG['calendar'][7] . "&nbsp;: ";
         echo "<input type='hidden' name='entities_id' value='" . $calendar->fields['entities_id'] . "'>";
         echo "<input type='hidden' name='is_recursive' value='" . $calendar->fields['is_recursive'] . "'>";
         echo "<input type='hidden' name='calendars_id' value='{$ID}'>";
         Dropdown::showFromArray('day', $LANG['calendarDay']);
         echo "</td><td class='center'>" . $LANG['buttons'][33] . "&nbsp;: ";
         Dropdown::showHours("begin", date('H') . ":00");
         echo "</td><td class='center'>" . $LANG['buttons'][32] . "&nbsp;: ";
         Dropdown::showHours("end", date('H') + 1 . ":00");
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
     }
     echo "<div class='center'><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='2'>" . $LANG['calendar'][7] . "</th>";
     echo "<th>" . $LANG['buttons'][33] . "</th>";
     echo "<th>" . $LANG['buttons'][32] . "</th>";
     echo "</tr>";
     $query = "SELECT *\n                FROM `glpi_calendarsegments`\n                WHERE `calendars_id` = '{$ID}'\n                ORDER BY `day`, `begin`, `end`";
     $result = $DB->query($query);
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_array($result)) {
             echo "<tr class='tab_bg_1'>";
             echo "<td width='10'>";
             if ($canedit) {
                 echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>";
             } else {
                 echo "&nbsp;";
             }
             echo "</td>";
             echo "<td>";
             echo $LANG['calendarDay'][$data['day']];
             echo "</td>";
             echo "<td>" . $data["begin"] . "</td>";
             echo "<td>" . $data["end"] . "</td>";
         }
         echo "</tr>";
     }
     echo "</table></div>";
     if ($canedit) {
         openArrowMassive("calendarsegment_form{$rand}", true);
         closeArrowMassive('delete', $LANG['buttons'][6]);
     }
     echo "</form>";
 }