table_column("survey_answers", "answer2", "answer2", "text", "", "", "");
}
+ if ($oldversion < 2004021900) {
+ modify_database("", "INSERT INTO prefix_log_display VALUES ('survey', 'add', 'survey', 'name');");
+ modify_database("", "INSERT INTO prefix_log_display VALUES ('survey', 'update', 'survey', 'name');");
+ }
+
return true;
}
# Dumping data for table `log_display`\r
#\r
\r
+INSERT INTO prefix_log_display VALUES ('survey', 'add', 'survey', 'name');\r
+INSERT INTO prefix_log_display VALUES ('survey', 'update', 'survey', 'name');\r
INSERT INTO prefix_log_display VALUES ('survey', 'download', 'survey', 'name');\r
INSERT INTO prefix_log_display VALUES ('survey', 'view form', 'survey', 'name');\r
INSERT INTO prefix_log_display VALUES ('survey', 'view graph', 'survey', 'name');\r
table_column("survey_answers", "answer1", "answer1", "text", "", "", "");
table_column("survey_answers", "answer2", "answer2", "text", "", "", "");
}
+ if ($oldversion < 2004021900) {
+ modify_database("", "INSERT INTO prefix_log_display VALUES ('survey', 'add', 'survey', 'name');");
+ modify_database("", "INSERT INTO prefix_log_display VALUES ('survey', 'update', 'survey', 'name');");
+ }
return true;
}
# Dumping data for table log_display
#
+INSERT INTO prefix_log_display VALUES ('survey', 'add', 'survey', 'name');
+INSERT INTO prefix_log_display VALUES ('survey', 'update', 'survey', 'name');
INSERT INTO prefix_log_display VALUES ('survey', 'download', 'survey', 'name');
INSERT INTO prefix_log_display VALUES ('survey', 'view form', 'survey', 'name');
INSERT INTO prefix_log_display VALUES ('survey', 'view graph', 'survey', 'name');
}
$streditingasurvey = get_string("editingasurvey", "survey");
+ $strsurveys = get_string("modulenameplural", "survey");
print_header("$course->shortname: $streditingasurvey", "$course->fullname",
- "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
- -> $streditingasurvey");
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>".
+ " -> <a href=\"index.php?id=$course->id\">$strsurveys</a>".
+ " -> $form->name ($streditingasurvey)");
if (!$form->name or !$form->template) {
error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
require_variable($id); // Course Module ID
optional_variable($type, "xls");
+ optional_variable($group, 0);
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
error("Survey ID was incorrect");
}
- add_to_log($course->id, "survey", "download", "download.php?id=$cm->id&type=$type", "$survey->id");
+ add_to_log($course->id, "survey", "download", "download.php?id=$cm->id&type=$type", "$survey->id", $cm->id);
+/// Check to see if groups are being used in this survey
+
+ $groupmode = groupmode($course, $cm); // Groups are being used
+
+ if ($groupmode and $group) {
+ $users = get_users_in_group($group);
+ } else {
+ $users = get_course_users($course->id);
+ $group = false;
+ }
// Get all the questions and their proper order
}
foreach ($aaa as $a) {
- if (!$results["$a->userid"]) { // init new array
- $results["$a->userid"]["time"] = $a->time;
- foreach ($order as $key => $qid) {
- $results["$a->userid"]["$qid"]["answer1"] = "";
- $results["$a->userid"]["$qid"]["answer2"] = "";
+ if (!$group or isset($users[$a->userid])) {
+ if (!$results["$a->userid"]) { // init new array
+ $results["$a->userid"]["time"] = $a->time;
+ foreach ($order as $key => $qid) {
+ $results["$a->userid"]["$qid"]["answer1"] = "";
+ $results["$a->userid"]["$qid"]["answer2"] = "";
+ }
}
+ $results["$a->userid"]["$a->question"]["answer1"] = $a->answer1;
+ $results["$a->userid"]["$a->question"]["answer2"] = $a->answer2;
}
- $results["$a->userid"]["$a->question"]["answer1"] = $a->answer1;
- $results["$a->userid"]["$a->question"]["answer2"] = $a->answer2;
}
// Output the file as a valid Excel spreadsheet if required
require_variable($id); // Course Module ID
require_variable($type); // Graph Type
+ optional_variable($group, "0"); // Group ID
optional_variable($sid); // Student ID
if (! $cm = get_record("course_modules", "id", $id)) {
require_login($course->id);
- if (!isteacher($course->id) && !isadmin()) {
- if (! ($type == "student.png" && $sid == $USER->id) ) {
+ $groupmode = groupmode($course, $cm); // Groups are being used
+
+ if (!isteacher($course->id)) {
+ if ($type != "student.png" or $sid != $USER->id ) {
+ error("Sorry, you aren't allowed to see this.");
+ } else if ($groupmode and !ismember($group)) {
error("Sorry, you aren't allowed to see this.");
}
}
error("Survey ID was incorrect");
}
+/// Check to see if groups are being used in this survey
+ if ($groupmode and $group) {
+ $users = get_users_in_group($group);
+ } else {
+ $users = get_course_users($course->id);
+ $group = false;
+ }
+
$stractual = get_string("actual", "survey");
$stractualclass = get_string("actualclass", "survey");
$stractualstudent = get_string("actualstudent", "survey", $course->student);
if ($aaa = get_records_select("survey_answers", "survey = '$cm->instance' AND question = '$qid'")) {
foreach ($aaa as $aa) {
- if ($a1 = $aa->answer1) {
- $buckets1[$a1 - 1]++;
- }
- if ($a2 = $aa->answer2) {
- $buckets2[$a2 - 1]++;
+ if (!$group or isset($users[$aa->userid])) {
+ if ($a1 = $aa->answer1) {
+ $buckets1[$a1 - 1]++;
+ }
+ if ($a2 = $aa->answer2) {
+ $buckets2[$a2 - 1]++;
+ }
}
}
}
if ($aaa) {
foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->answer1) {
- $buckets1[$index] += $a->answer1;
- $count1[$index]++;
- }
- if ($a->answer2) {
- $buckets2[$index] += $a->answer2;
- $count2[$index]++;
+ if (!$group or isset($users[$a->userid])) {
+ $index = $indexof[$a->question];
+ if ($a->answer1) {
+ $buckets1[$index] += $a->answer1;
+ $count1[$index]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$index] += $a->answer2;
+ $count2[$index]++;
+ }
}
}
}
if ($aaa) {
foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$index]);
- $stdev1[$index] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$index]);
- $stdev2[$index] += ($difference * $difference);
+ if (!$group or isset($users[$a->userid])) {
+ $index = $indexof[$a->question];
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$index]);
+ $stdev1[$index] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$index]);
+ $stdev2[$index] += ($difference * $difference);
+ }
}
}
}
if ($aaa) {
foreach ($aaa as $a) {
- if ($a->answer1) {
- $buckets1[$i] += $a->answer1;
- $count1[$i]++;
- }
- if ($a->answer2) {
- $buckets2[$i] += $a->answer2;
- $count2[$i]++;
+ if (!$group or isset($users[$a->userid])) {
+ if ($a->answer1) {
+ $buckets1[$i] += $a->answer1;
+ $count1[$i]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$i] += $a->answer2;
+ $count2[$i]++;
+ }
}
}
}
// Calculate the standard devaiations
if ($aaa) {
foreach ($aaa as $a) {
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$i]);
- $stdev1[$i] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$i]);
- $stdev2[$i] += ($difference * $difference);
+ if (!$group or isset($users[$a->userid])) {
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$i]);
+ $stdev1[$i] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$i]);
+ $stdev2[$i] += ($difference * $difference);
+ }
}
}
}
if ($aaa) {
foreach ($aaa as $a) {
- if ($a->userid == $sid) {
+ if (!$group or isset($users[$a->userid])) {
+ if ($a->userid == $sid) {
+ if ($a->answer1) {
+ $studbuckets1[$i] += $a->answer1;
+ $studcount1[$i]++;
+ }
+ if ($a->answer2) {
+ $studbuckets2[$i] += $a->answer2;
+ $studcount2[$i]++;
+ }
+ }
if ($a->answer1) {
- $studbuckets1[$i] += $a->answer1;
- $studcount1[$i]++;
+ $buckets1[$i] += $a->answer1;
+ $count1[$i]++;
}
if ($a->answer2) {
- $studbuckets2[$i] += $a->answer2;
- $studcount2[$i]++;
+ $buckets2[$i] += $a->answer2;
+ $count2[$i]++;
}
}
- if ($a->answer1) {
- $buckets1[$i] += $a->answer1;
- $count1[$i]++;
- }
- if ($a->answer2) {
- $buckets2[$i] += $a->answer2;
- $count2[$i]++;
- }
}
}
// Calculate the standard devaiations
foreach ($aaa as $a) {
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$i]);
- $stdev1[$i] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$i]);
- $stdev2[$i] += ($difference * $difference);
+ if (!$group or isset($users[$a->userid])) {
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$i]);
+ $stdev1[$i] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$i]);
+ $stdev2[$i] += ($difference * $difference);
+ }
}
}
if ($aaa) {
foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->userid == $sid) {
- if ($a->answer1) {
- $studbuckets1[$index] += $a->answer1;
- $studcount1[$index]++;
- }
- if ($a->answer2) {
- $studbuckets2[$index] += $a->answer2;
- $studcount2[$index]++;
+ if (!$group or isset($users[$a->userid])) {
+ $index = $indexof[$a->question];
+ if ($a->userid == $sid) {
+ if ($a->answer1) {
+ $studbuckets1[$index] += $a->answer1;
+ $studcount1[$index]++;
+ }
+ if ($a->answer2) {
+ $studbuckets2[$index] += $a->answer2;
+ $studcount2[$index]++;
+ }
}
+ if ($a->answer1) {
+ $buckets1[$index] += $a->answer1;
+ $count1[$index]++;
+ }
+ if ($a->answer2) {
+ $buckets2[$index] += $a->answer2;
+ $count2[$index]++;
}
- if ($a->answer1) {
- $buckets1[$index] += $a->answer1;
- $count1[$index]++;
- }
- if ($a->answer2) {
- $buckets2[$index] += $a->answer2;
- $count2[$index]++;
}
}
}
}
foreach ($aaa as $a) {
- $index = $indexof[$a->question];
- if ($a->answer1) {
- $difference = (float) ($a->answer1 - $buckets1[$index]);
- $stdev1[$index] += ($difference * $difference);
- }
- if ($a->answer2) {
- $difference = (float) ($a->answer2 - $buckets2[$index]);
- $stdev2[$index] += ($difference * $difference);
+ if (!$group or isset($users[$a->userid])) {
+ $index = $indexof[$a->question];
+ if ($a->answer1) {
+ $difference = (float) ($a->answer1 - $buckets1[$index]);
+ $stdev1[$index] += ($difference * $difference);
+ }
+ if ($a->answer2) {
+ $difference = (float) ($a->answer2 - $buckets2[$index]);
+ $stdev2[$index] += ($difference * $difference);
+ }
}
}
AND u.id = '$log->userid'");
}
-function survey_get_responses($survey) {
+function survey_get_responses($surveyid, $groupid) {
global $CFG;
+
+ if ($groupid) {
+ $groupsql = "AND gm.groupid = $groupid AND u.id = gm.userid";
+ } else {
+ $groupsql = "";
+ }
+
return get_records_sql("SELECT MAX(a.time) as time,
count(*) as numanswers,
u.id, u.firstname, u.lastname, u.picture
FROM {$CFG->prefix}survey_answers AS a,
- {$CFG->prefix}user AS u
- WHERE a.survey = $survey
- AND a.userid = u.id
+ {$CFG->prefix}user AS u,
+ {$CFG->prefix}groups_members AS gm
+ WHERE a.survey = $surveyid
+ AND a.userid = u.id $groupsql
GROUP BY u.id, u.firstname, u.lastname
ORDER BY time ASC");
}
}
-function survey_get_user_answers($surveyid, $questionid, $sort="sa.answer1,sa.answer2 ASC") {
+function survey_get_user_answers($surveyid, $questionid, $groupid, $sort="sa.answer1,sa.answer2 ASC") {
global $CFG;
+ if ($groupid) {
+ $groupsql = "AND gm.groupid = $groupid AND u.id = gm.userid";
+ } else {
+ $groupsql = "";
+ }
+
return get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture
FROM {$CFG->prefix}survey_answers sa,
- {$CFG->prefix}user u
+ {$CFG->prefix}user u,
+ {$CFG->prefix}groups_members gm
WHERE sa.survey = '$surveyid'
AND sa.question = $questionid
- AND u.id = sa.userid
+ AND u.id = sa.userid $groupsql
ORDER BY $sort");
}
return record_exists("survey_answers", "survey", $survey, "userid", $user);
}
-function survey_count_responses($survey) {
- if ($responses = survey_get_responses($survey)) {
+function survey_count_responses($surveyid, $groupid) {
+ if ($responses = survey_get_responses($surveyid, $groupid)) {
return count($responses);
} else {
return 0;
echo "(".get_string("gdneed").")";
} else {
- echo "<IMG HEIGHT=\"$SURVEY_GHEIGHT\" WIDTH=\"$SURVEY_GWIDTH\" BORDER=1".
- " SRC=\"$CFG->wwwroot/mod/survey/graph.php?$url\">";
+ echo "<img height=\"$survey_gheight\" width=\"$survey_gwidth\" border=\"1\"".
+ " src=\"$CFG->wwwroot/mod/survey/graph.php?$url\">";
}
}
// Check that all the parameters have been provided.
- require_variable($id); // Course Module ID
- optional_variable($action, "students"); // What to look at
+ require_variable($id); // Course Module ID
+ optional_variable($action, ""); // What to look at
+ optional_variable($qid, "0"); // Question id
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
"", "", true,
update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm));
+/// Check to see if groups are being used in this survey
+ if ($groupmode = groupmode($course, $cm)) { // Groups are being used
+ $currentgroup = setup_and_print_groups($course, $groupmode,
+ "report.php?id=$cm->id&action=$action&qid=$qid");
+ } else {
+ $currentgroup = 0;
+ }
+
+ if ($currentgroup) {
+ $users = get_users_in_group($currentgroup);
+ } else {
+ $users = get_course_users($course->id);
+ }
+
print_simple_box_start("center");
if ($showscales) {
echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
+ if (empty($action)) {
+ $action = "summary";
+ }
} else {
echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
+ if (empty($action)) {
+ $action = "questions";
+ }
}
print_simple_box_end();
case "summary":
print_heading($strsummary);
- if (survey_count_responses($survey->id)) {
+ if (survey_count_responses($survey->id, $currentgroup)) {
echo "<p align=center><a href=\"report.php?action=scales&id=$id\">";
- survey_print_graph("id=$id&type=overall.png");
+ survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
echo "</a>";
} else {
echo "<p align=center>".get_string("nobodyyet","survey")."</p>";
continue;
}
echo "<p align=center><a title=\"$strseemoredetail\" href=report.php?action=questions&id=$id&qid=$question->multi>";
- survey_print_graph("id=$id&qid=$question->id&type=multiquestion.png");
+ survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
echo "</a></p><br>";
}
}
if ($subquestion->type > 0) {
echo "<p align=center>";
echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
- survey_print_graph("id=$id&qid=$subquestion->id&type=question.png");
+ survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
echo "</a></p>";
}
}
} else if ($question->type > 0 ) {
echo "<p align=center>";
echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
- survey_print_graph("id=$id&qid=$question->id&type=question.png");
+ survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
echo "</a></p>";
} else {
$contents = '<table cellpadding="15" width="100%">';
- if ($aaa = survey_get_user_answers($survey->id, $question->id, "sa.time ASC")) {
+ if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup, "sa.time ASC")) {
foreach ($aaa as $a) {
$contents .= "<tr>";
$contents .= '<td nowrap="nowrap" width="10%" valign="top">'.fullname($a).'</td>';
$table->align = array ("left", "left", "left", "left", "right");
$table->size = array (35, "", "", "", "");
- if ($aaa = survey_get_user_answers($survey->id, $question->id)) {
+ if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup)) {
foreach ($aaa as $a) {
if ($a->answer1) {
$answer1 = "$a->answer1 - ".$answers[$a->answer1 - 1];
print_heading(get_string("analysisof", "survey", "$course->students"));
- if (! $results = survey_get_responses($survey->id) ) {
+ if (! $results = survey_get_responses($survey->id, $currentgroup) ) {
notify(get_string("nobodyyet","survey"));
} else {
survey_print_all_responses($cm->id, $results, $course->id);
echo '<center>';
$options["id"] = "$cm->id";
$options["type"] = "xls";
+ $options["group"] = $currentgroup;
print_single_button("download.php", $options, get_string("downloadexcel", "survey"));
$options["type"] = "txt";
$strsurveysaved = get_string("surveysaved", "survey");
print_header("$course->shortname: $strsurveysaved", "$course->fullname",
- "<A HREF=/course/view.php?id=$course->id>$course->shortname</A> ->
- <A HREF=index.php?id=$course->id>$strsurveys</A> -> $survey->name -> $strsurveysaved", "");
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
+ <a href=\"index.php?id=$course->id\">$strsurveys</a> -> $survey->name -> $strsurveysaved", "");
notice(get_string("thanksforanswers","survey", $USER->firstname), "$CFG->wwwroot/course/view.php?id=$course->id");
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004021602;
+$module->version = 2004021900;
$module->requires = 2004013101; // Requires this Moodle version
$module->cron = 0;
"$navigation <A HREF=index.php?id=$course->id>$strsurveys</A> -> $survey->name", "", "", true,
update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm));
+/// Check to see if groups are being used in this survey
+ if ($groupmode = groupmode($course, $cm)) { // Groups are being used
+ $currentgroup = get_current_group($course->id);
+ } else {
+ $currentgroup = 0;
+ }
+
+ if (isteacheredit($course->id) or ($groupmode == VISIBLEGROUPS)) {
+ $currentgroup = 0;
+ }
+
if (isteacher($course->id)) {
- $numusers = survey_count_responses($survey->id);
+ $numusers = survey_count_responses($survey->id, $currentgroup);
echo "<p align=right><a href=\"report.php?id=$cm->id\">".
get_string("viewsurveyresponses", "survey", $numusers)."</A></P>";
} else if (!$cm->visible) {
if (survey_already_done($survey->id, $USER->id)) {
add_to_log($course->id, "survey", "view graph", "view.php?id=$cm->id", $survey->id, $cm->id);
- $numusers = survey_count_responses($survey->id);
+ $numusers = survey_count_responses($survey->id, $currentgroup);
if ($showscales) {
print_heading(get_string("surveycompleted", "survey"));
print_heading(get_string("peoplecompleted", "survey", $numusers));
echo "<center>";
- survey_print_graph("id=$cm->id&sid=$USER->id&type=student.png");
+ survey_print_graph("id=$cm->id&sid=$USER->id&group=$currentgroup&type=student.png");
echo "</center>";
} else {