diff --git a/admin/roles/_export_form.php b/admin/roles/_export_form.php
new file mode 100644
index 0000000..c08349f
--- /dev/null
+++ b/admin/roles/_export_form.php
@@ -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>';
+
+?>
diff --git a/admin/roles/_import_form.php b/admin/roles/_import_form.php
new file mode 100644
index 0000000..afbf917
--- /dev/null
+++ b/admin/roles/_import_form.php
@@ -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>';
+}
+
+?>
diff --git a/admin/roles/_pre_import_form.php b/admin/roles/_pre_import_form.php
new file mode 100644
index 0000000..fbdb3e6
--- /dev/null
+++ b/admin/roles/_pre_import_form.php
@@ -0,0 +1,90 @@
+<?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'));
+
+$options = '';
+
+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] : '';
+
+    $replace_options = '';
+    foreach ($system_roles as $sr) {
+        if (isset($roles_to_replace[$role->shortname]) AND $roles_to_replace[$role->shortname] == $sr->shortname) {
+            $selected = ' selected ';
+        } else {
+            $selected = '';
+        }
+        $options .= "<option {$selected} value=\"{$sr->shortname}\"> {$sr->name} ({$sr->shortname})</option>";
+    }
+
+    $row[2] = '<ul>
+               <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>';
+?>
diff --git a/admin/roles/export.php b/admin/roles/export.php
new file mode 100644
index 0000000..f54303f
--- /dev/null
+++ b/admin/roles/export.php
@@ -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->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));
+
+        fwrite($bf,full_tag('ID', 3, false, $role->id));
+        fwrite($bf,full_tag('NAME',3,false,$role->name));
+        fwrite($bf,full_tag('SHORTNAME',3,false,$role->shortname));
+
+
+        // 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);
+}
+?>
diff --git a/admin/roles/import.php b/admin/roles/import.php
new file mode 100644
index 0000000..5844e97
--- /dev/null
+++ b/admin/roles/import.php
@@ -0,0 +1,170 @@
+<?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':
+
+            // um papel que deve ser criado com um novo nome
+
+            if (!array_key_exists($role->shortname, $USER->role_import['to_create'])) {
+                print_error('new_shortname_undefined');
+            }
+
+            // 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
+
+            $new_role_id = create_role(addslashes($currentfullname),
+                                       $USER->role_import['to_create'][$role->shortname],
+                                       '');
+            foreach ($role->capabilities as $capability) {
+
+                $roleinfo = new object();
+                $roleinfo = (object)$capability;
+                $roleinfo->contextid = $sitecontext->id;
+                $roleinfo->capability = $capability->name;
+                $roleinfo->roleid = $new_role_id;
+
+                insert_record('role_capabilities', $roleinfo);
+            }
+            $r = new object;
+            $r->new = $USER->role_import['to_create'][$role->shortname];
+            $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');
+            }
+
+            // primeiramente remover o papel original
+            if ($id = get_field('role', 'id', 'shortname', $USER->role_import['to_replace'][$role->shortname])) {
+                delete_role($id);
+            }
+
+            // 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
+
+            // e agora criar o papel novo com as capabilities
+            $new_role_id = create_role(addslashes($currentfullname),
+                                       $USER->role_import['to_replace'][$role->shortname],
+                                       '');
+            foreach ($role->capabilities as $capability) {
+
+                $roleinfo = new object();
+                $roleinfo = (object)$capability;
+                $roleinfo->contextid = $sitecontext->id;
+                $roleinfo->capability = $capability->name;
+                $roleinfo->roleid = $new_role_id;
+
+                insert_record('role_capabilities', $roleinfo);
+            }
+
+            $r = new object();
+            $r->new = $role->shortname;
+            $r->replaced = $USER->role_import['to_replace'][$role->shortname];
+            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();
+?>
diff --git a/admin/roles/import_export.php b/admin/roles/import_export.php
new file mode 100644
index 0000000..e3609c3
--- /dev/null
+++ b/admin/roles/import_export.php
@@ -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();
+?>
diff --git a/admin/roles/import_overview.php b/admin/roles/import_overview.php
new file mode 100644
index 0000000..bc97e65
--- /dev/null
+++ b/admin/roles/import_overview.php
@@ -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();
+?>
diff --git a/admin/roles/managetabs.php b/admin/roles/managetabs.php
index 170f315..cf8aa2b 100755
--- a/admin/roles/managetabs.php
+++ b/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 a/admin/roles/pre_import.php b/admin/roles/pre_import.php
new file mode 100644
index 0000000..05929cf
--- /dev/null
+++ b/admin/roles/pre_import.php
@@ -0,0 +1,67 @@
+<?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');
+        }
+    }
+}
+
+$default_roles = "{$CFG->notloggedinroleid}, {$CFG->guestroleid}, {$CFG->defaultuserroleid}, {$CFG->defaultcourseroleid}";
+$sql = "SELECT id, name, shortname
+          FROM {$CFG->dbname}.{$CFG->prefix}role
+         WHERE id NOT IN (1, {$default_roles})";
+$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 a/lang/en_utf8/role.php b/lang/en_utf8/role.php
index 1d05518..96cc7c0 100644
--- a/lang/en_utf8/role.php
+++ b/lang/en_utf8/role.php
@@ -10,6 +10,7 @@ $string['allsiteusers'] = 'All site users';
 $string['assignroles'] = 'Assign roles';
 $string['assignrolesin'] = 'Assign roles in $a';
 $string['assignglobalroles'] = 'Assign system roles';
+$string['as_new'] = '$a->original as $a->new';
 $string['blog:create'] = 'Create new blog entries';
 $string['blog:manageentries'] = 'Edit and manage entries';
 $string['blog:manageofficialtags'] = 'Manage official tags';
@@ -27,6 +28,7 @@ $string['category:manage'] = 'Manage categories';
 $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';
@@ -57,6 +59,7 @@ $string['course:viewscales'] = 'View scales';
 $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';
@@ -82,9 +85,22 @@ $string['errorbadrolename'] = 'Incorrect role name';
 $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';
+$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';
@@ -104,13 +120,20 @@ $string['overridepermissions'] = 'Override permissions';
 $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';
@@ -124,6 +147,7 @@ $string['question:useall'] = 'Use all questions';
 $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).';
@@ -137,8 +161,12 @@ $string['role:safeoverride'] = 'Override safe permissions for others';
 $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.';
@@ -162,10 +190,14 @@ $string['site:uploadusers'] = 'Upload new users from file';
 $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';
@@ -181,6 +213,7 @@ $string['user:viewuseractivitiesreport'] = 'See user activity reports';
 $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 a/lib/datalib.php b/lib/datalib.php
index 8276a87..49a6401 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1944,7 +1944,6 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
         $subject = 'Insert into log failed at your moodle site '.$site->fullname;
         $message = "Insert into log table failed at ". date('l dS \of F Y h:i:s A') .".\n It is possible that your disk is full.\n\n";
         $message .= "The failed SQL is:\n\n" . $sql;
-        $message .= "\n\nThe error message is:\n\n" . $db->ErrorMsg();
 
         // email_to_user is not usable because email_to_user tries to write to the logs table,
         // and this will get caught in an infinite loop, if disk is full
diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css
index 1900461..a5a50de 100644
--- a/theme/standard/styles_layout.css
+++ b/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;
 }
