$option->id = substr($name, 9); // Get the ID of the answer that needs to be updated.
$option->text = $value;
$option->choiceid = $choice->id;
- $option->maxanswers = $choice->{'oldlimit'.substr($name, 9)};
+ if (isset($choice->{'oldlimit'.substr($name, 9)})) {
+ $option->maxanswers = $choice->{'oldlimit'.substr($name, 9)};
+ }
$option->timemodified = time();
update_record("choice_options", $option);
} else { //empty old option - needs to be deleted.
if (isset($text)) { //make sure there are no dud entries in the db with blank text values.
$countanswers = (get_records("choice_answers", "optionid", $optionid));
$countans = 0;
- foreach ($countanswers as $ca) { //only return enrolled users.
- if (isstudent($cm->course, $ca->userid) or isteacher($cm->course, $ca->userid)) {
- $countans = $countans+1;
- }
- }
+ if (!empty($countanswers)) {
+ foreach ($countanswers as $ca) { //only return enrolled users.
+ if (isstudent($cm->course, $ca->userid) or isteacher($cm->course, $ca->userid)) {
+ $countans = $countans+1;
+ }
+ }
+ }
if ($countanswers) {
$countanswers = count($countanswers);
} else {
echo "</center>";
}
-function choice_user_submit_response($formanswer, $choice, $userid, $courseid) {
+function choice_user_submit_response($formanswer, $choice, $userid, $courseid, $cm) {
$current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $userid);
$newanswer = $current;
$newanswer->optionid = $formanswer;
- $newanswer->timemodified = $timenow;
+ $newanswer->timemodified = time();
if (! update_record("choice_answers", $newanswer)) {
error("Could not update your choice because of a database error");
}
- add_to_log($course->id, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id);
+ add_to_log($courseid, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id);
} else {
$newanswer = NULL;
$newanswer->choiceid = $choice->id;
if (! insert_record("choice_answers", $newanswer)) {
error("Could not save your choice");
}
- add_to_log($course->id, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
+ add_to_log($courseid, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id);
}
} else {
error("this choice is full!");
}
echo "<td align=\"center\" class=\"count\">";
$countanswers = get_records("choice_answers", "optionid", $optionid);
- $countans = 0;
- foreach ($countanswers as $ca) { //only return enrolled users.
+ $countans = 0;
+ if (!empty($countanswers)) {
+ foreach ($countanswers as $ca) { //only return enrolled users.
if (isstudent($course->id, $ca->userid) or isteacher($course->id, $ca->userid)) {
$countans = $countans+1;
}
- }
-
+ }
+ }
if ($choice->limitanswers && !$optionid==0) {
echo get_string("taken", "choice").":";
echo $countans;
$studentid=(!empty($user->idnumber) ? $user->idnumber : " ");
$myxls->write_string($row,2,$studentid);
$ug2 = '';
- foreach (user_group($course->id, $user->id) as $ug) {
- $ug2 = $ug2. $ug->name;
- }
+ $usergrp = user_group($course->id, $user->id);
+ if (!empty($usergrp)) {
+ foreach ($usergrp as $ug) {
+ $ug2 = $ug2. $ug->name;
+ }
+ }
$myxls->write_string($row,3,$ug2);
$useroption = choice_get_option_text($choice, $answers[$user->id]->optionid);
$i=0;
$row=1;
if ($users) foreach ($users as $user) {
- if (!($answers[$user->id]->optionid==0 && isadmin($user->id)) &&
+ if (!empty($answers[$user->id]) && !($answers[$user->id]->optionid==0 && isadmin($user->id)) &&
(!($answers[$user->id]->optionid==0 && isteacher($course->id, $user->id) && !(isteacheredit($course->id, $user->id)) ) ) &&
!($choice->showunanswered==0 && $answers[$user->id]->optionid==0) ) { //make sure admins and hidden teachers are not shown in not answered yet column, and not answered only shown if set in config page.
echo $user->lastname;
echo "\t".$user->firstname;
- $studentid=(($user->idnumber != "") ? $user->idnumber : " ");
+ $studentid = " ";
+ if (!empty($user->idnumber)) {
+ $studentid = $user->idnumber;
+ }
echo "\t". $studentid."\t";
$ug2 = '';
- foreach (user_group($course->id, $user->id) as $ug) {
- $ug2 = $ug2. $ug->name;
+ $usergrp = user_group($course->id, $user->id);
+ if (!empty($usergrp)) {
+ foreach ($usergrp as $ug) {
+ $ug2 = $ug2. $ug->name;
+ }
}
echo $ug2. "\t";
echo format_string(choice_get_option_text($choice, $answers[$user->id]->optionid),true). "\n";
if ($form = data_submitted()) {
$timenow = time();
- if (isteacher($course->id, $user->id)) {
+ if (isteacher($course->id, $USER->id)) {
if ($action == 'delete') { //some responses need to be deleted
$attemptids = isset($_POST['attemptid']) ? $_POST['attemptid'] : array(); //get array of repsonses to delete.
choice_delete_responses($attemptids); //delete responses.
if (empty($form->answer)) {
redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
} else {
- choice_user_submit_response($form->answer, $choice, $USER->id, $course->id);
+ choice_user_submit_response($form->answer, $choice, $USER->id, $course->id, $cm);
}
redirect("view.php?id=$cm->id");
exit;