Index: mod/choice/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/lib.php,v
retrieving revision 1.59.2.29
diff -u -r1.59.2.29 lib.php
--- mod/choice/lib.php	22 Nov 2009 11:09:31 -0000	1.59.2.29
+++ mod/choice/lib.php	21 Jun 2010 14:10:04 -0000
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php // $Id: lib.php,v 1.59.2.27 2009-03-26 21:24:07 danmarsden Exp $
 
 $COLUMN_HEIGHT = 300;
 
@@ -385,8 +385,11 @@
                 echo "<table class=\"choiceresponse\"><tr><td></td></tr>";
                 if (!empty($allresponses[0])) {
                     foreach ($allresponses[0] as $user) {
-                        echo "<tr>";
-                        echo "<td class=\"picture\">";
+                        echo '<tr><td class="attemptcell">';
+                        if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) {
+                            echo '<input type="checkbox" name="attemptid[]" value="'. $user->id. '" />';
+                        }
+                        echo '</td><td class="picture">';
                         print_user_picture($user->id, $course->id, $user->picture);
                         echo "</td><td class=\"fullname\">";
                         echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">";
@@ -456,7 +463,19 @@
                 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'quiz').'</a> / ';
                 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'quiz').'</a> ';
                 echo '&nbsp;&nbsp;';
-                $options = array('delete' => get_string('delete'));
+                $options = array();
+                foreach (array_keys($choice->option) as $optionid) {
+                    // Check if target is full
+                    $choice_option = get_record("choice_options", "id", $optionid);
+                    $noofchosen = count_records('choice_answers', 'optionid', $optionid);
+                    if ($choice->limitanswers && ($noofchosen >= $choice_option->maxanswers)) {
+                        $fullup = ' ' . get_string('full', 'choice');
+                    } else {
+                        $fullup = '';
+                    }
+                    $options[$optionid] = get_string('moveto', 'choice') . ': ' . $choice->option[$optionid] . $fullup;
+                }
+                $options = array('delete' => get_string('delete')) + $options;
                 echo choose_from_menu($options, 'action', '', get_string('withselected', 'quiz'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
                 echo '<noscript id="noscriptmenuaction" style="display: inline;">';
                 echo '<div>';
@@ -581,6 +600,45 @@
 }
 
 
+function choice_move_responses($attemptids, $choiceid, $newoptionid) {
+
+    if(!is_array($attemptids) || empty($attemptids)) {
+        return false;
+    }
+
+    foreach($attemptids as $num => $attemptid) {
+        if(empty($attemptid)) {
+            unset($attemptids[$num]);
+        }
+    }
+
+    // Remove the choice, change the option chosen, and put it back
+    foreach($attemptids as $attemptid) {
+        // Get maximum number of answers allowed for this option
+        $choice = get_record('choice', 'id', $choiceid);
+        $option = get_record('choice_options', 'id', $newoptionid);
+        $noofchosen = count_records('choice_answers', 'optionid', $newoptionid);
+        // Only move if there is room in the target option
+        if (!$choice->limitanswers || ($noofchosen < $option->maxanswers)) {
+            if ($tomove = get_record('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid)) {
+                delete_records('choice_answers', 'choiceid', $choiceid, 'userid', $attemptid);
+                $tomove->optionid = $newoptionid;
+                insert_record('choice_answers', $tomove);
+            } else {
+                // Moving from 'unanswered', so insert a new record
+                $newanswer = NULL;
+                $newanswer->choiceid = $choiceid;
+                $newanswer->userid = $attemptid;
+                $newanswer->optionid = $newoptionid;
+                $newanswer->timemodified = time();
+                insert_record("choice_answers", $newanswer);
+            }
+        }
+    }
+    return true;
+}
+
+
 function choice_delete_instance($id) {
 // Given an ID of an instance of this module,
 // this function will permanently delete the instance
