MDL-10689:
[moodle-linuxchix.git] / backup / backup_check.html
blob817fbf5b48e4d1e9ea344e5a86683913d6b3faba
1 <?php //$Id$
2 require_once("$CFG->dirroot/question/backuplib.php");
3 //This page prints the backup todo list to see everything
5 //Check login
6 require_login();
8 if (!empty($course->id)) {
9 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
10 if (empty($to)) {
11 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
12 } else {
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");
18 } else {
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;
27 $count = 0;
28 backup_fetch_prefs_from_request($backupprefs,$count,$course);
32 //Check site
33 if (!$site = get_site()) {
34 error("Site not found!");
36 if ($count == 0) {
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">
48 <?php
50 if (empty($to)) {
51 //Now print the Backup Name tr
52 echo "<tr>";
53 echo "<td align=\"right\"><b>";
54 echo get_string("name").":";
55 echo "</b></td><td>";
56 //Add as text field
57 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name."\" />";
58 echo "</td></tr>";
60 //Line
61 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
63 //Now print the To Do list
64 echo "<tr>";
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
72 //inform the user.
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");
93 echo "<hr />";
96 if (empty($to)) {
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)) {
109 continue;
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;
117 //Only if selected
118 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
119 //Print the full tr
120 echo "<tr>";
121 echo "<td colspan=\"2\">";
122 //Print the mod name
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();
136 $countinstances = 0;
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)) {
141 $obj = new StdClass;
142 $obj->name = $instance->name;
143 $obj->userdata = $backupprefs->$var2;
144 $obj->id = $instance->id;
145 $instancestopass[$instance->id]= $obj;
146 $countinstances++;
151 $table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
152 print_table($table);
153 echo "</td></tr>";
159 if (empty($to)) {
160 //Line
161 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
163 //Now print the Users tr
164 echo "<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>';
170 //Print info
171 $table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages);
172 print_table($table);
173 echo "</td></tr>";
177 //Now print the Logs tr conditionally
178 if ($backupprefs->backup_logs && empty($to)) {
179 echo "<tr>";
180 echo "<td colspan=\"2\"><b>";
181 echo get_string("includelogentries").'</b>';
182 //Print info
183 $table->data = log_check_backup($id);
184 print_table($table);
185 echo "</td></tr>";
188 //Now print the User Files tr conditionally
189 if ($backupprefs->backup_user_files) {
190 echo "<tr>";
191 echo "<td colspan=\"2\"><b>";
192 echo get_string("includeuserfiles").'</b>';
193 //Print info
194 $table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
195 print_table($table);
196 echo "</td></tr>";
199 //Now print the Course Files tr conditionally
200 if ($backupprefs->backup_course_files) {
201 echo "<tr>";
202 echo "<td colspan=\"2\"><b>";
203 echo get_string("includecoursefiles").'</b>';
204 //Print info
205 $table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
206 print_table($table);
207 echo "</td></tr>";
209 //Now print the site Files tr conditionally
210 if ($backupprefs->backup_site_files) {
211 echo "<tr>";
212 echo "<td colspan=\"2\"><b>";
213 echo get_string("includesitefiles").'</b>';
214 //Print info
215 $table->data = site_files_check_backup($id,$backupprefs->backup_unique_code);
216 print_table($table);
217 echo "</td></tr>";
221 // now keep it for next time.
222 $SESSION->backupprefs[$course->id] = $backupprefs;
225 </table>
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") ?>" />
232 </div>
233 </form>