Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 607809b3ba
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 138 lines (104 sloc) 4.145 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
<?PHP // $Id$

    include("../../config.php");
    include("lib.php");

    require_variable($id); // Course Module ID

    if (! $cm = get_record("course_modules", "id", $id)) {
        error("Course Module ID was incorrect");
    }

    if (! $course = get_record("course", "id", $cm->course)) {
        error("Course is misconfigured");
    }

    require_login($course->id);

    if (! $survey = get_record("survey", "id", $cm->instance)) {
        error("Survey ID was incorrect");
    }
 
    if ($course->category) {
        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
    }

    $strsurveys = get_string("modulenameplural", "survey");
    $strsurvey = get_string("modulename", "survey");

    print_header("$course->shortname: $survey->name", "$course->fullname",
                 "$navigation <A HREF=index.php?id=$course->id>$strsurveys</A> -> $survey->name", "", "", true,
                  update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm));

    if (isteacher($course->id)) {
        $numusers = survey_count_responses($survey->id);
        echo "<P align=right><A HREF=\"report.php?id=$cm->id\">".
              get_string("viewsurveyresponses", "survey", $numusers)."</A></P>";
    }


// Check the survey hasn't already been filled out.

    if (survey_already_done($survey->id, $USER->id)) {
        add_to_log($course->id, "survey", "view graph", "view.php?id=$cm->id", "$survey->id");
        print_heading(get_string("surveycompleted", "survey"));
        $numusers = survey_count_responses($survey->id);
        print_heading(get_string("peoplecompleted", "survey", $numusers));
        echo "<CENTER>";
        survey_print_graph("id=$cm->id&sid=$USER->id&type=student.png");
        echo "</CENTER>";
        print_footer($course);
        exit;
    }

// Start the survey form
    add_to_log($course->id, "survey", "view form", "view.php?id=$cm->id", "$survey->id");

    echo "<FORM NAME=form METHOD=post ACTION=save.php>";
    echo "<INPUT TYPE=hidden NAME=id VALUE=$id>";

    print_simple_box(text_to_html($survey->intro), "center", "80%");

// Get all the major questions and their proper order
    if (! $questions = get_records_list("survey_questions", "id", $survey->questions)) {
        error("Couldn't find any questions in this survey!!");
    }
    $questionorder = explode( ",", $survey->questions);

// Cycle through all the questions in order and print them

    $qnum = 0;
    foreach ($questionorder as $key => $val) {
        $question = $questions["$val"];
        $question->id = $val;
        
        if ($question->type > 0) {
            if ($question->text) {
                $question->text = get_string($question->text, "survey");
            }
            if ($question->shorttext) {
                $question->shorttext = get_string($question->shorttext, "survey");
            }
            if ($question->intro) {
                $question->intro = get_string($question->intro, "survey");
            }
            if ($question->options) {
                $question->options = get_string($question->options, "survey");
            }

            if ($question->multi) {
                survey_print_multi($question);
            } else {
                survey_print_single($question);
            }
        }
    }

?>

<CENTER>
<BR>
<SCRIPT>
<!-- // BEGIN
function checkform() {

var error=false;

with (document.form) {
<? foreach ($checklist as $question => $default) {
           echo " if (".$question."[".$default."].checked) error=true;\n";
    }?>
}

if (error) {
alert("<?PHP print_string("questionsnotanswered", "survey") ?>");
} else {
document.form.submit();
}
}

<?PHP echo "document.write('<INPUT TYPE=button VALUE=\"".get_string("clicktocontinuecheck", "survey")."\" onClick=\"checkform()\">');"; ?>

// END -->
</SCRIPT>

<NOSCRIPT>
<!-- Without Javascript, no checking is done -->
<INPUT TYPE="submit" VALUE="<? get_string("clicktocontinue", "survey") ?>">
</NOSCRIPT>

</CENTER>

<?
   echo "</FORM>";

   print_footer($course);

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