<?php

/**
* Module Brainstorm V2
* Operator : order
* @author Valery Fremaux
* @package Brainstorm
* @date 20/12/2007
*/
include_once $CFG->dirroot . "/mod/brainstorm/operators/{$page}/locallib.php";
include_once "{$CFG->dirroot}/mod/brainstorm/operators/operator.class.php";
$responses = order_get_ordering($brainstorm->id, null, $currentgroup, false);
$current_operator = new BrainstormOperator($brainstorm->id, $page);
if (has_ordering_data($brainstorm->id, null, $currentgroup, false)) {
    $class = 'saved';
} else {
    $class = 'unsaved';
}
if (!@$current_operator->configdata->blindness) {
    $otherorderings = order_get_otherorderings($brainstorm->id, array_keys($responses), $currentgroup);
}
$totalspan = 4;
print_heading("<img src=\"{$CFG->wwwroot}/mod/brainstorm/operators/{$page}/pix/enabled_small.gif\" align=\"left\" width=\"40\" /> " . get_string('puttingideasinorder', 'brainstorm'));
?>
<center>
<?php 
if (isset($current_operator->configdata->requirement)) {
    print_simple_box($current_operator->configdata->requirement);
}
?>
<style>
/**
*
*
*/
function order_display(&$brainstorm, $userid, $groupid)
{
    $responses = brainstorm_get_responses($brainstorm->id, 0, $groupid, false, 'timemodified,id');
    $myordering = order_get_ordering($brainstorm->id, $userid, 0, false);
    ?>
<center>
<style>
.match { background-color : #54DE57 }
</style>
<table>
    <tr>
        <th>
            <?php 
    print_string('original', 'brainstorm');
    ?>
        </th>
        <th>
            <?php 
    print_string('myordering', 'brainstorm');
    ?>
        </th>
    </tr>
    <tr>
        <td>
<?php 
    if ($responses) {
        $i = 0;
        echo '<table cellspacing="10">';
        $myorderingkeys = array_keys($myordering);
        foreach ($responses as $response) {
            $matchclass = $response->id == @$myorderingkeys[$i] ? 'match' : '';
            ?>
                <tr>
                    <th class="<?php 
            echo $matchclass;
            ?>
">
                        <?php 
            echo $i + 1;
            ?>
.
                    </th>
                    <td>
                        <?php 
            echo $response->response;
            ?>
                    </td>
                </tr>
<?php 
            $i++;
        }
        echo '</table>';
    } else {
        print_simple_box(get_string('noresponses', 'brainstorm'));
    }
    ?>
        </td>
        <td>
<?php 
    if ($myordering) {
        $i = 0;
        echo '<table cellspacing="10">';
        $responsekeys = array_keys($responses);
        foreach ($myordering as $response) {
            $matchclass = $response->id == @$responsekeys[$i] ? 'match' : '';
            ?>
                <tr>
                    <th class="<?php 
            echo $matchclass;
            ?>
">
                        <?php 
            echo $i + 1;
            ?>
.
                    </th>
                    <td>
                        <?php 
            echo $response->response;
            ?>
                    </td>
                </tr>
<?php 
            $i++;
        }
        echo '</table>';
    } else {
        print_simple_box(get_string('noorderset', 'brainstorm'));
    }
    ?>
        </td>
    </tr>
</table>
<?php 
}