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