2 //This page prints the backup todo list to see everything
7 if (!empty($course->id
)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
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");
18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
25 $backupprefs = new StdClass
;
27 backup_fetch_prefs_from_request($backupprefs,$count,$course);
32 if (!$site = get_site()) {
33 error("Site not found!");
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">
50 //Now print the Backup Name tr
52 echo "<td align=\"right\"><b>";
53 echo get_string("name").":";
56 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name
."\" />";
60 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
62 //Now print the To Do list
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 backups. A Warning is showed to
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->backuproleassignments
= array();
119 print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
124 echo get_string("backupdetails").":";
125 echo "</b></td></tr>";
128 //This is the alignment of every row in the table
129 $table->align
= array ("left","right");
131 if ($allmods = get_records("modules") ) {
132 foreach ($allmods as $mod) {
133 $modname = $mod->name
;
134 $modfile = $CFG->dirroot
.'/mod/'.$modname.'/backuplib.php';
135 if (!file_exists($modfile)) {
138 require_once($modfile);
139 $modbackup = $modname."_backup_mods";
140 //If exists the lib & function
141 $var = "exists_".$modname;
142 if (isset($backupprefs->$var) && $backupprefs->$var) {
143 $var = "backup_".$modname;
145 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
148 echo "<td colspan=\"2\">";
150 echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
151 //Now look for user-data status
152 $backup_user_options[0] = get_string("withoutuserdata");
153 $backup_user_options[1] = get_string("withuserdata");
154 $var = "backup_user_info_".$modname;
155 //Print the user info
156 echo $backup_user_options[$backupprefs->$var]."</b>";
157 //Call the check function to show more info
158 $modcheckbackup = $modname."_check_backup_mods";
159 $var = $modname.'_instances';
160 $instancestopass = array();
161 if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
162 $table->data
= array();
164 foreach ($backupprefs->$var as $instance) {
165 $var1 = 'backup_'.$modname.'_instance_'.$instance->id
;
166 $var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id
;
167 if (!empty($backupprefs->$var1)) {
169 $obj->name
= $instance->name
;
170 $obj->userdata
= $backupprefs->$var2;
171 $obj->id
= $instance->id
;
172 $instancestopass[$instance->id
]= $obj;
178 $table->data
= $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code
,$instancestopass);
188 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
190 //Now print the Users tr
192 echo "<td colspan=\"2\"><b>";
193 $user_options[0] = get_string("includeallusers");
194 $user_options[1] = get_string("includecourseusers");
195 $user_options[2] = get_string("includenoneusers");
196 echo $user_options[$backupprefs->backup_users
].'</b>';
198 $table->data
= user_check_backup($id,$backupprefs->backup_unique_code
,$backupprefs->backup_users
,$backupprefs->backup_messages
);
204 //Now print the Logs tr conditionally
205 if ($backupprefs->backup_logs
&& empty($to)) {
207 echo "<td colspan=\"2\"><b>";
208 echo get_string("includelogentries").'</b>';
210 $table->data
= log_check_backup($id);
215 //Now print the User Files tr conditionally
216 if ($backupprefs->backup_user_files
) {
218 echo "<td colspan=\"2\"><b>";
219 echo get_string("includeuserfiles").'</b>';
221 $table->data
= user_files_check_backup($id,$backupprefs->backup_unique_code
);
226 //Now print the Course Files tr conditionally
227 if ($backupprefs->backup_course_files
) {
229 echo "<td colspan=\"2\"><b>";
230 echo get_string("includecoursefiles").'</b>';
232 $table->data
= course_files_check_backup($id,$backupprefs->backup_unique_code
);
237 //Now print the site Files tr conditionally
238 if ($backupprefs->backup_site_files
) {
240 echo "<td colspan=\"2\"><b>";
241 echo get_string("includesitefiles").'</b>';
243 $table->data
= site_files_check_backup($id,$backupprefs->backup_unique_code
);
248 //Now print the role assignments information conditionally
249 if (!empty($backupprefs->backuproleassignments
)) {
251 echo "<td colspan=\"2\"><b>";
252 echo get_string("includeroleassignments").'</b>';
254 $table->data
= array(array(get_string('roles'), count($backupprefs->backuproleassignments
)));
260 // now keep it for next time.
261 $SESSION->backupprefs
[$course->id
] = $backupprefs;
265 <div style=
"text-align:center;margin-left:auto;margin-right:auto">
266 <input type=
"hidden" name=
"to" value=
"<?php p($to) ?>" />
267 <input type
="hidden" name
="id" value
="<?php p($id) ?>" />
268 <input type
="hidden" name
="launch" value
="execute" />
269 <input type
="submit" value
="<?php print_string("continue") ?>" />
270 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />