Exemplo n.º 1
0
 function print_header($title)
 {
     global $USER, $CFG;
     $replacements = array('%fullname%' => get_string('mymoodle', 'my'));
     foreach ($replacements as $search => $replace) {
         $title = str_replace($search, $replace, $title);
     }
     $site = get_site();
     $button = update_mymoodle_icon($USER->id);
     $nav = get_string('mymoodle', 'my');
     $header = $site->shortname . ': ' . $nav;
     $navlinks = array(array('name' => $nav, 'link' => '', 'type' => 'misc'));
     $navigation = build_navigation($navlinks);
     $loggedinas = user_login_string($site);
     if (empty($CFG->langmenu)) {
         $langmenu = '';
     } else {
         $currlang = current_language();
         $langs = get_list_of_languages();
         $langlabel = get_accesshide(get_string('language'));
         $langmenu = popup_form($CFG->wwwroot . '/my/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
     }
     print_header($title, $header, $navigation, '', '', true, $button, $loggedinas . $langmenu);
 }
Exemplo n.º 2
0
 function write_setting($data)
 {
     $return = parent::write_setting($data);
     get_list_of_languages(true);
     //refresh the list
     return $return;
 }
 * A simple test script that hammers get_string, and times how long it takes.
 *
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package moodlecore
 */
/** */
require_once dirname(__FILE__) . '/../../config.php';
require_once $CFG->libdir . '/moodlelib.php';
define('NUM_CALLS', 20000);
define('NUM_REPITITIONS', 3);
$TEST_LANGUAGES = array('en_utf8', 'fr_utf8', 'fr_ca_utf8', 'nonexistant');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
$title = 'get_string performance test';
print_header($title, $title, build_navigation($title));
$installedlangs = get_list_of_languages();
$requiredlangs = $TEST_LANGUAGES;
array_pop($requiredlangs);
foreach ($requiredlangs as $lang) {
    if (!isset($installedlangs[$lang])) {
        echo $OUTPUT->notification('You must install the following language packs to run these test: ' . implode(', ', $requiredlangs));
        echo $OUTPUT->footer();
        die;
    }
}
time_for_loop();
echo $OUTPUT->heading('Timing calling functions');
time_function_call('dummy_function');
time_function_call('simple_eval');
time_function_call('simple_eval_with_interp');
time_function_call('sprintf_eval');
Exemplo n.º 4
0
 function print_languageform()
 {
     global $CFG;
     $editlang = optional_param('editlang', current_language(), PARAM_TEXT);
     $enKeys = get_records('podcaster_language', 'language', 'en_utf8', 'name DESC');
     $langKeys = $editlang != 'en_utf8' ? get_records('podcaster_language', 'language', $editlang, 'name') : $enKeys;
     $editMap = array();
     if ($langKeys) {
         foreach ($langKeys as $key) {
             $editMap[$key->name] = $key->value;
         }
     }
     $languages = get_list_of_languages();
     echo '<tr>
         <td>&nbsp;</td>
         <td>' . get_string('config_currentlanguage', 'podcaster') . '</td>
         <td>';
     choose_from_menu($languages, 'editlang', $editlang, '', 'document.location.href=\'' . $CFG->wwwroot . '/' . $CFG->admin . '/module.php?module=podcaster&amp;tab=language&amp;editlang=\' + this.value');
     echo '  </td>
       </tr>';
     if ($enKeys) {
         $i = 0;
         foreach ($enKeys as $key) {
             $exists = isset($editMap[$key->name]) ? true : false;
             $value = $exists ? $editMap[$key->name] : '';
             echo '<tr>
             <td valign="top"><b>' . $key->name . '</b></td>
             <td valign="top">' . $key->value . '</td>
             <td valign="top"' . ($exists ? '' : ' style="border:1px solid red;"') . '>';
             if (substr($key->name, -5) == 'title') {
                 echo '<input type="text" size="32" name="' . $key->name . '" value="' . htmlspecialchars($value) . '" />';
             } else {
                 echo '<textarea name="' . $key->name . '" rows="7" cols="32">' . $value . '</textarea>';
             }
             echo '
             </td>
           </tr>';
             if (++$i % 2 == 0) {
                 echo '<tr><td colspan="3"><hr size="1" /></td></tr>';
             }
         }
     }
 }
Exemplo n.º 5
0
 function definition()
 {
     global $USER, $CFG, $DB;
     $courseconfig = get_config('moodlecourse');
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $category = $this->_customdata['category'];
     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
     $disable_meta = false;
     // basic meta course state protection; server-side security checks not needed
     if (!empty($course)) {
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         $context = $coursecontext;
         if (course_in_meta($course)) {
             $disable_meta = get_string('metaalreadyinmeta');
         } else {
             if ($course->metacourse) {
                 if ($DB->count_records('course_meta', array('parent_course' => $course->id)) > 0) {
                     $disable_meta = get_string('metaalreadyhascourses');
                 }
             } else {
                 // if users already enrolled directly into coures, do not allow switching to meta,
                 // users with metacourse manage permission are exception
                 // please note that we do not need exact results - anything unexpected here prevents metacourse
                 $managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id');
                 $enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext);
                 if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) {
                     foreach ($users as $user) {
                         if (!isset($managers[$user->id])) {
                             $disable_meta = get_string('metaalreadyhasenrolments');
                             break;
                         }
                     }
                 }
                 unset($managers);
                 unset($users);
                 unset($enrolroles);
             }
         }
     } else {
         $coursecontext = null;
         $context = $categorycontext;
     }
     /// form definition with new course defaults
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     // Must have create course capability in both categories in order to move course
     if (has_capability('moodle/course:create', $categorycontext)) {
         $displaylist = array();
         $parentlist = array();
         make_categories_list($displaylist, $parentlist, 'moodle/course:create');
         $mform->addElement('select', 'category', get_string('category'), $displaylist);
     } else {
         $mform->addElement('hidden', 'category', null);
     }
     $mform->setHelpButton('category', array('coursecategory', get_string('category')));
     $mform->setDefault('category', $category->id);
     $mform->setType('category', PARAM_INT);
     $fullname = get_string('defaultcoursefullname');
     $shortname = get_string('defaultcourseshortname');
     while ($DB->record_exists('course', array('fullname' => $fullname)) or $DB->record_exists('course', array('fullname' => $fullname))) {
         $fullname++;
         $shortname++;
     }
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_MULTILANG);
     if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
         $mform->hardFreeze('fullname');
         $mform->setConstant('fullname', $course->fullname);
     }
     $mform->setDefault('fullname', $fullname);
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_MULTILANG);
     if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
         $mform->hardFreeze('shortname');
         $mform->setConstant('shortname', $course->shortname);
     }
     $mform->setDefault('shortname', $shortname);
     $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100"  size="10"');
     $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
     $mform->setType('idnumber', PARAM_RAW);
     if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
         $mform->setConstants('idnumber', $course->idnumber);
     }
     $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65'));
     $mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
     $mform->setType('summary', PARAM_RAW);
     $courseformats = get_list_of_plugins('course/format');
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
         if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
             $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
     $mform->setDefault('format', $courseconfig->format);
     for ($i = 1; $i <= 52; $i++) {
         $sectionmenu[$i] = "{$i}";
     }
     $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
     $mform->setDefault('numsections', $courseconfig->numsections);
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
     $mform->setDefault('startdate', time() + 3600 * 24);
     $choices = array();
     $choices['0'] = get_string('hiddensectionscollapsed');
     $choices['1'] = get_string('hiddensectionsinvisible');
     $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
     $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
     $mform->setDefault('hiddensections', $courseconfig->hiddensections);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
     $mform->setDefault('newsitems', $courseconfig->newsitems);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
     $mform->setDefault('showgrades', $courseconfig->showgrades);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
     $mform->setDefault('showreports', $courseconfig->showreports);
     $choices = get_max_upload_sizes($CFG->maxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
     $mform->setDefault('maxbytes', $courseconfig->maxbytes);
     if (!empty($CFG->allowcoursethemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $meta = array();
     $meta[0] = get_string('no');
     $meta[1] = get_string('yes');
     if ($disable_meta === false) {
         $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
         $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
         $mform->setDefault('metacourse', $courseconfig->metacourse);
     } else {
         // no metacourse element - we do not want to change it anyway!
         $mform->addElement('static', 'nometacourse', get_string('managemeta'), (empty($course->metacourse) ? $meta[0] : $meta[1]) . " - {$disable_meta} ");
         $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'enrolhdr', get_string('enrolments'));
     $choices = array();
     $modules = explode(',', $CFG->enrol_plugins_enabled);
     foreach ($modules as $module) {
         $name = get_string('enrolname', "enrol_{$module}");
         $plugin = enrolment_factory::factory($module);
         if (method_exists($plugin, 'print_entry')) {
             $choices[$name] = $module;
         }
     }
     asort($choices);
     $choices = array_flip($choices);
     $choices = array_merge(array('' => get_string('sitedefault') . ' (' . get_string('enrolname', "enrol_{$CFG->enrol}") . ')'), $choices);
     $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
     $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
     $mform->setDefault('enrol', $courseconfig->enrol);
     $roles = get_assignable_roles($context);
     if (!empty($course)) {
         // add current default role, so that it is selectable even when user can not assign it
         if ($current_role = $DB->get_record('role', array('id' => $course->defaultrole))) {
             $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
         }
     }
     $choices = array();
     if ($sitedefaultrole = $DB->get_record('role', array('id' => $CFG->defaultcourseroleid))) {
         $choices[0] = get_string('sitedefault') . ' (' . $sitedefaultrole->name . ')';
     } else {
         $choices[0] = get_string('sitedefault');
     }
     $choices = $choices + $roles;
     // fix for MDL-9197
     foreach ($choices as $choiceid => $choice) {
         $choices[$choiceid] = format_string($choice);
     }
     $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
     $mform->setDefault('defaultrole', 0);
     $radio = array();
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
     $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
     $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true);
     $mform->setDefault('enrollable', $courseconfig->enrollable);
     $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate'), array('optional' => true));
     $mform->setDefault('enrolstartdate', 0);
     $mform->disabledIf('enrolstartdate', 'enrollable', 'neq', 2);
     $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate'), array('optional' => true));
     $mform->setDefault('enrolenddate', 0);
     $mform->disabledIf('enrolenddate', 'enrollable', 'neq', 2);
     $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod'), array('optional' => true, 'defaultunit' => 86400));
     $mform->setDefault('enrolperiod', $courseconfig->enrolperiod);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'expirynotifyhdr', get_string('expirynotify'));
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'expirynotify', get_string('notify'), $choices);
     $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
     $mform->setDefault('expirynotify', $courseconfig->expirynotify);
     $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
     $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
     $mform->setDefault('notifystudents', $courseconfig->notifystudents);
     $thresholdmenu = array();
     for ($i = 1; $i <= 30; $i++) {
         $seconds = $i * 86400;
         $thresholdmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
     $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
     $mform->setDefault('expirythreshold', $courseconfig->expirythreshold);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('groups', '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'), $choices);
     $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
     $mform->setDefault('groupmode', $courseconfig->groupmode);
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
     $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
     $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
     if (!empty($CFG->enablegroupings)) {
         //default groupings selector
         $options = array();
         $options[0] = get_string('none');
         $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('availability'));
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $mform->addElement('select', 'visible', get_string('availability'), $choices);
     $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
     $mform->setDefault('visible', $courseconfig->visible);
     if ($course and !has_capability('moodle/course:visibility', $coursecontext)) {
         $mform->hardFreeze('visible');
         $mform->setConstant('visible', $course->visible);
     }
     $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"');
     $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true);
     $mform->setDefault('enrolpassword', '');
     $mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
     $mform->setType('enrolpassword', PARAM_RAW);
     if (empty($course) or $course->password !== '' and $course->id != SITEID) {
         // do not require password in existing courses that do not have password yet - backwards compatibility ;-)
         if (!empty($CFG->enrol_manual_requirekey)) {
             $mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client');
         }
     }
     $choices = array();
     $choices['0'] = get_string('guestsno');
     $choices['1'] = get_string('guestsyes');
     $choices['2'] = get_string('guestskey');
     $mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
     $mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
     $mform->setDefault('guest', $courseconfig->guest);
     // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
     $enrol_object = $CFG;
     if (!empty($course)) {
         $enrol_object = $course;
     }
     // If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
     if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && !($enrol_object->enrol == 'manual' || empty($enrol_object->enrol) && $CFG->enrol == 'manual')) {
         $costgroup = array();
         $currencies = get_list_of_currencies();
         $costgroup[] =& MoodleQuickForm::createElement('text', 'cost', '', 'maxlength="6" size="6"');
         $costgroup[] =& MoodleQuickForm::createElement('select', 'currency', '', $currencies);
         $mform->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
         //defining a rule for a form element within a group :
         $costgrprules = array();
         //set the message to null to tell Moodle to use a default message
         //available for most rules, fetched from language pack (err_{rulename}).
         $costgrprules['cost'][] = array(null, 'numeric', null, 'client');
         $mform->addGroupRule('costgrp', $costgrprules);
         $mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
         $mform->setDefault('cost', '');
         $mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('language'));
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_list_of_languages();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     $mform->setDefault('lang', $courseconfig->lang);
     //--------------------------------------------------------------------------------
     require_once $CFG->libdir . '/completionlib.php';
     if (completion_info::is_enabled_for_site()) {
         $mform->addElement('header', '', get_string('progress', 'completion'));
         $mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'), array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion')));
         $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
     } else {
         $mform->addElement('hidden', 'enablecompletion');
         $mform->setDefault('enablecompletion', 0);
     }
     //--------------------------------------------------------------------------------
     if (has_capability('moodle/site:config', $systemcontext) && (!empty($course->requested) && $CFG->restrictmodulesfor == 'requested' || $CFG->restrictmodulesfor == 'all')) {
         $mform->addElement('header', '', get_string('restrictmodules'));
         $options = array();
         $options['0'] = get_string('no');
         $options['1'] = get_string('yes');
         $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
         $mods = array(0 => get_string('allownone'));
         $mods += $DB->get_records_menu('modules', array(), 'name', 'id, name');
         $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple' => 'multiple', 'size' => '10'));
         $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
     } else {
         $mform->addElement('hidden', 'restrictmodules', null);
     }
     if ($CFG->restrictmodulesfor == 'all') {
         $mform->setDefault('allowedmods', explode(',', $CFG->defaultallowedmodules));
         if (!empty($CFG->restrictbydefault)) {
             $mform->setDefault('restrictmodules', 1);
         }
     }
     $mform->setType('restrictmodules', PARAM_INT);
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
     $mform->setHelpButton('rolerenaming', array('rolerenaming', get_string('rolerenaming')), true);
     if ($roles = get_all_roles()) {
         if ($coursecontext) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW);
         }
         $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->name));
             if (isset($role->localname)) {
                 $mform->setDefault('role_' . $role->id, $role->localname);
             }
             $mform->setType('role_' . $role->id, PARAM_TEXT);
             if (!in_array($role->id, $assignableroles)) {
                 $mform->setAdvanced('role_' . $role->id);
             }
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
 }
Exemplo n.º 6
0
                        break;
                    default:
                }
            } else {
            }
        }
        if ($updated) {
            $notice_ok[] = get_string('langupdatecomplete', 'admin');
        } else {
            $notice_ok[] = get_string('nolangupdateneeded', 'admin');
        }
        break;
}
//close of main switch
admin_externalpage_print_header();
$installedlangs = get_list_of_languages(true, true);
$missingparents = array();
$oldlang = isset($SESSION->lang) ? $SESSION->lang : null;
// override current lang
foreach ($installedlangs as $l => $unused) {
    $SESSION->lang = $l;
    $parent = get_string('parentlanguage');
    if ($parent == 'en_utf8') {
        continue;
    }
    if (strpos($parent, '[[') !== false) {
        continue;
        // no parent
    }
    if (!isset($installedlangs[$parent])) {
        $missingparents[$l] = $parent;
Exemplo n.º 7
0
if (has_capability('moodle/site:langeditlocal', $context, $USER->id, false)) {
    $firstrow[] = new tabobject('uselocal', "{$CFG->wwwroot}/{$CFG->admin}/lang.php?mode={$mode}&amp;currentfile={$currentfile}&amp;uselocal=1", $strlocalstringcustomization);
}
if (has_capability('moodle/site:langeditmaster', $context, $USER->id, false)) {
    $firstrow[] = new tabobject('usemaster', "{$CFG->wwwroot}/{$CFG->admin}/lang.php?mode={$mode}&amp;currentfile={$currentfile}&amp;uselocal=0", $strlangpackmaintaining);
}
$secondrow[] = new tabobject('missing', "{$CFG->wwwroot}/{$CFG->admin}/lang.php?mode=missing", $strmissingstrings);
$secondrow[] = new tabobject('compare', "{$CFG->wwwroot}/{$CFG->admin}/lang.php?mode=compare", $streditstrings);
$secondrow[] = new tabobject('helpfiles', "{$CFG->wwwroot}/{$CFG->admin}/lang.php?mode=helpfiles", $stredithelpdocs);
$tabs = array($firstrow, $secondrow);
print_tabs($tabs, $currenttab, $inactive, $activated);
if (!$mode) {
    // TODO this is a very nice place to put some translation statistics
    print_box_start();
    $currlang = current_language();
    $langs = get_list_of_languages(false, true);
    popup_form("{$CFG->wwwroot}/{$CFG->admin}/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", false, 'self', $strcurrentlanguage . ':');
    print_box_end();
    admin_externalpage_print_footer();
    exit;
}
// Get a list of all the root files in the English directory
$langbase = $CFG->dataroot . '/lang';
$enlangdir = "{$CFG->dirroot}/lang/en_utf8";
if ($currentlang == 'en_utf8') {
    $langdir = $enlangdir;
} else {
    $langdir = "{$langbase}/{$currentlang}";
}
$locallangdir = "{$langbase}/{$currentlang}_local";
$saveto = $uselocal ? $locallangdir : $langdir;
Exemplo n.º 8
0
function restore_create_users($restore, $xml_file)
{
    global $CFG, $db;
    require_once $CFG->dirroot . '/tag/lib.php';
    $authcache = array();
    // Cache to get some bits from authentication plugins
    $status = true;
    // Users have already been checked by restore_precheck_users() so they are loaded
    // in backup_ids table. They don't need to be loaded (parsed) from XML again. Also, note
    // the same function has performed the needed modifications in the $user->mnethostid field
    // so we don't need to do it again here at all. Just some checks.
    // Get users ids from backup_ids table
    $userids = get_fieldset_select('backup_ids', 'old_id', "backup_code = {$restore->backup_unique_code} AND table_name = 'user'");
    // Have users to process, proceed with them
    if (!empty($userids)) {
        /// Get languages for quick search later
        $languages = get_list_of_languages();
        /// Iterate over all users loaded from xml
        $counter = 0;
        /// Init trailing messages
        $messages = array();
        foreach ($userids as $userid) {
            // Defaults
            $user_exists = false;
            // By default user does not exist
            $newid = null;
            // By default, there is not newid
            // Get record from backup_ids
            $useridsdbrec = backup_getid($restore->backup_unique_code, 'user', $userid);
            // Based in restore_precheck_users() calculations, if the user exists
            // new_id must contain the id of the matching user
            if (!empty($useridsdbrec->new_id)) {
                $user_exists = true;
                $newid = $useridsdbrec->new_id;
            }
            $user = $useridsdbrec->info;
            foreach (array_keys(get_object_vars($user)) as $field) {
                if (!is_array($user->{$field})) {
                    $user->{$field} = backup_todb($user->{$field}, false);
                    if (is_null($user->{$field})) {
                        $user->{$field} = '';
                    }
                }
            }
            //Now, recode some languages (Moodle 1.5)
            if ($user->lang == 'ma_nt') {
                $user->lang = 'mi_nt';
            }
            //Country list updates - MDL-13060
            //Any user whose country code has been deleted or modified needs to be assigned a valid one.
            $country_update_map = array('ZR' => 'CD', 'TP' => 'TL', 'FX' => 'FR', 'KO' => 'RS', 'CS' => 'RS', 'WA' => 'GB');
            if (array_key_exists($user->country, $country_update_map)) {
                $user->country = $country_update_map[$user->country];
            }
            //If language does not exist here - use site default
            if (!array_key_exists($user->lang, $languages)) {
                $user->lang = $CFG->lang;
            }
            //Check if it's admin and coursecreator
            $is_admin = !empty($user->roles['admin']);
            $is_coursecreator = !empty($user->roles['coursecreator']);
            //Check if it's teacher and student
            $is_teacher = !empty($user->roles['teacher']);
            $is_student = !empty($user->roles['student']);
            //Check if it's needed
            $is_needed = !empty($user->roles['needed']);
            //Calculate if it is a course user
            //Has role teacher or student or needed
            $is_course_user = ($is_teacher or $is_student or $is_needed);
            // Only try to perform mnethost/auth modifications if restoring to another server
            // or if, while restoring to same server, the user doesn't exists yet (rebuilt site)
            //
            // So existing user data in same server *won't be modified by restore anymore*,
            // under any circumpstance. If somehting is wrong with existing data, it's server fault.
            if (!backup_is_same_site($restore) || backup_is_same_site($restore) && !$user_exists) {
                //Arriving here, any user with mnet auth and using $CFG->mnet_localhost_id is wrong
                //as own server cannot be accesed over mnet. Change auth to manual and inform about the switch
                if ($user->auth == 'mnet' && $user->mnethostid == $CFG->mnet_localhost_id) {
                    // Respect registerauth
                    if ($CFG->registerauth == 'email') {
                        $user->auth = 'email';
                    } else {
                        $user->auth = 'manual';
                    }
                    // inform about the automatic switch of authentication/host
                    if (empty($user->mnethosturl)) {
                        $user->mnethosturl = '----';
                    }
                    $messages[] = get_string('mnetrestore_extusers_switchuserauth', 'admin', $user);
                }
            }
            unset($user->mnethosturl);
            //Flags to see what parts are we going to restore
            $create_user = true;
            $create_roles = true;
            $create_custom_profile_fields = true;
            $create_tags = true;
            $create_preferences = true;
            //If we are restoring course users and it isn't a course user
            if ($restore->users == 1 and !$is_course_user) {
                //If only restoring course_users and user isn't a course_user, inform to $backup_ids
                $status = backup_putid($restore->backup_unique_code, "user", $userid, null, 'notincourse');
                $create_user = false;
                $create_roles = false;
                $create_custom_profile_fields = false;
                $create_tags = false;
                $create_preferences = false;
            }
            if ($user_exists and $create_user) {
                //If user exists mark its newid in backup_ids (the same than old)
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, 'exists');
                $create_user = false;
                $create_custom_profile_fields = false;
                $create_tags = false;
                $create_preferences = false;
            }
            //Here, if create_user, do it
            if ($create_user) {
                //Unset the id because it's going to be inserted with a new one
                unset($user->id);
                /// Disable pictures based on global setting or existing empty value (old backups can contain wrong empties)
                if (!empty($CFG->disableuserimages) || empty($user->picture)) {
                    $user->picture = 0;
                }
                //We need to analyse the AUTH field to recode it:
                //   - if the field isn't set, we are in a pre 1.4 backup and $CFG->registerauth will decide
                //   - if the auth isn't enabled in target site, $CFG->registerauth will decide
                //   - finally, if the auth resulting isn't enabled, default to 'manual'
                if (empty($user->auth) || !is_enabled_auth($user->auth)) {
                    if ($CFG->registerauth == 'email') {
                        $user->auth = 'email';
                    } else {
                        $user->auth = 'manual';
                    }
                }
                if (!is_enabled_auth($user->auth)) {
                    // Final auth check verify, default to manual if not enabled
                    $user->auth = 'manual';
                }
                // Now that we know the auth method, for users to be created without pass
                // if password handling is internal and reset password is available
                // we set the password to "restored" (plain text), so the login process
                // will know how to handle that situation in order to allow the user to
                // recover the password. MDL-20846
                if (empty($user->password)) {
                    // Only if restore comes without password
                    if (!array_key_exists($user->auth, $authcache)) {
                        // Not in cache
                        $userauth = new stdClass();
                        $authplugin = get_auth_plugin($user->auth);
                        $userauth->preventpassindb = $authplugin->prevent_local_passwords();
                        $userauth->isinternal = $authplugin->is_internal();
                        $userauth->canresetpwd = $authplugin->can_reset_password();
                        $authcache[$user->auth] = $userauth;
                    } else {
                        $userauth = $authcache[$user->auth];
                        // Get from cache
                    }
                    // Most external plugins do not store passwords locally
                    if (!empty($userauth->preventpassindb)) {
                        $user->password = '******';
                        // If Moodle is responsible for storing/validating pwd and reset functionality is available, mark
                    } else {
                        if ($userauth->isinternal and $userauth->canresetpwd) {
                            $user->password = '******';
                        }
                    }
                }
                //We need to process the POLICYAGREED field to recalculate it:
                //    - if the destination site is different (by wwwroot) reset it.
                //    - if the destination site is the same (by wwwroot), leave it unmodified
                if (!backup_is_same_site($restore)) {
                    $user->policyagreed = 0;
                } else {
                    //Nothing to do, we are in the same server
                }
                //Check if the theme exists in destination server
                $themes = get_list_of_themes();
                if (!in_array($user->theme, $themes)) {
                    $user->theme = '';
                }
                //We are going to create the user
                //The structure is exactly as we need
                $newid = insert_record("user", addslashes_recursive($user));
                //Put the new id
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, "new");
            }
            ///TODO: This seccion is to support pre 1.7 course backups, using old roles
            ///      teacher, coursecreator, student.... providing a basic mapping to new ones.
            ///      Someday we'll drop support for them and this section will be safely deleted (2.0?)
            //Here, if create_roles, do it as necessary
            if ($create_roles) {
                //Get the newid and current info from backup_ids
                $data = backup_getid($restore->backup_unique_code, "user", $userid);
                $newid = $data->new_id;
                $currinfo = $data->info . ",";
                //Now, depending of the role, create records in user_studentes and user_teacher
                //and/or mark it in backup_ids
                if ($is_admin) {
                    //If the record (user_admins) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "admin,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_coursecreator) {
                    //If the record (user_coursecreators) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "coursecreator,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_needed) {
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "needed,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_teacher) {
                    //If the record (teacher) doesn't exists
                    //Put status in backup_ids
                    $currinfo = $currinfo . "teacher,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['teacher']->course = $restore->course_id;
                    $user->roles['teacher']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['teacher']->enrol)) {
                        $user->roles['teacher']->enrol = $CFG->enrol;
                    } else {
                        if (!backup_is_same_site($restore)) {
                            $user->roles['teacher']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    if ($user->roles['teacher']->editall) {
                        role_assign($rolesmapping['defaultteacheredit'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                        // editting teacher
                    } else {
                        // non editting teacher
                        role_assign($rolesmapping['defaultteacher'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                    }
                }
                if ($is_student) {
                    //Put status in backup_ids
                    $currinfo = $currinfo . "student,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['student']->course = $restore->course_id;
                    $user->roles['student']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['student']->enrol)) {
                        $user->roles['student']->enrol = $CFG->enrol;
                    } else {
                        if (!backup_is_same_site($restore)) {
                            $user->roles['student']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    role_assign($rolesmapping['defaultstudent'], $newid, 0, $context->id, $user->roles['student']->timestart, $user->roles['student']->timeend, 0, $user->roles['student']->enrol);
                }
                if (!$is_course_user) {
                    //If the record (user) doesn't exists
                    if (!record_exists("user", "id", $newid)) {
                        //Put status in backup_ids
                        $currinfo = $currinfo . "user,";
                        $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    }
                }
            }
            /// Here, if create_custom_profile_fields, do it as necessary
            if ($create_custom_profile_fields) {
                if (isset($user->user_custom_profile_fields)) {
                    foreach ($user->user_custom_profile_fields as $udata) {
                        /// If the profile field has data and the profile shortname-datatype is defined in server
                        if ($udata->field_data) {
                            if ($field = get_record('user_info_field', 'shortname', $udata->field_name, 'datatype', $udata->field_type)) {
                                /// Insert the user_custom_profile_field
                                $rec = new object();
                                $rec->userid = $newid;
                                $rec->fieldid = $field->id;
                                $rec->data = $udata->field_data;
                                insert_record('user_info_data', $rec);
                            }
                        }
                    }
                }
            }
            /// Here, if create_tags, do it as necessary
            if ($create_tags) {
                /// if tags are enabled and there are user tags
                if (!empty($CFG->usetags) && isset($user->user_tags)) {
                    $tags = array();
                    foreach ($user->user_tags as $user_tag) {
                        $tags[] = $user_tag->rawname;
                    }
                    tag_set('user', $newid, $tags);
                }
            }
            //Here, if create_preferences, do it as necessary
            if ($create_preferences) {
                if (isset($user->user_preferences)) {
                    foreach ($user->user_preferences as $user_preference) {
                        //We check if that user_preference exists in DB
                        if (!record_exists("user_preferences", "userid", $newid, "name", $user_preference->name)) {
                            //Prepare the record and insert it
                            $user_preference->userid = $newid;
                            $status = insert_record("user_preferences", $user_preference);
                        }
                    }
                }
            }
            //Do some output
            $counter++;
            if ($counter % 10 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if ($counter % 200 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
        /// End of loop over all the users loaded from backup_ids table
        /// Inform about all the messages geerated while restoring users
        if (!defined('RESTORE_SILENTLY')) {
            if ($messages) {
                echo '<ul>';
                foreach ($messages as $message) {
                    echo '<li>' . $message . '</li>';
                }
                echo '</ul>';
            }
        }
    }
    return $status;
}
/**
* Get an array with the languages
*
* @return array   The array with each language.
*/
function jclic_get_languages()
{
    global $CFG;
    $tmplanglist = get_list_of_languages();
    $langlist = array();
    foreach ($tmplanglist as $lang => $langname) {
        if (substr($lang, -5) == '_utf8') {
            //Remove the _utf8 suffix from the lang to show
            $lang = substr($lang, 0, -5);
        }
        $langlist[$lang] = $langname;
    }
    return $langlist;
}
Exemplo n.º 10
0
function restore_create_users($restore, $xml_file)
{
    global $CFG, $db;
    $status = true;
    //Check it exists
    if (!file_exists($xml_file)) {
        $status = false;
    }
    //Get info from xml
    if ($status) {
        //info will contain the old_id of every user
        //in backup_ids->info will be the real info (serialized)
        $info = restore_read_xml_users($restore, $xml_file);
    }
    //Now, get evey user_id from $info and user data from $backup_ids
    //and create the necessary records (users, user_students, user_teachers
    //user_course_creators and user_admins
    if (!empty($info->users)) {
        // Grab mnethosts keyed by wwwroot, to map to id
        $mnethosts = get_records('mnet_host', '', '', 'wwwroot', 'wwwroot, id');
        $languages = get_list_of_languages();
        foreach ($info->users as $userid) {
            $rec = backup_getid($restore->backup_unique_code, "user", $userid);
            $user = $rec->info;
            //Now, recode some languages (Moodle 1.5)
            if ($user->lang == 'ma_nt') {
                $user->lang = 'mi_nt';
            }
            //If language does not exist here - use site default
            if (!array_key_exists($user->lang, $languages)) {
                $user->lang = $CFG->lang;
            }
            //Check if it's admin and coursecreator
            $is_admin = !empty($user->roles['admin']);
            $is_coursecreator = !empty($user->roles['coursecreator']);
            //Check if it's teacher and student
            $is_teacher = !empty($user->roles['teacher']);
            $is_student = !empty($user->roles['student']);
            //Check if it's needed
            $is_needed = !empty($user->roles['needed']);
            //Calculate if it is a course user
            //Has role teacher or student or needed
            $is_course_user = ($is_teacher or $is_student or $is_needed);
            //Calculate mnethostid
            if (empty($user->mnethosturl) || $user->mnethosturl === $CFG->wwwroot) {
                $user->mnethostid = $CFG->mnet_localhost_id;
            } else {
                // fast url-to-id lookups
                if (isset($mnethosts[$user->mnethosturl])) {
                    $user->mnethostid = $mnethosts[$user->mnethosturl]->id;
                } else {
                    // should not happen, as we check in restore_chech.php
                    // but handle the error if it does
                    error("This backup file contains external Moodle Network Hosts that are not configured locally.");
                }
            }
            unset($user->mnethosturl);
            //To store new ids created
            $newid = null;
            //check if it exists (by username) and get its id
            $user_exists = true;
            $user_data = get_record("user", "username", addslashes($user->username), 'mnethostid', $user->mnethostid);
            if (!$user_data) {
                $user_exists = false;
            } else {
                $newid = $user_data->id;
            }
            //Flags to see if we have to create the user, roles and preferences
            $create_user = true;
            $create_roles = true;
            $create_preferences = true;
            //If we are restoring course users and it isn't a course user
            if ($restore->users == 1 and !$is_course_user) {
                //If only restoring course_users and user isn't a course_user, inform to $backup_ids
                $status = backup_putid($restore->backup_unique_code, "user", $userid, null, 'notincourse');
                $create_user = false;
                $create_roles = false;
                $create_preferences = false;
            }
            if ($user_exists and $create_user) {
                //If user exists mark its newid in backup_ids (the same than old)
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, 'exists');
                $create_user = false;
            }
            //Here, if create_user, do it
            if ($create_user) {
                //Unset the id because it's going to be inserted with a new one
                unset($user->id);
                //We addslashes to necessary fields
                $user->username = addslashes($user->username);
                $user->firstname = addslashes($user->firstname);
                $user->lastname = addslashes($user->lastname);
                $user->email = addslashes($user->email);
                $user->institution = addslashes($user->institution);
                $user->department = addslashes($user->department);
                $user->address = addslashes($user->address);
                $user->city = addslashes($user->city);
                $user->url = addslashes($user->url);
                $user->description = backup_todb($user->description);
                //We need to analyse the AUTH field to recode it:
                //   - if the field isn't set, we are in a pre 1.4 backup and we'll
                //     use manual
                if (empty($user->auth)) {
                    if ($CFG->registerauth == 'email') {
                        $user->auth = 'email';
                    } else {
                        $user->auth = 'manual';
                    }
                }
                //We need to process the POLICYAGREED field to recalculate it:
                //    - if the destination site is different (by wwwroot) reset it.
                //    - if the destination site is the same (by wwwroot), leave it unmodified
                if ($restore->original_wwwroot != $CFG->wwwroot) {
                    $user->policyagreed = 0;
                } else {
                    //Nothing to do, we are in the same server
                }
                //Check if the theme exists in destination server
                $themes = get_list_of_themes();
                if (!in_array($user->theme, $themes)) {
                    $user->theme = '';
                }
                //We are going to create the user
                //The structure is exactly as we need
                $newid = insert_record("user", $user);
                //Put the new id
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, "new");
            }
            //Here, if create_roles, do it as necessary
            if ($create_roles) {
                //Get the newid and current info from backup_ids
                $data = backup_getid($restore->backup_unique_code, "user", $userid);
                $newid = $data->new_id;
                $currinfo = $data->info . ",";
                //Now, depending of the role, create records in user_studentes and user_teacher
                //and/or mark it in backup_ids
                if ($is_admin) {
                    //If the record (user_admins) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "admin,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_coursecreator) {
                    //If the record (user_coursecreators) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "coursecreator,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_needed) {
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "needed,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_teacher) {
                    //If the record (teacher) doesn't exists
                    //Put status in backup_ids
                    $currinfo = $currinfo . "teacher,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['teacher']->course = $restore->course_id;
                    $user->roles['teacher']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['teacher']->enrol)) {
                        $user->roles['teacher']->enrol = $CFG->enrol;
                    } else {
                        if ($restore->original_wwwroot != $CFG->wwwroot) {
                            $user->roles['teacher']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    if ($user->roles['teacher']->editall) {
                        role_assign($rolesmapping['defaultteacheredit'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                        // editting teacher
                    } else {
                        // non editting teacher
                        role_assign($rolesmapping['defaultteacher'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                    }
                }
                if ($is_student) {
                    //Put status in backup_ids
                    $currinfo = $currinfo . "student,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['student']->course = $restore->course_id;
                    $user->roles['student']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['student']->enrol)) {
                        $user->roles['student']->enrol = $CFG->enrol;
                    } else {
                        if ($restore->original_wwwroot != $CFG->wwwroot) {
                            $user->roles['student']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    role_assign($rolesmapping['defaultstudent'], $newid, 0, $context->id, $user->roles['student']->timestart, $user->roles['student']->timeend, 0, $user->roles['student']->enrol);
                }
                if (!$is_course_user) {
                    //If the record (user) doesn't exists
                    if (!record_exists("user", "id", $newid)) {
                        //Put status in backup_ids
                        $currinfo = $currinfo . "user,";
                        $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    }
                }
            }
            //Here, if create_preferences, do it as necessary
            if ($create_preferences) {
                //echo "Checking for preferences of user ".$user->username."<br />";         //Debug
                //Get user new id from backup_ids
                $data = backup_getid($restore->backup_unique_code, "user", $userid);
                $newid = $data->new_id;
                if (isset($user->user_preferences)) {
                    //echo "Preferences exist in backup file<br />";                         //Debug
                    foreach ($user->user_preferences as $user_preference) {
                        //echo $user_preference->name." = ".$user_preference->value."<br />";    //Debug
                        //We check if that user_preference exists in DB
                        if (!record_exists("user_preferences", "userid", $newid, "name", $user_preference->name)) {
                            //echo "Creating it<br />";                                              //Debug
                            //Prepare the record and insert it
                            $user_preference->userid = $newid;
                            $status = insert_record("user_preferences", $user_preference);
                        }
                    }
                }
            }
        }
    }
    return $status;
}
Exemplo n.º 11
0
 /**
  * Make Custom Filter Options
  *
  * This function handles filters that require custom values (languages, countries, etc).
  *
  * @param string $group  The index of the group to which the sub filter belongs to.
  * @param string $name   The name of the sub filter to process.
  * @param array  $help   An array representing the help icon for the filter
  * @return array The customized options for the selected sub-filter
  */
 function make_filter_options_custom($options, $group, $name)
 {
     switch ($name) {
         case 'fullname':
             $firstname = $this->tables[$group]['user'] . '.firstname';
             $lastname = $this->tables[$group]['user'] . '.lastname';
             $options['dbfield'] = sql_concat($firstname, "' '", $lastname);
             $options['talias'] = '';
             $this->fieldtofiltermap[$group][$options['dbfield']] = generalized_filter_userprofilematch::filtertypetext;
             break;
         case 'country':
             // TBD: new 'country' filter spec???
             $countries = get_list_of_countries();
             $options['choices'] = $countries;
             // TBD: foreach assoc.
             //$this->err_dump($countries, '$countries');
             break;
         case 'confirmed':
             // TBD: yesno filter???
             $options['choices'] = array('0' => 'No', 1 => 'Yes');
             $options['numeric'] = 1;
             //$this->err_dump($myoptions['choices'],'options for confir
             break;
         case 'crsrole':
             $roles = get_records('role', '', '', '', 'id,name');
             $options['choices'] = array();
             foreach ($roles as $role) {
                 $options['choices'][$role->id] = $role->name;
             }
             $options['numeric'] = 1;
             $options['talias'] = $this->tables[$group]['role_assignments'];
             $options['dbfield'] = 'roleid';
             break;
         case 'lang':
             $options['choices'] = get_list_of_languages(true);
             // TBD
             //$this->err_dump($myoptions['choices'], 'list_of_languages
             break;
         case 'crscat':
             break;
         case 'sysrole':
             break;
         case 'auth':
             $auths = get_list_of_plugins('auth');
             //$this->err_dump($auths, '$auths');
             $options['choices'] = array();
             foreach ($auths as $auth) {
                 $options['choices'][$auth] = $auth;
                 // TBD
             }
             break;
     }
     if (array_key_exists($name, $this->_choices)) {
         $options['choices'] = $this->_choices[$name];
     }
     if (array_key_exists($name, $this->_fieldids)) {
         $options['fieldid'] = $this->_fieldids[$name];
     }
     return $options;
 }
Exemplo n.º 12
0
/**
 * Return the language options.
 */
function cm_get_list_of_languages()
{
    /// Get them from Moodle... Replace this if they should be something else.
    /// Should thie really rely on Moodle? Or should we provide our own?
    $languages = get_list_of_languages(false, true);
    return $languages;
}
Exemplo n.º 13
0
 /**
  * realizes the template (the standard way is to compile content fields 
  * in a HTML template. 
  */
 public function make_template($lang = '')
 {
     global $CFG, $USER, $COURSE;
     $content = '';
     $context = context_course::instance($COURSE->id);
     if (!empty($lang)) {
         $languages[] = $lang;
     } else {
         if (strpos(@$CFG->textfilters, 'filter/multilang') !== false || strpos(@$CFG->textfilters, 'filter/multilangenhanced') !== false) {
             // We have multilang.
             $languages = array_keys(get_list_of_languages());
         } else {
             $languages[] = current_language();
         }
     }
     $content = '';
     foreach ($languages as $lang) {
         $template = $this->get_template($lang);
         if (!$template && !empty($CFG->defaultlang)) {
             $template = $this->get_template($CFG->defaultlang);
         }
         if ($template) {
             $contentlang = "<span class=\"multilang\" lang=\"{$lang}\" >";
             $contentlang .= $this->process_conditional($template);
             $contentlang .= "</span>";
             if (!empty($this->data)) {
                 $CFG->multilang_target_language = $lang;
                 foreach ($this->data as $key => $value) {
                     if (is_array($value) || is_object($value)) {
                         continue;
                     }
                     if (file_exists($CFG->dirroot . '/filter/multilangenhanced/filter.php')) {
                         include_once $CFG->dirroot . '/filter/multilangenhanced/filter.php';
                         $filter = new filter_multilangenhanced($context, array());
                         $formattedvalue = preg_match('/option$/', $key) || preg_match('/^http?:\\/\\//', $value) ? $value : $filter->filter($value);
                     } else {
                         $formattedvalue = $value;
                     }
                     $contentlang = str_replace("<%%{$key}%%>", $formattedvalue, $contentlang);
                 }
                 // Cleanup any unused tags and final replacements.
                 $contentlang = str_replace("<%%WWWROOT%%>", $CFG->wwwroot, $contentlang);
                 $contentlang = str_replace("<%%COURSEID%%>", $COURSE->id, $contentlang);
                 $contentlang = str_replace("<%%USERID%%>", $USER->id, $contentlang);
                 $contentlang = preg_replace("/<%%.*?%%>/", '', $contentlang);
                 unset($CFG->multilang_target_language);
             }
         } else {
             $contentlang = "<span class=\"multilang\" lang=\"{$multilang}\" >";
             $contentlang .= get_string('nocontentforthislanguage', 'customlabel');
             $contentlang .= "</span>";
         }
         $content .= $contentlang;
     }
     return $content;
 }
Exemplo n.º 14
0
 function definition()
 {
     global $CFG;
     $templateuser = $this->_customdata;
     if (empty($templateuser)) {
         if (!($templateuser = get_admin())) {
             error('Could not find site admin');
         }
     }
     $mform =& $this->_form;
     $mform->addElement('file', 'userfile', get_string('file'));
     $mform->addRule('userfile', null, 'required');
     $mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'admin'));
     $mform->addElement('text', 'username', get_string('username'), 'size="20"');
     $modules = get_list_of_plugins('auth');
     $auth_options = array();
     foreach ($modules as $module) {
         $auth_options[$module] = get_string("auth_{$module}" . "title", "auth");
     }
     $mform->addElement('select', 'auth', get_string('chooseauthmethod', 'auth'), $auth_options);
     $mform->setDefault('auth', $templateuser->auth);
     $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod', 'auth')));
     $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
     $choices = array(get_string('emaildisplayno'), get_string('emaildisplayyes'), get_string('emaildisplaycourse'));
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
     $mform->setDefault('maildisplay', 2);
     $choices = array(get_string('emailenable'), get_string('emaildisable'));
     $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
     $choices = array(get_string('textformat'), get_string('htmlformat'));
     $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
     $mform->setDefault('mailformat', 1);
     $choices = array(get_string('autosubscribeyes'), get_string('autosubscribeno'));
     $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
     $mform->setDefault('autosubscribe', 1);
     if ($CFG->htmleditor) {
         $choices = array(get_string('texteditor'), get_string('htmleditor'));
         $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
         $mform->setDefault('htmleditor', 1);
     }
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
     $mform->setType('city', PARAM_MULTILANG);
     $mform->setDefault('city', $templateuser->city);
     $mform->addElement('select', 'country', get_string('selectacountry'), get_list_of_countries());
     $mform->setDefault('country', $templateuser->country);
     $choices = get_list_of_timezones();
     $choices['99'] = get_string('serverlocaltime');
     $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
     $mform->setDefault('timezone', $templateuser->timezone);
     $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
     $mform->setDefault('lang', $templateuser->lang);
     $mform->addElement('htmleditor', 'description', get_string('userdescription'));
     $mform->setType('description', PARAM_CLEAN);
     $mform->setHelpButton('description', array('text', get_string('helptext')));
     $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
     $mform->setType('institution', PARAM_MULTILANG);
     $mform->setDefault('institution', $templateuser->institution);
     $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
     $mform->setType('department', PARAM_MULTILANG);
     $mform->setDefault('department', $templateuser->department);
     $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
     $mform->setType('phone1', PARAM_CLEAN);
     $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
     $mform->setType('phone2', PARAM_CLEAN);
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
     $mform->setType('address', PARAM_MULTILANG);
     $mform->addElement('header', 'settingsheader', get_string('settings'));
     $choices = array(get_string('infilefield', 'auth'), get_string('createpasswordifneeded', 'auth'));
     $mform->addElement('select', 'createpassword', get_string('passwordhandling', 'auth'), $choices);
     $mform->addElement('selectyesno', 'updateaccounts', get_string('updateaccounts', 'admin'));
     $mform->addElement('selectyesno', 'allowrenames', get_string('allowrenames', 'admin'));
     $choices = array(get_string('addcounter', 'admin'), get_string('skipuser', 'admin'));
     $mform->addElement('select', 'duplicatehandling', get_string('newusernamehandling', 'admin'), $choices);
     $this->add_action_buttons(false, get_string('uploadusers'));
 }
Exemplo n.º 15
0
 function definition()
 {
     global $CFG, $USER;
     //no editors here - we need proper empty fields
     $CFG->htmleditor = null;
     $mform =& $this->_form;
     $columns =& $this->_customdata;
     // I am the template user, why should it be the administrator? we have roles now, other ppl may use this script ;-)
     $templateuser = $USER;
     // upload settings and file
     $mform->addElement('header', 'settingsheader', get_string('settings'));
     $choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'admin'), UU_ADDINC => get_string('uuoptype_addinc', 'admin'), UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'), UU_UPDATE => get_string('uuoptype_update', 'admin'));
     $mform->addElement('select', 'uutype', get_string('uuoptype', 'admin'), $choices);
     $choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
     $mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'admin'), $choices);
     $mform->setDefault('uupasswordnew', 0);
     $mform->disabledIf('uupasswordnew', 'uutype', 'eq', UU_UPDATE);
     $choices = array(0 => get_string('nochanges', 'admin'), 1 => get_string('uuupdatefromfile', 'admin'), 2 => get_string('uuupdateall', 'admin'), 3 => get_string('uuupdatemissing', 'admin'));
     $mform->addElement('select', 'uuupdatetype', get_string('uuupdatetype', 'admin'), $choices);
     $mform->setDefault('uuupdatetype', 0);
     $mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDNEW);
     $mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDINC);
     $choices = array(0 => get_string('nochanges', 'admin'), 1 => get_string('update'));
     $mform->addElement('select', 'uupasswordold', get_string('uupasswordold', 'admin'), $choices);
     $mform->setDefault('uupasswordold', 0);
     $mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDNEW);
     $mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDINC);
     $mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 0);
     $mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 3);
     $mform->addElement('selectyesno', 'uuallowrenames', get_string('allowrenames', 'admin'));
     $mform->setDefault('uuallowrenames', 0);
     $mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDNEW);
     $mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDINC);
     $mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'admin'));
     $mform->setDefault('uuallowdeletes', 0);
     $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDNEW);
     $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDINC);
     $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'admin'));
     $mform->setDefault('uunoemailduplicates', 0);
     $choices = array(0 => get_string('no'), 1 => get_string('uubulknew', 'admin'), 2 => get_string('uubulkupdated', 'admin'), 3 => get_string('uubulkall', 'admin'));
     $mform->addElement('select', 'uubulk', get_string('uubulk', 'admin'), $choices);
     $mform->setDefault('uubulk', 0);
     // roles selection
     $showroles = false;
     foreach ($columns as $column) {
         if (preg_match('/^type\\d+$/', $column)) {
             $showroles = true;
             break;
         }
     }
     if ($showroles) {
         $mform->addElement('header', 'rolesheader', get_string('roles'));
         $choices = uu_allowed_roles(true);
         $choices[0] = get_string('uucoursedefaultrole', 'admin');
         $mform->addElement('select', 'uulegacy1', get_string('uulegacy1role', 'admin'), $choices);
         $mform->setDefault('uulegacy1', 0);
         unset($choices[0]);
         $mform->addElement('select', 'uulegacy2', get_string('uulegacy2role', 'admin'), $choices);
         if ($editteacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) {
             $editteacherrole = array_shift($editteacherroles);
             /// Take the first one
             $mform->setDefault('uulegacy2', $editteacherrole->id);
             unset($editteacherroles);
         } else {
             $mform->setDefault('uulegacy2', $CFG->defaultcourseroleid);
         }
         $mform->addElement('select', 'uulegacy3', get_string('uulegacy3role', 'admin'), $choices);
         if ($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
             $teacherrole = array_shift($teacherroles);
             /// Take the first one
             $mform->setDefault('uulegacy3', $teacherrole->id);
             unset($teacherroles);
         } else {
             $mform->setDefault('uulegacy3', $CFG->defaultcourseroleid);
         }
     }
     // default values
     $mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'admin'));
     $mform->addElement('text', 'username', get_string('username'), 'size="20"');
     $mform->addRule('username', get_string('requiredtemplate', 'admin'), 'required', null, 'client');
     // only enabled and known to work plugins
     $choices = uu_allowed_auths();
     $mform->addElement('select', 'auth', get_string('chooseauthmethod', 'auth'), $choices);
     $mform->setDefault('auth', 'manual');
     // manual is a sensible backwards compatible default
     $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod', 'auth')));
     $mform->setAdvanced('auth');
     $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
     $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
     $mform->setDefault('maildisplay', 2);
     $choices = array(0 => get_string('emailenable'), 1 => get_string('emaildisable'));
     $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
     $choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
     $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
     $mform->setDefault('mailformat', 1);
     $mform->setAdvanced('mailformat');
     $choices = array(0 => get_string('autosubscribeyes'), 1 => get_string('autosubscribeno'));
     $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
     $mform->setDefault('autosubscribe', 1);
     if ($CFG->htmleditor) {
         $choices = array(0 => get_string('texteditor'), 1 => get_string('htmleditor'));
         $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
         $mform->setDefault('htmleditor', 1);
     } else {
         $mform->addElement('static', 'htmleditor', get_string('textediting'), get_string('texteditor'));
     }
     $mform->setAdvanced('htmleditor');
     if (empty($CFG->enableajax)) {
         $mform->addElement('static', 'ajax', get_string('ajaxuse'), get_string('ajaxno'));
     } else {
         $choices = array(0 => get_string('ajaxno'), 1 => get_string('ajaxyes'));
         $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
         $mform->setDefault('ajax', 1);
     }
     $mform->setAdvanced('ajax');
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
     $mform->setType('city', PARAM_MULTILANG);
     $mform->setDefault('city', $templateuser->city);
     $mform->addElement('select', 'country', get_string('selectacountry'), get_list_of_countries());
     $mform->setDefault('country', $templateuser->country);
     $mform->setAdvanced('country');
     $choices = get_list_of_timezones();
     $choices['99'] = get_string('serverlocaltime');
     $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
     $mform->setDefault('timezone', $templateuser->timezone);
     $mform->setAdvanced('timezone');
     $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
     $mform->setDefault('lang', $templateuser->lang);
     $mform->setAdvanced('lang');
     $mform->addElement('htmleditor', 'description', get_string('userdescription'));
     $mform->setType('description', PARAM_CLEAN);
     $mform->setHelpButton('description', array('text', get_string('helptext')));
     $mform->setAdvanced('description');
     $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
     $mform->setAdvanced('url');
     $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
     $mform->setType('idnumber', PARAM_CLEAN);
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
     $mform->setType('institution', PARAM_MULTILANG);
     $mform->setDefault('institution', $templateuser->institution);
     $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
     $mform->setType('department', PARAM_MULTILANG);
     $mform->setDefault('department', $templateuser->department);
     $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
     $mform->setType('phone1', PARAM_CLEAN);
     $mform->setAdvanced('phone1');
     $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
     $mform->setType('phone2', PARAM_CLEAN);
     $mform->setAdvanced('phone2');
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
     $mform->setType('address', PARAM_MULTILANG);
     $mform->setAdvanced('address');
     /// Next the profile defaults
     profile_definition($mform);
     // hidden fields
     $mform->addElement('hidden', 'iid');
     $mform->setType('iid', PARAM_INT);
     $mform->addElement('hidden', 'previewrows');
     $mform->setType('previewrows', PARAM_INT);
     $mform->addElement('hidden', 'readcount');
     $mform->setType('readcount', PARAM_INT);
     $this->add_action_buttons(true, get_string('uploadusers'));
 }
Exemplo n.º 16
0
/**
 * This function will search for browser prefereed languages, setting Moodle
 * to use the best one available if $SESSION->lang is undefined
 */
function setup_lang_from_browser()
{
    global $CFG, $SESSION, $USER;
    if (!empty($SESSION->lang) or !empty($USER->lang) or empty($CFG->autolang)) {
        // Lang is defined in session or user profile, nothing to do
        return;
    }
    if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        // There isn't list of browser langs, nothing to do
        return;
    }
    /// Extract and clean langs from headers
    $rawlangs = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $rawlangs = str_replace('-', '_', $rawlangs);
    // we are using underscores
    $rawlangs = explode(',', $rawlangs);
    // Convert to array
    $langs = array();
    $order = 1.0;
    foreach ($rawlangs as $lang) {
        if (strpos($lang, ';') === false) {
            $langs[(string) $order] = $lang;
            $order = $order - 0.01;
        } else {
            $parts = explode(';', $lang);
            $pos = strpos($parts[1], '=');
            $langs[substr($parts[1], $pos + 1)] = $parts[0];
        }
    }
    krsort($langs, SORT_NUMERIC);
    $langlist = get_list_of_languages();
    /// Look for such langs under standard locations
    foreach ($langs as $lang) {
        $lang = strtolower(clean_param($lang . '_utf8', PARAM_SAFEDIR));
        // clean it properly for include
        if (!array_key_exists($lang, $langlist)) {
            continue;
            // language not allowed, try next one
        }
        if (file_exists($CFG->dataroot . '/lang/' . $lang) or file_exists($CFG->dirroot . '/lang/' . $lang)) {
            $SESSION->lang = $lang;
            /// Lang exists, set it in session
            break;
            /// We have finished. Go out
        }
    }
    return;
}
Exemplo n.º 17
0
 function definition()
 {
     global $USER, $CFG;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $category = $this->_customdata['category'];
     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
     $disable_meta = false;
     // basic meta course state protection; server-side security checks not needed
     if (!empty($course)) {
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         $context = $coursecontext;
         if (course_in_meta($course)) {
             $disable_meta = get_string('metaalreadyinmeta');
         } else {
             if ($course->metacourse) {
                 if (count_records('course_meta', 'parent_course', $course->id) > 0) {
                     $disable_meta = get_string('metaalreadyhascourses');
                 }
             } else {
                 $managers = count(get_users_by_capability($coursecontext, 'moodle/course:managemetacourse'));
                 $participants = count(get_users_by_capability($coursecontext, 'moodle/course:view'));
                 if ($participants > $managers) {
                     $disable_meta = get_string('metaalreadyhasenrolments');
                 }
             }
         }
     } else {
         $coursecontext = null;
         $context = $categorycontext;
     }
     /// form definition with new course defaults
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     //must have create course capability in both categories in order to move course
     if (has_capability('moodle/course:create', $categorycontext)) {
         $displaylist = array();
         $parentlist = array();
         make_categories_list($displaylist, $parentlist);
         foreach ($displaylist as $key => $val) {
             if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $key))) {
                 unset($displaylist[$key]);
             }
         }
         $mform->addElement('select', 'category', get_string('category'), $displaylist);
     } else {
         $mform->addElement('hidden', 'category', null);
     }
     $mform->setHelpButton('category', array('coursecategory', get_string('category')));
     $mform->setDefault('category', $category->id);
     $mform->setType('category', PARAM_INT);
     $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
     $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
     $mform->setDefault('fullname', get_string('defaultcoursefullname'));
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_MULTILANG);
     $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="100" size="20"');
     $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
     $mform->setDefault('shortname', get_string('defaultcourseshortname'));
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_MULTILANG);
     $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100"  size="10"');
     $mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
     $mform->setType('idnumber', PARAM_RAW);
     $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65'));
     $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
     $mform->setDefault('summary', get_string('defaultcoursesummary'));
     $mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
     $mform->setType('summary', PARAM_RAW);
     $courseformats = get_list_of_plugins('course/format');
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
         if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
             $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
     $mform->setDefault('format', 'weeks');
     for ($i = 1; $i <= 52; $i++) {
         $sectionmenu[$i] = "{$i}";
     }
     $mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
     $mform->setDefault('numsections', 10);
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->setHelpButton('startdate', array('coursestartdate', get_string('startdate')), true);
     $mform->setDefault('startdate', time() + 3600 * 24);
     $choices = array();
     $choices['0'] = get_string('hiddensectionscollapsed');
     $choices['1'] = get_string('hiddensectionsinvisible');
     $mform->addElement('select', 'hiddensections', get_string('hiddensections'), $choices);
     $mform->setHelpButton('hiddensections', array('coursehiddensections', get_string('hiddensections')), true);
     $mform->setDefault('hiddensections', 0);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->setHelpButton('newsitems', array('coursenewsitems', get_string('newsitemsnumber')), true);
     $mform->setDefault('newsitems', 5);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->setHelpButton('showgrades', array('coursegrades', get_string('grades')), true);
     $mform->setDefault('showgrades', 1);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->setHelpButton('showreports', array('coursereports', get_string('activityreport')), true);
     $mform->setDefault('showreports', 0);
     $choices = get_max_upload_sizes($CFG->maxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->setHelpButton('maxbytes', array('courseuploadsize', get_string('maximumupload')), true);
     if (!empty($CFG->allowcoursethemes)) {
         $themes = array();
         $themes[''] = get_string('forceno');
         $themes += get_list_of_themes();
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $meta = array();
     $meta[0] = get_string('no');
     $meta[1] = get_string('yes');
     if ($disable_meta === false) {
         $mform->addElement('select', 'metacourse', get_string('managemeta'), $meta);
         $mform->setHelpButton('metacourse', array('metacourse', get_string('metacourse')), true);
         $mform->setDefault('metacourse', 0);
     } else {
         // no metacourse element - we do not want to change it anyway!
         $mform->addElement('static', 'nometacourse', get_string('managemeta'), (empty($course->metacourse) ? $meta[0] : $meta[1]) . " - {$disable_meta} ");
         $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'enrolhdr', get_string('enrolments'));
     $choices = array();
     $modules = explode(',', $CFG->enrol_plugins_enabled);
     foreach ($modules as $module) {
         $name = get_string('enrolname', "enrol_{$module}");
         $plugin = enrolment_factory::factory($module);
         if (method_exists($plugin, 'print_entry')) {
             $choices[$name] = $module;
         }
     }
     asort($choices);
     $choices = array_flip($choices);
     $choices = array_merge(array('' => get_string('sitedefault') . ' (' . get_string('enrolname', "enrol_{$CFG->enrol}") . ')'), $choices);
     $mform->addElement('select', 'enrol', get_string('enrolmentplugins'), $choices);
     $mform->setHelpButton('enrol', array('courseenrolmentplugins', get_string('enrolmentplugins')), true);
     $roles = get_assignable_roles($context);
     if (!empty($course)) {
         // add current default role, so that it is selectable even when user can not assign it
         if ($current_role = get_record('role', 'id', $course->defaultrole)) {
             $roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
         }
     }
     $choices = array();
     if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) {
         $choices[0] = get_string('sitedefault') . ' (' . $sitedefaultrole->name . ')';
     } else {
         $choices[0] = get_string('sitedefault');
     }
     $choices = $choices + $roles;
     // fix for MDL-9197
     foreach ($choices as $choiceid => $choice) {
         $choices[$choiceid] = format_string($choice);
     }
     $mform->addElement('select', 'defaultrole', get_string('defaultrole', 'role'), $choices);
     $mform->setDefault('defaultrole', 0);
     $radio = array();
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('no'), 0);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('yes'), 1);
     $radio[] =& MoodleQuickForm::createElement('radio', 'enrollable', null, get_string('enroldate'), 2);
     $mform->addGroup($radio, 'enrollable', get_string('enrollable'), ' ', false);
     $mform->setHelpButton('enrollable', array('courseenrollable2', get_string('enrollable')), true);
     $mform->setDefault('enrollable', 1);
     $enroldatestartgrp = array();
     $enroldatestartgrp[] =& MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
     $enroldatestartgrp[] =& MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
     $mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false);
     $mform->setDefault('enrolstartdate', 0);
     $mform->setDefault('enrolstartdisabled', 1);
     $mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked');
     $enroldateendgrp = array();
     $enroldateendgrp[] =& MoodleQuickForm::createElement('date_selector', 'enrolenddate');
     $enroldateendgrp[] =& MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
     $mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
     $mform->setDefault('enrolenddate', 0);
     $mform->setDefault('enrolenddisabled', 1);
     $mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked');
     $periodmenu = array();
     $periodmenu[0] = get_string('unlimited');
     for ($i = 1; $i <= 365; $i++) {
         $seconds = $i * 86400;
         $periodmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'enrolperiod', get_string('enrolperiod'), $periodmenu);
     $mform->setDefault('enrolperiod', 0);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'expirynotifyhdr', get_string('expirynotify'));
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'expirynotify', get_string('notify'), $choices);
     $mform->setHelpButton('expirynotify', array('expirynotify', get_string('expirynotify')), true);
     $mform->setDefault('expirynotify', 0);
     $mform->addElement('select', 'notifystudents', get_string('expirynotifystudents'), $choices);
     $mform->setHelpButton('notifystudents', array('expirynotifystudents', get_string('expirynotifystudents')), true);
     $mform->setDefault('notifystudents', 0);
     $thresholdmenu = array();
     for ($i = 1; $i <= 30; $i++) {
         $seconds = $i * 86400;
         $thresholdmenu[$seconds] = get_string('numdays', '', $i);
     }
     $mform->addElement('select', 'expirythreshold', get_string('expirythreshold'), $thresholdmenu);
     $mform->setHelpButton('expirythreshold', array('expirythreshold', get_string('expirythreshold')), true);
     $mform->setDefault('expirythreshold', 10 * 86400);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('no');
     $choices[SEPARATEGROUPS] = get_string('separate');
     $choices[VISIBLEGROUPS] = get_string('visible');
     $mform->addElement('select', 'groupmode', get_string('groupmode'), $choices);
     $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')), true);
     $mform->setDefault('groupmode', 0);
     $choices = array();
     $choices['0'] = get_string('no');
     $choices['1'] = get_string('yes');
     $mform->addElement('select', 'groupmodeforce', get_string('force'), $choices);
     $mform->setHelpButton('groupmodeforce', array('groupmodeforce', get_string('groupmodeforce')), true);
     $mform->setDefault('groupmodeforce', 0);
     if (!empty($CFG->enablegroupings)) {
         //default groupings selector
         $options = array();
         $options[0] = get_string('none');
         $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('availability'));
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $mform->addElement('select', 'visible', get_string('availability'), $choices);
     $mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
     $mform->setDefault('visible', 1);
     $mform->addElement('passwordunmask', 'enrolpassword', get_string('enrolmentkey'), 'size="25"');
     $mform->setHelpButton('enrolpassword', array('enrolmentkey', get_string('enrolmentkey')), true);
     $mform->setDefault('enrolpassword', '');
     $mform->setType('enrolpassword', PARAM_RAW);
     $choices = array();
     $choices['0'] = get_string('guestsno');
     $choices['1'] = get_string('guestsyes');
     $choices['2'] = get_string('guestskey');
     $mform->addElement('select', 'guest', get_string('opentoguests'), $choices);
     $mform->setHelpButton('guest', array('guestaccess', get_string('opentoguests')), true);
     $mform->setDefault('guest', 0);
     // If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
     $enrol_object = $CFG;
     if (!empty($course)) {
         $enrol_object = $course;
     }
     if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && $enrol_object->enrol != 'manual') {
         $costgroup = array();
         $currencies = get_list_of_currencies();
         $costgroup[] =& MoodleQuickForm::createElement('text', 'cost', '', 'maxlength="6" size="6"');
         $costgroup[] =& MoodleQuickForm::createElement('select', 'currency', '', $currencies);
         $mform->addGroup($costgroup, 'costgrp', get_string('cost'), '&nbsp;', false);
         //defining a rule for a form element within a group :
         $costgrprules = array();
         //set the message to null to tell Moodle to use a default message
         //available for most rules, fetched from language pack (err_{rulename}).
         $costgrprules['cost'][] = array(null, 'numeric', null, 'client');
         $mform->addGroupRule('costgrp', $costgrprules);
         $mform->setHelpButton('costgrp', array('cost', get_string('cost')), true);
         $mform->setDefault('cost', '');
         $mform->setDefault('currency', empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
     }
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('language'));
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_list_of_languages();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     //--------------------------------------------------------------------------------
     if (has_capability('moodle/site:config', $systemcontext) && (!empty($course->requested) && $CFG->restrictmodulesfor == 'requested' || $CFG->restrictmodulesfor == 'all')) {
         $mform->addElement('header', '', get_string('restrictmodules'));
         $options = array();
         $options['0'] = get_string('no');
         $options['1'] = get_string('yes');
         $mform->addElement('select', 'restrictmodules', get_string('restrictmodules'), $options);
         $mods = array(0 => get_string('allownone'));
         $mods += get_records_menu('modules', '', '', '', 'id, name');
         $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple' => 'multiple', 'size' => '10'));
         $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
     } else {
         $mform->addElement('hidden', 'restrictmodules', null);
     }
     if ($CFG->restrictmodulesfor == 'all') {
         $mform->setDefault('allowedmods', explode(',', $CFG->defaultallowedmodules));
         if (!empty($CFG->restrictbydefault)) {
             $mform->setDefault('restrictmodules', 1);
         }
     }
     $mform->setType('restrictmodules', PARAM_INT);
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', '', get_string('roles'));
     if ($roles = get_records('role')) {
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, $role->name);
             if ($coursecontext) {
                 if ($rolename = get_record('role_names', 'roleid', $role->id, 'contextid', $coursecontext->id)) {
                     $mform->setDefault('role_' . $role->id, $rolename->text);
                 }
             }
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     // fill in default teacher and student names to keep backwards compatibility for a while
     $mform->addElement('hidden', 'teacher', get_string('defaultcourseteacher'));
     $mform->addElement('hidden', 'teachers', get_string('defaultcourseteachers'));
     $mform->addElement('hidden', 'student', get_string('defaultcoursestudent'));
     $mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
 }
Exemplo n.º 18
0
function restore_create_users($restore, $xml_file)
{
    global $CFG, $db;
    require_once $CFG->dirroot . '/tag/lib.php';
    $status = true;
    //Check it exists
    if (!file_exists($xml_file)) {
        $status = false;
    }
    //Get info from xml
    if ($status) {
        //info will contain the old_id of every user
        //in backup_ids->info will be the real info (serialized)
        $info = restore_read_xml_users($restore, $xml_file);
    }
    //Now, get evey user_id from $info and user data from $backup_ids
    //and create the necessary db structures
    if (!empty($info->users)) {
        /// Grab mnethosts keyed by wwwroot, to map to id
        $mnethosts = get_records('mnet_host', '', '', 'wwwroot', 'wwwroot, id');
        /// Get languages for quick search later
        $languages = get_list_of_languages();
        /// Iterate over all users loaded from xml
        $counter = 0;
        /// Init trailing messages
        $messages = array();
        foreach ($info->users as $userid) {
            $rec = backup_getid($restore->backup_unique_code, "user", $userid);
            $user = $rec->info;
            foreach (array_keys(get_object_vars($user)) as $field) {
                if (!is_array($user->{$field})) {
                    $user->{$field} = backup_todb($user->{$field});
                    if (is_null($user->{$field})) {
                        $user->{$field} = '';
                    }
                }
            }
            //Now, recode some languages (Moodle 1.5)
            if ($user->lang == 'ma_nt') {
                $user->lang = 'mi_nt';
            }
            //Country list updates - MDL-13060
            //Any user whose country code has been deleted or modified needs to be assigned a valid one.
            $country_update_map = array('ZR' => 'CD', 'TP' => 'TL', 'FX' => 'FR', 'KO' => 'RS', 'CS' => 'RS', 'WA' => 'GB');
            if (array_key_exists($user->country, $country_update_map)) {
                $user->country = $country_update_map[$user->country];
            }
            //If language does not exist here - use site default
            if (!array_key_exists($user->lang, $languages)) {
                $user->lang = $CFG->lang;
            }
            //Check if it's admin and coursecreator
            $is_admin = !empty($user->roles['admin']);
            $is_coursecreator = !empty($user->roles['coursecreator']);
            //Check if it's teacher and student
            $is_teacher = !empty($user->roles['teacher']);
            $is_student = !empty($user->roles['student']);
            //Check if it's needed
            $is_needed = !empty($user->roles['needed']);
            //Calculate if it is a course user
            //Has role teacher or student or needed
            $is_course_user = ($is_teacher or $is_student or $is_needed);
            // in case we are restoring to same server, look for user by id
            // it should return record always, but in sites rebuilt from scratch
            // and being reconstructed using course backups
            $user_data = false;
            if (backup_is_same_site($restore)) {
                $user_data = get_record('user', 'id', $user->id);
            }
            // Only try to perform mnethost/auth modifications if restoring to another server
            // or if, while restoring to same server, the user doesn't exists yet (rebuilt site)
            //
            // So existing user data in same server *won't be modified by restore anymore*,
            // under any circumpstance. If somehting is wrong with existing data, it's server fault.
            if (!backup_is_same_site($restore) || backup_is_same_site($restore) && !$user_data) {
                //Calculate mnethostid
                if (empty($user->mnethosturl) || $user->mnethosturl === $CFG->wwwroot) {
                    $user->mnethostid = $CFG->mnet_localhost_id;
                } else {
                    // fast url-to-id lookups
                    if (isset($mnethosts[$user->mnethosturl])) {
                        $user->mnethostid = $mnethosts[$user->mnethosturl]->id;
                    } else {
                        $user->mnethostid = $CFG->mnet_localhost_id;
                    }
                }
                //Arriving here, any user with mnet auth and using $CFG->mnet_localhost_id is wrong
                //as own server cannot be accesed over mnet. Change auth to manual and inform about the switch
                if ($user->auth == 'mnet' && $user->mnethostid == $CFG->mnet_localhost_id) {
                    // Respect registerauth
                    if ($CFG->registerauth == 'email') {
                        $user->auth = 'email';
                    } else {
                        $user->auth = 'manual';
                    }
                    // inform about the automatic switch of authentication/host
                    if (empty($user->mnethosturl)) {
                        $user->mnethosturl = '----';
                    }
                    $messages[] = get_string('mnetrestore_extusers_switchuserauth', 'admin', $user);
                }
            }
            unset($user->mnethosturl);
            //To store user->id along all the iteration
            $newid = null;
            //check if it exists (by username) and get its id
            $user_exists = true;
            if (!backup_is_same_site($restore)) {
                /// Restoring to another server, look for existing user based on fields
                /// If restoring to same server, look has been performed some lines above (by id)
                $user_data = get_record('user', 'username', addslashes($user->username), 'mnethostid', $user->mnethostid);
            }
            if (!$user_data) {
                $user_exists = false;
            } else {
                $newid = $user_data->id;
            }
            //Flags to see what parts are we going to restore
            $create_user = true;
            $create_roles = true;
            $create_custom_profile_fields = true;
            $create_tags = true;
            $create_preferences = true;
            //If we are restoring course users and it isn't a course user
            if ($restore->users == 1 and !$is_course_user) {
                //If only restoring course_users and user isn't a course_user, inform to $backup_ids
                $status = backup_putid($restore->backup_unique_code, "user", $userid, null, 'notincourse');
                $create_user = false;
                $create_roles = false;
                $create_custom_profile_fields = false;
                $create_tags = false;
                $create_preferences = false;
            }
            if ($user_exists and $create_user) {
                //If user exists mark its newid in backup_ids (the same than old)
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, 'exists');
                $create_user = false;
                $create_custom_profile_fields = false;
                $create_tags = false;
                $create_preferences = false;
            }
            //Here, if create_user, do it
            if ($create_user) {
                //Unset the id because it's going to be inserted with a new one
                unset($user->id);
                // relink the descriptions
                $user->description = stripslashes($user->description);
                /// Disable pictures based on global setting or existing empty value (old backups can contain wrong empties)
                if (!empty($CFG->disableuserimages) || empty($user->picture)) {
                    $user->picture = 0;
                }
                //We need to analyse the AUTH field to recode it:
                //   - if the field isn't set, we are in a pre 1.4 backup and we'll
                //     use manual
                if (empty($user->auth)) {
                    if ($CFG->registerauth == 'email') {
                        $user->auth = 'email';
                    } else {
                        $user->auth = 'manual';
                    }
                }
                //We need to process the POLICYAGREED field to recalculate it:
                //    - if the destination site is different (by wwwroot) reset it.
                //    - if the destination site is the same (by wwwroot), leave it unmodified
                if (!backup_is_same_site($restore)) {
                    $user->policyagreed = 0;
                } else {
                    //Nothing to do, we are in the same server
                }
                //Check if the theme exists in destination server
                $themes = get_list_of_themes();
                if (!in_array($user->theme, $themes)) {
                    $user->theme = '';
                }
                //We are going to create the user
                //The structure is exactly as we need
                $newid = insert_record("user", addslashes_recursive($user));
                //Put the new id
                $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, "new");
            }
            ///TODO: This seccion is to support pre 1.7 course backups, using old roles
            ///      teacher, coursecreator, student.... providing a basic mapping to new ones.
            ///      Someday we'll drop support for them and this section will be safely deleted (2.0?)
            //Here, if create_roles, do it as necessary
            if ($create_roles) {
                //Get the newid and current info from backup_ids
                $data = backup_getid($restore->backup_unique_code, "user", $userid);
                $newid = $data->new_id;
                $currinfo = $data->info . ",";
                //Now, depending of the role, create records in user_studentes and user_teacher
                //and/or mark it in backup_ids
                if ($is_admin) {
                    //If the record (user_admins) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "admin,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_coursecreator) {
                    //If the record (user_coursecreators) doesn't exists
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "coursecreator,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_needed) {
                    //Only put status in backup_ids
                    $currinfo = $currinfo . "needed,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                }
                if ($is_teacher) {
                    //If the record (teacher) doesn't exists
                    //Put status in backup_ids
                    $currinfo = $currinfo . "teacher,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['teacher']->course = $restore->course_id;
                    $user->roles['teacher']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['teacher']->enrol)) {
                        $user->roles['teacher']->enrol = $CFG->enrol;
                    } else {
                        if (!backup_is_same_site($restore)) {
                            $user->roles['teacher']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    if ($user->roles['teacher']->editall) {
                        role_assign($rolesmapping['defaultteacheredit'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                        // editting teacher
                    } else {
                        // non editting teacher
                        role_assign($rolesmapping['defaultteacher'], $newid, 0, $context->id, $user->roles['teacher']->timestart, $user->roles['teacher']->timeend, 0, $user->roles['teacher']->enrol);
                    }
                }
                if ($is_student) {
                    //Put status in backup_ids
                    $currinfo = $currinfo . "student,";
                    $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    //Set course and user
                    $user->roles['student']->course = $restore->course_id;
                    $user->roles['student']->userid = $newid;
                    //Need to analyse the enrol field
                    //    - if it isn't set, set it to $CFG->enrol
                    //    - if we are in a different server (by wwwroot), set it to $CFG->enrol
                    //    - if we are in the same server (by wwwroot), maintain it unmodified.
                    if (empty($user->roles['student']->enrol)) {
                        $user->roles['student']->enrol = $CFG->enrol;
                    } else {
                        if (!backup_is_same_site($restore)) {
                            $user->roles['student']->enrol = $CFG->enrol;
                        } else {
                            //Nothing to do. Leave it unmodified
                        }
                    }
                    $rolesmapping = $restore->rolesmapping;
                    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
                    role_assign($rolesmapping['defaultstudent'], $newid, 0, $context->id, $user->roles['student']->timestart, $user->roles['student']->timeend, 0, $user->roles['student']->enrol);
                }
                if (!$is_course_user) {
                    //If the record (user) doesn't exists
                    if (!record_exists("user", "id", $newid)) {
                        //Put status in backup_ids
                        $currinfo = $currinfo . "user,";
                        $status = backup_putid($restore->backup_unique_code, "user", $userid, $newid, $currinfo);
                    }
                }
            }
            /// Here, if create_custom_profile_fields, do it as necessary
            if ($create_custom_profile_fields) {
                if (isset($user->user_custom_profile_fields)) {
                    foreach ($user->user_custom_profile_fields as $udata) {
                        /// If the profile field has data and the profile shortname-datatype is defined in server
                        if ($udata->field_data) {
                            if ($field = get_record('user_info_field', 'shortname', $udata->field_name, 'datatype', $udata->field_type)) {
                                /// Insert the user_custom_profile_field
                                $rec = new object();
                                $rec->userid = $newid;
                                $rec->fieldid = $field->id;
                                $rec->data = $udata->field_data;
                                insert_record('user_info_data', $rec);
                            }
                        }
                    }
                }
            }
            /// Here, if create_tags, do it as necessary
            if ($create_tags) {
                /// if tags are enabled and there are user tags
                if (!empty($CFG->usetags) && isset($user->user_tags)) {
                    $tags = array();
                    foreach ($user->user_tags as $user_tag) {
                        $tags[] = $user_tag->rawname;
                    }
                    tag_set('user', $newid, $tags);
                }
            }
            //Here, if create_preferences, do it as necessary
            if ($create_preferences) {
                if (isset($user->user_preferences)) {
                    foreach ($user->user_preferences as $user_preference) {
                        //We check if that user_preference exists in DB
                        if (!record_exists("user_preferences", "userid", $newid, "name", $user_preference->name)) {
                            //Prepare the record and insert it
                            $user_preference->userid = $newid;
                            $status = insert_record("user_preferences", $user_preference);
                        }
                    }
                }
            }
            //Do some output
            $counter++;
            if ($counter % 10 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if ($counter % 200 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
        /// End of loop over all the users loaded from xml
        /// Inform about all the messages geerated while restoring users
        if (!defined('RESTORE_SILENTLY')) {
            if ($messages) {
                echo '<ul>';
                foreach ($messages as $message) {
                    echo '<li>' . $message . '</li>';
                }
                echo '</ul>';
            }
        }
    }
    return $status;
}
 /**
  * realizes the template (the standard way is to compile content fields 
  * in a HTML template. 
  */
 function make_template($lang = '')
 {
     global $CFG, $USER;
     $content = '';
     if (!empty($lang)) {
         $languages[] = $lang;
     } else {
         if (strpos(@$CFG->textfilters, 'filter/multilang') !== false) {
             // we have multilang
             $languages = array_keys(get_list_of_languages());
         } else {
             $languages[] = current_language();
         }
     }
     $content = '';
     foreach ($languages as $lang) {
         $template = $this->get_template($lang);
         if (!$template && !empty($CFG->defaultlang)) {
             $template = $this->get_template($CFG->defaultlang);
         }
         if ($template) {
             $contentlang = "<span class=\"multilang\" lang=\"{$lang}\" >";
             $contentlang .= $this->process_conditional($template);
             $contentlang .= "</span>";
             // $contentlang = str_replace("'", "\\'", $contentlang);
             if (!empty($this->data)) {
                 $CFG->multilang_target_language = $lang;
                 foreach ($this->data as $key => $value) {
                     if (is_array($value)) {
                         continue;
                     }
                     if (file_exists($CFG->wwwroot . '/filter/multilangenhanced/filter.php')) {
                         include_once $CFG->wwwroot . '/filter/multilangenhanced/filter.php';
                         $formattedvalue = preg_match('/option$/', $key) || preg_match('/^http?:\\/\\//', $value) ? $value : $filter->filter($value);
                     } else {
                         $formattedvalue = $value;
                     }
                     $contentlang = str_replace("<%%{$key}%%>", $formattedvalue, $contentlang);
                 }
                 // cleanup any unused tags
                 $contentlang = preg_replace("/<%%.*?%%>/", '', $contentlang);
                 unset($CFG->multilang_target_language);
             }
         } else {
             $contentlang = "<span class=\"multilang\" lang=\"{$multilang}\" >";
             $contentlang .= get_string('nocontentforthislanguage', 'customlabel');
             $contentlang .= "</span>";
         }
         $content .= $contentlang;
     }
     return $content;
 }
Exemplo n.º 20
0
<?php

// $Id$
// This file defines settingpages and externalpages under the "appearance" category
if ($hassiteconfig or has_capability('moodle/site:langeditmaster', $systemcontext) or has_capability('moodle/site:langeditlocal', $systemcontext)) {
    // speedup for non-admins, add all caps used on this page
    // "languageandlocation" settingpage
    $temp = new admin_settingpage('langsettings', get_string('languagesettings', 'admin'));
    $temp->add(new admin_setting_configcheckbox('autolang', get_string('autolang', 'admin'), get_string('configautolang', 'admin'), 1));
    $temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), current_language(), get_list_of_languages()));
    // $CFG->lang might be set in installer already, default en or en_utf8 is in setup.php
    $temp->add(new admin_setting_configcheckbox('langmenu', get_string('langmenu', 'admin'), get_string('configlangmenu', 'admin'), 1));
    $temp->add(new admin_setting_langlist());
    $temp->add(new admin_setting_configcheckbox('langcache', get_string('langcache', 'admin'), get_string('configlangcache', 'admin'), 1));
    $temp->add(new admin_setting_configtext('locale', get_string('localetext', 'admin'), get_string('configlocale', 'admin'), '', PARAM_FILE));
    // new CFG variable for excel encoding
    $temp->add(new admin_setting_configselect('latinexcelexport', get_string('latinexcelexport', 'admin'), get_string('configlatinexcelexport', 'admin'), '0', array('0' => 'Unicode', '1' => 'Latin')));
    $ADMIN->add('language', $temp);
    $ADMIN->add('language', new admin_externalpage('langedit', get_string('langedit', 'admin'), "{$CFG->wwwroot}/{$CFG->admin}/lang.php", array('moodle/site:langeditmaster', 'moodle/site:langeditlocal')));
    $ADMIN->add('language', new admin_externalpage('langimport', get_string('langpacks', 'admin'), "{$CFG->wwwroot}/{$CFG->admin}/langimport.php"));
}
// end of speedup
Exemplo n.º 21
0
     if (empty($CFG->registerauth)) {
         $register_users_enabled = FALSE;
     } else {
         $authplugin = get_auth_plugin($CFG->registerauth);
         if ($authplugin) {
             if (!$authplugin->can_signup()) {
                 $register_users_enabled = FALSE;
             }
         } else {
             $register_users_enabled = TRUE;
         }
     }
 }
 $json_output["version"] = $server_files_version;
 $json_output["server_language"] = $CFG->lang;
 $json_output["language_list"] = get_list_of_languages();
 $json_output["user_registration_enabled"] = $register_users_enabled;
 $json_output["guest_login_enabled"] = !empty($CFG->guestloginbutton);
 $json_output["https_login_required"] = $CFG->loginhttps;
 $json_output["sitefullname"] = $SITE->fullname;
 $json_output["siteshortname"] = $SITE->shortname;
 $json_output["sitesummary"] = $SITE->summary;
 $frontpagelayout = $CFG->frontpageloggedin;
 foreach (explode(',', $frontpagelayout) as $v) {
     switch ($v) {
         case FRONTPAGENEWS:
             $json_output["frontpage_news"] = TRUE;
             break;
         case FRONTPAGECOURSELIST:
             $json_output["frontpage_courselist"] = TRUE;
             break;
Exemplo n.º 22
0
                if ($blockobj->cron()) {
                    if (!set_field('block', 'lastcron', $timenow, 'id', $block->id)) {
                        mtrace('Error: could not update timestamp for ' . $block->name);
                    }
                }
                /// Reset possible changes by blocks to time_limit. MDL-11597
                @set_time_limit(0);
                mtrace('done.');
            }
        }
    }
}
mtrace('Finished blocks');
if (!empty($CFG->langcache)) {
    mtrace('Updating languages cache');
    get_list_of_languages(true);
}
mtrace('Removing expired enrolments ...', '');
// See MDL-8785
$timenow = time();
$somefound = false;
// The preferred way saves memory, dmllib.php
// find courses where limited enrolment is enabled
global $CFG;
$rs_enrol = get_recordset_sql("SELECT ra.roleid, ra.userid, ra.contextid\n        FROM {$CFG->prefix}course c\n        INNER JOIN {$CFG->prefix}context cx ON cx.instanceid = c.id\n        INNER JOIN {$CFG->prefix}role_assignments ra ON ra.contextid = cx.id\n        WHERE cx.contextlevel = '" . CONTEXT_COURSE . "'\n        AND ra.timeend > 0\n        AND ra.timeend < '{$timenow}'\n        AND c.enrolperiod > 0\n        ");
while ($oldenrolment = rs_fetch_next_record($rs_enrol)) {
    role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid);
    $somefound = true;
}
rs_close($rs_enrol);
if ($somefound) {
Exemplo n.º 23
0
function useredit_shared_definition(&$mform)
{
    global $CFG, $USER;
    $user = get_record('user', 'id', $USER->id);
    useredit_load_preferences($user, false);
    $strrequired = get_string('required');
    $nameordercheck = new object();
    $nameordercheck->firstname = 'a';
    $nameordercheck->lastname = 'b';
    if (fullname($nameordercheck) == 'b a') {
        // See MDL-4325
        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
    } else {
        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
    }
    $mform->addRule('firstname', $strrequired, 'required', null, 'client');
    $mform->setType('firstname', PARAM_NOTAGS);
    $mform->addRule('lastname', $strrequired, 'required', null, 'client');
    $mform->setType('lastname', PARAM_NOTAGS);
    // Do not show email field if change confirmation is pending
    if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
        $notice = get_string('auth_emailchangepending', 'auth', $user);
        $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('auth_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');
    }
    $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('emailenable');
    $choices['1'] = get_string('emaildisable');
    $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
    $mform->setDefault('emailenable', 1);
    $choices = array();
    $choices['0'] = get_string('textformat');
    $choices['1'] = get_string('htmlformat');
    $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
    $mform->setDefault('mailformat', 1);
    $mform->setAdvanced('mailformat');
    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);
        $mform->setAdvanced('preference_mailcharset');
    }
    $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->setAdvanced('maildigest');
    $choices = array();
    $choices['1'] = get_string('autosubscribeyes');
    $choices['0'] = get_string('autosubscribeno');
    $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
    $mform->setDefault('autosubscribe', 1);
    $mform->setAdvanced('autosubscribe');
    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);
        $mform->setAdvanced('trackforums');
    }
    if ($CFG->htmleditor) {
        $choices = array();
        $choices['0'] = get_string('texteditor');
        $choices['1'] = get_string('htmleditor');
        $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
        $mform->setDefault('htmleditor', 1);
        $mform->setAdvanced('htmleditor');
    }
    if (empty($CFG->enableajax)) {
        $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
        $mform->setAdvanced('ajaxdisabled');
    } else {
        $choices = array();
        $choices['0'] = get_string('ajaxno');
        $choices['1'] = get_string('ajaxyes');
        $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
        $mform->setDefault('ajax', 0);
        $mform->setAdvanced('ajax');
    }
    $choices = array();
    $choices['0'] = get_string('screenreaderno');
    $choices['1'] = get_string('screenreaderyes');
    $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
    $mform->setDefault('screenreader', 0);
    $mform->setAdvanced('screenreader');
    $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"');
    $mform->setType('city', PARAM_MULTILANG);
    $mform->addRule('city', $strrequired, 'required', null, 'client');
    $choices = get_list_of_countries();
    $choices = array('' => get_string('selectacountry') . '...') + $choices;
    $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
    $mform->addRule('country', $strrequired, 'required', null, 'client');
    if (!empty($CFG->country)) {
        $mform->setDefault('country', $CFG->country);
    }
    $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_list_of_languages());
    $mform->setDefault('lang', $CFG->lang);
    if (!empty($CFG->allowuserthemes)) {
        $choices = array();
        $choices[''] = get_string('default');
        $choices += get_list_of_themes();
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
        $mform->setAdvanced('theme');
    }
    $mform->addElement('htmleditor', 'description', get_string('userdescription'));
    $mform->setType('description', PARAM_CLEAN);
    $mform->setHelpButton('description', array('text', get_string('helptext')));
    if (!empty($CFG->gdversion)) {
        $mform->addElement('header', 'moodle_picture', get_string('pictureof'));
        //TODO: Accessibility fix fieldset legend
        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
        $mform->setDefault('deletepicture', false);
        $mform->addElement('file', 'imagefile', get_string('newpicture'));
        $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
        $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
        $mform->setType('imagealt', PARAM_MULTILANG);
    }
    if (!empty($CFG->usetags)) {
        $mform->addElement('header', 'moodle_interests', get_string('interests'));
        $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
        $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'), false, true, false));
    }
    /// Moodle optional fields
    $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
    $mform->setAdvanced('moodle_optional');
    $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_CLEAN);
    $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
    $mform->setType('skype', PARAM_CLEAN);
    $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
    $mform->setType('aim', PARAM_CLEAN);
    $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
    $mform->setType('yahoo', PARAM_CLEAN);
    $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
    $mform->setType('msn', PARAM_CLEAN);
    $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
    $mform->setType('idnumber', PARAM_CLEAN);
    $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
    $mform->setType('institution', PARAM_MULTILANG);
    $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
    $mform->setType('department', PARAM_MULTILANG);
    $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
    $mform->setType('phone1', PARAM_CLEAN);
    $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
    $mform->setType('phone2', PARAM_CLEAN);
    $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
    $mform->setType('address', PARAM_MULTILANG);
}
Exemplo n.º 24
0
    if (isadmin() && moodle_needs_upgrading()) {
        redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
    }
}
if (get_moodle_cookie() == '') {
    set_moodle_cookie('nobody');
    // To help search for cookies on login page
}
if (!empty($USER->id)) {
    add_to_log(SITEID, 'course', 'view', 'view.php?id=' . SITEID, SITEID);
}
if (empty($CFG->langmenu)) {
    $langmenu = '';
} else {
    $currlang = current_language();
    $langs = get_list_of_languages();
    $langlabel = get_accesshide(get_string('language'));
    $langmenu = popup_form($CFG->wwwroot . '/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
}
$PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
$pageblocks = blocks_setup($PAGE);
$editing = $PAGE->user_is_editing();
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
print_header($SITE->fullname, $SITE->fullname, 'home', '', '<meta name="description" content="' . strip_tags(format_text($SITE->summary, FORMAT_HTML)) . '" />', true, '', user_login_string($SITE) . $langmenu);
?>


<table id="layout-table" summary="layout">
  <tr>
  <?php 
function game_detectlanguage($word)
{
    global $CFG;
    $langs = get_list_of_languages();
    foreach ($langs as $lang => $name) {
        $langfile = "{$CFG->dirroot}/mod/game/lang/{$lang}/game.php";
        if (file_exists($langfile)) {
            for ($i = 1; $i <= 2; $i++) {
                if ($result = get_string_from_file('lettersall' . $i, $langfile, "\$letters")) {
                    eval($result);
                    if ($letters != '') {
                        $word2 = game_upper($word, $lang);
                        if (hangman_existall($word2, $letters)) {
                            return $lang;
                        }
                    }
                }
            }
        }
    }
    return false;
}