--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/_export_form.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,39 @@
+<?php
+
+print_heading(get_string('export', 'role'));
+
+echo '<form method="post" action="export.php">',
+     '<p>', get_string('export_desc', 'role'), '</p>';
+
+$table = new object;     
+$table->tablealign = 'center';
+$table->align = array('right', 'left', 'left', 'left');
+$table->wrap = array('nowrap', '', 'nowrap', 'nowrap');
+$table->cellpadding = 5;
+$table->cellspacing = 0;
+$table->width = '90%';
+$table->data = array();
+
+$table->head = array(get_string('name'),
+                     get_string('description'),
+                     get_string('shortname'),
+                     get_string('export', 'role'));
+
+$roles = get_all_roles();
+foreach ($roles as $role) {
+
+    $row = array();
+    $row[0] = '<a href="manage.php?roleid='.$role->id.'&amp;action=view">'.format_string($role->name).'</a>';
+    $row[1] = format_text($role->description, FORMAT_HTML);
+    $row[2] = s($role->shortname);
+    $row[3] = '<input type="checkbox" name="export[]" value="'.$role->shortname.'" />';
+
+    $table->data[] = $row;
+}
+
+print_table($table);
+
+echo '<input type="submit" value="'.get_string('export', 'role'), '" />',
+     '</form>';
+
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/export.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,96 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->dirroot.'/backup/lib.php');
+require_once($CFG->dirroot.'/backup/backuplib.php');
+
+admin_externalpage_setup('defineroles');
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+
+require_capability('moodle/role:manage', $sitecontext);
+
+$export = required_param('export');
+
+$preferences = new StdClass;
+$preferences->backup_unique_code = time();
+$preferences->backup_name = 'roles_backup';
+$preferences->backup_course = false;
+$preferences->mods = array();
+backup_add_static_preferences($preferences);
+
+if ($status = check_and_create_backup_dir($preferences->backup_unique_code)) {
+    $status = clear_backup_dir($preferences->backup_unique_code);
+}
+
+//Obtain the xml file (create and open) and print prolog information
+if ($bf = backup_open_xml($preferences->backup_unique_code)) {
+
+    fwrite($bf, start_tag("INFO", 1, true));
+
+    //The name of the backup
+    fwrite($bf, full_tag("NAME", 2, false, $preferences->backup_name));
+    //The moodle_version
+    fwrite($bf, full_tag("MOODLE_VERSION", 2, false, $preferences->moodle_version));
+    fwrite($bf, full_tag("MOODLE_RELEASE", 2, false, $preferences->moodle_release));
+    //The backup_version
+    fwrite($bf, full_tag("BACKUP_VERSION", 2, false, $preferences->backup_version));
+    fwrite($bf, full_tag("BACKUP_RELEASE", 2, false, $preferences->backup_release));
+    //The date
+    fwrite($bf, full_tag("DATE", 2, false, $preferences->backup_unique_code));
+    //The original site wwwroot
+    fwrite($bf, full_tag("ORIGINAL_WWWROOT", 2, false, $CFG->wwwroot));
+    //The original site identifier. MD5 hashed for security.
+    fwrite($bf, full_tag("ORIGINAL_SITE_IDENTIFIER_HASH", 2, false, md5(get_site_identifier())));
+
+    fwrite($bf, end_tag("INFO", 1, true));
+
+    fwrite($bf, start_tag('ROLES', 1, true));
+    foreach ($export as $role) {
+
+        $role = get_record('role', 'shortname', $role);
+
+        fwrite($bf, start_tag('ROLE', 2, true));
+
+        $role_array = (array) $role;
+        foreach ($role_array as $field => $value) {
+            fwrite($bf, full_tag(strtoupper($field), 3, false, $value));
+        }
+
+        // pull out all default (site context) capabilities
+        if ($capabilities = role_context_capabilities($role->id, $sitecontext)) {
+
+            // find and write all default capabilities
+            fwrite($bf, start_tag('CAPABILITIES', 3, true));
+
+            foreach ($capabilities as $capability=>$value) {
+
+                fwrite($bf, start_tag('CAPABILITY', 4, true));
+                fwrite($bf, full_tag('NAME', 5, false, $capability));
+                fwrite($bf, full_tag('PERMISSION', 5, false, $value));
+
+                // use this to pull out the other info (timemodified and modifierid)
+                $cap = get_record_sql("SELECT *
+                                         FROM {$CFG->prefix}role_capabilities
+                                        WHERE capability = '{$capability}'
+                                          AND contextid = {$sitecontext->id}
+                                          AND roleid = {$role->id}");
+
+                fwrite($bf, full_tag("TIMEMODIFIED", 5, false, $cap->timemodified));
+                fwrite($bf, full_tag("MODIFIERID", 5, false, $cap->modifierid));
+                fwrite($bf, end_tag('CAPABILITY', 4, true));
+            }
+            fwrite($bf, end_tag('CAPABILITIES', 3, true));
+        }
+        fwrite($bf, end_tag('ROLE', 2, true));
+    }
+    fwrite($bf, end_tag('ROLES', 1, true));
+
+    backup_close_xml($bf);
+
+    // send file
+    send_file($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/moodle.xml", 'roles.xml', 'default', 0, false, true);
+
+    $status = clean_temp_data($preferences);
+}
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/import_export.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,42 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+
+admin_externalpage_setup('defineroles');
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+require_capability('moodle/role:manage', $sitecontext);
+
+if (isset($_POST['form_submitted'])) {
+
+    if (isset($_FILES) AND $_FILES['roles_backup']['error'] == 0) {
+
+        $dest_dir = $CFG->dataroot.'/temp/roles';
+        check_dir_exists($dest_dir, true);
+
+        $dest_file = $dest_dir.'/backup_'.time().'.xml';
+
+        if (!move_uploaded_file($_FILES['roles_backup']['tmp_name'], $dest_file)) {
+            print_error('upload_failed', 'role');
+        }
+
+        $USER->role_import = array('xml_file' => $dest_file);
+
+        redirect('pre_import.php');
+
+    } else {
+        $upload_error = true;
+    }
+}
+
+admin_externalpage_print_header('');
+
+$currenttab = 'import_export';
+include_once('managetabs.php');
+
+include('_import_form.php');
+echo '<hr />';
+include('_export_form.php');
+
+admin_externalpage_print_footer();
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/_import_form.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,14 @@
+<?php
+print_heading(get_string('import', 'role'));
+
+echo '<form method="post" action="import_export.php" enctype="multipart/form-data">',
+     '<p>', get_string('import_desc', 'role'), '</p>',
+     '<input type="file" name="roles_backup" />',
+     '<input type="submit" name="form_submitted" value="'.get_string('next_step', 'role'), '" />',
+     '</form>';
+
+if (isset($upload_error) && $upload_error == true) {
+    echo '<p class="error">', get_string('no_file_uploaded', 'role'), '</p>';
+}
+
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/import_overview.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,67 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+
+require_capability('moodle/role:manage', get_context_instance(CONTEXT_SYSTEM));
+
+if (!isset($USER->role_import)) {
+    print_error('errorimportsession', 'role');
+}
+
+if (!file_exists($USER->role_import['xml_file'])) {
+    print_error('xml_file_not_found', 'role');
+}
+
+admin_externalpage_setup('defineroles');
+
+admin_externalpage_print_header('');
+
+$currenttab = 'import_export';
+include_once('managetabs.php');
+
+print_heading(get_string('importing', 'role'));
+
+echo '<form method="post" action="import.php">';
+
+print_heading(get_string('roles_import_as_new', 'role'), 'left', 3);
+$roles_count = 0;
+echo '<ul>';
+foreach ($USER->role_import['to_create'] as $original => $new) {
+    if (isset($USER->role_import['actions'][$original]) and $USER->role_import['actions'][$original] == 'import' ) {
+        $r = new object();
+        $r->original = $original;
+        $r->new = $new;
+        echo '<li>', get_string('as_new', 'role', $r), '</li>';
+        $roles_count++;
+    }
+}
+if ($roles_count == 0) {
+        echo '<li>', get_string('none', 'role'), '</li>';
+}
+echo '</ul>';
+
+print_heading(get_string('roles_import_replacing', 'role'), 'left', 3);
+$roles_count = 0;
+echo '<ul>';
+foreach ($USER->role_import['to_replace'] as $original => $new) {
+    if (isset($USER->role_import['actions'][$original]) and $USER->role_import['actions'][$original] == 'replace' ) {
+        $r = new object();
+        $r->original = $original;
+        $r->new = $new;
+        echo '<li>', get_string('replacing', 'role', $r), '</li>';
+        $roles_count++;
+    }
+}
+if ($roles_count == 0) {
+        echo '<li>', get_string('none', 'role'), '</li>';
+}
+
+echo '</ul>',
+     '<input type="submit" value="'.get_string('import'), '" />',
+     '</form>',
+     '<form method="post" action="import_export.php">',
+     '<input type="submit" value="'.get_string('cancel'), '" />',
+     '</form>';
+
+admin_externalpage_print_footer();
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/import.php	2010-06-29 17:05:27.000000000 -0400
@@ -0,0 +1,164 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->dirroot.'/backup/restorelib.php');
+
+if (!isset($USER->role_import)) {
+    print_error('errorimportsession', 'role');
+}
+
+if (!file_exists($USER->role_import['xml_file'])) {
+    print_error('xml_file_not_found', 'role');
+}
+
+admin_externalpage_setup('defineroles');
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+
+require_capability('moodle/role:manage', $sitecontext);
+
+admin_externalpage_print_header('');
+
+$currenttab = 'import_export';
+include_once('managetabs.php');
+
+print_heading(get_string('importing', 'role'));
+
+echo '<p>', get_string('starting_import', 'role'), '</p>';
+
+$info = restore_read_xml($USER->role_import['xml_file'], "ROLES", false);
+$roles_in_file = $info->roles;
+
+foreach ($roles_in_file as $role) {
+
+    if (!isset($USER->role_import['actions'][$role->shortname])) {
+        echo '<p>', get_string('role_ignored', 'role', $role), '</p>';
+        continue;
+    }
+
+    switch ($USER->role_import['actions'][$role->shortname]) {
+
+        case 'dont':
+            echo '<p>', get_string('role_ignored', 'role', $role), '</p>';
+            break;
+
+        case 'import':
+
+            if (!array_key_exists($role->shortname, $USER->role_import['to_create'])) {
+                print_error('new_shortname_undefined');
+            }
+
+            $new_role = $USER->role_import['to_create'][$role->shortname];
+
+            // code to make new role name/short name if same role name or shortname exists
+            $fullname = $role->name;
+            $shortname = $role->shortname;
+            $currentfullname = "";
+            $currentshortname = "";
+            $counter = 0;
+
+            do {
+                if ($counter) {
+                    $suffixfull = " ".get_string("copyasnoun")." ".$counter;
+                    $suffixshort = "_".$counter;
+                } else {
+                    $suffixfull = "";
+                    $suffixshort = "";
+                }
+                $currentfullname = $fullname.$suffixfull;
+                // Limit the size of shortname - database column accepts <= 100 chars
+                $currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)).$suffixshort;
+                $coursefull  = get_record("role", "name", addslashes($currentfullname));
+                $courseshort = get_record("role", "shortname", addslashes($currentshortname));
+                $counter++;
+            } while ($coursefull || $courseshort);
+
+            // done finding a unique name
+
+            $role_id = create_role(addslashes($currentfullname), $new_role, $role->description);
+
+            foreach ($role->capabilities as $capability) {
+                $roleinfo = new object();
+                $roleinfo = (object)$capability;
+                $roleinfo->contextid = $sitecontext->id;
+                $roleinfo->capability = $capability->name;
+                $roleinfo->roleid = $role_id;
+
+                insert_record('role_capabilities', $roleinfo);
+            }
+
+            $r = new object;
+            $r->new = $new_role;
+            $r->old = $role->shortname;
+            echo '<p>', get_string('new_role_created', 'role', $r), '</p>';
+            break;
+
+        case 'replace':
+
+            if (!array_key_exists($role->shortname, $USER->role_import['to_replace'])) {
+                print_error('shortname_to_replace_undefined');
+            }
+
+            $existing_role = $USER->role_import['to_replace'][$role->shortname];
+
+            // get the role to be updated
+            $role_record = get_record('role', 'shortname', $existing_role);
+
+            if (!$role_record) {
+                print_error('shortname_to_replace_undefined');
+            }
+
+            $role_id = $role_record->id;
+
+            $role_record->name = $role->name;
+            $role_record->description = $role->description;
+
+            update_record('role', $role_record);
+
+            //delete_records('role_capabilities', 'contextid', $sitecontext->id, 'roleid', $role_id);
+            $role_capabilities = get_records('role_capabilities', "contextid = '$sitecontext->id' AND roleid", $role_id, NULL, 'capability,id,contextid,roleid,permission');
+
+            foreach ($role->capabilities as $capability) {
+                $roleinfo = new object();
+                $roleinfo = (object)$capability;
+                $roleinfo->contextid = $sitecontext->id;
+                $roleinfo->capability = $capability->name;
+                $roleinfo->roleid = $role_id;
+
+                if (!isset($role_capabilities[$roleinfo->capability])) {
+                    insert_record('role_capabilities', $roleinfo);
+                } elseif ($role_capabilities[$roleinfo->capability]->permission != $roleinfo->permission) {
+                    $roleinfo->id = $role_capabilities[$roleinfo->capability]->id;
+                    update_record('role_capabilities', $roleinfo);
+                }
+
+                unset($role_capabilities[$roleinfo->capability]);
+            }
+
+            foreach ($role_capabilities as $delete_capability) {
+                delete_records('role_capabilities', 'id', $delete_capability->id);
+            }
+
+            $r = new object();
+            $r->new = $role->shortname;
+            $r->replaced = $existing_role;
+            echo '<p>', get_string('role_replaced', 'role', $r), '</p>';
+            break;
+
+        default:
+            $a = new stdclass();
+            $a->action = $USER->role_import['actions'][$role->shortname];
+            $a->shortname = $role->shortname;
+            echo '<p>', get_string('unknown_import_action', 'role', $a), '</p>';
+    }
+}
+
+echo '<p>', get_string('import_finished', 'role'), '</p>',
+     '<p><a href="manage.php">', get_string('back'), '</a></p>';
+
+unlink($USER->role_import['xml_file']);
+
+unset($USER->role_import);
+
+admin_externalpage_print_footer();
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/_pre_import_form.php	2010-07-12 16:42:21.000000000 -0400
@@ -0,0 +1,93 @@
+<?php
+print_heading(get_string('importing', 'role'));
+
+echo '<p>', get_string('pre_import_desc', 'role'), '</p>';
+
+if (isset($errors['no_action_selected']) and $errors['no_action_selected'] == true) {
+    print_heading(get_string('no_action_selected', 'role'), 'center', 3, 'error');
+}
+
+if (isset($errors['unknown_shortname_to_create'])) {
+    echo '<p class="error">', get_string('errorunknownshortnametocreate', 'role'), '</p>', '<ul class="error">';
+    foreach ($errors['unknown_shortname_to_create'] as $shortname) {
+        echo '<li>', $shortname, '</li>';
+    }
+    echo '</ul>';
+}
+
+if (isset($errors['unknown_role_to_replace'])) {
+    echo '<p class="error">', get_string('errorunknownroletoreplace', 'role'), '</p>', '<ul class="error">';
+    foreach ($errors['unknown_role_to_replace'] as $shortname) {
+        echo '<li>', $shortname, '</li>';
+    }
+    echo '</ul>';
+}
+
+echo '<form method="post" action="pre_import.php" >';
+
+$table = new object;     
+$table->tablealign = 'center';
+$table->align = array('right', 'left', 'left', 'left');
+$table->wrap = array('nowrap', '', 'nowrap', 'nowrap');
+$table->cellpadding = 5;
+$table->cellspacing = 0;
+$table->width = '90%';
+$table->data = array();
+
+$table->head = array(get_string('name'),
+                     get_string('shortname'),
+                     get_string('action'));
+
+foreach ($roles_to_import as $role) {
+
+    $row = array();
+    $row[0] = $role->name;
+    $row[1] = $role->shortname;
+
+    $dni_checked = (isset($actions[$role->shortname]) and $actions[$role->shortname] == 'dont') ? 'checked="checked"' : '';
+    $in_checked = (isset($actions[$role->shortname]) and $actions[$role->shortname] == 'import') ? 'checked="checked"' : '';
+    $ir_checked = (isset($actions[$role->shortname]) and $actions[$role->shortname] == 'replace') ? 'checked="checked"' : '';
+
+    $new_value = isset($roles_to_create[$role->shortname]) ? $roles_to_create[$role->shortname] : $role->shortname;
+
+    $options = '';
+    $replace_options = '';
+    foreach ($system_roles as $sr) {
+        if (isset($roles_to_replace[$role->shortname])) {
+            if ($roles_to_replace[$role->shortname] == $sr->shortname) {
+                $selected = ' selected="selected" ';
+            }
+        } elseif ($role->shortname == $sr->shortname) {
+            $selected = ' selected="selected" ';
+        } else {
+            $selected = '';
+        }
+        $options .= "<option {$selected} value=\"{$sr->shortname}\"> {$sr->name} ({$sr->shortname})</option>";
+    }
+
+    $row[2] = '<ul style="list-style-type: none;">
+               <li>
+                 <input type="radio" '.$dni_checked.' id="dni'.$role->id.'" name="actions['.$role->shortname.']" value="dont" />
+                 <label for="dni'.$role->id.'">'.get_string('do_not_import', 'role').'</label>
+               </li>
+               <li>
+                <input type="radio" '.$in_checked.' id="in'.$role->id.'" name="actions['.$role->shortname.']" value="import" />
+                <label for="in'.$role->id.'">'.get_string('import_new', 'role').'</label>
+                <input type="text" name="new['.$role->shortname.']" value="'.$new_value.'" />
+               </li>
+               <li>
+                <input type="radio" '.$ir_checked.' id="ir'.$role->id.'" name="actions['.$role->shortname.']" value="replace" />
+                <label for="ir'.$role->id.'">'.get_string('import_replacing', 'role').'</label>
+                <select name="replace['.$role->shortname.']" >'.$options.'</select>
+               </li>
+             </ul>
+         </tr>';
+
+    $table->data[] = $row;
+}
+
+print_table($table);
+
+echo '<input type="submit" name="form_submitted" value="'.get_string('next_step', 'role'), '" />',
+     '</form>';
+?>
--- /dev/null	2010-05-24 10:25:11.511663769 -0400
+++ admin/roles/pre_import.php	2010-07-12 16:44:39.000000000 -0400
@@ -0,0 +1,65 @@
+<?php
+require_once('../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->dirroot.'/backup/restorelib.php');
+
+require_capability('moodle/role:manage', get_context_instance(CONTEXT_SYSTEM));
+
+$actions          = optional_param('actions', array());
+$roles_to_create  = optional_param('new', array());
+$roles_to_replace = optional_param('replace', array());
+
+if (!isset($USER->role_import)) {
+    print_error('errorimportsession', 'role');
+}
+
+if (!file_exists($USER->role_import['xml_file'])) {
+    print_error('xml_file_not_found', 'role');
+}
+
+admin_externalpage_setup('defineroles');
+
+if (isset($_POST['form_submitted'])) {
+
+    $errors = array();
+
+    if (empty($actions) OR (!in_array('import', $actions) AND !in_array('replace', $actions))) {
+        $errors['no_action_selected'] = true;
+    } else {
+
+        foreach ($actions as $shortname => $action) {
+            if ($action == 'import')  {
+                if (!isset($roles_to_create[$shortname]) or empty($roles_to_create[$shortname])) {
+                    $errors['unknown_shortname_to_create'][] = $shortname;
+                }
+            } else if ($action == 'replace') {
+                if (!isset($roles_to_replace[$shortname])) {
+                    $errors['unknown_role_to_replace'][] = $shortname;
+                }
+            }
+        }
+
+        if (empty($errors)) {
+            $USER->role_import['to_create']  = $roles_to_create;
+            $USER->role_import['to_replace'] = $roles_to_replace;
+            $USER->role_import['actions']    = $actions;
+            redirect('import_overview.php');
+        }
+    }
+}
+
+$sql = "SELECT id, name, shortname
+          FROM {$CFG->dbname}.{$CFG->prefix}role";
+$system_roles = get_records_sql($sql);
+
+$roles_to_import = restore_read_xml($USER->role_import['xml_file'], "ROLES", false)->roles;
+
+admin_externalpage_print_header('');
+
+$currenttab = 'import_export';
+include_once('managetabs.php');
+
+include('_pre_import_form.php');
+
+admin_externalpage_print_footer();
+?>
diff --git admin/roles/managetabs.php admin/roles/managetabs.php
index 170f315..cf8aa2b 100755
--- admin/roles/managetabs.php
+++ admin/roles/managetabs.php
@@ -13,6 +13,8 @@
 
     $toprow[] = new tabobject('allowoverride', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowoverride.php', get_string('allowoverride', 'role'));
 
+    $toprow[] = new tabobject('import_export', $CFG->wwwroot.'/'.$CFG->admin.'/roles/import_export.php', get_string('import_export', 'role'));
+
     $tabs = array($toprow);
 
     print_tabs($tabs, $currenttab);
diff --git lang/en_utf8/role.php lang/en_utf8/role.php
index 1d05518..96cc7c0 100644
--- lang/en_utf8/role.php
+++ lang/en_utf8/role.php
@@ -10,6 +10,7 @@
 $string['assignroles'] = 'Assign roles';
 $string['assignrolesin'] = 'Assign roles in $a';
 $string['assignglobalroles'] = 'Assign system roles';
+$string['as_new'] = '$a->original as $a->new';
 $string['backup:userinfo'] = 'Backup user data';
 $string['blog:create'] = 'Create new blog entries';
 $string['blog:manageentries'] = 'Edit and manage entries';
@@ -28,6 +29,7 @@
 $string['category:update'] = 'Update categories';
 $string['category:viewhiddencategories'] = 'See hidden categories';
 $string['category:visibility'] = 'See hidden categories';
+$string['finish'] = 'Finish';
 $string['course:activityvisibility'] = 'Hide/show activities';
 $string['course:bulkmessaging'] = 'Send a message to many people';
 $string['course:changefullname'] = 'Change course full name';
@@ -58,6 +60,7 @@
 $string['course:visibility'] = 'Hide/show courses';
 $string['deletecourseoverrides'] = 'Delete all overrides in course';
 $string['deletelocalroles'] = 'Delete all local role assignments';
+$string['do_not_import'] = 'Do not import';
 $string['grade:edit'] = 'Edit grades';
 $string['grade:export'] = 'Export grades';
 $string['grade:hide'] = 'Hide/unhide grades or items';
@@ -83,9 +86,22 @@
 $string['errorbadroleshortname'] = 'Incorrect role name';
 $string['errorexistsrolename'] = 'Role name already exists';
 $string['errorexistsroleshortname'] = 'Role name already exists';
+$string['errorimportfile'] = 'There was an error reading the file you uploaded. Please try again.';
+$string['errorimportsession'] = 'There was an error in your import session. Please try again.';
 $string['existingusers'] = '$a existing users';
+$string['export'] = 'Export';
+$string['export_desc'] = 'If you want to backup roles of your system, please mark them at the list below and click on the \"Export\" button.';
 $string['globalrole'] = 'System role';
 $string['globalroleswarning'] = 'WARNING! Any roles you assign from this page will apply to the assigned users throughout the entire system, including the front page and all the courses.';
+$string['import'] = 'Import';
+$string['import_assigns'] = 'Import allow assigns';
+$string['import_desc'] = 'If you want to import roles to this system, please select a file and click on the \"Next step\" button.';
+$string['import_export'] = 'Import/Export';
+$string['import_finished'] = 'Import finished. Please verify the role assignments and role overrides using the tabs above.';
+$string['import_new'] = 'Import, creating new role with this shortname';
+$string['import_overrides'] = 'Import allow overrides';
+$string['import_replacing'] = 'Import, replacing with the selected existing role';
+$string['importing'] = 'Importing';
 $string['inherit'] = 'Inherit';
 $string['legacy:admin'] = 'LEGACY ROLE: Administrator';
 $string['legacy:coursecreator'] = 'LEGACY ROLE: Course Creator';
@@ -105,13 +121,20 @@
 $string['overridepermissionsin'] = 'Override permissions in $a';
 $string['morethan'] = 'More than $a';
 $string['my:manageblocks'] = 'Manage myMoodle page blocks';
+$string['needed_role_remaps'] = 'Needed role remaps';
+$string['next_step'] = 'Next step';
+$string['new_role_created'] = 'New role created: $a->new (was originally: $a->old)';
+$string['no_action_selected'] = 'You did not select any action or ignored all roles.';
+$string['no_file_uploaded'] = 'No file was uploaded.';
 $string['nocapabilitiesincontext'] = 'No capabilities available in this context';
+$string['none'] = 'None';
 $string['notset'] = 'Not set';
 $string['overrideroles'] = 'Override roles';
 $string['overriderolesin'] = 'Override roles in $a';
 $string['overrides'] = 'Overrides';
 $string['permissions'] = 'Permissions';
 $string['potentialusers'] = '$a potential users';
+$string['pre_import_desc'] = 'Below is the list of roles found in the file you uploaded. Please, choose how you want to import them to your system.';
 $string['prevent'] = 'Prevent';
 $string['prohibit'] = 'Prohibit';
 $string['question:add'] = 'Add new questions';
@@ -125,6 +148,7 @@
 $string['question:usemine'] = 'Use your own questions';
 $string['question:viewall'] = 'View all questions';
 $string['question:viewmine'] = 'View your own questions';
+$string['replacing'] = '$a->original replacing $a->new';
 $string['resetrole'] = 'Reset to defaults';
 $string['resetrolenolegacy'] = 'Clear permissions';
 $string['resetrolesure'] = 'Are you sure that you want to reset role \"$a->name ($a->shortname)\" to defaults?<p></p>The defaults are taken from the selected legacy capability ($a->legacytype).';
@@ -140,8 +164,12 @@
 $string['role:switchroles'] = 'Switch to other roles';
 $string['role:unassignself'] = 'Unassign own roles';
 $string['role:viewhiddenassigns'] = 'View hidden role assignments';
+$string['role_ignored'] = 'Role ignored: $a->shortname';
+$string['role_replaced'] = 'New role created: $a->new replaces old role $a->replaced ';
 $string['roleassignments'] = 'Role assignments';
 $string['roles'] = 'Roles';
+$string['roles_import_as_new'] = 'Roles that will be imported as new:';
+$string['roles_import_replacing'] = 'Roles that will be imported replacing existing roles:';
 $string['roletoassign'] = 'Role to assign';
 $string['roletooverride'] = 'Role to override';
 $string['safeoverridenotice'] = 'Note: Capabilities with higher risks are locked because you are only allowed to override safe capabilities.';
@@ -165,10 +193,14 @@
 $string['site:viewfullnames'] = 'Always see full names of users';
 $string['site:viewparticipants'] = 'View participants';
 $string['site:viewreports'] = 'View reports';
+$string['starting_import'] = 'Starting role imports';
 $string['tag:manage'] = 'Manage all tags';
 $string['tag:create'] = 'Create new tags';
 $string['tag:edit'] = 'Edit existing tags';
 $string['tag:editblocks'] = 'Edit blocks in tags pages';
+$string['unknown_import_action'] = 'Unknown import action ($a->action) for role $a->shortname';
+$string['errorunknownroletoreplace'] = 'These roles was marked to import replacing a role, but no shortname was informed:';
+$string['errorunknownshortnametocreate'] = 'These roles was marked to import as new, but no shortname was informed:';
 $string['user:changeownpassword'] = 'Change own password';
 $string['user:create'] = 'Create users';
 $string['user:delete'] = 'Delete users';
@@ -184,6 +216,7 @@
 $string['userhashiddenassignments'] = 'This user has one or more hidden role assignments in this course';
 $string['userswithrole'] = 'All users with a role';
 $string['viewrole'] = 'View role details';
+$string['xml_file_not_found'] = 'It seems the file you have uploaded was deleted. Please, try again.';
 $string['xuserswiththerole'] = 'Users with the role \"$a->role\"';
 $string['ingroup'] = 'in the group \"$a->group\"';
 $string['inactiveformorethan'] = 'inactive for more than $a->timeperiod';
diff --git theme/standard/styles_layout.css theme/standard/styles_layout.css
index 1900461..a5a50de 100644
--- theme/standard/styles_layout.css
+++ theme/standard/styles_layout.css
@@ -909,6 +909,14 @@ body#admin-modules table.generaltable td.c0
   margin: auto;
 }
 
+#admin-roles-import_export input {
+  display: block;
+  width: auto;
+  margin: 0.5em auto;
+}
+
+#admin-roles-pre_import input[type='submit'],
+#admin-roles-import_export p,
 #admin-stickyblocks .generalbox {
   text-align:center;
 }
--- backup/restorelib.php	2010-07-12 16:51:12.000000000 -0400
+++ backup/restorelib.php	2010-07-12 16:51:38.000000000 -0400
@@ -5712,6 +5712,9 @@
                             case "NAMEINCOURSE": // custom name of the role in course
                                 $this->info->roles[$this->info->tempid]->nameincourse = $this->getContents();;
                                 break;
+                            case "DESCRIPTION":
+                                $this->info->roles[$this->info->tempid]->description = $this->getContents();;
+                                break;
                         }
                     }
                     if ($this->level == 6) {
