/** * Initalize javascript for date type form element * * @staticvar bool $done make sure it gets initalize once. * @global moodle_page $PAGE */ function form_init_date_js() { global $PAGE; static $done = false; if (!$done) { $calendar = \core_calendar\type_factory::get_calendar_instance(); $module = 'moodle-form-dateselector'; $function = 'M.form.dateselector.init_date_selectors'; $config = array(array('firstdayofweek' => $calendar->get_starting_weekday(), 'mon' => date_format_string(strtotime("Monday"), '%a', 99), 'tue' => date_format_string(strtotime("Tuesday"), '%a', 99), 'wed' => date_format_string(strtotime("Wednesday"), '%a', 99), 'thu' => date_format_string(strtotime("Thursday"), '%a', 99), 'fri' => date_format_string(strtotime("Friday"), '%a', 99), 'sat' => date_format_string(strtotime("Saturday"), '%a', 99), 'sun' => date_format_string(strtotime("Sunday"), '%a', 99), 'january' => date_format_string(strtotime("January 1"), '%B', 99), 'february' => date_format_string(strtotime("February 1"), '%B', 99), 'march' => date_format_string(strtotime("March 1"), '%B', 99), 'april' => date_format_string(strtotime("April 1"), '%B', 99), 'may' => date_format_string(strtotime("May 1"), '%B', 99), 'june' => date_format_string(strtotime("June 1"), '%B', 99), 'july' => date_format_string(strtotime("July 1"), '%B', 99), 'august' => date_format_string(strtotime("August 1"), '%B', 99), 'september' => date_format_string(strtotime("September 1"), '%B', 99), 'october' => date_format_string(strtotime("October 1"), '%B', 99), 'november' => date_format_string(strtotime("November 1"), '%B', 99), 'december' => date_format_string(strtotime("December 1"), '%B', 99))); $PAGE->requires->yui_module($module, $function, $config); $done = true; } }
/** * Handles editing datetime fields. * * @param moodleform $mform */ public function edit_field_add($mform) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Check if the field is required. if ($this->field->required) { $optional = false; } else { $optional = true; } // Convert the year stored in the DB as gregorian to that used by the calendar type. $startdate = $calendartype->convert_from_gregorian($this->field->param1, 1, 1); $stopdate = $calendartype->convert_from_gregorian($this->field->param2, 1, 1); $attributes = array('startyear' => $startdate['year'], 'stopyear' => $stopdate['year'], 'optional' => $optional); // Check if they wanted to include time as well. if (!empty($this->field->param3)) { $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes); } else { $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes); } $mform->setType($this->inputname, PARAM_INT); $mform->setDefault($this->inputname, time()); }
/** * Powerful function that is used by edit and editadvanced to add common form elements/rules/etc. * * @param moodleform $mform * @param array $editoroptions * @param array $filemanageroptions * @param stdClass $user */ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions, $user) { global $CFG, $USER, $DB; if ($user->id > 0) { useredit_load_preferences($user, false); } $strrequired = get_string('required'); // Add the necessary names. foreach (useredit_get_required_name_fields() as $fullname) { $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"'); $mform->addRule($fullname, $strrequired, 'required', null, 'client'); $mform->setType($fullname, PARAM_NOTAGS); } $enabledusernamefields = useredit_get_enabled_name_fields(); // Add the enabled additional name fields. foreach ($enabledusernamefields as $addname) { $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"'); $mform->setType($addname, PARAM_NOTAGS); } // Do not show email field if change confirmation is pending. if ($user->id > 0 and !empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) { $notice = get_string('emailchangepending', 'auth', $user); $notice .= '<br /><a href="edit.php?cancelemailchange=1&id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>'; $mform->addElement('static', 'emailpending', get_string('email'), $notice); } else { $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); $mform->addRule('email', $strrequired, 'required', null, 'client'); $mform->setType('email', PARAM_RAW_TRIMMED); } $choices = array(); $choices['0'] = get_string('emaildisplayno'); $choices['1'] = get_string('emaildisplayyes'); $choices['2'] = get_string('emaildisplaycourse'); $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); $mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay); $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"'); $mform->setType('city', PARAM_TEXT); if (!empty($CFG->defaultcity)) { $mform->setDefault('city', $CFG->defaultcity); } $choices = get_string_manager()->get_list_of_countries(); $choices = array('' => get_string('selectacountry') . '...') + $choices; $mform->addElement('select', 'country', get_string('selectacountry'), $choices); if (!empty($CFG->country)) { $mform->setDefault('country', $CFG->country); } if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) { $choices = core_date::get_list_of_timezones($CFG->forcetimezone); $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); $mform->addElement('hidden', 'timezone'); $mform->setType('timezone', PARAM_TIMEZONE); } else { $choices = core_date::get_list_of_timezones($user->timezone, true); $mform->addElement('select', 'timezone', get_string('timezone'), $choices); } // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes); $mform->setDefault('calendartype', $CFG->calendartype); } if (!empty($CFG->allowuserthemes)) { $choices = array(); $choices[''] = get_string('default'); $themes = get_list_of_themes(); foreach ($themes as $key => $theme) { if (empty($theme->hidefromselector)) { $choices[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); } $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions); $mform->setType('description_editor', PARAM_CLEANHTML); $mform->addHelpButton('description_editor', 'userdescription'); if (empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_picture', get_string('pictureofuser')); if (!empty($CFG->enablegravatar)) { $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled'))); } $mform->addElement('static', 'currentpicture', get_string('currentpicture')); $mform->addElement('checkbox', 'deletepicture', get_string('delete')); $mform->setDefault('deletepicture', 0); $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions); $mform->addHelpButton('imagefile', 'newpicture'); $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); $mform->setType('imagealt', PARAM_TEXT); } // Display user name fields that are not currenlty enabled here if there are any. $disabledusernamefields = useredit_get_disabled_name_fields($enabledusernamefields); if (count($disabledusernamefields) > 0) { $mform->addElement('header', 'moodle_additional_names', get_string('additionalnames')); foreach ($disabledusernamefields as $allname) { $mform->addElement('text', $allname, get_string($allname), 'maxlength="100" size="30"'); $mform->setType($allname, PARAM_NOTAGS); } } if (!empty($CFG->usetags) and empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_interests', get_string('interests')); $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial')); $mform->addHelpButton('interests', 'interestslist'); } // Moodle optional fields. $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); $mform->setType('url', PARAM_URL); $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); $mform->setType('icq', PARAM_NOTAGS); $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); $mform->setType('skype', PARAM_NOTAGS); $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); $mform->setType('aim', PARAM_NOTAGS); $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); $mform->setType('yahoo', PARAM_NOTAGS); $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); $mform->setType('msn', PARAM_NOTAGS); $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"'); $mform->setType('idnumber', PARAM_NOTAGS); $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"'); $mform->setType('institution', PARAM_TEXT); $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"'); $mform->setType('department', PARAM_TEXT); $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"'); $mform->setType('phone1', PARAM_NOTAGS); $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"'); $mform->setType('phone2', PARAM_NOTAGS); $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"'); $mform->setType('address', PARAM_TEXT); }
/** * Extend the form definition after the data has been parsed. */ public function definition_after_data() { global $CFG; $mform = $this->_form; // If calendar type does not exist, use site default calendar type. if ($calendarselected = $mform->getElementValue('calendartype')) { if (is_array($calendarselected)) { // There are multiple calendar types available. $calendar = reset($calendarselected); } else { // There is only one calendar type available. $calendar = $calendarselected; } // Check calendar type exists. if (!array_key_exists($calendar, \core_calendar\type_factory::get_list_of_calendar_types())) { $calendartypeel = $mform->getElement('calendartype'); $calendartypeel->setValue($CFG->calendartype); } } }
/** * */ protected function get_timestamp_from_value($value) { if (empty($value)) { return null; } $timestamp = null; // Timestamp or time string. if (!is_array($value)) { if ((string) (int) $value === (string) $value && $value <= PHP_INT_MAX && $value >= ~PHP_INT_MAX) { // It's a timestamp. $timestamp = $value; } else { if ($value = strtotime($value)) { // It's a valid time string. $timestamp = $value; } } } else { // Assuming any of year, month, day, hour, minute is passed. $enabled = 0; $year = 0; $month = 1; $day = 1; $hour = 0; $minute = 0; foreach ($value as $name => $val) { if (!empty($val)) { ${$name} = $val; } } if ($enabled and $year) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day, $hour, $minute); $timestamp = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']); } } return $timestamp; }
/** * Update a user with a user object (will compare against the ID) * * @param stdClass $user the user to update * @param bool $updatepassword if true, authentication plugin will update password. * @param bool $triggerevent set false if user_updated event should not be triggred. */ function user_update_user($user, $updatepassword = true, $triggerevent = true) { global $DB; // set the timecreate field to the current time if (!is_object($user)) { $user = (object) $user; } //check username if (isset($user->username)) { if ($user->username !== core_text::strtolower($user->username)) { throw new moodle_exception('usernamelowercase'); } else { if ($user->username !== clean_param($user->username, PARAM_USERNAME)) { throw new moodle_exception('invalidusername'); } } } // Unset password here, for updating later, if password update is required. if ($updatepassword && isset($user->password)) { //check password toward the password policy if (!check_password_policy($user->password, $errmsg)) { throw new moodle_exception($errmsg); } $passwd = $user->password; unset($user->password); } // Make sure calendartype, if set, is valid. if (!empty($user->calendartype)) { $availablecalendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // If it doesn't exist, then unset this value, we do not want to update the user's value. if (empty($availablecalendartypes[$user->calendartype])) { unset($user->calendartype); } } else { // Unset this variable, must be an empty string, which we do not want to update the calendartype to. unset($user->calendartype); } $user->timemodified = time(); $DB->update_record('user', $user); if ($updatepassword) { // Get full user record. $updateduser = $DB->get_record('user', array('id' => $user->id)); // if password was set, then update its hash if (isset($passwd)) { $authplugin = get_auth_plugin($updateduser->auth); if ($authplugin->can_change_password()) { $authplugin->user_update_password($updateduser, $passwd); } } } // Trigger event if required. if ($triggerevent) { \core\event\user_updated::create_from_userid($user->id)->trigger(); } }
/** * Get per-day basis events * * @param array $events list of events * @param int $month the number of the month * @param int $year the number of the year * @param array $eventsbyday event on specific day * @param array $durationbyday duration of the event in days * @param array $typesbyday event type (eg: global, course, user, or group) * @param array $courses list of courses * @return void */ function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$durationbyday, &$typesbyday, &$courses) { // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $eventsbyday = array(); $typesbyday = array(); $durationbyday = array(); if ($events === false) { return; } foreach ($events as $event) { $startdate = $calendartype->timestamp_to_date_array($event->timestart); // Set end date = start date if no duration if ($event->timeduration) { $enddate = $calendartype->timestamp_to_date_array($event->timestart + $event->timeduration - 1); } else { $enddate = $startdate; } // Simple arithmetic: $year * 13 + $month is a distinct integer for each distinct ($year, $month) pair if (!($startdate['year'] * 13 + $startdate['mon'] <= $year * 13 + $month) && $enddate['year'] * 13 + $enddate['mon'] >= $year * 13 + $month) { // Out of bounds continue; } $eventdaystart = intval($startdate['mday']); if ($startdate['mon'] == $month && $startdate['year'] == $year) { // Give the event to its day $eventsbyday[$eventdaystart][] = $event->id; // Mark the day as having such an event if ($event->courseid == SITEID && $event->groupid == 0) { $typesbyday[$eventdaystart]['startglobal'] = true; // Set event class for global event $events[$event->id]->class = 'calendar_event_global'; } else { if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { $typesbyday[$eventdaystart]['startcourse'] = true; // Set event class for course event $events[$event->id]->class = 'calendar_event_course'; } else { if ($event->groupid) { $typesbyday[$eventdaystart]['startgroup'] = true; // Set event class for group event $events[$event->id]->class = 'calendar_event_group'; } else { if ($event->userid) { $typesbyday[$eventdaystart]['startuser'] = true; // Set event class for user event $events[$event->id]->class = 'calendar_event_user'; } } } } } if ($event->timeduration == 0) { // Proceed with the next continue; } // The event starts on $month $year or before. So... $lowerbound = $startdate['mon'] == $month && $startdate['year'] == $year ? intval($startdate['mday']) : 0; // Also, it ends on $month $year or later... $upperbound = $enddate['mon'] == $month && $enddate['year'] == $year ? intval($enddate['mday']) : calendar_days_in_month($month, $year); // Mark all days between $lowerbound and $upperbound (inclusive) as duration for ($i = $lowerbound + 1; $i <= $upperbound; ++$i) { $durationbyday[$i][] = $event->id; if ($event->courseid == SITEID && $event->groupid == 0) { $typesbyday[$i]['durationglobal'] = true; } else { if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { $typesbyday[$i]['durationcourse'] = true; } else { if ($event->groupid) { $typesbyday[$i]['durationgroup'] = true; } else { if ($event->userid) { $typesbyday[$i]['durationuser'] = true; } } } } } } return; }
protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null) { global $CFG, $OUTPUT; require_once $CFG->libdir . '/formslib.php'; // Support internationalised calendars. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Get current date, but set time to 00:00 (to make it easier to // specify whole days) and change name of mday field to match below. $wrongfields = $calendartype->timestamp_to_date_array(time()); $current = array('day' => $wrongfields['mday'], 'month' => $wrongfields['mon'], 'year' => $wrongfields['year'], 'hour' => 0, 'minute' => 0); // Time part is handled the same everywhere. $hours = array(); for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } $minutes = array(); for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } // List date fields. $fields = $calendartype->get_date_order($calendartype->get_min_year(), $calendartype->get_max_year()); // Add time fields - in RTL mode these are switched. $fields['split'] = '/'; if (right_to_left()) { $fields['minute'] = $minutes; $fields['colon'] = ':'; $fields['hour'] = $hours; } else { $fields['hour'] = $hours; $fields['colon'] = ':'; $fields['minute'] = $minutes; } // Output all date fields. $html = '<span class="availability-group">'; foreach ($fields as $field => $options) { if ($options === '/') { $html = rtrim($html); // In Gregorian calendar mode only, we support a date selector popup, reusing // code from form to ensure consistency. if ($calendartype->get_name() === 'gregorian' && self::DATE_SELECTOR_SUPPORTED) { $image = $OUTPUT->pix_icon('i/calendar', get_string('calendar', 'calendar'), 'moodle'); $html .= ' ' . \html_writer::link('#', $image, array('name' => 'x[calendar]')); form_init_date_js(); } $html .= '</span> <span class="availability-group">'; continue; } if ($options === ':') { $html .= ': '; continue; } $html .= \html_writer::start_tag('label'); $html .= \html_writer::span(get_string($field) . ' ', 'accesshide'); // NOTE: The fields need to have these weird names in order that they // match the standard Moodle form control, otherwise the date selector // won't find them. $html .= \html_writer::start_tag('select', array('name' => 'x[' . $field . ']', 'class' => 'custom-select')); foreach ($options as $key => $value) { $params = array('value' => $key); if ($current[$field] == $key) { $params['selected'] = 'selected'; } $html .= \html_writer::tag('option', s($value), $params); } $html .= \html_writer::end_tag('select'); $html .= \html_writer::end_tag('label'); $html .= ' '; } $html = rtrim($html) . '</span>'; // Also get the time that corresponds to this default date. $time = self::get_time_from_fields($current['year'], $current['month'], $current['day'], $current['hour'], $current['minute']); return array($html, $time); }
$calendar->prepare_for_view($course, $courses); $pagetitle = get_string('export', 'calendar'); // Print title and header if ($issite) { $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id' => $course->id))); } $link = new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming', 'course' => $calendar->courseid)); $PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time)); $PAGE->navbar->add($pagetitle); $PAGE->set_title($course->shortname . ': ' . get_string('calendar', 'calendar') . ': ' . $pagetitle); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); $renderer = $PAGE->get_renderer('core_calendar'); $calendar->add_sidecalendar_blocks($renderer); // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $now = $calendartype->timestamp_to_date_array($time); $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } $numberofdaysinweek = $calendartype->get_num_weekdays(); $formdata = array('allownextweek' => $weekend & 1 << $now['wday'], 'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek, 'allowthisweek' => !($weekend & 1 << $now['wday'] && !($weekend & 1 << ($now['wday'] + 1) % $numberofdaysinweek))); $exportform = new core_calendar_export_form(null, $formdata); $calendarurl = ''; if ($data = $exportform->get_data()) { $password = $DB->get_record('user', array('id' => $USER->id), 'password'); $params = array(); $params['userid'] = $USER->id; $params['authtoken'] = sha1($USER->id . (isset($password->password) ? $password->password : '') . $CFG->calendar_exportsalt); $params['preset_what'] = $data->events['exportevents'];
/** * This is a shortcut for making an hour selector menu. * * @param string $type The type of selector (years, months, days, hours, minutes) * @param string $name fieldname * @param int $currenttime A default timestamp in GMT * @param int $step minute spacing * @param array $attributes - html select element attributes * @return HTML fragment */ public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) { if (!$currenttime) { $currenttime = time(); } $calendartype = \core_calendar\type_factory::get_calendar_instance(); $currentdate = $calendartype->timestamp_to_date_array($currenttime); $userdatetype = $type; $timeunits = array(); switch ($type) { case 'years': $timeunits = $calendartype->get_years(); $userdatetype = 'year'; break; case 'months': $timeunits = $calendartype->get_months(); $userdatetype = 'month'; $currentdate['month'] = (int) $currentdate['mon']; break; case 'days': $timeunits = $calendartype->get_days(); $userdatetype = 'mday'; break; case 'hours': for ($i = 0; $i <= 23; $i++) { $timeunits[$i] = sprintf("%02d", $i); } break; case 'minutes': if ($step != 1) { $currentdate['minutes'] = ceil($currentdate['minutes'] / $step) * $step; } for ($i = 0; $i <= 59; $i += $step) { $timeunits[$i] = sprintf("%02d", $i); } break; default: throw new coding_exception("Time type {$type} is not supported by html_writer::select_time()."); } if (empty($attributes['id'])) { $attributes['id'] = self::random_id('ts_'); } $timerselector = self::select($timeunits, $name, $currentdate[$userdatetype], null, $attributes); $label = self::tag('label', get_string(substr($type, 0, -1), 'form'), array('for' => $attributes['id'], 'class' => 'accesshide')); return $label . $timerselector; }
/** * This is a shortcut for making an hour selector menu. * * @param string $type The type of selector (years, months, days, hours, minutes) * @param string $name fieldname * @param int $currenttime A default timestamp in GMT * @param int $step minute spacing * @param array $attributes - html select element attributes * @return HTML fragment */ public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) { global $OUTPUT; if (!$currenttime) { $currenttime = time(); } $calendartype = \core_calendar\type_factory::get_calendar_instance(); $currentdate = $calendartype->timestamp_to_date_array($currenttime); $userdatetype = $type; $timeunits = array(); switch ($type) { case 'years': $timeunits = $calendartype->get_years(); $userdatetype = 'year'; break; case 'months': $timeunits = $calendartype->get_months(); $userdatetype = 'month'; $currentdate['month'] = (int)$currentdate['mon']; break; case 'days': $timeunits = $calendartype->get_days(); $userdatetype = 'mday'; break; case 'hours': for ($i=0; $i<=23; $i++) { $timeunits[$i] = sprintf("%02d",$i); } break; case 'minutes': if ($step != 1) { $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step; } for ($i=0; $i<=59; $i+=$step) { $timeunits[$i] = sprintf("%02d",$i); } break; default: throw new coding_exception("Time type $type is not supported by html_writer::select_time()."); } $attributes = (array) $attributes; $data = (object) [ 'name' => $name, 'id' => !empty($attributes['id']) ? $attributes['id'] : self::random_id('ts_'), 'label' => get_string(substr($type, 0, -1), 'form'), 'options' => array_map(function($value) use ($timeunits, $currentdate, $userdatetype) { return [ 'name' => $timeunits[$value], 'value' => $value, 'selected' => $currentdate[$userdatetype] == $value ]; }, array_keys($timeunits)), ]; unset($attributes['id']); unset($attributes['name']); $data->attributes = array_map(function($name) use ($attributes) { return [ 'name' => $name, 'value' => $attributes[$name] ]; }, array_keys($attributes)); return $OUTPUT->render_from_template('core/select_time', $data); }
$data->startwday = abs($data->startwday % 7); } set_user_preference('calendar_startwday', $data->startwday); // Calendar events. if (intval($data->maxevents) >= 1) { set_user_preference('calendar_maxevents', $data->maxevents); } // Calendar lookahead. if (intval($data->lookahead) >= 1) { set_user_preference('calendar_lookahead', $data->lookahead); } set_user_preference('calendar_persistflt', intval($data->persistflt)); // Calendar type. $calendartype = $data->calendartype; // If the specified calendar type does not exist, use the site default. if (!array_key_exists($calendartype, \core_calendar\type_factory::get_list_of_calendar_types())) { $calendartype = $CFG->calendartype; } $user->calendartype = $calendartype; // Update user with new calendar type. user_update_user($user, false, false); // Trigger event. \core\event\user_updated::create_from_userid($user->id)->trigger(); if ($USER->id == $user->id) { $USER->calendartype = $calendartype; } redirect($redirect); } } // Display page header. $streditmycalendar = get_string('calendarpreferences', 'calendar');
/** * Definition of user profile fields and the expected parameter type for data validation. * * array( * 'property_name' => array( // The user property to be checked. Should match the field on the user table. * 'null' => NULL_ALLOWED, // Defaults to NULL_NOT_ALLOWED. Takes NULL_NOT_ALLOWED or NULL_ALLOWED. * 'type' => PARAM_TYPE, // Expected parameter type of the user field. * 'choices' => array(1, 2..) // An array of accepted values of the user field. * 'default' => $CFG->setting // An default value for the field. * ) * ) * * The fields choices and default are optional. * * @return void */ protected static function fill_properties_cache() { global $CFG; if (self::$propertiescache !== null) { return; } // Array of user fields properties and expected parameters. // Every new field on the user table should be added here otherwise it won't be validated. $fields = array(); $fields['id'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['auth'] = array('type' => PARAM_AUTH, 'null' => NULL_NOT_ALLOWED); $fields['confirmed'] = array('type' => PARAM_BOOL, 'null' => NULL_NOT_ALLOWED); $fields['policyagreed'] = array('type' => PARAM_BOOL, 'null' => NULL_NOT_ALLOWED); $fields['deleted'] = array('type' => PARAM_BOOL, 'null' => NULL_NOT_ALLOWED); $fields['suspended'] = array('type' => PARAM_BOOL, 'null' => NULL_NOT_ALLOWED); $fields['mnethostid'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['username'] = array('type' => PARAM_USERNAME, 'null' => NULL_NOT_ALLOWED); $fields['password'] = array('type' => PARAM_RAW, 'null' => NULL_NOT_ALLOWED); $fields['idnumber'] = array('type' => PARAM_RAW, 'null' => NULL_NOT_ALLOWED); $fields['firstname'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['lastname'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['surname'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['email'] = array('type' => PARAM_RAW_TRIMMED, 'null' => NULL_NOT_ALLOWED); $fields['emailstop'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['icq'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['skype'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED); $fields['aim'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['yahoo'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['msn'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['phone1'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['phone2'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['institution'] = array('type' => PARAM_TEXT, 'null' => NULL_NOT_ALLOWED); $fields['department'] = array('type' => PARAM_TEXT, 'null' => NULL_NOT_ALLOWED); $fields['address'] = array('type' => PARAM_TEXT, 'null' => NULL_NOT_ALLOWED); $fields['city'] = array('type' => PARAM_TEXT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultcity); $fields['country'] = array('type' => PARAM_ALPHA, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->country, 'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_countries(true, true))); $fields['lang'] = array('type' => PARAM_LANG, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->lang, 'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_translations(false))); $fields['calendartype'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->calendartype, 'choices' => array_merge(array('' => ''), \core_calendar\type_factory::get_list_of_calendar_types())); $fields['theme'] = array('type' => PARAM_THEME, 'null' => NULL_NOT_ALLOWED, 'default' => theme_config::DEFAULT_THEME, 'choices' => array_merge(array('' => ''), get_list_of_themes())); $fields['timezone'] = array('type' => PARAM_TIMEZONE, 'null' => NULL_NOT_ALLOWED, 'default' => core_date::get_server_timezone()); // Must not use choices here: timezones can come and go. $fields['firstaccess'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['lastaccess'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['lastlogin'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['currentlogin'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['lastip'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED); $fields['secret'] = array('type' => PARAM_RAW, 'null' => NULL_NOT_ALLOWED); $fields['picture'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['url'] = array('type' => PARAM_URL, 'null' => NULL_NOT_ALLOWED); $fields['description'] = array('type' => PARAM_RAW, 'null' => NULL_ALLOWED); $fields['descriptionformat'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['mailformat'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultpreference_mailformat); $fields['maildigest'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultpreference_maildigest); $fields['maildisplay'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultpreference_maildisplay); $fields['autosubscribe'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultpreference_autosubscribe); $fields['trackforums'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->defaultpreference_trackforums); $fields['timecreated'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['timemodified'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['trustbitmask'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED); $fields['imagealt'] = array('type' => PARAM_TEXT, 'null' => NULL_ALLOWED); $fields['lastnamephonetic'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED); $fields['firstnamephonetic'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED); $fields['middlename'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED); $fields['alternatename'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED); self::$propertiescache = $fields; }
/** * Form definition. */ function definition() { global $CFG, $PAGE; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $returnurl = $this->_customdata['returnurl']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; // Form definition with new course defaults. $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); $mform->addElement('hidden', 'returnurl', null); $mform->setType('returnurl', PARAM_LOCALURL); $mform->setConstant('returnurl', $returnurl); $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); if (!isset($displaylist[$course->category])) { //always keep current $displaylist[$course->category] = coursecat::get($course->category, MUST_EXIST, true)->get_formatted_name(); } $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); $mform->addHelpButton('category', 'coursecategory'); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!empty($course->id)) { if (!has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } } else { if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes = array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key => $theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages = array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $calendars = array(); $calendars[''] = get_string('forceno'); $calendars += $calendartypes; $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars); } $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0' => get_string('no'), '2' => get_string('yes')); } else { $choices = array('1' => get_string('no'), '2' => get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } enrol_course_edit_form($mform, $course, $context); $mform->addElement('header', 'groups', get_string('groupsettingsheader', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); // Customizable role names in this course. $mform->addElement('header', 'rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_' . $role->id, PARAM_TEXT); } } // When two elements we need a group. $buttonarray = array(); if ($returnto !== 0) { $buttonarray[] =& $mform->createElement('submit', 'saveandreturn', get_string('savechangesandreturn')); } $buttonarray[] =& $mform->createElement('submit', 'saveanddisplay', get_string('savechangesanddisplay')); $buttonarray[] =& $mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($course); }
/** * Given a $time timestamp in GMT (seconds since epoch), returns an array that represents * the date in user time. * * @param int $time timestamp in GMT * @param float|int|string $timezone the timezone to use to calculate the time * {@link http://docs.moodle.org/dev/Time_API#Timezone} * @return array an array that represents the date in user time */ public function timestamp_to_date_array($time, $timezone = 99) { $gregoriancalendar = \core_calendar\type_factory::get_calendar_instance('gregorian'); $date = $gregoriancalendar->timestamp_to_date_array($time, $timezone); $newdate = $this->convert_from_gregorian($date['year'], $date['mon'], $date['mday'], $date['hours'], $date['minutes']); $date['year'] = $newdate['year']; $date['mon'] = $newdate['month']; $date['mday'] = $newdate['day']; $date['hours'] = $newdate['hour']; $date['minutes'] = $newdate['minute']; return $date; }
$ADMIN->add('themes', $temp); $ADMIN->add('themes', new admin_externalpage('themeselector', new lang_string('themeselector', 'admin'), $CFG->wwwroot . '/theme/index.php')); // settings for each theme foreach (core_component::get_plugin_list('theme') as $theme => $themedir) { $settings_path = "{$themedir}/settings.php"; if (file_exists($settings_path)) { $settings = new admin_settingpage('themesetting' . $theme, new lang_string('pluginname', 'theme_' . $theme)); include $settings_path; if ($settings) { $ADMIN->add('themes', $settings); } } } // Calendar settings. $temp = new admin_settingpage('calendar', new lang_string('calendarsettings', 'admin')); $temp->add(new admin_setting_configselect('calendartype', new lang_string('calendartype', 'admin'), new lang_string('calendartype_desc', 'admin'), 'gregorian', \core_calendar\type_factory::get_list_of_calendar_types())); $temp->add(new admin_setting_special_adminseesall()); //this is hacky because we do not want to include the stuff from calendar/lib.php $temp->add(new admin_setting_configselect('calendar_site_timeformat', new lang_string('pref_timeformat', 'calendar'), new lang_string('explain_site_timeformat', 'calendar'), '0', array('0' => new lang_string('default', 'calendar'), '%I:%M %p' => new lang_string('timeformat_12', 'calendar'), '%H:%M' => new lang_string('timeformat_24', 'calendar')))); $temp->add(new admin_setting_configselect('calendar_startwday', new lang_string('configstartwday', 'admin'), new lang_string('helpstartofweek', 'admin'), 0, array(0 => new lang_string('sunday', 'calendar'), 1 => new lang_string('monday', 'calendar'), 2 => new lang_string('tuesday', 'calendar'), 3 => new lang_string('wednesday', 'calendar'), 4 => new lang_string('thursday', 'calendar'), 5 => new lang_string('friday', 'calendar'), 6 => new lang_string('saturday', 'calendar')))); $temp->add(new admin_setting_special_calendar_weekend()); $options = array(); for ($i = 1; $i <= 99; $i++) { $options[$i] = $i; } $temp->add(new admin_setting_configselect('calendar_lookahead', new lang_string('configlookahead', 'admin'), new lang_string('helpupcominglookahead', 'admin'), 21, $options)); $options = array(); for ($i = 1; $i <= 20; $i++) { $options[$i] = $i; } $temp->add(new admin_setting_configselect('calendar_maxevents', new lang_string('configmaxevents', 'admin'), new lang_string('helpupcomingmaxevents', 'admin'), 10, $options));
function update_content($recordid, $value, $name='') { global $DB; $names = explode('_',$name); $name = $names[2]; // day month or year $this->$name = $value; if ($this->day and $this->month and $this->year) { // All of them have been collected now $content = new stdClass(); $content->fieldid = $this->field->id; $content->recordid = $recordid; $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($this->year, $this->month, $this->day); $content->content = make_timestamp( $gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute'], 0, 0, false); if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; return $DB->update_record('data_content', $content); } else { return $DB->insert_record('data_content', $content); } } }
/** * Form definition. */ function definition() { global $CFG, $PAGE,$USER,$DB; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id')))); $course = $this->_customdata['course']; // this contains the data of this form //print_object($course); $category = $this->_customdata['category']; $editoroptions = $this->_customdata['editoroptions']; $returnto = $this->_customdata['returnto']; $systemcontext = context_system::instance(); $categorycontext = context_coursecat::instance($category->id); if (!empty($course->id)) { $coursecontext = context_course::instance($course->id); $context = $coursecontext; } else { $coursecontext = null; $context = $categorycontext; } $courseconfig = get_config('moodlecourse'); $this->course = $course; $this->context = $context; // Form definition with new course defaults. $mform->addElement('header','general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); $mform->setType('returnto', PARAM_ALPHANUM); $mform->setConstant('returnto', $returnto); /* * EA_NK23-02-2015 * Added cost center field */ $is_manager = $DB->record_exists_sql("SELECT ra.userid FROM {role_assignments} as ra JOIN {role} as r ON ra.roleid=r.id WHERE r.archetype='manager' AND ra.userid={$USER->id}"); if(is_siteadmin()) { /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $admincostcenters=user_wise_department(); //print_object($admincostcenters); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }elseif(!is_siteadmin()){ $admincostcenters=user_wise_department(); $mform->addElement('select', 'costcenter', get_string('pluginname', 'local_costcenter'), $admincostcenters); } //$costcenter = $DB->get_records_sql_menu("SELECT cc.id,cc.fullname FROM mdl_local_userdata ud JOIN mdl_local_costcenter cc ON ud.costcenterid=cc.id WHERE ud.userid={$USER->id}"); //$mform->addElement('hidden','costcenter'); //$mform->setDefault('costcenter',$costcenter->id); //$mform->addElement('static', 'costcenterid', get_string('pluginname', 'local_costcenter'), $costcenter->fullname); $mform->setType('costcenter', PARAM_RAW); /* EA_NK23-02-2015 Customization ends here */ $mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); $mform->setConstant('shortname', $course->shortname); } // Verify permissions to change course category or keep current. if (empty($course->id)) { if (has_capability('moodle/course:create', $categorycontext)) { $displaylist = coursecat::make_categories_list('moodle/course:create'); /*======================Started By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ if(is_siteadmin()){ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); /*==================Ended by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ }else{ /*======================Ended By Raju.T for Disaply Course Categories based on training manager deparment on 9-11-2015============*/ $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ } $mform->addHelpButton('category', 'coursecategory'); $mform->setDefault('category', $category->id); $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } else { $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $category->id); } } else { if (has_capability('moodle/course:changecategory', $coursecontext)) { $admincoursecategory=department_category_course(); $mform->addElement('select', 'category', get_string('coursecategory'), $admincoursecategory); } else { //keep current $mform->addElement('hidden', 'category', null); $mform->setType('category', PARAM_INT); $mform->setConstant('category', $course->category); } $userdepartment_exist=$DB->record_exists('local_userdata',array('userid'=>$USER->id)); if($userdepartment_exist==1){ $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id)); if($userdepartment->lms_category=="AST" || $userdepartment->lms_category=="AST-EXT"){ $trainer_type_options=array(null=>'----Select to----',T=>'Trainer',SM=>'Sales Manager'); $mform->addElement('select', 'assignedto', get_string('assigne_to'), $trainer_type_options); //$mform->setConstant('category', $category->id); //$mform->setDefault('assignedto', $course->assignedto); } } /*==================strated by raju.t for admin created courses goes to HR department on 9-11-2015=============*/ $mform->addElement('text','duration',get_string('course_duration'),'maxlength="100" size="10"'); if(!empty($course->assignedto)){ $mform->setDefault('duration', $course->duration); }else{ $mform->setDefault('duration','0'); } $mform->setType('duration', PARAM_RAW); $mform->addRule('duration', get_string('possitiveonly'), 'regex', '#^(0|[1-9][0-9]*)$#'); } $choices = array(); $choices['0'] = get_string('hide'); $choices['1'] = get_string('show'); $mform->addElement('select', 'visible', get_string('visible'), $choices); $mform->addHelpButton('visible', 'visible'); $mform->setDefault('visible', $courseconfig->visible); if (!empty($course->id)) { if (!has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } } else { if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $courseconfig->visible); } } $mform->addElement('date_selector', 'startdate', get_string('startdate')); $mform->addHelpButton('startdate', 'startdate'); $mform->setDefault('startdate', time() + 3600 * 24); $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbercourse'); $mform->setType('idnumber', PARAM_RAW); if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); $mform->setConstants('idnumber', $course->idnumber); } // Description. $mform->addElement('header', 'descriptionhdr', get_string('description')); $mform->setExpanded('descriptionhdr'); $mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); $summaryfields = 'summary_editor'; if ($overviewfilesoptions = course_overviewfiles_options($course)) { $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions); $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles'); $summaryfields .= ',overviewfiles_filemanager'; } if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) { // Remove the description header it does not contain anything any more. $mform->removeElement('descriptionhdr'); $mform->hardFreeze($summaryfields); } // Course format. $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); $formcourseformats = array(); foreach ($courseformats as $courseformat) { $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); } if (isset($course->format)) { $course->format = course_get_format($course)->get_format(); // replace with default if not found if (!in_array($course->format, $courseformats)) { // this format is disabled. Still display it in the dropdown $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_'.$course->format)); } } $mform->addElement('select', 'format', get_string('format'), $formcourseformats); $mform->addHelpButton('format', 'format'); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). $mform->registerNoSubmitButton('updatecourseformat'); $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate')); // Just a placeholder for the course format options. $mform->addElement('hidden', 'addcourseformatoptionshere'); $mform->setType('addcourseformatoptionshere', PARAM_BOOL); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); if (!empty($CFG->allowcoursethemes)) { $themeobjects = get_list_of_themes(); $themes=array(); $themes[''] = get_string('forceno'); foreach ($themeobjects as $key=>$theme) { if (empty($theme->hidefromselector)) { $themes[$key] = get_string('pluginname', 'theme_'.$theme->name); } } $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); } $languages=array(); $languages[''] = get_string('forceno'); $languages += get_string_manager()->get_list_of_translations(); $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages); $mform->setDefault('lang', $courseconfig->lang); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $calendars = array(); $calendars[''] = get_string('forceno'); $calendars += $calendartypes; $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars); } $options = range(0, 10); $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options); $mform->addHelpButton('newsitems', 'newsitemsnumber'); $mform->setDefault('newsitems', $courseconfig->newsitems); $mform->addElement('selectyesno', 'showgrades', get_string('showgrades')); $mform->addHelpButton('showgrades', 'showgrades'); $mform->setDefault('showgrades', $courseconfig->showgrades); $mform->addElement('selectyesno', 'showreports', get_string('showreports')); $mform->addHelpButton('showreports', 'showreports'); $mform->setDefault('showreports', $courseconfig->showreports); // Files and uploads. $mform->addElement('header', 'filehdr', get_string('filesanduploads')); if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) { if (empty($course->legacyfiles)) { //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet $choices = array('0'=>get_string('no'), '2'=>get_string('yes')); } else { $choices = array('1'=>get_string('no'), '2'=>get_string('yes')); } $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices); $mform->addHelpButton('legacyfiles', 'courselegacyfiles'); if (!isset($courseconfig->legacyfiles)) { // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses $courseconfig->legacyfiles = 0; } $mform->setDefault('legacyfiles', $courseconfig->legacyfiles); } // Handle non-existing $course->maxbytes on course creation. $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes; // Let's prepare the maxbytes popup. $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes); $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->addHelpButton('maxbytes', 'maximumupload'); $mform->setDefault('maxbytes', $courseconfig->maxbytes); // Completion tracking. if (completion_info::is_enabled_for_site()) { $mform->addElement('header', 'completionhdr', get_string('completion', 'completion')); $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion')); $mform->setDefault('enablecompletion', $courseconfig->enablecompletion); $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion'); } else { $mform->addElement('hidden', 'enablecompletion'); $mform->setType('enablecompletion', PARAM_INT); $mform->setDefault('enablecompletion', 0); } enrol_course_edit_form($mform, $course, $context); $mform->addElement('header','groups', get_string('groupsettingsheader', 'group')); $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group'); $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices); $mform->addHelpButton('groupmode', 'groupmode', 'group'); $mform->setDefault('groupmode', $courseconfig->groupmode); $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group')); $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group'); $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce); //default groupings selector $options = array(); $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); // Customizable role names in this course. $mform->addElement('header','rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); if ($roles = get_all_roles()) { $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL); $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE); foreach ($roles as $role) { $mform->addElement('text', 'role_'.$role->id, get_string('yourwordforx', '', $role->localname)); $mform->setType('role_'.$role->id, PARAM_TEXT); } } $this->add_action_buttons(); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($course); }
/** * Calculate the position in the week of a specific calendar day * * @package core * @category time * @param int $day The day of the date whose position in the week is sought * @param int $month The month of the date whose position in the week is sought * @param int $year The year of the date whose position in the week is sought * @return int */ function dayofweek($day, $month, $year) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); return $calendartype->get_weekday($year, $month, $day); }
/** * Preprocess data from the profile field form before * it is saved. * * @param stdClass $data from the add/edit profile field form * @return stdClass processed data object */ public function define_save_preprocess($data) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Check if the start year was changed, if it was then convert from the start of that year. if ($data->param1 != $data->startyear) { $startdate = $calendartype->convert_to_gregorian($data->param1, 1, 1); } else { $startdate = $calendartype->convert_to_gregorian($data->param1, $data->startmonth, $data->startday); } // Check if the end year was changed, if it was then convert from the start of that year. if ($data->param2 != $data->endyear) { $stopdate = $calendartype->convert_to_gregorian($data->param2, 1, 1); } else { $stopdate = $calendartype->convert_to_gregorian($data->param2, $data->endmonth, $data->endday); } $data->param1 = $startdate['year']; $data->param2 = $stopdate['year']; if (empty($data->param3)) { $data->param3 = null; } // No valid value in the default data column needed. $data->defaultdata = '0'; return $data; }
/** * Displays a month in detail * * @param calendar_information $calendar * @param moodle_url $returnurl the url to return to * @return string */ public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { global $CFG; if (empty($returnurl)) { $returnurl = $this->page->url; } // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Store the display settings. $display = new stdClass(); $display->thismonth = false; // Get the specified date in the calendar type being used. $date = $calendartype->timestamp_to_date_array($calendar->time); $thisdate = $calendartype->timestamp_to_date_array(time()); if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) { $display->thismonth = true; $date = $thisdate; $calendar->time = time(); } // Get Gregorian date for the start of the month. $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1); // Store the gregorian date values to be used later. list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']); // Get the starting week day for this month. $startwday = dayofweek(1, $date['mon'], $date['year']); // Get the days in a week. $daynames = calendar_get_days(); // Store the number of days in a week. $numberofdaysinweek = $calendartype->get_num_weekdays(); $display->minwday = calendar_get_starting_weekday(); $display->maxwday = $display->minwday + ($numberofdaysinweek - 1); $display->maxdays = calendar_days_in_month($date['mon'], $date['year']); // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates. $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0); $display->tend = $display->tstart + $display->maxdays * DAYSECS - 1; // Align the starting weekday to fall in our display range // This is simple, not foolproof. if ($startwday < $display->minwday) { $startwday += $numberofdaysinweek; } // Get events from database $events = calendar_get_events($display->tstart, $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 (!\core_availability\info_module::is_user_visible($cm, 0, false)) { unset($events[$eventid]); } } } } // Extract information: events vs. time calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); $output = html_writer::start_tag('div', array('class' => 'header')); $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time); } $output .= html_writer::end_tag('div', array('class' => 'header')); // Controls $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class' => 'controls')); $table = new html_table(); $table->attributes = array('class' => 'calendarmonth calendartable'); $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear'))); $table->data = array(); // Get the day names as the header. $header = array(); for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { $header[] = $daynames[$i % $numberofdaysinweek]['shortname']; } $table->head = $header; // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; $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 dayblank'); $row->cells[] = $cell; } // Now display all the calendar $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } $daytime = $display->tstart - DAYSECS; for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { $daytime = $daytime + DAYSECS; 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)), 0, 0, 0, $daytime); $cellclasses = array(); if ($weekend & 1 << $dayweek % $numberofdaysinweek) { // Weekend. This is true no matter what the exact range is. $cellclasses[] = 'weekend'; } // 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->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title' => $title)), array('class' => 'day')); } else { $cell->text = html_writer::tag('div', $day, array('class' => 'day')); } // Special visual fx if an event spans many days $durationclass = false; if (isset($typesbyday[$day]['durationglobal'])) { $durationclass = 'duration_global'; } else { if (isset($typesbyday[$day]['durationcourse'])) { $durationclass = 'duration_course'; } else { if (isset($typesbyday[$day]['durationgroup'])) { $durationclass = 'duration_group'; } else { if (isset($typesbyday[$day]['durationuser'])) { $durationclass = 'duration_user'; } } } } if ($durationclass) { $cellclasses[] = 'duration'; $cellclasses[] = $durationclass; } // Special visual fx for today if ($display->thismonth && $day == $date['mday']) { $cellclasses[] = 'day today'; } else { $cellclasses[] = 'day nottoday'; } $cell->attributes = array('class' => join(' ', $cellclasses)); if (isset($eventsbyday[$day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new')); foreach ($eventsbyday[$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[$day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway')); foreach ($durationbyday[$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 dayblank'); $row->cells[] = $cell; } $table->data[] = $row; $output .= html_writer::table($table); return $output; }
/** * Output a timestamp. Give it the name of the group. * * @param array $submitValues values submitted. * @param bool $assoc specifies if returned array is associative * @return array */ function exportValue(&$submitValues, $assoc = false) { $value = null; $valuearray = array(); foreach ($this->_elements as $element) { $thisexport = $element->exportValue($submitValues[$this->getName()], true); if ($thisexport != null) { $valuearray += $thisexport; } } if (count($valuearray)) { if ($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further if (empty($valuearray['enabled'])) { $value[$this->getName()] = 0; return $value; } } // Get the calendar type used - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']); $value[$this->getName()] = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], 0, 0, 0, $this->_options['timezone'], true); return $value; } else { return null; } }
/** * Test converting dates from unixtime to a date for the calendar type specified. * * @param string $type the calendar type we want to test * @param array $date the date variables */ private function convert_unixtime_to_dateselector_test($type, $date) { $this->set_calendar_type($type); // Get the calendar. $calendar = \core_calendar\type_factory::get_calendar_instance(); $usergetdate = $calendar->timestamp_to_date_array($date['timestamp'], 0.0); $comparedate = array('minute' => $usergetdate['minutes'], 'hour' => $usergetdate['hours'], 'day' => $usergetdate['mday'], 'month' => $usergetdate['mon'], 'year' => $usergetdate['year'], 'timestamp' => $date['timestamp']); $this->assertEquals($comparedate, $date); }
/** * Powerful function that is used by edit and editadvanced to add common form elements/rules/etc. * * @param moodleform $mform * @param array|null $editoroptions * @param array|null $filemanageroptions */ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanageroptions = null) { global $CFG, $USER, $DB; $user = $DB->get_record('user', array('id' => $USER->id)); useredit_load_preferences($user, false); $strrequired = get_string('required'); // Add the necessary names. foreach (useredit_get_required_name_fields() as $fullname) { $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"'); $mform->addRule($fullname, $strrequired, 'required', null, 'client'); $mform->setType($fullname, PARAM_NOTAGS); } $enabledusernamefields = useredit_get_enabled_name_fields(); // Add the enabled additional name fields. foreach ($enabledusernamefields as $addname) { $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"'); $mform->setType($addname, PARAM_NOTAGS); } // Do not show email field if change confirmation is pending. if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) { $notice = get_string('emailchangepending', 'auth', $user); $notice .= '<br /><a href="edit.php?cancelemailchange=1&id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>'; $mform->addElement('static', 'emailpending', get_string('email'), $notice); } else { $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); $mform->addRule('email', $strrequired, 'required', null, 'client'); $mform->setType('email', PARAM_EMAIL); } $choices = array(); $choices['0'] = get_string('emaildisplayno'); $choices['1'] = get_string('emaildisplayyes'); $choices['2'] = get_string('emaildisplaycourse'); $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); $mform->setDefault('maildisplay', 2); $choices = array(); $choices['0'] = get_string('textformat'); $choices['1'] = get_string('htmlformat'); // $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); //$mform->setDefault('mailformat', 1); if (!empty($CFG->allowusermailcharset)) { $choices = array(); $charsets = get_list_of_charsets(); if (!empty($CFG->sitemailcharset)) { $choices['0'] = get_string('site') . ' (' . $CFG->sitemailcharset . ')'; } else { $choices['0'] = get_string('site') . ' (UTF-8)'; } $choices = array_merge($choices, $charsets); $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices); } /* $choices = array(); $choices['0'] = get_string('emaildigestoff'); $choices['1'] = get_string('emaildigestcomplete'); $choices['2'] = get_string('emaildigestsubjects'); $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); $mform->setDefault('maildigest', 0); $mform->addHelpButton('maildigest', 'emaildigest'); $choices = array(); $choices['1'] = get_string('autosubscribeyes'); $choices['0'] = get_string('autosubscribeno'); $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); $mform->setDefault('autosubscribe', 1); if (!empty($CFG->forum_trackreadposts)) { $choices = array(); $choices['0'] = get_string('trackforumsno'); $choices['1'] = get_string('trackforumsyes'); $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); $mform->setDefault('trackforums', 0); } $editors = editors_get_enabled(); if (count($editors) > 1) { $choices = array('' => get_string('defaulteditor')); $firsteditor = ''; foreach (array_keys($editors) as $editor) { if (!$firsteditor) { $firsteditor = $editor; } $choices[$editor] = get_string('pluginname', 'editor_' . $editor); } $mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices); $mform->setDefault('preference_htmleditor', ''); } else { // Empty string means use the first chosen text editor. $mform->addElement('hidden', 'preference_htmleditor'); $mform->setDefault('preference_htmleditor', ''); $mform->setType('preference_htmleditor', PARAM_PLUGIN); } $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"'); $mform->setType('city', PARAM_TEXT); if (!empty($CFG->defaultcity)) { $mform->setDefault('city', $CFG->defaultcity); } $choices = get_string_manager()->get_list_of_countries(); $choices = array('' => get_string('selectacountry') . '...') + $choices; $mform->addElement('select', 'country', get_string('selectacountry'), $choices); if (!empty($CFG->country)) { $mform->setDefault('country', $CFG->country); } /* GWL - Remove Extra */ /* $choices = get_list_of_timezones(); $choices['99'] = get_string('serverlocaltime'); if ($CFG->forcetimezone != 99) { $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); } else { $mform->addElement('select', 'timezone', get_string('timezone'), $choices); $mform->setDefault('timezone', '99'); } */ $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations()); $mform->setDefault('lang', $CFG->lang); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes); $mform->setDefault('calendartype', $CFG->calendartype); } /*GWL - Remove Edit Profile Extra Field*/ /* if (!empty($CFG->allowuserthemes)) { $choices = array(); $choices[''] = get_string('default'); $themes = get_list_of_themes(); foreach ($themes as $key => $theme) { if (empty($theme->hidefromselector)) { $choices[$key] = get_string('pluginname', 'theme_'.$theme->name); } } $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); } */ /*GWL - Remove Edit Profile Extra Field*/ $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions); $mform->setType('description_editor', PARAM_CLEANHTML); $mform->addHelpButton('description_editor', 'userdescription'); if (empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_picture', get_string('pictureofuser')); if (!empty($CFG->enablegravatar)) { $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled'))); } $mform->addElement('static', 'currentpicture', get_string('currentpicture')); $mform->addElement('checkbox', 'deletepicture', get_string('delete')); $mform->setDefault('deletepicture', 0); $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions); $mform->addHelpButton('imagefile', 'newpicture'); // $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); //$mform->setType('imagealt', PARAM_TEXT); } // Display user name fields that are not currenlty enabled here if there are any. $disabledusernamefields = useredit_get_disabled_name_fields($enabledusernamefields); /* GWL - Remove Extra Fields While registration */ /* if (count($disabledusernamefields) > 0) { $mform->addElement('header', 'moodle_additional_names', get_string('additionalnames')); foreach ($disabledusernamefields as $allname) { $mform->addElement('text', $allname, get_string($allname), 'maxlength="100" size="30"'); $mform->setType($allname, PARAM_NOTAGS); } } */ /* GWL - Remove Extra Fields While registration */ /* GWL - Remove Extra Fields While registration */ /* if (!empty($CFG->usetags) and empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_interests', get_string('interests')); $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial')); $mform->addHelpButton('interests', 'interestslist'); } */ /* GWL - Remove Extra Fields While registration */ /* GWL - Remove Extra Fields While registration */ // Moodle optional fields. /* $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); $mform->setType('url', PARAM_URL); $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); $mform->setType('icq', PARAM_NOTAGS); $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); $mform->setType('skype', PARAM_NOTAGS); $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); $mform->setType('aim', PARAM_NOTAGS); $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); $mform->setType('yahoo', PARAM_NOTAGS); $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); $mform->setType('msn', PARAM_NOTAGS); $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"'); $mform->setType('idnumber', PARAM_NOTAGS); $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"'); $mform->setType('institution', PARAM_TEXT); $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"'); $mform->setType('department', PARAM_TEXT); */ /* GWL - Remove Extra Fields While registration */ //$mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"'); //$mform->setType('phone1', PARAM_NOTAGS); //$mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"'); //$mform->setType('phone2', PARAM_NOTAGS); //$mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"'); //$mform->setType('address', PARAM_TEXT); }