MDL-24203 unused string removed
[moodle.git] / backup / backup_check.html
1 <?php
2     //This page prints the backup todo list to see everything
4     //Check login
5     require_login();
7     $loginurl = get_login_url();
9     // Init backupuserinfo
10     $backupuserinfo = false;
12     if (!empty($course->id)) {
13         if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
14             if (empty($to)) {
15                 print_error("cannotuseadminadminorteacher", '', $loginurl);
16             } else {
17                 if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
18                     print_error("cannotuseadminadminorteacher", '', $loginurl);
19                 }
20             }
21         }
22         $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_COURSE, $course->id));
23     } else {
24         if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
25             print_error("cannotuseadmin", '', $loginurl);
26         }
27         $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
28     }
32     $backupprefs = new StdClass;
33     $count = 0;
34     backup_fetch_prefs_from_request($backupprefs,$count,$course);
38     //Check site
39     $site = get_site();
40     if ($count == 0) {
41         notice("No backupable modules are installed!");
42     }
44     if (!$DB->delete_records("backup_ids", array('backup_code'=>$backupprefs->backup_unique_code))){
45         print_error('cannotdeletebackupids');
46     }
48 ?>
50 <form id="form" method="post" action="backup.php">
51 <table cellpadding="5" style="text-align:center;margin-left:auto;margin-right:auto">
52 <?php
53     echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
55     if (empty($to)) {
56         //Now print the Backup Name tr
57         echo "<tr>";
58         echo "<td align=\"right\"><b>";
59         echo get_string("name").":";
60         echo "</b></td><td>";
61         //Add as text field
62         echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name."\" />";
63         echo "</td></tr>";
65         //Line
66         echo "<tr><td colspan=\"2\"><hr /></td></tr>";
68         //Now print the To Do list
69         echo "<tr>";
70         echo "<td colspan=\"2\" align=\"center\"><b>";
72     }
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))) {
76         $backupprefs->backup_users = 1; // users => course
77     }
79     // Re-enforce moodle/backup:userinfo capability
80     if (!$backupuserinfo) {
81         $backupprefs->backup_users = 2; // users => none
82     }
84     //Here we check if backup_users = None. Then, we switch off every module
85     //user info, user_files, logs and exercises, workshop and messages & blogs backups. A Warning is showed to
86     //inform the user.
87     // TODO: Move this logic to one function to be shared by any (manual, scheduled) backup
88     if ($backupprefs->backup_users == 2) {
89         if ($allmods = $DB->get_records('modules') ) {
90             foreach ($allmods as $mod) {
91             /// Reset global user_info settings to "no" (0)
92                 $modname = $mod->name;
93                 $var = 'backup_user_info_'.$modname;
94                 if (isset($backupprefs->$var)) {
95                     $backupprefs->$var = 0;
96                 }
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)) {
112                         $backupprefs->$var = 0;
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                         }
126                     }
127                 }
128             }
129         }
130         $backupprefs->backup_user_files = 0;
131         $backupprefs->backup_logs = 0;
132         $backupprefs->backup_messages = 0;
133         $backupprefs->backup_blogs = 0;
134         $backupprefs->backuproleassignments = array();
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");
142         echo "<hr />";
143     }
145     if (empty($to)) {
146         echo get_string("backupdetails").":";
147         echo "</b></td></tr>";
148     }
150     //This is the alignment of every row in the table
151     $table = new html_table();
152     $table->align = array ("left","right");
154     if ($allmods = $DB->get_records("modules") ) {
155         foreach ($allmods as $mod) {
156             $modname = $mod->name;
157             $modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php';
158             if (!file_exists($modfile)) {
159                 continue;
160             }
161             require_once($modfile);
162             $modbackup = $modname."_backup_mods";
163             //If exists the lib & function
164             $var = "exists_".$modname;
165             if (isset($backupprefs->$var) && $backupprefs->$var) {
166                 $var = "backup_".$modname;
167                 //Only if selected
168                 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
169                     //Print the full tr
170                     echo "<tr>";
171                     echo "<td colspan=\"2\">";
172                     //Print the mod name
173                     echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
174                     //Now look for user-data status
175                     $backup_user_options[0] = get_string("withoutuserdata");
176                     $backup_user_options[1] = get_string("withuserdata");
177                     $var = "backup_user_info_".$modname;
178                     //Print the user info
179                     echo $backup_user_options[$backupprefs->$var]."</b>";
180                     //Call the check function to show more info
181                     $modcheckbackup = $modname."_check_backup_mods";
182                     $var = $modname.'_instances';
183                     $instancestopass = array();
184                     if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
185                         $table->data = array();
186                         $countinstances = 0;
187                         foreach ($backupprefs->$var as $instance) {
188                             $var1 = 'backup_'.$modname.'_instance_'.$instance->id;
189                             $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
190                             if (!empty($backupprefs->$var1)) {
191                                 $obj = new StdClass;
192                                 $obj->name = $instance->name;
193                                 $obj->userdata = $backupprefs->$var2;
194                                 $obj->id = $instance->id;
195                                 $instancestopass[$instance->id]= $obj;
196                                 $countinstances++;
198                             }
199                         }
200                     }
201                     $table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
202                     echo html_writer::table($table);
203                     echo "</td></tr>";
204                 }
205             }
206         }
209         if (empty($to)) {
210             //Line
211             echo "<tr><td colspan=\"2\"><hr /></td></tr>";
213             //Now print the Users tr
214             echo "<tr>";
215             echo "<td colspan=\"2\"><b>";
216             $user_options[0] = get_string("includeallusers");
217             $user_options[1] = get_string("includecourseusers");
218             $user_options[2] = get_string("includenoneusers");
219             echo $user_options[$backupprefs->backup_users].'</b>';
220             //Print info
221             $table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages, $backupprefs->backup_blogs);
222             echo html_writer::table($table);
223             echo "</td></tr>";
225         }
227         //Now print the Logs tr conditionally
228         if ($backupprefs->backup_logs && empty($to)) {
229             echo "<tr>";
230             echo "<td colspan=\"2\"><b>";
231             echo get_string("includelogentries").'</b>';
232             //Print info
233             $table->data = log_check_backup($id);
234             echo html_writer::table($table);
235             echo "</td></tr>";
236         }
238         //Now print the User Files tr conditionally
239         if ($backupprefs->backup_user_files) {
240             echo "<tr>";
241             echo "<td colspan=\"2\"><b>";
242             echo get_string("includeuserfiles").'</b>';
243             //Print info
244             $table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
245             echo html_writer::table($table);
246             echo "</td></tr>";
247         }
249         //Now print the Course Files tr conditionally
250         if ($backupprefs->backup_course_files) {
251             echo "<tr>";
252             echo "<td colspan=\"2\"><b>";
253             echo get_string("includecoursefiles").'</b>';
254             //Print info
255             $table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
256             echo html_writer::table($table);
257             echo "</td></tr>";
258         }
260         //Now print the site Files tr conditionally
261         if ($backupprefs->backup_site_files) {
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);
267             echo html_writer::table($table);
268             echo "</td></tr>";
269         }
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)));
278             echo html_writer::table($table);
279             echo "</td></tr>";
280         }
281     }
283     // now keep it for next time.
284     $SESSION->backupprefs[$course->id] = $backupprefs;
286 ?>
287 </table>
288 <div style="text-align:center;margin-left:auto;margin-right:auto">
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") ?>" />
294 </div>
295 </form>