2 require_once("$CFG->dirroot/question/backuplib.php");
3 //This page prints the backup todo list to see everything
8 if (!empty($course->id
)) {
9 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
11 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
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");
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
;
28 backup_fetch_prefs_from_request($backupprefs,$count,$course);
33 if (!$site = get_site()) {
34 error("Site not found!");
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">
51 //Now print the Backup Name tr
53 echo "<td align=\"right\"><b>";
54 echo get_string("name").":";
57 echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name
."\" />";
61 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
63 //Now print the To Do list
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
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");
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)) {
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;
119 if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
122 echo "<td colspan=\"2\">";
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();
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)) {
143 $obj->name
= $instance->name
;
144 $obj->userdata
= $backupprefs->$var2;
145 $obj->id
= $instance->id
;
146 $instancestopass[$instance->id
]= $obj;
152 $table->data
= $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code
,$instancestopass);
162 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
164 //Now print the Users 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>';
172 $table->data
= user_check_backup($id,$backupprefs->backup_unique_code
,$backupprefs->backup_users
,$backupprefs->backup_messages
);
178 //Now print the Logs tr conditionally
179 if ($backupprefs->backup_logs
&& empty($to)) {
181 echo "<td colspan=\"2\"><b>";
182 echo get_string("includelogentries").'</b>';
184 $table->data
= log_check_backup($id);
189 //Now print the User Files tr conditionally
190 if ($backupprefs->backup_user_files
) {
192 echo "<td colspan=\"2\"><b>";
193 echo get_string("includeuserfiles").'</b>';
195 $table->data
= user_files_check_backup($id,$backupprefs->backup_unique_code
);
200 //Now print the Course Files tr conditionally
201 if ($backupprefs->backup_course_files
) {
203 echo "<td colspan=\"2\"><b>";
204 echo get_string("includecoursefiles").'</b>';
206 $table->data
= course_files_check_backup($id,$backupprefs->backup_unique_code
);
211 //Now print the site Files tr conditionally
212 if ($backupprefs->backup_site_files
) {
214 echo "<td colspan=\"2\"><b>";
215 echo get_string("includesitefiles").'</b>';
217 $table->data
= site_files_check_backup($id,$backupprefs->backup_unique_code
);
222 //Now print the role assignments information conditionally
223 if (!empty($backupprefs->backuproleassignments
)) {
225 echo "<td colspan=\"2\"><b>";
226 echo get_string("includeroleassignments").'</b>';
228 $table->data
= array(array(get_string('roles'), count($backupprefs->backuproleassignments
)));
234 // now keep it for next time.
235 $SESSION->backupprefs
[$course->id
] = $backupprefs;
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
") ?>" />