function get_options($dataobject)
{
$result = array();
//get list of theme objects
$themes = get_list_of_themes();
foreach ($themes as $theme) {
//we just need the name of each theme
$result[$theme->name] = $theme->name;
}
//option for not setting a cluster theme
$unset_option = array('' => get_string('unset_theme_option', 'elisfields_manual'));
return $unset_option + $result;
}
开发者ID:jamesmcq,项目名称:elis,代码行数:13,代码来源:themes.php
示例4: definition
function definition() {
global $CFG, $DB;
$mform =& $this->_form;
$category = $this->_customdata['category'];
$editoroptions = $this->_customdata['editoroptions'];
// get list of categories to use as parents, with site as the first one
$options = array();
if (has_capability('moodle/category:manage', context_system::instance()) || $category->parent == 0) {
$options[0] = get_string('top');
}
if ($category->id) {
// Editing an existing category.
$options += coursecat::make_categories_list('moodle/category:manage', $category->id);
if (empty($options[$category->parent])) {
$options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
}
$strsubmit = get_string('savechanges');
} else {
// Making a new category
$options += coursecat::make_categories_list('moodle/category:manage');
$strsubmit = get_string('createcategory');
}
$mform->addElement('select', 'parent', get_string('parentcategory'), $options);
$mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
$mform->addRule('name', get_string('required'), 'required', null);
$mform->setType('name', PARAM_TEXT);
$mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercoursecategory');
$mform->setType('idnumber', PARAM_RAW);
$mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);
if (!empty($CFG->allowcategorythemes)) {
$themes = array(''=>get_string('forceno'));
$allthemes = get_list_of_themes();
foreach ($allthemes as $key=>$theme) {
if (empty($theme->hidefromselector)) {
$themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
}
}
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
}
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $category->id);
$this->add_action_buttons(true, $strsubmit);
}
//.........这里部分代码省略.........
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 = 'not cached';
// If Moodle is responsible for storing/validating pwd and reset functionality is available, mark
} else {
if ($userauth->isinternal and $userauth->canresetpwd) {
$user->password = 'restored';
}
}
}
//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);
}
/**
* Given one restoreid, create in DB all the users present
* in backup_ids having newitemid = 0, as far as
* precheck_included_users() have left them there
* ready to be created. Also, annotate their newids
* once created for later reference
*/
public static function create_included_users($basepath, $restoreid, $userid)
{
global $CFG, $DB;
$authcache = array();
// Cache to get some bits from authentication plugins
$languages = get_string_manager()->get_list_of_translations();
// Get languages for quick search later
$themes = get_list_of_themes();
// Get themes for quick search later
// Iterate over all the included users with newitemid = 0, have to create them
$rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $restoreid, 'itemname' => 'user', 'newitemid' => 0), '', 'itemid, parentitemid');
foreach ($rs as $recuser) {
$user = (object) self::get_backup_ids_record($restoreid, 'user', $recuser->itemid)->info;
// if user lang doesn't exist here, use site default
if (!array_key_exists($user->lang, $languages)) {
$user->lang = $CFG->lang;
}
// if user theme isn't available on target site or they are disabled, reset theme
if (!empty($user->theme)) {
if (empty($CFG->allowuserthemes) || !in_array($user->theme, $themes)) {
$user->theme = '';
}
}
// if user to be created has mnet auth and its mnethostid is $CFG->mnet_localhost_id
// that's 100% impossible as own server cannot be accesed over mnet. Change auth to email/manual
if ($user->auth == 'mnet' && $user->mnethostid == $CFG->mnet_localhost_id) {
// Respect registerauth
if ($CFG->registerauth == 'email') {
$user->auth = 'email';
} else {
$user->auth = 'manual';
}
}
unset($user->mnethosturl);
// Not needed anymore
// Disable pictures based on global setting
if (!empty($CFG->disableuserimages)) {
$user->picture = 0;
}
// We need to analyse the AUTH field to recode it:
// - 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 (!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 = 'not cached';
// If Moodle is responsible for storing/validating pwd and reset functionality is available, mark
} else {
if ($userauth->isinternal and $userauth->canresetpwd) {
$user->password = 'restored';
}
}
}
// Creating new user, we must reset the policyagreed always
$user->policyagreed = 0;
// Set time created if empty
if (empty($user->timecreated)) {
$user->timecreated = time();
}
// Done, let's create the user and annotate its id
$newuserid = $DB->insert_record('user', $user);
self::set_backup_ids_record($restoreid, 'user', $recuser->itemid, $newuserid);
// Let's create the user context and annotate it (we need it for sure at least for files)
// but for deleted users that don't have a context anymore (MDL-30192). We are done for them
//.........这里部分代码省略.........
//.........这里部分代码省略.........
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,";
请发表评论