Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (4 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

Location:
moodle/trunk/fuentes/calendar
Files:
20 added
2 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/calendar/classes/type_factory.php

    r136 r1331  
    3232     *
    3333     * @param string|null $type the calendar type to use, if none provided use logic to determine
    34      * @return calendartype_* the created calendar_type class
    35      * @throws coding_exception if the calendar type file could not be loaded
     34     * @return \core_calendar\type_base the created calendar_type class
     35     * @throws \coding_exception if the calendar type file could not be loaded
    3636     */
    3737    public static function get_calendar_instance($type = null) {
  • moodle/trunk/fuentes/calendar/export.php

    r136 r1331  
    6363$generateurl = optional_param('generateurl', 0, PARAM_BOOL);
    6464
    65 // Get the calendar type we are using.
    66 $calendartype = \core_calendar\type_factory::get_calendar_instance();
    6765
    6866// If a day, month and year were passed then convert it to a timestamp. If these were passed
     
    105103
    106104$pagetitle = get_string('export', 'calendar');
    107 $now = $calendartype->timestamp_to_date_array($time);
    108105
    109106// Print title and header
     
    123120$calendar->add_sidecalendar_blocks($renderer);
    124121
     122// Get the calendar type we are using.
     123$calendartype = \core_calendar\type_factory::get_calendar_instance();
     124$now = $calendartype->timestamp_to_date_array($time);
     125
     126$weekend = CALENDAR_DEFAULT_WEEKEND;
     127if (isset($CFG->calendar_weekend)) {
     128    $weekend = intval($CFG->calendar_weekend);
     129}
     130$numberofdaysinweek = $calendartype->get_num_weekdays();
     131
     132$formdata = array(
     133    // Let's populate some vars to let "common tasks" be somewhat smart...
     134    // If today it's weekend, give the "next week" option.
     135    'allownextweek' => $weekend & (1 << $now['wday']),
     136    // If it's the last week of the month, give the "next month" option.
     137    'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek,
     138    // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
     139    'allowthisweek' => !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % $numberofdaysinweek))))
     140);
     141$exportform = new core_calendar_export_form(null, $formdata);
     142$calendarurl = '';
     143if ($data = $exportform->get_data()) {
     144    $password = $DB->get_record('user', array('id' => $USER->id), 'password');
     145    $params = array();
     146    $params['userid']      = $USER->id;
     147    $params['authtoken']   = sha1($USER->id . (isset($password->password) ? $password->password : '') . $CFG->calendar_exportsalt);
     148    $params['preset_what'] = $data->events['exportevents'];
     149    $params['preset_time'] = $data->period['timeperiod'];
     150
     151    $link = new moodle_url('/calendar/export_execute.php', $params);
     152    if (!empty($data->generateurl)) {
     153        $urlclasses = array('class' => 'generalbox calendarurl');
     154        $calendarurl = html_writer::tag( 'div', get_string('calendarurl', 'calendar', $link->out()), $urlclasses);
     155    }
     156
     157    if (!empty($data->export)) {
     158        redirect($link);
     159    }
     160}
     161
    125162echo $OUTPUT->header();
    126163echo $renderer->start_layout();
    127 switch($action) {
    128     case 'advanced':
    129         // Why nothing?
    130         break;
    131     case '':
    132     default:
    133         $weekend = CALENDAR_DEFAULT_WEEKEND;
    134         if (isset($CFG->calendar_weekend)) {
    135             $weekend = intval($CFG->calendar_weekend);
    136         }
     164echo $OUTPUT->heading(get_string('exportcalendar', 'calendar'));
    137165
    138         // Get the number of days.
    139         $numberofdaysinweek = $calendartype->get_num_weekdays();
    140 
    141         $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id'=>$USER->id)). $CFG->calendar_exportsalt);
    142         // Let's populate some vars to let "common tasks" be somewhat smart...
    143         // If today it's weekend, give the "next week" option.
    144         $allownextweek = $weekend & (1 << $now['wday']);
    145         // If it's the last week of the month, give the "next month" option.
    146         $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek;
    147         // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
    148         $allowthisweek = !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % $numberofdaysinweek))));
    149         echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $USER->id, $authtoken);
    150         break;
     166if ($action != 'advanced') {
     167    $exportform->display();
    151168}
    152169
    153 if (!empty($generateurl)) {
    154     $params['userid']      = optional_param('userid', 0, PARAM_INT);
    155     $params['authtoken']   = optional_param('authtoken', '', PARAM_ALPHANUM);
    156     $params['preset_what'] = optional_param('preset_what', 'all', PARAM_ALPHA);
    157     $params['preset_time'] = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
    158 
    159     $link = new moodle_url('/calendar/export_execute.php', $params);
    160     print html_writer::tag('div', get_string('calendarurl', 'calendar', $link->out()), array('class' => 'generalbox calendarurl'));
    161 }
     170echo $calendarurl;
    162171
    163172echo $renderer->complete_layout();
  • moodle/trunk/fuentes/calendar/export_execute.php

    r136 r1331  
    190190    $ev->add_property('last-modified', Bennu::timestamp_to_datetime($event->timemodified));
    191191    $ev->add_property('dtstamp', Bennu::timestamp_to_datetime()); // now
    192     $ev->add_property('dtstart', Bennu::timestamp_to_datetime($event->timestart)); // when event starts
    193192    if ($event->timeduration > 0) {
    194193        //dtend is better than duration, because it works in Microsoft Outlook and works better in Korganizer
     194        $ev->add_property('dtstart', Bennu::timestamp_to_datetime($event->timestart)); // when event starts.
    195195        $ev->add_property('dtend', Bennu::timestamp_to_datetime($event->timestart + $event->timeduration));
     196    } else {
     197        // When no duration is present, ie an all day event, VALUE should be date instead of time and dtend = dtstart + 1 day.
     198        $ev->add_property('dtstart', Bennu::timestamp_to_date($event->timestart), array('value' => 'DATE')); // All day event.
     199        $ev->add_property('dtend', Bennu::timestamp_to_date($event->timestart + DAYSECS), array('value' => 'DATE')); // All day event.
    196200    }
    197201    if ($event->courseid != 0) {
  • moodle/trunk/fuentes/calendar/externallib.php

    r136 r1331  
    143143                                             VALUE_DEFAULT, 0, NULL_ALLOWED),
    144144                                    'timeend' => new external_value(PARAM_INT,
    145                                              "Time to which the events should be returned",
    146                                              VALUE_DEFAULT, time(), NULL_ALLOWED),
     145                                             "Time to which the events should be returned. We treat 0 and null as no end",
     146                                             VALUE_DEFAULT, 0, NULL_ALLOWED),
    147147                                    'ignorehidden' => new external_value(PARAM_BOOL,
    148148                                             "Ignore hidden events or not",
     
    174174        // Let us findout courses that we can return events from.
    175175        if (!$hassystemcap) {
    176             $courses = enrol_get_my_courses();
     176            $courses = enrol_get_my_courses('id');
    177177            $courses = array_keys($courses);
    178178            foreach ($params['events']['courseids'] as $id) {
    179                 if (in_array($id, $courses)) {
     179               try {
     180                    $context = context_course::instance($id);
     181                    self::validate_context($context);
    180182                    $funcparam['courses'][] = $id;
    181                 } else {
    182                     $warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this course');
     183                } catch (Exception $e) {
     184                    $warnings[] = array(
     185                        'item' => 'course',
     186                        'itemid' => $id,
     187                        'warningcode' => 'nopermissions',
     188                        'message' => 'No access rights in course context '.$e->getMessage().$e->getTraceAsString()
     189                    );
    183190                }
    184191            }
     
    216223        }
    217224
     225        // We treat 0 and null as no end.
     226        if (empty($params['options']['timeend'])) {
     227            $params['options']['timeend'] = PHP_INT_MAX;
     228        }
     229
     230        // Event list does not check visibility and permissions, we'll check that later.
    218231        $eventlist = calendar_get_events($params['options']['timestart'], $params['options']['timeend'], $funcparam['users'], $funcparam['groups'],
    219232                $funcparam['courses'], true, $params['options']['ignorehidden']);
     233
    220234        // WS expects arrays.
    221235        $events = array();
    222         foreach ($eventlist as $id => $event) {
    223             $events[$id] = (array) $event;
    224         }
    225236
    226237        // We need to get events asked for eventids.
    227         $eventsbyid = calendar_get_events_by_id($params['events']['eventids']);
    228         foreach ($eventsbyid as $eventid => $eventobj) {
     238        if ($eventsbyid = calendar_get_events_by_id($params['events']['eventids'])) {
     239            $eventlist += $eventsbyid;
     240        }
     241
     242        foreach ($eventlist as $eventid => $eventobj) {
    229243            $event = (array) $eventobj;
    230             if (isset($events[$eventid])) {
    231                    continue;
    232             }
     244
    233245            if ($hassystemcap) {
    234246                // User can see everything, no further check is needed.
  • moodle/trunk/fuentes/calendar/lib.php

    r136 r1331  
    180180function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
    181181    $courseid = false, $time = 0) {
    182     global $CFG, $OUTPUT;
     182    global $CFG, $OUTPUT, $PAGE;
    183183
    184184    // Get the calendar type we are using.
     
    290290    // Accessibility: added summary and <abbr> elements.
    291291    $summary = get_string('calendarheading', 'calendar', userdate($display->tstart, get_string('strftimemonthyear')));
    292     $content .= '<table class="minicalendar calendartable" summary="'.$summary.'">'; // Begin table.
     292    // Begin table.
     293    $content .= '<table class="minicalendar calendartable" summary="' . $summary . '">';
    293294    if (($placement !== false) && ($courseid !== false)) {
    294295        $content .= '<caption>'. calendar_top_controls($placement, array('id' => $courseid, 'time' => $time)) .'</caption>';
     
    321322    $daytime = strtotime('-1 day', $display->tstart);
    322323    for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
     324        $cellattributes = array();
    323325        $daytime = strtotime('+1 day', $daytime);
    324326        if($dayweek > $display->maxwday) {
     
    337339        }
    338340
    339         // Special visual fx if an event is defined
    340         if(isset($eventsbyday[$day])) {
     341        if (isset($eventsbyday[$day])) {
     342            // There is at least one event on this day.
    341343
    342344            $class .= ' hasevent';
     
    382384            }
    383385
    384             //Accessibility: functionality moved to calendar_get_popup.
    385             if($display->thismonth && $day == $d) {
    386                 $popupid = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
     386            if ($display->thismonth && $day == $d) {
     387                $popupdata = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
    387388            } else {
    388                 $popupid = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
    389             }
     389                $popupdata = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
     390            }
     391            $cellattributes = array_merge($cellattributes, $popupdata);
    390392
    391393            // Class and cell content
     
    399401                $class .= ' calendar_event_user';
    400402            }
    401             $cell = html_writer::link($dayhref, $day, array('id' => $popupid));
     403            $cell = html_writer::link($dayhref, $day);
    402404        } else {
    403405            $cell = $day;
     
    433435        }
    434436
    435         // Special visual fx for today
    436         //Accessibility: hidden text for today, and popup.
    437         if($display->thismonth && $day == $d) {
     437        if ($display->thismonth && $day == $d) {
     438            // The current cell is for today - add appropriate classes and additional information for styling.
    438439            $class .= ' today';
    439440            $today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));
    440441
    441             if(! isset($eventsbyday[$day])) {
     442            if (!isset($eventsbyday[$day])) {
    442443                $class .= ' eventnone';
    443                 $popupid = calendar_get_popup(true, false);
    444                 $cell = html_writer::link('#', $day, array('id' => $popupid));
    445             }
    446             $cell = get_accesshide($today.' ').$cell;
     444                $popupdata = calendar_get_popup(true, false);
     445                $cellattributes = array_merge($cellattributes, $popupdata);
     446                $cell = html_writer::link('#', $day);
     447            }
     448            $cell = get_accesshide($today . ' ') . $cell;
    447449        }
    448450
    449451        // Just display it
    450         if(!empty($class)) {
    451             $class = ' class="'.$class.'"';
    452         }
    453         $content .= '<td'.$class.'>'.$cell."</td>\n";
     452        $cellattributes['class'] = $class;
     453        $content .= html_writer::tag('td', $cell, $cellattributes);
    454454    }
    455455
     
    462462    $content .= '</table>'; // Tabular display of days ends
    463463
     464    static $jsincluded = false;
     465    if (!$jsincluded) {
     466        $PAGE->requires->yui_module('moodle-calendar-info', 'Y.M.core_calendar.info.init');
     467        $jsincluded = true;
     468    }
    464469    return $content;
    465470}
     
    476481 * @return string eventid for the calendar_tooltip popup window/layout.
    477482 */
    478 function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
     483function calendar_get_popup($today = false, $timestart, $popupcontent = '') {
    479484    global $PAGE;
    480     static $popupcount;
    481     if ($popupcount === null) {
    482         $popupcount = 1;
    483     }
     485
    484486    $popupcaption = '';
    485     if($is_today) {
    486         $popupcaption = get_string('today', 'calendar').' ';
    487     }
    488     if (false === $event_timestart) {
     487    if ($today) {
     488        $popupcaption = get_string('today', 'calendar') . ' ';
     489    }
     490
     491    if (false === $timestart) {
    489492        $popupcaption .= userdate(time(), get_string('strftimedayshort'));
    490493        $popupcontent = get_string('eventnone', 'calendar');
    491494
    492495    } else {
    493         $popupcaption .= get_string('eventsfor', 'calendar', userdate($event_timestart, get_string('strftimedayshort')));
    494     }
    495     $id = 'calendar_tooltip_'.$popupcount;
    496     $PAGE->requires->yui_module('moodle-calendar-eventmanager', 'M.core_calendar.add_event', array(array('eventId'=>$id,'title'=>$popupcaption, 'content'=>$popupcontent)));
    497 
    498     $popupcount++;
    499     return $id;
     496        $popupcaption .= get_string('eventsfor', 'calendar', userdate($timestart, get_string('strftimedayshort')));
     497    }
     498
     499    return array(
     500        'data-core_calendar-title' => $popupcaption,
     501        'data-core_calendar-popupcontent' => $popupcontent,
     502    );
    500503}
    501504
     
    657660        $event->cssclass = 'calendar_event_course';
    658661    } else if ($event->groupid) {                                    // Group event
    659         $event->icon = '<img src="'.$OUTPUT->pix_url('i/groupevent') . '" alt="'.get_string('groupevent', 'calendar').'" class="icon" />';
    660         $event->courselink = calendar_get_courselink($event->courseid);
     662        if ($group = calendar_get_group_cached($event->groupid)) {
     663            $groupname = format_string($group->name, true, context_course::instance($group->courseid));
     664        } else {
     665            $groupname = '';
     666        }
     667        $event->icon = html_writer::empty_tag('image', array('src' => $OUTPUT->pix_url('i/groupevent'),
     668            'alt' => get_string('groupevent', 'calendar'), 'title' => $groupname, 'class' => 'icon'));
     669        $event->courselink = calendar_get_courselink($event->courseid) . ', ' . $groupname;
    661670        $event->cssclass = 'calendar_event_group';
    662671    } else if($event->userid) {                                      // User event
     
    685694    $whereclause = '';
    686695    $params = array();
    687     // Quick test
    688     if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
     696    // Quick test.
     697    if (empty($users) && empty($groups) && empty($courses)) {
    689698        return array();
    690699    }
     
    9921001    }
    9931002    $content = html_writer::start_tag('li', array('class' => 'calendar_event'));
    994     $content .= html_writer::start_tag('a', array('href' => $url));
     1003    $content .= html_writer::start_tag('a', array('href' => $url, 'rel' => 'nofollow'));
    9951004    $content .= html_writer::tag('span', $icon, array('class' => $class));
    9961005    $content .= html_writer::tag('span', $str, array('class' => 'eventname'));
     
    14111420    }
    14121421    return $coursecache[$courseid];
     1422}
     1423
     1424/**
     1425 * Get group from groupid for calendar display
     1426 *
     1427 * @param int $groupid
     1428 * @return stdClass group object with fields 'id', 'name' and 'courseid'
     1429 */
     1430function calendar_get_group_cached($groupid) {
     1431    static $groupscache = array();
     1432    if (!isset($groupscache[$groupid])) {
     1433        $groupscache[$groupid] = groups_get_group($groupid, 'id,name,courseid');
     1434    }
     1435    return $groupscache[$groupid];
    14131436}
    14141437
     
    18921915
    18931916/**
    1894  * Convert region timezone to php supported timezone
    1895  *
    1896  * @param string $tz value from ical file
    1897  * @return string $tz php supported timezone
    1898  */
    1899 function calendar_normalize_tz($tz) {
    1900     switch ($tz) {
    1901         case('CST'):
    1902         case('Central Time'):
    1903         case('Central Standard Time'):
    1904             $tz = 'America/Chicago';
    1905             break;
    1906         case('CET'):
    1907         case('Central European Time'):
    1908             $tz = 'Europe/Berlin';
    1909             break;
    1910         case('EST'):
    1911         case('Eastern Time'):
    1912         case('Eastern Standard Time'):
    1913             $tz = 'America/New_York';
    1914             break;
    1915         case('PST'):
    1916         case('Pacific Time'):
    1917         case('Pacific Standard Time'):
    1918             $tz = 'America/Los_Angeles';
    1919             break;
    1920         case('China Time'):
    1921         case('China Standard Time'):
    1922             $tz = 'Asia/Beijing';
    1923             break;
    1924         case('IST'):
    1925         case('India Time'):
    1926         case('India Standard Time'):
    1927             $tz = 'Asia/New_Delhi';
    1928             break;
    1929         case('JST');
    1930         case('Japan Time'):
    1931         case('Japan Standard Time'):
    1932             $tz = 'Asia/Tokyo';
    1933             break;
    1934     }
    1935     return $tz;
    1936 }
    1937 
    1938 /**
    19391917 * Manage calendar events
    19401918 *
     
    21972175     * insert it into the database and deal with any associated files
    21982176     *
    2199      * @see add_event()
    2200      * @see update_event()
     2177     * @see self::create()
     2178     * @see self::update()
    22012179     *
    22022180     * @param stdClass $data object of event
     
    23042282                unset($eventcopy->id);
    23052283
     2284                $timestart = new DateTime('@' . $eventcopy->timestart);
     2285                $timestart->setTimezone(core_date::get_user_timezone_object());
     2286
    23062287                for($i = 1; $i < $eventcopy->repeats; $i++) {
    23072288
    2308                     $eventcopy->timestart = ($eventcopy->timestart+WEEKSECS) + dst_offset_on($eventcopy->timestart) - dst_offset_on($eventcopy->timestart+WEEKSECS);
     2289                    $timestart->add(new DateInterval('P7D'));
     2290                    $eventcopy->timestart = $timestart->getTimestamp();
    23092291
    23102292                    // Get the event id for the log record.
     
    24102392     * and cleans up any files associated with the events.
    24112393     *
    2412      * @see delete_event()
     2394     * @see self::delete()
    24132395     *
    24142396     * @param bool $deleterepeated  delete event repeatedly
     
    29422924    $name = str_replace('\n', '<br />', $name);
    29432925    $name = str_replace('\\', '', $name);
    2944     $name = preg_replace('/\s+/', ' ', $name);
     2926    $name = preg_replace('/\s+/u', ' ', $name);
    29452927
    29462928    $eventrecord = new stdClass;
     
    29512933    } else {
    29522934        $description = $event->properties['DESCRIPTION'][0]->value;
     2935        $description = clean_param($description, PARAM_NOTAGS);
    29532936        $description = str_replace('\n', '<br />', $description);
    29542937        $description = str_replace('\\', '', $description);
    2955         $description = preg_replace('/\s+/', ' ', $description);
    2956     }
    2957     $eventrecord->description = clean_param($description, PARAM_NOTAGS);
     2938        $description = preg_replace('/\s+/u', ' ', $description);
     2939    }
     2940    $eventrecord->description = $description;
    29582941
    29592942    // Probably a repeating event with RRULE etc. TODO: skip for now.
     
    29622945    }
    29632946
    2964     $defaulttz = date_default_timezone_get();
    29652947    $tz = isset($event->properties['DTSTART'][0]->parameters['TZID']) ? $event->properties['DTSTART'][0]->parameters['TZID'] :
    29662948            $timezone;
    2967     $tz = calendar_normalize_tz($tz);
     2949    $tz = core_date::normalise_timezone($tz);
    29682950    $eventrecord->timestart = strtotime($event->properties['DTSTART'][0]->value . ' ' . $tz);
    29692951    if (empty($event->properties['DTEND'])) {
     
    29722954        $endtz = isset($event->properties['DTEND'][0]->parameters['TZID']) ? $event->properties['DTEND'][0]->parameters['TZID'] :
    29732955                $timezone;
     2956        $endtz = core_date::normalise_timezone($endtz);
    29742957        $eventrecord->timeduration = strtotime($event->properties['DTEND'][0]->value . ' ' . $endtz) - $eventrecord->timestart;
    29752958    }
     
    29832966            $eventrecord->timeduration = 0;
    29842967        }
    2985         date_default_timezone_set($defaulttz);
     2968        core_date::set_default_server_timezone();
    29862969    }
    29872970
     
    30112994            $rrule->parse_rrule();
    30122995            $rrule->create_events($createdevent);
    3013             date_default_timezone_set($defaulttz); // Change time zone back to what it was.
     2996            core_date::set_default_server_timezone(); // Change time zone back to what it was.
    30142997        }
    30152998        return $return;
  • moodle/trunk/fuentes/calendar/renderer.php

    r136 r1331  
    3434
    3535    /**
    36      * Creates a basic export form
    37      *
    38      * @param bool $allowthisweek
    39      * @param bool $allownextweek
    40      * @param bool $allownextmonth
    41      * @param int $userid
    42      * @param string $authtoken
    43      * @return string
    44      */
    45     public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $userid, $authtoken) {
    46         global $CFG;
    47 
    48         $output  = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
    49         $output .= html_writer::start_tag('fieldset');
    50         $output .= html_writer::tag('legend', get_string('commontasks', 'calendar'));
    51         $output .= html_writer::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
    52 
    53         $output .= html_writer::tag('div', get_string('iwanttoexport', 'calendar'));
    54 
    55         $output .= html_writer::start_tag('div', array('class'=>'indent'));
    56         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
    57         $output .= html_writer::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
    58         $output .= html_writer::empty_tag('br');
    59         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
    60         $output .= html_writer::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
    61         $output .= html_writer::empty_tag('br');
    62         $output .= html_writer::end_tag('div');
    63 
    64         $output .= html_writer::tag('div', get_string('for', 'calendar').':');
    65 
    66         $output .= html_writer::start_tag('div', array('class'=>'indent'));
    67         if ($allowthisweek) {
    68             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
    69             $output .= html_writer::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
    70             $output .= html_writer::empty_tag('br');
    71         }
    72         if ($allownextweek) {
    73             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
    74             $output .= html_writer::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
    75             $output .= html_writer::empty_tag('br');
    76         }
    77         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
    78         $output .= html_writer::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
    79         $output .= html_writer::empty_tag('br');
    80         if ($allownextmonth) {
    81             $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
    82             $output .= html_writer::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
    83             $output .= html_writer::empty_tag('br');
    84         }
    85         $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
    86         $output .= html_writer::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
    87         $output .= html_writer::empty_tag('br');
    88 
    89         if ($CFG->calendar_customexport) {
    90             $a = new stdClass();
    91             $now = time();
    92             $time = $now - $CFG->calendar_exportlookback * DAYSECS;
    93             $a->timestart = userdate($time, get_string('strftimedatefullshort', 'langconfig'));
    94             $time = $now + $CFG->calendar_exportlookahead * DAYSECS;
    95             $a->timeend = userdate($time, get_string('strftimedatefullshort', 'langconfig'));
    96             $output .= html_writer::empty_tag('input', array('type' => 'radio', 'name' => 'preset_time', 'id' => 'pt_custom', 'value' => 'custom'));
    97             $output .= html_writer::tag('label', get_string('customexport', 'calendar', $a), array('for' => 'pt_custom'));
    98             $output .= html_writer::empty_tag('br');
    99         }
    100 
    101         $output .= html_writer::end_tag('div');
    102         $output .= html_writer::start_tag('div', array('class'=>'rightalign'));
    103         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
    104         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
    105         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
    106         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'userid', 'value'=>$userid));
    107         $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
    108 
    109         $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name' => 'generateurl', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
    110         $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
    111 
    112         $output .= html_writer::end_tag('div');
    113 
    114         $output .= html_writer::end_tag('form');
    115         $output .= html_writer::end_tag('fieldset');
    116 
    117         $output .= html_writer::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
    118         $output .= html_writer::tag('p', get_string('urlforical', 'calendar'));
    119         $output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
    120         $output .= html_writer::end_tag('div');
    121 
    122         return $output;
    123     }
    124 
    125     /**
    12636     * Starts the standard layout for the page
    12737     *
     
    267177        if (empty($events)) {
    268178            // There is nothing to display today.
    269             $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3);
     179            $output .= html_writer::span(get_string('daywithnoevents', 'calendar'), 'calendar-information calendar-no-results');
    270180        } else {
    271181            $output .= html_writer::start_tag('div', array('class' => 'eventlist'));
     
    285195            // Then, show a list of all events that just span this day
    286196            if (!empty($underway)) {
    287                 $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3);
     197                $output .= html_writer::span(get_string('spanningevents', 'calendar'),
     198                    'calendar-information calendar-span-multiple-days');
    288199                foreach ($underway as $event) {
    289200                    $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
     
    627538            $output .= html_writer::end_tag('div');
    628539        } else {
    629             $output .= $this->output->heading(get_string('noupcomingevents', 'calendar'));
     540            $output .= html_writer::span(get_string('noupcomingevents', 'calendar'), 'calendar-information calendar-no-results');
    630541        }
    631542
     
    702613        if (empty($subscriptions)) {
    703614            $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
    704             $cell->colspan = 4;
     615            $cell->colspan = 5;
    705616            $table->data[] = new html_table_row(array($cell));
    706617        }
  • moodle/trunk/fuentes/calendar/set.php

    r136 r1331  
    4242require_once($CFG->dirroot.'/calendar/lib.php');
    4343
    44 require_sesskey();
    45 
    4644$var = required_param('var', PARAM_ALPHA);
    4745$return = clean_param(base64_decode(required_param('return', PARAM_RAW)), PARAM_LOCALURL);
     
    5250    $return = new moodle_url($return);
    5351}
     52
     53if (!confirm_sesskey()) {
     54    // Do not call require_sesskey() since this page may be accessed without session (for example by bots).
     55    redirect($return);
     56}
     57
    5458$url = new moodle_url('/calendar/set.php', array('return'=>base64_encode($return->out_as_local_url(false)), 'course' => $courseid, 'var'=>$var, 'sesskey'=>sesskey()));
    5559$PAGE->set_url($url);
  • moodle/trunk/fuentes/calendar/tests/behat/behat_calendar.php

    r136 r1331  
    4141
    4242    /**
    43      * Create event.
     43     * Create event when starting on the front page.
    4444     *
    4545     * @Given /^I create a calendar event with form data:$/
     
    5454        return array(
    5555            new Given('I follow "' . get_string('monththis', 'calendar') . '"'),
     56            new Given('I create a calendar event:', $data),
     57        );
     58    }
     59
     60    /**
     61     * Create event.
     62     *
     63     * @Given /^I create a calendar event:$/
     64     * @param TableNode $data
     65     * @return array the list of actions to perform
     66     */
     67    public function i_create_a_calendar_event($data) {
     68        // Get the event name.
     69        $eventname = $data->getRow(1);
     70        $eventname = $eventname[1];
     71
     72        return array(
    5673            new Given('I click on "' . get_string('newevent', 'calendar') .'" "button"'),
    5774            new Given('I set the following fields to these values:', $data),
     
    6077        );
    6178    }
     79
     80    /**
     81     * Hover over a specific day in the calendar.
     82     *
     83     * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the calendar$/
     84     * @param int $day The day of the current month
     85     * @return Given[]
     86     */
     87    public function i_hover_over_day_of_this_month_in_calendar($day) {
     88        $summarytitle = get_string('calendarheading', 'calendar', userdate(time(), get_string('strftimemonthyear')));
     89        // The current month table.
     90        $currentmonth = "table[contains(concat(' ', normalize-space(@summary), ' '), ' {$summarytitle} ')]";
     91
     92        // Strings for the class cell match.
     93        $cellclasses  = "contains(concat(' ', normalize-space(@class), ' '), ' day ')";
     94        $daycontains  = "text()[contains(concat(' ', normalize-space(.), ' '), ' {$day} ')]";
     95        $daycell      = "td[{$cellclasses}]";
     96        $dayofmonth   = "a[{$daycontains}]";
     97        return array(
     98            new Given('I hover "//' . $currentmonth . '/descendant::' . $daycell . '/' . $dayofmonth . '" "xpath_element"'),
     99        );
     100    }
     101
     102    /**
     103     * Hover over today in the calendar.
     104     *
     105     * @Given /^I hover over today in the calendar$/
     106     * @return Given[]
     107     */
     108    public function i_hover_over_today_in_the_calendar() {
     109        // For window's compatibility, using %d and not %e.
     110        $todaysday = trim(strftime('%d'));
     111        $todaysday = ltrim($todaysday, '0');
     112        return $this->i_hover_over_day_of_this_month_in_calendar($todaysday);
     113    }
    62114}
  • moodle/trunk/fuentes/calendar/tests/behat/calendar.feature

    r136 r1331  
    88    Given the following "users" exist:
    99      | username | firstname | lastname | email |
    10       | student1 | Student | 1 | student1@asd.com |
    11       | student2 | Student | 2 | student2@asd.com |
     10      | student1 | Student | 1 | student1@example.com |
     11      | student2 | Student | 2 | student2@example.com |
     12      | student3 | Student | 3 | student3@example.com |
    1213    And the following "courses" exist:
    1314      | fullname | shortname | format |
     
    1617      | user | course | role |
    1718      | student1 | C1 | student |
     19      | student3 | C1 | student |
     20    And the following "groups" exist:
     21      | name | course | idnumber |
     22      | Group 1 | C1 | G1 |
     23    And the following "group members" exist:
     24      | user | group |
     25      | student1 | G1 |
    1826    When I log in as "admin"
     27    And I am on site homepage
    1928    And I follow "Course 1"
    2029    And I turn editing mode on
     
    2837    And I log out
    2938    And I log in as "student1"
     39    And I am on site homepage
    3040    And I follow "Course 1"
    3141    And I follow "This month"
     
    4353    And I log out
    4454    And I log in as "student1"
     55    And I am on site homepage
    4556    And I follow "Course 1"
    4657    And I follow "This month"
     
    4859    And I log out
    4960    And I log in as "student2"
     61    And I follow "This month"
     62    And I should not see "Really awesome event!"
     63
     64  Scenario: Create a group event
     65    And I create a calendar event with form data:
     66      | Type of event | group |
     67      | Group | Group 1 |
     68      | Event title | Really awesome event! |
     69      | Description | Come join this awesome event |
     70    And I log out
     71    And I log in as "student1"
     72    And I am on site homepage
     73    And I follow "Course 1"
     74    And I follow "This month"
     75    And I follow "Really awesome event!"
     76    And "Group 1" "text" should exist in the ".eventlist" "css_element"
     77    And I log out
     78    And I log in as "student3"
    5079    And I follow "This month"
    5180    And I should not see "Really awesome event!"
     
    5887    And I log out
    5988    And I log in as "student1"
     89    And I am on site homepage
    6090    And I follow "Course 1"
    6191    And I follow "This month"
  • moodle/trunk/fuentes/calendar/tests/calendartype_test.php

    r136 r1331  
    103103     */
    104104    public function test_calendar_type_dateselector_elements() {
     105        global $CFG;
     106
    105107        // We want to reset the test data after this run.
    106108        $this->resetAfterTest();
     109
     110        $this->setTimezone('UTC');
     111
     112        // Note: this test is pretty useless because it does not test current user timezones.
    107113
    108114        // Check converting dates to Gregorian when submitting a date selector element works. Note: the test
  • moodle/trunk/fuentes/calendar/tests/externallib_test.php

    r136 r1331  
    293293
    294294        // Check to see if we got all events.
    295         $this->assertEquals(4, count($events['events']));
     295        $this->assertEquals(5, count($events['events']));
    296296        $this->assertEquals(0, count($events['warnings']));
    297297        $options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + 7*WEEKSECS);
     
    315315        $this->assertEquals(1, count($events['warnings'])); // group.
    316316
    317         $options = array ('siteevents' => true, 'userevents' => true);
     317        $options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + HOURSECS);
    318318        $events = core_calendar_external::get_calendar_events($paramevents, $options);
    319319        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     
    329329        $paramevents = array ('courseids' => array($course->id), 'groupids' => array($group->id));
    330330        $events = core_calendar_external::get_calendar_events($paramevents, $options);
     331        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
    331332        $this->assertEquals(4, count($events['events'])); // site, user, group, one course event.
    332333        $this->assertEquals(0, count($events['warnings']));
     
    363364        $this->assertEquals(1, count($events['events'])); // site.
    364365        $this->assertEquals(0, count($events['warnings']));
     366
     367        // Try getting a course event by its id.
     368        $paramevents = array ('eventids' => array($courseevent->id));
     369        $events = core_calendar_external::get_calendar_events($paramevents, $options);
     370        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     371        $this->assertEquals(1, count($events['events']));
     372        $this->assertEquals(0, count($events['warnings']));
     373
     374        // Now, create an activity event.
     375        $this->setAdminUser();
     376        $nexttime = time() + DAYSECS;
     377        $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id, 'duedate' => $nexttime));
     378
     379        $this->setUser($user);
     380        $paramevents = array ('courseids' => array($course->id));
     381        $options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + WEEKSECS);
     382        $events = core_calendar_external::get_calendar_events($paramevents, $options);
     383        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     384
     385        $this->assertCount(5, $events['events']);
     386
     387        // Hide the assignment.
     388        set_coursemodule_visible($assign->cmid, 0);
     389        // Empty all the caches that may be affected  by this change.
     390        accesslib_clear_all_caches_for_unit_testing();
     391        course_modinfo::clear_instance_cache();
     392
     393        $events = core_calendar_external::get_calendar_events($paramevents, $options);
     394        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     395        // Expect one less.
     396        $this->assertCount(4, $events['events']);
    365397    }
    366398
     
    391423                );
    392424        $eventsret = core_calendar_external::create_calendar_events($events);
     425        $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
    393426
    394427        // Check to see if things were created properly.
  • moodle/trunk/fuentes/calendar/tests/lib_test.php

    r136 r1331  
    7979        require_once($CFG->dirroot . '/lib/cronlib.php');
    8080
    81         // Moodle ICal URL (moodle.org events).
    82         $presetwhat = 'all';
    83         $presettime = 'recentupcoming';
    84         $userid = 1;
    85         $authtoken = 'a8bcfee2fb868a05357f650bd65dc0699b026524';
    86         $subscriptionurl = 'https://moodle.org/calendar/export_execute.php'
    87                 . '?preset_what='.$presetwhat.'&preset_time='.$presettime.'&userid='.$userid.'&authtoken='.$authtoken;
     81        // ICal URL from external test repo.
     82        $subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
    8883
    8984        $subscription = new stdClass();
  • moodle/trunk/fuentes/calendar/tests/rrule_manager_tests.php

    r136 r1331  
    2828    protected $event;
    2929
    30     /** @var string system timezone */
    31     protected $tz;
    32 
    3330    /**
    3431     * Set up method.
    3532     */
    3633    protected function setUp() {
    37         global $DB;
     34        global $DB, $CFG;
    3835        $this->resetAfterTest();
    39         $this->tz = date_default_timezone_get();
    40         date_default_timezone_set('Australia/Perth');
     36
     37        $this->setTimezone('Australia/Perth');
    4138
    4239        $user = $this->getDataGenerator()->create_user();
     
    6764
    6865    /**
    69      * Tear down method.
    70      */
    71     protected function tearDown() {
    72         date_default_timezone_set($this->tz);
    73     }
    74 
    75     /**
    7666     * Test parse_rrule() method.
    7767     */
  • moodle/trunk/fuentes/calendar/type/gregorian/classes/structure.php

    r136 r1331  
    6969        $months = array();
    7070
     71        $date = new \DateTime('@1263556800');
     72        $date->setTimezone(new \DateTimeZone('UTC'));
    7173        for ($i = 1; $i <= 12; $i++) {
    72             $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
     74            $date->setDate(2000, $i, 15);
     75            $months[$i] = userdate($date->getTimestamp(), '%B', 'UTC');
    7376        }
    7477
     
    321324        }
    322325
    323         // Add daylight saving offset for string timezones only, as we can't get dst for
    324         // float values. if timezone is 99 (user default timezone), then try update dst.
    325         if ((99 == $timezone) || !is_numeric($timezone)) {
    326             $time += dst_offset_on($time, $timezone);
    327         }
    328 
    329         $timezone = get_user_timezone_offset($timezone);
    330 
    331         // If we are running under Windows convert to windows encoding and then back to UTF-8
    332         // (because it's impossible to specify UTF-8 to fetch locale info in Win32).
    333         if (abs($timezone) > 13) { // Server time.
    334             $datestring = date_format_string($time, $format, $timezone);
    335             if ($fixday) {
    336                 $daystring  = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time)));
    337                 $datestring = str_replace('DD', $daystring, $datestring);
    338             }
    339             if ($fixhour) {
    340                 $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time)));
    341                 $datestring = str_replace('HH', $hourstring, $datestring);
    342             }
    343         } else {
    344             $time += (int)($timezone * 3600);
    345             $datestring = date_format_string($time, $format, $timezone);
    346             if ($fixday) {
    347                 $daystring  = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $time)));
    348                 $datestring = str_replace('DD', $daystring, $datestring);
    349             }
    350             if ($fixhour) {
    351                 $hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $time)));
    352                 $datestring = str_replace('HH', $hourstring, $datestring);
    353             }
    354         }
     326        $time = (int)$time; // Moodle allows rubbish in input...
     327        $datestring = date_format_string($time, $format, $timezone);
     328
     329        date_default_timezone_set(\core_date::get_user_timezone($timezone));
     330
     331        if ($fixday) {
     332            $daystring  = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time)));
     333            $datestring = str_replace('DD', $daystring, $datestring);
     334        }
     335        if ($fixhour) {
     336            $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time)));
     337            $datestring = str_replace('HH', $hourstring, $datestring);
     338        }
     339
     340        \core_date::set_default_server_timezone();
    355341
    356342        return $datestring;
  • moodle/trunk/fuentes/calendar/type/gregorian/version.php

    r136 r1331  
    2525defined('MOODLE_INTERNAL') || die();
    2626
    27 $plugin->version   = 2014111000; // The current plugin version (Date: YYYYMMDDXX).
    28 $plugin->requires  = 2014110400; // Requires this Moodle version.
     27$plugin->version   = 2015111600; // The current plugin version (Date: YYYYMMDDXX).
     28$plugin->requires  = 2015111000; // Requires this Moodle version.
    2929$plugin->component = 'calendartype_gregorian'; // Full name of the plugin (used for diagnostics).
  • moodle/trunk/fuentes/calendar/upgrade.txt

    r136 r1331  
    11This files describes API changes in /calendar/* ,
    22information provided here is intended especially for developers.
     3
     4=== 2.9 ===
     5default values changes in code:
     6* core_calendar_external::get_calendar_events_parameters() 'timeend' default option changed; now, by default,
     7  all events are returned, not only the past ones.
     8* calendar types need to be updated to be compatible with standard PHP date/time code
    39
    410=== 2.5 ===
  • moodle/trunk/fuentes/calendar/view.php

    r136 r1331  
    6969        $time = make_timestamp($year, $mon, $day);
    7070    } else {
    71         $time = time();
     71        $time = usergetmidnight(time());
    7272    }
    7373} else if (empty($time)) {
    74     $time = time();
     74    $time = usergetmidnight(time());
    7575}
    7676
     
    125125echo $renderer->start_layout();
    126126echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
     127echo $OUTPUT->heading(get_string('calendar', 'calendar'));
    127128
    128129switch($view) {
Note: See TracChangeset for help on using the changeset viewer.