$current_operator = new BrainstormOperator($brainstorm->id, $page);
$responsesnum = brainstorm_count_responses($brainstorm->id, 0, $currentgroup, false);
if (!isset($current_operator->configdata->maxideasleft)) {
    $current_operator->configdata->maxideasleft = $responsesnum;
    notice(get_string('filterlimitundefined', 'brainstorm'));
}
$unassignedresponses = merge_get_unassigned($brainstorm->id, 0, $currentgroup, false, $current_operator->configdata);
$assignations = merge_get_assignations($brainstorm->id, null, $currentgroup, false, $current_operator->configdata);
/// get currently selected status for non data moving commands
$current_target = optional_param('to', null, PARAM_INT);
if (isset($nochecks)) {
    $checks = array();
}
if (!isset($checks)) {
    // might have been setup within the controller
    $checks = array_keys(merge_get_dataset_from_query('choose_'));
}
$strsource = get_string('sourcedata', 'brainstorm');
$strmerge = get_string('mergedata', 'brainstorm');
$strchoice = get_string('choicedata', 'brainstorm');
$strmerged = get_string('mergeddata', 'brainstorm');
$toeliminate = max(0, $current_operator->configdata->maxideasleft - count($assignations));
print_heading("<img src=\"{$CFG->wwwroot}/mod/brainstorm/operators/{$page}/pix/enabled_small.gif\" align=\"left\" width=\"40\" /> " . get_string("organizing{$page}", 'brainstorm'));
?>
<center>
<?php 
$intro = isset($current_operator->configdata->requirement) ? $current_operator->configdata->requirement . '<br/>' : '';
$intro .= "<span id=\"leftcount\">" . $toeliminate . '</span> ' . get_string('responsestokeep', 'brainstorm');
print_simple_box($intro);
print_simple_box_start('center');
?>
    $oldassign = get_records_select('brainstorm_operatordata', $select, 'id,id');
    /// discard old assignation - the fastest way to do it
    if (!delete_records_select('brainstorm_operatordata', $select)) {
        // IS NOT AN ERROR ; nothing previously assigned to delete
    }
    /// restore checks
    if ($oldassign) {
        foreach ($oldassign as $assign) {
            $checks[] = $assign->id;
        }
    }
}
/********************************** saves the merged data ********************************/
if ($action == 'savemerges' || $action == 'saveandreduce') {
    $merges = merge_get_dataset_from_query('merge_');
    $choices = merge_get_dataset_from_query('choice_');
    $kept = array();
    $added = array();
    //print_object($merges);
    //print_object($choices);
    /// delete all merging data
    $sql = "\r\n        UPDATE\r\n            {$CFG->prefix}brainstorm_operatordata\r\n        SET\r\n            blobvalue = NULL,\r\n            itemdest = NULL\r\n        WHERE\r\n            brainstormid = {$brainstorm->id} AND\r\n            operatorid = 'merge' AND\r\n            groupid = {$currentgroup}\r\n    ";
    execute_sql($sql, false);
    /// saving changes, updating when necessary
    foreach ($choices as $key => $choice) {
        unset($mergerecord);
        $mergerecord->brainstormid = $brainstorm->id;
        $mergerecord->userid = $USER->id;
        $mergerecord->groupid = $currentgroup;
        $mergerecord->operatorid = 'merge';
        $mergerecord->timemodified = time();