/** * Renders the table into HTML markup. * * @return string $string HTML markup */ public function __toString() { global $OUTPUT, $DB, $COURSE, $CFG, $USER, $PAGE; $context = get_context_instance(CONTEXT_COURSE, $this->course); $PAGE->set_context($context); $room_obj = $DB->get_record('roomscheduler_rooms', array('id' => $this->room)); $string = '<div id="' . $this->get_instance() . '">'; //Mode picker $string .= '<div class="calendar_day" style="margin-right:10px;padding:0px;border:0;width:20%;">'; $string .= '<table style="width:100%;margin:0;padding:0;"><tr>'; $string .= '<td class="calendar_side_picker" style="border-bottom:0;" onclick="window.location.href=\'' . $CFG->wwwroot . '/blocks/roomscheduler/room.php?course=' . $this->course . '&room=' . $this->room . '&time=' . $this->focus_time . '\';">' . get_string('day', 'block_roomscheduler') . '</td>'; $string .= '<td class="calendar_side_picker" style="background-color:#DDDDDD;border-bottom:0;">' . get_string('week', 'block_roomscheduler') . '</td>'; $string .= '<td class="calendar_side_picker" style="border-bottom:0;" onclick="window.location.href=\'' . $CFG->wwwroot . '/blocks/roomscheduler/room_calendar.php?course=' . $this->course . '&room=' . $this->room . '&time=' . $this->focus_time . '\';">' . get_string('month', 'block_roomscheduler') . '</td>'; $string .= '</tr></table>'; $string .= '</div>'; $string .= '<table class="calendar_day" style="width:100%;">'; //Date $string .= '<tr><th colspan="9">'; $string .= $OUTPUT->pix_icon('t/left', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'previousWeek\',[]);')); $string .= ' '; //Get Sunday of week $focus_dayofweek = strftime('%w', $this->get_focusTime()); $sunday = $this->get_focusTime() - $focus_dayofweek * 86400; $difference_to_sat = 6 - $focus_dayofweek; $saturday = $this->get_focusTime() + $difference_to_sat * 86400; $string .= strftime('%B %d, %Y', $sunday); $string .= ' - '; $string .= strftime('%B %d, %Y', $saturday); $string .= ' '; $string .= $OUTPUT->pix_icon('t/right', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'nextWeek\',[]);')); $string .= '</th></tr>'; //Time picker $string .= '<tr><td colspan="9" style="font-size:10px;text-align:center;">'; $string .= calendar_day::calendar_hourdropdown($this->get_startTime(), 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'set_startTime\',[this.value]);'); $string .= ' - '; $string .= calendar_day::calendar_hourdropdown($this->get_endTime(), 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'set_endTime\',[this.value]);'); $string .= '</td></tr>'; if (has_capability('block/roomscheduler:reserve', $context) && isset($room_obj) && !$room_obj->reservable && !has_capability('block/roomscheduler:manage', $context)) { $string .= '<tr><th colspan="9">'; $string .= '<font size="1" color="red">To book this book this room please contant:</font>' . $this->email_icon($room_obj); $string .= '</th></tr>'; } //Days of week $string .= '<tr><th style="width:9%;"></th>'; for ($i = 0; $i < 7; $i++) { $string .= '<th style="width:13%">' . strftime('%A', $sunday + $i * 86400) . '</th>'; } $string .= '<td style="width:2%;"></td>'; $string .= '</tr>'; $day = date('j', $sunday); $month = date('n', $sunday); $year = date('Y', $sunday); for ($hour = $this->get_startTime(); $hour < $this->get_endTime(); $hour++) { for ($minute = 0; $minute < 60; $minute += 10) { if ($minute == 0) { $minute = '00'; $string .= '<tr class="calendar_tophour">'; $string .= '<td rowspan="6" style="width:7%;" valign="top" id="calendar_time_' . $hour . '"></td>'; } else { $string .= '<tr>'; } for ($dayofweek = 0; $dayofweek < 7; $dayofweek++) { $timestamp = mktime($hour, $minute, 0, $month, $day + $dayofweek, $year); if ($reservation = get_reservation_byTime($this->room, $timestamp)) { $user = $DB->get_record('user', array('id' => $reservation->meetingorganizer)); //Set style of calendar event if ($reservation->categories == '') { $category = 'default'; } else { $category = $reservation->categories; } //Top portion if ($timestamp == $reservation->startdate) { $string .= '<td class="calendar_' . $category . '_top">'; $starttimedisplay = strftime('%H:%M', $reservation->startdate); $endtimedisplay = strftime('%H:%M', $reservation->enddate); if ($reservation->alldayevent == 1) { $string .= ' ' . get_string('alldayevent', 'block_roomscheduler'); $string .= '-' . strftime('%h %d', $reservation->startdate); $string .= ' ' . get_string('to', 'block_roomscheduler') . ' '; $string .= strftime('%h %d', $reservation->enddate - 600); } else { $string .= ' ' . $starttimedisplay . '-' . $endtimedisplay; } if (has_capability('block/roomscheduler:manage', $context) || $reservation->meetingorganizer == $USER->id) { $string .= ' <span style="font-weight:normal;"><a href="" onclick="calendar_removeAppt(\'' . $reservation->id . '\',\'' . get_string('reservationdelete', 'block_roomscheduler') . '\');">[' . get_string('remove', 'block_roomscheduler') . ']</a></span>'; } $string .= '</td>'; } else { if ($timestamp == $reservation->startdate + 600) { $string .= '<td class="calendar_' . $category . '_top">'; $string .= ' ' . $reservation->subject; $string .= '</td>'; } else { if ($timestamp == $reservation->startdate + 1200) { $string .= '<td class="calendar_' . $category . '_bottom">'; $string .= ' ' . $reservation->description; $string .= '</td>'; } else { if ($timestamp == $reservation->enddate - 600) { $string .= '<td class="calendar_' . $category . '_bottom">'; $string .= '</td>'; } else { $string .= '<td class="calendar_' . $category . '_middle">'; $string .= '</td>'; } } } } } else { $string .= '<td style="font-size:10px;"'; if (has_capability('block/roomscheduler:reserve', $context) && isset($room_obj) && $room_obj->reservable) { $string .= 'onmousedown="calendar_startAppt(this)" onmouseover="hoverAppt(this)" onmouseup="calendar_endAppt(this)"'; } elseif (has_capability('block/roomscheduler:manage', $context)) { $string .= 'onmousedown="calendar_startAppt(this)" onmouseover="hoverAppt(this)" onmouseup="calendar_endAppt(this)"'; } $string .= ' id="' . $timestamp . '";></td>'; } } $string .= '<td style="width:2%;"></td>'; $string .= '</tr>'; } } $string .= '</table>'; $string .= '</div>'; $string .= '</div>'; $this->serialize(); return $string; }
/** * Renders the table into HTML markup. * * @return string $string HTML markup */ public function __toString() { global $OUTPUT, $DB, $CFG, $USER, $PAGE; $context = get_context_instance(CONTEXT_COURSE, $this->course); $PAGE->set_context($context); $this->focus_time = $this->day; $string = '<div id="' . $this->get_instance() . '">'; if ($this->show_toolbar) { $cal_style = 'width:70%;float:left;'; $string .= '<table cellspacing="0" cellpadding="0" style="width:20%;float:left;">'; //Mode picker $string .= '<tr><td style="margin:0;padding:0;">'; $string .= '<div class="calendar_day" style="margin-right:10px;padding:0px;border:0;">'; $string .= '<table style="width:100%;margin:0;padding:0;"><tr>'; $string .= '<td class="calendar_side_picker" style="background-color:#DDDDDD;">' . get_string('day', 'block_roomscheduler') . '</td>'; $string .= '<td class="calendar_side_picker" onclick="window.location.href=\'' . $CFG->wwwroot . '/blocks/roomscheduler/room_week.php?course=' . $this->course . '&room=' . $this->room . '&time=' . $this->focus_time . '\';">' . get_string('week', 'block_roomscheduler') . '</td>'; $string .= '<td class="calendar_side_picker" onclick="window.location.href=\'' . $CFG->wwwroot . '/blocks/roomscheduler/room_calendar.php?course=' . $this->course . '&room=' . $this->room . '&time=' . $this->focus_time . '\';">' . get_string('month', 'block_roomscheduler') . '</td>'; $string .= '</tr></table>'; $string .= '</div></td></tr>'; //Mini calendar picker $string .= '<tr><td style="margin:0;padding:0;">'; $string .= '<div class="calendar_day" style="margin-right:10px;margin-top:10px;padding:5px;">'; $string .= '<table style="font-size:10px;width:100%;">'; //Month $string .= '<tr>'; $string .= '<th style="font-align:left;">'; $string .= $OUTPUT->pix_icon('t/left', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'miniCal_previousMonth\',[]);')); $string .= '</th><th colspan="5">'; $string .= strftime('%B %Y', $this->get_miniCal()); $string .= '</th><th style="font-align:right;">'; $string .= $OUTPUT->pix_icon('t/right', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'miniCal_nextMonth\',[]);')); $string .= '</th>'; $string .= '</tr>'; //Days of week $sunday = strtotime('8/8/2010'); //Use this as a reference point for sunday $string .= '<tr class="calendar_minical_daysofweek">'; for ($day = 0; $day < 7; $day++) { $string .= '<th>' . strftime('%a', $sunday + 86400 * $day) . '</th>'; } $string .= '</tr>'; //Determine which day of the week is the first day of the month $month = date('n', $this->get_miniCal()); $year = date('Y', $this->get_miniCal()); $dayofweek_first = strftime_dayofweek_compatible(mktime(0, 0, 0, $month, 1, $year)); $totaldays = date('t', mktime(0, 0, 0, $month, 1, $year)); //Calculate offset, offset is dayofweek_first (except in the case of sunday) if ($dayofweek_first == 7) { $dayofweek_first = 0; } //Days $count = 1; for ($week = 1; $week <= 6; $week++) { $string .= '<tr>'; for ($dayofweek = 0; $dayofweek < 7; $dayofweek++) { //Beginning offset period if ($dayofweek_first > 0) { $dayofweek_first--; $string .= '<td></td>'; } else { if ($count > $totaldays) { $string .= '<td></td>'; } else { $daystamp = mktime(0, 0, 0, $month, $count, $year); $string .= '<td style="text-align:right;" class="calendar_miniCal_day" onclick="calendar_phpFunction(\'' . $this->get_instance() . '\',\'set_day\',[\'' . $daystamp . '\']);">'; $string .= '<div '; if ($month == date('n') && $count == date('j') && $year == date('Y')) { if ($month == date('n', $this->get_day()) && $count == date('j', $this->get_day()) && $year == date('Y', $this->get_day())) { $string .= 'class="calendar_miniCal_todaySelected"'; } else { $string .= 'class="calendar_miniCal_today"'; } } else { if ($month == date('n', $this->get_day()) && $count == date('j', $this->get_day()) && $year == date('Y', $this->get_day())) { $string .= 'class="calendar_miniCal_selected"'; } } $string .= '>'; $string .= $count; $string .= '</div></td>'; $count++; } } } $string .= '</tr>'; } $string .= '</table>'; $string .= '</div>'; $string .= '</td></tr>'; //Resources $room_obj = $DB->get_record('roomscheduler_rooms', array('id' => $this->room)); if ($room_obj->resources != '') { $string .= '<tr><td style="margin:0;padding:0;">'; $string .= '<div class="calendar_day" style="margin-right:10px;margin-top:10px;padding:5px;">'; $resources = explode(',', $room_obj->resources); $string .= '<ul style="margin-top:0;margin-bottom:0;">'; foreach ($resources as $resource) { $resource = trim($resource); $string .= '<li>' . $resource . '</li>'; } $string .= '</ul>'; $string .= '</div>'; $string .= '</td></tr>'; } //Other rooms picker $string .= '<tr><td style="margin:0;padding:0;">'; $string .= '<div class="calendar_day" style="margin-right:10px;margin-top:10px;padding:5px;">'; $rooms = $DB->get_records('roomscheduler_rooms', array('active' => 1), 'name ASC'); $string .= '<select onchange="window.location.href=(this.options[this.selectedIndex].value);">'; foreach ($rooms as $room) { $string .= '<option value="' . $CFG->wwwroot . '/blocks/roomscheduler/room.php?time=' . $this->focus_time . '&course=' . $this->course . '&room=' . $room->id . '"'; if ($this->room == $room->id) { $string .= 'SELECTED'; } $string .= '>' . $room->name . '</option>'; } $string .= '</select>'; $string .= '</div>'; $string .= '</td></tr>'; $string .= '</table>'; } else { $cal_style = 'width:100%;'; } $string .= '<table class="calendar_day" style="' . $cal_style . '">'; //Date $string .= '<tr><th colspan="3">'; $string .= $OUTPUT->pix_icon('t/left', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'previousDay\',[]);')); $string .= ' '; $string .= strftime('%B %d, %Y', $this->get_day()); $string .= ' '; $string .= $OUTPUT->pix_icon('t/right', '', 'moodle', array('class' => 'calendar_icon', 'onclick' => 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'nextDay\',[]);')); $string .= '</th></tr>'; //Time picker $string .= '<tr><td colspan="3" style="font-size:10px;text-align:center;">'; $string .= calendar_day::calendar_hourdropdown($this->get_startTime(), 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'set_startTime\',[this.value]);'); $string .= ' - '; $string .= calendar_day::calendar_hourdropdown($this->get_endTime(), 'calendar_phpFunction(\'' . $this->get_instance() . '\',\'set_endTime\',[this.value]);'); $string .= '</td></tr>'; if (has_capability('block/roomscheduler:reserve', $context) && isset($room_obj) && !$room_obj->reservable && !has_capability('block/roomscheduler:manage', $context)) { $string .= '<tr><th colspan="3">'; $string .= '<font size="1" color="red">To book this book this room please contant:</font>' . $this->email_icon($room_obj); $string .= '</th></tr>'; } //Day of week + day $string .= '<tr><th style="text-align:left;">'; $string .= strftime('%A', $this->get_day()); $string .= '</th><th></th><th style="text-align:right;">'; $string .= strftime('%d', $this->get_day()); $string .= '</th></tr>'; $day = date('j', $this->get_day()); $month = date('n', $this->get_day()); $year = date('Y', $this->get_day()); $block_counter = 1; //Count how many blocks are printed out for ($hour = $this->get_startTime(); $hour < $this->get_endTime(); $hour++) { $count = 1; for ($minute = 0; $minute < 60; $minute += 10) { if ($minute == 0) { $minute = '00'; $string .= '<tr class="calendar_tophour">'; $string .= '<td rowspan="6" style="width:20%;" valign="top" id="calendar_time_' . $hour . '"></td>'; } else { $string .= '<tr>'; } $timestamp = mktime($hour, $minute, 0, $month, $day, $year); if ($reservation = get_reservation_byTime($this->room, $timestamp)) { $user = $DB->get_record('user', array('id' => $reservation->meetingorganizer)); //Set style of calendar event if ($reservation->categories == '') { $category = 'default'; } else { $category = $reservation->categories; } //Top portion if ($timestamp == $reservation->startdate || $block_counter == 1) { $string .= '<td class="calendar_' . $category . '_top">'; $starttimedisplay = strftime('%H:%M', $reservation->startdate); $endtimedisplay = strftime('%H:%M', $reservation->enddate); if ($reservation->alldayevent == 1) { $string .= ' ' . get_string('alldayevent', 'block_roomscheduler'); $string .= ' - ' . strftime('%h %d', $reservation->startdate); $string .= ' ' . get_string('to', 'block_roomscheduler') . ' '; $string .= strftime('%h %d', $reservation->enddate - 600); } else { $string .= ' ' . $starttimedisplay . ' - ' . $endtimedisplay; } $string .= ' : ' . $reservation->subject; if (has_capability('block/roomscheduler:manage', $context) || $reservation->meetingorganizer == $USER->id) { $string .= ' <span style="font-weight:normal;"><a href="" onclick="calendar_removeAppt(\'' . $reservation->id . '\',\'' . get_string('reservationdelete', 'block_roomscheduler') . '\');">[' . get_string('remove', 'block_roomscheduler') . ']</a></span>'; $string .= ' <span style="font-weight:normal;"><a href="#" onclick="calendar_editAppt(\'' . $reservation->id . '\',\'' . apptForm_edit::apptForm_formName() . '\', \'single\');">[' . get_string('edit', 'block_roomscheduler') . ']</a></span>'; if ($reservation->recurrence_id > 0) { $string .= ' <span style="font-weight:normal;"><a href="#" onclick="calendar_editAppt(\'' . $reservation->id . '\',\'' . apptForm_recursiveEdit::apptForm_formName() . '\', \'recursive\');">[' . get_string('editall', 'block_roomscheduler') . ']</a></span>'; $string .= ' <span style="font-weight:normal;"><a href="" onclick="calendar_removeAppts(\'' . $reservation->id . '\',\'' . get_string('reservationdeletes', 'block_roomscheduler') . '\');">[' . get_string('removeall', 'block_roomscheduler') . ']</a></span>'; } } if ($reservation->confirm == 0) { $string .= ' <span style="font-weight:normal;">'; if (has_capability('block/roomscheduler:manage', $context)) { // $string .= '<a href="" onclick="calendar_confirmAppt(\'' . $reservation->id . '\',\'' . get_string('confirmconfirmation', 'block_roomscheduler') . '\');">'; } // $string .= '['.get_string('unconfirmed','block_roomscheduler').']'; if (has_capability('block/roomscheduler:manage', $context)) { // $string .= '</a>'; } $string .= '</span>'; } if ($reservation->recurrence_id != 0 && $reservation->confirm == 0 && has_capability('block/roomscheduler:manage', $context)) { // $string .= ' <span style="font-weight:normal;"><a href="" onclick="calendar_confirmAppts(\'' . $reservation->id . '\',\'' . get_string('confirmconfirmations', 'block_roomscheduler') . '\');">['.get_string('confirmall','block_roomscheduler').']</a></span>'; } $string .= '</td>'; $block_counter++; } else { if ($timestamp == $reservation->enddate - 600) { $string .= '<td class="calendar_' . $category . '_bottom">'; if ($block_counter == 2) { $string .= ' ' . $reservation->description; } /* else if($block_counter==3){ $string .= ' '.$user->firstname.' '.$user->lastname; } * */ $string .= '</td>'; $block_counter = 1; } else { $string .= '<td class="calendar_' . $category . '_middle">'; if ($block_counter == 2) { $string .= ' ' . $reservation->description; } /* else if($block_counter==3){ $string .= ' '.$user->firstname.' '.$user->lastname; } * */ $string .= '</td>'; $block_counter++; } } } else { //blank row $string .= '<td style="font-size:10px;"'; if (has_capability('block/roomscheduler:reserve', $context) && isset($room_obj) && $room_obj->reservable) { $string .= ' onmousedown="calendar_startAppt(this);" onmouseover="hoverAppt(this);" onmouseup="calendar_endAppt(this);"'; } elseif (has_capability('block/roomscheduler:manage', $context)) { $string .= ' onmousedown="calendar_startAppt(this);" onmouseover="hoverAppt(this);" onmouseup="calendar_endAppt(this);"'; } $string .= ' id="' . $timestamp . '"></td>'; } $string .= '<td style="width:10%;"></td></tr>'; $count++; } } $string .= '</table>'; $string .= '</div>'; $string .= '</div>'; $this->serialize(); return $string; }