]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20901 fixed input validation
authorPetr Skoda <skodak@moodle.org>
Sat, 21 Nov 2009 15:16:09 +0000 (15:16 +0000)
committerPetr Skoda <skodak@moodle.org>
Sat, 21 Nov 2009 15:16:09 +0000 (15:16 +0000)
mod/choice/lib.php
mod/choice/view.php

index b6029fdf775f5116b3ae1570fb64c6e401ade81f..6bf3e6f9f70d95ccd8b13eb27ce67e41d764d36f 100644 (file)
@@ -288,6 +288,7 @@ function choice_show_form($choice, $user, $cm, $allresponses) {
     //show save choice button
     echo '<div class="button">';
     echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
+    echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
     if (has_capability('mod/choice:choose', $context, $user->id, false)) { //don't show save button if the logged in user is the guest user.
         if ($choicefull) {
             print_string('choicefull', 'choice');
@@ -296,7 +297,7 @@ function choice_show_form($choice, $user, $cm, $allresponses) {
             echo "<input type=\"submit\" value=\"".get_string("savemychoice","choice")."\" />";
         }
         if ($choice->allowupdate && $aaa = $DB->get_record('choice_answers', 'choiceid', $choice->id, 'userid', $user->id)) {
-            echo "<br /><a href='view.php?id=".$cm->id."&amp;action=delchoice'>".get_string("removemychoice","choice")."</a>";
+            echo "<br /><a href='view.php?id=".$cm->id."&amp;action=delchoice&amp;sesskey=".sesskey()."'>".get_string("removemychoice","choice")."</a>";
         }
     } else {
         print_string('havetologin', 'choice');
index c951db2f5eee958a14587798e9186830a39deb39..9c37459dca26580b048d82f83ff7107bb9270bd4 100644 (file)
@@ -35,7 +35,7 @@
         print_error('badcontext');
     }
 
-    if ($action == 'delchoice') {
+    if ($action == 'delchoice' and confirm_sesskey() and has_capability('mod/choice:choose', $context) and $choice->allowupdate) {
         if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
             //print_object($answer);
             $DB->delete_records('choice_answers', array('id' => $answer->id));
@@ -47,7 +47,7 @@
     echo $OUTPUT->header();
 
 /// Submit any new data if there is any
-    if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) {
+    if ($form = data_submitted() && has_capability('mod/choice:choose', $context) && confirm_sesskey()) {
         $timenow = time();
         if (has_capability('mod/choice:deleteresponses', $context)) {
             if ($action == 'delete') { //some responses need to be deleted