MDL-24203 unused string removed
[moodle.git] / backup / backup_check.html
CommitLineData
795b6945 1<?php
a615cc7b 2 //This page prints the backup todo list to see everything
3
3bee1ead 4 //Check login
c563a9a0 5 require_login();
6
93f66983 7 $loginurl = get_login_url();
8
f2a0da6c
EL
9 // Init backupuserinfo
10 $backupuserinfo = false;
11
bd38123e 12 if (!empty($course->id)) {
d2940003 13 if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
873bf875 14 if (empty($to)) {
93f66983 15 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 16 } else {
d2940003 17 if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
93f66983 18 print_error("cannotuseadminadminorteacher", '', $loginurl);
873bf875 19 }
20 }
bd38123e 21 }
f2a0da6c 22 $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_COURSE, $course->id));
bd38123e 23 } else {
d2940003 24 if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
93f66983 25 print_error("cannotuseadmin", '', $loginurl);
bd38123e 26 }
f2a0da6c 27 $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
c563a9a0 28 }
29
3bee1ead 30
a94baeaf 31
32 $backupprefs = new StdClass;
33 $count = 0;
34 backup_fetch_prefs_from_request($backupprefs,$count,$course);
bd38123e 35
3bee1ead 36
37
c563a9a0 38 //Check site
3f77c158 39 $site = get_site();
a615cc7b 40 if ($count == 0) {
41 notice("No backupable modules are installed!");
42 }
3bee1ead 43
655b09ca 44 if (!$DB->delete_records("backup_ids", array('backup_code'=>$backupprefs->backup_unique_code))){
d3b7ea93 45 print_error('cannotdeletebackupids');
3bee1ead 46 }
47
a615cc7b 48?>
49
b7dc2256 50<form id="form" method="post" action="backup.php">
fbe31d22 51<table cellpadding="5" style="text-align:center;margin-left:auto;margin-right:auto">
145cb8f9 52<?php
7e7089e3 53 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
a615cc7b 54
873bf875 55 if (empty($to)) {
56 //Now print the Backup Name tr
57 echo "<tr>";
f2d57378 58 echo "<td align=\"right\"><b>";
873bf875 59 echo get_string("name").":";
f2d57378 60 echo "</b></td><td>";
873bf875 61 //Add as text field
a94baeaf 62 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name."\" />";
873bf875 63 echo "</td></tr>";
3bee1ead 64
873bf875 65 //Line
f2d57378 66 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
3bee1ead 67
873bf875 68 //Now print the To Do list
3bee1ead 69 echo "<tr>";
f2d57378 70 echo "<td colspan=\"2\" align=\"center\"><b>";
873bf875 71
873bf875 72 }
a615cc7b 73
d2940003
EL
74 // Re-enforce 'moodle/backup:backupcourse' at system context to be able to backup all users
75 if ($backupprefs->backup_users == 0 and !has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
a89fcd7a
EL
76 $backupprefs->backup_users = 1; // users => course
77 }
78
f2a0da6c
EL
79 // Re-enforce moodle/backup:userinfo capability
80 if (!$backupuserinfo) {
81 $backupprefs->backup_users = 2; // users => none
82 }
83
fa96ad2f 84 //Here we check if backup_users = None. Then, we switch off every module
fe75799d 85 //user info, user_files, logs and exercises, workshop and messages & blogs backups. A Warning is showed to
fa96ad2f 86 //inform the user.
81243b7b 87 // TODO: Move this logic to one function to be shared by any (manual, scheduled) backup
a94baeaf 88 if ($backupprefs->backup_users == 2) {
ad4375ac 89 if ($allmods = $DB->get_records('modules') ) {
fa96ad2f 90 foreach ($allmods as $mod) {
81243b7b 91 /// Reset global user_info settings to "no" (0)
fa96ad2f 92 $modname = $mod->name;
81243b7b 93 $var = 'backup_user_info_'.$modname;
a94baeaf 94 if (isset($backupprefs->$var)) {
95 $backupprefs->$var = 0;
fa96ad2f 96 }
81243b7b 97 /// Reset each instance userinfo settings to "no" (0)
98 if (isset($backupprefs->mods[$modname])) {
99 /// Set the module userinfo to no (0)
100 $backupprefs->mods[$modname]->userinfo = 0;
101 /// Set the instances to no (o)
102 foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
103 $backupprefs->mods[$modname]->instances[$key]->userinfo = 0;
104 $var = 'backup_user_info_' . $modname . '_instance_' . $key;
105 $backupprefs->$var = 0;
106 }
107 }
108 /// If modules are workshop or exercise, disable their backup completely
109 if ($modname == 'exercise' || $modname == 'workshop') {
110 $var = 'backup_'.$modname;
111 if (isset($backupprefs->$var)) {
a94baeaf 112 $backupprefs->$var = 0;
81243b7b 113 /// Reset each instance backup settings to "no" (0)
114 if (isset($backupprefs->mods[$modname])) {
115 /// Set the module backup to no (0)
116 $backupprefs->mods[$modname]->backup = 0;
117 $var = 'backup_' . $modname . '_instances';
118 $backupprefs->$var = 0;
119 /// Set the instances backup to no (o)
120 foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
121 $backupprefs->mods[$modname]->instances[$key]->backup = 0;
122 $var = 'backup_' . $modname . '_instance_' . $key;
123 $backupprefs->$var = 0;
124 }
125 }
fa96ad2f 126 }
127 }
128 }
fa96ad2f 129 }
81243b7b 130 $backupprefs->backup_user_files = 0;
131 $backupprefs->backup_logs = 0;
132 $backupprefs->backup_messages = 0;
fe75799d 133 $backupprefs->backup_blogs = 0;
81243b7b 134 $backupprefs->backuproleassignments = array();
135
b72db8b3
EL
136 if ($backupuserinfo) { // Based on perms, decide the msg to show
137 $nousersmsgtoshow = 'backupnoneusersinfo';
138 } else {
139 $nousersmsgtoshow = 'backupmissinguserinfoperms';
140 }
141 echo $OUTPUT->box(get_string($nousersmsgtoshow), "noticebox");
f2d57378 142 echo "<hr />";
fa96ad2f 143 }
144
873bf875 145 if (empty($to)) {
146 echo get_string("backupdetails").":";
f2d57378 147 echo "</b></td></tr>";
873bf875 148 }
a615cc7b 149
3bee1ead 150 //This is the alignment of every row in the table
c4c7d936 151 $table = new html_table();
7ef0797d 152 $table->align = array ("left","right");
a615cc7b 153
ad4375ac 154 if ($allmods = $DB->get_records("modules") ) {
a615cc7b 155 foreach ($allmods as $mod) {
156 $modname = $mod->name;
a94baeaf 157 $modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php';
158 if (!file_exists($modfile)) {
159 continue;
160 }
161 require_once($modfile);
a615cc7b 162 $modbackup = $modname."_backup_mods";
163 //If exists the lib & function
164 $var = "exists_".$modname;
a94baeaf 165 if (isset($backupprefs->$var) && $backupprefs->$var) {
a615cc7b 166 $var = "backup_".$modname;
167 //Only if selected
394832e1 168 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
a615cc7b 169 //Print the full tr
170 echo "<tr>";
f2d57378 171 echo "<td colspan=\"2\">";
a615cc7b 172 //Print the mod name
f2d57378 173 echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
a615cc7b 174 //Now look for user-data status
3bee1ead 175 $backup_user_options[0] = get_string("withoutuserdata");
a615cc7b 176 $backup_user_options[1] = get_string("withuserdata");
177 $var = "backup_user_info_".$modname;
178 //Print the user info
a94baeaf 179 echo $backup_user_options[$backupprefs->$var]."</b>";
a615cc7b 180 //Call the check function to show more info
181 $modcheckbackup = $modname."_check_backup_mods";
1ecea976 182 $var = $modname.'_instances';
183 $instancestopass = array();
a94baeaf 184 if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
1ecea976 185 $table->data = array();
186 $countinstances = 0;
a94baeaf 187 foreach ($backupprefs->$var as $instance) {
1ecea976 188 $var1 = 'backup_'.$modname.'_instance_'.$instance->id;
189 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
a94baeaf 190 if (!empty($backupprefs->$var1)) {
1ecea976 191 $obj = new StdClass;
192 $obj->name = $instance->name;
a94baeaf 193 $obj->userdata = $backupprefs->$var2;
1ecea976 194 $obj->id = $instance->id;
195 $instancestopass[$instance->id]= $obj;
196 $countinstances++;
3bee1ead 197
1ecea976 198 }
199 }
3bee1ead 200 }
a94baeaf 201 $table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
16be8974 202 echo html_writer::table($table);
a615cc7b 203 echo "</td></tr>";
204 }
205 }
206 }
3bee1ead 207
57224893 208
873bf875 209 if (empty($to)) {
210 //Line
f2d57378 211 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
57224893 212
873bf875 213 //Now print the Users tr
214 echo "<tr>";
f2d57378 215 echo "<td colspan=\"2\"><b>";
873bf875 216 $user_options[0] = get_string("includeallusers");
217 $user_options[1] = get_string("includecourseusers");
218 $user_options[2] = get_string("includenoneusers");
a94baeaf 219 echo $user_options[$backupprefs->backup_users].'</b>';
873bf875 220 //Print info
fe75799d 221 $table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages, $backupprefs->backup_blogs);
16be8974 222 echo html_writer::table($table);
873bf875 223 echo "</td></tr>";
3bee1ead 224
873bf875 225 }
3bee1ead 226
a615cc7b 227 //Now print the Logs tr conditionally
a94baeaf 228 if ($backupprefs->backup_logs && empty($to)) {
a615cc7b 229 echo "<tr>";
f2d57378 230 echo "<td colspan=\"2\"><b>";
231 echo get_string("includelogentries").'</b>';
a615cc7b 232 //Print info
233 $table->data = log_check_backup($id);
16be8974 234 echo html_writer::table($table);
a615cc7b 235 echo "</td></tr>";
236 }
a615cc7b 237
238 //Now print the User Files tr conditionally
a94baeaf 239 if ($backupprefs->backup_user_files) {
a615cc7b 240 echo "<tr>";
f2d57378 241 echo "<td colspan=\"2\"><b>";
242 echo get_string("includeuserfiles").'</b>';
a615cc7b 243 //Print info
a94baeaf 244 $table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
16be8974 245 echo html_writer::table($table);
a615cc7b 246 echo "</td></tr>";
247 }
a615cc7b 248
249 //Now print the Course Files tr conditionally
f8f95b45 250 if ($backupprefs->backup_course_files) {
a615cc7b 251 echo "<tr>";
f2d57378 252 echo "<td colspan=\"2\"><b>";
253 echo get_string("includecoursefiles").'</b>';
a615cc7b 254 //Print info
a94baeaf 255 $table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
16be8974 256 echo html_writer::table($table);
a615cc7b 257 echo "</td></tr>";
258 }
f8f95b45 259
260 //Now print the site Files tr conditionally
261 if ($backupprefs->backup_site_files) {
3bee1ead 262 echo "<tr>";
263 echo "<td colspan=\"2\"><b>";
264 echo get_string("includesitefiles").'</b>';
265 //Print info
266 $table->data = site_files_check_backup($id,$backupprefs->backup_unique_code);
16be8974 267 echo html_writer::table($table);
3bee1ead 268 echo "</td></tr>";
269 }
f8f95b45 270
271 //Now print the role assignments information conditionally
272 if (!empty($backupprefs->backuproleassignments)) {
273 echo "<tr>";
274 echo "<td colspan=\"2\"><b>";
275 echo get_string("includeroleassignments").'</b>';
276 //Print info
277 $table->data = array(array(get_string('roles'), count($backupprefs->backuproleassignments)));
16be8974 278 echo html_writer::table($table);
f8f95b45 279 echo "</td></tr>";
280 }
a615cc7b 281 }
a94baeaf 282
283 // now keep it for next time.
284 $SESSION->backupprefs[$course->id] = $backupprefs;
285
a615cc7b 286?>
287</table>
fbe31d22 288<div style="text-align:center;margin-left:auto;margin-right:auto">
873bf875 289<input type="hidden" name="to" value="<?php p($to) ?>" />
290<input type="hidden" name="id" value="<?php p($id) ?>" />
291<input type="hidden" name="launch" value="execute" />
292<input type="submit" value="<?php print_string("continue") ?>" />
293<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
fbe31d22 294</div>
7ef0797d 295</form>