$position = $PARSER->required_param('position', PARAM_INT);
//the id of the reportfield used when editing
$move = $PARSER->required_param('move', PARAM_INT);
// instantiate the db
$dbc = new ilp_db();
//change field position
$reportfields = $dbc->get_report_fields_by_position($report_id, $position, $move);
$movesuc = true;
//loop through fields returned
if (!empty($reportfields)) {
    foreach ($reportfields as $field) {
        if ($field->id != $reportfield_id) {
            //if the field is being moved up all other fields have postion value increased
            //if the field is being moved down all other fields have postion value decreased
            //move up = 1 move down = 0
            $newposition = empty($move) ? $field->position - 1 : $field->position + 1;
        } else {
            //move the field
            $newposition = !empty($move) ? $field->position - 1 : $field->position + 1;
        }
        if (!$dbc->set_new_position($field->id, $newposition)) {
            $movesuc = false;
        }
    }
} else {
    $movesuc = false;
}
$resulttext = !empty($movesuc) ? get_string("fieldmovesuc", 'block_ilp') : get_string("fieldmoveerror", 'block_ilp');
//$return_url = $CFG->wwwroot.'/blocks/ilp/actions/edit_prompt.php?report_id='.$report_id.'&course_id='.$course_id;
$return_url = $CFG->wwwroot . '/blocks/ilp/actions/edit_prompt.php?report_id=' . $report_id;
redirect($return_url, $resulttext, ILP_REDIRECT_DELAY);
    // include the moodle form for this table
    include_once "{$CFG->dirroot}/blocks/ilp/classes/form_elements/plugins/{$classname}.php";
    if (!class_exists($classname)) {
        print_error('noclassforplugin', 'block_ilp', '', $pluginrecord->name);
    }
    $pluginclass = new $classname();
    $deletedposition = $reportfield->position;
    if ($pluginclass->delete_form_element($reportfield_id)) {
        $resulttext = get_string('formelementdeletesuc', 'block_ilp');
        //we now need to change the positions of all fields in the report move everything under the deleted position up
        $reportfields = $dbc->get_report_fields_by_position($report_id);
        //loop through fields returned
        if (!empty($reportfields)) {
            foreach ($reportfields as $field) {
                if ($field->position > $deletedposition) {
                    //if the field is being moved up all other fields have postion value increased
                    //if the field is being moved down all other fields have postion value decreased
                    //move up = 1 move down = 0
                    if (!$dbc->set_new_position($field->id, $field->position - 1)) {
                    }
                }
            }
        }
    } else {
        $resulttext = get_string('formelementdeleteerror', 'block_ilp');
    }
} else {
    $resulttext = get_string('formelementdeleteerror', 'block_ilp');
}
$return_url = $CFG->wwwroot . '/blocks/ilp/actions/edit_prompt.php?report_id=' . $report_id;
redirect($return_url, $resulttext, ILP_REDIRECT_DELAY);