diff --git a/backup/backuplib.php b/backup/backuplib.php
index 3fa5f3dcdf5..3eaea31879c 100644
--- a/backup/backuplib.php
+++ b/backup/backuplib.php
@@ -1,773 +1,4 @@
id]->id = $enrolled_user->id;
- }
- }
- }
-
- /// If we have backupable users
- if ($backupable_users) {
- /// Iterate over users putting their roles
- foreach ($backupable_users as $backupable_user) {
- $backupable_user->info = "";
-
- /// Is needed user or enrolled user, mark it as needed
- if (isset($needed_users[$backupable_user->id]) || isset($enrolled_users[$backupable_user->id])) {
- $backupable_user->info .= "needed";
- } /// Yu: also needed because they can view course
- /// might need another variable
-
- /// Now create the backup_id record
- $backupids_rec->backup_code = $backup_unique_code;
- $backupids_rec->table_name = "user";
- $backupids_rec->old_id = $backupable_user->id;
- $backupids_rec->info = $backupable_user->info;
-
- /// TODO: Change this call inserting to a standard backup_putid() call
- /// And read data acordingly with backup_getid() when needed.
- /// TODO: Also analyse it the "needed" info is really needed for anything. Drop if not.
- /// Insert the user to the backup_ids table. backup_user_info() will use that info
- $status = $DB->insert_record('backup_ids', $backupids_rec, false);
- $count_users++;
- }
- /// Do some output
- backup_flush(30);
- }
-
- /// Prepare Info
- /// Gets the user data
- $info[0][0] = get_string("users");
- $info[0][1] = $count_users;
-
- return $info;
- }
-
- //Returns every needed user (participant) in a course
- //It uses the xxxx_get_participants() function
- //Also it search for users having messages and
- //users having blogs
- //WARNING: It returns only NEEDED users, not every
- // every student and teacher in the course, so it
- //must be merged with backup_get_enrrolled_users !!
- function backup_get_needed_users ($courseid, $includemessages=false, $includeblogs=false) {
- global $CFG, $DB;
-
- $result = false;
-
- $course_modules = $DB->get_records_sql("SELECT cm.id, m.name, cm.instance
- FROM {modules} m, {course_modules} cm
- WHERE m.id = cm.module and
- cm.course = ?", array($courseid));
-
- if ($course_modules) {
- //Iterate over each module
- foreach ($course_modules as $course_module) {
- $modlib = "$CFG->dirroot/mod/$course_module->name/lib.php";
- $modgetparticipants = $course_module->name."_get_participants";
- if (file_exists($modlib)) {
- include_once($modlib);
- if (function_exists($modgetparticipants)) {
- $module_participants = $modgetparticipants($course_module->instance);
- //Add them to result
- if ($module_participants) {
- foreach ($module_participants as $module_participant) {
- $result[$module_participant->id]->id = $module_participant->id;
- }
- }
- }
- }
- }
- }
-
- //Now, add message users if necessary
- if ($includemessages) {
- include_once("$CFG->dirroot/message/lib.php");
- //Get users
- $messageusers = message_get_participants();
- //Add message users to results
- if ($messageusers) {
- foreach ($messageusers as $messageuser) {
- //If id != 0
- if ($messageuser->id !=0) {
- $result[$messageuser->id]->id = $messageuser->id;
- }
- }
- }
- }
-
- //Now, add blog users if necessary
- if ($includeblogs) {
- //Get users
- $blogusers = $DB->get_records_sql("SELECT u.id, u.id FROM {user} u WHERE u.id IN (SELECT DISTINCT userid FROM {post})");
-
- //Add blog users to results
- if ($blogusers) {
- foreach ($blogusers as $bloguser) {
- //If id != 0
- if ($bloguser->id !=0) {
- $result[$bloguser->id]->id = $bloguser->id;
- }
- }
- }
- }
-
- return $result;
-
- }
-
- //Returns every enrolled user (student and teacher) in a course
-
- function backup_get_enrolled_users ($courseid) {
- global $CFG;
-
- return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
- }
-
- //Returns all users ids (every record in users table)
- function backup_get_all_users() {
- global $DB;
-
- return $DB->get_records('user', null, '', 'id, id');
- }
-
- //Calculate the number of log entries to backup
- //Return an array of info (name,value)
- function log_check_backup($course) {
- global $CFG, $DB;
-
- //Now execute the count
- $ids = $DB->count_records("log", array("course"=>$course));
-
- //Gets the user data
- $info[0][0] = get_string("logs");
- if ($ids) {
- $info[0][1] = $ids;
- } else {
- $info[0][1] = 0;
- }
-
- return $info;
- }
-
- //Calculate the number of user files to backup
- //Under $CFG->dataroot/users
- //Return an array of info (name,value)
- function user_files_check_backup($course,$backup_unique_code) {
- global $CFG, $DB;
-
- $count = 0;
-
- $backup_users = $DB->get_recordset("backup_ids",
- array('backup_code'=>$backup_unique_code, 'table_name'=>'user'), "", "id, old_id");
-
- foreach ($backup_users as $user) {
- //TODO: deleted old user pic processing
- }
- $backup_users->close();
- //Gets the user data
- $info[0][0] = get_string('userswithfiles', 'moodle');
- $info[0][1] = $count;
-
- return $info;
- }
-
- /**
- * Calculate the number of course files to backup
- * under $CFG->dataroot/$course, except $CFG->moddata, and backupdata
- * and put them (their path) in backup_ids
- * Return an array of info (name,value)
- */
- function course_files_check_backup($course, $backup_unique_code) {
- global $CFG, $DB;
-
- $rootdir = $CFG->dataroot."/$course";
- //Check if directory exists
- if (is_dir($rootdir)) {
- //Get files and directories without descend
- $coursedirs = get_directory_list($rootdir,$CFG->moddata,false,true,true);
- $backupdata_dir = "backupdata";
- foreach ($coursedirs as $dir) {
- //Check it isn't backupdata_dir
- if (strpos($dir,$backupdata_dir)!==0) {
- //Insert them into backup_files
- $file = new stdClass();
- $file->backup_code = $backup_unique_code;
- $file->file_type = 'course';
- $file->path = $dir;
- $status = $DB->insert_record("backup_files", $file);
- }
- //Do some output
- backup_flush(30);
- }
- }
-
- //Now execute the select
- $ids = $DB->get_records_sql("SELECT DISTINCT b.path, b.old_id
- FROM {backup_files} b
- WHERE backup_code = ? AND
- file_type = 'course'", array($backup_unique_code));
- //Gets the user data
- $info = array();
- $info[0] = array();
- $info[0][0] = get_string("files");
- if ($ids) {
- $info[0][1] = count($ids);
- } else {
- $info[0][1] = 0;
- }
-
- return $info;
- }
-
- /**
- * Calculate the number of site files to backup
- * under $CFG->dataroot/SITEID
- * Their path is already in backup_ids, put there by modules check_backup functions.
- * Modules only put in paths of files that are used.
- *
- * Return an array of info (name,value)
- */
- function site_files_check_backup($course, $backup_unique_code) {
- global $CFG, $DB;
-
- //execute the select, records have been inserted by modules during their ****_check_backup_mods function.
- $ids = $DB->get_records_sql("SELECT DISTINCT b.path
- FROM {backup_files} b
- WHERE backup_code = ? AND
- file_type = 'site'", array($backup_unique_code));
- //Gets the user data
- $info = array();
- $info[0] = array();
- $info[0][0] = get_string('files');
- if ($ids) {
- $info[0][1] = count($ids);
- } else {
- $info[0][1] = 0;
- }
-
- return $info;
- }
-
- //Function to check and create the needed moddata dir to
- //save all the mod backup files. We always name it moddata
- //to be able to restore it, but in restore we check for
- //$CFG->moddata !!
- function check_and_create_moddata_dir($backup_unique_code) {
- global $CFG;
-
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/moddata",true);
-
- return $status;
- }
-
- //Function to check and create the "user_files" dir to
- //save all the user files we need from "users" dir
- function check_and_create_user_files_dir($backup_unique_code) {
- global $CFG;
-
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/user_files",true);
-
- return $status;
- }
-
- //Function to check and create the "group_files" dir to
- //save all the user files we need from "groups" dir
- function check_and_create_group_files_dir($backup_unique_code) {
- global $CFG;
-
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/group_files",true);
-
- return $status;
- }
-
- //Function to check and create the "course_files" dir to
- //save all the course files we need from "CFG->datadir/course" dir
- function check_and_create_course_files_dir($backup_unique_code) {
- global $CFG;
-
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/course_files",true);
-
- return $status;
- }
-
- //Function to check and create the "site_files" dir to
- //save all the course files we need from "CFG->datadir/SITEID" dir
- function check_and_create_site_files_dir($backup_unique_code) {
- global $CFG;
-
- $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/site_files",true);
-
- return $status;
- }
-
- //Function to create, open and write header of the xml file
- function backup_open_xml($backup_unique_code) {
- global $CFG;
-
- $status = true;
-
- //Open for writing
-
- $file = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
- $backup_file = fopen($file,"w");
- //Writes the header
- $status = fwrite ($backup_file,"\n");
- if ($status) {
- $status = fwrite ($backup_file,start_tag("MOODLE_BACKUP",0,true));
- }
- if ($status) {
- return $backup_file;
- } else {
- return false;
- }
- }
-
- //Close the file
- function backup_close_xml($backup_file) {
- $status = fwrite ($backup_file,end_tag("MOODLE_BACKUP",0,true));
- return fclose($backup_file);
- }
-
- //Return the xml start tag
- function start_tag($tag,$level=0,$endline=false,$attributes=null) {
- if ($endline) {
- $endchar = "\n";
- } else {
- $endchar = "";
- }
- $attrstring = '';
- if (!empty($attributes) && is_array($attributes)) {
- foreach ($attributes as $key => $value) {
- $attrstring .= " ".xml_tag_safe_content($key)."=\"".
- xml_tag_safe_content($value)."\"";
- }
- }
- return str_repeat(" ",$level*2)."<".strtoupper($tag).$attrstring.">".$endchar;
- }
-
- //Return the xml end tag
- function end_tag($tag,$level=0,$endline=true) {
- if ($endline) {
- $endchar = "\n";
- } else {
- $endchar = "";
- }
- return str_repeat(" ",$level*2)."".strtoupper($tag).">".$endchar;
- }
-
- //Return the start tag, the contents and the end tag
- function full_tag($tag,$level=0,$endline=true,$content,$attributes=null) {
- global $CFG;
-
- //Here we encode absolute links
- // MDL-10770
- if (is_null($content)) {
- $content = '$@NULL@$';
- } else {
- $content = backup_encode_absolute_links($content);
- }
- $st = start_tag($tag,$level,$endline,$attributes);
-
- $co = xml_tag_safe_content($content);
-
- $et = end_tag($tag,0,true);
-
- return $st.$co.$et;
- }
-
-
- function xml_tag_safe_content($content) {
- global $CFG;
- //If enabled, we strip all the control chars (\x0-\x1f) from the text but tabs (\x9),
- //newlines (\xa) and returns (\xd). The delete control char (\x7f) is also included.
- //because they are forbiden in XML 1.0 specs. The expression below seems to be
- //UTF-8 safe too because it simply ignores the rest of characters.
- $content = preg_replace("/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is","",$content);
- $content = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content));
- return $content;
- }
-
- //Prints General info about the course
- //name, moodle_version (internal and release), backup_version, date, info in file...
- function backup_general_info ($bf,$preferences) {
- global $CFG, $DB;
-
- fwrite ($bf,start_tag("INFO",1,true));
-
- //The name of the backup
- fwrite ($bf,full_tag("NAME",2,false,$preferences->backup_name));
- //The moodle_version
- fwrite ($bf,full_tag("MOODLE_VERSION",2,false,$preferences->moodle_version));
- fwrite ($bf,full_tag("MOODLE_RELEASE",2,false,$preferences->moodle_release));
- //The backup_version
- fwrite ($bf,full_tag("BACKUP_VERSION",2,false,$preferences->backup_version));
- fwrite ($bf,full_tag("BACKUP_RELEASE",2,false,$preferences->backup_release));
- //The date
- fwrite ($bf,full_tag("DATE",2,false,$preferences->backup_unique_code));
- //The original site wwwroot
- fwrite ($bf,full_tag("ORIGINAL_WWWROOT",2,false,$CFG->wwwroot));
- //The original site identifier. MD5 hashed for security.
- fwrite ($bf,full_tag("ORIGINAL_SITE_IDENTIFIER_HASH",2,false,md5(get_site_identifier())));
- //Indicate if it includes external MNET users
- $sql = "SELECT b.old_id
- FROM {backup_ids} b
- JOIN {user} u ON b.old_id=u.id
- WHERE b.backup_code = ?
- AND b.table_name = 'user' AND u.mnethostid != ?";
- if ($DB->record_exists_sql($sql, array($preferences->backup_unique_code, $CFG->mnet_localhost_id))) {
- fwrite ($bf,full_tag("MNET_REMOTEUSERS",2,false,'true'));
- }
- //Te includes tag
- fwrite ($bf,start_tag("DETAILS",2,true));
- //Now, go to mod element of preferences to print its status
- foreach ($preferences->mods as $element) {
- //Calculate info
- $included = "false";
- $userinfo = "false";
- if ($element->backup) {
- $included = "true";
- if ($element->userinfo) {
- $userinfo = "true";
- }
- }
- //Prints the mod start
- fwrite ($bf,start_tag("MOD",3,true));
- fwrite ($bf,full_tag("NAME",4,false,$element->name));
- fwrite ($bf,full_tag("INCLUDED",4,false,$included));
- fwrite ($bf,full_tag("USERINFO",4,false,$userinfo));
-
- if (isset($preferences->mods[$element->name]->instances)
- && is_array($preferences->mods[$element->name]->instances)
- && count($preferences->mods[$element->name]->instances)) {
- fwrite ($bf, start_tag("INSTANCES",4,true));
- foreach ($preferences->mods[$element->name]->instances as $id => $object) {
- if (!empty($object->backup)) {
- //Calculate info
- $included = "false";
- $userinfo = "false";
- if ($object->backup) {
- $included = "true";
- if ($object->userinfo) {
- $userinfo = "true";
- }
- }
- fwrite ($bf, start_tag("INSTANCE",5,true));
- fwrite ($bf, full_tag("ID",5,false,$id));
- fwrite ($bf, full_tag("NAME",5,false,$object->name));
- fwrite ($bf, full_tag("INCLUDED",5,false,$included)) ;
- fwrite ($bf, full_tag("USERINFO",5,false,$userinfo));
- fwrite ($bf, end_tag("INSTANCE",5,true));
- }
- }
- fwrite ($bf, end_tag("INSTANCES",4,true));
- }
-
-
- //Print the end
- fwrite ($bf,end_tag("MOD",3,true));
- }
- //The metacourse in backup
- if ($preferences->backup_metacourse == 1) {
- fwrite ($bf,full_tag("METACOURSE",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("METACOURSE",3,false,"false"));
- }
- //The user in backup
- if ($preferences->backup_users == 1) {
- fwrite ($bf,full_tag("USERS",3,false,"course"));
- } else if ($preferences->backup_users == 0) {
- fwrite ($bf,full_tag("USERS",3,false,"all"));
- } else {
- fwrite ($bf,full_tag("USERS",3,false,"none"));
- }
- //The logs in backup
- if ($preferences->backup_logs == 1) {
- fwrite ($bf,full_tag("LOGS",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("LOGS",3,false,"false"));
- }
- //The user files
- if ($preferences->backup_user_files == 1) {
- fwrite ($bf,full_tag("USERFILES",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("USERFILES",3,false,"false"));
- }
- //The course files
- if ($preferences->backup_course_files == 1) {
- fwrite ($bf,full_tag("COURSEFILES",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("COURSEFILES",3,false,"false"));
- }
- //The site files
- if ($preferences->backup_site_files == 1) {
- fwrite ($bf,full_tag("SITEFILES",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("SITEFILES",3,false,"false"));
- }
- //The gradebook histories
- if (empty($CFG->disablegradehistory) && $preferences->backup_gradebook_history == 1) {
- fwrite ($bf,full_tag("GRADEBOOKHISTORIES",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("GRADEBOOKHISTORIES",3,false,"false"));
- }
- //The messages in backup
- if ($preferences->backup_messages == 1 && $preferences->backup_course == SITEID) {
- fwrite ($bf,full_tag("MESSAGES",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("MESSAGES",3,false,"false"));
- }
- //The blogs in backup
- if ($preferences->backup_blogs == 1 && $preferences->backup_course == SITEID) {
- fwrite ($bf,full_tag("BLOGS",3,false,"true"));
- } else {
- fwrite ($bf,full_tag("BLOGS",3,false,"false"));
- }
- //The mode of writing the block data
- fwrite ($bf,full_tag('BLOCKFORMAT',3,false,'instances'));
- fwrite ($bf,end_tag("DETAILS",2,true));
-
- $status = fwrite ($bf,end_tag("INFO",1,true));
-
- ///Roles stuff goes in here
-
- fwrite ($bf, start_tag('ROLES', 1, true));
- $roles = backup_fetch_roles($preferences);
-
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
- $coursecontext = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
-
- foreach ($roles as $role) {
- fwrite ($bf,start_tag('ROLE',2,true));
- fwrite ($bf,full_tag('ID', 3, false, $role->id));
- fwrite ($bf,full_tag('NAME',3,false,$role->name));
- fwrite ($bf,full_tag('SHORTNAME',3,false,$role->shortname));
- /// Calculate $role name in course
- $nameincourse = role_get_name($role, $coursecontext);
- if ($nameincourse != $role->name) {
- fwrite ($bf,full_tag('NAMEINCOURSE', 3, false, $nameincourse));
- }
- /// List of context level where this role can be assigned.
- fwrite ($bf,start_tag('CONTEXTLEVELS',3,true));
- $contextlevels = get_role_contextlevels($role->id);
- foreach ($contextlevels as $cl) {
- fwrite ($bf,full_tag('CONTEXTLEVEL', 4, false, $cl));
- }
- fwrite ($bf,end_tag('CONTEXTLEVELS',3,true));
- /// find and write all default capabilities
- fwrite ($bf,start_tag('CAPABILITIES',3,true));
- // pull out all default (site context) capabilities
- if ($capabilities = role_context_capabilities($role->id, $sitecontext)) {
- foreach ($capabilities as $capability=>$value) {
- fwrite ($bf,start_tag('CAPABILITY',4,true));
- fwrite ($bf,full_tag('NAME', 5, false, $capability));
- fwrite ($bf,full_tag('PERMISSION', 5, false, $value));
- // use this to pull out the other info (timemodified and modifierid)
-
- $cap = $DB->get_record_sql("SELECT *
- FROM {role_capabilities}
- WHERE capability = ?
- AND contextid = ?
- AND roleid = ?", array($capability, $sitecontext->id, $role->id));
- fwrite ($bf, full_tag("TIMEMODIFIED", 5, false, $cap->timemodified));
- fwrite ($bf, full_tag("MODIFIERID", 5, false, $cap->modifierid));
- fwrite ($bf,end_tag('CAPABILITY',4,true));
- }
- }
- fwrite ($bf,end_tag('CAPABILITIES',3,true));
- fwrite ($bf,end_tag('ROLE',2,true));
- }
- fwrite ($bf,end_tag('ROLES', 1, true));
- return $status;
- }
-
- //Prints course's general info (table course)
- function backup_course_start ($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- //Course open tag
- fwrite ($bf,start_tag("COURSE",1,true));
- //Header open tag
- fwrite ($bf,start_tag("HEADER",2,true));
-
- //Get info from course
- $course = $DB->get_record("course", array("id"=>$preferences->backup_course));
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- if ($course) {
- //Prints course info
- fwrite ($bf,full_tag("ID",3,false,$course->id));
- //Obtain the category
- $category = $DB->get_record("course_categories", array("id"=>"$course->category"));
- if ($category) {
- //Prints category info
- fwrite ($bf,start_tag("CATEGORY",3,true));
- fwrite ($bf,full_tag("ID",4,false,$course->category));
- fwrite ($bf,full_tag("NAME",4,false,$category->name));
- fwrite ($bf,end_tag("CATEGORY",3,true));
- }
- //Continues with the course
- fwrite ($bf,full_tag("PASSWORD",3,false,$course->password));
- fwrite ($bf,full_tag("FULLNAME",3,false,$course->fullname));
- fwrite ($bf,full_tag("SHORTNAME",3,false,$course->shortname));
- fwrite ($bf,full_tag("IDNUMBER",3,false,$course->idnumber));
- fwrite ($bf,full_tag("SUMMARY",3,false,$course->summary));
- fwrite ($bf,full_tag("FORMAT",3,false,$course->format));
- fwrite ($bf,full_tag("SHOWGRADES",3,false,$course->showgrades));
- fwrite ($bf,full_tag("NEWSITEMS",3,false,$course->newsitems));
- fwrite ($bf,full_tag("GUEST",3,false,$course->guest));
- fwrite ($bf,full_tag("STARTDATE",3,false,$course->startdate));
- fwrite ($bf,full_tag("NUMSECTIONS",3,false,$course->numsections));
- //fwrite ($bf,full_tag("SHOWRECENT",3,false,$course->showrecent)); INFO: This is out in 1.3
- fwrite ($bf,full_tag("MAXBYTES",3,false,$course->maxbytes));
- fwrite ($bf,full_tag("SHOWREPORTS",3,false,$course->showreports));
- fwrite ($bf,full_tag("GROUPMODE",3,false,$course->groupmode));
- fwrite ($bf,full_tag("GROUPMODEFORCE",3,false,$course->groupmodeforce));
- fwrite ($bf,full_tag("DEFAULTGROUPINGID",3,false,$course->defaultgroupingid));
- fwrite ($bf,full_tag("LANG",3,false,$course->lang));
- fwrite ($bf,full_tag("THEME",3,false,$course->theme));
- fwrite ($bf,full_tag("COST",3,false,$course->cost));
- fwrite ($bf,full_tag("CURRENCY",3,false,$course->currency));
- fwrite ($bf,full_tag("MARKER",3,false,$course->marker));
- fwrite ($bf,full_tag("VISIBLE",3,false,$course->visible));
- fwrite ($bf,full_tag("HIDDENSECTIONS",3,false,$course->hiddensections));
- fwrite ($bf,full_tag("TIMECREATED",3,false,$course->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",3,false,$course->timemodified));
- //If not selected, force metacourse to 0
- if (!$preferences->backup_metacourse) {
- $status = fwrite ($bf,full_tag("METACOURSE",3,false,'0'));
- //else, export the field as is in DB
- } else {
- $status = fwrite ($bf,full_tag("METACOURSE",3,false,$course->metacourse));
- }
- fwrite ($bf,full_tag("EXPIRENOTIFY",3,false,$course->expirynotify));
- fwrite ($bf,full_tag("NOTIFYSTUDENTS",3,false,$course->notifystudents));
- fwrite ($bf,full_tag("EXPIRYTHRESHOLD",3,false,$course->expirythreshold));
- fwrite ($bf,full_tag("ENROLLABLE",3,false,$course->enrollable));
- fwrite ($bf,full_tag("ENROLSTARTDATE",3,false,$course->enrolstartdate));
- fwrite ($bf,full_tag("ENROLENDDATE",3,false,$course->enrolenddate));
- fwrite ($bf,full_tag("ENROLPERIOD",3,false,$course->enrolperiod));
- fwrite ($bf,full_tag("ENABLECOMPLETION",3,false,$course->enablecompletion));
-
- // Write role assigns, overrides, etc.
- write_per_context_data($bf, $preferences, $context, 3);
-
- // Print header end
- fwrite ($bf,end_tag("HEADER",2,true));
- } else {
- $status = false;
- }
-
- return $status;
- }
-
- //Prints course's end tag
- function backup_course_end ($bf,$preferences) {
-
- //Course end tag
- $status = fwrite ($bf,end_tag("COURSE",1,true));
-
- return $status;
-
- }
-
- //Prints course's metacourse info (table course_meta)
- function backup_course_metacourse ($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- //Get info from meta
- $parents = $DB->get_records_sql ("SELECT m.*, c.idnumber, c.shortname
- FROM {course_meta} m, {course} c
- WHERE m.child_course = ? AND
- m.parent_course = c.id", array($preferences->backup_course));
- $childs = $DB->get_records_sql ("SELECT m.*, c.idnumber, c.shortname
- FROM {course_meta} m, {course} c
- WHERE m.parent_course = ? AND
- m.child_course = c.id", array($preferences->backup_course));
-
- if ($parents || $childs) {
- //metacourse open tag
- fwrite ($bf,start_tag("METACOURSE",2,true));
- if ($parents) {
- fwrite($bf, start_tag("PARENTS",3,true));
- //Iterate over every parent
- foreach ($parents as $parent) {
- //Begin parent
- fwrite ($bf,start_tag("PARENT",4,true));
- fwrite ($bf,full_tag("ID",5,false,$parent->parent_course));
- fwrite ($bf,full_tag("IDNUMBER",5,false,$parent->idnumber));
- fwrite ($bf,full_tag("SHORTNAME",5,false,$parent->shortname));
- //End parent
- fwrite ($bf,end_tag("PARENT",4,true));
- }
- fwrite ($bf,end_tag("PARENTS",3,true));
- }
- if ($childs) {
- fwrite($bf, start_tag("CHILDS",3,true));
- //Iterate over every child
- foreach ($childs as $child) {
- //Begin parent
- fwrite ($bf,start_tag("CHILD",4,true));
- fwrite ($bf,full_tag("ID",5,false,$child->child_course));
- fwrite ($bf,full_tag("IDNUMBER",5,false,$child->idnumber));
- fwrite ($bf,full_tag("SHORTNAME",5,false,$child->shortname));
- //End parent
- fwrite ($bf,end_tag("CHILD",4,true));
- }
- fwrite ($bf,end_tag("CHILDS",3,true));
- }
- //metacourse close tag
- $status = fwrite ($bf,end_tag("METACOURSE",3,true));
- }
-
- return $status;
-
- }
-
//Prints course's messages info (tables message, message_read and message_contacts)
function backup_messages ($bf,$preferences) {
global $CFG, $DB;
@@ -969,141 +200,6 @@
fwrite($bf, end_tag("BLOG",$level,true));
}
-
-
- /**
- * Prints course's blocks info (table block_instance)
- */
- function backup_course_blocks ($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- // Read all of the block table
- $blocks = blocks_get_record();
-
- $pages = array();
- $pages[] = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course);
-
- // get course structure
- $course = $DB->get_record('course', array('id'=>$preferences->backup_course));
- $modinfo =& get_fast_modinfo($course);
-
- // backup blocks on mod pages.
- foreach($preferences->mods as $module) {
- if (!$module->backup) {
- continue;
- }
-
- if (empty($modinfo->instances[$module->name])) {
- continue;
- }
-
- $pagetypes = page_import_types('mod/'.$module->name.'/');
- if (empty($pagetypes)) {
- continue;
- }
-
- foreach($pagetypes as $pagetype) {
- foreach($modinfo->instances[$module->name] as $cm) {
- if (!empty($module->instances[$cm->instance]->backup)) {
- $pages[] = page_create_object($pagetype, $cm->instance);
- }
- }
- }
- }
-
- //Blocks open tag
- fwrite ($bf,start_tag('BLOCKS',2,true));
-
- foreach($pages as $page) {
- if ($instances = array()) { // TODO fix.
- //Iterate over every block
- foreach ($instances as $position) {
- foreach ($position as $instance) {
-
- //If we somehow have a block with an invalid id, skip it
- if(empty($blocks[$instance->blockid]->name)) {
- continue;
- }
- $blockname = $blocks[$instance->blockid]->name;
-
- if (!$blockobj = block_instance($blockname, $instance)) {
- // Invalid block
- continue;
- }
-
- // encode absolute links in block config
- $instance->configdata = $blockobj->get_backup_encoded_config();
-
- //Begin Block
- fwrite ($bf,start_tag('BLOCK',3,true));
- fwrite ($bf,full_tag('ID', 4, false,$instance->id));
- fwrite ($bf,full_tag('NAME',4,false,$blockname));
- fwrite ($bf,full_tag('PAGEID',4,false,$instance->pageid));
- fwrite ($bf,full_tag('PAGETYPE',4,false,$instance->pagetype));
- fwrite ($bf,full_tag('POSITION',4,false,$instance->position));
- fwrite ($bf,full_tag('WEIGHT',4,false,$instance->weight));
- fwrite ($bf,full_tag('VISIBLE',4,false,$instance->visible));
- fwrite ($bf,full_tag('CONFIGDATA',4,false,$instance->configdata));
- // Write instance data if needed
- if ($blockobj->backuprestore_instancedata_used()) {
- fwrite ($bf,start_tag('INSTANCEDATA',4,true));
- $status = $blockobj->instance_backup($bf, $preferences);
- fwrite ($bf,end_tag('INSTANCEDATA',4,true));
- }
-
- // Write role assigns, overrides, etc.
- $context = get_context_instance(CONTEXT_BLOCK, $instance->id);
- write_per_context_data($bf, $preferences, $context, 4);
-
- //End Block
- fwrite ($bf,end_tag('BLOCK',3,true));
- }
- }
- }
- }
-
- //Blocks close tag
- $status = fwrite ($bf,end_tag('BLOCKS',2,true));
-
- return $status;
-
- }
-
- //Prints course's sections info (table course_sections)
- function backup_course_sections ($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
-
- //Get info from sections
- $section=false;
- if ($sections = $DB->get_records("course_sections", array("course"=>$preferences->backup_course),"section")) {
- //Section open tag
- fwrite ($bf,start_tag("SECTIONS",2,true));
- //Iterate over every section (ordered by section)
- foreach ($sections as $section) {
- //Begin Section
- fwrite ($bf,start_tag("SECTION",3,true));
- fwrite ($bf,full_tag("ID",4,false,$section->id));
- fwrite ($bf,full_tag("NUMBER",4,false,$section->section));
- fwrite ($bf,full_tag("SUMMARY",4,false,$section->summary));
- fwrite ($bf,full_tag("VISIBLE",4,false,$section->visible));
- //Now print the mods in section
- backup_course_modules ($bf,$preferences,$section);
- //End section
- fwrite ($bf,end_tag("SECTION",3,true));
- }
- //Section close tag
- $status = fwrite ($bf,end_tag("SECTIONS",2,true));
- }
-
- return $status;
-
- }
-
//Prints course's format data (any data the format might want to save).
function backup_format_data ($bf,$preferences) {
global $CFG, $DB;
@@ -1133,346 +229,6 @@
return fwrite ($bf,end_tag("FORMATDATA",2,true));
}
- //Prints course's modules info (table course_modules)
- //Only for selected mods in preferences
- function backup_course_modules ($bf,$preferences,$section) {
- global $CFG, $DB;
-
- $status = true;
-
- $first_record = true;
-
- $course=$DB->get_record('course',array('id'=>$preferences->backup_course));
- if(!$course) {
- return false;
- }
-
- //Now print the mods in section
- //Extracts mod id from sequence
- $tok = strtok($section->sequence,",");
- while ($tok) {
- //Get module's type
- $moduletype = get_module_type ($preferences->backup_course,$tok);
- //Check if we've selected to backup that type
- if ($moduletype and $preferences->mods[$moduletype]->backup) {
- $selected = true;
- } else {
- $selected = false;
- }
-
- if ($selected) {
- $context = get_context_instance(CONTEXT_MODULE, $tok);
- //Gets course_module data from db - verify activity exists and is enabled!
- $sql = "SELECT cm.*
- FROM {course_modules} cm
- JOIN {modules} m ON m.id = cm.module
- JOIN {".$moduletype."} a ON a.id = cm.instance
- WHERE m.visible = 1 AND cm.id = $tok";
- if (!$course_module = $DB->get_record_sql($sql)) {
- // cm exists but activity instance missing - probably caused by double clicking
- $tok = strtok(",");
- continue;
- }
-
- //If it's the first, pring MODS tag
- if ($first_record) {
- fwrite ($bf,start_tag("MODS",4,true));
- $first_record = false;
- }
- // if we're doing selected instances, check that too.
- if (is_array($preferences->mods[$moduletype]->instances)
- && count($preferences->mods[$moduletype]->instances)
- && (!array_key_exists($course_module->instance,$preferences->mods[$moduletype]->instances)
- || empty($preferences->mods[$moduletype]->instances[$course_module->instance]->backup))) {
- $tok = strtok(",");
- continue;
- }
-
- // find all role values that has an override in this context
- $roles = $DB->get_records('role_capabilities', array('contextid'=>$context->id));
-
- //Print mod info from course_modules
- fwrite ($bf,start_tag("MOD",5,true));
- //Save neccesary info to backup_ids
- fwrite ($bf,full_tag("ID",6,false,$tok));
- fwrite ($bf,full_tag("TYPE",6,false,$moduletype));
- fwrite ($bf,full_tag("INSTANCE",6,false,$course_module->instance));
- fwrite ($bf,full_tag("ADDED",6,false,$course_module->added));
- fwrite ($bf,full_tag("SCORE",6,false,$course_module->score));
- fwrite ($bf,full_tag("INDENT",6,false,$course_module->indent));
- fwrite ($bf,full_tag("VISIBLE",6,false,$course_module->visible));
- fwrite ($bf,full_tag("GROUPMODE",6,false,$course_module->groupmode));
- fwrite ($bf,full_tag("GROUPINGID",6,false,$course_module->groupingid));
- fwrite ($bf,full_tag("GROUPMEMBERSONLY",6,false,$course_module->groupmembersonly));
- fwrite ($bf,full_tag("IDNUMBER",6,false,$course_module->idnumber));
- fwrite ($bf,full_tag("COMPLETION",6,false,$course_module->completion));
- fwrite ($bf,full_tag("COMPLETIONGRADEITEMNUMBER",6,false,$course_module->completiongradeitemnumber));
- fwrite ($bf,full_tag("COMPLETIONVIEW",6,false,$course_module->completionview));
- fwrite ($bf,full_tag("COMPLETIONEXPECTED",6,false,$course_module->completionexpected));
- fwrite ($bf,full_tag("AVAILABLEFROM",6,false,$course_module->availablefrom));
- fwrite ($bf,full_tag("AVAILABLEUNTIL",6,false,$course_module->availableuntil));
- fwrite ($bf,full_tag("SHOWAVAILABILITY",6,false,$course_module->showavailability));
-
- // Write role assigns, overrides, etc.
- write_per_context_data($bf, $preferences, $context, 6);
-
- // write completion data if enabled and user data enabled
- require_once($CFG->libdir.'/completionlib.php');
- $completion=new completion_info($course);
- if($completion->is_enabled($course_module) &&
- backup_userdata_selected($preferences,$moduletype,$course_module->instance)) {
- fwrite ($bf,start_tag("COMPLETIONDATA",6,true));
-
- // Get all completion records for this module and loop
- $data=$DB->get_records('course_modules_completion',array('coursemoduleid'=>$course_module->id));
- $data=$data ? $data : array();
- foreach($data as $completion) {
- // Write completion record
- fwrite ($bf,start_tag("COMPLETION",7,true));
- fwrite ($bf,full_tag("USERID",8,false,$completion->userid));
- fwrite ($bf,full_tag("COMPLETIONSTATE",8,false,$completion->completionstate));
- fwrite ($bf,full_tag("VIEWED",8,false,$completion->viewed));
- fwrite ($bf,full_tag("TIMEMODIFIED",8,false,$completion->timemodified));
- fwrite ($bf,end_tag("COMPLETION",7,true));
- }
-
- fwrite ($bf,end_tag("COMPLETIONDATA",6,true));
- }
-
- // Write availability data if enabled
- require_once($CFG->libdir.'/conditionlib.php');
- if(!empty($CFG->enableavailability)) {
- fwrite ($bf,start_tag("AVAILABILITYDATA",6,true));
- // Get all availability restrictions for this activity
- $data=$DB->get_records('course_modules_availability',
- array('coursemoduleid'=>$course_module->id));
- $data=$data ? $data : array();
- foreach($data as $availability) {
- // Write availability record
- fwrite ($bf,start_tag("AVAILABILITY",7,true));
- fwrite ($bf,full_tag("SOURCECMID",8,false,$availability->sourcecmid));
- fwrite ($bf,full_tag("REQUIREDCOMPLETION",8,false,$availability->requiredcompletion));
- fwrite ($bf,full_tag("GRADEITEMID",8,false,$availability->gradeitemid));
- fwrite ($bf,full_tag("GRADEMIN",8,false,$availability->grademin));
- fwrite ($bf,full_tag("GRADEMAX",8,false,$availability->grademax));
- fwrite ($bf,end_tag("AVAILABILITY",7,true));
- }
- fwrite ($bf,end_tag("AVAILABILITYDATA",6,true));
- }
-
- fwrite ($bf,end_tag("MOD",5,true));
- }
- //check for next
- $tok = strtok(",");
- }
-
- //Si ha habido modulos, final de MODS
- if (!$first_record) {
- $status =fwrite ($bf,end_tag("MODS",4,true));
- }
-
- return $status;
- }
-
- //Print users to xml
- //Only users previously calculated in backup_ids will output
- //
- function backup_user_info ($bf,$preferences) {
- global $CFG, $DB;
- require_once ($CFG->dirroot.'/tag/lib.php');
-
- $status = true;
-
- // Use a recordset to for the memory handling on to
- // the DB and run faster
- // Note the outer join with mnet_host: It shouldn't be neccesary
- // but there are some sites having mnet_host records missing
- // and that causes backup to fail (no users). Being a bit more
- // flexible here (outer joing) we bypass the problem and doesn't
- // cause more troubles. Eloy - MDL-16879
- $users = $DB->get_recordset_sql("SELECT b.old_id, b.table_name, b.info,
- u.*, m.wwwroot
- FROM {backup_ids} b
- JOIN {user} u ON b.old_id=u.id
- LEFT JOIN {mnet_host} m ON u.mnethostid=m.id
- WHERE b.backup_code = ? AND
- b.table_name = 'user'", array($preferences->backup_unique_code));
-
- //If we have users to backup
- if ($users && $users->valid()) {
- //Begin Users tag
- fwrite ($bf,start_tag("USERS",2,true));
- $counter = 0;
- //With every user
- foreach ($users as $user) {
- //Begin User tag
- fwrite ($bf,start_tag("USER",3,true));
- //Output all user data
- fwrite ($bf,full_tag("ID",4,false,$user->id));
- fwrite ($bf,full_tag("AUTH",4,false,$user->auth));
- fwrite ($bf,full_tag("CONFIRMED",4,false,$user->confirmed));
- fwrite ($bf,full_tag("POLICYAGREED",4,false,$user->policyagreed));
- fwrite ($bf,full_tag("DELETED",4,false,$user->deleted));
- fwrite ($bf,full_tag("USERNAME",4,false,$user->username));
- // Prevent user passwords in backup files unless
- // $CFG->includeuserpasswordsinbackup is defined. MDL-20838
- if (!empty($CFG->includeuserpasswordsinbackup)) {
- fwrite ($bf,full_tag("PASSWORD",4,false,$user->password));
- }
- fwrite ($bf,full_tag("IDNUMBER",4,false,$user->idnumber));
- fwrite ($bf,full_tag("FIRSTNAME",4,false,$user->firstname));
- fwrite ($bf,full_tag("LASTNAME",4,false,$user->lastname));
- fwrite ($bf,full_tag("EMAIL",4,false,$user->email));
- fwrite ($bf,full_tag("EMAILSTOP",4,false,$user->emailstop));
- fwrite ($bf,full_tag("ICQ",4,false,$user->icq));
- fwrite ($bf,full_tag("SKYPE",4,false,$user->skype));
- fwrite ($bf,full_tag("YAHOO",4,false,$user->yahoo));
- fwrite ($bf,full_tag("AIM",4,false,$user->aim));
- fwrite ($bf,full_tag("MSN",4,false,$user->msn));
- fwrite ($bf,full_tag("PHONE1",4,false,$user->phone1));
- fwrite ($bf,full_tag("PHONE2",4,false,$user->phone2));
- fwrite ($bf,full_tag("INSTITUTION",4,false,$user->institution));
- fwrite ($bf,full_tag("DEPARTMENT",4,false,$user->department));
- fwrite ($bf,full_tag("ADDRESS",4,false,$user->address));
- fwrite ($bf,full_tag("CITY",4,false,$user->city));
- fwrite ($bf,full_tag("COUNTRY",4,false,$user->country));
- fwrite ($bf,full_tag("LANG",4,false,$user->lang));
- fwrite ($bf,full_tag("THEME",4,false,$user->theme));
- fwrite ($bf,full_tag("TIMEZONE",4,false,$user->timezone));
- fwrite ($bf,full_tag("FIRSTACCESS",4,false,$user->firstaccess));
- fwrite ($bf,full_tag("LASTACCESS",4,false,$user->lastaccess));
- fwrite ($bf,full_tag("LASTLOGIN",4,false,$user->lastlogin));
- fwrite ($bf,full_tag("CURRENTLOGIN",4,false,$user->currentlogin));
- fwrite ($bf,full_tag("LASTIP",4,false,$user->lastip));
- fwrite ($bf,full_tag("PICTURE",4,false,$user->picture));
- fwrite ($bf,full_tag("URL",4,false,$user->url));
- fwrite ($bf,full_tag("DESCRIPTION",4,false,$user->description));
- fwrite ($bf,full_tag("MAILFORMAT",4,false,$user->mailformat));
- fwrite ($bf,full_tag("MAILDIGEST",4,false,$user->maildigest));
- fwrite ($bf,full_tag("MAILDISPLAY",4,false,$user->maildisplay));
- fwrite ($bf,full_tag("HTMLEDITOR",4,false,$user->htmleditor));
- fwrite ($bf,full_tag("AJAX",4,false,$user->ajax));
- fwrite ($bf,full_tag("AUTOSUBSCRIBE",4,false,$user->autosubscribe));
- fwrite ($bf,full_tag("TRACKFORUMS",4,false,$user->trackforums));
- if ($user->mnethostid != $CFG->mnet_localhost_id && !empty($user->wwwroot)) {
- fwrite ($bf,full_tag("MNETHOSTURL",4,false,$user->wwwroot));
- }
- fwrite ($bf,full_tag("TIMECREATED",4,false,$user->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$user->timemodified));
-
- /// write assign/override code for context_userid
-
- $user->isneeded = strpos($user->info,"needed");
-
- fwrite ($bf,start_tag("ROLES",4,true));
- if ($user->info != "needed" && $user->info!="") {
- //PRINT ROLE INFO
- $roles = explode(",", $user->info);
- foreach ($roles as $role) {
- if ($role!="" && $role!="needed") {
- fwrite ($bf,start_tag("ROLE",5,true));
- //Print Role info
- fwrite ($bf,full_tag("TYPE",6,false,$role));
- //Print ROLE end
- fwrite ($bf,end_tag("ROLE",5,true));
- }
- }
- }
- //Needed
- if ($user->isneeded!==false) {
- //Print ROLE start
- fwrite ($bf,start_tag("ROLE",5,true));
- //Print Role info
- fwrite ($bf,full_tag("TYPE",6,false,"needed"));
- //Print ROLE end
- fwrite ($bf,end_tag("ROLE",5,true));
- }
-
- //End ROLES tag
- fwrite ($bf,end_tag("ROLES",4,true));
-
- //Check if we have custom profile fields to backup
- if ($cpfields = $DB->get_records_sql("SELECT uif.shortname, uif.datatype, uidata.data
- FROM {user_info_field} uif,
- {user_info_data} uidata
- WHERE uif.id = uidata.fieldid
- AND uidata.userid = ?", array($user->id))) {
- //Start USER_CUSTOM_PROFILE_FIELDS tag
- fwrite ($bf,start_tag("USER_CUSTOM_PROFILE_FIELDS",4,true));
- //Write custom profile fields
- foreach ($cpfields as $cpfield) {
- fwrite ($bf,start_tag("USER_CUSTOM_PROFILE_FIELD",5,true));
- fwrite ($bf,full_tag("FIELD_NAME",6,false,$cpfield->shortname));
- fwrite ($bf,full_tag("FIELD_TYPE",6,false,$cpfield->datatype));
- fwrite ($bf,full_tag("FIELD_DATA",6,false,$cpfield->data));
- fwrite ($bf,end_tag("USER_CUSTOM_PROFILE_FIELD",5,true));
- }
- //End USER_CUSTOM_PROFILE_FIELDS tag
- fwrite ($bf,end_tag("USER_CUSTOM_PROFILE_FIELDS",4,true));
- }
-
- //Check if we have user tags to backup
- if (!empty($CFG->usetags)) {
- if ($tags = tag_get_tags('user', $user->id)) { //This return them ordered by default
- //Start USER_TAGS tag
- fwrite ($bf,start_tag("USER_TAGS",4,true));
- //Write user tags fields
- foreach ($tags as $tag) {
- fwrite ($bf,start_tag("USER_TAG",5,true));
- fwrite ($bf,full_tag("NAME",6,false,$tag->name));
- fwrite ($bf,full_tag("RAWNAME",6,false,$tag->rawname));
- fwrite ($bf,end_tag("USER_TAG",5,true));
- }
- //End USER_TAGS tag
- fwrite ($bf,end_tag("USER_TAGS",4,true));
- }
- }
-
- //Check if we have user_preferences to backup
- if ($preferences_data = $DB->get_records("user_preferences", array("userid"=>$user->old_id))) {
- //Start USER_PREFERENCES tag
- fwrite ($bf,start_tag("USER_PREFERENCES",4,true));
- //Write each user_preference
- foreach ($preferences_data as $user_preference) {
- fwrite ($bf,start_tag("USER_PREFERENCE",5,true));
- fwrite ($bf,full_tag("NAME",6,false,$user_preference->name));
- fwrite ($bf,full_tag("VALUE",6,false,$user_preference->value));
- fwrite ($bf,end_tag("USER_PREFERENCE",5,true));
- }
- //End USER_PREFERENCES tag
- fwrite ($bf,end_tag("USER_PREFERENCES",4,true));
- }
-
- // Write role assigns, overrides, etc.
- $context = get_context_instance(CONTEXT_USER, $user->old_id);
- write_per_context_data($bf, $preferences, $context, 4);
-
- //End User tag
- fwrite ($bf,end_tag("USER",3,true));
- //Do some output
- $counter++;
- if ($counter % 10 == 0) {
- echo ".";
- if ($counter % 200 == 0) {
- echo "
";
- }
- backup_flush(300);
- }
- }
- //End Users tag
- fwrite ($bf,end_tag("USERS",2,true));
- } else {
- // There aren't any users.
- $status = true;
- }
-
- if ($users) {
- $users->close();
- }
-
- return $status;
- }
-
//Backup log info (time ordered)
function backup_log_info($bf,$preferences) {
global $CFG, $DB;
@@ -1541,302 +297,6 @@
return $status;
}
- //Backup gradebook info
- function backup_gradebook_info($bf, $preferences) {
- global $CFG, $DB;
- require_once($CFG->libdir.'/gradelib.php');
-
- //first make sure items are properly sorted and everything is ok
- grade_category::fetch_course_tree($preferences->backup_course, true);
- grade_regrade_final_grades($preferences->backup_course);
-
- $status = true;
-
- // see if ALL grade items of type mod of this course are being backed up
- // if not, we do not need to backup grade category and associated grade items/grades
- $backupall = true;
-
- if ($grade_items = $DB->get_records_sql("SELECT *
- FROM {grade_items}
- WHERE courseid = ?
- AND itemtype = 'mod'", array($preferences->backup_course))) {
- foreach ($grade_items as $grade_item) {
- // get module information
- // if some activities not selected, we do not backup categories at all
- if (!backup_mod_selected($preferences,$grade_item->itemmodule,$grade_item->iteminstance)) {
- $backupall = false;
- break;
- }
- }
- unset($grade_items); //free memory
- }
-
- //Gradebook header
- fwrite ($bf,start_tag("GRADEBOOK",2,true));
-
- $status = backup_gradebook_outcomes_info($bf, $preferences);
- $status = backup_gradebook_grade_letters_info($bf,$preferences);
-
- // Now backup grade_item (inside grade_category)
- if ($backupall) {
- $status = backup_gradebook_category_info($bf,$preferences);
- }
-
- $status = backup_gradebook_item_info($bf,$preferences, $backupall);
-
- // backup gradebook histories (only if grade history is enabled and selected)
- if (empty($CFG->disablegradehistory) && $preferences->backup_gradebook_history) {
- $status = backup_gradebook_outcomes_history($bf, $preferences);
- $status = backup_gradebook_categories_history_info($bf, $preferences);
- $status = backup_gradebook_items_history_info($bf, $preferences);
- $status = backup_gradebook_grades_history_info($bf, $preferences);
- }
-
- //Gradebook footer
- $status = fwrite ($bf,end_tag("GRADEBOOK",2,true));
- return $status;
- }
-
- function backup_gradebook_category_info($bf, $preferences) {
- global $CFG, $DB;
- $status = true;
-
- // get grade categories in proper order - specified in category grade items
- $course_item = grade_item::fetch_course_item($preferences->backup_course);
- $grade_categories = $DB->get_records_sql("SELECT gc.*, gi.sortorder
- FROM {grade_categories} gc
- JOIN {grade_items} gi ON (gi.iteminstance = gc.id)
- WHERE gc.courseid = ?
- AND (gi.itemtype='course' OR gi.itemtype='category')
- ORDER BY gi.sortorder ASC", array($preferences->backup_course));
-
- if ($grade_categories) {
- //Begin grade_categories tag
- fwrite ($bf,start_tag("GRADE_CATEGORIES",3,true));
- //Iterate for each category
- foreach ($grade_categories as $grade_category) {
- //Begin grade_category
- fwrite ($bf,start_tag("GRADE_CATEGORY",4,true));
- //Output individual fields
- fwrite ($bf,full_tag("ID",5,false,$grade_category->id));
-
- // not keeping path and depth because they can be derived
- fwrite ($bf,full_tag("PARENT",5,false,$grade_category->parent));
- fwrite ($bf,full_tag("FULLNAME",5,false,$grade_category->fullname));
- fwrite ($bf,full_tag("AGGREGATION",5,false,$grade_category->aggregation));
- fwrite ($bf,full_tag("KEEPHIGH",5,false,$grade_category->keephigh));
- fwrite ($bf,full_tag("DROPLOW",5,false,$grade_category->droplow));
- fwrite ($bf,full_tag("AGGREGATEONLYGRADED",5,false,$grade_category->aggregateonlygraded));
- fwrite ($bf,full_tag("AGGREGATEOUTCOMES",5,false,$grade_category->aggregateoutcomes));
- fwrite ($bf,full_tag("AGGREGATESUBCATS",5,false,$grade_category->aggregatesubcats));
- fwrite ($bf,full_tag("TIMECREATED",5,false,$grade_category->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$grade_category->timemodified));
-
- //End grade_category
- fwrite ($bf,end_tag("GRADE_CATEGORY",4,true));
- }
- //End grade_categories tag
- $status = fwrite ($bf,end_tag("GRADE_CATEGORIES",3,true));
- }
-
- return $status;
- }
-
- //Backup gradebook_item (called from backup_gradebook_info
- function backup_gradebook_item_info($bf, $preferences, $backupall) {
- global $CFG, $DB;
-
- $status = true;
- // get all the grade_items, ordered by sort order since upon restoring, it is not always
- // possible to use the same sort order. We could at least preserve the sortorder by restoring
- // grade_items in the original sortorder
- if ($grade_items = $DB->get_records_sql("SELECT *
- FROM {grade_items}
- WHERE courseid = ?
- ORDER BY sortorder ASC", array($preferences->backup_course))) {
-
- //Begin grade_items tag
- fwrite ($bf,start_tag("GRADE_ITEMS",3,true));
- //Iterate over each item
- foreach ($grade_items as $item) {
- // Instantiate a grade_item object, to access its methods
- $grade_item = new grade_item($item, false);
-
- // do not restore if this grade_item is a mod, and
- if ($grade_item->itemtype == 'mod') {
- //MDL-12463 - exclude grade_items of instances not chosen for backup
- if (empty($preferences->mods[$grade_item->itemmodule]->instances[$grade_item->iteminstance]->backup)) {
- continue;
- }
-
- } else if ($grade_item->itemtype == 'category') {
- // if not all grade items are being backed up
- // we ignore this type of grade_item and grades associated
- if (!$backupall) {
- continue;
- }
- }
-
- //Begin grade_item
- fwrite ($bf,start_tag("GRADE_ITEM",4,true));
- //Output individual fields
-
- fwrite ($bf,full_tag("ID",5,false,$grade_item->id));
- fwrite ($bf,full_tag("CATEGORYID",5,false,$grade_item->categoryid));
- fwrite ($bf,full_tag("ITEMNAME",5,false,$grade_item->itemname));
- fwrite ($bf,full_tag("ITEMTYPE",5,false,$grade_item->itemtype));
- fwrite ($bf,full_tag("ITEMMODULE",5,false,$grade_item->itemmodule));
- fwrite ($bf,full_tag("ITEMINSTANCE",5,false,$grade_item->iteminstance));
- fwrite ($bf,full_tag("ITEMNUMBER",5,false,$grade_item->itemnumber));
- fwrite ($bf,full_tag("ITEMINFO",5,false,$grade_item->iteminfo));
- fwrite ($bf,full_tag("IDNUMBER",5,false,$grade_item->idnumber));
- // use [idnumber] in calculation instead of [#giXXX#]
- fwrite ($bf,full_tag("CALCULATION",5,false,$grade_item->get_calculation()));
- fwrite ($bf,full_tag("GRADETYPE",5,false,$grade_item->gradetype));
- fwrite ($bf,full_tag("GRADEMAX",5,false,$grade_item->grademax));
- fwrite ($bf,full_tag("GRADEMIN",5,false,$grade_item->grademin));
- fwrite ($bf,full_tag("SCALEID",5,false,$grade_item->scaleid));
- fwrite ($bf,full_tag("OUTCOMEID",5,false,$grade_item->outcomeid));
- fwrite ($bf,full_tag("GRADEPASS",5,false,$grade_item->gradepass));
- fwrite ($bf,full_tag("MULTFACTOR",5,false,$grade_item->multfactor));
- fwrite ($bf,full_tag("PLUSFACTOR",5,false,$grade_item->plusfactor));
- fwrite ($bf,full_tag("AGGREGATIONCOEF",5,false,$grade_item->aggregationcoef));
- fwrite ($bf,full_tag("DISPLAY",5,false,$grade_item->display));
- fwrite ($bf,full_tag("DECIMALS",5,false,$grade_item->decimals));
- fwrite ($bf,full_tag("HIDDEN",5,false,$grade_item->hidden));
- fwrite ($bf,full_tag("LOCKED",5,false,$grade_item->locked));
- fwrite ($bf,full_tag("LOCKTIME",5,false,$grade_item->locktime));
- fwrite ($bf,full_tag("NEEDSUPDATE",5,false,$grade_item->needsupdate));
- fwrite ($bf,full_tag("TIMECREATED",5,false,$grade_item->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$grade_item->timemodified));
-
- // back up the other stuff here
- // mod grades should only be backed up if selected
- if ($grade_item->itemtype == 'mod' && !backup_userdata_selected($preferences,$grade_item->itemmodule,$grade_item->iteminstance)) {
- // do not write grades if a mod grade_item is being restored
- // but userdata is not selected
- } else {
- $status = backup_gradebook_grades_info($bf,$preferences,$grade_item->id);
- }
- //End grade_item
- fwrite ($bf,end_tag("GRADE_ITEM",4,true));
- }
- //End grade_items tag
- $status = fwrite ($bf,end_tag("GRADE_ITEMS",3,true));
- }
-
- return $status;
- }
- //Backup gradebook_item (called from backup_gradebook_info
-
- function backup_gradebook_grade_letters_info($bf, $preferences) {
- global $CFG, $DB;
- $status = true;
-
- $context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
- $grade_letters = $DB->get_records_sql("SELECT *
- FROM {grade_letters}
- WHERE contextid = ?", array($context->id));
- if ($grade_letters) {
- //Begin grade_l tag
- fwrite ($bf,start_tag("GRADE_LETTERS",3,true));
- //Iterate for each letter
- foreach ($grade_letters as $grade_letter) {
- //Begin grade_letter
- fwrite ($bf,start_tag("GRADE_LETTER",4,true));
- //Output individual fields
- fwrite ($bf,full_tag("ID",5,false,$grade_letter->id));
- fwrite ($bf,full_tag("LOWERBOUNDARY",5,false,$grade_letter->lowerboundary));
- fwrite ($bf,full_tag("LETTER",5,false,$grade_letter->letter));
-
- //End grade_letter
- fwrite ($bf,end_tag("GRADE_LETTER",4,true));
- }
- //End grade_categories tag
- $status = fwrite ($bf,end_tag("GRADE_LETTERS",3,true));
- }
-
- return $status;
- }
-
- function backup_gradebook_outcomes_info($bf, $preferences) {
- global $CFG, $DB;
-
- $status = true;
- // only back up courses already in the grade_outcomes_courses table
- $grade_outcomes = $DB->get_records_sql("SELECT go.*
- FROM {grade_outcomes} go
- JOIN {grade_outcomes_courses} goc ON (goc.outcomeid = go.id)
- WHERE goc.courseid = ?", array($preferences->backup_course));
-
- if (!empty($grade_outcomes)) {
- //Begin grade_outcomes tag
- fwrite ($bf,start_tag("GRADE_OUTCOMES",3,true));
- //Iterate for each outcome
- foreach ($grade_outcomes as $grade_outcome) {
- //Begin grade_outcome
- fwrite ($bf,start_tag("GRADE_OUTCOME",4,true));
- //Output individual fields
-
- fwrite ($bf,full_tag("ID",5,false,$grade_outcome->id));
- fwrite ($bf,full_tag("COURSEID",5,false,$grade_outcome->courseid));
- fwrite ($bf,full_tag("SHORTNAME",5,false,$grade_outcome->shortname));
- fwrite ($bf,full_tag("FULLNAME",5,false,$grade_outcome->fullname));
- fwrite ($bf,full_tag("SCALEID",5,false,$grade_outcome->scaleid));
- fwrite ($bf,full_tag("DESCRIPTION",5,false,$grade_outcome->description));
- fwrite ($bf,full_tag("TIMECREATED",5,false,$grade_outcome->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$grade_outcome->timemodified));
- fwrite ($bf,full_tag("USERMODIFIED",5,false,$grade_outcome->usermodified));
-
- //End grade_outcome
- fwrite ($bf,end_tag("GRADE_OUTCOME",4,true));
- }
- //End grade_outcomes tag
- $status = fwrite ($bf,end_tag("GRADE_OUTCOMES",3,true));
- }
- return $status;
- }
-
- function backup_gradebook_grades_info($bf,$preferences, $itemid) {
- global $CFG, $DB;
-
- $status = true;
-
- // find all grades belonging to this item
- if ($grades = $DB->get_records('grade_grades', array('itemid'=>$itemid))) {
- fwrite ($bf,start_tag("GRADE_GRADES",5,true));
- foreach ($grades as $grade) {
- /// Grades are only sent to backup if the user is one target user
- if (backup_getid($preferences->backup_unique_code, 'user', $grade->userid)) {
- fwrite ($bf,start_tag("GRADE",6,true));
- fwrite ($bf,full_tag("ID",7,false,$grade->id));
- fwrite ($bf,full_tag("USERID",7,false,$grade->userid));
- fwrite ($bf,full_tag("RAWGRADE",7,false,$grade->rawgrade));
- fwrite ($bf,full_tag("RAWGRADEMAX",7,false,$grade->rawgrademax));
- fwrite ($bf,full_tag("RAWGRADEMIN",7,false,$grade->rawgrademin));
- fwrite ($bf,full_tag("RAWSCALEID",7,false,$grade->rawscaleid));
- fwrite ($bf,full_tag("USERMODIFIED",7,false,$grade->usermodified));
- fwrite ($bf,full_tag("FINALGRADE",7,false,$grade->finalgrade));
- fwrite ($bf,full_tag("HIDDEN",7,false,$grade->hidden));
- fwrite ($bf,full_tag("LOCKED",7,false,$grade->locked));
- fwrite ($bf,full_tag("LOCKTIME",7,false,$grade->locktime));
- fwrite ($bf,full_tag("EXPORTED",7,false,$grade->exported));
- fwrite ($bf,full_tag("OVERRIDDEN",7,false,$grade->overridden));
- fwrite ($bf,full_tag("EXCLUDED",7,false,$grade->excluded));
- fwrite ($bf,full_tag("FEEDBACK",7,false,$grade->feedback));
- fwrite ($bf,full_tag("FEEDBACKFORMAT",7,false,$grade->feedbackformat));
- fwrite ($bf,full_tag("INFORMATION",7,false,$grade->information));
- fwrite ($bf,full_tag("INFORMATIONFORMAT",7,false,$grade->informationformat));
- fwrite ($bf,full_tag("TIMECREATED",7,false,$grade->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",7,false,$grade->timemodified));
- fwrite ($bf,end_tag("GRADE",6,true));
- }
- }
- $status = fwrite ($bf,end_tag("GRADE_GRADES",5,true));
- }
- return $status;
- }
-
function backup_gradebook_categories_history_info($bf, $preferences) {
global $CFG, $DB;
@@ -1990,55 +450,6 @@
return $status;
}
- //Backup scales info (common and course scales)
- function backup_scales_info($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- //Counter, points to current record
- $counter = 0;
-
- //Get scales (common and course scales)
- $scales = $DB->get_records_sql("SELECT id, courseid, userid, name, scale, description, timemodified
- FROM {scale}
- WHERE courseid = 0 OR courseid = ?", array($preferences->backup_course));
-
- //Copy only used scales to $backupscales. They will be in backup (unused no). See Bug 1223.
- $backupscales = array();
- if ($scales) {
- foreach ($scales as $scale) {
- if (course_scale_used($preferences->backup_course, $scale->id)) {
- $backupscales[] = $scale;
- }
- }
- }
-
- //Pring scales header
- if ($backupscales) {
- //Pring scales header
- fwrite ($bf,start_tag("SCALES",2,true));
- //Iterate
- foreach ($backupscales as $scale) {
- //Begin scale tag
- fwrite ($bf,start_tag("SCALE",3,true));
- //Output scale tag
- fwrite ($bf,full_tag("ID",4,false,$scale->id));
- fwrite ($bf,full_tag("COURSEID",4,false,$scale->courseid));
- fwrite ($bf,full_tag("USERID",4,false,$scale->userid));
- fwrite ($bf,full_tag("NAME",4,false,$scale->name));
- fwrite ($bf,full_tag("SCALETEXT",4,false,$scale->scale));
- fwrite ($bf,full_tag("DESCRIPTION",4,false,$scale->description));
- fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scale->timemodified));
- //End scale tag
- fwrite ($bf,end_tag("SCALE",3,true));
- }
- //End scales tag
- $status = fwrite ($bf,end_tag("SCALES",2,true));
- }
- return $status;
- }
-
//Backup events info (course events)
function backup_events_info($bf,$preferences) {
global $CFG, $DB;
@@ -2081,1484 +492,3 @@
}
return $status;
}
-
- //Backup groups info
- function backup_groups_info($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
- $status2 = true;
-
- //Get groups
- $groups = $DB->get_records("groups", array("courseid"=>$preferences->backup_course));
-
- //Pring groups header
- if ($groups) {
- //Pring groups header
- fwrite ($bf,start_tag("GROUPS",2,true));
- //Iterate
- foreach ($groups as $group) {
- //Begin group tag
- fwrite ($bf,start_tag("GROUP",3,true));
- //Output group contents
- fwrite ($bf,full_tag("ID",4,false,$group->id));
- //fwrite ($bf,full_tag("COURSEID",4,false,$group->courseid));
- fwrite ($bf,full_tag("NAME",4,false,$group->name));
- fwrite ($bf,full_tag("DESCRIPTION",4,false,$group->description));
- fwrite ($bf,full_tag("ENROLMENTKEY",4,false,$group->enrolmentkey));
- fwrite ($bf,full_tag("PICTURE",4,false,$group->picture));
- fwrite ($bf,full_tag("HIDEPICTURE",4,false,$group->hidepicture));
- fwrite ($bf,full_tag("TIMECREATED",4,false,$group->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$group->timemodified));
-
- //Now, backup groups_members, only if users are included
- if ($preferences->backup_users != 2) {
- $status2 = backup_groups_members_info($bf,$preferences,$group->id);
- }
-
- //End group tag
- fwrite ($bf,end_tag("GROUP",3,true));
- }
- //End groups tag
- $status = fwrite ($bf,end_tag("GROUPS",2,true));
-
- //Now save group_files
- if ($status && $status2) {
- $status2 = backup_copy_group_files($preferences);
- }
- }
- return ($status && $status2);
- }
-
- //Backup groups_members info
- function backup_groups_members_info($bf,$preferences,$groupid) {
- global $CFG, $DB;
-
- $status = true;
-
- //Get groups_members that are being included in backup
- $groups_members = $DB->get_records_sql("SELECT gm.*
- FROM {groups_members} gm, {backup_ids} bi
- WHERE gm.groupid = ?
- AND bi.backup_code = ?
- AND bi.table_name = 'user'
- AND bi.old_id = gm.userid", array($groupid, $preferences->backup_unique_code));
-
- //Pring groups_members header
- if ($groups_members) {
- //Pring groups_members header
- fwrite ($bf,start_tag("MEMBERS",4,true));
- //Iterate
- foreach ($groups_members as $group_member) {
- //Begin group_member tag
- fwrite ($bf,start_tag("MEMBER",5,true));
- //Output group_member contents
- fwrite ($bf,full_tag("GROUPID",6,false,$group_member->groupid));
- fwrite ($bf,full_tag("USERID",6,false,$group_member->userid));
- fwrite ($bf,full_tag("TIMEADDED",6,false,$group_member->timeadded));
- //End group_member tag
- fwrite ($bf,end_tag("MEMBER",5,true));
- }
- //End groups_members tag
- $status = fwrite ($bf,end_tag("MEMBERS",4,true));
- }
- return $status;
- }
-
- //Backup groupings info
- function backup_groupings_info($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- //Get groups
- $groupings = $DB->get_records("groupings", array("courseid"=>$preferences->backup_course));
-
- //Pring groups header
- if ($groupings) {
- //Pring groups header
- fwrite ($bf,start_tag("GROUPINGS",2,true));
- //Iterate
- foreach ($groupings as $grouping) {
- //Begin group tag
- fwrite ($bf,start_tag("GROUPING",3,true));
- //Output group contents
- fwrite ($bf,full_tag("ID",4,false,$grouping->id));
- //fwrite ($bf,full_tag("COURSEID",4,false,$grouping->courseid));
- fwrite ($bf,full_tag("NAME",4,false,$grouping->name));
- fwrite ($bf,full_tag("DESCRIPTION",4,false,$grouping->description));
- fwrite ($bf,full_tag("CONFIGDATA",4,false,$grouping->configdata));
- fwrite ($bf,full_tag("TIMECREATED",4,false,$grouping->timecreated));
- fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$grouping->timemodified));
-
- //End group tag
- fwrite ($bf,end_tag("GROUPING",3,true));
- }
- //End groups tag
- $status = fwrite ($bf,end_tag("GROUPINGS",2,true));
-
- //(Now save grouping_files)
- }
- return $status;
- }
-
- //Backup groupings-groups info
- function backup_groupings_groups_info($bf,$preferences) {
- global $CFG, $DB;
-
- $status = true;
-
- //Get grouping_groups
- $courseid = $preferences->backup_course;
- $sql = "SELECT gg.* FROM {groupings} g, {groupings_groups} gg
- WHERE g.courseid=? AND g.id=gg.groupingid";
- $grouping_groups = $DB->get_records_sql($sql, array($courseid));
-
- //Pring grouping_groups header
- if ($grouping_groups) {
- //Pring grouping_groups header
- fwrite ($bf,start_tag("GROUPINGSGROUPS",2,true));
- //Iterate
- foreach ($grouping_groups as $members) {
- //Begin grouping_group tag
- fwrite ($bf,start_tag("GROUPINGGROUP",3,true));
- //Output group_member contents
- fwrite ($bf,full_tag("ID",4,false,$members->id));
- fwrite ($bf,full_tag("GROUPINGID",4,false,$members->groupingid));
- fwrite ($bf,full_tag("GROUPID",4,false,$members->groupid));
- fwrite ($bf,full_tag("TIMEADDED",4,false,$members->timeadded));
- //End grouping_group tag
- fwrite ($bf,end_tag("GROUPINGGROUP",3,true));
- }
- //End grouping_groups tag
- $status = fwrite ($bf,end_tag("GROUPINGSGROUPS",2,true));
- }
- return $status;
- }
-
- //Start the modules tag
- function backup_modules_start ($bf,$preferences) {
-
- return fwrite ($bf,start_tag("MODULES",2,true));
- }
-
- //End the modules tag
- function backup_modules_end ($bf,$preferences) {
-
- return fwrite ($bf,end_tag("MODULES",2,true));
- }
-
- //This function makes all the necesary calls to every mod
- //to export itself and its files !!!
- function backup_module($bf,$preferences,$module) {
- global $CFG, $DB, $OUTPUT;
-
- $status = true;
- $statusm = true;
-
- require_once($CFG->dirroot.'/mod/'.$module.'/backuplib.php');
-
- if (isset($preferences->mods[$module]->instances)
- && is_array($preferences->mods[$module]->instances)) {
- $onemodbackup = $module.'_backup_one_mod';
- if (function_exists($onemodbackup)) {
- foreach ($preferences->mods[$module]->instances as $instance => $object) {
- if (!empty($object->backup)) {
- $statusm = $onemodbackup($bf,$preferences,$instance);
- if (!$statusm) {
- $errorstr = 'backup of '.$module.'-'.$object->name.' failed.';
- add_to_backup_log(time(),$preferences->backup_course,$errorstr,'manual');
- if (!defined('BACKUP_SILENTLY')) {
- echo $OUTPUT->notification($errorstr);
- }
- $status = false;
- }
- }
- }
- } else {
- $status = false;
- }
- } else { // whole module.
- //First, re-check if necessary functions exists
- $modbackup = $module."_backup_mods";
- if (function_exists($modbackup)) {
- //Call the function
- $status = $modbackup($bf,$preferences);
- } else {
- //Something was wrong. Function should exist.
- $status = false;
- }
- }
-
- return $status;
-
- }
-
- //This function encode things to make backup multi-site fully functional
- //It does this conversions:
- // - $CFG->wwwroot/file.php/courseid ------------------> $@FILEPHP@$ (slasharguments links)
- // - $CFG->wwwroot/file.php?file=/courseid ------------> $@FILEPHP@$ (non-slasharguments links)
- // - Every module/block/course_format xxxx_encode_content_links() is executed too
- //
- function backup_encode_absolute_links($content) {
- global $CFG,$preferences, $DB;
-
- /// MDL-14072: Prevent NULLs, empties and numbers to be processed by the
- /// heavy interlinking. Just a few cpu cycles saved.
- if ($content === NULL) {
- return NULL;
- } else if ($content === '') {
- return '';
- } else if (is_numeric($content)) {
- return $content;
- }
-
- //Use one static variable to cache all the require_once calls that,
- //under PHP5 seems to increase load too much, and we are requiring
- //them here thousands of times (one per content). MDL-8700.
- //Once fixed by PHP, we'll delete this hack
-
- static $includedfiles;
- if (!isset($includedfiles)) {
- $includedfiles = array();
- }
-
- //Check if we support unicode modifiers in regular expressions. Cache it.
- static $unicoderegexp;
- if (!isset($unicoderegexp)) {
- $unicoderegexp = @preg_match('/\pL/u', 'a'); // This will fail silenty, returning false,
- } // if regexp libraries don't support unicode
-
- //Check if preferences is ok. If it isn't set, we are
- //in a scheduled_backup to we are able to get a copy
- //from CFG->backup_preferences
- if (!isset($preferences)) {
- $mypreferences = $CFG->backup_preferences;
- } else {
- //We are in manual backups so global preferences must exist!!
- $mypreferences = $preferences;
- }
- //First, we check for every call to file.php inside the course
- $search = array($CFG->wwwroot.'/file.php/'.$mypreferences->backup_course,
- $CFG->wwwroot.'/file.php?file=/'.$mypreferences->backup_course,
- $CFG->wwwroot.'/file.php?file=%2f'.$mypreferences->backup_course,
- $CFG->wwwroot.'/file.php?file=%2F'.$mypreferences->backup_course);
-
- $replace = array('$@FILEPHP@$', '$@FILEPHP@$', '$@FILEPHP@$', '$@FILEPHP@$');
-
- $result = str_replace($search,$replace,$content);
-
- // Now we look for any '$@FILEPHP@$' URLs, replacing:
- // - slashes and %2F by $@SLASH@$
- // - &forcedownload=1 &forcedownload=1 and ?forcedownload=1 by $@FORCEDOWNLOAD@$
- // This way, backup contents will be neutral and independent of slasharguments configuration. MDL-18799
- // Based in $unicoderegexp, decide the regular expression to use
- if ($unicoderegexp) { //We can use unicode modifiers
- $search = '/(\$@FILEPHP@\$)((?:(?:\/|%2f|%2F))(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*)?(\?(?:(?:(?:\([-;:@#&=\pL0-9\$~_.+!*\',]*?\))|[-;:@#&=?\pL0-9\$~_.+!*\',]|%[a-fA-F0-9]{2}|\/)*))?(?mods as $name => $info) {
- /// We only include the corresponding backuplib.php if it hasn't been included before
- /// This will save some load under PHP5. MDL-8700.
- /// Once fixed by PHP, we'll delete this hack
- if (!in_array($name, $includedfiles)) {
- include_once("$CFG->dirroot/mod/$name/backuplib.php");
- $includedfiles[] = $name;
- }
- //Check if the xxxx_encode_content_links exists
- $function_name = $name."_encode_content_links";
- if (function_exists($function_name)) {
- $result = $function_name($result,$mypreferences);
- }
- }
-
- // For the current course format call its encode_content_links method (if it exists)
- static $format_function_name;
- if (!isset($format_function_name)) {
- $format_function_name = false;
- if ($format = $DB->get_field('course','format', array('id'=>$mypreferences->backup_course))) {
- if (file_exists("$CFG->dirroot/course/format/$format/backuplib.php")) {
- include_once("$CFG->dirroot/course/format/$format/backuplib.php");
- $function_name = $format.'_encode_format_content_links';
- if (function_exists($function_name)) {
- $format_function_name = $function_name;
- }
- }
- }
- }
- // If the above worked - then we have a function to call
- if ($format_function_name) {
- $result = $format_function_name($result, $mypreferences);
- }
-
- // For each block, call its encode_content_links method.
- // This encodes forexample links to blocks/something/viewphp?id=666
- // that are stored in other activities.
- static $blockobjects = null;
- if (!isset($blockobjects)) {
- $blockobjects = array();
- if ($blocks = $DB->get_records('block', array('visible'=>1))) {
- foreach ($blocks as $block) {
- if ($blockobject = block_instance($block->name)) {
- $blockobjects[] = $blockobject;
- }
- }
- }
- }
-
- foreach ($blockobjects as $blockobject) {
- $result = $blockobject->encode_content_links($result,$mypreferences);
- }
-
- if ($result != $content) {
- debugging('
";
-
- //Start the mail ul
- echo "
|
Can't find new ID for grade item $data->gradeitemid, ignoring availability condition.
"; - } - continue; - } - } - $rs->close(); - - if (!defined('RESTORE_SILENTLY')) { - echo '