$CFG->wwwroot = "http://localhost";
$CFG->httpswwwroot = $CFG->wwwroot;
$CFG->dataroot = str_replace('\\', '/', dirname(dirname(dirname(dirname(__FILE__)))).'/moodledata');
+$CFG->tempdir = $CFG->dataroot.'/temp';
+$CFG->cachedir = $CFG->dataroot.'/temp';
$CFG->docroot = 'http://docs.moodle.org';
$CFG->running_installer = true;
$CFG->early_install_lang = true;
$action = clam_handle_infected_file($file,$log->userid,true);
clam_replace_infected_file($file);
+ list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
+ $sql = "SELECT c.id, c.fullname $ctxselect FROM {course} c $ctxjoin WHERE c.id = :courseid";
+ $course = $DB->get_record_sql($sql, array('courseid' => $log->course));
+ context_instance_preload($course);
+
$user = $DB->get_record("user", array("id"=>$log->userid));
- $course = $DB->get_record("course", array("id"=>$log->course));
$subject = get_string('virusfoundsubject','moodle',format_string($site->fullname));
$a->date = userdate($log->time);
$a->action = $action;
- $a->course = $course->fullname;
+ $a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$a->user = fullname($user);
notify_user($user,$subject,$a);
if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) {
set_time_limit(0);
- make_upload_directory('temp');
+ make_temp_directory('');
make_upload_directory('lang');
$installer = new lang_installer($pack);
}
}
- make_upload_directory('temp');
+ make_temp_directory('');
make_upload_directory('lang');
// clean-up currently installed versions of the packs
/// get a list of all courses on this site
- $courses = $DB->get_records('course');
+ list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
+ $sql = "SELECT c.* $ctxselect FROM {course} c $ctxjoin";
+ $courses = $DB->get_records_sql($sql);
/// cycle through each course
foreach ($courses as $course) {
+ context_instance_preload($course);
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $fullname = empty($course->fullname) ? 'Course: '.$course->id : $course->fullname;
+ if (empty($course->fullname)) {
+ $fullname = get_string('course').': '.$course->id;
+ } else {
+ $fullname = format_string($course->fullname, true, array('context' => $context));
+ }
if ($output) echo $OUTPUT->heading($fullname);
/// retrieve a list of sections beyond what is currently being shown
/// grab the section record
if (!($section = $DB->get_record('course_sections', array('id'=>$newsection)))) {
- if ($output) echo 'Serious error: Cannot retrieve section: '.$newsection.' for course: '. format_string($course->fullname) .'<br />';
+ if ($output) {
+ echo 'Serious error: Cannot retrieve section: '.$newsection.' for course: '. $fullname .'<br />';
+ }
continue;
}
/// grab the old section record
if (!($section = $DB->get_record('course_sections', array('id'=>$xsection->id)))) {
- if ($output) echo 'Serious error: Cannot retrieve old section: '.$xsection->id.' for course: '.$course->fullname.'<br />';
+ if ($output) echo 'Serious error: Cannot retrieve old section: '.$xsection->id.' for course: '.$fullname.'<br />';
continue;
}
$options = array();
foreach ($hubs as $hub) {
//to not display a name longer than 100 character (too big)
- if (strlen($hub['name']) > 100) {
- $hubname = substr($hub['name'], 0, 100);
+ if (textlib::strlen($hub['name']) > 100) {
+ $hubname = textlib::substr($hub['name'], 0, 100);
$hubname = $hubname . "...";
} else {
$hubname = $hub['name'];
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
$sitename = get_config('hub', 'site_name_' . $cleanhuburl);
if ($sitename === false) {
- $sitename = $site->fullname;
+ $sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
}
$sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
if ($sitedescription === false) {
$temp->add(new admin_setting_configcheckbox('navshowallcourses', get_string('navshowallcourses', 'admin'), get_string('confignavshowallcourses', 'admin'), 0));
$temp->add(new admin_setting_configtext('navcourselimit',get_string('navcourselimit','admin'),get_string('confignavcourselimit', 'admin'),20,PARAM_INT));
$temp->add(new admin_setting_configcheckbox('navlinkcoursesections', get_string('navlinkcoursesections', 'admin'), get_string('navlinkcoursesections_help', 'admin'), 0));
+ $temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', get_string('usesitenameforsitepages', 'admin'), get_string('configusesitenameforsitepages', 'admin'), 0));
$ADMIN->add('appearance', $temp);
$temp->add(new admin_setting_heading('automatedsettings', get_string('automatedsettings','backup'), ''));
- $temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('users'), get_string('backupusershelp'), 1));
+ $temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('generalusers', 'backup'), get_string('configgeneralusers', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', get_string('generalroleassignments','backup'), get_string('configgeneralroleassignments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_user_files', get_string('generaluserfiles', 'backup'), get_string('configgeneraluserfiles','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', get_string('generalactivities','backup'), get_string('configgeneralactivities','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_filters', get_string('generalfilters','backup'), get_string('configgeneralfilters','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_comments', get_string('generalcomments','backup'), get_string('configgeneralcomments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', get_string('generaluserscompletion','backup'), get_string('configgeneraluserscompletion','backup'), 1));
- $temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', get_string('logs'), get_string('backuplogshelp'), 0));
+ $temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', get_string('generallogs', 'backup'), get_string('configgenerallogs', 'backup'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', get_string('generalhistories','backup'), get_string('configgeneralhistories','backup'), 0));
$temp->add(new admin_setting_manageauths());
$temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), ''));
$temp->add(new admin_setting_special_registerauth());
+ $temp->add(new admin_setting_configcheckbox('authpreventaccountcreation', get_string('authpreventaccountcreation', 'admin'), get_string('authpreventaccountcreation_help', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('loginpageautofocus', get_string('loginpageautofocus', 'admin'), get_string('loginpageautofocus_help', 'admin'), 0));
$temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'),
get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show'))));
if (!$ok or !confirm_sesskey()) {
$message = '<br /><br />';
- $message .= $CFG->dataroot.'/temp/olson.txt<br />';
- $message .= $CFG->dataroot.'/temp/timezone.txt<br />';
+ $message .= $CFG->tempdir.'/olson.txt<br />';
+ $message .= $CFG->tempdir.'/timezone.txt<br />';
$message .= '<a href="http://download.moodle.org/timezone/">http://download.moodle.org/timezone/</a><br />';
$message .= '<a href="'.$CFG->wwwroot.'/lib/timezone.txt">'.$CFG->dirroot.'/lib/timezone.txt</a><br />';
$message .= '<br />';
/// First, look for an Olson file locally
- $source = $CFG->dataroot.'/temp/olson.txt';
+ $source = $CFG->tempdir.'/olson.txt';
if (!$importdone and is_readable($source)) {
if ($timezones = olson_to_timezones($source)) {
update_timezone_records($timezones);
/// Next, look for a CSV file locally
- $source = $CFG->dataroot.'/temp/timezone.txt';
+ $source = $CFG->tempdir.'/timezone.txt';
if (!$importdone and is_readable($source)) {
if ($timezones = get_records_csv($source, 'timezone')) {
update_timezone_records($timezones);
/// Otherwise, let's try moodle.org's copy
$source = 'http://download.moodle.org/timezone/';
if (!$importdone && ($content=download_file_content($source))) {
- if ($file = fopen($CFG->dataroot.'/temp/timezone.txt', 'w')) { // Make local copy
+ if ($file = fopen($CFG->tempdir.'/timezone.txt', 'w')) { // Make local copy
fwrite($file, $content);
fclose($file);
- if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezone.txt', 'timezone')) { // Parse it
+ if ($timezones = get_records_csv($CFG->tempdir.'/timezone.txt', 'timezone')) { // Parse it
update_timezone_records($timezones);
$importdone = $source;
}
- unlink($CFG->dataroot.'/temp/timezone.txt');
+ unlink($CFG->tempdir.'/timezone.txt');
}
}
// Create a unique temporary directory, to process the zip file
// contents.
- $zipdir = my_mktempdir($CFG->dataroot.'/temp/', 'usrpic');
+ $zipdir = my_mktempdir($CFG->tempdir.'/', 'usrpic');
$dstfile = $zipdir.'/images.zip';
if (!$mform->save_file('userpicturesfile', $dstfile, true)) {
<?php
-
/**
* Authentication Plugin: External Database Authentication
*
function user_login($username, $password) {
global $CFG, $DB;
- $textlib = textlib_get_instance();
- $extusername = $textlib->convert($username, 'utf-8', $this->config->extencoding);
- $extpassword = $textlib->convert($password, 'utf-8', $this->config->extencoding);
+ $extusername = textlib::convert($username, 'utf-8', $this->config->extencoding);
+ $extpassword = textlib::convert($password, 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
function db_init() {
// Connect to the external database (forcing new connection)
- $authdb = &ADONewConnection($this->config->type);
+ $authdb = ADONewConnection($this->config->type);
if (!empty($this->config->debugauthdb)) {
$authdb->debug = true;
ob_start();//start output buffer to allow later use of the page headers
}
/**
- * retuns user attribute mappings between moodle and ldap
+ * Returns user attribute mappings between moodle and ldap
*
* @return array
*/
function get_userinfo($username) {
global $CFG;
- $textlib = textlib_get_instance();
- $extusername = $textlib->convert($username, 'utf-8', $this->config->extencoding);
+ $extusername = textlib::convert($username, 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
$fields_obj = $rs->FetchObj();
$fields_obj = (object)array_change_key_case((array)$fields_obj , CASE_LOWER);
foreach ($selectfields as $localname=>$externalname) {
- $result[$localname] = $textlib->convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
+ $result[$localname] = textlib::convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
}
}
$rs->Close();
}
/**
- * syncronizes user fron external db to moodle user table
+ * synchronizes user from external db to moodle user table
*
- * Sync shouid be done by using idnumber attribute, not username.
+ * Sync should be done by using idnumber attribute, not username.
* You need to pass firstsync parameter to function to fill in
- * idnumbers if they dont exists in moodle user table.
+ * idnumbers if they don't exists in moodle user table.
*
- * Syncing users removes (disables) users that dont exists anymore in external db.
+ * Syncing users removes (disables) users that don't exists anymore in external db.
* Creates new users and updates coursecreator status of users.
*
* This implementation is simpler but less scalable than the one found in the LDAP module.
*
* @param bool $do_updates Optional: set to true to force an update of existing accounts
- * @return bool success
+ * @param bool $verbose
+ * @return int 0 means success, 1 means failure
*/
- function sync_users($do_updates=false) {
+ function sync_users($do_updates=false, $verbose=false) {
global $CFG, $DB;
-/// list external users
+ // list external users
$userlist = $this->get_userlist();
-/// delete obsolete internal users
+ // delete obsolete internal users
if (!empty($this->config->removeuser)) {
// find obsolete users
$remove_users = $DB->get_records_sql($sql, $params);
if (!empty($remove_users)) {
- print_string('auth_dbuserstoremove','auth_db', count($remove_users)); echo "\n";
+ if ($verbose) {
+ mtrace(print_string('auth_dbuserstoremove','auth_db', count($remove_users)));
+ }
foreach ($remove_users as $user) {
if ($this->config->removeuser == AUTH_REMOVEUSER_FULLDELETE) {
- if (delete_user($user)) {
- echo "\t"; print_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
- } else {
- echo "\t"; print_string('auth_dbdeleteusererror', 'auth_db', $user->username); echo "\n";
+ delete_user($user);
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
}
} else if ($this->config->removeuser == AUTH_REMOVEUSER_SUSPEND) {
$updateuser = new stdClass();
$updateuser->id = $user->id;
$updateuser->auth = 'nologin';
$DB->update_record('user', $updateuser);
- echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
+ }
}
}
}
if (!count($userlist)) {
// exit right here
// nothing else to do
- return true;
+ return 0;
}
///
FROM {user} u
WHERE u.auth=:authtype AND u.deleted=0 AND u.username {$in_sql}";
if ($update_users = $DB->get_records_sql($sql, $params)) {
- print "User entries to update: ". count($update_users). "\n";
+ if ($verbose) {
+ mtrace("User entries to update: ".count($update_users));
+ }
foreach ($update_users as $user) {
- echo "\t"; print_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id));
- if (!$this->update_user_record($user->username, $updatekeys)) {
- echo " - ".get_string('skipped');
+ if ($this->update_user_record($user->username, $updatekeys)) {
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
+ }
+ } else {
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id))." - ".get_string('skipped'));
+ }
}
- echo "\n";
}
unset($update_users); // free memory
}
unset($usernames);
if (!empty($add_users)) {
- print_string('auth_dbuserstoadd','auth_db',count($add_users)); echo "\n";
+ if ($verbose) {
+ mtrace(get_string('auth_dbuserstoadd','auth_db',count($add_users)));
+ }
$transaction = $DB->start_delegated_transaction();
foreach($add_users as $user) {
$username = $user;
if ($old_user = $DB->get_record('user', array('username'=>$user->username, 'deleted'=>1, 'mnethostid'=>$user->mnethostid))) {
$user->id = $old_user->id;
$DB->set_field('user', 'deleted', 0, array('username'=>$user->username));
- echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
+ }
} else {
- $id = $DB->insert_record ('user',$user); // it is truly a new user
- echo "\t"; print_string('auth_dbinsertuser','auth_db',array('name'=>$user->username, 'id'=>$id)); echo "\n";
+ $id = $DB->insert_record ('user', $user); // it is truly a new user
+ if ($verbose) {
+ mtrace("\t".get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)));
+ }
// if relevant, tag for password generation
if ($this->is_internal()) {
set_user_preference('auth_forcepasswordchange', 1, $id);
$transaction->allow_commit();
unset($add_users); // free mem
}
- return true;
+ return 0;
}
function user_exists($username) {
/// Init result value
$result = false;
- $textlib = textlib_get_instance();
- $extusername = $textlib->convert($username, 'utf-8', $this->config->extencoding);
+ $extusername = textlib::convert($username, 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
if (!$rs) {
print_error('auth_dbcantconnect','auth_db');
} else if (!$rs->EOF) {
- // user exists exterally
+ // user exists externally
$result = true;
}
}
/**
- * reads userinformation from DB and return it in an object
+ * reads user information from DB and return it in an object
*
* @param string $username username (with system magic quotes)
* @return array
* values removed from DB won't be removed from moodle.
*
* @param string $username username
+ * @param bool $updatekeys
+ * @return stdClass
*/
function update_user_record($username, $updatekeys=false) {
global $CFG, $DB;
//just in case check text case
- $username = trim(moodle_strtolower($username));
+ $username = trim(textlib::strtolower($username));
// get the current user record
$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id));
/**
* Called when the user record is updated.
* Modifies user in external database. It takes olduser (before changes) and newuser (after changes)
- * conpares information saved modified information to external db.
+ * compares information saved modified information to external db.
*
* @param mixed $olduser Userobject before modifications
* @param mixed $newuser Userobject new modified userobject
return false;
}
- $textlib = textlib_get_instance();
- $extusername = $textlib->convert($olduser->username, 'utf-8', $this->config->extencoding);
+ $extusername = textlib::convert($olduser->username, 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
}
$nuvalue = $newuser->$key;
if ($nuvalue != $value) {
- $update[] = $this->config->{"field_map_$key"}."='".$this->ext_addslashes($textlib->convert($nuvalue, 'utf-8', $this->config->extencoding))."'";
+ $update[] = $this->config->{"field_map_$key"}."='".$this->ext_addslashes(textlib::convert($nuvalue, 'utf-8', $this->config->extencoding))."'";
}
}
if (!empty($update)) {
/**
* A chance to validate form data, and last chance to
* do stuff before it is inserted in config_plugin
+ *
+ * @param stfdClass config form
+ * @param array $error errors
+ * @return void
*/
- function validate_form(&$form, &$err) {
+ function validate_form($form, &$err) {
if ($form->passtype === 'internal') {
$this->config->changepasswordurl = '';
set_config('changepasswordurl', '', 'auth/db');
* This function is called from admin/auth.php, and outputs a full page with
* a form for configuring this plugin.
*
- * @param array $page An object containing all the data for this page.
+ * @param stdClass $config
+ * @param array $err errors
+ * @param array $user_fields
+ * @return void
*/
function config_form($config, $err, $user_fields) {
include 'config.html';
/**
* Processes and stores configuration data for this authentication plugin.
+ * @param srdClass $config
+ * @return bool always true or exception
*/
function process_config($config) {
// set to defaults if undefined
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
require_once($CFG->dirroot.'/course/lib.php');
+require_once($CFG->libdir.'/clilib.php');
+
+// now get cli options
+list($options, $unrecognized) = cli_get_params(array('noupdate'=>false, 'verbose'=>false, 'help'=>false), array('n'=>'noupdate', 'v'=>'verbose', 'h'=>'help'));
+
+if ($unrecognized) {
+ $unrecognized = implode("\n ", $unrecognized);
+ cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
+}
+
+if ($options['help']) {
+ $help =
+"Execute user account sync with external database.
+The auth_db plugin must be enabled and properly configured.
+
+Options:
+-n, --noupdate Skip update of existing users
+-v, --verbose Print verbose progess information
+-h, --help Print out this help
+
+Example:
+\$sudo -u www-data /usr/bin/php auth/db/cli/sync_users.php
+
+Sample cron entry:
+# 5 minutes past 4am
+5 4 * * * $sudo -u www-data /usr/bin/php /var/www/moodle/auth/db/cli/sync_users.php
+";
+
+ echo $help;
+ die;
+}
if (!is_enabled_auth('db')) {
echo "Plugin not enabled!";
- die;
+ exit(1);
}
+$verbose = !empty($options['verbose']);
+$update = empty($options['noupdate']);
+
$dbauth = get_auth_plugin('db');
-$dbauth->sync_users(true);
+return $dbauth->sync_users($update, $verbose);
<tr valign="top" class="required">
<td align="right"><label for="menutype"><?php print_string("auth_dbtype_key", "auth_db") ?></label></td>
<td>
- <?php $dbtypes = array("access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
+ <?php $dbtypes = array("access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mssqlnative", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
foreach ($dbtypes as $dbtype) {
$dboptions[$dbtype] = $dbtype;
}
$fetchrequest->add_param($localuser->username);
if ($fetchrequest->send($remotepeer) === true) {
if (strlen($fetchrequest->response['f1']) > 0) {
- $imagefilename = $CFG->dataroot . '/temp/mnet-usericon-' . $localuser->id;
+ $imagefilename = $CFG->tempdir . '/mnet-usericon-' . $localuser->id;
$imagecontents = base64_decode($fetchrequest->response['f1']);
file_put_contents($imagefilename, $imagecontents);
if (process_new_icon($usercontext, 'user', 'icon', 0, $imagefilename)) {
*
*/
function logoutpage_hook() {
- global $redirect;
+ global $SESSION, $redirect;
- // Only do this if logout handler is defined
- if (
- isset($this->config->logout_handler)
- && !empty($this->config->logout_handler)
- ){
+ // Only do this if logout handler is defined, and if the user is actually logged in via Shibboleth
+ $logouthandlervalid = isset($this->config->logout_handler) && !empty($this->config->logout_handler);
+ if (isset($SESSION->shibboleth_session_id) && $logouthandlervalid ) {
// Check if there is an alternative logout return url defined
- if (
- isset($this->config->logout_return_url)
- && !empty($this->config->logout_return_url)
- ){
+ if (isset($this->config->logout_return_url) && !empty($this->config->logout_return_url)) {
// Set temp_redirect to alternative return url
$temp_redirect = $this->config->logout_return_url;
} else {
$heading = get_string('backupcourse', 'backup', $course->shortname);
break;
case backup::TYPE_1SECTION :
- require_capability('moodle/backup:backupsection', get_context_instance(CONTEXT_COURSE, $course->id));
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/backup:backupsection', $coursecontext);
if (!empty($section->name)) {
- $heading = get_string('backupsection', 'backup', $section->name);
- $PAGE->navbar->add($section->name);
+ $sectionname = format_string($section->name, true, array('context' => $coursecontext));
+ $heading = get_string('backupsection', 'backup', $sectionname);
+ $PAGE->navbar->add($sectionname);
} else {
$heading = get_string('backupsection', 'backup', $section->section);
$PAGE->navbar->add(get_string('section').' '.$section->section);
//Build the message subject
$site = get_site();
- $prefix = $site->shortname.": ";
+ $prefix = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))).": ";
if ($count_error != 0 || $count_unfinished != 0) {
$prefix .= "[".strtoupper(get_string('error'))."] ";
}
protected function apply_defaults() {
$this->log('applying plan defaults', backup::LOG_DEBUG);
- backup_controller_dbops::apply_general_config_defaults($this);
+ backup_controller_dbops::apply_config_defaults($this);
$this->set_status(backup::STATUS_CONFIGURED);
}
}
*/
class restore_controller extends backup implements loggable {
- protected $tempdir; // Directory under dataroot/temp/backup awaiting restore
+ protected $tempdir; // Directory under tempdir/backup awaiting restore
protected $restoreid; // Unique identificator for this restore
protected $courseid; // courseid where restore is going to happen
/**
*
- * @param string $tempdir Directory under dataroot/temp/backup awaiting restore
+ * @param string $tempdir Directory under tempdir/backup awaiting restore
* @param int $courseid Course id where restore is going to happen
* @param bool $interactive backup::INTERACTIVE_YES[true] or backup::INTERACTIVE_NO[false]
* @param int $mode backup::MODE_[ GENERAL | HUB | IMPORT | SAMESITE ]
public function get_workdir_path() {
global $CFG;
- return "$CFG->dataroot/temp/backup/$this->workdir";
+ return "$CFG->tempdir/backup/$this->workdir";
}
/**
public function get_tempdir_path() {
global $CFG;
- return "$CFG->dataroot/temp/backup/$this->tempdir";
+ return "$CFG->tempdir/backup/$this->tempdir";
}
/// public static methods //////////////////////////////////////////////////
public static function detect_format($tempdir) {
global $CFG;
- $filepath = $CFG->dataroot . '/temp/backup/' . $tempdir . '/moodle.xml';
+ $filepath = $CFG->tempdir . '/backup/' . $tempdir . '/moodle.xml';
if (file_exists($filepath)) {
// looks promising, lets load some information
$handle = fopen($filepath, 'r');
global $CFG;
$this->tempdir = convert_helper::generate_id('simpletest');
- check_dir_exists("$CFG->dataroot/temp/backup/$this->tempdir/course_files/sub1");
- check_dir_exists("$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/7");
+ check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
+ check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/moodle.xml",
- "$CFG->dataroot/temp/backup/$this->tempdir/moodle.xml"
+ "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->dataroot/temp/backup/$this->tempdir/course_files/file1.gif"
+ "$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->dataroot/temp/backup/$this->tempdir/course_files/sub1/file2.gif"
+ "$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/file1.gif"
+ "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/icon.gif"
+ "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
+ "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
);
}
public function tearDown() {
global $CFG;
if (empty($CFG->keeptempdirectoriesonbackup)) {
- fulldelete("$CFG->dataroot/temp/backup/$this->tempdir");
+ fulldelete("$CFG->tempdir/backup/$this->tempdir");
}
}
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/questions.xml",
- "$CFG->dataroot/temp/backup/$this->tempdir/moodle.xml"
+ "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->convert();
// Check whether the backup directory still exists. If missing, something
// went really wrong in backup, throw error. Note that backup::MODE_IMPORT
// backups don't store resulting files ever
- $tempdestination = $CFG->dataroot . '/temp/backup/' . $backupid;
+ $tempdestination = $CFG->tempdir . '/backup/' . $backupid;
if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
print_error('unknownbackupexporterror'); // shouldn't happen ever
}
$status = true;
//Get files and directories in the temp backup dir witout descend
- $list = get_directory_list($CFG->dataroot."/temp/backup", "", false, true, true);
+ $list = get_directory_list($CFG->tempdir."/backup", "", false, true, true);
foreach ($list as $file) {
- $file_path = $CFG->dataroot."/temp/backup/".$file;
+ $file_path = $CFG->tempdir."/backup/".$file;
$moddate = filemtime($file_path);
if ($status && $moddate < $delete_from) {
//If directory, recurse
function check_and_create_backup_dir($backup_unique_code) {
global $CFG;
- $status = check_dir_exists($CFG->dataroot."/temp",true);
+ $status = check_dir_exists($CFG->tempdir."",true);
if ($status) {
- $status = check_dir_exists($CFG->dataroot."/temp/backup",true);
+ $status = check_dir_exists($CFG->tempdir."/backup",true);
}
if ($status) {
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code,true);
+ $status = check_dir_exists($CFG->tempdir."/backup/".$backup_unique_code,true);
}
return $status;
function clear_backup_dir($backup_unique_code) {
global $CFG;
- $rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code;
+ $rootdir = $CFG->tempdir."/backup/".$backup_unique_code;
//Delete recursively
$status = delete_dir_contents($rootdir);
&& $DB->delete_records('backup_files', array('backup_code'=>$preferences->backup_unique_code));
//Now, delete temp directory (if exists)
- $file_path = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code;
+ $file_path = $CFG->tempdir."/backup/".$preferences->backup_unique_code;
if (is_dir($file_path)) {
$status = delete_dir_contents($file_path);
//There is nothing, delete the directory itself
if (strlen($info_ser) > $max_db_storage) {
//Calculate filename (in current_backup_dir, $backup_unique_code_$table_$old_id.info)
- $filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
+ $filename = $CFG->tempdir."/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
//Save data to file
$status = backup_data2file($filename,$info_ser);
//Set info_to save
//If info field = "infile", get file contents
if (!empty($status->info) && $status->info == "infile") {
- $filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
+ $filename = $CFG->tempdir."/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
//Read data from file
$status2 = backup_file2data($filename,$info);
if ($status2) {
$browser = get_file_browser();
// check if tmp dir exists
-$tmpdir = $CFG->dataroot . '/temp/backup';
+$tmpdir = $CFG->tempdir . '/backup';
if (!check_dir_exists($tmpdir, true, true)) {
throw new restore_controller_exception('cannot_create_backup_temp_dir');
}
// Note: all the checks along the function MUST be performed for $userid, that
// is the user who "requested" the course backup, not current $USER at all!!
- // First of all, check the main backup[course|section|activity] principal caps
- // Lacking the corresponding one makes this to break with exception always
+ // First of all, decide which caps/contexts are we going to check
+ // for common backups (general, automated...) based exclusively
+ // in the type (course, section, activity). And store them into
+ // one capability => context array structure
+ $typecapstocheck = array();
switch ($type) {
case backup::TYPE_1COURSE :
$DB->get_record('course', array('id' => $id), '*', MUST_EXIST); // course exists
- if (!has_capability('moodle/backup:backupcourse', $coursectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->courseid = $courseid;
- $a->capability = 'moodle/backup:backupcourse';
- throw new backup_controller_exception('backup_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/backup:backupcourse'] = $coursectx;
break;
case backup::TYPE_1SECTION :
$DB->get_record('course_sections', array('course' => $courseid, 'id' => $id), '*', MUST_EXIST); // sec exists
- if (!has_capability('moodle/backup:backupsection', $coursectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->courseid = $courseid;
- $a->capability = 'moodle/backup:backupsection';
- throw new backup_controller_exception('backup_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/backup:backupsection'] = $coursectx;
break;
case backup::TYPE_1ACTIVITY :
get_coursemodule_from_id(null, $id, $courseid, false, MUST_EXIST); // cm exists
$modulectx = get_context_instance(CONTEXT_MODULE, $id);
- if (!has_capability('moodle/backup:backupactivity', $modulectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->cmid = $id;
- $a->capability = 'moodle/backup:backupactivity';
- throw new backup_controller_exception('backup_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/backup:backupactivity'] = $modulectx;
break;
default :
- print_error('unknownbackuptype');
+ throw new backup_controller_exception('backup_unknown_backup_type', $type);
}
// Now, if backup mode is hub or import, check userid has permissions for those modes
+ // other modes will perform common checks only (backupxxxx capabilities in $typecapstocheck)
switch ($mode) {
case backup::MODE_HUB:
if (!has_capability('moodle/backup:backuptargethub', $coursectx, $userid)) {
throw new backup_controller_exception('backup_user_missing_capability', $a);
}
break;
+ // Common backup (general, automated...), let's check all the $typecapstocheck
+ // capability => context pairs
+ default:
+ foreach ($typecapstocheck as $capability => $context) {
+ if (!has_capability($capability, $context, $userid)) {
+ $a = new stdclass();
+ $a->userid = $userid;
+ $a->courseid = $courseid;
+ $a->capability = $capability;
+ throw new backup_controller_exception('backup_user_missing_capability', $a);
+ }
+ }
}
// Now, enforce 'moodle/backup:userinfo' to 'users' setting, applying changes if allowed,
}
// Check the user has the ability to configure the backup. If not then we need
- // to lock all settings by permission so that no changes can be made.
- $hasconfigcap = has_capability('moodle/backup:configure', $coursectx, $userid);
- if (!$hasconfigcap) {
- $settings = $backup_controller->get_plan()->get_settings();
- foreach ($settings as $setting) {
- if ($setting->get_name()=='filename') {
- continue;
+ // to lock all settings by permission so that no changes can be made. This does
+ // not apply to the import facility, where the activities must be always enabled
+ // to be able to pick them
+ if ($mode != backup::MODE_IMPORT) {
+ $hasconfigcap = has_capability('moodle/backup:configure', $coursectx, $userid);
+ if (!$hasconfigcap) {
+ $settings = $backup_controller->get_plan()->get_settings();
+ foreach ($settings as $setting) {
+ if ($setting->get_name() == 'filename') {
+ continue;
+ }
+ $setting->set_status(base_setting::LOCKED_BY_PERMISSION);
}
- $setting->set_status(base_setting::LOCKED_BY_PERMISSION);
}
}
// Note: all the checks along the function MUST be performed for $userid, that
// is the user who "requested" the course restore, not current $USER at all!!
- // First of all, check the main restore[course|section|activity] principal caps
- // Lacking the corresponding one makes this to break with exception always
+ // First of all, decide which caps/contexts are we going to check
+ // for common backups (general, automated...) based exclusively
+ // in the type (course, section, activity). And store them into
+ // one capability => context array structure
+ $typecapstocheck = array();
switch ($type) {
case backup::TYPE_1COURSE :
- if (!has_capability('moodle/restore:restorecourse', $coursectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->courseid = $courseid;
- $a->capability = 'moodle/restore:restorecourse';
- throw new restore_controller_exception('restore_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/restore:restorecourse'] = $coursectx;
break;
case backup::TYPE_1SECTION :
- if (!has_capability('moodle/restore:restoresection', $coursectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->courseid = $courseid;
- $a->capability = 'moodle/restore:restoresection';
- throw new restore_controller_exception('restore_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/restore:restoresection'] = $coursectx;
break;
case backup::TYPE_1ACTIVITY :
- if (!has_capability('moodle/restore:restoreactivity', $coursectx, $userid)) {
- $a = new stdclass();
- $a->userid = $userid;
- $a->courseid = $courseid;
- $a->capability = 'moodle/restore:restoreactivity';
- throw new restore_controller_exception('restore_user_missing_capability', $a);
- }
+ $typecapstocheck['moodle/restore:restoreactivity'] = $coursectx;
break;
default :
- print_error('unknownrestoretype');
+ throw new restore_controller_exception('restore_unknown_restore_type', $type);
}
// Now, if restore mode is hub or import, check userid has permissions for those modes
+ // other modes will perform common checks only (restorexxxx capabilities in $typecapstocheck)
switch ($mode) {
case backup::MODE_HUB:
if (!has_capability('moodle/restore:restoretargethub', $coursectx, $userid)) {
throw new restore_controller_exception('restore_user_missing_capability', $a);
}
break;
+ // Common backup (general, automated...), let's check all the $typecapstocheck
+ // capability => context pairs
+ default:
+ foreach ($typecapstocheck as $capability => $context) {
+ if (!has_capability($capability, $context, $userid)) {
+ $a = new stdclass();
+ $a->userid = $userid;
+ $a->courseid = $courseid;
+ $a->capability = $capability;
+ throw new restore_controller_exception('restore_user_missing_capability', $a);
+ }
+ }
}
// Now, enforce 'moodle/restore:userinfo' to 'users' setting, applying changes if allowed,
}
// Check the user has the ability to configure the restore. If not then we need
- // to lock all settings by permission so that no changes can be made.
- $hasconfigcap = has_capability('moodle/restore:configure', $coursectx, $userid);
- if (!$hasconfigcap) {
- $settings = $restore_controller->get_plan()->get_settings();
- foreach ($settings as $setting) {
- $setting->set_status(base_setting::LOCKED_BY_PERMISSION);
+ // to lock all settings by permission so that no changes can be made. This does
+ // not apply to the import facility, where all the activities (picked on backup)
+ // are restored automatically without restore UI
+ if ($mode != backup::MODE_IMPORT) {
+ $hasconfigcap = has_capability('moodle/restore:configure', $coursectx, $userid);
+ if (!$hasconfigcap) {
+ $settings = $restore_controller->get_plan()->get_settings();
+ foreach ($settings as $setting) {
+ $setting->set_status(base_setting::LOCKED_BY_PERMISSION);
+ }
}
}
return $DB->get_record('course', array('id' => $courseid), 'fullname, shortname, startdate');
}
+ /**
+ * Sets the default values for the settings in a backup operation
+ *
+ * Based on the mode of the backup it will delegate the process to
+ * other methods like {@link apply_general_config_defaults} ...
+ * to get proper defaults loaded
+ *
+ * @param backup_controller $controller
+ */
+ public static function apply_config_defaults(backup_controller $controller) {
+ // Based on the mode of the backup (general, automated, import, hub...)
+ // decide the action to perform to get defaults loaded
+ $mode = $controller->get_mode();
+
+ switch ($mode) {
+ case backup::MODE_GENERAL:
+ // Load the general defaults
+ self::apply_general_config_defaults($controller);
+ break;
+ case backup::MODE_AUTOMATED:
+ // TODO: Move the loading from automatic stuff to here
+ break;
+ default:
+ // Nothing to do for other modes (IMPORT/HUB...). Some day we
+ // can define defaults (admin UI...) for them if we want to
+ }
+ }
+
/**
* Sets the controller settings default values from the backup config.
*
* @param backup_controller $controller
*/
- public static function apply_general_config_defaults(backup_controller $controller) {
+ private static function apply_general_config_defaults(backup_controller $controller) {
$settings = array(
// Config name => Setting name
'backup_general_users' => 'users',
switch ($type) {
case backup::TYPE_1COURSE:
$shortname = $DB->get_field('course', 'shortname', array('id' => $id));
+ $context = get_context_instance(CONTEXT_COURSE, $id);
+ $shortname = format_string($shortname, true, array('context' => $context));
break;
case backup::TYPE_1SECTION:
if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) {
// Create file_logger, observing $CFG->backup_file_logger_level
// defaulting to $dfltloglevel
- check_dir_exists($CFG->dataroot . '/temp/backup', true, true); // need to ensure that temp/backup already exists
+ check_dir_exists($CFG->tempdir . '/backup', true, true); // need to ensure that temp/backup already exists
$fllevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : $dfltloglevel;
- $enabledloggers[] = new file_logger($fllevel, true, true, $CFG->dataroot . '/temp/backup/' . $backupid . '.log');
+ $enabledloggers[] = new file_logger($fllevel, true, true, $CFG->tempdir . '/backup/' . $backupid . '.log');
// Create database_logger, observing $CFG->backup_database_logger_level and defaulting to LOG_WARNING
// and pointing to the backup_logs table
//Build the message subject
$site = get_site();
- $prefix = $site->shortname.": ";
+ $prefix = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))).": ";
if ($haserrors) {
$prefix .= "[".strtoupper(get_string('error'))."] ";
}
public static function get_backup_storage_base_dir($backupid) {
global $CFG;
- return $CFG->dataroot . '/temp/backup/' . $backupid . '/files';
+ return $CFG->tempdir . '/backup/' . $backupid . '/files';
}
/**
$info = new stdclass(); // Final information goes here
- $moodlefile = $CFG->dataroot . '/temp/backup/' . $tempdir . '/moodle_backup.xml';
+ $moodlefile = $CFG->tempdir . '/backup/' . $tempdir . '/moodle_backup.xml';
if (!file_exists($moodlefile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile);
}
*/
static public function check_and_create_backup_dir($backupid) {
global $CFG;
- if (!check_dir_exists($CFG->dataroot . '/temp/backup/' . $backupid, true, true)) {
+ if (!check_dir_exists($CFG->tempdir . '/backup/' . $backupid, true, true)) {
throw new backup_helper_exception('cannot_create_backup_temp_dir');
}
}
*/
static public function clear_backup_dir($backupid) {
global $CFG;
- if (!self::delete_dir_contents($CFG->dataroot . '/temp/backup/' . $backupid)) {
+ if (!self::delete_dir_contents($CFG->tempdir . '/backup/' . $backupid)) {
throw new backup_helper_exception('cannot_empty_backup_temp_dir');
}
return true;
static public function delete_backup_dir($backupid) {
global $CFG;
self::clear_backup_dir($backupid);
- return rmdir($CFG->dataroot . '/temp/backup/' . $backupid);
+ return rmdir($CFG->tempdir . '/backup/' . $backupid);
}
/**
$status = true;
// Get files and directories in the temp backup dir witout descend
- $list = get_directory_list($CFG->dataroot . '/temp/backup', '', false, true, true);
+ $list = get_directory_list($CFG->tempdir . '/backup', '', false, true, true);
foreach ($list as $file) {
- $file_path = $CFG->dataroot . '/temp/backup/' . $file;
+ $file_path = $CFG->tempdir . '/backup/' . $file;
$moddate = filemtime($file_path);
if ($status && $moddate < $deletefrom) {
//If directory, recurse
public static function detect_moodle2_format($tempdir) {
global $CFG;
- $dirpath = $CFG->dataroot . '/temp/backup/' . $tempdir;
+ $dirpath = $CFG->tempdir . '/backup/' . $tempdir;
$filepath = $dirpath . '/moodle_backup.xml';
if (!is_dir($dirpath)) {
function test_file_logger() {
global $CFG;
- $file = $CFG->dataroot . '/temp/test/test_file_logger.txt';
+ $file = $CFG->tempdir . '/test/test_file_logger.txt';
// Remove the test dir and any content
@remove_dir(dirname($file));
// Recreate test dir
unlink($file); // delete file
// Try one html file
- $file = $CFG->dataroot . '/temp/test/test_file_logger.html';
+ $file = $CFG->tempdir . '/test/test_file_logger.html';
$options = array('depth' => 1);
$lo = new file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue($lo instanceof file_logger);
unlink($file); // delete file
// Instantiate, write something, force deletion, try to write again
- $file = $CFG->dataroot . '/temp/test/test_file_logger.html';
+ $file = $CFG->tempdir . '/test/test_file_logger.html';
$lo = new mock_file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue(file_exists($file));
$message = 'testing file_logger';
}
// Instantiate in (near) impossible path
- $file = $CFG->dataroot . '/temp/test_azby/test_file_logger.txt';
+ $file = $CFG->tempdir . '/test_azby/test_file_logger.txt';
try {
$lo = new file_logger(backup::LOG_WARNING, true, true, $file);
$this->assertTrue(false, 'base_logger_exception expected');
}
// Instatiate one file logger with level = backup::LOG_NONE
- $file = $CFG->dataroot . '/temp/test/test_file_logger.txt';
+ $file = $CFG->tempdir . '/test/test_file_logger.txt';
$lo = new file_logger(backup::LOG_NONE, true, true, $file);
$this->assertTrue($lo instanceof file_logger);
$this->assertFalse(file_exists($file));
throw new backup_plan_exception('wrong_backup_controller_specified');
}
$this->controller = $controller;
- $this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_backupid();
+ $this->basepath = $CFG->tempdir . '/backup/' . $controller->get_backupid();
parent::__construct('backup_plan');
}
throw new restore_plan_exception('wrong_restore_controller_specified');
}
$this->controller = $controller;
- $this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_tempdir();
+ $this->basepath = $CFG->tempdir . '/backup/' . $controller->get_tempdir();
$this->preloaded = false;
$this->decoder = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot);
$this->missingmodules = false;
function test_backup_structure_step() {
global $CFG;
- $file = $CFG->dataroot . '/temp/test/test_backup_structure_step.txt';
+ $file = $CFG->tempdir . '/test/test_backup_structure_step.txt';
// Remove the test dir and any content
@remove_dir(dirname($file));
// Recreate test dir
public function get_taskbasepath() {
global $CFG;
- return $CFG->dataroot . '/temp/test';
+ return $CFG->tempdir . '/test';
}
}
}
$row->cells = array(
html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)),
- $course->shortname,
- $course->fullname
+ format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))),
+ format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)))
);
$table->data[] = $row;
}
}
$row->cells = array(
html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)),
- $course->shortname,
- $course->fullname
+ format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))),
+ format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)))
);
$table->data[] = $row;
}
}
$row->cells = array(
html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)),
- $category->name,
+ format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id))),
format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true))
);
$table->data[] = $row;
}
public function process() {
global $CFG;
- if (!file_exists("$CFG->dataroot/temp/backup/".$this->filename)) {
+ if (!file_exists("$CFG->tempdir/backup/".$this->filename)) {
throw new restore_ui_exception('invalidrestorefile');
}
$outcome = $this->extract_file_to_dir();
$this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id);
$fb = get_file_packer();
- return ($fb->extract_to_pathname("$CFG->dataroot/temp/backup/".$this->filename, "$CFG->dataroot/temp/backup/$this->filepath/"));
+ return ($fb->extract_to_pathname("$CFG->tempdir/backup/".$this->filename, "$CFG->tempdir/backup/$this->filepath/"));
}
/**
}
public function process() {
global $CFG, $DB;
- if (!file_exists("$CFG->dataroot/temp/backup/".$this->filepath) || !is_dir("$CFG->dataroot/temp/backup/".$this->filepath)) {
+ if (!file_exists("$CFG->tempdir/backup/".$this->filepath) || !is_dir("$CFG->tempdir/backup/".$this->filepath)) {
throw new restore_ui_exception('invalidrestorepath');
}
if (optional_param('searchcourses', false, PARAM_BOOL)) {
function test_file_xml_output() {
global $CFG;
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
// Remove the test dir and any content
@remove_dir(dirname($file));
// Recreate test dir
$this->assertTrue($xo instanceof xml_output);
// Try to init file in (near) impossible path
- $file = $CFG->dataroot . '/temp/test_azby/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test_azby/test_file_xml_output.txt';
$xo = new file_xml_output($file);
try {
$xo->start();
}
// Try to init file already existing
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
file_put_contents($file, 'createdtobedeleted'); // create file manually
$xo = new file_xml_output($file);
try {
unlink($file); // delete file
// Send some output and check
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
$xo = new file_xml_output($file);
$xo->start();
$xo->write('first text');
// With buffer of 4 bytes, send 3 contents of 3 bytes each
// so we force both buffering and last write on stop
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
$xo = new file_xml_output($file);
$xo->set_buffersize(5);
$xo->start();
unlink($file); // delete file
// Write some line feeds, tabs and friends
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
$string = "\n\r\tcrazy test\n\r\t";
$xo = new file_xml_output($file);
$xo->start();
unlink($file); // delete file
// Write some UTF-8 chars
- $file = $CFG->dataroot . '/temp/test/test_file_xml_output.txt';
+ $file = $CFG->tempdir . '/test/test_file_xml_output.txt';
$string = 'áéÃóú';
$xo = new file_xml_output($file);
$xo->start();
if ($usercandownload and $cancelrestore and confirm_sesskey()) {
$filename = optional_param('filename', '', PARAM_ALPHANUMEXT);
//delete temp file
- unlink($CFG->dataroot . '/temp/backup/' . $filename . ".mbz");
+ unlink($CFG->tempdir . '/backup/' . $filename . ".mbz");
}
/// Download
$params['courseid'] = $course->id;
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
- make_upload_directory('temp/backup');
+ make_temp_directory('backup');
$filename = md5(time() . '-' . $course->id . '-'. $USER->id . '-'. random_string(20));
$url = new moodle_url($course->huburl.'/local/hub/webservice/download.php', $params);
- $path = $CFG->dataroot.'/temp/backup/'.$filename.".mbz";
+ $path = $CFG->tempdir.'/backup/'.$filename.".mbz";
$fp = fopen($path, 'w');
$curlurl = $course->huburl.'/local/hub/webservice/download.php?filetype='
.HUB_BACKUP_FILE_TYPE.'&courseid='.$course->id;
if (!$fs->file_exists($record->contextid, $record->component,
$record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record,
- $CFG->dataroot.'/temp/backup/'.$filename.".mbz");
+ $CFG->tempdir.'/backup/'.$filename.".mbz");
}
$filenames = array();
!(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall)) { // Just print My Courses
if ($courses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
foreach ($courses as $course) {
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
- $this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname) . "\" ".
+ $this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">".$icon.format_string($course->fullname). "</a>";
}
$this->title = get_string('mycourses');
if ($categories) { //Check we have categories
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
foreach ($categories as $category) {
+ $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
- $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . format_string($category->name) . "</a>";
+ $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . $categoryname . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
if ($courses) {
foreach ($courses as $course) {
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss title=\""
- . format_string($course->shortname)."\" ".
+ . format_string($course->shortname, true, array('context' => $coursecontext))."\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
- .$icon. format_string($course->fullname) . "</a>";
+ .$icon. format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
$this->content->items[] = get_string('remotecourses','mnet');
$this->content->icons[] = '';
foreach ($courses as $course) {
- $this->content->items[]="<a title=\"" . format_string($course->shortname) . "\" ".
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $this->content->items[]="<a title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">"
.$icon. format_string($course->fullname) . "</a>";
}
// Truncate the text to $long characters
$node->text = $this->trim_left($textlib, $node->text, $long);
}
- if (is_string($node->shorttext) && strlen($node->shorttext)>($short+3)) {
+ if (is_string($node->shorttext) && $textlib->strlen($node->shorttext)>($short+3)) {
// Truncate the shorttext
$node->shorttext = $this->trim_left($textlib, $node->shorttext, $short);
}
// Truncate the text to $long characters
$node->text = $this->trim_center($textlib, $node->text, $long);
}
- if (is_string($node->shorttext) && strlen($node->shorttext)>($short+3)) {
+ if (is_string($node->shorttext) && $textlib->strlen($node->shorttext)>($short+3)) {
// Truncate the shorttext
$node->shorttext = $this->trim_center($textlib, $node->shorttext, $short);
}
if(empty($title)){
// no title present, use portion of description
- $title = substr(strip_tags($description), 0, 20) . '...';
+ $title = textlib::substr(strip_tags($description), 0, 20) . '...';
}else{
$title = break_up_long_words($title, 30);
}
$mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$a = new stdClass();
- $a->coursename = $course->fullname;
+ $a->coursename = format_string($course->fullname, true, array('context' => $context));
$contextid = $context->id;
} else {
$sql = 'SELECT fullname FROM {course} cr LEFT JOIN {context} ct ON ct.instanceid = cr.id WHERE ct.id = ?';
// Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
// Note: if action is set to 'add' or 'edit', we do this at the end
if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid) && !in_array($action, array('edit', 'add'))) {
+ $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$PAGE->navbar->add($strblogentries, $blogurl);
- $PAGE->set_title("$site->shortname: " . get_string('blog', 'blog'));
- $PAGE->set_heading("$site->shortname: " . get_string('blog', 'blog'));
- $headers['heading'] = get_string('siteblog', 'blog', $site->shortname);
+ $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
+ $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
+ $headers['heading'] = get_string('siteblog', 'blog', $shortname);
// $headers['strview'] = get_string('viewsiteentries', 'blog');
}
} else {
$mycourseid = $site->id;
}
+ $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$PAGE->navbar->add($strblogentries, $blogurl);
$blogurl->remove_params('userid');
$PAGE->navbar->add($entry->subject, $blogurl);
-
- $PAGE->set_title("$site->shortname: " . fullname($user) . ": $entry->subject");
- $PAGE->set_heading("$site->shortname: " . fullname($user) . ": $entry->subject");
+ $PAGE->set_title("$shortname: " . fullname($user) . ": $entry->subject");
+ $PAGE->set_heading("$shortname: " . fullname($user) . ": $entry->subject");
$headers['heading'] = get_string('blogentrybyuser', 'blog', fullname($user));
// We ignore tag and search params
// Case 3: A user's blog entries
if (!empty($userid) && empty($entryid) && ((empty($courseid) && empty($modid)) || !$CFG->useblogassociations)) {
+ $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$blogurl->param('userid', $userid);
- $PAGE->set_title("$site->shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
- $PAGE->set_heading("$site->shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
+ $PAGE->set_title("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
+ $PAGE->set_heading("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
$headers['heading'] = get_string('userblog', 'blog', fullname($user));
$headers['strview'] = get_string('viewuserentries', 'blog', fullname($user));
// Case 4: No blog associations, no userid
if (!$CFG->useblogassociations && empty($userid) && !in_array($action, array('edit', 'add'))) {
- $PAGE->set_title("$site->shortname: " . get_string('blog', 'blog'));
- $PAGE->set_heading("$site->shortname: " . get_string('blog', 'blog'));
- $headers['heading'] = get_string('siteblog', 'blog', $site->shortname);
+ $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
+ $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
+ $headers['heading'] = get_string('siteblog', 'blog', $shortname);
} else
// Case 5: Blog entries associated with an activity by a specific user (courseid ignored)
if (!empty($userid) && !empty($modid) && empty($entryid)) {
+ $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$blogurl->param('userid', $userid);
$blogurl->param('modid', $modid);
$PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
$PAGE->navbar->add($strblogentries, $blogurl);
- $PAGE->set_title("$site->shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
- $PAGE->set_heading("$site->shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
+ $PAGE->set_title("$shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
+ $PAGE->set_heading("$shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
$a = new stdClass();
$a->user = fullname($user);
// Case 6: Blog entries associated with a course by a specific user
if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
+ $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$blogurl->param('userid', $userid);
$blogurl->param('courseid', $courseid);
$PAGE->navbar->add($strblogentries, $blogurl);
- $PAGE->set_title("$site->shortname: $course->shortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
- $PAGE->set_heading("$site->shortname: $course->shortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
+ $PAGE->set_title("$siteshortname: $courseshortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
+ $PAGE->set_heading("$siteshortname: $courseshortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
$a = new stdClass();
$a->user = fullname($user);
- $a->course = $course->fullname;
+ $a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
$a->type = get_string('course');
$headers['heading'] = get_string('blogentriesbyuseraboutcourse', 'blog', $a);
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
// Case 7: Blog entries by members of a group, associated with that group's course
if (!empty($groupid) && empty($modid) && empty($entryid)) {
+ $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$blogurl->param('courseid', $course->id);
$PAGE->navbar->add($strblogentries, $blogurl);
$blogurl->param('groupid', $groupid);
$PAGE->navbar->add($group->name, $blogurl);
- $PAGE->set_title("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog') . ": $group->name");
- $PAGE->set_heading("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog') . ": $group->name");
+ $PAGE->set_title("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog') . ": $group->name");
+ $PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog') . ": $group->name");
$a = new stdClass();
$a->group = $group->name;
- $a->course = $course->fullname;
+ $a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
$a->type = get_string('course');
$headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
// Case 8: Blog entries by members of a group, associated with an activity in that course
if (!empty($groupid) && !empty($modid) && empty($entryid)) {
+ $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$headers['cm'] = $cm;
$blogurl->param('modid', $modid);
$PAGE->navbar->add($strblogentries, $blogurl);
$blogurl->param('groupid', $groupid);
$PAGE->navbar->add($group->name, $blogurl);
- $PAGE->set_title("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
- $PAGE->set_heading("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
+ $PAGE->set_title("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
+ $PAGE->set_heading("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
$a = new stdClass();
$a->group = $group->name;
// Case 9: All blog entries associated with an activity
if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
+ $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$PAGE->set_cm($cm, $course);
$blogurl->param('modid', $modid);
$PAGE->navbar->add($strblogentries, $blogurl);
- $PAGE->set_title("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog'));
- $PAGE->set_heading("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog'));
+ $PAGE->set_title("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog'));
+ $PAGE->set_heading("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog'));
$headers['heading'] = get_string('blogentriesabout', 'blog', $cm->name);
$a = new stdClass();
$a->type = get_string('modulename', $cm->modname);
// Case 10: All blog entries associated with a course
if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
+ $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$blogurl->param('courseid', $courseid);
$PAGE->navbar->add($strblogentries, $blogurl);
- $PAGE->set_title("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog'));
- $PAGE->set_heading("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog'));
+ $PAGE->set_title("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
+ $PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
$a = new stdClass();
$a->type = get_string('course');
- $headers['heading'] = get_string('blogentriesabout', 'blog', $course->fullname);
+ $headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid))));
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewblogentries', 'blog', $a);
$blogurl->remove_params(array('userid'));
break;
case 'course':
$info = $DB->get_field('course', 'fullname', array('id'=>$id));
+ $info = format_string($info, true, array('context' => get_context_instance(CONTEXT_COURSE, $id)));
break;
case 'site':
- $info = $SITE->fullname;
+ $info = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
break;
case 'group':
$group = groups_get_group($id);
global $CFG;
if ($tagid) {
- return "$CFG->dataroot/cache/rss/blog/$type/$id/$tagid.xml";
+ return "$CFG->cachedir/rss/blog/$type/$id/$tagid.xml";
} else {
- return "$CFG->dataroot/cache/rss/blog/$type/$id.xml";
+ return "$CFG->cachedir/rss/blog/$type/$id.xml";
}
}
$status = true;
//blog creates some additional dirs within the rss cache so make sure they all exist
- make_upload_directory('cache/rss/blog');
- make_upload_directory('cache/rss/blog/'.$type);
+ make_cache_directory('rss/blog');
+ make_cache_directory('rss/blog/'.$type);
$filename = blog_rss_file_name($type, $id, $tagid);
$expandfilename = false; //we're supplying a full file path
$ev->add_property('dtend', Bennu::timestamp_to_datetime($event->timestart + $event->timeduration));
}
if ($event->courseid != 0) {
- $ev->add_property('categories', $courses[$event->courseid]->shortname);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $event->courseid);
+ $ev->add_property('categories', format_string($courses[$event->courseid]->shortname, true, array('context' => $coursecontext)));
}
$ical->add_component($ev);
}
}
$icon = $OUTPUT->pix_url('icon', $event->modulename) . '';
+ $context = get_context_instance(CONTEXT_COURSE, $module->course);
+ $fullname = format_string($coursecache[$module->course]->fullname, true, array('context' => $context));
+
$event->icon = '<img height="16" width="16" src="'.$icon.'" alt="'.$eventtype.'" title="'.$modulename.'" style="vertical-align: middle;" />';
$event->referer = '<a href="'.$CFG->wwwroot.'/mod/'.$event->modulename.'/view.php?id='.$module->id.'">'.$event->name.'</a>';
- $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$module->course.'">'.$coursecache[$module->course]->fullname.'</a>';
+ $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$module->course.'">'.$fullname.'</a>';
$event->cmid = $module->id;
$event->cssclass = 'calendar_event_global';
} else if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event
calendar_get_course_cached($coursecache, $event->courseid);
+
+ $context = get_context_instance(CONTEXT_COURSE, $event->courseid);
+ $fullname = format_string($coursecache[$event->courseid]->fullname, true, array('context' => $context));
+
$event->icon = '<img height="16" width="16" src="'.$OUTPUT->pix_url('c/course') . '" alt="'.get_string('courseevent', 'calendar').'" style="vertical-align: middle;" />';
- $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$event->courseid.'">'.$coursecache[$event->courseid]->fullname.'</a>';
+ $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$event->courseid.'">'.$fullname.'</a>';
$event->cssclass = 'calendar_event_course';
} else if ($event->groupid) { // Group event
$event->icon = '<img height="16" width="16" src="'.$OUTPUT->pix_url('c/group') . '" alt="'.get_string('groupevent', 'calendar').'" style="vertical-align: middle;" />';
$courseoptions = array();
$courseoptions[SITEID] = get_string('fulllistofcourses');
foreach ($courses as $course) {
- $courseoptions[$course->id] = format_string($course->shortname);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
}
if ($this->page->course->id !== SITEID) {
//
// $CFG->themedir = '/location/of/extra/themes';
//
+// It is possible to specify different cache and temp directories, use local fast filesystem.
+// The directories must not be accessible via web.
+//
+// $CFG->tempdir = '/var/www/moodle/temp';
+// $CFG->cachedir = '/var/www/moodle/cache';
+//
// If $CFG->langstringcache is enabled (which should always be in production
// environment), Moodle keeps aggregated strings in its own internal format
// optimised for performance. By default, this on-disk cache is created in
-// $CFG->dataroot/cache/lang. In cluster environment, you may wish to specify
+// $CFG->cachedir/lang. In cluster environment, you may wish to specify
// an alternative location of this cache so that each web server in the cluster
// uses its own local cache and does not need to access the shared dataroot.
// Make sure that the web server process has write permission to this location
}
$catlinkcss = $subcategory->visible ? '' : ' class="dimmed" ';
echo '<a '.$catlinkcss.' href="category.php?id='.$subcategory->id.'">'.
- format_string($subcategory->name).'</a><br />';
+ format_string($subcategory->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $subcategory->id))).'</a><br />';
}
}
if (!$firstentry) {
$selectbox = array();
$selected = array();
foreach ($courses as $c) {
- $selectbox[$c->id] = $list[$c->category] . ' / ' . s($c->fullname);
+ $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $c->id)));
// If already selected
if ($c->selected) {
print_error("invalidcourseid", 'error', '', $id);
}
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
if (!can_delete_course($id)) {
print_error('cannotdeletecourse');
}
$category = $DB->get_record("course_categories", array("id"=>$course->category));
+ $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
$PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
- $PAGE->navbar->add($category->name, new moodle_url('/course/category.php', array('id'=>$course->category)));
+ $PAGE->navbar->add($categoryname, new moodle_url('/course/category.php', array('id'=>$course->category)));
if (! $delete) {
- $strdeletecheck = get_string("deletecheck", "", $course->shortname);
+ $strdeletecheck = get_string("deletecheck", "", $courseshortname);
$strdeletecoursecheck = get_string("deletecoursecheck");
$PAGE->navbar->add($strdeletecheck);
$PAGE->set_heading($site->fullname);
echo $OUTPUT->header();
- $message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname) . " (" . format_string($course->shortname) . ")";
+ $message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname, true, array('context' => $coursecontext)) . " (" . $courseshortname . ")";
+
echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
echo $OUTPUT->footer();
add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
- $strdeletingcourse = get_string("deletingcourse", "", format_string($course->shortname));
+ $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
$PAGE->navbar->add($strdeletingcourse);
$PAGE->set_title("$site->shortname: $strdeletingcourse");
delete_course($course);
fix_course_sortorder(); //update course count in catagories
- echo $OUTPUT->heading( get_string("deletedcourse", "", format_string($course->shortname)) );
+ echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
echo $OUTPUT->continue_button("category.php?id=$course->category");
}
/// Now build the form.
- $mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name)));
+ $mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name, true, array('context' => $categorycontext))));
if ($containscourses || $containscategories || $containsquestions) {
if (empty($options)) {
- print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name));
+ print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name, true, array('context' => $categorycontext)));
}
/// Describe the contents of this category.
echo '<div class="right side" > </div>';
echo '<div class="content">';
if (!is_null($thissection->name)) {
- echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
+ echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
}
echo '<div class="summary">';
echo get_string('notavailable');
} else {
if (!is_null($thissection->name)) {
- echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
+ echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
}
echo '<div class="summary">';
if ($thissection->summary) {
function callback_topics_get_section_name($course, $section) {
// We can't add a node without any text
if (!empty($section->name)) {
- return $section->name;
+ return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
} else if ($section->section == 0) {
return get_string('section0name', 'format_topics');
} else {
echo '<div class="content">';
if (!empty($thissection->name)) {
- echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
+ echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
}
echo '<div class="summary">';
} else {
if (isset($thissection->name) && ($thissection->name !== NULL)) { // empty string is ok
- echo $OUTPUT->heading($thissection->name, 3, 'weekdates');
+ echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'weekdates');
} else {
echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates');
}
// We can't add a node without text
if (!empty($section->name)) {
// Return the name the user set
- return $section->name;
+ return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
} else if ($section->section == 0) {
// Return the section0name
return get_string('section0name', 'format_weeks');
require_capability('moodle/category:manage', $context);
require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent));
- $heading = get_string('deletecategory', 'moodle', format_string($deletecat->name));
+ $heading = get_string('deletecategory', 'moodle', format_string($deletecat->name, true, array('context' => $context)));
require_once('delete_category_form.php');
$mform = new delete_category_form(null, $deletecat);
$mform->set_data(array('delete'=>$delete));
foreach($deletedcourses as $course) {
echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
}
- echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name)), 'notifysuccess');
+ echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name, true, array('context' => $context))), 'notifysuccess');
} else {
category_delete_move($deletecat, $data->newparent, true);
$linkcss = $category->visible ? '' : ' class="dimmed" ';
echo '<a '.$linkcss.' title="'.$str->edit.'" '.
' href="category.php?id='.$category->id.'&categoryedit=on&sesskey='.sesskey().'">'.
- format_string($category->name).'</a>';
+ format_string($category->name, true, array('context' => $category->context)).'</a>';
echo '</td>';
echo '<td class="count">'.$category->coursecount.'</td>';
$PAGE->navbar->add(get_string('summary'));
echo $OUTPUT->header();
- echo $OUTPUT->heading('<a href="view.php?id='.$course->id.'">'.format_string($course->fullname) . '</a><br />(' . format_string($course->shortname) . ')');
+ echo $OUTPUT->heading('<a href="view.php?id='.$course->id.'">'.format_string($course->fullname) . '</a><br />(' . format_string($course->shortname, true, array('context' => $context)) . ')');
// print enrol info
if ($texts = enrol_get_course_description_texts($course)) {
echo '<tr class="r'.$row.'">';
if ($course->id == SITEID) {
+ $courseshortname = format_string($courses[$log->course], true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
echo "<td class=\"r$row c0\" >\n";
- echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courses[$log->course]."</a>\n";
+ echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courseshortname."</a>\n";
echo "</td>\n";
}
echo "<td class=\"r$row c1\" align=\"right\">".userdate($log->time, '%a').
$log->info = format_string($log->info);
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
- $firstField = $courses[$log->course];
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
+ $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
$text = implode("\t", $row);
echo $text." \n";
}
}
- $myxls->write($row, 0, $courses[$log->course], '');
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ $myxls->write($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)), '');
$myxls->write_date($row, 1, $log->time, $formatDate); // write_date() does conversion/timezone support. MDL-14934
$myxls->write($row, 2, $log->ip, '');
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
+ $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$myxls->write($row, 3, $fullname, '');
$myxls->write($row, 4, $log->module.' '.$log->action, '');
$myxls->write($row, 5, $log->info, '');
}
}
- $myxls->write_string($row, 0, $courses[$log->course]);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $context)));
$myxls->write_date($row, 1, $log->time);
$myxls->write_string($row, 2, $log->ip);
- $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
+ $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$myxls->write_string($row, 3, $fullname);
$myxls->write_string($row, 4, $log->module.' '.$log->action);
$myxls->write_string($row, 5, $log->info);
}
}
foreach ($courses as $course) {
+ $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
echo $OUTPUT->box_start('coursebox');
- $attributes = array('title' => s($course->fullname));
+ $attributes = array('title' => s($fullname));
if (empty($course->visible)) {
$attributes['class'] = 'dimmed';
}
echo $OUTPUT->heading(html_writer::link(
- new moodle_url('/course/view.php', array('id' => $course->id)), format_string($course->fullname), $attributes), 3);
+ new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
if (array_key_exists($course->id,$htmlarray)) {
foreach ($htmlarray[$course->id] as $modname => $html) {
echo $html;
function get_print_section_cm_text(cm_info $cm, $course) {
global $OUTPUT;
- // Get course context
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
// Get content from modinfo if specified. Content displays either
// in addition to the standard link (below), or replaces it if
// the link is turned off by setting ->url to null.
if (($content = $cm->get_content()) !== '') {
+ // Improve filter performance by preloading filter setttings for all
+ // activities on the course (this does nothing if called multiple
+ // times)
+ filter_preload_activities($cm->get_modinfo());
+
+ // Get module context
+ $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$labelformatoptions = new stdClass();
$labelformatoptions->noclean = true;
$labelformatoptions->overflowdiv = true;
- $labelformatoptions->context = $coursecontext;
+ $labelformatoptions->context = $modulecontext;
$content = format_text($content, FORMAT_HTML, $labelformatoptions);
} else {
$content = '';
}
+ // Get course context
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$stringoptions = new stdClass;
$stringoptions->context = $coursecontext;
$instancename = format_string($cm->name, true, $stringoptions);
return;
}
+ $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $categoryname = format_string($category->name, true, array('context' => $context));
+
// Update $path.
if ($path) {
- $path = $path.' / '.format_string($category->name);
+ $path = $path.' / '.$categoryname;
} else {
- $path = format_string($category->name);
+ $path = $categoryname;
}
// Add this category to $list, if the permissions check out.
$list[$category->id] = $path;
} else {
- ensure_context_subobj_present($category, CONTEXT_COURSECAT);
$requiredcapability = (array)$requiredcapability;
- if (has_all_capabilities($requiredcapability, $category->context)) {
+ if (has_all_capabilities($requiredcapability, $context)) {
$list[$category->id] = $path;
}
}
}
$courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary');
+ $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ $fullname = format_string($category->name, true, array('context' => $context));
+
if ($showcourses and $coursecount) {
echo '<div class="categorylist clearfix">';
$cat = '';
$cat .= html_writer::tag('div', $catimage, array('class'=>'image'));
- $catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
+ $catlink = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss);
$cat .= html_writer::tag('div', $catlink, array('class'=>'name'));
$html = '';
} else {
echo '<div class="categorylist">';
$html = '';
- $cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), format_string($category->name), $catlinkcss);
+ $cat = html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $fullname, $catlinkcss);
$cat .= html_writer::tag('span', ' ('.count($courses).')', array('title'=>get_string('numberofcourses'), 'class'=>'numberofcourse'));
if ($depth > 0) {
array('class' => 'editing_update', 'title' => $str->update)
);
- // Duplicate
- $actions[] = new action_link(
- new moodle_url($baseurl, array('duplicate' => $mod->id)),
- new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')),
- null,
- array('class' => 'editing_duplicate', 'title' => $str->duplicate)
- );
+ // Duplicate (require both target import caps to be able to duplicate, see modduplicate.php)
+ $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
+ if (has_all_capabilities($dupecaps, $coursecontext)) {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('duplicate' => $mod->id)),
+ new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_duplicate', 'title' => $str->duplicate)
+ );
+ }
// Delete
$actions[] = new action_link(
*/
function course_format_name ($course,$max=100) {
- $str = $course->shortname.': '. $course->fullname;
- if (strlen($str) <= $max) {
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $shortname = format_string($course->shortname, true, array('context' => $context));
+ $fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $str = $shortname.': '. $fullname;
+ if (textlib::strlen($str) <= $max) {
return $str;
}
else {
- return substr($str,0,$max-3).'...';
+ return textlib::substr($str,0,$max-3).'...';
}
}
$this->delete();
$a = new stdClass();
- $a->name = $course->fullname;
+ $a->name = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$a->url = $CFG->wwwroot.'/course/view.php?id=' . $course->id;
$this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
require_login($course);
require_sesskey();
require_capability('moodle/course:manageactivities', $context);
+// Require both target import caps to be able to duplicate, see make_editing_buttons()
require_capability('moodle/backup:backuptargetimport', $context);
require_capability('moodle/restore:restoretargetimport', $context);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$shortname = format_string($course->shortname, true, array('context' => $context));
$PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
$PAGE->set_pagelayout('course');
$notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$notificationerror .= get_string('xmlrpcdisabledpublish', 'hub');
echo $OUTPUT->header();
- echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main');
+ echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $OUTPUT->notification($notificationerror);
echo $OUTPUT->footer();
die();
} else {
//display confirmation page for unpublishing
-
+
echo $OUTPUT->header();
- echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $course->shortname), 3, 'main');
+ echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
echo $OUTPUT->header();
echo $confirmmessage;
- echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main');
+ echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->publicationselector($course->id);
$publications = $publicationmanager->get_course_publications($course->id);
if (!extension_loaded('xmlrpc')) {
$errornotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$errornotification .= get_string('xmlrpcdisabledpublish', 'hub');
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $shortname = format_string($course->shortname, true, array('context' => $context));
echo $OUTPUT->header();
- echo $OUTPUT->heading(get_string('publishcourse', 'hub', $course->shortname), 3, 'main');
+ echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $OUTPUT->notification($errornotification);
echo $OUTPUT->footer();
die();
$mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
+ $groupoptions = array();
+ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
+ // limited group access
+ $groups = groups_get_user_groups($COURSE->id);
+ $allgroups = groups_get_all_groups($COURSE->id);
+ if (!empty($groups[$COURSE->defaultgroupingid])) {
+ foreach ($groups[$COURSE->defaultgroupingid] AS $groupid) {
+ $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context'=>$context));
+ }
+ }
+ } else {
+ $groupoptions = array('0'=>get_string('allgroups'));
+ if (has_capability('moodle/site:accessallgroups', $context)) {
+ // user can see all groups
+ $allgroups = groups_get_all_groups($COURSE->id);
+ } else {
+ // user can see course level groups
+ $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid);
+ }
+ foreach($allgroups as $group) {
+ $groupoptions[$group->id] = format_string($group->name, true, array('context'=>$context));
+ }
+ }
+
if ($COURSE->id == SITEID) {
$viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
} else {
$viewparticipants = has_capability('moodle/course:viewparticipants', $context);
}
- $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
-
if ($viewparticipants) {
+ $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
+
$options = array();
$options[0] = get_string('allparticipants');
$options[$CFG->siteguest] = get_string('guestuser');
- if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
- $groups = groups_get_user_groups($COURSE->id);
- $group = $groups[0];
+ if (isset($groupoptions[0])) {
+ // can see all enrolled users
+ if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) {
+ foreach ($enrolled as $euser) {
+ $options[$euser->id] = fullname($euser, $viewfullnames);
+ }
+ }
} else {
- $group = '';
- }
-
- if ($enrolled = get_enrolled_users($context, null, $group, user_picture::fields('u'))) {
- foreach ($enrolled as $euser) {
- $options[$euser->id] = fullname($euser, $viewfullnames);
+ // can see users from some groups only
+ foreach ($groupoptions as $groupid=>$unused) {
+ if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) {
+ foreach ($enrolled as $euser) {
+ if (!array_key_exists($euser->id, $options)) {
+ $options[$euser->id] = fullname($euser, $viewfullnames);
+ }
+ }
+ }
}
}
+
$mform->addElement('select', 'user', get_string('participants'), $options);
$mform->setAdvanced('user');
}
$mform->setAdvanced('modid');
- if (has_capability('moodle/site:accessallgroups', $context)) {
- if ($groups = groups_get_all_groups($COURSE->id)) {
- $options = array('0'=>get_string('allgroups'));
- foreach($groups as $group) {
- $options[$group->id] = format_string($group->name);
- }
- $mform->addElement('select', 'group', get_string('groups'), $options);
- $mform->setAdvanced('group');
- } else {
- $mform->addElement('hidden','group');
- $mform->setType('group', PARAM_INT);
- $mform->setConstants(array('group'=>0));
- }
+ if ($groupoptions) {
+ $mform->addElement('select', 'group', get_string('groups'), $groupoptions);
+ $mform->setAdvanced('group');
} else {
+ // no access to groups in separate mode
$mform->addElement('hidden','group');
$mform->setType('group', PARAM_INT);
- $mform->setConstants(array('group'=>0));
+ $mform->setConstants(array('group'=>-1));
}
$options = array('default' => get_string('bycourseorder'),
$classes[] = 'collapsed';
}
}
+ $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
+
$content .= html_writer::start_tag('div', array('class'=>join(' ', $classes)));
$content .= html_writer::start_tag('div', array('class'=>'category_label'));
- $content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $category->name, array('class'=>'category_link'));
+ $content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $categoryname, array('class'=>'category_link'));
$content .= html_writer::end_tag('div');
if ($hassubcategories) {
$content .= html_writer::start_tag('div', array('class'=>'subcategories'));
* Setup page header
*/
if ($csv) {
+ $shortname = format_string($course->shortname, true, array('context' => $context));
+ $textlib = textlib_get_instance();
header('Content-Disposition: attachment; filename=progress.'.
- preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv');
+ preg_replace('/[^a-z0-9-]/','_',$textlib->strtolower(strip_tags($shortname))).'.csv');
// Unicode byte-order mark for Excel
if($excel) {
header('Content-Type: text/csv; charset=UTF-16LE');
// Display icon
$iconlink = $CFG->wwwroot.'/course/view.php?id='.$criterion->courseinstance;
- $icontitle = $crs->fullname;
- $iconalt = $crs->shortname;
+ $icontitle = format_string($crs->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $crs->id, MUST_EXIST)));
+ $iconalt = format_string($crs->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $crs->id)));
break;
case COMPLETION_CRITERIA_TYPE_ROLE:
$graph = new graph(750, 400);
- $a->coursename = $course->shortname;
+ $a->coursename = format_string($course->shortname, true, array('context' => $context));
$a->username = fullname($user, true);
$graph->parameter['title'] = get_string("hitsoncourse", "", $a);
$graph = new graph(750, 400);
- $a->coursename = $course->shortname;
+ $a->coursename = format_string($course->shortname, true, array('context' => $context));
$a->username = fullname($user, true);
$graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a);
}
$section = $mod->section;
$mod->name = strip_tags(format_string($mod->name, true));
- if (strlen($mod->name) > 55) {
- $mod->name = substr($mod->name, 0, 50)."...";
+ if (textlib::strlen($mod->name) > 55) {
+ $mod->name = textlib::substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
$section = $mod->section;
$mod->name = strip_tags(format_string($mod->name, true));
- if (strlen($mod->name) > 55) {
- $mod->name = substr($mod->name, 0, 50)."...";
+ if (textlib::strlen($mod->name) > 55) {
+ $mod->name = textlib::substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
if($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are some users/actvs
+
+ $shortname = format_string($course->shortname, true, array('context' => $context));
+ $textlib = textlib_get_instance();
header('Content-Disposition: attachment; filename=progress.'.
- preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv');
+ preg_replace('/[^a-z0-9-]/','_',$textlib->strtolower(strip_tags($shortname))).'.csv');
// Unicode byte-order mark for Excel
if($excel) {
header('Content-Type: text/csv; charset=UTF-16LE');
$context = get_context_instance(CONTEXT_COURSE, $c->id);
if (has_capability('coursereport/stats:view', $context)) {
- $courseoptions[$c->id] = $c->shortname;
+ $courseoptions[$c->id] = format_string($c->shortname, true, array('context' => $context));
}
}
error_log("Ajax rest.php: Could not delete the $cm->modname $cm->name from section");
}
+ // Trigger a mod_deleted event with information about this module.
+ $eventdata = new stdClass();
+ $eventdata->modulename = $cm->modname;
+ $eventdata->cmid = $cm->id;
+ $eventdata->courseid = $course->id;
+ $eventdata->userid = $USER->id;
+ events_trigger('mod_deleted', $eventdata);
+
rebuild_course_cache($course->id);
add_to_log($courseid, "course", "delete mod",
// Get course info
$c_course = $DB->get_record('course', array('id' => $c_info->course_id));
- $course_name = $c_course->fullname;
+ $course_context = get_context_instance(CONTEXT_COURSE, $c_course->id, MUST_EXIST);
+ $course_name = format_string($c_course->fullname, true, array('context' => $course_context));
// Get completions
$completions = $c_info->get_completions($user->id);
// Display course name on first row
if ($first_row) {
- echo '<tr><td class="c0"><a href="'.$CFG->wwwroot.'/course/view.php?id='.$c_course->id.'">'.format_string($course_name).'</a></td>';
+ echo '<tr><td class="c0"><a href="'.$CFG->wwwroot.'/course/view.php?id='.$c_course->id.'">'.$course_name.'</a></td>';
} else {
echo '<tr><td class="c0"></td>';
}
$lastuserid = $ei->userid;
while ($ei && $ei->userid == $lastuserid) {
- $usercourses[] = $ei->fullname;
+ $context = get_context_instance(CONTEXT_COURSE, $ei->courseid);
+ $usercourses[] = format_string($ei->fullname, true, array('context' => $context));
if (!$rs->valid()) {
break;
}
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid";
$a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid";
$emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a);
+ $subject = get_string("enrolmentnew", '', format_string($SITE->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))));
$eventdata = new stdClass();
$eventdata->modulename = 'moodle';
$eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $sender;
$eventdata->userto = $user;
- $eventdata->subject = get_string("enrolmentnew", '', $SITE->shortname);
+ $eventdata->subject = $subject;
$eventdata->fullmessage = $emailmessage;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$original_antest = $plugin->get_config('an_test');
$plugin->set_config('an_test', 1); // Test mode
+ $shortname = format_string($SITE->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$order = new stdClass();
$order->id = -1;
$extra->x_country = $USER->country;
$extra->x_invoice_num = $order->id;
- $extra->x_description = $SITE->shortname . ' - Authorize.net Merchant Account Verification Test';
+ $extra->x_description = $shortname . ' - Authorize.net Merchant Account Verification Test';
$ret = '';
$message = '';
$searchtype = optional_param('searchtype', 'orderid', PARAM_ALPHA);
$status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+
$searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour);
$buttons = "<form method='post' action='index.php' autocomplete='off'><div>";
$buttons .= html_writer::select($searchmenu, 'searchtype', $searchtype, false);
$buttons .= "<form method='get' action='uploadcsv.php'><div><input type='submit' value='".get_string('uploadcsv', 'enrol_authorize')."' /></div></form>";
}
- $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid));
+ $canmanagepayments = has_capability('enrol/authorize:managepayments', $coursecontext);
if ($showonlymy || !$canmanagepayments) {
$userid = $USER->id;
}
}
if (SITEID != $courseid) {
- $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
+ $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
}
$PAGE->navbar->add($authstrs->paymentmanagement, 'index.php');
$PAGE->set_title("$course->shortname: $authstrs->paymentmanagement");
}
if (SITEID != $course->id) {
- $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
+ $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
+ $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
}
$PAGE->navbar->add($authstrs->paymentmanagement, 'index.php?course='.$course->id);
$PAGE->navbar->add($authstrs->orderid . ': ' . $orderid, 'index.php');
redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid");
}
else {
- redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'", 20);
+ $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
+ redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "Error while trying to enrol ".fullname($user)." in '" . $shortname . "'", 20);
}
}
else {
if (!$form->get_data()) {
$form->display();
} else {
- $filename = $CFG->dataroot . '/temp/enrolauthorize/importedfile_'.time().'.csv';
- make_upload_directory('temp/enrolauthorize');
+ $filename = $CFG->tempdir . '/enrolauthorize/importedfile_'.time().'.csv';
+ make_temp_directory('enrolauthorize');
// Fix mac/dos newlines
$text = $form->get_file_content('csvfile');
$text = preg_replace('!\r\n?!', "\n", $text);
$eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
- $eventdata->subject = "$SITE->fullname: Authorize.net CSV ERROR LOG";
+ $eventdata->subject = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID))).': Authorize.net CSV ERROR LOG';
$eventdata->fullmessage = $ignoredlines;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
}
}
+ // assign extra roles
+ foreach ($userroles as $roleid) {
+ if (empty($current_roles[$userid][$roleid])) {
+ role_assign($roleid, $userid, $context->id, 'enrol_database', $instance->id);
+ $current_roles[$userid][$roleid] = $roleid;
+ if ($verbose) {
+ mtrace(" assigning roles: $userid ==> $course->shortname as ".$allroles[$roleid]->shortname);
+ }
+ }
+ }
+
// unassign removed roles
foreach($current_roles[$userid] as $cr) {
if (empty($userroles[$cr])) {
$settings->add(new admin_setting_heading('enrol_database_exdbheader', get_string('settingsheaderdb', 'enrol_database'), ''));
- $options = array('', "access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
+ $options = array('', "access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mssqlnative", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
$options = array_combine($options, $options);
$settings->add(new admin_setting_configselect('enrol_database/dbtype', get_string('dbtype', 'enrol_database'), get_string('dbtype_desc', 'enrol_database'), '', $options));
if (!empty($mailstudents)) {
// Send mail to students
$a = new stdClass();
- $a->coursename = "$course->fullname";
+ $a->coursename = format_string($course->fullname, true, array('context' => $context));
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
+ $subject = get_string("enrolmentnew", 'enrol', format_string($course->shortname, true, array('context' => $context)));
$eventdata = new stdClass();
$eventdata->modulename = 'moodle';
$eventdata->name = 'flatfile_enrolment';
$eventdata->userfrom = $teacher;
$eventdata->userto = $user;
- $eventdata->subject = get_string("enrolmentnew", 'enrol', $course->shortname);
+ $eventdata->subject = $subject;
$eventdata->fullmessage = get_string('welcometocoursetext', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
// Send mail to teachers
foreach($teachers as $teacher) {
$a = new stdClass();
- $a->course = "$course->fullname";
+ $a->course = format_string($course->fullname, true, array('context' => $context));
$a->user = fullname($user);
+ $subject = get_string("enrolmentnew", 'enrol', format_string($course->shortname, true, array('context' => $context)));
$eventdata = new stdClass();
$eventdata->modulename = 'moodle';
$eventdata->name = 'flatfile_enrolment';
$eventdata->userfrom = $user;
$eventdata->userto = $teacher;
- $eventdata->subject = get_string("enrolmentnew", 'enrol', $course->shortname);
+ $eventdata->subject = $subject;
$eventdata->fullmessage = get_string('enrolmentnewuser', 'enrol', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
JOIN {enrol} e ON (e.id = ue.enrolid)
WHERE u.deleted = 0 AND e.courseid = :courseid ";
$params = array('roleid'=>$role->id, 'courseid'=>$course_obj->id);
+ $context = get_context_instance(CONTEXT_COURSE, $course_obj->id);
if (!empty($ldapmembers)) {
list($ldapml, $params2) = $DB->get_in_or_equal($ldapmembers, SQL_PARAMS_NAMED, 'm', false);
$sql .= "AND u.idnumber $ldapml";
$params = array_merge($params, $params2);
unset($params2);
} else {
+ $shortname = format_string($course_obj->shortname, true, array('context' => $context));
print_string('emptyenrolment', 'enrol_ldap',
array('role_shortname'=> $role->shortname,
- 'course_shortname'=>$course_obj->shortname));
+ 'course_shortname' => $shortname));
}
$todelete = $DB->get_records_sql($sql, $params);
- $context = get_context_instance(CONTEXT_COURSE, $course_obj->id);
if (!empty($todelete)) {
$transaction = $DB->start_delegated_transaction();
foreach ($todelete as $row) {
if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
continue;
}
- $courses[$c->id] = format_string($c->fullname). ' ['.$c->shortname.']';
+ $courses[$c->id] = format_string($c->fullname). ' ['.format_string($c->shortname, true, array('context' => $coursecontext)).']';
}
$rs->close();
die;
}
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
// Check that amount paid is the correct amount
if ( (float) $plugin_instance->cost <= 0 ) {
$cost = (float) $plugin->get_config('cost');
$mailstudents = $plugin->get_config('mailstudents');
$mailteachers = $plugin->get_config('mailteachers');
$mailadmins = $plugin->get_config('mailadmins');
+ $shortname = format_string($course->shortname, true, array('context' => $context));
+
if (!empty($mailstudents)) {
- $a->coursename = $course->fullname;
+ $a->coursename = format_string($course->fullname, true, array('context' => $coursecontext));
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
$eventdata = new stdClass();
$eventdata->name = 'paypal_enrolment';
$eventdata->userfrom = $teacher;
$eventdata->userto = $user;
- $eventdata->subject = get_string("enrolmentnew", '', $course->shortname);
+ $eventdata->subject = get_string("enrolmentnew", '', $shortname);
$eventdata->fullmessage = get_string('welcometocoursetext', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
}
if (!empty($mailteachers)) {
- $a->course = $course->fullname;
+ $a->course = format_string($course->fullname, true, array('context' => $coursecontext));
$a->user = fullname($user);
$eventdata = new stdClass();
$eventdata->name = 'paypal_enrolment';
$eventdata->userfrom = $user;
$eventdata->userto = $teacher;
- $eventdata->subject = get_string("enrolmentnew", '', $course->shortname);
+ $eventdata->subject = get_string("enrolmentnew", '', $shortname);
$eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
}
if (!empty($mailadmins)) {
- $a->course = $course->fullname;
+ $a->course = format_string($course->fullname, true, array('context' => $coursecontext));
$a->user = fullname($user);
$admins = get_admins();
foreach ($admins as $admin) {
$eventdata->name = 'paypal_enrolment';
$eventdata->userfrom = $user;
$eventdata->userto = $admin;
- $eventdata->subject = get_string("enrolmentnew", '', $course->shortname);
+ $eventdata->subject = get_string("enrolmentnew", '', $shortname);
$eventdata->fullmessage = get_string('enrolmentnewuser', '', $a);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
}
$course = $DB->get_record('course', array('id'=>$instance->courseid));
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
- $strloginto = get_string("loginto", "", $course->shortname);
+ $shortname = format_string($course->shortname, true, array('context' => $context));
+ $strloginto = get_string("loginto", "", $shortname);
$strcourses = get_string("courses");
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
'', '', '', '', false, true)) {
} else {
//Sanitise some fields before building the PayPal form
$coursefullname = format_string($course->fullname, true, array('context'=>$context));
- $courseshortname = $course->shortname;
+ $courseshortname = $shortname;
$userfullname = fullname($USER);
$userfirstname = $USER->firstname;
$userlastname = $USER->lastname;
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
}
+$fullname = format_string($course->fullname, true, array('context' => $context));
+
if (is_enrolled($context, NULL, '', true)) { // TODO: use real paypal check
- redirect($destination, get_string('paymentthanks', '', $course->fullname));
+ redirect($destination, get_string('paymentthanks', '', $fullname));
} else { /// Somehow they aren't enrolled yet! :-(
$PAGE->set_url($destination);
echo $OUTPUT->header();
$a = new stdClass();
$a->teacher = get_string('defaultcourseteacher');
- $a->fullname = format_string($course->fullname);
+ $a->fullname = $fullname;
notice(get_string('paymentsorry', '', $a), $destination);
}
require_capability('moodle/course:managefiles', $context);
$PAGE->set_url($url);
-$heading = get_string('coursefiles') . ': ' . $course->fullname;
+$heading = get_string('coursefiles') . ': ' . format_string($course->fullname, true, array('context' => $context));
$strfiles = get_string("files");
if ($node = $PAGE->settingsnav->find('coursefiles', navigation_node::TYPE_SETTING)) {
$node->make_active();
throw new moodle_exception('nofile');
}
// saving file
- $dir = make_upload_directory('temp/wsupload');
+ $dir = make_temp_directory('wsupload');
if (empty($fileinfo['filename'])) {
- $filename = uniqid('wsupload').'_'.time().'.tmp';
+ $filename = uniqid('wsupload', true).'_'.time().'.tmp';
} else {
$filename = $fileinfo['filename'];
}
global $CFG;
// construct directory structure
- $this->temp_dir = $CFG->dataroot . "/temp/latex";
- make_upload_directory('temp/latex');
+ $this->temp_dir = $CFG->tempdir . "/latex";
+ make_temp_directory('latex');
}
/**
if (file_exists("$CFG->dataroot/filter/algebra")) {
remove_dir("$CFG->dataroot/filter/algebra");
}
- if (file_exists("$CFG->dataroot/temp/latex")) {
- remove_dir("$CFG->dataroot/temp/latex");
+ if (file_exists("$CFG->tempdir/latex")) {
+ remove_dir("$CFG->tempdir/latex");
}
$DB->delete_records('cache_filters', array('filter'=>'tex'));
}
print_grade_page_head($courseid, 'outcome', 'import', get_string('importoutcomes', 'grades'));
-$imported_file = $CFG->dataroot . '/temp/outcomeimport/importedfile_'.time().'.csv';
-make_upload_directory('temp/outcomeimport');
+$imported_file = $CFG->tempdir . '/outcomeimport/importedfile_'.time().'.csv';
+make_temp_directory('outcomeimport');
// copying imported file
if (!$upload_form->save_file('userfile', $imported_file, true)) {
$strgrades = get_string('grades');
+ $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
+
/// Calculate file name
- $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.ods");
+ $downloadfilename = clean_filename("$shortname $strgrades.ods");
/// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
/// Sending HTTP headers
@header('Pragma: no-cache');
}
header("Content-Type: application/download\n");
- $downloadfilename = clean_filename("{$this->course->shortname} $strgrades");
+ $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
+ $downloadfilename = clean_filename("$shortname $strgrades");
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
/// Print names of all the fields
$strgrades = get_string('grades');
/// Calculate file name
- $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xls");
+ $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
+ $downloadfilename = clean_filename("$shortname $strgrades.xls");
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
$strgrades = get_string('grades');
/// Calculate file name
- $downloadfilename = clean_filename("{$this->course->shortname} $strgrades.xml");
+ $shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id)));
+ $downloadfilename = clean_filename("$shortname $strgrades.xml");
- make_upload_directory('temp/gradeexport');
- $tempfilename = $CFG->dataroot .'/temp/gradeexport/'. md5(sesskey().microtime().$downloadfilename);
+ make_temp_directory('gradeexport');
+ $tempfilename = $CFG->tempdir .'/gradeexport/'. md5(sesskey().microtime().$downloadfilename);
if (!$handle = fopen($tempfilename, 'w+b')) {
print_error('cannotcreatetempdir');
}
}
if ($importcode = optional_param('importcode', '', PARAM_FILE)) {
- $filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode;
+ $filename = $CFG->tempdir.'/gradeimport/cvs/'.$USER->id.'/'.$importcode;
$fp = fopen($filename, "r");
$headers = fgets($fp, GRADE_CSV_LINE_LENGTH);
$header = explode($csv_delimiter, $headers);
// use current (non-conflicting) time stamp
$importcode = get_new_importcode();
- $filename = make_upload_directory('temp/gradeimport/cvs/'.$USER->id);
+ $filename = make_temp_directory('gradeimport/cvs/'.$USER->id);
$filename = $filename.'/'.$importcode;
$text = $mform->get_file_content('userfile');
} else if ($formdata = $mform2->get_data()) {
$importcode = clean_param($formdata->importcode, PARAM_FILE);
- $filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode;
+ $filename = $CFG->tempdir.'/gradeimport/cvs/'.$USER->id.'/'.$importcode;
if (!file_exists($filename)) {
print_error('cannotuploadfile');
if (!$course->showgrades) {
continue;
}
- $courselink = '<a href="'.$CFG->wwwroot.'/grade/report/user/index.php?id='.$course->id.'&userid='.$this->user->id.'">'.$course->shortname.'</a>';
- $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id));
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
+ $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id)), $courseshortname);
+ $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
// Get course grade_item
$course_item = grade_item::fetch_course_item($course->id);
$deletegroup_disabled = '';
}
-echo $OUTPUT->heading(format_string($course->shortname) .' '.$strgroups, 3);
+echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$strgroups, 3);
echo '<form id="groupeditform" action="index.php" method="post">'."\n";
echo '<div>'."\n";
echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
require('tabs.php');
/// Print overview
-echo $OUTPUT->heading(format_string($course->shortname) .' '.$stroverview, 3);
+echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$stroverview, 3);
echo $strfiltergroups;
$CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing
$CFG->httpswwwroot = $CFG->wwwroot;
$CFG->dataroot = $config->dataroot;
+$CFG->tempdir = $CFG->dataroot.'/temp';
+$CFG->cachedir = $CFG->dataroot.'/temp';
$CFG->admin = $config->admin;
$CFG->docroot = 'http://docs.moodle.org';
$CFG->langotherroot = $CFG->dataroot.'/lang';
$string['appearance'] = 'Appearance';
$string['aspellpath'] = 'Path to aspell';
$string['authentication'] = 'Authentication';
+$string['authpreventaccountcreation'] = 'Prevent account creation when authenticating';
+$string['authpreventaccountcreation_help'] = 'When a user authenticates, an account on the site is automatically created if it doesn\'t yet exist. If an external database, such as LDAP, is used for authentication, but you wish to restrict access to the site to users with an existing account only, then this option should be enabled. New accounts will need to be created manually or via the upload users feature.';
$string['authsettings'] = 'Manage authentication';
$string['autolang'] = 'Language autodetect';
$string['autologinguests'] = 'Auto-login guests';
$string['configunzip'] = 'Indicate the location of your unzip program (Unix only, optional). If specified, this will be used to unpack zip archives on the server. If you leave this blank, then Moodle will use internal routines.';
$string['configuseblogassociations'] = 'Should users be able to organize their blog by associating entries with courses and course modules?';
$string['configuseexternalyui'] = 'Instead of using local files, use online files available on Yahoo‘s servers. WARNING: This requires an internet connection, or no AJAX will work on your site.';
+$string['configusesitenameforsitepages'] = 'If enabled the site\'s shortname will be used for the site pages node in the navigation rather than the string \'Site pages\'';
$string['configusetags'] = 'Should tags functionality across the site be enabled?';
$string['configvariables'] = 'Variables';
$string['configverifychangedemail'] = 'Enables verification of changed email addresses using allowed and denied email domains settings. If this setting is disabled the domains are enforced only when creating new users.';
$string['development'] = 'Development';
$string['devicedetectregex'] = 'Device detection regular expressions';
$string['devicedetectregex_desc'] = '<p>By default, Moodle can detect devices of the type default (desktop PCs, laptops, etc), mobile (phones and small hand held devices), tablet (iPads, Android tablets) and legacy (Internet Explorer 6 users). The theme selector can be used to apply separate themes to all of these. This setting allows regular expressions that allow the detection of extra device types (these take precedence over the default types).</p>
-<p>For example, you could enter the regular expression \'/(MIDP-1.0|Maemo|Windows CE)/\' to detect some commonly used feasture phones add the return value \'featurephone\'. This adds \'featurephone\' on the theme selector that would allow you to add a theme that would be used on these devices. Other phones would still use the theme selected for the mobile device type.</p>';
+<p>For example, you could enter the regular expression \'/(MIDP-1.0|Maemo|Windows CE)/\' to detect some commonly used feature phones add the return value \'featurephone\'. This adds \'featurephone\' on the theme selector that would allow you to add a theme that would be used on these devices. Other phones would still use the theme selected for the mobile device type.</p>';
$string['devicedetectregexexpression'] = 'Regular expression';
$string['devicedetectregexvalue'] = 'Return value';
$string['devicetype'] = 'Device type';
$string['usersupdated'] = 'Users updated';
$string['usersweakpassword'] = 'Users having a weak password';
$string['userquota'] = 'User quota';
+$string['usesitenameforsitepages'] = 'Use site name for site pages';
$string['usetags'] = 'Enable tags functionality';
$string['uubulk'] = 'Select for bulk operations';
$string['uubulkall'] = 'All users';
$string['idnumbertaken'] = 'ID number is already used for another course';
$string['importformatnotimplement'] = 'Sorry, importing this format is not yet implemented!';
$string['incorrectext'] = 'File has an incorrect extension';
+$string['installproblem'] = 'It is usually not possible to recover from errors triggered during installation, you may need to create a new database or use a different database prefix if you want to retry the installation.';
$string['internalauthpassworderror'] = 'Missing password or invalid password policy for internal authentication';
$string['invalidaccess'] = 'This page was not accessed correctly';
$string['invalidaccessparameter'] = 'Invalid access parameter';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
+$string['disableall'] = 'Temporarily disable notifications';
+$string['disableall_help'] = 'Temporarily disable all notifications except those marked as "forced" by the site administrator';
$string['disabled'] = 'Messaging is disabled on this site';
$string['disallowed'] = 'Disallowed';
$string['discussion'] = 'Discussion';
$string['backupkeephelp'] = 'How many recent backups for each course do you want to keep? (older ones will be deleted automatically)';
$string['backuplogdetailed'] = 'Detailed execution log';
$string['backuploglaststatus'] = 'Last execution log';
-$string['backuplogshelp'] = 'If enabled, then course logs will be included in automated backups';
$string['backupmissinguserinfoperms'] = 'Note: This backup contains no user data. Exercise and Workshop activities will not be included in the backup, since these modules are not compatible with this type of backup.';
$string['backupnext'] = 'Next backup';
$string['backupnonisowarning'] = 'Warning: this backup is from a non-Unicode version of Moodle (pre 1.6). If this backup contains any non-ISO-8859-1 texts then they may be CORRUPTED if you try to restore them to this Unicode version of Moodle. See the <a href="http://docs.moodle.org/en/Backup_FAQ">Backup FAQ</a> for more information about how to recover this backup correctly.';
$string['backuptakealook'] = 'Please take a look at your backup logs in:
{$a}';
$string['backupuserfileshelp'] = 'Choose whether user files (eg profile images) should be included in automated backups';
-$string['backupusershelp'] = 'Select whether you want to include all the users in the server or only the needed users for each course';
$string['backupversion'] = 'Backup version';
$string['block'] = 'Block';
$string['blockconfiga'] = 'Configuring a {$a} block';
if ($withprefix){
$name = get_string('category').': ';
}
- $name .=format_string($category->name);
+ $name .= format_string($category->name, true, array('context' => $context));
}
break;
$name = get_string('course').': ';
}
if ($short){
- $name .= format_string($course->shortname);
+ $name .= format_string($course->shortname, true, array('context' => $context));
} else {
$name .= format_string($course->fullname);
}
<?php
/*
-@version V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+@version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Latest version is available at http://adodb.sourceforge.net
Released under both BSD license and Lesser GPL library license.
<?php
/*
-@version V5.06 29 Sept 2008 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+@version V5.06 29 Sept 2008 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Latest version is available at http://adodb.sourceforge.net
Released under both BSD license and Lesser GPL library license.
/*
- V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
<?php
/**
- V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
<?php
/**
- * @version V5.06 16 Oct 2008 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
<?php
/**
- * @version V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
<?php
/**
- * @version V5.06 16 Oct 2008 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
<?php
/**
- * @version V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
<?php
/*
- V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
<?php
-
-
-
-
// security - hide paths
if (!defined('ADODB_DIR')) die();
$ADODB_INCLUDED_LIB = 1;
/*
- @version V5.06 16 Oct 2008 (c) 2000-2010 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
$type = 'C';
}
- if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
- $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
- else
+ if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) {
+ switch (ADODB_QUOTE_FIELDNAMES) {
+ case 'LOWER':
+ $fnameq = $zthis->nameQuote.strtolower($field->name).$zthis->nameQuote;break;
+ case 'NATIVE':
+ $fnameq = $zthis->nameQuote.$field->name.$zthis->nameQuote;break;
+ case 'UPPER':
+ default:
+ $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;break;
+ }
+ } else
$fnameq = $upperfname;
$upperfname = strtoupper($field->name);
if (adodb_key_exists($upperfname,$arrFields,$force)) {
$bad = false;
- if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
- $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
- else
+ if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) {
+ switch (ADODB_QUOTE_FIELDNAMES) {
+ case 'LOWER':
+ $fnameq = $zthis->nameQuote.strtolower($field->name).$zthis->nameQuote;break;
+ case 'NATIVE':
+ $fnameq = $zthis->nameQuote.$field->name.$zthis->nameQuote;break;
+ case 'UPPER':
+ default:
+ $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;break;
+ }
+ } else
$fnameq = $upperfname;
$type = $recordSet->MetaType($field->type);
/*
- V5.06 16 Oct 2008 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
}
if (!$this->_memcache) return false;
- if (!$this->_memcache->set($filename, $contents, $this->compress, $secs2cache)) {
+ if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) {
if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
return false;
}
<?php
/*
- V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
+ V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.