mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Changes to use new database stuff
This commit is contained in:
parent
1d881d926b
commit
e323955db8
@ -35,7 +35,10 @@
|
||||
<TR VALIGN=top>
|
||||
<TD ALIGN=right NOWRAP>
|
||||
<P><B><? print_string("introtext", "survey") ?>:</B></P><BR>
|
||||
<? helpbutton("text", get_string("helptext")) ?>
|
||||
<font SIZE="1">
|
||||
<? helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br \>
|
||||
<? helpbutton("text", get_string("helptext"), "moodle", true, true) ?><br \>
|
||||
</font>
|
||||
</TD>
|
||||
<TD>
|
||||
<TEXTAREA NAME="intro" ROWS=20 COLS=50 WRAP="virtual"><?
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
// Get all the questions and their proper order
|
||||
|
||||
$questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
|
||||
$questions = get_records_list("survey_questions", "id", $survey->questions);
|
||||
$order = explode(",", $survey->questions);
|
||||
|
||||
foreach ($order as $key => $qid) { // Do we have virtual scales?
|
||||
@ -63,7 +63,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$fullquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($fullorderlist)");
|
||||
$fullquestions = get_records_list("survey_questions", "id", $fullorderlist);
|
||||
|
||||
// Question type of multi-questions overrides the type of single questions
|
||||
foreach ($order as $key => $qid) {
|
||||
@ -136,7 +136,7 @@
|
||||
if (! $u = get_record("user", "id", $user)) {
|
||||
error("Error finding student # $user");
|
||||
}
|
||||
if ($n = get_record_sql("SELECT * FROM survey_analysis WHERE survey='$survey->id' AND user='$user'")) {
|
||||
if ($n = get_record("survey_analysis", "survey", $survey->id, "user", $user)) {
|
||||
$notes = $n->notes;
|
||||
} else {
|
||||
$notes = "No notes made";
|
||||
@ -190,7 +190,7 @@
|
||||
// Print all the lines of data.
|
||||
|
||||
foreach ($results as $user => $rest) {
|
||||
if (! $u = get_record_sql("SELECT firstname,lastname,email,idnumber FROM user WHERE id = '$user'")) {
|
||||
if (! $u = get_record("user", "id", $user)) {
|
||||
error("Error finding student # $user");
|
||||
}
|
||||
echo $survey->id."\t";
|
||||
|
@ -51,16 +51,15 @@
|
||||
$buckets2[$key] = 0;
|
||||
}
|
||||
|
||||
$aa = $db->Execute("SELECT * FROM survey_answers WHERE survey = $cm->instance AND question = $qid");
|
||||
|
||||
while (!$aa->EOF) {
|
||||
if ($a1 = $aa->fields["answer1"]) {
|
||||
$buckets1[$a1 - 1]++;
|
||||
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 ($a2 = $aa->fields["answer2"]) {
|
||||
$buckets2[$a2 - 1]++;
|
||||
}
|
||||
$aa->MoveNext();
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +110,7 @@
|
||||
$options = explode(",",$question->options);
|
||||
$questionorder = explode( ",", $question->multi);
|
||||
|
||||
$qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
|
||||
$qqq = get_records_list("survey_questions", "id", $question->multi);
|
||||
|
||||
foreach ($questionorder as $i => $val) {
|
||||
$names[$i] = get_string($qqq["$val"]->shorttext, "survey");
|
||||
@ -122,17 +121,19 @@
|
||||
$indexof[$val] = $i;
|
||||
}
|
||||
|
||||
$aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
|
||||
$aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
|
||||
|
||||
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 ($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]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,15 +146,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
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 ($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,20 +226,24 @@
|
||||
|
||||
case "overall.png":
|
||||
|
||||
$qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
|
||||
$qqq = get_records_list("survey_questions", "id", $survey->questions);
|
||||
|
||||
foreach ($qqq as $key => $qq) {
|
||||
$qqq[$key]->text = get_string($qq->text, "survey");
|
||||
$qqq[$key]->options = get_string($qq->options, "survey");
|
||||
if ($qq->type < 0) {
|
||||
$virtualscales = true;
|
||||
if ($qq->multi) {
|
||||
$qqq[$key]->text = get_string($qq->text, "survey");
|
||||
$qqq[$key]->options = get_string($qq->options, "survey");
|
||||
if ($qq->type < 0) {
|
||||
$virtualscales = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
|
||||
if ($virtualscales && $qq->type < 0) {
|
||||
$question[] = $qq;
|
||||
} else if (!$virtualscales && $qq->type > 0) {
|
||||
$question[] = $qq;
|
||||
if ($qq->multi) {
|
||||
if ($virtualscales && $qq->type < 0) {
|
||||
$question[] = $qq;
|
||||
} else if (!$virtualscales && $qq->type > 0) {
|
||||
$question[] = $qq;
|
||||
}
|
||||
}
|
||||
}
|
||||
$numquestions = count($question);
|
||||
@ -253,16 +260,18 @@
|
||||
$count1[$i] = 0;
|
||||
$count2[$i] = 0;
|
||||
$subquestions = $question[$i]->multi; // otherwise next line doesn't work
|
||||
$aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
|
||||
$aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($subquestions)))");
|
||||
|
||||
foreach ($aaa as $a) {
|
||||
if ($a->answer1) {
|
||||
$buckets1[$i] += $a->answer1;
|
||||
$count1[$i]++;
|
||||
}
|
||||
if ($a->answer2) {
|
||||
$buckets2[$i] += $a->answer2;
|
||||
$count2[$i]++;
|
||||
if ($aaa) {
|
||||
foreach ($aaa as $a) {
|
||||
if ($a->answer1) {
|
||||
$buckets1[$i] += $a->answer1;
|
||||
$count1[$i]++;
|
||||
}
|
||||
if ($a->answer2) {
|
||||
$buckets2[$i] += $a->answer2;
|
||||
$count2[$i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,14 +283,16 @@
|
||||
}
|
||||
|
||||
// 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 ($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,20 +361,24 @@
|
||||
|
||||
case "student.png":
|
||||
|
||||
$qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
|
||||
$qqq = get_records_list("survey_questions", "id", $survey->questions);
|
||||
|
||||
foreach ($qqq as $key => $qq) {
|
||||
$qqq[$key]->text = get_string($qq->text, "survey");
|
||||
$qqq[$key]->options = get_string($qq->options, "survey");
|
||||
if ($qq->type < 0) {
|
||||
$virtualscales = true;
|
||||
if ($qq->multi) {
|
||||
$qqq[$key]->text = get_string($qq->text, "survey");
|
||||
$qqq[$key]->options = get_string($qq->options, "survey");
|
||||
if ($qq->type < 0) {
|
||||
$virtualscales = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($qqq as $qq) { // if any virtual, then use JUST virtual, else use JUST nonvirtual
|
||||
if ($virtualscales && $qq->type < 0) {
|
||||
$question[] = $qq;
|
||||
} else if (!$virtualscales && $qq->type > 0) {
|
||||
$question[] = $qq;
|
||||
if ($qq->multi) {
|
||||
if ($virtualscales && $qq->type < 0) {
|
||||
$question[] = $qq;
|
||||
} else if (!$virtualscales && $qq->type > 0) {
|
||||
$question[] = $qq;
|
||||
}
|
||||
}
|
||||
}
|
||||
$numquestions= count($question);
|
||||
@ -381,28 +396,31 @@
|
||||
$studbuckets2[$i] = 0.0;
|
||||
$studcount1[$i] = 0;
|
||||
$studcount2[$i] = 0;
|
||||
$subquestions = $question[$i]->multi; // otherwise next line doesn't work
|
||||
$aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
|
||||
|
||||
foreach ($aaa as $a) {
|
||||
if ($a->user == $sid) {
|
||||
$subquestions = $question[$i]->multi; // otherwise next line doesn't work
|
||||
$aaa = get_records_select("survey_answers","((survey = $cm->instance) AND (question in ($subquestions)))");
|
||||
|
||||
if ($aaa) {
|
||||
foreach ($aaa as $a) {
|
||||
if ($a->user == $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]++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($count1[$i]) {
|
||||
@ -510,7 +528,7 @@
|
||||
$options = explode(",",$question->options);
|
||||
$questionorder = explode( ",", $question->multi);
|
||||
|
||||
$qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
|
||||
$qqq = get_records_list("survey_questions", "id", $question->multi);
|
||||
|
||||
foreach ($questionorder as $i => $val) {
|
||||
$names[$i] = get_string($qqq[$val]->shorttext, "survey");
|
||||
@ -525,27 +543,29 @@
|
||||
$studcount2[$i] = 0;
|
||||
}
|
||||
|
||||
$aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
|
||||
$aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
|
||||
|
||||
foreach ($aaa as $a) {
|
||||
$index = $indexof[$a->question];
|
||||
if ($a->user == $sid) {
|
||||
if ($a->answer1) {
|
||||
$studbuckets1[$index] += $a->answer1;
|
||||
$studcount1[$index]++;
|
||||
}
|
||||
if ($a->answer2) {
|
||||
$studbuckets2[$index] += $a->answer2;
|
||||
$studcount2[$index]++;
|
||||
if ($aaa) {
|
||||
foreach ($aaa as $a) {
|
||||
$index = $indexof[$a->question];
|
||||
if ($a->user == $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]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ function survey_delete_instance($id) {
|
||||
}
|
||||
|
||||
function survey_user_outline($course, $user, $mod, $survey) {
|
||||
if ($answers = get_records_sql("SELECT * FROM survey_answers WHERE survey='$survey->id' AND user='$user->id'")) {
|
||||
if ($answers = get_records_select("survey_answers", "survey='$survey->id' AND user='$user->id'")) {
|
||||
|
||||
$lastanswer = array_pop($answers);
|
||||
|
||||
@ -108,9 +108,7 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
|
||||
|
||||
foreach ($logs as $log) {
|
||||
if ($log->module == "survey" and $log->action == "submit") {
|
||||
$surveys[$log->id] = get_record_sql("SELECT s.name, u.firstname, u.lastname
|
||||
FROM survey s, user u
|
||||
WHERE s.id = '$log->info' AND u.id = '$log->user'");
|
||||
$surveys[$log->id] = survey_log_info($log);
|
||||
$surveys[$log->id]->time = $log->time;
|
||||
$surveys[$log->id]->url = $log->url;
|
||||
}
|
||||
@ -132,20 +130,74 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
|
||||
}
|
||||
|
||||
|
||||
// MODULE FUNCTIONS ////////////////////////////////////////////////////////
|
||||
// SQL FUNCTIONS ////////////////////////////////////////////////////////
|
||||
|
||||
function survey_already_done($survey, $user) {
|
||||
return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'");
|
||||
|
||||
function survey_log_info($log) {
|
||||
global $CFG;
|
||||
return get_record_sql("SELECT s.name, u.firstname, u.lastname
|
||||
FROM {$CFG->prefix}survey s,
|
||||
{$CFG->prefix}user u
|
||||
WHERE s.id = '$log->info'
|
||||
AND u.id = '$log->user'");
|
||||
}
|
||||
|
||||
function survey_get_responses($survey) {
|
||||
global $CFG;
|
||||
return get_records_sql("SELECT a.time as time, count(*) as numanswers, u.*
|
||||
FROM {$CFG->prefix}survey_answers AS a,
|
||||
{$CFG->prefix}user AS u
|
||||
WHERE a.answer1 <> '0' AND a.answer2 <> '0'
|
||||
AND a.survey = $survey
|
||||
AND a.user = u.id
|
||||
GROUP BY a.user
|
||||
ORDER BY a.time ASC");
|
||||
}
|
||||
|
||||
function survey_get_analysis($survey, $user) {
|
||||
global $db, $CFG;
|
||||
|
||||
return get_record_sql("SELECT notes
|
||||
FROM {$CFG->prefix}survey_analysis
|
||||
WHERE survey='$survey'
|
||||
AND user='$user'");
|
||||
}
|
||||
|
||||
function survey_update_analysis($survey, $user, $notes) {
|
||||
global $db, $CFG;
|
||||
|
||||
return $db->Execute("UPDATE {$CFG->prefix}survey_analysis
|
||||
SET notes='$notes'
|
||||
WHERE survey='$survey'
|
||||
AND user='$user'");
|
||||
}
|
||||
|
||||
|
||||
function survey_get_responses($survey) {
|
||||
return get_records_sql("SELECT a.time as time, count(*) as numanswers, u.*
|
||||
FROM survey_answers AS a, user AS u
|
||||
WHERE a.answer1 <> '0' AND a.answer2 <> '0'
|
||||
AND a.survey = $survey
|
||||
AND a.user = u.id
|
||||
GROUP BY a.user ORDER BY a.time ASC");
|
||||
function survey_add_analysis($survey, $user, $notes) {
|
||||
global $db, $CFG;
|
||||
|
||||
return $db->Execute("INSERT INTO {$CFG->prefix}survey_analysis
|
||||
SET notes='$notes',
|
||||
survey='$survey',
|
||||
user='$user'");
|
||||
}
|
||||
|
||||
function survey_get_user_answers($surveyid, $questionid) {
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture
|
||||
FROM survey_answers sa,
|
||||
user u
|
||||
WHERE sa.survey = '$surveyid'
|
||||
AND sa.question = $questionid
|
||||
AND u.id = sa.user
|
||||
ORDER BY sa.answer1,sa.answer2 ASC");
|
||||
}
|
||||
|
||||
// MODULE FUNCTIONS ////////////////////////////////////////////////////////
|
||||
|
||||
function survey_already_done($survey, $user) {
|
||||
return record_exists("survey_answers", "survey", $survey, "user", $user);
|
||||
}
|
||||
|
||||
function survey_count_responses($survey) {
|
||||
@ -179,8 +231,8 @@ function survey_get_template_name($templateid) {
|
||||
global $db;
|
||||
|
||||
if ($templateid) {
|
||||
if ($ss = $db->Execute("SELECT name FROM surveys WHERE id = $templateid")) {
|
||||
return $ss->fields["name"];
|
||||
if ($ss = get_record("surveys", "id", $templateid)) {
|
||||
return $ss->name;
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
@ -188,24 +240,6 @@ function survey_get_template_name($templateid) {
|
||||
}
|
||||
|
||||
|
||||
function survey_get_analysis($survey, $user) {
|
||||
global $db;
|
||||
|
||||
return get_record_sql("SELECT notes from survey_analysis WHERE survey='$survey' and user='$user'");
|
||||
}
|
||||
|
||||
function survey_update_analysis($survey, $user, $notes) {
|
||||
global $db;
|
||||
|
||||
return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'");
|
||||
}
|
||||
|
||||
|
||||
function survey_add_analysis($survey, $user, $notes) {
|
||||
global $db;
|
||||
|
||||
return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'");
|
||||
}
|
||||
|
||||
function survey_shorten_name ($name, $numwords) {
|
||||
$words = explode(" ", $name);
|
||||
@ -249,7 +283,7 @@ function survey_print_multi($question) {
|
||||
}
|
||||
echo "<TD ALIGN=CENTER BGCOLOR=\"$THEME->body\"> </TD></TR>\n";
|
||||
|
||||
$subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi) ");
|
||||
$subquestions = get_records_list("survey_questions", "id", $question->multi);
|
||||
|
||||
foreach ($subquestions as $q) {
|
||||
$qnum++;
|
||||
|
@ -10,7 +10,7 @@
|
||||
<td align=right><P><B><? print_string("surveytype", "survey") ?>:</B></P></TD>
|
||||
<td>
|
||||
<?
|
||||
if ($options = get_records_sql_menu("SELECT id, name FROM survey WHERE template='0'")) {
|
||||
if ($options = get_records_menu("survey", "template", 0, "name", "id, name")) {
|
||||
foreach ($options as $id => $name) {
|
||||
$options[$id] = get_string($name, "survey");
|
||||
}
|
||||
|
@ -102,7 +102,7 @@
|
||||
case "scales":
|
||||
print_header("$survey->name: $strscales", "$strallscales");
|
||||
|
||||
$questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
|
||||
$questions = get_records_list("survey_questions", "id", $survey->questions);
|
||||
$questionorder = explode(",", $survey->questions);
|
||||
|
||||
foreach ($questionorder as $key => $val) {
|
||||
@ -132,7 +132,7 @@
|
||||
case "questions":
|
||||
|
||||
if ($qid) { // just get one multi-question
|
||||
$questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($qid)");
|
||||
$questions = get_records_list("survey_questions", "id", $qid);
|
||||
$questionorder = explode(",", $qid);
|
||||
|
||||
if ($scale = get_records("survey_questions", "multi", "$qid")) {
|
||||
@ -143,7 +143,7 @@
|
||||
}
|
||||
|
||||
} else { // get all top-level questions
|
||||
$questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
|
||||
$questions = get_records_list("survey_questions", "id", $survey->questions);
|
||||
$questionorder = explode(",", $survey->questions);
|
||||
|
||||
print_header("$survey->name: $strquestions", "$strallquestions");
|
||||
@ -167,7 +167,7 @@
|
||||
if ($question->multi) {
|
||||
echo "<H3>$question->text :</H3>";
|
||||
|
||||
$subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
|
||||
$subquestions = get_records_list("survey_questions", "id", $question->multi);
|
||||
$subquestionorder = explode(",", $question->multi);
|
||||
foreach ($subquestionorder as $key => $val) {
|
||||
$subquestion = $subquestions[$val];
|
||||
@ -183,7 +183,7 @@
|
||||
BORDER=1 SRC=\"graph.php?id=$id&qid=$question->id&type=question.png\"></A></P>";
|
||||
} else {
|
||||
echo "<H3>$question->text</H3>";
|
||||
if ($aaa = get_records_sql("SELECT sa.*, u.firstname,u.lastname FROM survey_answers sa, user u WHERE survey = '$survey->id' AND question = $question->id and sa.user = u.id")) {
|
||||
if ($aaa = survey_get_user_answers($survey->id, $question->id)) {
|
||||
echo "<UL>";
|
||||
foreach ($aaa as $a) {
|
||||
echo "<LI>$a->firstname $a->lastname: $a->answer1";
|
||||
@ -205,7 +205,6 @@
|
||||
|
||||
print_header("$survey->name: $strquestion", "$strquestion: $question->text");
|
||||
|
||||
$aaa = get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture FROM survey_answers sa, user u WHERE sa.survey = '$survey->id' AND sa.question = $question->id AND u.id = sa.user ORDER by sa.answer1,sa.answer2 ASC");
|
||||
|
||||
$strname = get_string("name", "survey");
|
||||
$strtime = get_string("time", "survey");
|
||||
@ -213,30 +212,33 @@
|
||||
$strpreferred = get_string("preferred", "survey");
|
||||
|
||||
echo "<TABLE ALIGN=center CELLPADDING=0 CELLSPACING=10><TR><TD> <TH align=left>$strname<TH align=left>$strtime<TH align=left>$stractual<TH align=left>$strpreferred</TR>";
|
||||
foreach ($aaa as $a) {
|
||||
echo "<TR>";
|
||||
echo "<TD WIDTH=35>";
|
||||
print_user_picture($a->user, $course->id, $a->picture, false);
|
||||
echo "</TD>";
|
||||
echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->user\">$a->firstname $a->lastname</A></TD>";
|
||||
echo "<TD><P>".userdate($a->time, "%d %B %Y, %I:%M %p")."</TD>";
|
||||
echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
|
||||
if ($a->answer1) {
|
||||
echo "$a->answer1 - ".$answers[$a->answer1 - 1];
|
||||
} else {
|
||||
echo " ";
|
||||
}
|
||||
echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\"><P>";
|
||||
if ($a->answer2) {
|
||||
echo "$a->answer2 - ".$answers[$a->answer2 - 1];
|
||||
} else {
|
||||
echo " ";
|
||||
}
|
||||
echo "</TD></TR>";
|
||||
|
||||
if ($aaa = survey_get_user_answers($survey->id, $question->id)) {
|
||||
foreach ($aaa as $a) {
|
||||
echo "<TR>";
|
||||
echo "<TD WIDTH=35>";
|
||||
print_user_picture($a->user, $course->id, $a->picture, false);
|
||||
echo "</TD>";
|
||||
echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->user\">$a->firstname $a->lastname</A></TD>";
|
||||
echo "<TD><P>".userdate($a->time, "%d %B %Y, %I:%M %p")."</TD>";
|
||||
echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
|
||||
if ($a->answer1) {
|
||||
echo "$a->answer1 - ".$answers[$a->answer1 - 1];
|
||||
} else {
|
||||
echo " ";
|
||||
}
|
||||
echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\"><P>";
|
||||
if ($a->answer2) {
|
||||
echo "$a->answer2 - ".$answers[$a->answer2 - 1];
|
||||
} else {
|
||||
echo " ";
|
||||
}
|
||||
echo "</TD></TR>";
|
||||
|
||||
}
|
||||
}
|
||||
echo "</TABLE>";
|
||||
|
||||
echo "</TABLE>";
|
||||
|
||||
print_footer($course);
|
||||
break;
|
||||
@ -288,7 +290,7 @@
|
||||
echo "<P ALIGN=CENTER><IMG HEIGHT=$SURVEY_GHEIGHT WIDTH=$SURVEY_GWIDTH ALIGN=CENTER SRC=\"graph.php?id=$id&sid=$student&type=student.png\"></P>";
|
||||
|
||||
// Print scales
|
||||
$questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
|
||||
$questions = get_records_list("survey_questions", "id", $survey->questions);
|
||||
$questionorder = explode(",", $survey->questions);
|
||||
|
||||
foreach ($questionorder as $key => $val) {
|
||||
|
@ -63,10 +63,15 @@
|
||||
|
||||
$timenow = time();
|
||||
foreach ($answers as $key => $val) {
|
||||
$val1 = $val[0]; $val2 = $val[1];
|
||||
if (! $result = $db->Execute("INSERT INTO survey_answers
|
||||
(time, user, survey, question, answer1, answer2)
|
||||
VALUES ('$timenow', '$USER->id', '$survey->id', '$key', '$val1', '$val2')") ) {
|
||||
|
||||
$newdata->time = $timenow;
|
||||
$newdata->user = $USER->id;
|
||||
$newdata->survey = $survey->id;
|
||||
$newdata->question = $key;
|
||||
$newdata->answer1 = $val[0];
|
||||
$newdata->answer2 = $val[1];
|
||||
|
||||
if (! insert_record("survey_answers", $newdata)) {
|
||||
error("Encountered a problem trying to store your results. Sorry.");
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
$numusers = survey_count_responses($survey->id);
|
||||
print_heading(get_string("peoplecompleted", "survey", $numusers));
|
||||
echo "<CENTER>";
|
||||
echo "<IMG SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$cm->id&sid=$USER->id&type=student.png\">";
|
||||
echo "<IMG HEIGHT=\"$SURVEY_GHEIGHT\" WIDTH=\"$SURVEY_GWIDTH\" SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$cm->id&sid=$USER->id&type=student.png\">";
|
||||
echo "</CENTER>";
|
||||
print_footer($course);
|
||||
exit;
|
||||
@ -60,7 +60,7 @@
|
||||
print_simple_box(text_to_html($survey->intro), "center", "80%");
|
||||
|
||||
// Get all the major questions and their proper order
|
||||
if (! $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)")) {
|
||||
if (! $questions = get_records_list("survey_questions", "id", $survey->questions)) {
|
||||
error("Couldn't find any questions in this survey!!");
|
||||
}
|
||||
$questionorder = explode( ",", $survey->questions);
|
||||
|
Loading…
x
Reference in New Issue
Block a user