. * --------------------------------------------------------------------- */ 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 0.84 **/ function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } /** * Show holidays for a calendar * * @param $calendar Calendar object * * @return void|boolean (HTML display) False if there is a rights error. */ static function showForCalendar(Calendar $calendar) { global $DB; $ID = $calendar->getField('id'); if (!$calendar->can($ID, READ)) { return false; } $canedit = $calendar->can($ID, UPDATE); $rand = mt_rand(); $iterator = $DB->request([ 'SELECT' => [ 'glpi_calendars_holidays.id AS linkid', 'glpi_holidays.*' ], 'DISTINCT' => true, 'FROM' => 'glpi_calendars_holidays', 'LEFT JOIN' => [ 'glpi_holidays' => [ 'ON' => [ 'glpi_calendars_holidays' => 'holidays_id', 'glpi_holidays' => 'id' ] ] ], 'WHERE' => [ 'glpi_calendars_holidays.calendars_id' => $ID ], 'ORDERBY' => 'glpi_holidays.name' ]); $numrows = count($iterator); $holidays = []; $used = []; while ($data = $iterator->next()) { $holidays[$data['id']] = $data; $used[$data['id']] = $data['id']; } if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
".__('Add a close time')."
"; echo ""; Holiday::dropdown(['used' => $used, 'entity' => $calendar->fields["entities_id"]]); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } echo "
"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['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 = []; 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 "
"; echo Html::getCheckAllAsCheckbox('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 * * @deprecated 9.5 * * @param integer $oldid The ID of the calendar to copy from. * @param integer $newid The ID of the calendar to copy to. **/ static function cloneCalendar($oldid, $newid) { global $DB; Toolbox::deprecated('Use clone'); $result = $DB->request( [ 'FROM' => self::getTable(), 'WHERE' => [ 'calendars_id' => $oldid, ] ] ); foreach ($result 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; } }