2 require_once("$CFG->dirroot/question/backuplib.php");
3 //This page prints the backup todo list to see everything
8 if (!empty($course->id
)) {
9 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
11 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
13 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $to))) {
14 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
19 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
20 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
26 $backupprefs = new StdClass
;
28 backup_fetch_prefs_from_request($backupprefs,$count,$course);
33 if (!$site = get_site()) {
34 error("Site not found!");
37 notice("No backupable modules are installed!");
40 if (!execute_sql("DELETE FROM {$CFG->prefix}backup_ids WHERE backup_code = '{$backupprefs->backup_unique_code}'",false)){
41 error('Couldn\'t delete previous backup ids.');
46 <form id=
"form" method=
"post" action=
"backup.php">
47 <table cellpadding=
"5" style=
"text-align:center;margin-left:auto;margin-right:auto">
51 //Now print the Backup Name tr
53 echo "<td align=\"right\"><b>";
54 echo get_string("name").":";
57 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name
."\" />";
61 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
63 //Now print the To Do list
65 echo "<td colspan=\"2\" align=\"center\"><b>";
70 //Here we check if backup_users = None. Then, we switch off every module
71 //user info, user_files, logs and exercises, workshop and messages backups. A Warning is showed to
73 if ($backupprefs->backup_users
== 2) {
74 if ($allmods = get_records("modules") ) {
75 foreach ($allmods as $mod) {
76 $modname = $mod->name
;
77 $var = "backup_user_info_".$modname;
78 if (isset($backupprefs->$var)) {
79 $backupprefs->$var = 0;
81 $var = "backup_".$modname;
82 if (isset($backupprefs->$var)) {
83 if ($modname == "exercise" ||
$modname == "workshop") {
84 $backupprefs->$var = 0;
88 $backupprefs->backup_user_files
= 0;
89 $backupprefs->backup_logs
= 0;
90 $backupprefs->backup_messages
= 0;
92 print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
97 echo get_string("backupdetails").":";
98 echo "</b></td></tr>";
101 //This is the alignment of every row in the table
102 $table->align
= array ("left","right");
104 if ($allmods = get_records("modules") ) {
105 foreach ($allmods as $mod) {
106 $modname = $mod->name
;
107 $modfile = $CFG->dirroot
.'/mod/'.$modname.'/backuplib.php';
108 if (!file_exists($modfile)) {
111 require_once($modfile);
112 $modbackup = $modname."_backup_mods";
113 //If exists the lib & function
114 $var = "exists_".$modname;
115 if (isset($backupprefs->$var) && $backupprefs->$var) {
116 $var = "backup_".$modname;
118 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
121 echo "<td colspan=\"2\">";
123 echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
124 //Now look for user-data status
125 $backup_user_options[0] = get_string("withoutuserdata");
126 $backup_user_options[1] = get_string("withuserdata");
127 $var = "backup_user_info_".$modname;
128 //Print the user info
129 echo $backup_user_options[$backupprefs->$var]."</b>";
130 //Call the check function to show more info
131 $modcheckbackup = $modname."_check_backup_mods";
132 $var = $modname.'_instances';
133 $instancestopass = array();
134 if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
135 $table->data
= array();
137 foreach ($backupprefs->$var as $instance) {
138 $var1 = 'backup_'.$modname.'_instance_'.$instance->id
;
139 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id
;
140 if (!empty($backupprefs->$var1)) {
142 $obj->name
= $instance->name
;
143 $obj->userdata
= $backupprefs->$var2;
144 $obj->id
= $instance->id
;
145 $instancestopass[$instance->id
]= $obj;
151 $table->data
= $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code
,$instancestopass);
161 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
163 //Now print the Users tr
165 echo "<td colspan=\"2\"><b>";
166 $user_options[0] = get_string("includeallusers");
167 $user_options[1] = get_string("includecourseusers");
168 $user_options[2] = get_string("includenoneusers");
169 echo $user_options[$backupprefs->backup_users
].'</b>';
171 $table->data
= user_check_backup($id,$backupprefs->backup_unique_code
,$backupprefs->backup_users
,$backupprefs->backup_messages
);
177 //Now print the Logs tr conditionally
178 if ($backupprefs->backup_logs
&& empty($to)) {
180 echo "<td colspan=\"2\"><b>";
181 echo get_string("includelogentries").'</b>';
183 $table->data
= log_check_backup($id);
188 //Now print the User Files tr conditionally
189 if ($backupprefs->backup_user_files
) {
191 echo "<td colspan=\"2\"><b>";
192 echo get_string("includeuserfiles").'</b>';
194 $table->data
= user_files_check_backup($id,$backupprefs->backup_unique_code
);
199 //Now print the Course Files tr conditionally
200 if ($backupprefs->backup_course_files
) {
202 echo "<td colspan=\"2\"><b>";
203 echo get_string("includecoursefiles").'</b>';
205 $table->data
= course_files_check_backup($id,$backupprefs->backup_unique_code
);
209 //Now print the site Files tr conditionally
210 if ($backupprefs->backup_site_files
) {
212 echo "<td colspan=\"2\"><b>";
213 echo get_string("includesitefiles").'</b>';
215 $table->data
= site_files_check_backup($id,$backupprefs->backup_unique_code
);
221 // now keep it for next time.
222 $SESSION->backupprefs
[$course->id
] = $backupprefs;
226 <div style=
"text-align:center;margin-left:auto;margin-right:auto">
227 <input type=
"hidden" name=
"to" value=
"<?php p($to) ?>" />
228 <input type
="hidden" name
="id" value
="<?php p($id) ?>" />
229 <input type
="hidden" name
="launch" value
="execute" />
230 <input type
="submit" value
="<?php print_string("continue") ?>" />
231 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />