]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10898 - Option to back up only selected role assignements when backing up a cours...
authortjhunt <tjhunt>
Tue, 25 Sep 2007 14:44:53 +0000 (14:44 +0000)
committertjhunt <tjhunt>
Tue, 25 Sep 2007 14:44:53 +0000 (14:44 +0000)
backup/backup_check.html
backup/backup_form.html
backup/backuplib.php
backup/lib.php
lang/en_utf8/moodle.php

index 817fbf5b48e4d1e9ea344e5a86683913d6b3faba..6a54826bd154a51c2baa40ac19db95236123dded 100644 (file)
                     }
                 }
             }
-        $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 />";
         }
 
         //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>';
             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>';
             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.
index d7b63bf3260b819948e1fb1600d9142849013bad..fd484368dc421e6ef9c1bc6ddbb46073a9ba1eb3 100644 (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
index 52fe33e544070875322b4caad0ce8a81f3d9205a..f27c85a0a00e4e30108f0d92986f47bbdb78ffd1 100644 (file)
             /// 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 {
                         $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));
                     }
                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));
            }
 
                 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++;
                 $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;
         $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;
     }
     }
 
     /* 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));
index f97edbeb9de4390b9c57fdfbfd1f2b097bb40788..2a309c54f3afba84af0c382a55fcc64f8fcf79d1 100644 (file)
                 $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;
index 64ec5eb282ee3e8a0036c8de12a442254014f945..1bc0c84459617f19d2fc315b9dd4df7be81ff678 100644 (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';