Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / backup / backup_check.html
blobac1f7fd81cf8a422616da0fc3a664cd5b65b9146
1 <?php //$Id$
2 //This page prints the backup todo list to see everything
4 //Check login
5 require_login();
7 if (!empty($course->id)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
9 if (empty($to)) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
11 } else {
12 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
17 } else {
18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
25 $backupprefs = new StdClass;
26 $count = 0;
27 backup_fetch_prefs_from_request($backupprefs,$count,$course);
31 //Check site
32 if (!$site = get_site()) {
33 error("Site not found!");
35 if ($count == 0) {
36 notice("No backupable modules are installed!");
39 if (!execute_sql("DELETE FROM {$CFG->prefix}backup_ids WHERE backup_code = '{$backupprefs->backup_unique_code}'",false)){
40 error('Couldn\'t delete previous backup ids.');
45 <form id="form" method="post" action="backup.php">
46 <table cellpadding="5" style="text-align:center;margin-left:auto;margin-right:auto">
47 <?php
49 if (empty($to)) {
50 //Now print the Backup Name tr
51 echo "<tr>";
52 echo "<td align=\"right\"><b>";
53 echo get_string("name").":";
54 echo "</b></td><td>";
55 //Add as text field
56 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name."\" />";
57 echo "</td></tr>";
59 //Line
60 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
62 //Now print the To Do list
63 echo "<tr>";
64 echo "<td colspan=\"2\" align=\"center\"><b>";
68 //Here we check if backup_users = None. Then, we switch off every module
69 //user info, user_files, logs and exercises, workshop and messages & blogs backups. A Warning is showed to
70 //inform the user.
71 // TODO: Move this logic to one function to be shared by any (manual, scheduled) backup
72 if ($backupprefs->backup_users == 2) {
73 if ($allmods = get_records('modules') ) {
74 foreach ($allmods as $mod) {
75 /// Reset global user_info settings to "no" (0)
76 $modname = $mod->name;
77 $var = 'backup_user_info_'.$modname;
78 if (isset($backupprefs->$var)) {
79 $backupprefs->$var = 0;
81 /// Reset each instance userinfo settings to "no" (0)
82 if (isset($backupprefs->mods[$modname])) {
83 /// Set the module userinfo to no (0)
84 $backupprefs->mods[$modname]->userinfo = 0;
85 /// Set the instances to no (o)
86 foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
87 $backupprefs->mods[$modname]->instances[$key]->userinfo = 0;
88 $var = 'backup_user_info_' . $modname . '_instance_' . $key;
89 $backupprefs->$var = 0;
92 /// If modules are workshop or exercise, disable their backup completely
93 if ($modname == 'exercise' || $modname == 'workshop') {
94 $var = 'backup_'.$modname;
95 if (isset($backupprefs->$var)) {
96 $backupprefs->$var = 0;
97 /// Reset each instance backup settings to "no" (0)
98 if (isset($backupprefs->mods[$modname])) {
99 /// Set the module backup to no (0)
100 $backupprefs->mods[$modname]->backup = 0;
101 $var = 'backup_' . $modname . '_instances';
102 $backupprefs->$var = 0;
103 /// Set the instances backup to no (o)
104 foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
105 $backupprefs->mods[$modname]->instances[$key]->backup = 0;
106 $var = 'backup_' . $modname . '_instance_' . $key;
107 $backupprefs->$var = 0;
114 $backupprefs->backup_user_files = 0;
115 $backupprefs->backup_logs = 0;
116 $backupprefs->backup_messages = 0;
117 $backupprefs->backup_blogs = 0;
118 $backupprefs->backuproleassignments = array();
120 print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
121 echo "<hr />";
124 if (empty($to)) {
125 echo get_string("backupdetails").":";
126 echo "</b></td></tr>";
129 //This is the alignment of every row in the table
130 $table->align = array ("left","right");
132 if ($allmods = get_records("modules") ) {
133 foreach ($allmods as $mod) {
134 $modname = $mod->name;
135 $modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php';
136 if (!file_exists($modfile)) {
137 continue;
139 require_once($modfile);
140 $modbackup = $modname."_backup_mods";
141 //If exists the lib & function
142 $var = "exists_".$modname;
143 if (isset($backupprefs->$var) && $backupprefs->$var) {
144 $var = "backup_".$modname;
145 //Only if selected
146 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
147 //Print the full tr
148 echo "<tr>";
149 echo "<td colspan=\"2\">";
150 //Print the mod name
151 echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
152 //Now look for user-data status
153 $backup_user_options[0] = get_string("withoutuserdata");
154 $backup_user_options[1] = get_string("withuserdata");
155 $var = "backup_user_info_".$modname;
156 //Print the user info
157 echo $backup_user_options[$backupprefs->$var]."</b>";
158 //Call the check function to show more info
159 $modcheckbackup = $modname."_check_backup_mods";
160 $var = $modname.'_instances';
161 $instancestopass = array();
162 if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
163 $table->data = array();
164 $countinstances = 0;
165 foreach ($backupprefs->$var as $instance) {
166 $var1 = 'backup_'.$modname.'_instance_'.$instance->id;
167 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
168 if (!empty($backupprefs->$var1)) {
169 $obj = new StdClass;
170 $obj->name = $instance->name;
171 $obj->userdata = $backupprefs->$var2;
172 $obj->id = $instance->id;
173 $instancestopass[$instance->id]= $obj;
174 $countinstances++;
179 $table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
180 print_table($table);
181 echo "</td></tr>";
187 if (empty($to)) {
188 //Line
189 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
191 //Now print the Users tr
192 echo "<tr>";
193 echo "<td colspan=\"2\"><b>";
194 $user_options[0] = get_string("includeallusers");
195 $user_options[1] = get_string("includecourseusers");
196 $user_options[2] = get_string("includenoneusers");
197 echo $user_options[$backupprefs->backup_users].'</b>';
198 //Print info
199 $table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages, $backupprefs->backup_blogs);
200 print_table($table);
201 echo "</td></tr>";
205 //Now print the Logs tr conditionally
206 if ($backupprefs->backup_logs && empty($to)) {
207 echo "<tr>";
208 echo "<td colspan=\"2\"><b>";
209 echo get_string("includelogentries").'</b>';
210 //Print info
211 $table->data = log_check_backup($id);
212 print_table($table);
213 echo "</td></tr>";
216 //Now print the User Files tr conditionally
217 if ($backupprefs->backup_user_files) {
218 echo "<tr>";
219 echo "<td colspan=\"2\"><b>";
220 echo get_string("includeuserfiles").'</b>';
221 //Print info
222 $table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
223 print_table($table);
224 echo "</td></tr>";
227 //Now print the Course Files tr conditionally
228 if ($backupprefs->backup_course_files) {
229 echo "<tr>";
230 echo "<td colspan=\"2\"><b>";
231 echo get_string("includecoursefiles").'</b>';
232 //Print info
233 $table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
234 print_table($table);
235 echo "</td></tr>";
238 //Now print the site Files tr conditionally
239 if ($backupprefs->backup_site_files) {
240 echo "<tr>";
241 echo "<td colspan=\"2\"><b>";
242 echo get_string("includesitefiles").'</b>';
243 //Print info
244 $table->data = site_files_check_backup($id,$backupprefs->backup_unique_code);
245 print_table($table);
246 echo "</td></tr>";
249 //Now print the role assignments information conditionally
250 if (!empty($backupprefs->backuproleassignments)) {
251 echo "<tr>";
252 echo "<td colspan=\"2\"><b>";
253 echo get_string("includeroleassignments").'</b>';
254 //Print info
255 $table->data = array(array(get_string('roles'), count($backupprefs->backuproleassignments)));
256 print_table($table);
257 echo "</td></tr>";
261 // now keep it for next time.
262 $SESSION->backupprefs[$course->id] = $backupprefs;
265 </table>
266 <div style="text-align:center;margin-left:auto;margin-right:auto">
267 <input type="hidden" name="to" value="<?php p($to) ?>" />
268 <input type="hidden" name="id" value="<?php p($id) ?>" />
269 <input type="hidden" name="launch" value="execute" />
270 <input type="submit" value="<?php print_string("continue") ?>" />
271 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
272 </div>
273 </form>