| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: assignment.class.php,v 1.33.2.5 2008/04/08 03:02:49 scyrma Exp $ 2 3 /** 4 * Extend the base assignment class for assignments where you upload a single file 5 * 6 */ 7 class assignment_uploadsingle extends assignment_base { 8 9 10 function print_student_answer($userid, $return=false){ 11 global $CFG, $USER; 12 13 $filearea = $this->file_area_name($userid); 14 15 $output = ''; 16 17 if ($basedir = $this->file_area($userid)) { 18 if ($files = get_directory_list($basedir)) { 19 require_once($CFG->libdir.'/filelib.php'); 20 foreach ($files as $key => $file) { 21 22 $icon = mimeinfo('icon', $file); 23 $ffurl = get_file_url("$filearea/$file"); 24 25 //died right here 26 //require_once($ffurl); 27 $output = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'. 28 '<a href="'.$ffurl.'" >'.$file.'</a><br />'; 29 } 30 } 31 } 32 33 $output = '<div class="files">'.$output.'</div>'; 34 return $output; 35 } 36 37 function assignment_uploadsingle($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) { 38 parent::assignment_base($cmid, $assignment, $cm, $course); 39 $this->type = 'uploadsingle'; 40 } 41 42 function view() { 43 44 global $USER; 45 46 $context = get_context_instance(CONTEXT_MODULE,$this->cm->id); 47 require_capability('mod/assignment:view', $context); 48 49 add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); 50 51 $this->view_header(); 52 53 $this->view_intro(); 54 55 $this->view_dates(); 56 57 $filecount = $this->count_user_files($USER->id); 58 59 if ($submission = $this->get_submission()) { 60 if ($submission->timemarked) { 61 $this->view_feedback(); 62 } 63 if ($filecount) { 64 print_simple_box($this->print_user_files($USER->id, true), 'center'); 65 } 66 } 67 68 if (has_capability('mod/assignment:submit', $context) && $this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) { 69 $this->view_upload_form(); 70 } 71 72 $this->view_footer(); 73 } 74 75 76 function view_upload_form() { 77 global $CFG; 78 $struploadafile = get_string("uploadafile"); 79 80 $maxbytes = $this->assignment->maxbytes == 0 ? $this->course->maxbytes : $this->assignment->maxbytes; 81 $strmaxsize = get_string('maxsize', '', display_size($maxbytes)); 82 83 echo '<div style="text-align:center">'; 84 echo '<form enctype="multipart/form-data" method="post" '. 85 "action=\"$CFG->wwwroot/mod/assignment/upload.php\">"; 86 echo '<fieldset class="invisiblefieldset">'; 87 echo "<p>$struploadafile ($strmaxsize)</p>"; 88 echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; 89 require_once($CFG->libdir.'/uploadlib.php'); 90 upload_print_form_fragment(1,array('newfile'),false,null,0,$this->assignment->maxbytes,false); 91 echo '<input type="submit" name="save" value="'.get_string('uploadthisfile').'" />'; 92 echo '</fieldset>'; 93 echo '</form>'; 94 echo '</div>'; 95 } 96 97 98 function upload() { 99 100 global $CFG, $USER; 101 102 require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)); 103 104 $this->view_header(get_string('upload')); 105 106 $filecount = $this->count_user_files($USER->id); 107 $submission = $this->get_submission($USER->id); 108 if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) { 109 if ($submission = $this->get_submission($USER->id)) { 110 //TODO: change later to ">= 0", to prevent resubmission when graded 0 111 if (($submission->grade > 0) and !$this->assignment->resubmit) { 112 notify(get_string('alreadygraded', 'assignment')); 113 } 114 } 115 116 $dir = $this->file_area_name($USER->id); 117 118 require_once($CFG->dirroot.'/lib/uploadlib.php'); 119 $um = new upload_manager('newfile',true,false,$this->course,false,$this->assignment->maxbytes); 120 if ($um->process_file_uploads($dir)) { 121 $newfile_name = $um->get_new_filename(); 122 if ($submission) { 123 $submission->timemodified = time(); 124 $submission->numfiles = 1; 125 $submission->submissioncomment = addslashes($submission->submissioncomment); 126 unset($submission->data1); // Don't need to update this. 127 unset($submission->data2); // Don't need to update this. 128 if (update_record("assignment_submissions", $submission)) { 129 add_to_log($this->course->id, 'assignment', 'upload', 130 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 131 $submission = $this->get_submission($USER->id); 132 $this->update_grade($submission); 133 $this->email_teachers($submission); 134 print_heading(get_string('uploadedfile')); 135 } else { 136 notify(get_string("uploadfailnoupdate", "assignment")); 137 } 138 } else { 139 $newsubmission = $this->prepare_new_submission($USER->id); 140 $newsubmission->timemodified = time(); 141 $newsubmission->numfiles = 1; 142 if (insert_record('assignment_submissions', $newsubmission)) { 143 add_to_log($this->course->id, 'assignment', 'upload', 144 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id); 145 $submission = $this->get_submission($USER->id); 146 $this->update_grade($submission); 147 $this->email_teachers($newsubmission); 148 print_heading(get_string('uploadedfile')); 149 } else { 150 notify(get_string("uploadnotregistered", "assignment", $newfile_name) ); 151 } 152 } 153 } 154 } else { 155 notify(get_string("uploaderror", "assignment")); //submitting not allowed! 156 } 157 158 print_continue('view.php?id='.$this->cm->id); 159 160 $this->view_footer(); 161 } 162 163 function setup_elements(&$mform) { 164 global $CFG, $COURSE; 165 166 $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); 167 168 $mform->addElement('select', 'resubmit', get_string("allowresubmit", "assignment"), $ynoptions); 169 $mform->setHelpButton('resubmit', array('resubmit', get_string('allowresubmit', 'assignment'), 'assignment')); 170 $mform->setDefault('resubmit', 0); 171 172 $mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions); 173 $mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment')); 174 $mform->setDefault('emailteachers', 0); 175 176 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); 177 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; 178 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices); 179 $mform->setDefault('maxbytes', $CFG->assignment_maxbytes); 180 181 } 182 183 } 184 185 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |