Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3f4deb2b86
Fetching contributors…

Cannot retrieve contributors at this time

file 144 lines (109 sloc) 3.795 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
<?PHP // $Id$

// Graph size
$GHEIGHT = 500;
$GWIDTH = 900;

$QTYPE = array (
        "-3" => "Virtual Actual and Preferred",
        "-2" => "Virtual Preferred",
        "-1" => "Virtual Actual",
         "0" => "Text",
         "1" => "Actual",
         "2" => "Preferred",
         "3" => "Actual and Preferred",
        );

function survey_already_done($survey, $user) {
   return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'");
}

function get_survey_status($survey) {

    $timenow = time();
    if ($survey->locked) {
        if (($survey->timeopen <= $timenow) && ($timenow <= $survey->timeclose)) {
            return "released";
        } else if ($survey->timenow >= $survey->timeclose) {
            return "finished";
        } else {
            return "error";
        }
    } else {
        return "editing";
    }

}

function get_responses_for_survey($surveyid) {
        global $db;

        if ($aa = $db->Execute("SELECT user FROM survey_answers WHERE survey = $surveyid GROUP BY user")) {
                if ($aa) {
                        return $aa->RowCount();
                } else {
                        return -1;
                }
        } else {
                return -1;
        }
}

function print_all_responses($survey, $results) {

    global $THEME;

    echo "<TABLE CELLPADDING=5 CELLSPACING=2 ALIGN=CENTER>";
    echo "<TR><TD>Name<TD>Time<TD>Answered</TR>";

    foreach ($results as $a) {
                 
        echo "<TR>";
        echo "<TD><A HREF=\"report.php?action=student&student=$a->id&id=$survey\">$a->firstname $a->lastname</A></TD>";
echo "<TD>".userdate($a->time, "%e %B %Y, %I:%M %p")."</TD>";
echo "<TD align=right>$a->numanswers</TD>";
echo "</TR>";
}
echo "</TABLE>";
}

function get_survey_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 count_completed_surveys($survey) {
if ($responses = get_survey_responses($survey)) {
return count($responses);
} else {
return 0;
}
}


function get_template_name($templateid) {
global $db;

if ($templateid) {
if ($ss = $db->Execute("SELECT name FROM surveys WHERE id = $templateid")) {
return $ss->fields["name"];
}
} else {
return "";
}
}


function update_survey_analysis($survey, $user, $notes) {
global $db;

return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'");
}


function add_survey_analysis($survey, $user, $notes) {
global $db;

return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'");
}


function survey_user_summary($course, $user, $mod, $survey) {
global $CFG;
}


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'")) {

$lastanswer = array_pop($answers);

$result->info = "Done";
$result->time = $lastanswer->time;
return $result;
}
return NULL;
}


function survey_user_complete($course, $user, $mod, $survey) {
global $CFG;

if (survey_already_done($survey->id, $user->id)) {
echo "<IMG SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$mod->id&sid=$user->id&type=student.png\">";
    } else {
        echo "Not done yet";
    }
}

?>
Something went wrong with that request. Please try again.