function validation($data, $files) {
        $errors = array();

        if($file = $this->get_draft_files('importfile')){
            $file = reset($file);
            $content = $file->get_content();
            $xml = xmlize($content);
            if(empty($content)){
                $errors['importfile'] = get_string('error_emptyfile', 'report_rolesmigration');
            }else if(!$xml || !roles_migration_get_incoming_roles($xml)){
                $errors['importfile'] = get_string('error_badxml', 'report_rolesmigration');
            }
        }

        return $errors;
    }
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Performs the import from an Roles XML generated by the export roles script
 * @package   moodlerolesmigration
 * @copyright 2011 NCSU DELTA | <http://delta.ncsu.edu> and others
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
if ($roles_in_file = roles_migration_get_incoming_roles()) {
    foreach ($roles_in_file as $role) {
        if (!isset($actions[$role->shortname])) {
            echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
            continue;
        }
        switch ($actions[$role->shortname]) {
            case 'skip':
                echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
                break;
            case 'create':
                if (!array_key_exists($role->shortname, $roles['create'])) {
                    print_error('new_shortname_undefined');
                }
                $textlib = textlib_get_instance();
                $new_role_shortname = $textlib->specialtoascii($roles['create'][$role->shortname]['shortname']);
function import_config_table($xml, $roles_to_create, $actions){
    global $DB;

    // Existing roles in this installation
    $existing_roles = $DB->get_records('role');
    $incoming_roles = roles_migration_get_incoming_roles($xml);

    $table = new html_table();
    $table->attributes['class'] = 'import_form_table';
    $table->align = array('right', 'left', 'left', 'left');
    $table->wrap = array('nowrap', '', 'nowrap', 'nowrap');
    $table->data = array();
    $table->head = array(get_string('name'), get_string('shortname'),
    get_string('action'));
    if (! is_array($incoming_roles)) {
        echo get_string('no_roles_in_import', 'report_rolesmigration');
        return;
    }
    foreach ($incoming_roles as $role) {
        $row = array();
        $row[0] = $role->name;
        $row[1] = $role->shortname;

        $create_checked = (isset($actions[$role->shortname]) && 'create' == $actions[$role->shortname]) ? 'checked="checked"' : '';
        $replace_checked = (isset($actions[$role->shortname]) && 'replace' == $actions[$role->shortname]) ? 'checked="checked"' : '';
        $skip_checked = (empty($create_checked) && empty($replace_checked) ) ? 'checked="checked"' : ''; 

        $shortname_new_value = isset($roles_to_create[$role->shortname]['shortname']) ? $roles_to_create[$role->shortname]['shortname'] : $role->shortname;
        $name_new_value = isset($roles_to_create[$role->shortname]['name']) ? $roles_to_create[$role->shortname]['name'] : $role->name;

        $options = '';
        $replace_options = '';
        foreach ($existing_roles as $er) {
            if (isset($incoming_roles[$role->shortname])) {
                if ($incoming_roles[$role->shortname] == $er->shortname) {
                    $selected = ' selected="selected" ';
                }
            } elseif ($role->shortname == $er->shortname) {
                $selected = ' selected="selected" ';
            } else {
                $selected = '';
            }
            $options .= "<option {$selected} value=\"{$er->shortname}\"> {$er->name} ({$er->shortname})</option>";
        }
        $row[2] = '<ul style="list-style-type: none;">';
        $row[2] .= '<li style="list-style-type: none;">';
        $row[2] .= '<input type="radio" ' . $skip_checked . ' id="skip' . $role->id . '" name="actions[' . $role->shortname . ']" value="skip" />&nbsp;';
        $row[2] .= '<label for="skip' . $role->id . '">' . get_string('do_not_import', 'report_rolesmigration') . '</label>';
        $row[2] .= '</li>';
        $row[2] .= '<li style="list-style-type: none;">';
        $row[2] .= '<input type="radio" ' . $create_checked . ' id="create' . $role->id . '" name="actions[' . $role->shortname . ']" value="create" />&nbsp;';
        $row[2] .= '<label for="create' . $role->id . '">' . get_string('import_new', 'report_rolesmigration') . '</label>';
        $row[2] .= '<ul style="list-style-type: none;margin:0 0 0 35px;padding:0;"><li>' . get_string('shortname', 'report_rolesmigration') . ': <input type="text" name="to_create[' . $role->shortname . '][shortname]" value="' . $shortname_new_value . '" /></li>';
        $row[2] .= '<li>' . get_string('name', 'report_rolesmigration') . ': <input type="text" name="to_create[' . $role->shortname . '][name]" value="' . $name_new_value . '" /></li></ul>';
        $row[2] .= '</li>';
        $row[2] .= '<li style="list-style-type: none;">';
        $row[2] .= '<input type="radio" ' . $replace_checked . ' id="replace' . $role->id . '" name="actions[' . $role->shortname . ']" value="replace" />&nbsp;';
        $row[2] .= '<label for="replace' . $role->id . '">' . get_string('import_replacing', 'report_rolesmigration') . '</label>';
        $row[2] .= '<select name="to_replace[' . $role->shortname . ']" >' . $options . '</select>';
        $row[2] .= '</li>';
        $row[2] .= '</ul>';
        $table->data[] = $row;
    }

    return $table;
}