Moodle 1.7 Assignment Drop Box - upload type error

Moodle 1.7 Assignment Drop Box - upload type error

by Mawuli Kuivi -
Number of replies: 0
Hello Martin,
I know you are getting ready to release Moodle 1.7. I was doing some testing on the assignment module - type called upload and found somethings you might want to consider.  Here are some suggestion/errors/bugs.

1. In the function print_response_students($return), please change the lines at around 940 and 942 from "uploadreview" to "upload" shown in red. Please add the file "file.php" attached to the upload type directory.

    // Prints response files to students
    function print_response_students($return) {
        global $CFG, $USER;

        $stuid = $USER->id;

        echo '<table border="0" align="center" cellpadding="5" cellspacing="1" class="feedback">';

        $submission = $this->get_submission($stuid);
        if ($teachids = $submission->data2) {           // Only will show files if there is a submission
            $teachidarr = explode(',', $teachids);

            foreach ($teachidarr as $t) {
                if (! $teacher = get_record('user', 'id', $t)) {
                    print_object($submission);
                    error('Could not find the teacher');
                }
                echo '<tr>';
                echo '<td class="left picture">';
                print_user_picture($teacher->id, $this->course->id, $teacher->picture);
                echo '</td>';
                echo '<td class="topic">';
                echo '<div class="from">';
                echo '<div class="fullname">'.fullname($teacher).'</div>';
                echo '</div>';

                $filearea = $this->response_file_area_name($stuid, $t);
                if ($basedir = $this->response_file_area($stuid, $t)) {
                    $output = '';
                    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/mod/assignment/type/uploadreview/file.php/$filearea/$file";
                            } else {
                                $ffurl = "$CFG->wwwroot/mod/assignment/type/uploadreview/file.php?file=/$filearea/$file";
                            }
                                              /*echo '<div class="files"><center><img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />'.
                                               link_to_popup_window ('/'.$ffurl, 'file'.$key, $file, 450, 580, $file, 'none', true).'</div></center><br />';
                                               echo '</td></tr>';*/
                                              //displays multiple teachers responces
                            $output .='<img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />'.
                            link_to_popup_window ('/'.$ffurl, 'file'.$key, $file, 450, 580, $file, 'none', true)."<br />";
                        }
                    }
                }
                echo '<div class="files"><left>'.$output.'</left></div>';
                echo '</td></tr>';
            }
            echo '</table>';
        }
    }


2. In the function  print_user_files($userid=0, $return=false), please comment out the test at about line 1035 shown below.   This is because Teachers should also be able to delete their files as students can.

    //print student's files.
    //if it's teacher view - teacher can view the files, but can't delete them
    //if it's student's view - stident can delete files, but can't view them
    function print_user_files($userid=0, $return=false) {
        global $CFG, $USER;

        if (!$userid) {
            if (!isloggedin()) {
                return '';
            }
            $userid = $USER->id;
        }

        $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);
                    //get filesize for displaying
                    $filesize = display_size(filesize($basedir."/".$file));

                    if ($CFG->slasharguments) {
                        $ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
                    } else {
                        $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
                    }
            // Removed this option. Teachers should also be able to delete their files as students can
            // if (has_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $this->course->id))) {
                    //    $output .= '<img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />'.
                    //               '<a href="'.$ffurl.'" >'.$file.'</a> ['.$filesize.'] <br />';
                    //} else {
            if (!empty($USER->id)) {
              if ($submission = $this->get_submission($USER->id)) {
            //i have changed timemodified=0 for Draft assignments, thats' why we remove this condition
            //otherwise student's dont' se etheir own submissions
            //                                 if ($submission->timemodified) {
            if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
              //remove link shouldn't be displayed if file was marked or submited for marking
              $remove_link = '';
              if ($submission->data1 == get_string("submissionstatusdraft", "assignment") || $submission->data1 == get_string("submissionstatusreturned", "assignment")) {
                $course_mod_id=$this->cm->id; 
                $deleteurl="$CFG->wwwroot/mod/assignment/type/upload/deleteonesubmission.php?confirm=0&view=student&userid=$userid&id=$course_mod_id&name=$file&file=".$basedir."/".$file;
                $remove_link= '[<a href="'.$deleteurl.'">'.get_string("removelink", "assignment").'</a>]'; //students of the course
              }
              $output .= '<img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />'.$file.' ['.$filesize.']'.$remove_link.'<br />';
            } else {
              $output .= '';
            }
              }
            }
                    //} comment or remove this line
         }
        }
    }

        $output = '<div class="files">'.$output.'</div>';

        if ($return) {
            return $output;
        }
        echo $output;
    }
Average of ratings: -