grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } class Calendar_Holiday extends CommonDBRelation { public $auto_message_on_action = false; // From CommonDBRelation static public $itemtype_1 = 'Calendar'; static public $items_id_1 = 'calendars_id'; static public $itemtype_2 = 'Holiday'; static public $items_id_2 = 'holidays_id'; static public $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS; /** * @since version 0.84 **/ function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } /** * 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, READ)) { return false; } $canedit = $calendar->can($ID, UPDATE); $rand = mt_rand(); $query = "SELECT DISTINCT `glpi_calendars_holidays`.`id` AS linkID, `glpi_holidays`.* FROM `glpi_calendars_holidays` LEFT JOIN `glpi_holidays` ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`) WHERE `glpi_calendars_holidays`.`calendars_id` = '$ID' 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 "
"; echo "
"; echo ""; echo ""; echo ""; echo "
".__('Add a close time')."
"; echo ""; Holiday::dropdown(array('used' => $used, 'entity' => $calendar->fields["entities_id"])); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } echo "
"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = array('num_displayed' => min($_SESSION['glpilist_limit'], $numrows), 'container' => 'mass'.__CLASS__.$rand); Html::showMassiveActions($massiveactionparams); } echo ""; echo ""; if ($canedit && $numrows) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; $used = array(); if ($numrows) { Session::initNavigateListItems('Holiday', //TRANS : %1$s is the itemtype name, %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Calendar::getTypeName(1), $calendar->fields["name"])); foreach ($holidays as $data) { Session::addToNavigateListItems('Holiday', $data["id"]); echo ""; if ($canedit) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; } } echo "
"; Html::checkAllAsCheckbox('mass'.__CLASS__.$rand); echo "".__('Name')."".__('Start')."".__('End')."".__('Recurrent')."
"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "". $data["name"]."".Html::convDate($data["begin_date"])."".Html::convDate($data["end_date"])."".Dropdown::getYesNo($data["is_perpetual"])."
"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } /** * Duplicate all holidays from a calendar to its clone * * @param $oldid * @param $newid **/ static function cloneCalendar($oldid, $newid) { global $DB; $query = "SELECT * FROM `glpi_calendars_holidays` WHERE `calendars_id` = '$oldid'"; foreach ($DB->request($query) as $data) { $ch = new self(); unset($data['id']); $data['calendars_id'] = $newid; $data['_no_history'] = true; $ch->add($data); } } function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (!$withtemplate) { $nb = 0; switch ($item->getType()) { case 'Calendar' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable($this->getTable(), "calendars_id = '".$item->getID()."'"); } return self::createTabEntry(_n('Close time','Close times', Session::getPluralNumber()), $nb); } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { if ($item->getType()=='Calendar') { self::showForCalendar($item); } return true; } } ?>