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
))) {
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 & blogs 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->backup_blogs
= 0;
118 $backupprefs->backuproleassignments
= array();
120 print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
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)) {
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;
146 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
149 echo "<td colspan=\"2\">";
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();
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)) {
170 $obj->name
= $instance->name
;
171 $obj->userdata
= $backupprefs->$var2;
172 $obj->id
= $instance->id
;
173 $instancestopass[$instance->id
]= $obj;
179 $table->data
= $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code
,$instancestopass);
189 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
191 //Now print the Users 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>';
199 $table->data
= user_check_backup($id,$backupprefs->backup_unique_code
,$backupprefs->backup_users
,$backupprefs->backup_messages
, $backupprefs->backup_blogs
);
205 //Now print the Logs tr conditionally
206 if ($backupprefs->backup_logs
&& empty($to)) {
208 echo "<td colspan=\"2\"><b>";
209 echo get_string("includelogentries").'</b>';
211 $table->data
= log_check_backup($id);
216 //Now print the User Files tr conditionally
217 if ($backupprefs->backup_user_files
) {
219 echo "<td colspan=\"2\"><b>";
220 echo get_string("includeuserfiles").'</b>';
222 $table->data
= user_files_check_backup($id,$backupprefs->backup_unique_code
);
227 //Now print the Course Files tr conditionally
228 if ($backupprefs->backup_course_files
) {
230 echo "<td colspan=\"2\"><b>";
231 echo get_string("includecoursefiles").'</b>';
233 $table->data
= course_files_check_backup($id,$backupprefs->backup_unique_code
);
238 //Now print the site Files tr conditionally
239 if ($backupprefs->backup_site_files
) {
241 echo "<td colspan=\"2\"><b>";
242 echo get_string("includesitefiles").'</b>';
244 $table->data
= site_files_check_backup($id,$backupprefs->backup_unique_code
);
249 //Now print the role assignments information conditionally
250 if (!empty($backupprefs->backuproleassignments
)) {
252 echo "<td colspan=\"2\"><b>";
253 echo get_string("includeroleassignments").'</b>';
255 $table->data
= array(array(get_string('roles'), count($backupprefs->backuproleassignments
)));
261 // now keep it for next time.
262 $SESSION->backupprefs
[$course->id
] = $backupprefs;
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
") ?>" />