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 150 151 152 153 154 155 156 157 158 159 160 161 162
|
<?php // $Id: assignment.class.php,v 1.21.2.1 2006/10/02 08:36:49 skodak Exp $
/**
* Extend the base assignment class for assignments where you upload a single file
*
*/
class assignment_uploadsingle extends assignment_base {
function print_student_answer($userid, $return=false){
global $CFG, $USER;
$filearea = $this->file_area_name($userid);
$output = '';
if ($basedir = $this->file_area($userid)) {
if ($files = get_directory_list($basedir)) {
foreach ($files as $key => $file) {
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $file);
if ($CFG->slasharguments) {
$ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
} else {
$ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
}
//died right here
//require_once($ffurl);
$output = '<img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />'.
'<a href="'.$ffurl.'" >'.$file.'</a><br />';
}
}
}
$output = '<div class="files">'.$output.'</div>';
return $output;
}
function assignment_uploadsingle($cmid=0) {
parent::assignment_base($cmid);
}
function view() {
global $USER;
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
$this->view_header();
$this->view_intro();
$this->view_dates();
$filecount = $this->count_user_files($USER->id);
if ($submission = $this->get_submission()) {
if ($submission->timemarked) {
$this->view_feedback();
}
if ($filecount) {
print_simple_box($this->print_user_files($USER->id, true), 'center');
}
}
if (!isguest($USER->id) && $this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
$this->view_upload_form();
}
$this->view_footer();
}
function view_upload_form() {
global $CFG;
$struploadafile = get_string("uploadafile");
$strmaxsize = get_string("maxsize", "", display_size($this->assignment->maxbytes));
echo '<center>';
echo '<form enctype="multipart/form-data" method="post" '.
"action=\"$CFG->wwwroot/mod/assignment/upload.php\">";
echo "<p>$struploadafile ($strmaxsize)</p>";
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
require_once($CFG->libdir.'/uploadlib.php');
upload_print_form_fragment(1,array('newfile'),false,null,0,$this->assignment->maxbytes,false);
echo '<input type="submit" name="save" value="'.get_string('uploadthisfile').'" />';
echo '</form>';
echo '</center>';
}
function upload() {
global $CFG, $USER;
if (isguest($USER->id)) {
error(get_string('guestnoupload','assignment'));
}
$this->view_header(get_string('upload'));
$filecount = $this->count_user_files($USER->id);
$submission = $this->get_submission($USER->id);
if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
if ($submission = $this->get_submission($USER->id)) {
//TODO: change later to ">= 0", to prevent resubmission when graded 0
if (($submission->grade > 0) and !$this->assignment->resubmit) {
notify(get_string('alreadygraded', 'assignment'));
}
}
$dir = $this->file_area_name($USER->id);
require_once($CFG->dirroot.'/lib/uploadlib.php');
$um = new upload_manager('newfile',true,false,$this->course,false,$this->assignment->maxbytes);
if ($um->process_file_uploads($dir)) {
$newfile_name = $um->get_new_filename();
if ($submission) {
$submission->timemodified = time();
$submission->numfiles = 1;
$submission->comment = addslashes($submission->comment);
unset($submission->data1); // Don't need to update this.
unset($submission->data2); // Don't need to update this.
if (update_record("assignment_submissions", $submission)) {
add_to_log($this->course->id, 'assignment', 'upload',
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->email_teachers($submission);
print_heading(get_string('uploadedfile'));
} else {
notify(get_string("uploadfailnoupdate", "assignment"));
}
} else {
$newsubmission = $this->prepare_new_submission($USER->id);
$newsubmission->numfiles = 1;
if (insert_record('assignment_submissions', $newsubmission)) {
add_to_log($this->course->id, 'assignment', 'upload',
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->email_teachers($newsubmission);
print_heading(get_string('uploadedfile'));
} else {
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
}
}
}
} else {
notify(get_string("uploaderror", "assignment")); //submitting not allowed!
}
print_continue('view.php?id='.$this->cm->id);
$this->view_footer();
}
}
?>
|