File: assess.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (149 lines) | stat: -rw-r--r-- 6,929 bytes parent folder | download | duplicates (2)
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
145
146
147
148
149
<?php  // $Id: assess.php,v 1.8.2.1 2006/06/01 14:49:31 skodak Exp $

    require("../../config.php");
    require("lib.php");
    require("locallib.php");

    $id            = required_param('id', PARAM_INT);   // Submission ID
    $allowcomments = optional_param('allowcomments', 0, PARAM_BOOL);
    $redirect      = optional_param('redirect', '', PARAM_URL);
    $frameset      = optional_param('frameset', '', PARAM_ALPHA);
    $sid           = optional_param('sid', 0, PARAM_INT);

    if (! $submission = get_record('workshop_submissions', 'id', $sid)) {
        error("Incorrect submission id");
    }
    if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
        error("Submission is incorrect");
    }
    if (! $course = get_record("course", "id", $workshop->course)) {
        error("Workshop is misconfigured");
    }
    if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
        error("No coursemodule found");
    }

    if (!$redirect) {
        $redirect = urlencode($_SERVER["HTTP_REFERER"].'#sid='.$submission->id);
    }

    require_login($course->id, false, $cm);

    $strworkshops = get_string("modulenameplural", "workshop");
    $strworkshop  = get_string("modulename", "workshop");
    $strassess = get_string("assess", "workshop");

    /// Now check whether we need to display a frameset

    if (empty($frameset)) {
        $encoding = current_charset();
        if ( get_string('thisdirection') == 'rtl' ) {
            $direction = ' dir="rtl"';
        } else {
            $direction = ' dir="ltr"';
        }
        echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
        echo "<html $direction>\n";
        echo "<head><meta http-equiv=\"content-type\" content=\"text/html; charset=$encoding\" />\n";
        echo "<title>{$course->shortname}: ".format_string($workshop->name,true)."</title></head>\n";
        echo "<frameset rows=\"50%,*\" border=\"10\">";
        echo "  <frame src=\"assess.php?id=$id&amp;sid=$sid&amp;frameset=top&amp;redirect=$redirect\" border=\"10\" />";
        echo "  <frame src=\"assess.php?id=$id&amp;sid=$sid&amp;frameset=bottom&amp;redirect=$redirect\" />";
        echo "</frameset>";
        echo "</html>";
        exit;
    }

    /// top frame with the navigation bar and the assessment form

    if ($frameset == "top") {

        print_header_simple(format_string($workshop->name), "",
                     "<a href=\"index.php?id=$course->id\">$strworkshops</a> ->
                      <a href=\"view.php?id=$cm->id\">".format_string($workshop->name,true)."</a> -> $strassess",
                      "", '<base target="_parent" />', true);

        // there can be an assessment record (for teacher submissions), if there isn't...
        if (!$assessment = get_record("workshop_assessments", "submissionid", $submission->id, "userid",
                    $USER->id)) {
            // if it's the teacher see if the user has done a self assessment if so copy it
            if (isteacher($course->id) and  ($assessment = get_record("workshop_assessments", "submissionid",
                            $submission->id, "userid", $submission->userid))) {
                $assessment = workshop_copy_assessment($assessment, $submission, true);
                // need to set owner of assessment
                set_field("workshop_assessments", "userid", $USER->id, "id", $assessment->id);
                $assessment->resubmission = 0; // not set by workshop_copy_assessment
                $assessment->timegraded = 0; // not set by workshop_copy_assessment
                $assessment->timeagreed = 0; // not set by workshop_copy_assessment
            } else {
                $yearfromnow = time() + 365 * 86400;
                // ...create one and set timecreated way in the future, this is reset when record is updated
                $assessment->workshopid = $workshop->id;
                $assessment->submissionid = $submission->id;
                $assessment->userid = $USER->id;
                $assessment->timecreated = $yearfromnow;
                $assessment->grade = -1; // set impossible grade
                $assessment->timegraded = 0;
                $assessment->timeagreed = 0;
                $assessment->resubmission = 0;
                if (!$assessment->id = insert_record("workshop_assessments", $assessment)) {
                    error("Could not insert workshop assessment!");
                }
                // if it's the teacher and the workshop is error banded set all the elements to Yes
                if (isteacher($course->id) and ($workshop->gradingstrategy == 2)) {
                    for ($i =0; $i < $workshop->nelements; $i++) {
                        unset($element);
                        $element->workshopid = $workshop->id;
                        $element->assessmentid = $assessment->id;
                        $element->elementno = $i;
                        $element->feedback = '';
                        $element->grade = 1;
                        if (!$element->id = insert_record("workshop_grades", $element)) {
                            error("Could not insert workshop grade!");
                        }
                    }
                    // now set the adjustment
                    unset($element);
                    $i = $workshop->nelements;
                    $element->workshopid = $workshop->id;
                    $element->assessmentid = $assessment->id;
                    $element->elementno = $i;
                    $element->grade = 0;
                    if (!$element->id = insert_record("workshop_grades", $element)) {
                        error("Could not insert workshop grade!");
                    }
                }
            }
        }

        print_heading_with_help(get_string("assessthissubmission", "workshop"), "grading", "workshop");

        // show assessment and allow changes
        workshop_print_assessment($workshop, $assessment, true, $allowcomments, $redirect);

        print_heading("<a target=\"{$CFG->framename}\" href=\"$redirect\">".get_string("cancel")."</a>");
        print_footer($course);
        exit;
    }

    /// print bottom frame with the submission

    print_header('', '', '', '', '<base target="_parent" />');
    $title = '"'.$submission->title.'" ';
    if (isteacher($course->id)) {
        $title .= ' '.get_string('by', 'workshop').' '.workshop_fullname($submission->userid, $course->id);
    }
    print_heading($title);
    workshop_print_submission($workshop, $submission);

    if (isteacher($course->id)) {
        echo '<br /><center><b>'.get_string('assessments', 'workshop').': </b><br />';
        echo workshop_print_submission_assessments($workshop, $submission, "all");
        echo '</center>';
    }


    print_footer('none');

?>