MDL-11515:
[moodle-linuxchix.git] / backup / backup_check.html
blob6a54826bd154a51c2baa40ac19db95236123dded
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;
91 $backupprefs->backuproleassignments = array();
93 print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
94 echo "<hr />";
97 if (empty($to)) {
98 echo get_string("backupdetails").":";
99 echo "</b></td></tr>";
102 //This is the alignment of every row in the table
103 $table->align = array ("left","right");
105 if ($allmods = get_records("modules") ) {
106 foreach ($allmods as $mod) {
107 $modname = $mod->name;
108 $modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php';
109 if (!file_exists($modfile)) {
110 continue;
112 require_once($modfile);
113 $modbackup = $modname."_backup_mods";
114 //If exists the lib & function
115 $var = "exists_".$modname;
116 if (isset($backupprefs->$var) && $backupprefs->$var) {
117 $var = "backup_".$modname;
118 //Only if selected
119 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
120 //Print the full tr
121 echo "<tr>";
122 echo "<td colspan=\"2\">";
123 //Print the mod name
124 echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
125 //Now look for user-data status
126 $backup_user_options[0] = get_string("withoutuserdata");
127 $backup_user_options[1] = get_string("withuserdata");
128 $var = "backup_user_info_".$modname;
129 //Print the user info
130 echo $backup_user_options[$backupprefs->$var]."</b>";
131 //Call the check function to show more info
132 $modcheckbackup = $modname."_check_backup_mods";
133 $var = $modname.'_instances';
134 $instancestopass = array();
135 if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
136 $table->data = array();
137 $countinstances = 0;
138 foreach ($backupprefs->$var as $instance) {
139 $var1 = 'backup_'.$modname.'_instance_'.$instance->id;
140 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
141 if (!empty($backupprefs->$var1)) {
142 $obj = new StdClass;
143 $obj->name = $instance->name;
144 $obj->userdata = $backupprefs->$var2;
145 $obj->id = $instance->id;
146 $instancestopass[$instance->id]= $obj;
147 $countinstances++;
152 $table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
153 print_table($table);
154 echo "</td></tr>";
160 if (empty($to)) {
161 //Line
162 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
164 //Now print the Users tr
165 echo "<tr>";
166 echo "<td colspan=\"2\"><b>";
167 $user_options[0] = get_string("includeallusers");
168 $user_options[1] = get_string("includecourseusers");
169 $user_options[2] = get_string("includenoneusers");
170 echo $user_options[$backupprefs->backup_users].'</b>';
171 //Print info
172 $table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages);
173 print_table($table);
174 echo "</td></tr>";
178 //Now print the Logs tr conditionally
179 if ($backupprefs->backup_logs && empty($to)) {
180 echo "<tr>";
181 echo "<td colspan=\"2\"><b>";
182 echo get_string("includelogentries").'</b>';
183 //Print info
184 $table->data = log_check_backup($id);
185 print_table($table);
186 echo "</td></tr>";
189 //Now print the User Files tr conditionally
190 if ($backupprefs->backup_user_files) {
191 echo "<tr>";
192 echo "<td colspan=\"2\"><b>";
193 echo get_string("includeuserfiles").'</b>';
194 //Print info
195 $table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
196 print_table($table);
197 echo "</td></tr>";
200 //Now print the Course Files tr conditionally
201 if ($backupprefs->backup_course_files) {
202 echo "<tr>";
203 echo "<td colspan=\"2\"><b>";
204 echo get_string("includecoursefiles").'</b>';
205 //Print info
206 $table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
207 print_table($table);
208 echo "</td></tr>";
211 //Now print the site Files tr conditionally
212 if ($backupprefs->backup_site_files) {
213 echo "<tr>";
214 echo "<td colspan=\"2\"><b>";
215 echo get_string("includesitefiles").'</b>';
216 //Print info
217 $table->data = site_files_check_backup($id,$backupprefs->backup_unique_code);
218 print_table($table);
219 echo "</td></tr>";
222 //Now print the role assignments information conditionally
223 if (!empty($backupprefs->backuproleassignments)) {
224 echo "<tr>";
225 echo "<td colspan=\"2\"><b>";
226 echo get_string("includeroleassignments").'</b>';
227 //Print info
228 $table->data = array(array(get_string('roles'), count($backupprefs->backuproleassignments)));
229 print_table($table);
230 echo "</td></tr>";
234 // now keep it for next time.
235 $SESSION->backupprefs[$course->id] = $backupprefs;
238 </table>
239 <div style="text-align:center;margin-left:auto;margin-right:auto">
240 <input type="hidden" name="to" value="<?php p($to) ?>" />
241 <input type="hidden" name="id" value="<?php p($id) ?>" />
242 <input type="hidden" name="launch" value="execute" />
243 <input type="submit" value="<?php print_string("continue") ?>" />
244 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
245 </div>
246 </form>