id)) { if (!isteacheredit($course->id)) { if (empty($to)) { error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); } else { if (!isteacheredit($to)) { error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php"); } } } } else { if (!isadmin()) { error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php"); } } //Check site if (!$site = get_site()) { error("Site not found!"); } //Checks for the required files/functions to backup every mod //And check if there is data about it $count = 0; if ($allmods = get_records("modules") ) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "$CFG->dirroot/mod/$modname/backuplib.php"; $modbackup = $modname."_backup_mods"; $modcheckbackup = $modname."_check_backup_mods"; if (file_exists($modfile)) { include_once($modfile); if (function_exists($modbackup) and function_exists($modcheckbackup)) { $var = "exists_".$modname; $$var = true; $count++; } } //Check data //Check module info $var = "backup_".$modname; $$var = optional_param( $var,0,PARAM_INT ); //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->backup = $$var; //Check include user info $var = "backup_user_info_".$modname; $$var = optional_param( $var,0,PARAM_INT ); //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->userinfo = $$var; //And the name of the mod $preferences->mods[$modname]->name = $modname; } } //Check other parameters $backup_metacourse = optional_param( 'backup_metacourse',1,PARAM_INT ); $preferences->backup_metacourse = $backup_metacourse; $backup_users = optional_param( 'backup_users',1,PARAM_INT ); $preferences->backup_users = $backup_users; $backup_logs = optional_param( 'backup_logs',0,PARAM_INT ); $preferences->backup_logs = $backup_logs; $backup_user_files = optional_param( 'backup_user_files',1,PARAM_INT ); $preferences->backup_user_files = $backup_user_files; $backup_course_files = optional_param( 'backup_course_files',2,PARAM_INT ); $preferences->backup_course_files = $backup_course_files; $backup_messages = optional_param( 'backup_messages',1,PARAM_INT ); $preferences->backup_messages = $backup_messages; $id = required_param('id'); $preferences->backup_course = $id; $backup_name = required_param('backup_name',PARAM_FILE ); $preferences->backup_name = $backup_name; $backup_unique_code = required_param('backup_unique_code'); $preferences->backup_unique_code = $backup_unique_code; //Another Info $preferences->moodle_version = $CFG->version; $preferences->moodle_release = $CFG->release; $preferences->backup_version = $CFG->backup_version; $preferences->backup_release = $CFG->backup_release; if ($count == 0) { notice("No backupable modules are installed!"); } if (empty($to)) { //Start the main table echo ""; //Now print the Backup Name tr echo ""; echo ""; //Start the main tr, where all the backup progress is done echo ""; echo ""; //End the main table echo "
"; echo get_string("name").":"; echo ""; echo $preferences->backup_name; echo "
"; //Start the main ul echo "
    "; } //Check for temp and backup and backup_unique_code directory //Create them as needed echo "
  • ".get_string("creatingtemporarystructures").'
  • '; $status = check_and_create_backup_dir($backup_unique_code); //Empty dir if ($status) { $status = clear_backup_dir($backup_unique_code); } //Delete old_entries from backup tables echo "
  • ".get_string("deletingolddata").'
  • '; $status = backup_delete_old_data(); if (!$status) { error ("An error occurred deleting old backup data"); } //Create the moodle.xml file if ($status) { echo "
  • ".get_string("creatingxmlfile"); //Begin a new list to xml contents echo "
      "; echo "
    • ".get_string("writingheader").'
    • '; //Obtain the xml file (create and open) and print prolog information $backup_file = backup_open_xml($backup_unique_code); echo "
    • ".get_string("writinggeneralinfo").'
    • '; //Prints general info about backup to file if ($backup_file) { if (!$status = backup_general_info($backup_file,$preferences)) { notify("An error occurred while backing up general info"); } } echo "
    • ".get_string("writingcoursedata"); //Start new ul (for course) echo "
        "; echo "
      • ".get_string("courseinfo").'
      • '; //Prints course start (tag and general info) if ($status) { if (!$status = backup_course_start($backup_file,$preferences)) { notify("An error occurred while backing up course start"); } } //Metacourse information if ($status && $preferences->backup_metacourse) { echo "
      • ".get_string("metacourse").'
      • '; if (!$status = backup_course_metacourse($backup_file,$preferences)) { notify("An error occurred while backing up metacourse info"); } } echo "
      • ".get_string("blocks").'
      • '; //Blocks information if ($status) { if (!$status = backup_course_blocks($backup_file,$preferences)) { notify("An error occurred while backing up course blocks"); } } echo "
      • ".get_string("sections").'
      • '; //Section info if ($status) { if (!$status = backup_course_sections($backup_file,$preferences)) { notify("An error occurred while backing up course sections"); } } //End course contents (close ul) echo "
    • "; //User info if ($status) { echo "
    • ".get_string("writinguserinfo").'
    • '; if (!$status = backup_user_info($backup_file,$preferences)) { notify("An error occurred while backing up user info"); } } //If we have selected to backup messages and we are //doing a SITE backup, let's do it if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) { echo "
    • ".get_string("writingmessagesinfo").'
    • '; if (!$status = backup_messages($backup_file,$preferences)) { notify("An error occurred while backing up messages"); } } //If we have selected to backup quizzes, backup categories and //questions structure (step 1). See notes on mod/quiz/backuplib.php if ($status and $preferences->mods['quiz']->backup) { echo "
    • ".get_string("writingcategoriesandquestions").'
    • '; if (!$status = quiz_backup_question_categories($backup_file,$preferences)) { notify("An error occurred while backing up quiz categories"); } } //Print logs if selected if ($status) { if ($preferences->backup_logs) { echo "
    • ".get_string("writingloginfo").'
    • '; if (!$status = backup_log_info($backup_file,$preferences)) { notify("An error occurred while backing up log info"); } } } //Print scales info if ($status) { echo "
    • ".get_string("writingscalesinfo").'
    • '; if (!$status = backup_scales_info($backup_file,$preferences)) { notify("An error occurred while backing up scales"); } } //Print groups info if ($status) { echo "
    • ".get_string("writinggroupsinfo").'
    • '; if (!$status = backup_groups_info($backup_file,$preferences)) { notify("An error occurred while backing up groups"); } } //Print events info if ($status) { echo "
    • ".get_string("writingeventsinfo").'
    • '; if (!$status = backup_events_info($backup_file,$preferences)) { notify("An error occurred while backing up events"); } } //Print gradebook info if ($status) { echo "
    • ".get_string("writinggradebookinfo").'
    • '; if (!$status = backup_gradebook_info($backup_file,$preferences)) { notify("An error occurred while backing up gradebook"); } } //Module info, this unique function makes all the work!! //db export and module fileis copy if ($status) { $mods_to_backup = false; //Check if we have any mod to backup foreach ($preferences->mods as $module) { if ($module->backup) { $mods_to_backup = true; } } //If we have to backup some module if ($mods_to_backup) { echo "
    • ".get_string("writingmoduleinfo"); //Start modules tag if (!$status = backup_modules_start ($backup_file,$preferences)) { notify("An error occurred while backing up module info"); } //Open ul for module list echo "
        "; //Iterate over modules and call backup foreach ($preferences->mods as $module) { if ($module->backup and $status) { echo "
      • ".get_string("modulenameplural",$module->name).'
      • '; if (!$status = backup_module($backup_file,$preferences,$module->name)) { notify("An error occurred while backing up '$module->name'"); } } } //Close ul for module list echo "
    • "; //Close modules tag if (!$status = backup_modules_end ($backup_file,$preferences)) { notify("An error occurred while finishing the module backups"); } } } //Prints course end if ($status) { if (!$status = backup_course_end($backup_file,$preferences)) { notify("An error occurred while closing the course backup"); } } //Close the xml file and xml data if ($backup_file) { backup_close_xml($backup_file); } //End xml contents (close ul) echo "
  • "; } //Now, if selected, copy user files if ($status) { if ($preferences->backup_user_files) { echo "
  • ".get_string("copyinguserfiles").'
  • '; if (!$status = backup_copy_user_files ($preferences)) { notify("An error occurred while copying user files"); } } } //Now, if selected, copy course files if ($status) { if ($preferences->backup_course_files) { echo "
  • ".get_string("copyingcoursefiles").'
  • '; if (!$status = backup_copy_course_files ($preferences)) { notify("An error occurred while copying course files"); } } } //Now, zip all the backup directory contents if ($status) { echo "
  • ".get_string("zippingbackup").'
  • '; if (!$status = backup_zip ($preferences)) { notify("An error occurred while zipping the backup"); } } //Now, copy the zip file to course directory if ($status) { echo "
  • ".get_string("copyingzipfile").'
  • '; if (!$status = copy_zip_to_course_dir ($preferences)) { notify("An error occurred while copying the zip file to the course directory"); } } //Now, clean temporary data (db and filesystem) if ($status) { echo "
  • ".get_string("cleaningtempdata").'
  • '; if (!$status = clean_temp_data ($preferences)) { notify("An error occurred while cleaning up temporary data"); } } //Ends th main ul echo "
"; //End the main tr, where all the backup is done echo "
"; if (!$status) { error ("The backup did not complete successfully", "$CFG->wwwroot/course/view.php?id=$course->id"); } if (empty($to)) { //Print final message print_simple_box(get_string("backupfinished"),"center"); print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata"); } else { print_simple_box(get_string('importdataexported'),"CENTER"); if (!empty($preferences->backup_destination)) { $filename = $preferences->backup_destination."/".$preferences->backup_name; } else { $filename = $preferences->backup_course."/backupdata/".$preferences->backup_name; } error_log($filename); $SESSION->import_preferences = $preferences; print_continue($CFG->wwwroot.'/course/import.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename); } ?>