using 'counteditems' language string to help finnish translators, closing bug 2530
[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
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
68 echo '<form name="theform" action="view.php?id='.$this->cm->id.'" method="post">'; // do this so URLs look good
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 ':&nbsp;';
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
111 $submission->data1 = $data->text;
112 $submission->format = $data->format;
113 $submission->timemodified = time();
114
115 return update_record('assignment_submissions', $submission);
116 }
117
118
119 /*
120 * Display and process the submissions
121 */
122 function process_feedback() {
123
124 global $USER;
125
126 if (!$feedback = data_submitted()) { // No incoming data?
127 return false;
128 }
129
130 if (!empty($feedback->cancel)) { // User hit cancel button
131 return false;
132 }
133
134 $newsubmission = $this->get_submission($feedback->userid, true); // Get or make one
135
136 $newsubmission->grade = $feedback->grade;
137 $newsubmission->comment = $feedback->comment;
138 $newsubmission->format = $feedback->format;
139 $newsubmission->teacher = $USER->id;
140 $newsubmission->mailed = 0; // Make sure mail goes out (again, even)
141 $newsubmission->timemarked = time();
142
143 if (! update_record('assignment_submissions', $newsubmission)) {
144 return false;
145 }
146
147 add_to_log($this->course->id, 'assignment', 'update grades',
148 'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
149
150 return $newsubmission;
151
152 }
153
154 function print_user_files($userid, $return=false) {
155 global $CFG;
156
157 if (!$submission = $this->get_submission($userid)) {
158 return '';
159 }
160 $output = '<div class="files">'.
161 '<img align="middle" src="'.$CFG->pixpath.'/f/html.gif" height="16" width="16" alt="html" />'.
162 link_to_popup_window ('/mod/assignment/type/online/file.php?id='.$this->cm->id.'&amp;userid='.
163 $submission->userid, 'file'.$userid, shorten_text($submission->data1, 15), 450, 580,
164 get_string('submission', 'assignment'), 'none', true).
165 '</div>';
166
167 if ($return) {
168 return $output;
169 }
170 echo $output;
171 }
172
01e2fdfe 173 function preprocess_submission(&$submission) {
174 if ($this->assignment->var1 && empty($submission->comment)) { // comment inline
175 $submission->comment = $submission->data1; // Copy student data to teacher
176 $submission->format = $submission->data2;
177 }
178 }
179
f77cfb73 180}
181
182?>