f77cfb73 |
1 | <?php // $Id$ |
2 | |
3 | /** |
4 | * Extend the base assignment class for assignments where you upload a single file |
5 | * |
6 | */ |
7 | class assignment_online extends assignment_base { |
8 | |
9 | function assignment_online($cmid=0) { |
10 | parent::assignment_base($cmid); |
11 | |
12 | } |
13 | |
f77cfb73 |
14 | function view() { |
15 | |
16 | global $USER; |
17 | |
18 | $editmode = ($this->isopen() && !empty($_GET['edit'])); |
19 | |
20 | if ($editmode) { |
21 | $this->view_header(get_string('editmysubmission', 'assignment')); |
22 | } else { |
23 | $this->view_header(); |
24 | } |
25 | |
26 | $this->view_intro(); |
27 | |
28 | $this->view_dates(); |
29 | |
30 | if ($data = data_submitted()) { // No incoming data? |
31 | if ($this->update_submission($data)) { |
32 | notify(get_string('submissionsaved', 'assignment')); |
33 | } |
34 | } |
35 | |
36 | print_simple_box_start('center', '70%', '', '', 'generalbox', 'online'); |
37 | $submission = $this->get_submission(); |
38 | if ($editmode) { |
39 | $this->view_edit_form($submission); |
40 | } else { |
41 | if ($submission) { |
42 | echo format_text($submission->data1, $submission->data2); |
43 | } else { |
d8199f1d |
44 | echo '<center>'.get_string('emptysubmission', 'assignment').'</center>'; |
f77cfb73 |
45 | } |
46 | if ($this->isopen()) { |
47 | print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'), |
48 | get_string('editmysubmission', 'assignment')); |
49 | } |
50 | } |
51 | print_simple_box_end(); |
52 | |
53 | if ($editmode and $this->usehtmleditor) { |
54 | use_html_editor(); // MUst be at the end of the page |
55 | } |
56 | |
57 | $this->view_feedback(); |
58 | |
59 | $this->view_footer(); |
60 | } |
61 | |
62 | function view_edit_form($submission = NULL) { |
63 | global $CFG; |
64 | |
65 | $defaulttext = $submission ? $submission->data1 : ''; |
66 | $defaultformat = $submission ? $submission->data2 : $this->defaultformat; |
67 | |
088ec317 |
68 | echo '<form name="theform" action="view.php" method="post">'; // do this so URLs look good |
f77cfb73 |
69 | |
70 | echo '<table cellspacing="0" class="editbox" align="center">'; |
71 | echo '<tr><td align="right">'; |
72 | helpbutton('reading', get_string('helpreading'), 'moodle', true, true); |
73 | echo '<br />'; |
74 | helpbutton('writing', get_string('helpwriting'), 'moodle', true, true); |
75 | echo '<br />'; |
76 | if ($this->usehtmleditor) { |
77 | helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true); |
78 | } else { |
79 | emoticonhelpbutton('theform', 'text'); |
80 | } |
81 | echo '<br />'; |
82 | echo '</td></tr>'; |
83 | echo '<tr><td align="center">'; |
84 | print_textarea($this->usehtmleditor, 20, 60, 630, 400, 'text', $defaulttext); |
85 | if (!$this->usehtmleditor) { |
86 | echo '<div align="right" class="format">'; |
87 | print_string('formattexttype'); |
88 | echo ': '; |
89 | choose_from_menu(format_text_menu(), 'format', $defaultformat, ''); |
90 | helpbutton('textformat', get_string('helpformatting')); |
91 | echo '</div>'; |
92 | } else { |
93 | echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />'; |
94 | } |
95 | echo '</td></tr>'; |
96 | echo '<tr><td align="center">'; |
97 | echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; |
98 | echo '<input type="submit" value="'.get_string('savechanges').'" />'; |
99 | echo '<input type="reset" value="'.get_string('revert').'" />'; |
100 | echo '</td></tr></table>'; |
101 | |
102 | echo '</form>'; |
103 | |
104 | } |
105 | |
106 | function update_submission($data) { |
107 | global $CFG, $USER; |
108 | |
109 | $submission = $this->get_submission($USER->id, true); |
110 | |
0cbc1f11 |
111 | $update = NULL; |
112 | $update->id = $submission->id; |
113 | $update->data1 = $data->text; |
114 | $update->format = $data->format; |
115 | $update->timemodified = time(); |
f77cfb73 |
116 | |
0cbc1f11 |
117 | return update_record('assignment_submissions', $update); |
f77cfb73 |
118 | } |
119 | |
120 | |
121 | /* |
122 | * Display and process the submissions |
123 | */ |
124 | function process_feedback() { |
125 | |
126 | global $USER; |
127 | |
128 | if (!$feedback = data_submitted()) { // No incoming data? |
129 | return false; |
130 | } |
131 | |
132 | if (!empty($feedback->cancel)) { // User hit cancel button |
133 | return false; |
134 | } |
135 | |
136 | $newsubmission = $this->get_submission($feedback->userid, true); // Get or make one |
137 | |
138 | $newsubmission->grade = $feedback->grade; |
139 | $newsubmission->comment = $feedback->comment; |
140 | $newsubmission->format = $feedback->format; |
141 | $newsubmission->teacher = $USER->id; |
142 | $newsubmission->mailed = 0; // Make sure mail goes out (again, even) |
143 | $newsubmission->timemarked = time(); |
144 | |
145 | if (! update_record('assignment_submissions', $newsubmission)) { |
146 | return false; |
147 | } |
148 | |
149 | add_to_log($this->course->id, 'assignment', 'update grades', |
150 | 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id); |
151 | |
152 | return $newsubmission; |
153 | |
154 | } |
155 | |
156 | function print_user_files($userid, $return=false) { |
157 | global $CFG; |
158 | |
159 | if (!$submission = $this->get_submission($userid)) { |
160 | return ''; |
161 | } |
162 | $output = '<div class="files">'. |
163 | '<img align="middle" src="'.$CFG->pixpath.'/f/html.gif" height="16" width="16" alt="html" />'. |
164 | link_to_popup_window ('/mod/assignment/type/online/file.php?id='.$this->cm->id.'&userid='. |
47263937 |
165 | $submission->userid, 'file'.$userid, shorten_text(strip_tags(format_text($submission->data1,$submission->data2)), 15), 450, 580, |
f77cfb73 |
166 | get_string('submission', 'assignment'), 'none', true). |
167 | '</div>'; |
168 | |
169 | if ($return) { |
170 | return $output; |
171 | } |
172 | echo $output; |
173 | } |
174 | |
01e2fdfe |
175 | function preprocess_submission(&$submission) { |
176 | if ($this->assignment->var1 && empty($submission->comment)) { // comment inline |
47263937 |
177 | if ($this->usehtmleditor) { |
178 | // Convert to html, clean & copy student data to teacher |
179 | $submission->comment = format_text($submission->data1, $submission->data2); |
180 | $submission->format = FORMAT_HTML; |
181 | } else { |
182 | // Copy student data to teacher |
183 | $submission->comment = $submission->data1; |
184 | $submission->format = $submission->data2; |
185 | } |
01e2fdfe |
186 | } |
187 | } |
188 | |
f77cfb73 |
189 | } |
190 | |
191 | ?> |