MDL-10898 - Option to back up only selected role assignements when backing up a course with users.

This commit is contained in:
tjhunt
2007-09-25 14:44:53 +00:00
parent 31a6c06c46
commit f8f95b454a
5 changed files with 63 additions and 18 deletions
+19 -6
View File
@@ -85,9 +85,10 @@
}
}
}
$backupprefs->backup_user_files = 0;
$backupprefs->backup_logs = 0;
$backupprefs->backup_messages = 0;
$backupprefs->backup_user_files = 0;
$backupprefs->backup_logs = 0;
$backupprefs->backup_messages = 0;
$backupprefs->backuproleassignments = array();
}
print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
echo "<hr />";
@@ -197,7 +198,7 @@
}
//Now print the Course Files tr conditionally
if ($backupprefs->backup_course_files) {
if ($backupprefs->backup_course_files) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includecoursefiles").'</b>';
@@ -206,8 +207,9 @@
print_table($table);
echo "</td></tr>";
}
//Now print the site Files tr conditionally
if ($backupprefs->backup_site_files) {
//Now print the site Files tr conditionally
if ($backupprefs->backup_site_files) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includesitefiles").'</b>';
@@ -216,6 +218,17 @@
print_table($table);
echo "</td></tr>";
}
//Now print the role assignments information conditionally
if (!empty($backupprefs->backuproleassignments)) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includeroleassignments").'</b>';
//Print info
$table->data = array(array(get_string('roles'), count($backupprefs->backuproleassignments)));
print_table($table);
echo "</td></tr>";
}
}
// now keep it for next time.
+20 -1
View File
@@ -170,7 +170,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
$var = 'exists_one_'.$modname;
if (!empty($$var)) {
echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
$instances = get_all_instances_in_course($modname,$course);
$instances = get_all_instances_in_course($modname, $course, NULL, true);
foreach ($instances as $instance) {
echo '<tr><td>';
$var = 'backup_'.$modname.'_instance_'.$instance->id;
@@ -304,6 +304,25 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
}
}
//Now print a place to select which role assignments to back up.
if (empty($to)) {
//Line
echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
echo "<tr>";
echo "<td align=\"right\" valign=\"top\" colspan=\"2\"><b>";
echo get_string("backuproleassignments").":";
echo "</b></td><td colspan=\"2\">";
$roles = get_records('role', '', '', 'sortorder');
foreach ($roles as $role) {
print_checkbox('backupassignments_' . $role->shortname, 1, true, strip_tags(format_string($role->name, true)));
echo "<br />";
}
echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', true); return false;\">". get_string("all")."</a>/";
echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', false); return false;\">". get_string("none")."</a>";
echo "</td></tr>";
}
$backup_unique_code = time();
//Calculate the backup string
+21 -10
View File
@@ -721,7 +721,7 @@
/// write local course overrides here?
write_role_overrides_xml($bf, $context, 3);
/// write role_assign code here
write_role_assignments_xml($bf, $context, 3);
write_role_assignments_xml($bf, $context, 3, $preferences);
//Print header end
fwrite ($bf,end_tag("HEADER",2,true));
} else {
@@ -972,7 +972,7 @@
$context = get_context_instance(CONTEXT_BLOCK, $instance->id);
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $context, 4);
write_role_assignments_xml($bf, $context, 4, $preferences);
//End Block
fwrite ($bf,end_tag('BLOCK',3,true));
}
@@ -1109,9 +1109,9 @@
fwrite ($bf,full_tag("GROUPMEMBERSONLY",6,false,$course_module[$tok]->groupmembersonly));
// get all the role_capabilities overrides in this mod
write_role_overrides_xml($bf, $context, 6);
/// write role_assign code here
write_role_assignments_xml($bf, $context, 6);
/// write role_assign code here
/// write role_assign code here
write_role_assignments_xml($bf, $context, 6, $preferences);
/// write role_assign code here
fwrite ($bf,end_tag("MOD",5,true));
}
@@ -1270,8 +1270,8 @@
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $context, 4);
//End User tag
write_role_assignments_xml($bf, $context, 4, $preferences);
//End User tag
fwrite ($bf,end_tag("USER",3,true));
//Do some output
$counter++;
@@ -2429,7 +2429,7 @@
$var = 'exists_one_'.$modname;
$preferences->$var = true;
$varname = $modname.'_instances';
$preferences->$varname = get_all_instances_in_course($modname,$course);
$preferences->$varname = get_all_instances_in_course($modname, $course, NULL, true);
foreach ($preferences->$varname as $instance) {
$preferences->mods[$modname]->instances[$instance->id]->name = $instance->name;
$var = 'backup_'.$modname.'_instance_'.$instance->id;
@@ -2475,6 +2475,14 @@
$preferences->backup_name = required_param('backup_name',PARAM_FILE);
$preferences->backup_unique_code = required_param('backup_unique_code');
$roles = get_records('role', '', '', 'sortorder');
$preferences->backuproleassignments = array();
foreach ($roles as $role) {
if (optional_param('backupassignments_' . $role->shortname, 0, PARAM_INT)) {
$preferences->backuproleassignments[$role->id] = $role;
}
}
// put it (back) in the session
$SESSION->backupprefs[$course->id] = $preferences;
}
@@ -2579,12 +2587,15 @@
}
/* function to print xml for assignment */
function write_role_assignments_xml($bf, $context, $startlevel) {
/// write role_assign code here
function write_role_assignments_xml($bf, $context, $startlevel, $preferences) {
/// write role_assign code here
fwrite ($bf, start_tag("ROLES_ASSIGNMENTS", $startlevel, true));
if ($roles = get_roles_with_assignment_on_context($context)) {
foreach ($roles as $role) {
if (!isset($preferences->backuproleassignments[$role->id])) {
continue;
}
fwrite ($bf, start_tag("ROLE", $startlevel+1, true));
fwrite ($bf, full_tag("ID", $startlevel+2, false, $role->id));
fwrite ($bf, full_tag("NAME", $startlevel+2, false, $role->name));
+1 -1
View File
@@ -805,7 +805,7 @@
$var = 'exists_one_'.$modname;
$preferences->$var = true;
$varname = $modname.'_instances';
$preferences->$varname = get_all_instances_in_course($modname,$course);
$preferences->$varname = get_all_instances_in_course($modname, $course, NULL, true);
foreach ($preferences->$varname as $instance) {
$preferences->mods[$modname]->instances[$instance->id]->name = $instance->name;
$var = 'backup_'.$modname.'_instance_'.$instance->id;
+2
View File
@@ -157,6 +157,7 @@ $string['backupnameformat'] = '%%Y%%m%%d-%%H%%M';
$string['backupnoneusersinfo'] = 'Notice: You have selected to backup no users (\"none\"), so all the modules backup have been switched to \"without user data\" mode. Please note that the \"exercise\" and \"workshop\" modules aren\'t compatible with this type of backup, so they have been deactivated completely.';
$string['backupnonisowarning'] = 'Warning: this backup is from a non-Unicode version of Moodle (pre 1.6). If this backup contains any non-ISO-8859-1 texts then they may be CORRUPTED if you try to restore them to this Unicode version of Moodle. See the <a href=\"http://docs.moodle.org/en/Backup_FAQ\">Backup FAQ</a> for more information about how to recover this backup correctly.';
$string['backuporiginalname'] = 'Backup Name';
$string['backuproleassignments'] = 'Backup role assignments for these roles';
$string['backupsavetohelp'] = 'Full path to the directory where you want to save the backup files<br />(leave blank to save in its course default dir)';
$string['backupschedulehelp'] = 'Choose which days of the week to perform automated backups.';
$string['backupsitefileshelp'] = 'If enabled then site files used in courses will be included in automated backups';
@@ -779,6 +780,7 @@ $string['includemodules'] = 'Include Modules';
$string['includemoduleuserdata'] = 'Include module user data';
$string['includeneededusers'] = 'Include Needed Users';
$string['includenoneusers'] = 'Include No Users';
$string['includeroleassignments'] = 'Include role assignments';
$string['includesitefiles'] = 'Include Site Files Used in This Course';
$string['includeuserfiles'] = 'Include User Files';
$string['info'] = 'Information';