/** * Test pm_gmt_from_usertime() function * @param int $intimestamp the input timestamp * @param float|int|string $timezone the timezone of $intimestamp * @param int $outtimestamp the GMT timestamp for $intimestamp in $timezone * @dataProvider pm_gmt_from_usertime_dataprovider */ public function test_pm_gmt_from_usertime($intimestamp, $timezone, $outtimestamp) { if (get_user_timezone_offset($timezone) == 99) { $this->markTestSkipped("\nSkipping test_pm_gmt_from_usertime() with undefined timezone = '{$timezone}'\n"); } else { $this->assertEquals($outtimestamp, pm_gmt_from_usertime($intimestamp, $timezone)); } }
function get_end_time() { if ($this->endtimehour >= 25 || $this->endtimeminute >= 61) { return 0; } $endtime = ($this->endtimehour - get_user_timezone_offset()) * HOURSECS; $endtime += $this->endtimeminute * MINSECS; return $endtime; }
/** * Sets the parameters property of the extended class * * Sets the parameters property of the extended file resource class * * @param USER global object * @param CFG global object */ function set_parameters() { global $USER, $CFG; $site = get_site(); $this->parameters = array('label2' => array('langstr' => "", 'value' => '/optgroup'), 'label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullname'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortname'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format), 'courseteacher' => array('langstr' => get_string('wordforteacher'), 'value' => $this->course->teacher), 'courseteachers' => array('langstr' => get_string('wordforteachers'), 'value' => $this->course->teachers), 'coursestudent' => array('langstr' => get_string('wordforstudent'), 'value' => $this->course->student), 'coursestudents' => array('langstr' => get_string('wordforstudents'), 'value' => $this->course->students), 'label4' => array('langstr' => "", 'value' => '/optgroup'), 'label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG), 'value' => $CFG->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup')); if (!empty($USER->id)) { $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullname'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url)); $this->parameters = $userparameters + $this->parameters; } }
/** * Test pm_gmt_from_usertime() function * @param array $intimeparts the input time components array * @param float|int|string $timezone the timezone of $intimestamp * @param int $outtimestamp the GMT timestamp for $intimestamp in $timezone * @dataProvider pm_timestamp_dataprovider */ public function test_pm_timestamp($intimeparts, $timezone, $outtimestamp) { if ($outtimestamp == 0) { $outtimestamp = mktime(2, 3, 4, 1, 1, 2013); } if (get_user_timezone_offset($timezone) == 99) { $this->markTestSkipped("\nSkipping test_pm_gmt_from_usertime() with undefined timezone = '{$timezone}'\n"); } else { if (is_array($outtimestamp)) { $outtimestamp = call_user_func_array('mktime', $outtimestamp); } $this->assertEquals($outtimestamp, pm_timestamp($intimeparts['hour'], $intimeparts['minute'], $intimeparts['second'], $intimeparts['month'], $intimeparts['day'], $intimeparts['year'], $timezone)); } }
public function date($message) { $offset = get_user_timezone_offset(); $time = $offset < 13 ? $message->time() + $offset : $message->time(); $now = $offset < 13 ? time() + $offset : time(); $daysago = floor($now / 86400) - floor($time / 86400); $yearsago = (int) date('Y', $now) - (int) date('Y', $time); if ($daysago == 0) { $content = userdate($time, get_string('strftimetime')); } else { if ($yearsago == 0) { $content = userdate($time, get_string('strftimedateshort')); } else { $content = userdate($time, get_string('strftimedate')); } } return html_writer::tag('span', s($content), array('class' => 'mail_date')); }
/** * Sets the parameters property of the extended class * * @param USER global object * @param CFG global object */ function set_parameters() { global $USER, $CFG; $site = get_site(); $littlecfg = new object(); // to avoid some notices later $littlecfg->wwwroot = $CFG->wwwroot; $courseparameters = array('label3' => array('langstr' => get_string('course'), 'value' => 'optgroup'), 'courseid' => array('langstr' => 'id', 'value' => $this->course->id), 'coursefullname' => array('langstr' => get_string('fullnamecourse'), 'value' => $this->course->fullname), 'courseshortname' => array('langstr' => get_string('shortnamecourse'), 'value' => $this->course->shortname), 'courseidnumber' => array('langstr' => get_string('idnumbercourse'), 'value' => $this->course->idnumber), 'coursesummary' => array('langstr' => get_string('summary'), 'value' => $this->course->summary), 'courseformat' => array('langstr' => get_string('format'), 'value' => $this->course->format)); $roles = get_all_roles(); $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id); $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS); foreach ($roles as $role) { $courseparameters['course' . $role->shortname] = array('langstr' => get_string('yourwordforx', '', $role->name), 'value' => $role->localname); } $courseparameters['label4'] = array('langstr' => '', 'value' => '/optgroup'); $miscparameters = array('label5' => array('langstr' => get_string('miscellaneous'), 'value' => 'optgroup'), 'lang' => array('langstr' => get_string('preferredlanguage'), 'value' => current_language()), 'sitename' => array('langstr' => get_string('fullsitename'), 'value' => format_string($site->fullname)), 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $littlecfg), 'value' => $littlecfg->wwwroot), 'currenttime' => array('langstr' => get_string('time'), 'value' => time()), 'encryptedcode' => array('langstr' => get_string('encryptedcode'), 'value' => $this->set_encrypted_parameter()), 'label6' => array('langstr' => "", 'value' => '/optgroup')); $userparameters = array(); if (!empty($USER->id)) { $userparameters = array('label1' => array('langstr' => get_string('user'), 'value' => 'optgroup'), 'userid' => array('langstr' => 'id', 'value' => $USER->id), 'userusername' => array('langstr' => get_string('username'), 'value' => $USER->username), 'useridnumber' => array('langstr' => get_string('idnumber'), 'value' => $USER->idnumber), 'userfirstname' => array('langstr' => get_string('firstname'), 'value' => $USER->firstname), 'userlastname' => array('langstr' => get_string('lastname'), 'value' => $USER->lastname), 'userfullname' => array('langstr' => get_string('fullnameuser'), 'value' => fullname($USER)), 'useremail' => array('langstr' => get_string('email'), 'value' => $USER->email), 'usericq' => array('langstr' => get_string('icqnumber'), 'value' => $USER->icq), 'userphone1' => array('langstr' => get_string('phone') . ' 1', 'value' => $USER->phone1), 'userphone2' => array('langstr' => get_string('phone2') . ' 2', 'value' => $USER->phone2), 'userinstitution' => array('langstr' => get_string('institution'), 'value' => $USER->institution), 'userdepartment' => array('langstr' => get_string('department'), 'value' => $USER->department), 'useraddress' => array('langstr' => get_string('address'), 'value' => $USER->address), 'usercity' => array('langstr' => get_string('city'), 'value' => $USER->city), 'usertimezone' => array('langstr' => get_string('timezone'), 'value' => get_user_timezone_offset()), 'userurl' => array('langstr' => get_string('webpage'), 'value' => $USER->url), 'label2' => array('langstr' => "", 'value' => '/optgroup')); } $this->parameters = array_merge($userparameters, $courseparameters, $miscparameters); }
} if (!isset($frm->an_emailexpiredteacher)) { $frm->an_emailexpiredteacher = ''; } if (!isset($frm->an_sorttype)) { $frm->an_sorttype = 'ttl'; } if (isset($CFG->an_cutoff)) { $cutoff = intval($CFG->an_cutoff); $mins = $cutoff % 60; $hrs = ($cutoff - $mins) / 60; $frm->an_cutoff_hour = $hrs; $frm->an_cutoff_min = $mins; } if (!isset($frm->an_cutoff_hour)) { $timezone = format_float(get_user_timezone_offset(), 1); $frm->an_cutoff_hour = intval($timezone); $frm->an_cutoff_min = intval(round($timezone)) != intval($timezone) ? 35 : 5; } if (!isset($frm->acceptmethods)) { $frm->acceptmethods = get_list_of_payment_methods(); $CFG->an_acceptmethods = implode(',', $frm->acceptmethods); } if (!isset($frm->acceptccs)) { $frm->acceptccs = array_keys(get_list_of_creditcards()); $CFG->an_acceptccs = implode(',', $frm->acceptccs); } if (!isset($frm->acceptechecktypes)) { $frm->acceptechecktypes = get_list_of_bank_account_types(); $CFG->an_acceptechecktypes = implode(',', $frm->acceptechecktypes); }
public function test_get_user_timezone_offset() { // This is a useless function, the timezone offset may be changing! $this->assertSame(-5.0, get_user_timezone_offset('America/New_York')); $this->assertDebuggingCalled(); $this->assertSame(-1.0, get_user_timezone_offset(-1)); $this->assertSame(1.0, get_user_timezone_offset(1)); $this->assertSame(1.0, get_user_timezone_offset('Europe/Prague')); $this->assertSame(8.0, get_user_timezone_offset('Australia/Perth')); $this->assertSame(12.0, get_user_timezone_offset('Pacific/Auckland')); $this->resetDebugging(); }
/** * Write one date somewhere in the worksheet * @param integer $row Zero indexed row * @param integer $col Zero indexed column * @param string $date The date to write in UNIX timestamp format * @param mixed $format The XF format for the cell */ function write_date($row, $col, $date, $format=null) { /// Calculate the internal PEAR format $format = $this->MoodleExcelFormat2PearExcelFormat($format); /// Convert the date to Excel format $timezone = get_user_timezone_offset(); if ($timezone == 99) { // system timezone offset in seconds $offset = (int)date('Z'); } else { $offset = (int)($timezone * HOURSECS * 2); } $value = ((usertime($date) + $offset) / 86400) + 25569; /// Add the date safely to the PEAR Worksheet $this->pear_excel_worksheet->writeNumber($row, $col, $value, $format); }
function stats_getdate($time, $timezone = 99) { $timezone = get_user_timezone_offset($timezone); if (abs($timezone) > 13) { // Server time return getdate($time); } // There is no gmgetdate so we use gmdate instead $time += intval((double) $timezone * HOURSECS); $datestring = strftime('%S_%M_%H_%d_%m_%Y_%w_%j_%A_%B', $time); list($getdate['seconds'], $getdate['minutes'], $getdate['hours'], $getdate['mday'], $getdate['mon'], $getdate['year'], $getdate['wday'], $getdate['yday'], $getdate['weekday'], $getdate['month']) = explode('_', $datestring); return $getdate; }
/** * returns unix timestamp from a date string depending on the date format * * @param string $format e.g. "d/m/Y" - see date_parse_from_format for supported formats * @param string $date a date to be converted e.g. "12/06/12" * @return int unix timestamp (0 if fails to parse) */ function facetofaceb_date_parse_from_format($format, $date) { global $CFG; $tz = isset($CFG->timezone) ? $CFG->timezone : 99; $timezone = get_user_timezone_offset($tz); $dateArray = array(); $dateArray = date_parse_from_format($format, $date); if (is_array($dateArray) && isset($dateArray['error_count']) && $dateArray['error_count'] == 0) { if (abs($timezone) > 13) { $time = mktime($dateArray['hour'], $dateArray['minute'], $dateArray['second'], $dateArray['month'], $dateArray['day'], $dateArray['year']); } else { $time = gmmktime($dateArray['hour'], $dateArray['minute'], $dateArray['second'], $dateArray['month'], $dateArray['day'], $dateArray['year']); $time = usertime($time, $timezone); } return $time; } else { return 0; } }
/** * Get the parameter values that may be appended to URL * @param object $url module instance * @param object $cm * @param object $course * @param object $config module config options * @return array of parameter values */ function mediaelementjs_get_variable_values($url, $cm, $course, $config) { global $USER, $CFG; $site = get_site(); $values = array('courseid' => $course->id, 'coursefullname' => format_string($course->fullname), 'courseshortname' => $course->shortname, 'courseidnumber' => $course->idnumber, 'coursesummary' => $course->summary, 'courseformat' => $course->format, 'lang' => current_language(), 'sitename' => format_string($site->fullname), 'serverurl' => $CFG->wwwroot, 'currenttime' => time(), 'urlinstance' => $url->id, 'urlcmid' => $cm->id, 'urlname' => format_string($url->name), 'urlidnumber' => $cm->idnumber); if (isloggedin()) { $values['userid'] = $USER->id; $values['userusername'] = $USER->username; $values['useridnumber'] = $USER->idnumber; $values['userfirstname'] = $USER->firstname; $values['userlastname'] = $USER->lastname; $values['userfullname'] = fullname($USER); $values['useremail'] = $USER->email; $values['usericq'] = $USER->icq; $values['userphone1'] = $USER->phone1; $values['userphone2'] = $USER->phone2; $values['userinstitution'] = $USER->institution; $values['userdepartment'] = $USER->department; $values['useraddress'] = $USER->address; $values['usercity'] = $USER->city; $values['usertimezone'] = get_user_timezone_offset(); $values['userurl'] = $USER->url; } // weak imitation of Single-Sign-On, for backwards compatibility only // NOTE: login hack is not included in 2.0 any more, new contrib auth plugin // needs to be createed if somebody needs the old functionality! if (!empty($config->secretphrase)) { $values['encryptedcode'] = url_get_encrypted_parameter($url, $config); } //hmm, this is pretty fragile and slow, why do we need it here?? if ($config->rolesinparams) { $roles = get_all_roles(); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS); foreach ($roles as $role) { $values['course' . $role->shortname] = $role->localname; } } return $values; }
/** * Given a time, return the GMT timestamp of the most recent midnight * for the current user. * * @param int $date Timestamp in GMT * @param float $timezone ? * @return ? */ function usergetmidnight($date, $timezone = 99) { $timezone = get_user_timezone_offset($timezone); $userdate = usergetdate($date, $timezone); // Time of midnight of this user's day, in GMT return make_timestamp($userdate['year'], $userdate['mon'], $userdate['mday'], 0, 0, 0, $timezone); }
// show Quizports on MyMoodle page (default=1) $settings->add(new admin_setting_configcheckbox('hotpot_enablemymoodle', get_string('enablemymoodle', 'mod_hotpot'), get_string('configenablemymoodle', 'mod_hotpot'), 1)); // enable caching of browser content for each quiz (default=1) $str = get_string('clearcache', 'mod_hotpot'); $url = new moodle_url('/mod/hotpot/tools/clear_cache.php', array('sesskey' => sesskey())); $link = html_writer::link($url, $str, array('class' => 'small', 'style' => 'white-space: nowrap', 'onclick' => "this.target='_blank'")) . "\n"; $settings->add(new admin_setting_configcheckbox('hotpot_enablecache', get_string('enablecache', 'mod_hotpot'), get_string('configenablecache', 'mod_hotpot') . ' ' . $link, 1)); // restrict cron job to certain hours of the day (default=never) if (class_exists('core_date') && method_exists('core_date', 'get_user_timezone')) { // Moodle >= 2.9 $timezone = core_date::get_user_timezone(99); $datetime = new DateTime('now', new DateTimeZone($timezone)); $timezone = ($datetime->getOffset() - dst_offset_on(time(), $timezone)) / 3600.0; } else { // Moodle <= 2.8 $timezone = get_user_timezone_offset(); } if (abs($timezone) > 13) { $timezone = 0; } else { if ($timezone > 0) { $timezone = $timezone - 24; } } $options = array(); for ($i = 0; $i <= 23; $i++) { $options[($i - $timezone) % 24] = gmdate('H:i', $i * HOURSECS); } $settings->add(new admin_setting_configmultiselect('hotpot_enablecron', get_string('enablecron', 'mod_hotpot'), get_string('configenablecron', 'mod_hotpot'), array(), $options)); // enable embedding of swf media objects inhotpot quizzes (default=1) $settings->add(new admin_setting_configcheckbox('hotpot_enableswf', get_string('enableswf', 'mod_hotpot'), get_string('configenableswf', 'mod_hotpot'), 1));
function get_end_time() { $endtime = ($this->endtimehour - get_user_timezone_offset()) * HOURSECS; $endtime += $this->endtimeminute * MINSECS; return $endtime; }
} if (!isset($frm->an_emailexpiredteacher)) { $frm->an_emailexpiredteacher = ''; } if (!isset($frm->an_sorttype)) { $frm->an_sorttype = 'ttl'; } if (isset($CFG->an_cutoff)) { $cutoff = intval($CFG->an_cutoff); $mins = $cutoff % 60; $hrs = ($cutoff - $mins) / 60; $frm->an_cutoff_hour = $hrs; $frm->an_cutoff_min = $mins; } if (!isset($frm->an_cutoff_hour)) { $timezone = round(get_user_timezone_offset(), 1); $frm->an_cutoff_hour = intval($timezone); $frm->an_cutoff_min = intval(round($timezone)) != intval($timezone) ? 35 : 5; } if (!isset($frm->acceptmethods)) { $frm->acceptmethods = get_list_of_payment_methods(); $CFG->an_acceptmethods = implode(',', $frm->acceptmethods); } if (!isset($frm->acceptccs)) { $frm->acceptccs = array_keys(get_list_of_creditcards()); $CFG->an_acceptccs = implode(',', $frm->acceptccs); } if (!isset($frm->acceptechecktypes)) { $frm->acceptechecktypes = get_list_of_bank_account_types(); $CFG->an_acceptechecktypes = implode(',', $frm->acceptechecktypes); }
/** * Write one date somewhere in the worksheet * @param integer $row Zero indexed row * @param integer $col Zero indexed column * @param string $date The date to write in UNIX timestamp format * @param mixed $format The XF format for the cell */ function write_date($row, $col, $date, $format = null) { /// Calculate the internal PEAR format $format = $this->MoodleExcelFormat2PearExcelFormat($format); /// Convert the date to Excel format $timezone = get_user_timezone_offset(); $value = (usertime($date) + (int) ($timezone * HOURSECS * 2)) / 86400 + 25569; /// Add the date safely to the PEAR Worksheet $this->pear_excel_worksheet->writeNumber($row, $col, $value, $format); }
function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { global $CFG, $SESSION, $USER, $CALENDARDAYS; global $day, $mon, $yr; $getvars = 'from=month&cal_d=' . $day . '&cal_m=' . $mon . '&cal_y=' . $yr; // For filtering $display =& new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); $display->maxwday = $display->minwday + 6; if (!empty($m) && !empty($y)) { $thisdate = usergetdate(time()); // Time and day at the user's location if ($m == $thisdate['mon'] && $y == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if (!checkdate($m, 1, $y)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $m, 'year' => $y); $display->thismonth = false; } } } else { $date = usergetdate(time()); $display->thismonth = true; } // Fill in the variables we 're going to use, nice and tidy list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); $startwday = 0; if (get_user_timezone_offset() < 99) { // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $m, 1, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() } // Align the starting weekday to fall in our display range if ($startwday < $display->minwday) { $startwday += 7; } // Get events from database $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses); if (!empty($events)) { foreach ($events as $eventid => $event) { if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // Extract information: events vs. time calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); $text = ''; if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) { $text .= '<div class="buttons"><form action="' . CALENDAR_URL . 'event.php" method="get">'; $text .= '<div>'; $text .= '<input type="hidden" name="action" value="new" />'; $text .= '<input type="hidden" name="course" value="' . $courseid . '" />'; $text .= '<input type="hidden" name="cal_m" value="' . $m . '" />'; $text .= '<input type="hidden" name="cal_y" value="' . $y . '" />'; $text .= '<input type="submit" value="' . get_string('newevent', 'calendar') . '" />'; $text .= '</div></form></div>'; } $text .= '<label for="cal_course_flt_jump">' . get_string('detailedmonthview', 'calendar') . ':</label>' . calendar_course_filter_selector($getvars); echo '<div class="header">' . $text . '</div>'; echo '<div class="controls">'; echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y)); echo '</div>'; // Start calendar display echo '<table class="calendarmonth"><tr class="weekdays">'; // Begin table. First row: day names // Print out the names of the weekdays for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { // This uses the % operator to get the correct weekday no matter what shift we have // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 echo '<th scope="col">' . get_string($CALENDARDAYS[$i % 7], 'calendar') . '</th>'; } echo '</tr><tr>'; // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { echo '<td class="nottoday"> </td>' . "\n"; } // Now display all the calendar for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { if ($dayweek > $display->maxwday) { // We need to change week (table row) echo "</tr>\n<tr>"; $dayweek = $display->minwday; ++$week; } // Reset vars $cell = ''; $dayhref = calendar_get_link_href(CALENDAR_URL . 'view.php?view=day&course=' . $courseid . '&', $day, $m, $y); if (CALENDAR_WEEKEND & 1 << $dayweek % 7) { // Weekend. This is true no matter what the exact range is. $class = 'weekend'; } else { // Normal working day. $class = ''; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { if (count($eventsbyday[$day]) == 1) { $title = get_string('oneevent', 'calendar'); } else { $title = get_string('manyevents', 'calendar', count($eventsbyday[$day])); } $cell = '<div class="day"><a href="' . $dayhref . '" title="' . $title . '">' . $day . '</a></div>'; } else { $cell = '<div class="day">' . $day . '</div>'; } // Special visual fx if an event spans many days if (isset($typesbyday[$day]['durationglobal'])) { $class .= ' duration_global'; } else { if (isset($typesbyday[$day]['durationcourse'])) { $class .= ' duration_course'; } else { if (isset($typesbyday[$day]['durationgroup'])) { $class .= ' duration_group'; } else { if (isset($typesbyday[$day]['durationuser'])) { $class .= ' duration_user'; } } } } // Special visual fx for today if ($display->thismonth && $day == $d) { $class .= ' today'; } else { $class .= ' nottoday'; } // Just display it if (!empty($class)) { $class = ' class="' . trim($class) . '"'; } echo '<td' . $class . '>' . $cell; if (isset($eventsbyday[$day])) { echo '<ul class="events-new">'; foreach ($eventsbyday[$day] as $eventindex) { // If event has a class set then add it to the event <li> tag $eventclass = ''; if (!empty($events[$eventindex]->class)) { $eventclass = ' class="' . $events[$eventindex]->class . '"'; } echo '<li' . $eventclass . '><a href="' . $dayhref . '#event_' . $events[$eventindex]->id . '">' . format_string($events[$eventindex]->name, true) . '</a></li>'; } echo '</ul>'; } if (isset($durationbyday[$day])) { echo '<ul class="events-underway">'; foreach ($durationbyday[$day] as $eventindex) { echo '<li>[' . format_string($events[$eventindex]->name, true) . ']</li>'; } echo '</ul>'; } echo "</td>\n"; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { echo '<td class="nottoday"> </td>'; } echo "</tr>\n"; // Last row ends echo "</table>\n"; // Tabular display of days ends // OK, now for the filtering display echo '<div class="filters"><table><tr>'; // Global events if ($SESSION->cal_show_global) { echo '<td class="event_global" style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } // Course events if (!empty($SESSION->cal_show_course)) { echo '<td class="event_course" style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } echo "</tr>\n"; if (!empty($USER->id) && !isguest()) { echo '<tr>'; // Group events if ($SESSION->cal_show_groups) { echo '<td class="event_group" style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } // User events if ($SESSION->cal_show_user) { echo '<td class="event_user" style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } echo "</tr>\n"; } echo '</table></div>'; }
/** * Returns a formatted string that represents a date in user time. * * Returns a formatted string that represents a date in user time * <b>WARNING: note that the format is for strftime(), not date().</b> * Because of a bug in most Windows time libraries, we can't use * the nicer %e, so we have to use %d which has leading zeroes. * A lot of the fuss in the function is just getting rid of these leading * zeroes as efficiently as possible. * * If parameter fixday = true (default), then take off leading * zero from %d, else maintain it. * * @param int $time the timestamp in UTC, as obtained from the database * @param string $format strftime format * @param int|float|string $timezone the timezone to use * {@link http://docs.moodle.org/dev/Time_API#Timezone} * @param bool $fixday if true then the leading zero from %d is removed, * if false then the leading zero is maintained * @param bool $fixhour if true then the leading zero from %I is removed, * if false then the leading zero is maintained * @return string the formatted date/time */ public function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour) { global $CFG; if (empty($format)) { $format = get_string('strftimedaydatetime', 'langconfig'); } if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. $fixday = false; } else { if ($fixday) { $formatnoday = str_replace('%d', 'DD', $format); $fixday = $formatnoday != $format; $format = $formatnoday; } } // Note: This logic about fixing 12-hour time to remove unnecessary leading // zero is required because on Windows, PHP strftime function does not // support the correct 'hour without leading zero' parameter (%l). if (!empty($CFG->nofixhour)) { // Config.php can force %I not to be fixed. $fixhour = false; } else { if ($fixhour) { $formatnohour = str_replace('%I', 'HH', $format); $fixhour = $formatnohour != $format; $format = $formatnohour; } } // Add daylight saving offset for string timezones only, as we can't get dst for // float values. if timezone is 99 (user default timezone), then try update dst. if (99 == $timezone || !is_numeric($timezone)) { $time += dst_offset_on($time, $timezone); } $timezone = get_user_timezone_offset($timezone); // If we are running under Windows convert to windows encoding and then back to UTF-8 // (because it's impossible to specify UTF-8 to fetch locale info in Win32). if (abs($timezone) > 13) { // Server time. $datestring = date_format_string($time, $format, $timezone); if ($fixday) { $daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time))); $datestring = str_replace('DD', $daystring, $datestring); } if ($fixhour) { $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time))); $datestring = str_replace('HH', $hourstring, $datestring); } } else { $time += (int) ($timezone * 3600); $datestring = date_format_string($time, $format, $timezone); if ($fixday) { $daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $time))); $datestring = str_replace('DD', $daystring, $datestring); } if ($fixhour) { $hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $time))); $datestring = str_replace('HH', $hourstring, $datestring); } } return $datestring; }
/** * Given a GMT timestamp (seconds since epoch), offsets it by * the timezone. eg 3pm in India is 3pm GMT - 7 * 3600 seconds * * @package core * @category time * @uses HOURSECS * @param int $date Timestamp in GMT * @param float|int|string $timezone timezone to calculate GMT time offset before * calculating user time, 99 is default user timezone * {@link http://docs.moodle.org/dev/Time_API#Timezone} * @return int */ function usertime($date, $timezone=99) { $timezone = get_user_timezone_offset($timezone); if (abs($timezone) > 13) { return $date; } return $date - (int)($timezone * HOURSECS); }
/** * Displays a month in detail * * @param calendar_information $calendar * @return string */ public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { global $CFG; if (empty($returnurl)) { $returnurl = $this->page->url; } $date = usergetdate(time()); $display = new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); $display->maxwday = $display->minwday + 6; $display->thismonth = $date['mon'] == $calendar->month; $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year); $startwday = 0; if (get_user_timezone_offset() < 99) { // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year); $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() } // Align the starting weekday to fall in our display range if ($startwday < $display->minwday) { $startwday += 7; } // Get events from database $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses); if (!empty($events)) { foreach ($events as $eventid => $event) { $event = new calendar_event($event); if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // Extract information: events vs. time calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); $output = html_writer::start_tag('div', array('class' => 'header')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year); } $output .= get_string('detailedmonthview', 'calendar') . ': ' . $this->course_filter_selector($returnurl); $output .= html_writer::end_tag('div', array('class' => 'header')); // Controls $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class' => 'controls')); $days = calendar_get_days(); $table = new html_table(); $table->attributes = array('class' => 'calendarmonth calendartable'); $table->data = array(); $header = new html_table_row(); $header->attributes = array('class' => 'weekdays'); $header->cells = array(); for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { // This uses the % operator to get the correct weekday no matter what shift we have // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 $cell = new html_table_cell(get_string($days[$i % 7], 'calendar')); $cell->header = true; $header->cells[] = $cell; } // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; // Create an array of all the week days. $wdays = array(0 => '<strong>' . get_string('sunday', 'calendar') . '</strong>', 1 => '<strong>' . get_string('monday', 'calendar') . '</strong>', 2 => '<strong>' . get_string('tuesday', 'calendar') . '</strong>', 3 => '<strong>' . get_string('wednesday', 'calendar') . '</strong>', 4 => '<strong>' . get_string('thursday', 'calendar') . '</strong>', 5 => '<strong>' . get_string('friday', 'calendar') . '</strong>', 6 => '<strong>' . get_string('saturday', 'calendar') . '</strong>'); // Loop only if the day offset is greater than 0. // This loop involves shifting the days around until the desired start day // is at the start of the array. $daycount = 0; while ($display->minwday > $daycount++) { $wdays_end = array_shift($wdays); array_push($wdays, $wdays_end); } // Now we set the (modified) array to the table header to be displayed. $table->head = $wdays; $row = new html_table_row(array()); // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday'); $row->cells[] = $cell; } // Now display all the calendar $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) { if ($dayweek > $display->maxwday) { // We need to change week (table row) $table->data[] = $row; $row = new html_table_row(array()); $dayweek = $display->minwday; ++$week; } // Reset vars $cell = new html_table_cell(); $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day', 'course' => $calendar->courseid)), $calendar->day, $calendar->month, $calendar->year); $cellclasses = array(); if ($weekend & 1 << $dayweek % 7) { // Weekend. This is true no matter what the exact range is. $cellclasses[] = 'weekend'; } // Special visual fx if an event is defined if (isset($eventsbyday[$calendar->day])) { if (count($eventsbyday[$calendar->day]) == 1) { $title = get_string('oneevent', 'calendar'); } else { $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day])); } $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title' => $title)), array('class' => 'day')); } else { $cell->text = html_writer::tag('div', $calendar->day, array('class' => 'day')); } // Special visual fx if an event spans many days $durationclass = false; if (isset($typesbyday[$calendar->day]['durationglobal'])) { $durationclass = 'duration_global'; } else { if (isset($typesbyday[$calendar->day]['durationcourse'])) { $durationclass = 'duration_course'; } else { if (isset($typesbyday[$calendar->day]['durationgroup'])) { $durationclass = 'duration_group'; } else { if (isset($typesbyday[$calendar->day]['durationuser'])) { $durationclass = 'duration_user'; } } } } if ($durationclass) { $cellclasses[] = 'duration'; $cellclasses[] = $durationclass; } // Special visual fx for today if ($display->thismonth && $calendar->day == $calendar->day) { $cellclasses[] = 'today'; } else { $cellclasses[] = 'nottoday'; } $cell->attributes = array('class' => join(' ', $cellclasses)); if (isset($eventsbyday[$calendar->day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new')); foreach ($eventsbyday[$calendar->day] as $eventindex) { // If event has a class set then add it to the event <li> tag $attributes = array(); if (!empty($events[$eventindex]->class)) { $attributes['class'] = $events[$eventindex]->class; } $dayhref->set_anchor('event_' . $events[$eventindex]->id); $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true)); $cell->text .= html_writer::tag('li', $link, $attributes); } $cell->text .= html_writer::end_tag('ul'); } if (isset($durationbyday[$calendar->day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway')); foreach ($durationbyday[$calendar->day] as $eventindex) { $cell->text .= html_writer::tag('li', '[' . format_string($events[$eventindex]->name, true) . ']', array('class' => 'events-underway')); } $cell->text .= html_writer::end_tag('ul'); } $row->cells[] = $cell; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday'); $row->cells[] = $cell; } $table->data[] = $row; $output .= html_writer::table($table); // OK, now for the filtering display $output .= $this->filter_selection_table($calendar); return $output; }
/** * Function to convert time in user's timezone to GMT * Note: Moodle function usertime() doesn't include DST offset * @param int $usertime timestamp in user's timezone * @param float|int|string $timezone optional timezone to use, defaults to user's * @return int timestamp in GMT */ function pm_gmt_from_usertime($usertime, $timezone = 99) { $tz = get_user_timezone_offset($timezone); if (abs($tz) > 13) { return $usertime; } $usertime -= (int) ($tz * HOURSECS); if ($timezone == 99 || !is_numeric($timezone)) { $usertime -= dst_offset_on($usertime, $timezone); } return $usertime; }
/** * This function converts a timestamp in timezone to GMT (UTC) * @param $timestamp * @param $timezone * @param mixed $dstdate default null uses $timestamp (param1) for dst calc * false disables dst offset, * otherwise dstdate value used in place of timestamp for dst calc * @return int adjusted timestamp (secs since epoch) */ function to_gmt($timestamp, $timezone = 99, $dstdate = null) { if ($dstdate == null) { $dstdate = $timestamp; } $ts = $timestamp; $dstoffset = null; if (!empty($dstdate) && ($timezone == 99 || !is_numeric($timezone))) { $strtimezone = is_numeric($timezone) ? NULL : $timezone; $dstoffset = dst_offset_on($dstdate, $strtimezone); $ts -= $dstoffset; // or += see to_gmt() } $tz = get_user_timezone_offset($timezone); $ts = abs($tz) > 13 ? $ts : $ts - $tz * HOURSECS; //debug_error_log("/blocks/php_report/sharedlib.php::to_gmt({$timestamp}, {$timezone}): tz = {$tz} dstdate = {$dstdate} dstoffset = {$dstoffset} => $ts"); return $ts; }
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) { global $CFG, $USER; $display = new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); $display->maxwday = $display->minwday + 6; $content = ''; if (!empty($cal_month) && !empty($cal_year)) { $thisdate = usergetdate(time()); // Date and time the user sees at his location if ($cal_month == $thisdate['mon'] && $cal_year == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if (!checkdate($cal_month, 1, $cal_year)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $cal_month, 'year' => $cal_year); $display->thismonth = false; } } } else { $date = usergetdate(time()); // Date and time the user sees at his location $display->thismonth = true; } // Fill in the variables we 're going to use, nice and tidy list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); if (get_user_timezone_offset() < 99) { // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $m, 1, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); } $startwday = dayofweek(1, $m, $y); // Align the starting weekday to fall in our display range // This is simple, not foolproof. if ($startwday < $display->minwday) { $startwday += 7; } // TODO: THIS IS TEMPORARY CODE! // [pj] I was just reading through this and realized that I when writing this code I was probably // asking for trouble, as all these time manipulations seem to be unnecessary and a simple // make_timestamp would accomplish the same thing. So here goes a test: //$test_start = make_timestamp($y, $m, 1); //$test_end = make_timestamp($y, $m, $display->maxdays, 23, 59, 59); //if($test_start != usertime($display->tstart) - dst_offset_on($display->tstart)) { //notify('Failed assertion in calendar/lib.php line 126; display->tstart = '.$display->tstart.', dst_offset = '.dst_offset_on($display->tstart).', usertime = '.usertime($display->tstart).', make_t = '.$test_start); //} //if($test_end != usertime($display->tend) - dst_offset_on($display->tend)) { //notify('Failed assertion in calendar/lib.php line 130; display->tend = '.$display->tend.', dst_offset = '.dst_offset_on($display->tend).', usertime = '.usertime($display->tend).', make_t = '.$test_end); //} // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ! $events = calendar_get_events(usertime($display->tstart) - dst_offset_on($display->tstart), usertime($display->tend) - dst_offset_on($display->tend), $users, $groups, $courses); // Set event course class for course events if (!empty($events)) { foreach ($events as $eventid => $event) { if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $morehref = ''; if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $morehref = '&course=' . reset($courses); } } // We want to have easy access by day, since the display is on a per-day basis. // Arguments passed by reference. //calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday); calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); //Accessibility: added summary and <abbr> elements. ///global $CALENDARDAYS; appears to be broken. $days_title = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); $summary = get_string('calendarheading', 'calendar', userdate(make_timestamp($y, $m), get_string('strftimemonthyear'))); $summary = get_string('tabledata', 'access', $summary); $content .= '<table class="minicalendar" summary="' . $summary . '">'; // Begin table $content .= '<tr class="weekdays">'; // Header row: day names // Print out the names of the weekdays $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { // This uses the % operator to get the correct weekday no matter what shift we have // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 $content .= '<th scope="col"><abbr title="' . get_string($days_title[$i % 7], 'calendar') . '">' . get_string($days[$i % 7], 'calendar') . "</abbr></th>\n"; } $content .= '</tr><tr>'; // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $dayweek = $startwday; // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $content .= '<td class="dayblank"> </td>' . "\n"; } // Now display all the calendar for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { if ($dayweek > $display->maxwday) { // We need to change week (table row) $content .= '</tr><tr>'; $dayweek = $display->minwday; } // Reset vars $cell = ''; if (CALENDAR_WEEKEND & 1 << $dayweek % 7) { // Weekend. This is true no matter what the exact range is. $class = 'weekend day'; } else { // Normal working day. $class = 'day'; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { $dayhref = calendar_get_link_href(CALENDAR_URL . 'view.php?view=day' . $morehref . '&', $day, $m, $y); // OverLib popup $popupcontent = ''; foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = $events[$eventid]; if (!empty($event->modulename)) { $popupicon = $CFG->modpixpath . '/' . $event->modulename . '/icon.gif'; $popupalt = $event->modulename; } else { if ($event->courseid == SITEID) { // Site event $popupicon = $CFG->pixpath . '/c/site.gif'; $popupalt = ''; } else { if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event $popupicon = $CFG->pixpath . '/c/course.gif'; $popupalt = ''; } else { if ($event->groupid) { // Group event $popupicon = $CFG->pixpath . '/c/group.gif'; $popupalt = ''; } else { if ($event->userid) { // User event $popupicon = $CFG->pixpath . '/c/user.gif'; $popupalt = ''; } } } } } $popupcontent .= '<div><img class="icon" src="' . $popupicon . '" alt="' . $popupalt . '" /><a href="' . $dayhref . '#event_' . $event->id . '">' . format_string($event->name, true) . '</a></div>'; } //Accessibility: functionality moved to calendar_get_popup. if ($display->thismonth && $day == $d) { $popup = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent); } else { $popup = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent); } // Class and cell content if (isset($typesbyday[$day]['startglobal'])) { $class .= ' event_global'; } else { if (isset($typesbyday[$day]['startcourse'])) { $class .= ' event_course'; } else { if (isset($typesbyday[$day]['startgroup'])) { $class .= ' event_group'; } else { if (isset($typesbyday[$day]['startuser'])) { $class .= ' event_user'; } } } } $cell = '<a href="' . $dayhref . '" ' . $popup . '>' . $day . '</a>'; } else { $cell = $day; } if (isset($typesbyday[$day]['durationglobal'])) { $class .= ' duration_global'; } else { if (isset($typesbyday[$day]['durationcourse'])) { $class .= ' duration_course'; } else { if (isset($typesbyday[$day]['durationgroup'])) { $class .= ' duration_group'; } else { if (isset($typesbyday[$day]['durationuser'])) { $class .= ' duration_user'; } } } } // If event has a class set then add it to the table day <td> tag // Note: only one colour for minicalendar if (isset($eventsbyday[$day])) { foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = $events[$eventid]; if (!empty($event->class)) { $class .= ' ' . $event->class; } break; } } // Special visual fx for today //Accessibility: hidden text for today, and popup. if ($display->thismonth && $day == $d) { $class .= ' today'; $today = get_string('today', 'calendar') . ' ' . userdate(time(), get_string('strftimedayshort')); if (!isset($eventsbyday[$day])) { $class .= ' eventnone'; $popup = calendar_get_popup(true, false); $cell = '<a href="#" ' . $popup . '>' . $day . '</a>'; } $cell = get_accesshide($today . ' ') . $cell; } // Just display it if (!empty($class)) { $class = ' class="' . $class . '"'; } $content .= '<td' . $class . '>' . $cell . "</td>\n"; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $content .= '<td class="dayblank"> </td>'; } $content .= '</tr>'; // Last row ends $content .= '</table>'; // Tabular display of days ends return $content; }
function get_display_info($d, $m, $y) { $display = new stdClass; $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); $display->maxwday = $display->minwday + 6; $thisdate = usergetdate(time()); // Time and day at the user's location if ($m == $thisdate['mon'] && $y == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if (!checkdate($m, 1, $y)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $m, 'year' => $y); $display->thismonth = false; } } // Fill in the variables we 're going to use, nice and tidy list($day, $month, $year) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); $startwday = 0; if (get_user_timezone_offset() < 99) { // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $m, 1, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() } // Align the starting weekday to fall in our display range if ($startwday < $display->minwday) { $startwday += 7; } $display->startwday = $startwday; return $display; }