function geogebra_view_results($geogebra, $context, $cm, $course, $action)
{
    global $CFG, $DB, $OUTPUT, $PAGE, $USER;
    if ($action == 'submitgrade') {
        // Upgrade submitted grade
        $grade = optional_param('grade', '', PARAM_INT);
        $gradecomment = optional_param_array('comment_editor', '', PARAM_RAW);
        $attemptid = optional_param('attemptid', '', PARAM_INT);
        $attempt = geogebra_get_attempt($attemptid);
        parse_str($attempt->vars, $parsedvars);
        $parsedvars['grade'] = $grade;
        $attempt->vars = http_build_query($parsedvars, '', '&');
        geogebra_update_attempt($attemptid, $attempt->vars, GEOGEBRA_UPDATE_TEACHER, $gradecomment['text']);
    }
    // Show students list with their results
    require_once $CFG->libdir . '/gradelib.php';
    $perpage = optional_param('perpage', 10, PARAM_INT);
    $perpage = $perpage <= 0 ? 10 : $perpage;
    $page = optional_param('page', 0, PARAM_INT);
    // Find out current groups mode
    $groupmode = groups_get_activity_groupmode($cm);
    $currentgroup = groups_get_activity_group($cm, true);
    // Get all ppl that are allowed to submit geogebra
    list($esql, $params) = get_enrolled_sql($context, 'mod/geogebra:submit', $currentgroup);
    $sql = "SELECT u.id FROM {user} u " . "LEFT JOIN ({$esql}) eu ON eu.id=u.id " . "WHERE u.deleted = 0 AND eu.id=u.id ";
    $users = $DB->get_records_sql($sql, $params);
    if (!empty($users)) {
        $users = array_keys($users);
    }
    // If groupmembersonly used, remove users who are not in any group
    if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
            $users = array_intersect($users, array_keys($groupingusers));
        }
    }
    // TODO: Review to show all users information
    if (!empty($users)) {
        // Create results table
        $extrafields = get_extra_user_fields($context);
        $tablecolumns = array_merge(array('picture', 'fullname'), $extrafields, array('attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status'));
        $extrafieldnames = array();
        foreach ($extrafields as $field) {
            $extrafieldnames[] = get_user_field_name($field);
        }
        $tableheaders = array_merge(array('', get_string('fullnameuser')), $extrafieldnames, array(get_string('attempts', 'geogebra'), get_string('duration', 'geogebra'), get_string('grade'), get_string('comment', 'geogebra'), get_string('lastmodifiedsubmission', 'geogebra'), get_string('lastmodifiedgrade', 'geogebra'), get_string('status', 'geogebra')));
        require_once $CFG->libdir . '/tablelib.php';
        $table = new flexible_table('mod-geogebra-results');
        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot . '/mod/geogebra/report.php?id=' . $cm->id . '&amp;currentgroup=' . $currentgroup);
        $table->sortable(true, 'lastname');
        // Sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);
        $table->column_suppress('picture');
        $table->column_suppress('fullname');
        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        foreach ($extrafields as $field) {
            $table->column_class($field, $field);
        }
        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'results generaltable generalbox');
        $table->set_attribute('width', '100%');
        $table->no_sorting('attempts');
        $table->no_sorting('duration');
        $table->no_sorting('grade');
        $table->no_sorting('comment');
        $table->no_sorting('datestudent');
        $table->no_sorting('dateteacher');
        $table->no_sorting('status');
        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();
        // Construct the SQL
        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }
        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY ' . $sort;
        }
        $ufields = user_picture::fields('u', $extrafields);
        $select = "SELECT {$ufields} ";
        $sql = 'FROM {user} u WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
        $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size());
        $table->pagesize($perpage, count($users));
        $offset = $page * $perpage;
        // Offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        if ($ausers !== false) {
            // $grading_info = grade_get_grades($course->id, 'mod', 'geogebra', $geogebra->id, array_keys($ausers));
            foreach ($ausers as $auser) {
                $picture = $OUTPUT->user_picture($auser);
                $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>';
                $row = array($picture, $userlink);
                $extradata = array();
                foreach ($extrafields as $field) {
                    $extradata[] = $auser->{$field};
                }
                $row += $extradata;
                // Attempts summary
                $attempts = geogebra_get_user_attempts($geogebra->id, $auser->id);
                $attemptssummary = geogebra_get_user_grades($geogebra, $auser->id);
                if ($attemptssummary) {
                    $row[] = $attemptssummary->attempts;
                    $row[] = geogebra_time2str($attemptssummary->duration);
                    $row[] = $attemptssummary->grade;
                    $rowclass = $attemptssummary->attempts > 0 ? 'summary-row' : "";
                } else {
                    $row[] = "";
                    $row[] = "";
                    $row[] = "";
                    $rowclass = "";
                }
                $row[] = "";
                $row[] = "";
                $row[] = "";
                $row[] = "";
                $table->add_data($row, $rowclass);
                // Show attempts information
                foreach ($attempts as $attempt) {
                    $row = array();
                    // In the attempts row, show only the summary of the attempt (it's not necessary to repeat user information)
                    for ($i = 0; $i < count($extradata) + 2; $i++) {
                        array_push($row, '');
                    }
                    // Attempt information
                    $row = geogebra_get_attempt_row($geogebra, $attempt, $auser, $cm, $context, $row);
                    /*array_push($row, $attempt->duration);
                      array_push($row, $attempt->grade);
                      array_push($row, $attempt->comment);*/
                    $table->add_data($row);
                }
            }
        }
        $table->print_html();
        // Print the whole table
    } else {
        echo $OUTPUT->notification(get_string('msg_nosessions', 'geogebra'), 'notifymessage');
    }
}
Esempio n. 2
0
 // If using legacy log then get users from old table.
 if ($uselegacyreader || $onlyuselegacyreader) {
     $limittime = '';
     if ($uselegacyreader && !empty($minloginternalreader)) {
         $limittime = ' AND time < :tilltime ';
         $params['tilltime'] = $minloginternalreader;
     }
     $sql = "SELECT ra.userid, {$usernamefields}, u.idnumber, l.actioncount AS count\n                  FROM (SELECT DISTINCT userid FROM {role_assignments} WHERE contextid {$relatedctxsql} AND roleid = :roleid ) ra\n                  JOIN {user} u ON u.id = ra.userid\n             {$groupsql}\n             LEFT JOIN (\n                    SELECT userid, COUNT(action) AS actioncount\n                      FROM {log}\n                     WHERE cmid = :instanceid\n                           AND time > :timefrom " . $limittime . $actionsql . " GROUP BY userid) l ON (l.userid = ra.userid)";
     if ($twhere) {
         $sql .= ' WHERE ' . $twhere;
         // Initial bar.
     }
     if ($table->get_sql_sort()) {
         $sql .= ' ORDER BY ' . $table->get_sql_sort();
     }
     if (!($users = $DB->get_records_sql($sql, $params, $table->get_page_start(), $table->get_page_size()))) {
         $users = array();
         // Tablelib will handle saying 'Nothing to display' for us.
     }
 }
 // Get record from sql_internal_reader and merge with records got from legacy log (if needed).
 if (!$onlyuselegacyreader) {
     $sql = "SELECT ra.userid, {$usernamefields}, u.idnumber, COUNT(l.actioncount) AS count\n                  FROM (SELECT DISTINCT userid FROM {role_assignments} WHERE contextid {$relatedctxsql} AND roleid = :roleid ) ra\n                  JOIN {user} u ON u.id = ra.userid\n             {$groupsql}\n             LEFT JOIN (\n                    SELECT userid, COUNT(crud) AS actioncount\n                      FROM {" . $logtable . "}\n                     WHERE contextinstanceid = :instanceid\n                       AND timecreated > :timefrom" . $crudsql . "\n                       AND edulevel = :edulevel\n                       AND anonymous = 0\n                       AND contextlevel = :contextlevel\n                       AND (origin = 'web' OR origin = 'ws')\n                  GROUP BY userid,timecreated) l ON (l.userid = ra.userid)";
     // We add this after the WHERE statement that may come below.
     $groupbysql = " GROUP BY ra.userid, {$usernamefields}, u.idnumber";
     $params['edulevel'] = core\event\base::LEVEL_PARTICIPATING;
     $params['contextlevel'] = CONTEXT_MODULE;
     if ($twhere) {
         $sql .= ' WHERE ' . $twhere;
         // Initial bar.
     }
Esempio n. 3
0
    /**
     *  Display all the submissions ready for grading
     *
     * @global object
     * @global object
     * @global object
     * @global object
     * @param string $message
     * @return bool|void
     */
    function display_submissions($message='') {
        global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE;
        require_once($CFG->libdir.'/gradelib.php');

        /* first we check to see if the form has just been submitted
         * to request user_preference updates
         */

       $filters = array(self::FILTER_ALL             => get_string('all'),
                        self::FILTER_SUBMITTED       => get_string('submitted', 'assignment'),
                        self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));

        $updatepref = optional_param('updatepref', 0, PARAM_INT);

        if (isset($_POST['updatepref'])){
            $perpage = optional_param('perpage', 10, PARAM_INT);
            $perpage = ($perpage <= 0) ? 10 : $perpage ;
            $filter = optional_param('filter', 0, PARAM_INT);
            set_user_preference('assignment_perpage', $perpage);
            set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
            set_user_preference('assignment_filter', $filter);
        }

        /* next we get perpage and quickgrade (allow quick grade) params
         * from database
         */
        $perpage    = get_user_preferences('assignment_perpage', 10);
        $quickgrade = get_user_preferences('assignment_quickgrade', 0);
        $filter = get_user_preferences('assignment_filter', 0);
        $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);

        if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
            $uses_outcomes = true;
        } else {
            $uses_outcomes = false;
        }

        $page    = optional_param('page', 0, PARAM_INT);
        $strsaveallfeedback = get_string('saveallfeedback', 'assignment');

    /// Some shortcuts to make the code read better

        $course     = $this->course;
        $assignment = $this->assignment;
        $cm         = $this->cm;

        $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
        add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id, $this->assignment->id, $this->cm->id);

        $PAGE->set_title(format_string($this->assignment->name,true));
        $PAGE->set_heading($this->course->fullname);
        echo $OUTPUT->header();

        echo '<div class="usersubmissions">';

        //hook to allow plagiarism plugins to update status/print links.
        plagiarism_update_status($this->course, $this->cm);

        /// Print quickgrade form around the table
        if ($quickgrade) {
            $formattrs = array();
            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
            $formattrs['id'] = 'fastg';
            $formattrs['method'] = 'post';

            echo html_writer::start_tag('form', $formattrs);
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
        }

        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
                . get_string('seeallcoursegrades', 'grades') . '</a></div>';
        }

        if (!empty($message)) {
            echo $message;   // display messages here if any
        }

        $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    /// Check to see if groups are being used in this assignment

        /// find out current groups mode
        $groupmode = groups_get_activity_groupmode($cm);
        $currentgroup = groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);

        /// Get all ppl that are allowed to submit assignments
        list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup);

        if ($filter == self::FILTER_ALL) {
            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "WHERE u.deleted = 0 AND eu.id=u.id ";
        } else {
            $wherefilter = '';
            if($filter == self::FILTER_SUBMITTED) {
               $wherefilter = ' AND s.timemodified > 0';
            } else if($filter == self::FILTER_REQUIRE_GRADING) {
                $wherefilter = ' AND s.timemarked < s.timemodified ';
            }

            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " .
                   "WHERE u.deleted = 0 AND eu.id=u.id ".
                   'AND s.assignment = '. $this->assignment->id .
                    $wherefilter;
        }

        $users = $DB->get_records_sql($sql, $params);
        if (!empty($users)) {
            $users = array_keys($users);
        }

        // if groupmembersonly used, remove users who are not in any group
        if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
            if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
                $users = array_intersect($users, array_keys($groupingusers));
            }
        }

        $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
        if ($uses_outcomes) {
            $tablecolumns[] = 'outcome'; // no sorting based on outcomes column
        }

        $tableheaders = array('',
                              get_string('fullname'),
                              get_string('grade'),
                              get_string('comment', 'assignment'),
                              get_string('lastmodified').' ('.get_string('submission', 'assignment').')',
                              get_string('lastmodified').' ('.get_string('grade').')',
                              get_string('status'),
                              get_string('finalgrade', 'grades'));
        if ($uses_outcomes) {
            $tableheaders[] = get_string('outcome', 'grades');
        }

        require_once($CFG->libdir.'/tablelib.php');
        $table = new flexible_table('mod-assignment-submissions');

        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);

        $table->sortable(true, 'lastname');//sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);

        $table->column_suppress('picture');
        $table->column_suppress('fullname');

        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        $table->column_class('grade', 'grade');
        $table->column_class('submissioncomment', 'comment');
        $table->column_class('timemodified', 'timemodified');
        $table->column_class('timemarked', 'timemarked');
        $table->column_class('status', 'status');
        $table->column_class('finalgrade', 'finalgrade');
        if ($uses_outcomes) {
            $table->column_class('outcome', 'outcome');
        }

        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'submissions');
        $table->set_attribute('width', '100%');
        //$table->set_attribute('align', 'center');

        $table->no_sorting('finalgrade');
        $table->no_sorting('outcome');

        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();

        if (empty($users)) {
            echo $OUTPUT->heading(get_string('nosubmitusers','assignment'));
            echo '</div>';
            return true;
        }
        if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak)
            echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&amp;download=zip">'.get_string('downloadall', 'assignment').'</a></div>';
        }
    /// Construct the SQL

        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }

        if ($filter == self::FILTER_SUBMITTED) {
           $where .= 's.timemodified > 0 AND ';
        } else if($filter == self::FILTER_REQUIRE_GRADING) {
           $where .= 's.timemarked < s.timemodified AND ';
        }

        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY '.$sort;
        }

        $ufields = user_picture::fields('u');

        $select = "SELECT $ufields,
                          s.id AS submissionid, s.grade, s.submissioncomment,
                          s.timemodified, s.timemarked,
                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
        $sql = 'FROM {user} u '.
               'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                AND s.assignment = '.$this->assignment->id.' '.
               'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';

        $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());

        $table->pagesize($perpage, count($users));

        ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        $offset = $page * $perpage;
        $strupdate = get_string('update');
        $strgrade  = get_string('grade');
        $grademenu = make_grades_menu($this->assignment->grade);

        if ($ausers !== false) {
            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
            $endposition = $offset + $perpage;
            $currentposition = 0;
            foreach ($ausers as $auser) {
                if ($currentposition == $offset && $offset < $endposition) {
                    $final_grade = $grading_info->items[0]->grades[$auser->id];
                    $grademax = $grading_info->items[0]->grademax;
                    $final_grade->formatted_grade = round($final_grade->grade,2) .' / ' . round($grademax,2);
                    $locked_overridden = 'locked';
                    if ($final_grade->overridden) {
                        $locked_overridden = 'overridden';
                    }

                /// Calculate user status
                    $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified);
                    $picture = $OUTPUT->user_picture($auser);

                    if (empty($auser->submissionid)) {
                        $auser->grade = -1; //no submission yet
                    }

                    if (!empty($auser->submissionid)) {
                    ///Prints student answer and student modified date
                    ///attach file or print link to student answer, depending on the type of the assignment.
                    ///Refer to print_student_answer in inherited classes.
                        if ($auser->timemodified > 0) {
                            $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id)
                                             . userdate($auser->timemodified).'</div>';
                        } else {
                            $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        }
                    ///Print grade, dropdown or text
                        if ($auser->timemarked > 0) {
                            $teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';

                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'. $menu .'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }

                        } else {
                            $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }
                        }
                    ///Print Comment
                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';

                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>';
                        }
                    } else {
                        $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                        $status          = '<div id="st'.$auser->id.'">&nbsp;</div>';

                        if ($final_grade->locked or $final_grade->overridden) {
                            $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>';
                        } else if ($quickgrade) {   // allow editing
                            $attributes = array();
                            $attributes['tabindex'] = $tabindex++;
                            $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                            $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                        } else {
                            $grade = '<div id="g'.$auser->id.'">-</div>';
                        }

                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';
                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">&nbsp;</div>';
                        }
                    }

                    if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1
                        $auser->status = 0;
                    } else {
                        $auser->status = 1;
                    }

                    $buttontext = ($auser->status == 1) ? $strupdate : $strgrade;

                    ///No more buttons, we use popups ;-).
                    $popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id
                               . '&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;filter='.$filter.'&amp;offset='.$offset++;

                    $button = $OUTPUT->action_link($popup_url, $buttontext);

                    $status  = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';

                    $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';

                    $outcomes = '';

                    if ($uses_outcomes) {

                        foreach($grading_info->outcomes as $n=>$outcome) {
                            $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
                            $options = make_grades_menu(-$outcome->scaleid);

                            if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                                $options[0] = get_string('nooutcome', 'grades');
                                $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';
                            } else {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $attributes['id'] = 'outcome_'.$n.'_'.$auser->id;
                                $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes);
                            }
                            $outcomes .= '</div>';
                        }
                    }

                    $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>';
                    $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
                    if ($uses_outcomes) {
                        $row[] = $outcomes;
                    }

                    $table->add_data($row);
                }
                $currentposition++;
            }
        }

        $table->print_html();  /// Print the whole table

        /// Print quickgrade form around the table
        if ($quickgrade && $table->started_output){
            $mailinfopref = false;
            if (get_user_preferences('assignment_mailinfo', 1)) {
                $mailinfopref = true;
            }
            $emailnotification =  html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment'));

            $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'assignment');
            echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification'));

            $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'assignment')));
            echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton'));

            echo html_writer::end_tag('form');
        } else if ($quickgrade) {
            echo html_writer::end_tag('form');
        }

        echo '</div>';
        /// End of fast grading form

        /// Mini form for setting user preference

        $formaction = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id));
        $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref'));

        $mform->addElement('hidden', 'updatepref');
        $mform->setDefault('updatepref', 1);
        $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment'));
        $mform->addElement('select', 'filter', get_string('show'),  $filters);

        $mform->setDefault('filter', $filter);

        $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size'=>1));
        $mform->setDefault('perpage', $perpage);

        $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade','assignment'));
        $mform->setDefault('quickgrade', $quickgrade);
        $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment');

        $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));

        $mform->display();

        echo $OUTPUT->footer();
    }
Esempio n. 4
0
    /**
     * displays the full report
     * @param stdClass $scorm full SCORM object
     * @param stdClass $cm - full course_module object
     * @param stdClass $course - full course object
     * @param string $download - type of download being requested
     */
    function display($scorm, $cm, $course, $download) {
        global $CFG, $DB, $OUTPUT, $PAGE;
        $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
        $action = optional_param('action', '', PARAM_ALPHA);
        $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
        $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
        $PAGE->set_url(new moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));

        if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
            if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
                add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
                echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
            }
        }
        // find out current groups mode
        $currentgroup = groups_get_activity_group($cm, true);

        // detailed report
        $mform = new mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup'));
        if ($fromform = $mform->get_data()) {
            $pagesize = $fromform->pagesize;
            $includeqtext = $fromform->qtext;
            $includeresp = $fromform->resp;
            $includeright = $fromform->right;
            set_user_preference('scorm_report_pagesize', $pagesize);
            set_user_preference('scorm_report_interactions_qtext', $includeqtext);
            set_user_preference('scorm_report_interactions_resp', $includeresp);
            set_user_preference('scorm_report_interactions_right', $includeright);
        } else {
            $pagesize = get_user_preferences('scorm_report_pagesize', 0);
            $includeqtext = get_user_preferences('scorm_report_interactions_qtext', 0);
            $includeresp = get_user_preferences('scorm_report_interactions_resp', 1);
            $includeright = get_user_preferences('scorm_report_interactions_right', 0);
        }
        if ($pagesize < 1) {
            $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
        }

        // select group menu
        $displayoptions = array();
        $displayoptions['attemptsmode'] = $attemptsmode;
        $displayoptions['qtext'] = $includeqtext;
        $displayoptions['resp'] = $includeresp;
        $displayoptions['right'] = $includeright;

        $mform->set_data($displayoptions + array('pagesize' => $pagesize));
        if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
            if (!$download) {
                groups_print_activity_menu($cm, new moodle_url($PAGE->url, $displayoptions));
            }
        }
        $formattextoptions = array('context' => get_context_instance(CONTEXT_COURSE, $course->id));

        // We only want to show the checkbox to delete attempts
        // if the user has permissions and if the report mode is showing attempts.
        $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
                && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
        // select the students
        $nostudents = false;

        if (empty($currentgroup)) {
            // all users who can attempt scoes
            if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', '', '', '', '', '', '', false)) {
                echo $OUTPUT->notification(get_string('nostudentsyet'));
                $nostudents = true;
                $allowedlist = '';
            } else {
                $allowedlist = array_keys($students);
            }
        } else {
            // all users who can attempt scoes and who are in the currently selected group
            if (!$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', '', '', '', '', $currentgroup, '', false)) {
                echo $OUTPUT->notification(get_string('nostudentsingroup'));
                $nostudents = true;
                $groupstudents = array();
            }
            $allowedlist = array_keys($groupstudents);
        }
        if ( !$nostudents ) {
            // Now check if asked download of data
            $coursecontext = context_course::instance($course->id);
            if ($download) {
                $filename = clean_filename("$course->shortname ".format_string($scorm->name, true,$formattextoptions));
            }

            // Define table columns
            $columns = array();
            $headers = array();
            if (!$download && $candelete) {
                $columns[] = 'checkbox';
                $headers[] = null;
            }
            if (!$download && $CFG->grade_report_showuserimage) {
                $columns[] = 'picture';
                $headers[] = '';
            }
            $columns[] = 'fullname';
            $headers[] = get_string('name');

            $extrafields = get_extra_user_fields($coursecontext);
            foreach ($extrafields as $field) {
                $columns[] = $field;
                $headers[] = get_user_field_name($field);
            }
            $columns[] = 'attempt';
            $headers[] = get_string('attempt', 'scorm');
            $columns[] = 'start';
            $headers[] = get_string('started', 'scorm');
            $columns[] = 'finish';
            $headers[] = get_string('last', 'scorm');
            $columns[] = 'score';
            $headers[] = get_string('score', 'scorm');
            $scoes = $DB->get_records('scorm_scoes', array("scorm"=>$scorm->id), 'id');
            foreach ($scoes as $sco) {
                if ($sco->launch != '') {
                    $columns[] = 'scograde'.$sco->id;
                    $headers[] = format_string($sco->title,'',$formattextoptions);
                }
            }

            $params = array();
            list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED);
                                    // Construct the SQL
            $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
            $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
                    'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email'.
                    get_extra_user_fields_sql($coursecontext, 'u', '', array('idnumber')) . ' ';

            // This part is the same for all cases - join users and scorm_scoes_track tables
            $from = 'FROM {user} u ';
            $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id;
            switch ($attemptsmode) {
                case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
                    // Show only students with attempts
                    $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL';
                    break;
                case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
                    // Show only students without attempts
                    $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL';
                    break;
                case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
                    // Show all students with or without attempts
                    $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)';
                    break;
            }

            $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
            $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'st.attempt').')) AS nbattempts, ';
            $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
            $countsql .= $from.$where;
            $attempts = $DB->get_records_sql($select.$from.$where, $params);
            $questioncount = get_scorm_question_count($scorm->id);
            for($id = 0; $id < $questioncount; $id++) {
                if ($displayoptions['qtext']) {
                    $columns[] = 'question' . $id;
                    $headers[] = get_string('questionx', 'scormreport_interactions', $id);
                }
                if ($displayoptions['resp']) {
                    $columns[] = 'response' . $id;
                    $headers[] = get_string('responsex', 'scormreport_interactions', $id);
                }
                if ($displayoptions['right']) {
                    $columns[] = 'right' . $id;
                    $headers[] = get_string('rightanswerx', 'scormreport_interactions', $id);
                }
            }

            if (!$download) {
                $table = new flexible_table('mod-scorm-report');

                $table->define_columns($columns);
                $table->define_headers($headers);
                $table->define_baseurl($PAGE->url);

                $table->sortable(true);
                $table->collapsible(true);

                // This is done to prevent redundant data, when a user has multiple attempts
                $table->column_suppress('picture');
                $table->column_suppress('fullname');
                foreach ($extrafields as $field) {
                    $table->column_suppress($field);
                }

                $table->no_sorting('start');
                $table->no_sorting('finish');
                $table->no_sorting('score');

                foreach ($scoes as $sco) {
                    if ($sco->launch != '') {
                        $table->no_sorting('scograde'.$sco->id);
                    }
                }

                $table->column_class('picture', 'picture');
                $table->column_class('fullname', 'bold');
                $table->column_class('score', 'bold');

                $table->set_attribute('cellspacing', '0');
                $table->set_attribute('id', 'attempts');
                $table->set_attribute('class', 'generaltable generalbox');

                // Start working -- this is necessary as soon as the niceties are over
                $table->setup();
            } else if ($download == 'ODS') {
                require_once("$CFG->libdir/odslib.class.php");

                $filename .= ".ods";
                // Creating a workbook
                $workbook = new MoodleODSWorkbook("-");
                // Sending HTTP headers
                $workbook->send($filename);
                // Creating the first worksheet
                $sheettitle = get_string('report', 'scorm');
                $myxls =& $workbook->add_worksheet($sheettitle);
                // format types
                $format =& $workbook->add_format();
                $format->set_bold(0);
                $formatbc =& $workbook->add_format();
                $formatbc->set_bold(1);
                $formatbc->set_align('center');
                $formatb =& $workbook->add_format();
                $formatb->set_bold(1);
                $formaty =& $workbook->add_format();
                $formaty->set_bg_color('yellow');
                $formatc =& $workbook->add_format();
                $formatc->set_align('center');
                $formatr =& $workbook->add_format();
                $formatr->set_bold(1);
                $formatr->set_color('red');
                $formatr->set_align('center');
                $formatg =& $workbook->add_format();
                $formatg->set_bold(1);
                $formatg->set_color('green');
                $formatg->set_align('center');
                // Here starts workshhet headers

                $colnum = 0;
                foreach ($headers as $item) {
                    $myxls->write(0, $colnum, $item, $formatbc);
                    $colnum++;
                }
                $rownum = 1;
            } else if ($download =='Excel') {
                require_once("$CFG->libdir/excellib.class.php");

                $filename .= ".xls";
                // Creating a workbook
                $workbook = new MoodleExcelWorkbook("-");
                // Sending HTTP headers
                $workbook->send($filename);
                // Creating the first worksheet
                $sheettitle = get_string('report', 'scorm');
                $myxls =& $workbook->add_worksheet($sheettitle);
                // format types
                $format =& $workbook->add_format();
                $format->set_bold(0);
                $formatbc =& $workbook->add_format();
                $formatbc->set_bold(1);
                $formatbc->set_align('center');
                $formatb =& $workbook->add_format();
                $formatb->set_bold(1);
                $formaty =& $workbook->add_format();
                $formaty->set_bg_color('yellow');
                $formatc =& $workbook->add_format();
                $formatc->set_align('center');
                $formatr =& $workbook->add_format();
                $formatr->set_bold(1);
                $formatr->set_color('red');
                $formatr->set_align('center');
                $formatg =& $workbook->add_format();
                $formatg->set_bold(1);
                $formatg->set_color('green');
                $formatg->set_align('center');

                $colnum = 0;
                foreach ($headers as $item) {
                    $myxls->write(0, $colnum, $item, $formatbc);
                    $colnum++;
                }
                $rownum = 1;
            } else if ($download == 'CSV') {
                $filename .= ".txt";
                header("Content-Type: application/download\n");
                header("Content-Disposition: attachment; filename=\"$filename\"");
                header("Expires: 0");
                header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
                header("Pragma: public");
                echo implode("\t", $headers)." \n";
            }

            if (!$download) {
                $sort = $table->get_sql_sort();
            } else {
                $sort = '';
            }
            // Fix some wired sorting
            if (empty($sort)) {
                $sort = ' ORDER BY uniqueid';
            } else {
                $sort = ' ORDER BY '.$sort;
            }

            if (!$download) {
                // Add extra limits due to initials bar
                list($twhere, $tparams) = $table->get_sql_where();
                if ($twhere) {
                    $where .= ' AND '.$twhere; //initial bar
                    $params = array_merge($params, $tparams);
                }

                if (!empty($countsql)) {
                    $count = $DB->get_record_sql($countsql,$params);
                    $totalinitials = $count->nbresults;
                    if ($twhere) {
                        $countsql .= ' AND '.$twhere;
                    }
                    $count = $DB->get_record_sql($countsql, $params);
                    $total  = $count->nbresults;
                }

                $table->pagesize($pagesize, $total);

                echo '<div class="quizattemptcounts">';
                if ( $count->nbresults == $count->nbattempts ) {
                    echo get_string('reportcountattempts', 'scorm', $count);
                } else if ( $count->nbattempts>0 ) {
                    echo get_string('reportcountallattempts', 'scorm', $count);
                } else {
                    echo $count->nbusers.' '.get_string('users');
                }
                echo '</div>';
            }

            // Fetch the attempts
            if (!$download) {
                $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
                $table->get_page_start(), $table->get_page_size());
                echo '<div id="scormtablecontainer">';
                if ($candelete) {
                    // Start form
                    $strreallydel  = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
                    echo '<form id="attemptsform" method="post" action="' . $PAGE->url->out(false) .
                         '" onsubmit="return confirm(\''.$strreallydel.'\');">';
                    echo '<input type="hidden" name="action" value="delete"/>';
                    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
                    echo '<div style="display: none;">';
                    echo html_writer::input_hidden_params($PAGE->url);
                    echo '</div>';
                    echo '<div>';
                }
                $table->initialbars($totalinitials>20); // Build table rows
            } else {
                $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
            }
            if ($attempts) {
                foreach ($attempts as $scouser) {
                    $row = array();
                    if (!empty($scouser->attempt)) {
                        $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
                    } else {
                        $timetracks = '';
                    }
                    if (in_array('checkbox', $columns)) {
                        if ($candelete && !empty($timetracks->start)) {
                            $row[] = '<input type="checkbox" name="attemptid[]" value="'. $scouser->userid . ':' . $scouser->attempt . '" />';
                        } else if ($candelete) {
                            $row[] = '';
                        }
                    }
                    if (in_array('picture', $columns)) {
                        $user = (object)array(
                                    'id'=>$scouser->userid,
                                    'picture'=>$scouser->picture,
                                    'imagealt'=>$scouser->imagealt,
                                    'email'=>$scouser->email,
                                    'firstname'=>$scouser->firstname,
                                    'lastname'=>$scouser->lastname);
                        $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
                    }
                    if (!$download) {
                        $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&amp;course='.$course->id.'">'.fullname($scouser).'</a>';
                    } else {
                        $row[] = fullname($scouser);
                    }
                    foreach ($extrafields as $field) {
                        $row[] = s($scouser->{$field});
                    }
                    if (empty($timetracks->start)) {
                        $row[] = '-';
                        $row[] = '-';
                        $row[] = '-';
                        $row[] = '-';
                    } else {
                        if (!$download) {
                            $row[] = '<a href="userreport.php?a='.$scorm->id.'&amp;user='******'&amp;attempt='.$scouser->attempt.'">'.$scouser->attempt.'</a>';
                        } else {
                            $row[] = $scouser->attempt;
                        }
                        if ($download =='ODS' || $download =='Excel' ) {
                            $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
                        } else {
                            $row[] = userdate($timetracks->start);
                        }
                        if ($download =='ODS' || $download =='Excel' ) {
                            $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
                        } else {
                            $row[] = userdate($timetracks->finish);
                        }
                        $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
                    }
                    // print out all scores of attempt
                    foreach ($scoes as $sco) {
                        if ($sco->launch != '') {
                            if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
                                if ($trackdata->status == '') {
                                    $trackdata->status = 'notattempted';
                                }
                                $strstatus = get_string($trackdata->status, 'scorm');
                                // if raw score exists, print it
                                if ($trackdata->score_raw != '') {
                                    $score = $trackdata->score_raw;
                                    // add max score if it exists
                                    if ($scorm->version == 'SCORM_1.3') {
                                        $maxkey = 'cmi.score.max';
                                    } else {
                                        $maxkey = 'cmi.core.score.max';
                                    }
                                    if (isset($trackdata->$maxkey)) {
                                        $score .= '/'.$trackdata->$maxkey;
                                    }
                                // else print out status
                                } else {
                                    $score = $strstatus;
                                }
                                if (!$download) {
                                    $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>
                                            <a href="userreport.php?b='.$sco->id.'&amp;user='******'&amp;attempt='.$scouser->attempt.
                                            '" title="'.get_string('details', 'scorm').'">'.$score.'</a>';
                                } else {
                                    $row[] = $score;
                                }
                                // interaction data
                                $i=0;
                                $element='cmi.interactions_'.$i.'.id';
                                while(isset($trackdata->$element)) {
                                    if ($displayoptions['qtext']) {
                                        $element='cmi.interactions_'.$i.'.id';
                                        if (isset($trackdata->$element)) {
                                            $row[] = s($trackdata->$element);
                                        } else {
                                            $row[] = '&nbsp;';
                                        }
                                    }
                                    if ($displayoptions['resp']) {
                                        $element='cmi.interactions_'.$i.'.student_response';
                                        if (isset($trackdata->$element)) {
                                            $row[] = s($trackdata->$element);
                                        } else {
                                            $row[] = '&nbsp;';
                                        }
                                    }
                                    if ($displayoptions['right']) {
                                        $j=0;
                                        $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
                                        $rightans = '';
                                        if (isset($trackdata->$element)) {
                                            while(isset($trackdata->$element)) {
                                                if($j>0) {
                                                    $rightans .= ',';
                                                }
                                                $rightans .= s($trackdata->$element);
                                                $j++;
                                                $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
                                            }
                                            $row[] = $rightans;
                                        } else {
                                            $row[] = '&nbsp;';
                                        }
                                    }
                                    $i++;
                                    $element = 'cmi.interactions_'.$i.'.id';
                                }
                            //---end of interaction data*/
                            } else {
                                // if we don't have track data, we haven't attempted yet
                                $strstatus = get_string('notattempted', 'scorm');
                                if (!$download) {
                                    $row[] = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>'.$strstatus;
                                } else {
                                    $row[] = $strstatus;
                                }
                            }
                        }
                    }

                    if (!$download) {
                        $table->add_data($row);
                    } else if ($download == 'Excel' or $download == 'ODS') {
                        $colnum = 0;
                        foreach ($row as $item) {
                            $myxls->write($rownum, $colnum, $item, $format);
                            $colnum++;
                        }
                        $rownum++;
                    } else if ($download == 'CSV') {
                        $text = implode("\t", $row);
                        echo $text." \n";
                    }
                }
                if (!$download) {
                    $table->finish_output();
                    if ($candelete) {
                        echo '<table id="commands">';
                        echo '<tr><td>';
                        echo '<a href="javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
                             get_string('selectall', 'scorm').'</a> / ';
                        echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
                             get_string('selectnone', 'scorm').'</a> ';
                        echo '&nbsp;&nbsp;';
                        echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
                        echo '</td></tr></table>';
                        // Close form
                        echo '</div>';
                        echo '</form>';
                    }
                    echo '</div>';
                    if (!empty($attempts)) {
                        echo '<table class="boxaligncenter"><tr>';
                        echo '<td>';
                        echo $OUTPUT->single_button(new moodle_url($PAGE->url,
                                                                   array('download'=>'ODS') + $displayoptions),
                                                                   get_string('downloadods'));
                        echo "</td>\n";
                        echo '<td>';
                        echo $OUTPUT->single_button(new moodle_url($PAGE->url,
                                                                   array('download'=>'Excel') + $displayoptions),
                                                                   get_string('downloadexcel'));
                        echo "</td>\n";
                        echo '<td>';
                        echo $OUTPUT->single_button(new moodle_url($PAGE->url,
                                                                   array('download'=>'CSV') + $displayoptions),
                                                                   get_string('downloadtext'));
                        echo "</td>\n";
                        echo "<td>";
                        echo "</td>\n";
                        echo '</tr></table>';
                    }
                }
            } else {
                if ($candelete && !$download) {
                    echo '</div>';
                    echo '</form>';
                    $table->finish_output();
                }
                echo '</div>';
            }
            // Show preferences form irrespective of attempts are there to report or not
            if (!$download) {
                $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
                $mform->display();
            }
            if ($download == 'Excel' or $download == 'ODS') {
                $workbook->close();
                exit;
            } else if ($download == 'CSV') {
                exit;
            }
        } else {
            echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
        }
    }// function ends
Esempio n. 5
0
/// because it retrieves ALL users (without role checking) - MDL-14034
if ($table->get_sql_sort()) {
    $sort = ' ORDER BY ' . $table->get_sql_sort();
    if ($context->id != $frontpagectx->id or $roleid >= 0) {
        $sort .= ', r.hidden DESC';
    }
} else {
    $sort = '';
    if ($context->id != $frontpagectx->id or $roleid >= 0) {
        $sort .= ' ORDER BY r.hidden DESC';
    }
}
$matchcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) {$from} {$where} {$wheresearch}", $params);
$table->initialbars(true);
$table->pagesize($perpage, $matchcount);
$userlist = $DB->get_recordset_sql("{$select} {$from} {$where} {$wheresearch} {$sort}", $params, $table->get_page_start(), $table->get_page_size());
//
// The SELECT behind get_participants_extra() is cheaper if we pass an array
// if IDs. We could pass the SELECT we did before (with the limit bits - tricky!)
// but this is much cheaper. And in any case, it is only doable with limited numbers
// of rows anyway. On a large course it will explode badly...
//
if ($mode === MODE_ENROLDETAILS) {
    if ($context->id != $frontpagectx->id) {
        $userids = $DB->get_fieldset_sql("SELECT DISTINCT u.id {$from} {$where} {$wheresearch}", $params, $table->get_page_start(), $table->get_page_size());
    } else {
        $userids = $DB->get_fieldset_sql("SELECT u.id {$from} {$where} {$wheresearch}", $params, $table->get_page_start(), $table->get_page_size());
    }
    $userlist_extra = get_participants_extra($userids, $avoidroles, $course, $context);
}
if ($context->id == $frontpagectx->id) {
Esempio n. 6
0
        $where = "";
    }

    if ($table->get_sql_sort()) {
        $sort = ' ORDER BY '.$table->get_sql_sort();
    } else {
        $sort = '';
    }

    $matchcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);

    $table->initialbars(true);
    $table->pagesize($perpage, $matchcount);

    // list of users at the current visible page - paging makes it relatively short
    $userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table->get_page_start(), $table->get_page_size());

    /// If there are multiple Roles in the course, then show a drop down menu for switching
    if (count($rolenames) > 1) {
        echo '<div class="rolesform">';
        echo '<label for="rolesform_jump">'.get_string('currentrole', 'role').'&nbsp;</label>';
        echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, 'rolesform');
        echo '</div>';

    } else if (count($rolenames) == 1) {
        // when all users with the same role - print its name
        echo '<div class="rolesform">';
        echo get_string('role').get_string('labelsep', 'langconfig');
        $rolename = reset($rolenames);
        echo $rolename;
        echo '</div>';
         $usedgroupid = $mygroupid;
     } else {
         $usedgroupid = false;
     }
 } else {
     $usedgroupid = false;
 }
 $matchcount = feedback_count_complete_users($cm, $usedgroupid);
 $table->initialbars(true);
 if ($showall) {
     $startpage = false;
     $pagecount = false;
 } else {
     $table->pagesize($perpage, $matchcount);
     $startpage = $table->get_page_start();
     $pagecount = $table->get_page_size();
 }
 $students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);
 $completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid);
 if ($feedback->course == SITEID) {
     $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id, 'courseid' => $courseid));
     echo $OUTPUT->box_start('mdl-align');
     echo '<a href="' . $analysisurl->out() . '">' . get_string('course') . ' ' . get_string('analysis', 'feedback') . ' (' . get_string('completed_feedbacks', 'feedback') . ': ' . intval($completedFeedbackCount) . ')</a>';
     echo $OUTPUT->help_icon('viewcompleted', 'feedback');
     echo $OUTPUT->box_end();
 } else {
     $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $id, 'courseid' => $courseid));
     echo $OUTPUT->box_start('mdl-align');
     echo '<a href="' . $analysisurl->out() . '">' . get_string('analysis', 'feedback') . ' (' . get_string('completed_feedbacks', 'feedback') . ': ' . intval($completedFeedbackCount) . ')</a>';
     echo $OUTPUT->box_end();
 }
Esempio n. 8
0
$table->no_sorting('grade');
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
/// Construct the SQL
list($where, $params) = $table->get_sql_where();
if ($where) {
    $where .= ' AND ';
}
if ($sort = $table->get_sql_sort()) {
    $sort = ' ORDER BY ' . $sort;
}
$ufields = user_picture::fields('u', $extrafields);
if (!empty($users)) {
    $select = "SELECT {$ufields} ";
    $sql = 'FROM {user} u ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
    $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size());
    if ($ausers !== false) {
        //$grading_info = grade_get_grades($course->id, 'mod', 'jclic', $jclic->id, array_keys($ausers));
        $countusers = 0;
        foreach ($ausers as $auser) {
            $sessions_summary = jclic_get_sessions_summary($jclic->id, $auser->id);
            if ($sessions_summary->attempts <= 0) {
                continue;
            }
            $countusers++;
            $picture = $OUTPUT->user_picture($auser);
            $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>';
            $extradata = array();
            foreach ($extrafields as $field) {
                $extradata[] = $auser->{$field};
            }
Esempio n. 9
0
    }
    if ($table->get_sql_sort()) {
        $sql .= ' ORDER BY ' . $table->get_sql_sort();
    }
    $countsql = "SELECT COUNT(DISTINCT(ra.userid))\n                       FROM {$CFG->prefix}role_assignments ra\n                      WHERE ra.contextid {$relatedcontexts} AND ra.roleid = {$roleid}";
    $totalcount = count_records_sql($countsql);
    if ($table->get_sql_where()) {
        $matchcount = count_records_sql($countsql . ' AND ' . $table->get_sql_where());
    } else {
        $matchcount = $totalcount;
    }
    echo '<div id="participationreport">' . "\n";
    echo '<p class="modulename">' . $modulename . ' ' . $strviews . ': ' . implode(', ', $viewnames) . '<br />' . "\n" . $modulename . ' ' . $strposts . ': ' . implode(', ', $postnames) . '</p>' . "\n";
    $table->initialbars($totalcount > $perpage);
    $table->pagesize($perpage, $matchcount);
    if (!($users = get_records_sql($sql, $table->get_page_start(), $table->get_page_size()))) {
        $users = array();
        // tablelib will handle saying 'Nothing to display' for us.
    }
    $data = array();
    $a->count = $totalcount;
    $a->items = $role->name;
    if ($matchcount != $totalcount) {
        $a->count = $matchcount . '/' . $a->count;
    }
    echo '<h2>' . get_string('counteditems', '', $a) . '</h2>' . "\n";
    echo '
<script type="text/javascript">
//<![CDATA[
function checksubmit(form) {
    var destination = form.formaction.options[form.formaction.selectedIndex].value;
Esempio n. 10
0
        case 'time':
            $databaseOrder = 'o.timesent %DIR%';
            break;
    }
    if ($direction == SORT_ASC) {
        $databaseOrder = str_replace('%DIR%', 'ASC', $databaseOrder);
    } else {
        $databaseOrder = str_replace('%DIR%', 'DESC', $databaseOrder);
    }
    if ($orderBy != '') {
        $databaseOrder = ', ' . $databaseOrder;
    }
    $orderBy .= $databaseOrder;
}
// All parameters *MUST* be sorted out by here - getting messages
$sentMessages = $sentMessagesDAO->getSentMessagesForUser($userToView, $orderBy, 0, 0, $table->get_page_start(), $table->get_page_size(), $includeEvents);
// Populate table
foreach ($sentMessages as $message) {
    if ($table->is_downloading()) {
        $messageContent = $message->getMessageText();
    } else {
        $messageContent = html_writer::tag('a', $message->getMessageText(), array('href' => 'status.php?message=' . $message->getId() . '&course=' . $courseId . '&instance=' . $instanceId));
    }
    $rowData = array($message->getUser()->getFullNameForDisplay(!$table->is_downloading()), $message->getTxttoolsAccount()->getUsername(), $messageContent, $message->getTimeSent('%H:%M:%S,  %d %B %Y'));
    if ($includeEvents == TxttoolsSentMessageDAO::$EVENT_QUERY_INCLUDE || $includeEvents == TxttoolsSentMessageDAO::$EVENT_QUERY_EXCLUSIVE) {
        $eventStr = $message->isEventCreated() ? get_string('fragsystem', 'block_moodletxt') : get_string('fraguser', 'block_moodletxt');
        array_push($rowData, $eventStr);
    }
    $table->add_data($rowData);
}
$table->finish_output();
 if ($where = $table->get_sql_where()) {
     $where .= ' AND ';
 }
 if ($sort = $table->get_sql_sort()) {
     $sort = ' ORDER BY ' . $sort;
 }
 $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, COUNT(s.id) AS count ';
 $sql = 'FROM ' . $CFG->prefix . 'user AS u ' . 'LEFT JOIN ' . $CFG->prefix . 'stampcoll_stamps s ON u.id = s.userid AND s.stampcollid = ' . $stampcoll->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', array_keys($users)) . ') ' . 'GROUP BY u.id, u.firstname, u.lastname, u.picture ';
 if (!$stampcoll->displayzero) {
     $sql .= 'HAVING COUNT(s.id) > 0 ';
 }
 // First query with not limits to get the number of returned rows
 if (($ausers = get_records_sql($select . $sql . $sort)) !== false) {
     $table->pagesize($perpage, count($ausers));
     // Second query with pagination limits
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         foreach ($ausers as $auser) {
             $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true);
             $fullname = fullname($auser);
             $count = $auser->count;
             $stamps = '';
             if (isset($userstamps[$auser->id])) {
                 foreach ($userstamps[$auser->id] as $s) {
                     $stamps .= stampcoll_stamp($s, $stampcoll->image);
                 }
                 unset($s);
             }
             $row = array($picture, $fullname, $count, $stamps);
             $table->add_data($row);
         }
     }
Esempio n. 12
0
$table->setup();

if ($sort = $table->get_sql_sort()) {
    $sort = ' ORDER BY ' . $sort;
}

$sql = 'SELECT * FROM {facetoface_room} WHERE custom = 0';

$perpage = 25;

$totalcount = $DB->count_records_select('facetoface_room', 'custom = 0');

$table->initialbars($totalcount > $perpage);
$table->pagesize($perpage, $totalcount);

$rooms = $DB->get_records_sql($sql.$sort, array(), $table->get_page_start(), $table->get_page_size());

$rooms_in_use = array_keys($DB->get_records_sql('SELECT DISTINCT(roomid) FROM {facetoface_sessions}'));

foreach ($rooms as $room) {
    $row = array();
    $buttons = array();

    $row[] = $room->name;
    $row[] = $room->building;
    $row[] = $room->address;
    $row[] = $room->capacity;

    $editbutton = '';
    $deletebutton = '';
    /*commented by hameed on 21 dec reg: bug fix*/
 public function display_allfilesform()
 {
     global $CFG, $OUTPUT, $DB, $USER;
     $cm = $this->coursemodule;
     $context = $this->context;
     $course = $this->course;
     $updatepref = optional_param('updatepref', 0, PARAM_BOOL);
     if ($updatepref) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         $filter = optional_param('filter', 0, PARAM_INT);
         set_user_preference('publication_perpage', $perpage);
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('publication_perpage', 10);
     $quickgrade = get_user_preferences('publication_quickgrade', 0);
     $filter = get_user_preferences('publicationfilter', 0);
     $page = optional_param('page', 0, PARAM_INT);
     $formattrs = array();
     $formattrs['action'] = new moodle_url('/mod/publication/view.php');
     $formattrs['id'] = 'fastg';
     $formattrs['method'] = 'post';
     $formattrs['class'] = 'mform';
     $html = '';
     $html .= html_writer::start_tag('form', $formattrs);
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $this->get_coursemodule()->id));
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $page));
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
     echo $html;
     echo html_writer::start_tag('div', array('id' => 'id_allfiles', 'class' => 'clearfix', 'aria-live' => 'polite'));
     $title = has_capability('mod/publication:approve', $context) ? get_string('allfiles', 'publication') : get_string('publicfiles', 'publication');
     echo html_writer::tag('div', $title, array('class' => 'legend'));
     echo html_writer::start_div('fcontainer clearfix');
     // Check to see if groups are being used in this assignment.
     // Find out current groups mode.
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     echo groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/publication/view.php?id=' . $cm->id, true);
     $html = '';
     // Get all ppl that are allowed to submit assignments.
     list($esql, $params) = get_enrolled_sql($context, 'mod/publication:view', $currentgroup);
     $showall = false;
     if (has_capability('mod/publication:approve', $context) || has_capability('mod/publication:grantextension', $context)) {
         $showall = true;
     }
     if ($showall) {
         $sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'WHERE u.deleted = 0 AND eu.id=u.id ';
     } else {
         $sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'LEFT JOIN {publication_file} files ON (u.id = files.userid) ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . 'AND files.publication = ' . $this->get_instance()->id . ' ';
         if ($this->get_instance()->mode == PUBLICATION_MODE_UPLOAD) {
             // Node upload.
             if ($this->get_instance()->obtainteacherapproval) {
                 // Need teacher approval.
                 $where = 'files.teacherapproval = 1';
             } else {
                 // No need for teacher approval.
                 // Teacher only hasnt rejected.
                 $where = '(files.teacherapproval = 1 OR files.teacherapproval IS NULL)';
             }
         } else {
             // Mode import.
             if (!$this->get_instance()->obtainstudentapproval) {
                 // No need to ask student and teacher has approved.
                 $where = 'files.teacherapproval = 1';
             } else {
                 // Student and teacher have approved.
                 $where = 'files.teacherapproval = 1 AND files.studentapproval = 1';
             }
         }
         $sql .= 'AND ' . $where . ' ';
         $sql .= 'GROUP BY u.id';
     }
     $users = $DB->get_records_sql($sql, $params);
     if (!empty($users)) {
         $users = array_keys($users);
     }
     // If groupmembersonly used, remove users who are not in any group.
     if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $selectallnone = html_writer::checkbox('selectallnone', false, false, '', array('id' => 'selectallnone', 'onClick' => 'toggle_userselection()'));
     $tablecolumns = array('selection', 'fullname');
     $tableheaders = array($selectallnone, get_string('fullnameuser'));
     $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array();
     foreach ($useridentity as $cur) {
         if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) {
             $tablecolumns[] = $cur;
             $tableheaders[] = $cur == 'phone1' ? get_string('phone') : get_string($cur);
         }
     }
     $tableheaders[] = get_string('lastmodified');
     $tablecolumns[] = 'timemodified';
     if (has_capability('mod/publication:approve', $context)) {
         // Not necessary in upload mode without studentapproval.
         if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) {
             $tablecolumns[] = 'studentapproval';
             $tableheaders[] = get_string('studentapproval', 'publication') . ' ' . $OUTPUT->help_icon('studentapproval', 'publication');
         }
         $tablecolumns[] = 'teacherapproval';
         if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) {
             $tableheaders[] = get_string('obtainstudentapproval', 'publication');
         } else {
             $tableheaders[] = get_string('teacherapproval', 'publication');
         }
         $tablecolumns[] = 'visibleforstudents';
         $tableheaders[] = get_string('visibleforstudents', 'publication');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-publication-allfiles');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/publication/view.php?id=' . $cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     // Sorted by lastname by default.
     $table->collapsible(false);
     $table->initialbars(true);
     $table->column_class('fullname', 'fullname');
     $table->column_class('timemodified', 'timemodified');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'publications');
     $table->set_attribute('width', '100%');
     $table->no_sorting('studentapproval');
     $table->no_sorting('selection');
     $table->no_sorting('teacherapproval');
     $table->no_sorting('visibleforstudents');
     // Start working -- this is necessary as soon as the niceties are over.
     $table->setup();
     // Construct the SQL.
     list($where, $params) = $table->get_sql_where();
     if ($where) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $ufields = user_picture::fields('u');
     $useridentityfields = $CFG->showuseridentity != '' ? 'u.' . str_replace(', ', ', u.', $CFG->showuseridentity) . ', ' : '';
     $totalfiles = 0;
     if (!empty($users)) {
         $select = 'SELECT ' . $ufields . ', ' . $useridentityfields . ' username,
                             COUNT(*) filecount,
                             SUM(files.studentapproval) as status,
                             MAX(files.timecreated) timemodified ';
         $sql = 'FROM {user} u ' . 'LEFT JOIN {publication_file} files ON u.id = files.userid
                         AND files.publication = ' . $this->get_instance()->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(', ', $users) . ') ' . 'GROUP BY ' . $ufields . ', ' . $useridentityfields . ' username ';
         $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size());
         $table->pagesize($perpage, count($users));
         // Offset used to calculate index of student in that particular query, needed for the pop up to know who's next.
         $offset = $page * $perpage;
         $strupdate = get_string('update');
         if ($ausers !== false) {
             $endposition = $offset + $perpage;
             $currentposition = 0;
             $valid = $OUTPUT->pix_icon('i/valid', get_string('student_approved', 'publication'));
             $questionmark = $OUTPUT->pix_icon('questionmark', get_string('student_pending', 'publication'), 'mod_publication');
             $invalid = $OUTPUT->pix_icon('i/invalid', get_string('student_rejected', 'publication'));
             $visibleforstundetsyes = $OUTPUT->pix_icon('i/valid', get_string('visibleforstudents_yes', 'publication'));
             $visibleforstundetsno = $OUTPUT->pix_icon('i/invalid', get_string('visibleforstudents_no', 'publication'));
             $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context);
             foreach ($ausers as $auser) {
                 if ($currentposition >= $offset && $currentposition < $endposition) {
                     // Calculate user status.
                     $selecteduser = html_writer::checkbox('selectedeuser[' . $auser->id . ']', 'selected', false, null, array('class' => 'userselection'));
                     $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array();
                     foreach ($useridentity as $cur) {
                         if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) {
                             if (!empty($auser->{$cur})) {
                                 ${$cur} = html_writer::tag('div', $auser->{$cur}, array('id' => 'u' . $cur . $auser->id));
                             } else {
                                 ${$cur} = html_writer::tag('div', '-', array('id' => 'u' . $cur . $auser->id));
                             }
                         }
                     }
                     $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, $viewfullnames) . '</a>';
                     $extension = $this->user_extensionduedate($auser->id);
                     if ($extension) {
                         if (has_capability('mod/publication:grantextension', $context) || has_capability('mod/publication:approve', $context)) {
                             $userlink .= '<br/>' . get_string('extensionto', 'publication') . ': ' . userdate($extension);
                         }
                     }
                     $row = array($selecteduser, $userlink);
                     $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array();
                     foreach ($useridentity as $cur) {
                         if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) {
                             if (true) {
                                 $row[] = ${$cur};
                             } else {
                                 $row[] = "";
                             }
                         }
                     }
                     $filearea = 'attachment';
                     $sid = $auser->id;
                     $fs = get_file_storage();
                     $files = $fs->get_area_files($this->get_context()->id, 'mod_publication', $filearea, $sid, 'timemodified', false);
                     $filetable = new html_table();
                     $filetable->attributes = array('class' => 'filetable');
                     $statustable = new html_table();
                     $statustable->attributes = array('class' => 'statustable');
                     $permissiontable = new html_table();
                     $permissiontable->attributes = array('class' => 'permissionstable');
                     $visibleforuserstable = new html_table();
                     $visibleforuserstable->attributes = array('class' => 'statustable');
                     $conditions = array();
                     $conditions['publication'] = $this->get_instance()->id;
                     $conditions['userid'] = $auser->id;
                     foreach ($files as $file) {
                         $conditions['fileid'] = $file->get_id();
                         $filepermissions = $DB->get_record('publication_file', $conditions);
                         $showfile = false;
                         if (has_capability('mod/publication:approve', $context)) {
                             $showfile = true;
                         } else {
                             if ($this->has_filepermission($file->get_id())) {
                                 $showfile = true;
                             }
                         }
                         if ($this->has_filepermission($file->get_id())) {
                             $visibleforuserstable->data[] = array($visibleforstundetsyes);
                         } else {
                             $visibleforuserstable->data[] = array($visibleforstundetsno);
                         }
                         if ($showfile) {
                             $filerow = array();
                             $filerow[] = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file));
                             $url = new moodle_url('/mod/publication/view.php', array('id' => $cm->id, 'download' => $file->get_id()));
                             $filerow[] = html_writer::link($url, $file->get_filename());
                             if (has_capability('mod/publication:approve', $context)) {
                                 $checked = $filepermissions->teacherapproval;
                                 if (is_null($checked)) {
                                     $checked = "";
                                 } else {
                                     $checked = $checked + 1;
                                 }
                                 $permissionrow = array();
                                 $options = array();
                                 $options['2'] = get_string('yes');
                                 $options['1'] = get_string('no');
                                 $permissionrow[] = html_writer::select($options, 'files[' . $file->get_id() . ']', $checked);
                                 $statusrow = array();
                                 if (is_null($filepermissions->studentapproval)) {
                                     $statusrow[] = $questionmark;
                                 } else {
                                     if ($filepermissions->studentapproval) {
                                         $statusrow[] = $valid;
                                     } else {
                                         $statusrow[] = $invalid;
                                     }
                                 }
                                 $statustable->data[] = $statusrow;
                                 $permissiontable->data[] = $permissionrow;
                             }
                             $filetable->data[] = $filerow;
                             $totalfiles++;
                         }
                     }
                     $lastmodified = "";
                     if (count($filetable->data) > 0) {
                         $lastmodified = html_writer::table($filetable);
                         $lastmodified .= html_writer::span(userdate($auser->timemodified), "timemodified");
                     } else {
                         $lastmodified = get_string('nofiles', 'publication');
                     }
                     $row[] = $lastmodified;
                     if (has_capability('mod/publication:approve', $context)) {
                         // Not necessary in upload mode without studentapproval.
                         if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) {
                             if (count($statustable->data) > 0) {
                                 $status = html_writer::table($statustable);
                             } else {
                                 $status = '';
                             }
                             $row[] = $status;
                         }
                         if (count($permissiontable->data) > 0) {
                             $permissions = html_writer::table($permissiontable);
                         } else {
                             $permissions = '';
                         }
                         $row[] = $permissions;
                         $row[] = html_writer::table($visibleforuserstable);
                     }
                     $table->add_data($row);
                 }
                 $currentposition++;
             }
             if (true) {
                 // Always display download option.
                 $html .= html_writer::start_tag('div', array('class' => 'mod-publication-download-link'));
                 $html .= html_writer::link(new moodle_url('/mod/publication/view.php', array('id' => $this->coursemodule->id, 'action' => 'zip')), get_string('downloadall', 'publication'));
                 $html .= html_writer::end_tag('div');
             }
             echo $html;
             $html = "";
             $table->print_html();
             // Print the whole table.
             $options = array();
             if (true) {
                 // Always display download option.
                 $options['zipusers'] = get_string('zipusers', 'publication');
             }
             if ($totalfiles > 0) {
                 if (has_capability('mod/publication:approve', $context)) {
                     $options['approveusers'] = get_string('approveusers', 'publication');
                     $options['rejectusers'] = get_string('rejectusers', 'publication');
                     if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) {
                         $options['resetstudentapproval'] = get_string('resetstudentapproval', 'publication');
                     }
                 }
             }
             if (has_capability('mod/publication:grantextension', $this->get_context())) {
                 $options['grantextension'] = get_string('grantextension', 'publication');
             }
             if (count($options) > 0) {
                 if (has_capability('mod/publication:approve', $context)) {
                     $html .= html_writer::empty_tag('input', array('type' => 'reset', 'name' => 'resetvisibility', 'value' => get_string('reset', 'publication'), 'class' => 'visibilitysaver'));
                     if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) {
                         $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'savevisibility', 'value' => get_string('saveapproval', 'publication'), 'class' => 'visibilitysaver'));
                     } else {
                         $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'savevisibility', 'value' => get_string('saveteacherapproval', 'publication'), 'class' => 'visibilitysaver'));
                     }
                 }
                 $html .= html_writer::start_div('withselection');
                 $html .= html_writer::span(get_string('withselected', 'publication'));
                 $html .= html_writer::select($options, 'action');
                 $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'submitgo', 'value' => get_string('go', 'publication')));
                 $html .= html_writer::end_div();
             }
         } else {
             $html .= html_writer::tag('div', get_string('nothingtodisplay', 'publication'), array('class' => 'nosubmisson'));
         }
     } else {
         $html .= html_writer::tag('div', get_string('nothingtodisplay', 'publication'), array('class' => 'nosubmisson'));
     }
     // Select all/none.
     $html .= html_writer::start_tag('div', array('class' => 'checkboxcontroller'));
     $html .= "<script type=\"text/javascript\">\n                                        function toggle_userselection() {\n                                        var checkboxes = document.getElementsByClassName('userselection');\n                                        var sel = document.getElementById('selectallnone');\n\n                                        if (checkboxes.length > 0) {\n                                        checkboxes[0].checked = sel.checked;\n\n                                        for(var i = 1; i < checkboxes.length;i++) {\n                                        checkboxes[i].checked = checkboxes[0].checked;\n    }\n    }\n    }\n                                        </script>";
     $html .= html_writer::end_div();
     $html .= html_writer::end_div();
     $html .= html_writer::end_div();
     echo $html;
     echo html_writer::end_tag('form');
     // Mini form for setting user preference.
     $html = '';
     $formaction = new moodle_url('/mod/publication/view.php', array('id' => $this->coursemodule->id));
     $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class' => 'optionspref'));
     $mform->addElement('hidden', 'updatepref');
     $mform->setDefault('updatepref', 1);
     $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'publication'));
     $mform->addElement('text', 'perpage', get_string('entiresperpage', 'publication'), array('size' => 1));
     $mform->setDefault('perpage', $perpage);
     $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));
     $mform->display();
     return $html;
 }
 /**
  * Helper method, displays a table
  * of users with checkboxes next to them.
  * Also includes a submit button to take
  * action on those users.
  *
  * @param string $hook The calling hook
  * @return string
  * @todo Not in love with this method, but it works
  **/
 function display_user_table($hook)
 {
     global $CFG;
     global $DB, $OUTPUT;
     require_once $CFG->libdir . '/tablelib.php';
     ob_start();
     $pagesize = optional_param('pagesize', 50, PARAM_INT);
     print "<form class=\"userform\" id=\"userformid\" action=\"{$CFG->wwwroot}/blocks/gdata/index.php\" method=\"post\">";
     $table = new flexible_table("blocks-gdata-{$hook}");
     $filter = $this->create_filter($hook, $pagesize);
     // Define columns based on hook
     switch ($hook) {
         case 'users':
             $table->define_columns(array('username', 'fullname', 'email', 'lastsync', 'status'));
             $table->define_headers(array(get_string('username'), get_string('fullname'), get_string('email'), get_string('lastsync', 'block_gdata'), get_string('status')));
             break;
         case 'addusers':
             $table->define_columns(array('username', 'fullname', 'email'));
             $table->define_headers(array(get_string('username'), get_string('fullname'), get_string('email')));
             break;
     }
     $table->define_baseurl("{$CFG->wwwroot}/blocks/gdata/index.php?hook={$hook}&amp;pagesize={$pagesize}");
     $table->pageable(true);
     $table->sortable(true, 'username', SORT_DESC);
     $table->set_attribute('width', '100%');
     $table->set_attribute('class', 'flexible generaltable generalbox');
     $table->column_style('action', 'text-align', 'center');
     $table->setup();
     list($select, $from, $where, $params) = $this->get_sql($hook, $filter);
     $total = $DB->count_records_sql("SELECT COUNT(*) {$from} {$where}", $params);
     $table->pagesize($pagesize, $total);
     if ($users = $DB->get_records_sql("{$select} {$from} {$where} ORDER BY " . $table->get_sql_sort(), array(), $table->get_page_start(), $table->get_page_size())) {
         foreach ($users as $user) {
             $username = print_checkbox("userids[]", $user->id, false, s($user->username), s($user->username), '', true);
             // Define table contents based on hook
             switch ($hook) {
                 case 'users':
                     if ($user->lastsync > 0) {
                         $lastsync = userdate($user->lastsync);
                     } else {
                         $lastsync = get_string('never');
                     }
                     $table->add_data(array($username, fullname($user), $user->email, $lastsync, get_string("status{$user->status}", 'block_gdata')));
                     break;
                 case 'addusers':
                     $table->add_data(array($username, fullname($user), $user->email));
                     break;
             }
         }
     }
     print $OUTPUT->box_start('boxaligncenter boxwidthwide', '', array());
     print $filter->display_add();
     print $filter->display_active();
     if (empty($table->totalrows)) {
         // Avoid printing the form on empty tables
         print $table->finish_output();
     } else {
         $allstr = get_string('selectall', 'block_gdata');
         $nonestr = get_string('selectnone', 'block_gdata');
         $submitstr = get_string("submitbutton{$hook}", 'block_gdata');
         $submitallstr = get_string("submitbuttonall{$hook}", 'block_gdata', $total);
         $confirmstr = get_string("confirm{$hook}", 'block_gdata', $total);
         $confirmstr = addslashes_js($confirmstr);
         $options = array(50 => 50, 100 => 100, 250 => 250, 500 => 500, 1000 => 1000);
         print '<input type="hidden" name="hook" value="' . $hook . '" />';
         print '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
         print $table->finish_output();
         print "<p><a href=\"#\" title=\"{$allstr}\" onclick=\"select_all_in('FORM', 'userform', 'userformid'); return false;\">{$allstr}</a> / ";
         print "<a href=\"#\" title=\"{$nonestr}\" onclick=\"deselect_all_in('FORM', 'userform', 'userformid'); return false;\">{$nonestr}</a></p>";
         print "<input type=\"submit\" name=\"users\" value=\"{$submitstr}\" />&nbsp;&nbsp;";
         print "<input type=\"submit\" name=\"allusers\" value=\"{$submitallstr}\" onclick=\"return confirm('{$confirmstr}');\" />";
         print '</form><br />';
         print $OUTPUT->single_select("{$CFG->wwwroot}/blocks/gdata/index.php?hook={$hook}&amp;pagesize=", 'changepagesize', $options, $pagesize);
     }
     print $OUTPUT->box_end(true);
     $tablehtml = ob_get_contents();
     ob_end_clean();
     return $tablehtml;
 }
Esempio n. 15
0
 /**
  * displays the full report
  * @param \stdClass $scorm full SCORM object
  * @param \stdClass $cm - full course_module object
  * @param \stdClass $course - full course object
  * @param string $download - type of download being requested
  */
 public function display($scorm, $cm, $course, $download)
 {
     global $CFG, $DB, $OUTPUT, $PAGE;
     $contextmodule = \context_module::instance($cm->id);
     $action = optional_param('action', '', PARAM_ALPHA);
     $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
     $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
     $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
     if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
         if (scorm_delete_responses($attemptids, $scorm)) {
             // Delete responses.
             echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
         }
     }
     // Find out current groups mode.
     $currentgroup = groups_get_activity_group($cm, true);
     // Detailed report.
     $mform = new \mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup'));
     if ($fromform = $mform->get_data()) {
         $pagesize = $fromform->pagesize;
         $showobjectivescore = $fromform->objectivescore;
         set_user_preference('scorm_report_pagesize', $pagesize);
         set_user_preference('scorm_report_objectives_score', $showobjectivescore);
     } else {
         $pagesize = get_user_preferences('scorm_report_pagesize', 0);
         $showobjectivescore = get_user_preferences('scorm_report_objectives_score', 0);
     }
     if ($pagesize < 1) {
         $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
     }
     // Select group menu.
     $displayoptions = array();
     $displayoptions['attemptsmode'] = $attemptsmode;
     $displayoptions['objectivescore'] = $showobjectivescore;
     $mform->set_data($displayoptions + array('pagesize' => $pagesize));
     if ($groupmode = groups_get_activity_groupmode($cm)) {
         // Groups are being used.
         if (!$download) {
             groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
         }
     }
     $formattextoptions = array('context' => \context_course::instance($course->id));
     // We only want to show the checkbox to delete attempts
     // if the user has permissions and if the report mode is showing attempts.
     $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule) && $attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
     // Select the students.
     $nostudents = false;
     if (empty($currentgroup)) {
         // All users who can attempt scoes.
         if (!($students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false))) {
             echo $OUTPUT->notification(get_string('nostudentsyet'));
             $nostudents = true;
             $allowedlist = '';
         } else {
             $allowedlist = array_keys($students);
         }
         unset($students);
     } else {
         // All users who can attempt scoes and who are in the currently selected group.
         $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $currentgroup, '', false);
         if (!$groupstudents) {
             echo $OUTPUT->notification(get_string('nostudentsingroup'));
             $nostudents = true;
             $groupstudents = array();
         }
         $allowedlist = array_keys($groupstudents);
         unset($groupstudents);
     }
     if (!$nostudents) {
         // Now check if asked download of data.
         $coursecontext = \context_course::instance($course->id);
         if ($download) {
             $filename = clean_filename("{$course->shortname} " . format_string($scorm->name, true, $formattextoptions));
         }
         // Define table columns.
         $columns = array();
         $headers = array();
         if (!$download && $candelete) {
             $columns[] = 'checkbox';
             $headers[] = null;
         }
         if (!$download && $CFG->grade_report_showuserimage) {
             $columns[] = 'picture';
             $headers[] = '';
         }
         $columns[] = 'fullname';
         $headers[] = get_string('name');
         $extrafields = get_extra_user_fields($coursecontext);
         foreach ($extrafields as $field) {
             $columns[] = $field;
             $headers[] = get_user_field_name($field);
         }
         $columns[] = 'attempt';
         $headers[] = get_string('attempt', 'scorm');
         $columns[] = 'start';
         $headers[] = get_string('started', 'scorm');
         $columns[] = 'finish';
         $headers[] = get_string('last', 'scorm');
         $columns[] = 'score';
         $headers[] = get_string('score', 'scorm');
         $scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id');
         foreach ($scoes as $sco) {
             if ($sco->launch != '') {
                 $columns[] = 'scograde' . $sco->id;
                 $headers[] = format_string($sco->title, '', $formattextoptions);
             }
         }
         $params = array();
         list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED);
         // Construct the SQL.
         $select = 'SELECT DISTINCT ' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ' AS uniqueid, ';
         $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' ';
         // This part is the same for all cases - join users and scorm_scoes_track tables.
         $from = 'FROM {user} u ';
         $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = ' . $scorm->id;
         switch ($attemptsmode) {
             case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
                 // Show only students with attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NOT NULL';
                 break;
             case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
                 // Show only students without attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NULL';
                 break;
             case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
                 // Show all students with or without attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND (st.userid IS NOT NULL OR st.userid IS NULL)';
                 break;
         }
         $countsql = 'SELECT COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ')) AS nbresults, ';
         $countsql .= 'COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'st.attempt') . ')) AS nbattempts, ';
         $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
         $countsql .= $from . $where;
         $nbmaincolumns = count($columns);
         // Get number of main columns used.
         $objectives = get_scorm_objectives($scorm->id);
         $nosort = array();
         foreach ($objectives as $scoid => $sco) {
             foreach ($sco as $id => $objectivename) {
                 $colid = $scoid . 'objectivestatus' . $id;
                 $columns[] = $colid;
                 $nosort[] = $colid;
                 if (!$displayoptions['objectivescore']) {
                     // Display the objective name only.
                     $headers[] = $objectivename;
                 } else {
                     // Display the objective status header with a "status" suffix to avoid confusion.
                     $headers[] = $objectivename . ' ' . get_string('status', 'scormreport_objectives');
                     // Now print objective score headers.
                     $colid = $scoid . 'objectivescore' . $id;
                     $columns[] = $colid;
                     $nosort[] = $colid;
                     $headers[] = $objectivename . ' ' . get_string('score', 'scormreport_objectives');
                 }
             }
         }
         $emptycell = '';
         // Used when an empty cell is being printed - in html we add a space.
         if (!$download) {
             $emptycell = '&nbsp;';
             $table = new \flexible_table('mod-scorm-report');
             $table->define_columns($columns);
             $table->define_headers($headers);
             $table->define_baseurl($PAGE->url);
             $table->sortable(true);
             $table->collapsible(true);
             // This is done to prevent redundant data, when a user has multiple attempts.
             $table->column_suppress('picture');
             $table->column_suppress('fullname');
             foreach ($extrafields as $field) {
                 $table->column_suppress($field);
             }
             foreach ($nosort as $field) {
                 $table->no_sorting($field);
             }
             $table->no_sorting('start');
             $table->no_sorting('finish');
             $table->no_sorting('score');
             $table->no_sorting('checkbox');
             $table->no_sorting('picture');
             foreach ($scoes as $sco) {
                 if ($sco->launch != '') {
                     $table->no_sorting('scograde' . $sco->id);
                 }
             }
             $table->column_class('picture', 'picture');
             $table->column_class('fullname', 'bold');
             $table->column_class('score', 'bold');
             $table->set_attribute('cellspacing', '0');
             $table->set_attribute('id', 'attempts');
             $table->set_attribute('class', 'generaltable generalbox');
             // Start working -- this is necessary as soon as the niceties are over.
             $table->setup();
         } else {
             if ($download == 'ODS') {
                 require_once "{$CFG->libdir}/odslib.class.php";
                 $filename .= ".ods";
                 // Creating a workbook.
                 $workbook = new \MoodleODSWorkbook("-");
                 // Sending HTTP headers.
                 $workbook->send($filename);
                 // Creating the first worksheet.
                 $sheettitle = get_string('report', 'scorm');
                 $myxls = $workbook->add_worksheet($sheettitle);
                 // Format types.
                 $format = $workbook->add_format();
                 $format->set_bold(0);
                 $formatbc = $workbook->add_format();
                 $formatbc->set_bold(1);
                 $formatbc->set_align('center');
                 $formatb = $workbook->add_format();
                 $formatb->set_bold(1);
                 $formaty = $workbook->add_format();
                 $formaty->set_bg_color('yellow');
                 $formatc = $workbook->add_format();
                 $formatc->set_align('center');
                 $formatr = $workbook->add_format();
                 $formatr->set_bold(1);
                 $formatr->set_color('red');
                 $formatr->set_align('center');
                 $formatg = $workbook->add_format();
                 $formatg->set_bold(1);
                 $formatg->set_color('green');
                 $formatg->set_align('center');
                 // Here starts workshhet headers.
                 $colnum = 0;
                 foreach ($headers as $item) {
                     $myxls->write(0, $colnum, $item, $formatbc);
                     $colnum++;
                 }
                 $rownum = 1;
             } else {
                 if ($download == 'Excel') {
                     require_once "{$CFG->libdir}/excellib.class.php";
                     $filename .= ".xls";
                     // Creating a workbook.
                     $workbook = new \MoodleExcelWorkbook("-");
                     // Sending HTTP headers.
                     $workbook->send($filename);
                     // Creating the first worksheet.
                     $sheettitle = get_string('report', 'scorm');
                     $myxls = $workbook->add_worksheet($sheettitle);
                     // Format types.
                     $format = $workbook->add_format();
                     $format->set_bold(0);
                     $formatbc = $workbook->add_format();
                     $formatbc->set_bold(1);
                     $formatbc->set_align('center');
                     $formatb = $workbook->add_format();
                     $formatb->set_bold(1);
                     $formaty = $workbook->add_format();
                     $formaty->set_bg_color('yellow');
                     $formatc = $workbook->add_format();
                     $formatc->set_align('center');
                     $formatr = $workbook->add_format();
                     $formatr->set_bold(1);
                     $formatr->set_color('red');
                     $formatr->set_align('center');
                     $formatg = $workbook->add_format();
                     $formatg->set_bold(1);
                     $formatg->set_color('green');
                     $formatg->set_align('center');
                     $colnum = 0;
                     foreach ($headers as $item) {
                         $myxls->write(0, $colnum, $item, $formatbc);
                         $colnum++;
                     }
                     $rownum = 1;
                 } else {
                     if ($download == 'CSV') {
                         $csvexport = new \csv_export_writer("tab");
                         $csvexport->set_filename($filename, ".txt");
                         $csvexport->add_data($headers);
                     }
                 }
             }
         }
         if (!$download) {
             $sort = $table->get_sql_sort();
         } else {
             $sort = '';
         }
         // Fix some wired sorting.
         if (empty($sort)) {
             $sort = ' ORDER BY uniqueid';
         } else {
             $sort = ' ORDER BY ' . $sort;
         }
         if (!$download) {
             // Add extra limits due to initials bar.
             list($twhere, $tparams) = $table->get_sql_where();
             if ($twhere) {
                 $where .= ' AND ' . $twhere;
                 // Initial bar.
                 $params = array_merge($params, $tparams);
             }
             if (!empty($countsql)) {
                 $count = $DB->get_record_sql($countsql, $params);
                 $totalinitials = $count->nbresults;
                 if ($twhere) {
                     $countsql .= ' AND ' . $twhere;
                 }
                 $count = $DB->get_record_sql($countsql, $params);
                 $total = $count->nbresults;
             }
             $table->pagesize($pagesize, $total);
             echo \html_writer::start_div('scormattemptcounts');
             if ($count->nbresults == $count->nbattempts) {
                 echo get_string('reportcountattempts', 'scorm', $count);
             } else {
                 if ($count->nbattempts > 0) {
                     echo get_string('reportcountallattempts', 'scorm', $count);
                 } else {
                     echo $count->nbusers . ' ' . get_string('users');
                 }
             }
             echo \html_writer::end_div();
         }
         // Fetch the attempts.
         if (!$download) {
             $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size());
             echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
             if ($candelete) {
                 // Start form.
                 $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
                 echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post', 'action' => $PAGE->url->out(false), 'onsubmit' => 'return confirm("' . $strreallydel . '");'));
                 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
                 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
                 echo \html_writer::start_div('', array('style' => 'display: none;'));
                 echo \html_writer::input_hidden_params($PAGE->url);
                 echo \html_writer::end_div();
                 echo \html_writer::start_div();
             }
             $table->initialbars($totalinitials > 20);
             // Build table rows.
         } else {
             $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params);
         }
         if ($attempts) {
             foreach ($attempts as $scouser) {
                 $row = array();
                 if (!empty($scouser->attempt)) {
                     $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
                 } else {
                     $timetracks = '';
                 }
                 if (in_array('checkbox', $columns)) {
                     if ($candelete && !empty($timetracks->start)) {
                         $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false);
                     } else {
                         if ($candelete) {
                             $row[] = '';
                         }
                     }
                 }
                 if (in_array('picture', $columns)) {
                     $user = new \stdClass();
                     $additionalfields = explode(',', \user_picture::fields());
                     $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
                     $user->id = $scouser->userid;
                     $row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
                 }
                 if (!$download) {
                     $url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
                     $row[] = \html_writer::link($url, fullname($scouser));
                 } else {
                     $row[] = fullname($scouser);
                 }
                 foreach ($extrafields as $field) {
                     $row[] = s($scouser->{$field});
                 }
                 if (empty($timetracks->start)) {
                     $row[] = '-';
                     $row[] = '-';
                     $row[] = '-';
                     $row[] = '-';
                 } else {
                     if (!$download) {
                         $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
                         $row[] = \html_writer::link($url, $scouser->attempt);
                     } else {
                         $row[] = $scouser->attempt;
                     }
                     if ($download == 'ODS' || $download == 'Excel') {
                         $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
                     } else {
                         $row[] = userdate($timetracks->start);
                     }
                     if ($download == 'ODS' || $download == 'Excel') {
                         $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
                     } else {
                         $row[] = userdate($timetracks->finish);
                     }
                     $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
                 }
                 // Print out all scores of attempt.
                 foreach ($scoes as $sco) {
                     if ($sco->launch != '') {
                         if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
                             if ($trackdata->status == '') {
                                 $trackdata->status = 'notattempted';
                             }
                             $strstatus = get_string($trackdata->status, 'scorm');
                             if ($trackdata->score_raw != '') {
                                 // If raw score exists, print it.
                                 $score = $trackdata->score_raw;
                                 // Add max score if it exists.
                                 if (isset($trackdata->score_max)) {
                                     $score .= '/' . $trackdata->score_max;
                                 }
                             } else {
                                 // ...else print out status.
                                 $score = $strstatus;
                             }
                             if (!$download) {
                                 $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
                                 $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
                             } else {
                                 $row[] = $score;
                             }
                             // Iterate over tracks and match objective id against values.
                             $scorm2004 = false;
                             if (scorm_version_check($scorm->version, SCORM_13)) {
                                 $scorm2004 = true;
                                 $objectiveprefix = "cmi.objectives.";
                             } else {
                                 $objectiveprefix = "cmi.objectives_";
                             }
                             $keywords = array(".id", $objectiveprefix);
                             $objectivestatus = array();
                             $objectivescore = array();
                             foreach ($trackdata as $name => $value) {
                                 if (strpos($name, $objectiveprefix) === 0 && strrpos($name, '.id') !== false) {
                                     $num = trim(str_ireplace($keywords, '', $name));
                                     if (is_numeric($num)) {
                                         if ($scorm2004) {
                                             $element = $objectiveprefix . $num . '.completion_status';
                                         } else {
                                             $element = $objectiveprefix . $num . '.status';
                                         }
                                         if (isset($trackdata->{$element})) {
                                             $objectivestatus[$value] = $trackdata->{$element};
                                         } else {
                                             $objectivestatus[$value] = '';
                                         }
                                         if ($displayoptions['objectivescore']) {
                                             $element = $objectiveprefix . $num . '.score.raw';
                                             if (isset($trackdata->{$element})) {
                                                 $objectivescore[$value] = $trackdata->{$element};
                                             } else {
                                                 $objectivescore[$value] = '';
                                             }
                                         }
                                     }
                                 }
                             }
                             // Interaction data.
                             if (!empty($objectives[$trackdata->scoid])) {
                                 foreach ($objectives[$trackdata->scoid] as $name) {
                                     if (isset($objectivestatus[$name])) {
                                         $row[] = s($objectivestatus[$name]);
                                     } else {
                                         $row[] = $emptycell;
                                     }
                                     if ($displayoptions['objectivescore']) {
                                         if (isset($objectivescore[$name])) {
                                             $row[] = s($objectivescore[$name]);
                                         } else {
                                             $row[] = $emptycell;
                                         }
                                     }
                                 }
                             }
                             // End of interaction data.
                         } else {
                             // If we don't have track data, we haven't attempted yet.
                             $strstatus = get_string('notattempted', 'scorm');
                             if (!$download) {
                                 $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . $strstatus;
                             } else {
                                 $row[] = $strstatus;
                             }
                             // Complete the empty cells.
                             for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) {
                                 $row[] = $emptycell;
                             }
                         }
                     }
                 }
                 if (!$download) {
                     $table->add_data($row);
                 } else {
                     if ($download == 'Excel' or $download == 'ODS') {
                         $colnum = 0;
                         foreach ($row as $item) {
                             $myxls->write($rownum, $colnum, $item, $format);
                             $colnum++;
                         }
                         $rownum++;
                     } else {
                         if ($download == 'CSV') {
                             $csvexport->add_data($row);
                         }
                     }
                 }
             }
             if (!$download) {
                 $table->finish_output();
                 if ($candelete) {
                     echo \html_writer::start_tag('table', array('id' => 'commands'));
                     echo \html_writer::start_tag('tr') . \html_writer::start_tag('td');
                     echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')) . ' / ';
                     echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm'));
                     echo '&nbsp;&nbsp;';
                     echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'scorm'), 'class' => 'btn btn-secondary'));
                     echo \html_writer::end_tag('td') . \html_writer::end_tag('tr') . \html_writer::end_tag('table');
                     // Close form.
                     echo \html_writer::end_tag('div');
                     echo \html_writer::end_tag('form');
                 }
                 echo \html_writer::end_div();
                 if (!empty($attempts)) {
                     echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')) . \html_writer::start_tag('tr');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo \html_writer::end_tag('td');
                     echo \html_writer::end_tag('tr') . \html_writer::end_tag('table');
                 }
             }
         } else {
             if ($candelete && !$download) {
                 echo \html_writer::end_div();
                 echo \html_writer::end_tag('form');
                 $table->finish_output();
             }
             echo \html_writer::end_div();
         }
         // Show preferences form irrespective of attempts are there to report or not.
         if (!$download) {
             $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
             $mform->display();
         }
         if ($download == 'Excel' or $download == 'ODS') {
             $workbook->close();
             exit;
         } else {
             if ($download == 'CSV') {
                 $csvexport->download_file();
                 exit;
             }
         }
     } else {
         echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
     }
 }
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     // Update preferences
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 20, PARAM_INT);
         $perpage = $perpage <= 0 ? 20 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         $moderationtarget = optional_param('moderationtarget', 0, PARAM_INT);
         $moderationtarget = $moderationtarget <= 0 ? 0 : $moderationtarget;
         set_user_preference('assignment_moderationtarget', $moderationtarget);
     }
     // Get preferences
     $perpage = get_user_preferences('assignment_perpage', 10);
     $moderationtarget = get_user_preferences('assignment_moderationtarget', 0);
     // Some shortcuts to make the code read better
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $page = optional_param('page', 0, PARAM_INT);
     // Log this view
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     // Print header and navigation breadcrumbs
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     // Print tabs at top of page
     $tabs = array();
     $row = array();
     $inactive = array();
     $activated = array();
     $row[] = new tabobject('criteria', "type/peerreview/" . self::CRITERIA_FILE . "?id=" . $this->cm->id . "&a=" . $this->assignment->id, get_string('criteria', 'assignment_peerreview'));
     $row[] = new tabobject('submissions', '', get_string('submissions', 'assignment_peerreview'));
     $tabs[] = $row;
     $currenttab = 'submissions';
     $inactive[] = 'submissions';
     $activated[] = 'submissions';
     print_tabs($tabs, $currenttab, $inactive, $activated);
     // Print optional message
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     // Check to see if groups are being used in this assignment
     // find out current groups mode
     // $groupmode = groups_get_activity_groupmode($cm);
     // $currentgroup = groups_get_activity_group($cm, true);
     // groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/assignment/submissions.php?id=' . $cm->id);
     // Get all ppl that are allowed to submit assignments
     // if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id')) {
         $users = array_keys($users);
     }
     // Filter out teachers
     if ($users && ($teachers = get_users_by_capability($context, 'mod/assignment:grade', 'u.id'))) {
         $users = array_diff($users, array_keys($teachers));
     }
     // Warn if class is too small
     if (count($users) < 5) {
         notify(get_string('numberofstudentswarning', 'assignment_peerreview'));
     }
     // if groupmembersonly used, remove users who are not in any group
     // if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
     // if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
     // $users = array_intersect($users, array_keys($groupingusers));
     // }
     // }
     // Create the table to be shown
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $tablecolumns = array('picture', 'fullname', 'submitted', 'reviews', 'moderations', 'status', 'seedoreviews', 'suggestedmark', 'finalgrade');
     $table->define_columns($tablecolumns);
     $tableheaders = array('', get_string('fullname'), get_string('submission', 'assignment_peerreview'), get_string('reviewsbystudent', 'assignment_peerreview') . helpbutton('reviewsbystudent', get_string('reviewsbystudent', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('moderationstitle', 'assignment_peerreview') . helpbutton('moderationtarget', get_string('moderationtarget', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('status') . helpbutton('status', get_string('status', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('seedoreviews', 'assignment_peerreview') . helpbutton('seedoreviews', get_string('seedoreviews', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('suggestedgrade', 'assignment_peerreview') . helpbutton('suggestedgrade', get_string('suggestedgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('finalgrade', 'assignment_peerreview') . helpbutton('finalgrade', get_string('finalgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true));
     $table->define_headers($tableheaders);
     // $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
     // $table->sortable(true, 'submitted');
     $table->sortable(false);
     $table->collapsible(true);
     // $table->initialbars(true);
     $table->initialbars(false);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('submitted', 'submitted');
     $table->column_class('reviews', 'reviews');
     $table->column_class('moderations', 'moderations');
     $table->column_class('status', 'status');
     $table->column_class('seedoreviews', 'seedoreviews');
     $table->column_class('suggestedmark', 'suggestedmark');
     $table->column_class('finalgrade', 'finalgrade');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '99%');
     $table->set_attribute('align', 'center');
     $table->column_style('submitted', 'text-align', $alignment);
     $table->column_style('finalgrade', 'text-align', 'center');
     /*
     		$table->no_sorting('picture');
     		$table->no_sorting('fullname');
     		$table->no_sorting('submitted');
     		$table->no_sorting('reviews');
     		$table->no_sorting('moderations');
     		$table->no_sorting('status');
     		$table->no_sorting('seedoreviews');
     		$table->no_sorting('suggestedmark');
     		$table->no_sorting('finalgrade');
     */
     $table->setup();
     if (empty($users)) {
         print_heading(get_string('nosubmitusers', 'assignment'));
         return true;
     }
     // Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                       s.id AS submissionid, s.grade,
                       s.timecreated as submitted, s.timemarked ';
     $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id=s.userid AND s.assignment=' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $sort = 'ORDER BY COALESCE(submitted,2147483647) ASC, submissionid ASC, u.lastname ASC';
     // if ($sort = $table->get_sql_sort()) {
     // $sort = ' ORDER BY '.$sort;
     // }
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     // Get the criteria
     $criteriaList = get_records_list('assignment_criteria', 'assignment', $this->assignment->id, 'ordernumber');
     $numberOfCriteria = 0;
     if (is_array($criteriaList)) {
         $criteriaList = array_values($criteriaList);
         $numberOfCriteria = count($criteriaList);
     }
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         //            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             //              $final_grade = $grading_info->items[0]->grades[$auser->id];
             // Calculate user status
             $auser->status = $auser->timemarked > 0;
             $picture = print_user_picture($auser, $course->id, $auser->picture, false, true);
             $studentName = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $this->course->id . '">' . fullname($auser) . '</a>';
             // If submission has been made
             if (!empty($auser->submissionid)) {
                 $filearea = $this->file_area_name($auser->id);
                 $fileLink = '';
                 if (isset($this->assignment->var3) && $this->assignment->var3 == self::ONLINE_TEXT) {
                     $url = '/mod/assignment/type/peerreview/' . self::VIEW_ONLINE_TEXT . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '&view=moderation';
                     $fileLink .= '<a href="' . $CFG->wwwroot . $url . '" target="_blank" onclick="return openpopup(\'' . $url . '\',\'\',\'menubar=0,location=0,scrollbars,resizable,width=500,height=400\');"><img src="' . $CFG->pixpath . '/f/html.gif" /></a>';
                 } else {
                     $basedir = $this->file_area($auser->id);
                     if ($files = get_directory_list($basedir)) {
                         require_once $CFG->libdir . '/filelib.php';
                         foreach ($files as $key => $file) {
                             $icon = mimeinfo('icon', $file);
                             $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                             $fileLink .= '<a href="' . $ffurl . '" ><img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" /></a>';
                         }
                     }
                 }
                 $submitted = '<div class="files" style="display:inline;">' . $fileLink . '</div><div style="display:inline;" id="tt' . $auser->id . '">' . userdate($auser->submitted, get_string('strftimeintable', 'assignment_peerreview')) . '</div>';
                 $submitted .= ' <a href="' . $CFG->wwwroot . '/mod/assignment/type/peerreview/' . self::RESUBMIT_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '">(' . get_string('resubmitlabel', 'assignment_peerreview') . ')</a>';
                 // Reviews by student
                 $numberOfReviewsByThisStudent = 0;
                 if ($reviewsByThisStudent = get_records_select('assignment_review', 'assignment=\'' . $this->assignment->id . '\' AND reviewer=\'' . $auser->id . '\' AND complete=\'1\'')) {
                     $numberOfReviewsByThisStudent = count($reviewsByThisStudent);
                     $reviewsByThisStudent = array_values($reviewsByThisStudent);
                     $reviews = '<div style="text-align:center;" id="re' . $auser->id . '">';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= '<span id="rev' . $reviewsByThisStudent[$i]->id . '"  style="padding:5px 2px;">';
                         $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $reviewsByThisStudent[$i]->reviewee . '&amp;mode=single&amp;offset=1';
                         $reviews .= element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $i + 1, 600, 780, $i + 1, 'none', true, 'user' . $auser->id . 'rev' . $i);
                         $reviews .= '</span>';
                         // $reviews .= $i<$numberOfReviewsByThisStudent-1?', ':'';
                     }
                     $reviews .= '</div>';
                     $reviews .= '<script>';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseover\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="#ff9999";\');';
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseout\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="transparent";\');';
                     }
                     $reviews .= '</script>';
                 } else {
                     $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 }
                 // Reviews of student
                 $reviewsOfThisStudent = $this->get_reviews_of_student($auser->id);
                 $numberOfReviewsOfThisStudent = 0;
                 if (is_array($reviewsOfThisStudent)) {
                     $numberOfReviewsOfThisStudent = count($reviewsOfThisStudent);
                 }
                 $statusCode = $this->get_status($reviewsOfThisStudent, $numberOfCriteria);
                 $status = '<div id="st' . $auser->id . '">' . $this->print_status($statusCode, true) . '</div>';
                 $buttontext = get_string('review', 'assignment_peerreview');
                 $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $auser->id . '&amp;mode=single' . '&amp;offset=' . $offset++;
                 $button = element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'reviewbutton' . $auser->id);
                 $seedoreviews = '<div id="se' . $auser->id . '" style="text-align:center;padding:5px 0;"><span  id="seOutline' . $auser->id . '" class="s' . ($statusCode <= 3 ? '0' : '1') . '" style="padding:4px 1px;">' . $button . '</span></div>';
                 $seedoreviews .= '<script>';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseover\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="#ff9999";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseout\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="transparent";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= '</script>';
                 // Suggest mark
                 $suggestedmark = '<div style="text-align:center;" id="su' . $auser->id . '">';
                 $suggestedMarkToDisplay = $this->get_marks($reviewsOfThisStudent, $criteriaList, $numberOfReviewsByThisStudent, $this->assignment->var1);
                 $suggestedmark .= '<input type="text" size="4" id="gvalue' . $auser->id . '" value="' . $suggestedMarkToDisplay . '" />';
                 $suggestedmark .= '<input type="button" value="' . get_string('set', 'assignment_peerreview') . '" onclick="mark=parseInt(document.getElementById(\'gvalue' . $auser->id . '\').value); if(isNaN(mark)) {alert(\'' . get_string('gradenotanumber', 'assignment_peerreview') . '\'); return false;} else {popup_url=\'/mod/assignment/type/peerreview/' . self::SET_MARK_FILE . '?id=' . $this->cm->id . '&amp;a=' . $this->assignment->id . '&amp;userid=' . $auser->id . '&amp;mark=\'+mark; return openpopup(popup_url, \'grade5\', \'menubar=0,location=0,scrollbars,resizable,width=400,height=300\', 0);}" />';
                 $suggestedmark .= '</div>';
                 // Final grade
                 if ($auser->timemarked > 0) {
                     // if ($final_grade->locked or $final_grade->overridden) {
                     // $grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
                     // }
                     // else {
                     $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                     // }
                 } else {
                     $grade = '<div id="g' . $auser->id . '">' . get_string('notset', 'assignment_peerreview') . '</div>';
                 }
             } else {
                 $submitted = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 $seedoreviews = '<div id="se' . $auser->id . '">&nbsp;</div>';
                 $suggestedmark = '<div id="su' . $auser->id . '">&nbsp;</div>';
                 $grade = '<div id="g' . $auser->id . '">-</div>';
             }
             $moderationCountSQL = 'SELECT count(r.id) FROM ' . $CFG->prefix . 'assignment a, ' . $CFG->prefix . 'assignment_review r WHERE a.course=' . $course->id . ' AND a.id=r.assignment AND r.teacherreview=1 AND r.reviewee=\'' . $auser->id . '\'';
             $moderationCount = count_records_sql($moderationCountSQL);
             $moderations = '<div id="mo' . $auser->id . '" style="text-align:center;">' . ($moderationCount < $moderationtarget ? '<span class="errorStatus">' . $moderationCount . '</span>' : $moderationCount) . '</div>';
             // $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';
             // Add the row to the table
             $row = array($picture, $studentName, $submitted, $reviews, $moderations, $status, $seedoreviews, $suggestedmark, $grade);
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     require_once $CFG->dirroot . '/mod/assignment/type/peerreview/' . self::STYLES_FILE;
     $table->print_html();
     /// Print the whole table
     /// Mini form for setting user preference
     echo '<div style="margin:5px 10px;">';
     echo '<table id="optiontable" align="right">';
     echo '<tr><td colspan="2" align="right">';
     echo '<form id="options" action="type/peerreview/' . self::MASS_MARK_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '" method="post">';
     echo '<input type="submit" value="' . get_string('massmark', 'assignment_peerreview') . '" />';
     helpbutton('massmark', get_string('massmark', 'assignment_peerreview'), 'assignment/type/peerreview/');
     echo '</form>';
     echo '<br />';
     echo '</td></tr>';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment');
     echo '</td></tr>';
     echo '<tr align="right"><td>';
     echo '<label for="moderationtarget">' . get_string('moderationtarget', 'assignment_peerreview') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="moderationtarget" name="moderationtarget" size="1" value="' . $moderationtarget . '" />';
     helpbutton('moderationtarget', get_string('moderationtargetwhy', 'assignment_peerreview'), 'assignment/type/peerreview');
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</form>';
     echo '</td></tr></table>';
     echo '</div>';
     ///End of mini form
     print_footer($this->course);
 }
Esempio n. 17
0
    $sort = 'ORDER BY ' . $table->get_sql_sort();
} else {
    $sort = '';
}
list($where, $params) = $table->get_sql_where();
if ($where) {
    $where = 'WHERE ' . $where;
}
$query = "\n        SELECT tg.id, tg.name, tg.rawname, tg.tagtype, tg.flag, tg.timemodified,\n               u.id AS owner, u.firstname, u.lastname,\n               COUNT(ti.id) AS count\n          FROM {tag} tg\n     LEFT JOIN {tag_instance} ti ON ti.tagid = tg.id\n     LEFT JOIN {user} u ON u.id = tg.userid\n               {$where}\n      GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, tg.flag, tg.timemodified,\n               u.id, u.firstname, u.lastname\n         {$sort}";
$totalcount = $DB->count_records_sql("\n        SELECT COUNT(DISTINCT(tg.id))\n          FROM {tag} tg\n     LEFT JOIN {user} u ON u.id = tg.userid\n        {$where}", $params);
$table->initialbars(true);
// always initial bars
$table->pagesize($perpage, $totalcount);
echo '<form class="tag-management-form" method="post" action="' . $CFG->wwwroot . '/tag/manage.php"><div>';
//retrieve tags from DB
if ($tagrecords = $DB->get_records_sql($query, $params, $table->get_page_start(), $table->get_page_size())) {
    //populate table with data
    foreach ($tagrecords as $tag) {
        $id = $tag->id;
        $name = '<a href="' . $CFG->wwwroot . '/tag/index.php?id=' . $tag->id . '">' . tag_display_name($tag) . '</a>';
        $owner = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $tag->owner . '">' . fullname($tag) . '</a>';
        $count = $tag->count;
        $flag = $tag->flag;
        $timemodified = format_time(time() - $tag->timemodified);
        $checkbox = '<input type="checkbox" name="tagschecked[]" value="' . $tag->id . '" />';
        $text = html_writer::label(get_string('newname', 'tag'), 'newname_' . $tag->id, false, array('class' => 'accesshide'));
        $text .= '<input type="text" id="newname_' . $tag->id . '" name="newname[' . $tag->id . ']" />';
        $tagtype = html_writer::label(get_string('tagtype', 'tag'), 'menutagtypes' . $tag->id, false, array('class' => 'accesshide'));
        $tagtype .= html_writer::select($existing_tagtypes, 'tagtypes[' . $tag->id . ']', $tag->tagtype, false, array('id' => 'menutagtypes' . $tag->id));
        //if the tag if flagged, highlight it
        if ($tag->flag > 0) {
Esempio n. 18
0
/**
 * authorize_print_orders
 *
 */
function authorize_print_orders($courseid, $userid)
{
    global $course;
    global $CFG, $USER, $SITE, $DB, $OUTPUT, $PAGE;
    global $strs, $authstrs;
    $plugin = enrol_get_plugin('authorize');
    require_once $CFG->libdir . '/tablelib.php';
    $perpage = optional_param('perpage', 10, PARAM_INT);
    $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL);
    $searchquery = optional_param('searchquery', '0', PARAM_INT);
    $searchtype = optional_param('searchtype', 'orderid', PARAM_ALPHA);
    $status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
    $coursecontext = context_course::instance($courseid);
    $searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour);
    $buttons = "<form method='post' action='index.php' autocomplete='off'><div>";
    $buttons .= html_writer::label(get_string('orderdetails', 'enrol_authorize'), 'menusearchtype', false, array('class' => 'accesshide'));
    $buttons .= html_writer::select($searchmenu, 'searchtype', $searchtype, false);
    $buttons .= html_writer::label(get_string('search'), 'searchquery', false, array('class' => 'accesshide'));
    $buttons .= "<input id='searchquery' type='text' size='16' name='searchquery' value='' />";
    $buttons .= "<input type='submit' value='{$strs->search}' />";
    $buttons .= "</div></form>";
    if (has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) {
        $buttons .= "<form method='get' action='uploadcsv.php'><div><input type='submit' value='" . get_string('uploadcsv', 'enrol_authorize') . "' /></div></form>";
    }
    $canmanagepayments = has_capability('enrol/authorize:managepayments', $coursecontext);
    if ($showonlymy || !$canmanagepayments) {
        $userid = $USER->id;
    }
    $baseurl = $CFG->wwwroot . '/enrol/authorize/index.php?user='******'userid' => $userid);
    $sql = "SELECT c.id, c.fullname FROM {course} c JOIN {enrol_authorize} e ON c.id = e.courseid ";
    $sql .= $userid > 0 ? "WHERE (e.userid=:userid) " : '';
    $sql .= "ORDER BY c.sortorder, c.fullname";
    if ($popupcrs = $DB->get_records_sql_menu($sql, $params)) {
        $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs;
    }
    $popupmenu = empty($popupcrs) ? '' : $OUTPUT->single_select(new moodle_url($baseurl . '&status=' . $status), 'course', $popupcrs, $courseid, null, 'coursesmenu');
    $popupmenu .= '<br />';
    $statusmenu = array(AN_STATUS_NONE => $strs->all, AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, AN_STATUS_CREDIT => $authstrs->refunded, AN_STATUS_VOID => $authstrs->cancelled, AN_STATUS_EXPIRE => $authstrs->expired, AN_STATUS_UNDERREVIEW => $authstrs->underreview, AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, AN_STATUS_TEST => $authstrs->tested);
    $popupmenu .= $OUTPUT->single_select(new moodle_url($baseurl . '&course=' . $courseid), 'status', $statusmenu, $status, null, 'statusmenu');
    if ($canmanagepayments) {
        $popupmenu .= '<br />';
        $PAGE->requires->js('/enrol/authorize/authorize.js');
        $aid = $OUTPUT->add_action_handler(new component_action('click', 'authorize_jump_to_mypayments', array('userid' => $USER->id, 'status' => $status)));
        $popupmenu .= html_writer::checkbox('enrol_authorize', 1, $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), array('id' => $aid));
    }
    if (SITEID != $courseid) {
        $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
        $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id' => $course->id)));
    }
    $PAGE->navbar->add($authstrs->paymentmanagement, 'index.php');
    $PAGE->set_title("{$course->shortname}: {$authstrs->paymentmanagement}");
    $PAGE->set_heading($authstrs->paymentmanagement);
    $PAGE->set_headingmenu($popupmenu);
    $PAGE->set_button($buttons);
    echo $OUTPUT->header();
    $table = new flexible_table('enrol-authorize');
    $table->set_attribute('width', '100%');
    $table->set_attribute('cellspacing', '0');
    $table->set_attribute('cellpadding', '3');
    $table->set_attribute('id', 'orders');
    $table->set_attribute('class', 'generaltable generalbox');
    if ($perpage > 100) {
        $perpage = 100;
    }
    $perpagemenus = array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100);
    $perpagemenu = $OUTPUT->single_select(new moodle_url($baseurl . '&status=' . $status . '&course=' . $courseid), 'perpage', $perpagemenus, $perpage, array('' => 'choosedots'), 'perpagemenu');
    $table->define_columns(array('id', 'userid', 'timecreated', 'status', 'action'));
    $table->define_headers(array($authstrs->orderid, $authstrs->shopper, $strs->time, $strs->status, $perpagemenu));
    $table->define_baseurl($baseurl . "&amp;status={$status}&amp;course={$courseid}&amp;perpage={$perpage}");
    $table->no_sorting('action');
    $table->sortable(true, 'id', SORT_DESC);
    $table->pageable(true);
    $table->setup();
    $select = "SELECT e.id, e.paymentmethod, e.refundinfo, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime ";
    $from = "FROM {enrol_authorize} e ";
    $where = "WHERE (1=1) ";
    $params = array();
    if (!empty($searchquery)) {
        switch ($searchtype) {
            case 'orderid':
                $where = "WHERE (e.id = :searchquery) ";
                $params['searchquery'] = $searchquery;
                break;
            case 'transid':
                $where = "WHERE (e.transid = :searchquery) ";
                $params['searchquery'] = $searchquery;
                break;
            case 'cclastfour':
                $searchquery = sprintf("%04d", $searchquery);
                $where = "WHERE (e.refundinfo = :searchquery) AND (e.paymentmethod=:method) ";
                $params['searchquery'] = $searchquery;
                $params['method'] = AN_METHOD_CC;
                break;
        }
    } else {
        switch ($status) {
            case AN_STATUS_NONE:
                if (!$plugin->get_config('an_test')) {
                    $where .= "AND (e.status != :status) ";
                    $params['status'] = AN_STATUS_NONE;
                }
                break;
            case AN_STATUS_TEST:
                $newordertime = time() - 120;
                // -2 minutes. Order may be still in process.
                $where .= "AND (e.status = :status) AND (e.transid = '0') AND (e.timecreated < :newordertime) ";
                $params['status'] = AN_STATUS_NONE;
                $params['newordertime'] = $newordertime;
                break;
            case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW:
                $where .= 'AND (e.status IN(:status1,:status2,:status3)) ';
                $params['status1'] = AN_STATUS_AUTH;
                $params['status2'] = AN_STATUS_UNDERREVIEW;
                $params['status3'] = AN_STATUS_APPROVEDREVIEW;
                break;
            case AN_STATUS_CREDIT:
                $from .= "INNER JOIN {enrol_authorize_refunds} r ON e.id = r.orderid ";
                $where .= "AND (e.status = :status) ";
                $params['status'] = AN_STATUS_AUTHCAPTURE;
                break;
            default:
                $where .= "AND (e.status = :status) ";
                $params['status'] = $status;
                break;
        }
        if (SITEID != $courseid) {
            $where .= "AND (e.courseid = :courseid) ";
            $params['courseid'] = $courseid;
        }
    }
    // This must be always LAST where!!!
    if ($userid > 0) {
        $where .= "AND (e.userid = :userid) ";
        $params['userid'] = $userid;
    }
    if ($sort = $table->get_sql_sort()) {
        $sort = ' ORDER BY ' . $sort;
    }
    $totalcount = $DB->count_records_sql('SELECT COUNT(*) ' . $from . $where, $params);
    $table->initialbars($totalcount > $perpage);
    $table->pagesize($perpage, $totalcount);
    if ($records = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size())) {
        foreach ($records as $record) {
            $actionstatus = authorize_get_status_action($record);
            $color = authorize_get_status_color($actionstatus->status);
            $actions = '';
            if (empty($actionstatus->actions)) {
                $actions .= $strs->none;
            } else {
                foreach ($actionstatus->actions as $val) {
                    $actions .= authorize_print_action_button($record->id, $val);
                }
            }
            $table->add_data(array("<a href='index.php?order={$record->id}'>{$record->id}</a>", $record->ccname, userdate($record->timecreated), "<font style='color:{$color}'>" . $authstrs->{$actionstatus->status} . "</font>", $actions));
        }
    }
    $table->print_html();
    echo $OUTPUT->footer();
}
Esempio n. 19
0
 /**
  * Display the report.
  */
 public function display($game, $cm, $course)
 {
     global $CFG, $SESSION, $DB;
     // Define some strings.
     $strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));
     $strtimeformat = get_string('strftimedatetime');
     $strreviewquestion = get_string('reviewresponse', 'quiz');
     // Only print headers if not asked to download data.
     if (!($download = optional_param('download', null))) {
         $this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview");
     }
     // Deal with actions.
     $action = optional_param('action', '', PARAM_ACTION);
     switch ($action) {
         case 'delete':
             // Some attempts need to be deleted.
             $attemptids = optional_param('attemptid', array(), PARAM_INT);
             foreach ($attemptids as $attemptid) {
                 if ($attemptid && ($todelete = get_record('game_attempts', 'id', $attemptid))) {
                     delete_records('game_attempts', 'id', $attemptid);
                     delete_records('game_queries', 'attemptid', $attemptid);
                     // Search game_attempts for other instances by this user.
                     // If none, then delete record for this game, this user from game_grades.
                     // else recalculate best grade.
                     $userid = $todelete->userid;
                     if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
                         delete_records('game_grades', 'userid', $userid, 'gameid', $game->id);
                     } else {
                         game_save_best_score($game, $userid);
                     }
                 }
             }
             break;
     }
     // Print information on the number of existing attempts.
     if (!$download) {
         // Do not print notices when downloading.
         if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
             $a = new stdClass();
             $a->attemptnum = $attemptnum;
             $a->studentnum = count_records_select('game_attempts', "gameid = '{$game->id}' AND preview = '0'", 'COUNT(DISTINCT userid)');
             $a->studentstring = $course->students;
             notify(get_string('numattempts', 'game', $a));
         }
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     // Find out current groups mode.
     if ($groupmode = groupmode($course, $cm)) {
         // Groups are being used.
         if (!$download) {
             $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&amp;mode=overview");
         } else {
             $currentgroup = get_and_set_current_group($course, $groupmode);
         }
     } else {
         $currentgroup = get_and_set_current_group($course, $groupmode);
     }
     // Set table options.
     $noattempts = optional_param('noattempts', 0, PARAM_INT);
     $detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
     $pagesize = optional_param('pagesize', 10, PARAM_INT);
     $hasfeedback = game_has_feedback($game->id) && $game->grade > 1.0E-7;
     if ($pagesize < 1) {
         $pagesize = 10;
     }
     // Now check if asked download of data.
     if ($download) {
         $filename = clean_filename("{$course->shortname} " . format_string($game->name, true));
         $sort = '';
     }
     // Define table columns.
     $tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
     $tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
     if ($game->grade) {
         $tablecolumns[] = 'grade';
         $tableheaders[] = get_string('grade', 'game') . '/' . $game->grade;
     }
     if ($detailedmarks) {
         // We want to display marks for all questions.
         // Start by getting all questions.
         $questionlist = game_questions_in_game($game->questions);
         $questionids = explode(',', $questionlist);
         $sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance" . "  FROM {question} q," . "       {game_queries} i" . " WHERE i.gameid = '{$game->id}' AND q.id = i.questionid" . "   AND q.id IN ({$questionlist})";
         if (!($questions = get_records_sql($sql))) {
             print_error('No questions found');
         }
         $number = 1;
         foreach ($questionids as $key => $id) {
             if ($questions[$id]->length) {
                 // Only print questions of non-zero length.
                 $tablecolumns[] = '$' . $id;
                 $tableheaders[] = '#' . $number;
                 $questions[$id]->number = $number;
                 $number += $questions[$id]->length;
             } else {
                 // Get rid of zero length questions.
                 unset($questions[$id]);
                 unset($questionids[$key]);
             }
         }
     }
     if ($hasfeedback) {
         $tablecolumns[] = 'feedbacktext';
         $tableheaders[] = get_string('feedback', 'game');
     }
     if (!$download) {
         // Set up the table.
         $table = new flexible_table('mod-game-report-overview-report');
         $table->define_columns($tablecolumns);
         $table->define_headers($tableheaders);
         $table->define_baseurl($CFG->wwwroot . '/mod/game/report.php?mode=overview&amp;id=' . $cm->id . '&amp;noattempts=' . $noattempts . '&amp;detailedmarks=' . $detailedmarks . '&amp;pagesize=' . $pagesize);
         $table->sortable(true);
         $table->collapsible(true);
         $table->column_suppress('picture');
         $table->column_suppress('fullname');
         $table->column_class('picture', 'picture');
         $table->set_attribute('cellspacing', '0');
         $table->set_attribute('id', 'attempts');
         $table->set_attribute('class', 'generaltable generalbox');
         // Start working -- this is necessary as soon as the niceties are over.
         $table->setup();
     } else {
         if ($download == 'ODS') {
             require_once "{$CFG->libdir}/odslib.class.php";
             $filename .= ".ods";
             // Creating a workbook.
             $workbook = new MoodleODSWorkbook("-");
             // Sending HTTP headers.
             $workbook->send($filename);
             // Creating the first worksheet.
             $sheettitle = get_string('reportoverview', 'game');
             $myxls =& $workbook->add_worksheet($sheettitle);
             // Format types.
             $format =& $workbook->add_format();
             $format->set_bold(0);
             $formatbc =& $workbook->add_format();
             $formatbc->set_bold(1);
             $formatbc->set_align('center');
             $formatb =& $workbook->add_format();
             $formatb->set_bold(1);
             $formaty =& $workbook->add_format();
             $formaty->set_bg_color('yellow');
             $formatc =& $workbook->add_format();
             $formatc->set_align('center');
             $formatr =& $workbook->add_format();
             $formatr->set_bold(1);
             $formatr->set_color('red');
             $formatr->set_align('center');
             $formatg =& $workbook->add_format();
             $formatg->set_bold(1);
             $formatg->set_color('green');
             $formatg->set_align('center');
             // Here starts workshhet headers.
             $headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
             if ($game->grade) {
                 $headers[] = get_string('grade', 'game') . '/' . $game->grade;
             }
             if ($detailedmarks) {
                 foreach ($questionids as $id) {
                     $headers[] = '#' . $questions[$id]->number;
                 }
             }
             if ($hasfeedback) {
                 $headers[] = get_string('feedback', 'game');
             }
             $colnum = 0;
             foreach ($headers as $item) {
                 $myxls->write(0, $colnum, $item, $formatbc);
                 $colnum++;
             }
             $rownum = 1;
         } else {
             if ($download == 'Excel') {
                 require_once "{$CFG->libdir}/excellib.class.php";
                 $filename .= ".xls";
                 // Creating a workbook.
                 $workbook = new MoodleExcelWorkbook("-");
                 // Sending HTTP headers.
                 $workbook->send($filename);
                 // Creating the first worksheet.
                 $sheettitle = get_string('reportoverview', 'game');
                 $myxls =& $workbook->add_worksheet($sheettitle);
                 // Format types.
                 $format =& $workbook->add_format();
                 $format->set_bold(0);
                 $formatbc =& $workbook->add_format();
                 $formatbc->set_bold(1);
                 $formatbc->set_align('center');
                 $formatb =& $workbook->add_format();
                 $formatb->set_bold(1);
                 $formaty =& $workbook->add_format();
                 $formaty->set_bg_color('yellow');
                 $formatc =& $workbook->add_format();
                 $formatc->set_align('center');
                 $formatr =& $workbook->add_format();
                 $formatr->set_bold(1);
                 $formatr->set_color('red');
                 $formatr->set_align('center');
                 $formatg =& $workbook->add_format();
                 $formatg->set_bold(1);
                 $formatg->set_color('green');
                 $formatg->set_align('center');
                 // Here starts workshhet headers.
                 $headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
                 if ($game->grade) {
                     $headers[] = get_string('grade', 'game') . '/' . $game->grade;
                 }
                 if ($detailedmarks) {
                     foreach ($questionids as $id) {
                         $headers[] = '#' . $questions[$id]->number;
                     }
                 }
                 if ($hasfeedback) {
                     $headers[] = get_string('feedback', 'game');
                 }
                 $colnum = 0;
                 foreach ($headers as $item) {
                     $myxls->write(0, $colnum, $item, $formatbc);
                     $colnum++;
                 }
                 $rownum = 1;
             } else {
                 if ($download == 'CSV') {
                     $filename .= ".txt";
                     header("Content-Type: application/download\n");
                     header("Content-Disposition: attachment; filename=\"{$filename}\"");
                     header("Expires: 0");
                     header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
                     header("Pragma: public");
                     $headers = get_string('fullname') . "\t" . get_string('startedon', 'game') . "\t" . get_string('timecompleted', 'game') . "\t" . get_string('attemptduration', 'game');
                     if ($game->grade) {
                         $headers .= "\t" . get_string('grade', 'game') . "/" . $game->grade;
                     }
                     if ($detailedmarks) {
                         foreach ($questionids as $id) {
                             $headers .= "\t#" . $questions[$id]->number;
                         }
                     }
                     if ($hasfeedback) {
                         $headers .= "\t" . get_string('feedback', 'game');
                     }
                     echo $headers . " \n";
                 }
             }
         }
     }
     $contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id));
     // Construct the SQL.
     $select = 'SELECT qa.id,' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS uniqueid, ' . 'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, ' . 'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
     if ($course->id != SITEID) {
         // This is too complicated, so just do it for each of the four cases.
         if (!empty($currentgroup) && empty($noattempts)) {
             // We want a particular group and we only want to see students WITH attempts.
             // So join on groups_members and do an inner join on attempts.
             $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . groups_members_join_sql() . 'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id;
             $where = ' WHERE ra.contextid ' . $contextlists . ' AND ' . groups_members_where_sql($currentgroup) . ' AND qa.preview = 0';
         } else {
             if (!empty($currentgroup) && !empty($noattempts)) {
                 // We want a particular group and we want to do something funky with attempts.
                 // So join on groups_members and left join on attempts...
                 $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . groups_members_join_sql() . 'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id;
                 $where = ' WHERE ra.contextid ' . $contextlists . ' AND ' . groups_members_where_sql($currentgroup);
                 if ($noattempts == 1) {
                     // Noattempts = 1 means only no attempts, so make the left join ask.
                     // For only records where the right is null (no attempts).
                     $where .= ' AND qa.userid IS NULL';
                     // Show ONLY no attempts.
                 } else {
                     // We are including attempts, so exclude previews.
                     $where .= ' AND qa.preview = 0';
                 }
             } else {
                 if (empty($currentgroup)) {
                     // We don't care about group, and we to do something funky with attempts.
                     // So do a left join on attempts.
                     $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . ' LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id;
                     $where = " WHERE ra.contextid {$contextlists}";
                     if (empty($noattempts)) {
                         // Show ONLY students with attempts.
                         $where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0';
                     } else {
                         if ($noattempts == 1) {
                             // The noattempts = 1 means only no attempts,.
                             // So make the left join ask for only records where the right is null (no attempts).
                             // Show ONLY students without attempts.
                             $where .= ' AND qa.userid IS NULL';
                         } else {
                             if ($noattempts == 3) {
                                 // We want all attempts.
                                 $from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
                                 $where = ' WHERE qa.gameid = ' . $game->id . ' AND qa.preview = 0';
                             }
                         }
                     }
                     // The noattempts = 2 means we want all students, with or without attempts.
                 }
             }
         }
         $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ')) ' . $from . $where;
     } else {
         if (empty($noattempts)) {
             $from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
             $where = ' WHERE qa.gameid = ' . $game->id . ' AND qa.preview = 0';
             $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ')) ' . $from . $where;
         }
     }
     if (!$download) {
         // Add extra limits due to initials bar.
         if ($table->get_sql_where()) {
             $where .= ' AND ' . $table->get_sql_where();
         }
         // Count the records NOW, before funky question grade sorting messes up $from.
         if (!empty($countsql)) {
             $totalinitials = count_records_sql($countsql);
             if ($table->get_sql_where()) {
                 $countsql .= ' AND ' . $table->get_sql_where();
             }
             $total = count_records_sql($countsql);
         }
         // Add extra limits due to sorting by question grade.
         if ($sort = $table->get_sql_sort()) {
             $sortparts = explode(',', $sort);
             $newsort = array();
             $questionsort = false;
             foreach ($sortparts as $sortpart) {
                 $sortpart = trim($sortpart);
                 if (substr($sortpart, 0, 1) == '$') {
                     if (!$questionsort) {
                         $qid = intval(substr($sortpart, 1));
                         $select .= ', grade ';
                         $from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id ' . 'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded ';
                         $where .= ' AND (' . sql_isnull('qns.questionid') . ' OR qns.questionid = ' . $qid . ')';
                         $newsort[] = 'grade ' . (strpos($sortpart, 'ASC') ? 'ASC' : 'DESC');
                         $questionsort = true;
                     }
                 } else {
                     $newsort[] = $sortpart;
                 }
             }
             // Reconstruct the sort string.
             $sort = ' ORDER BY ' . implode(', ', $newsort);
         }
         // Fix some wired sorting.
         if (empty($sort)) {
             $sort = ' ORDER BY qa.id';
         }
         $table->pagesize($pagesize, $total);
     }
     // If there is feedback, include it in the query.
     if ($hasfeedback) {
         $select .= ', qf.feedbacktext ';
         $from .= " JOIN {game_feedback} qf ON " . "qf.gameid = {$game->id} AND qf.mingrade <= qa.score * {$game->grade}  AND qa.score * {$game->grade} < qf.maxgrade";
     }
     // Fetch the attempts.
     if (!empty($from)) {
         // If we're in the site course and displaying no attempts, it makes no sense to do the query.
         if (!$download) {
             $attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size());
         } else {
             $attempts = get_records_sql($select . $from . $where . $sort);
         }
     } else {
         $attempts = array();
     }
     // Build table rows.
     if (!$download) {
         $table->initialbars($totalinitials > 20);
     }
     if (!empty($attempts) || !empty($noattempts)) {
         if ($attempts) {
             foreach ($attempts as $attempt) {
                 $picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
                 /* Uncomment the commented lines below if you are choosing to show unenrolled users and
                  * have uncommented the corresponding lines earlier in this script
                  * if (in_array($attempt->userid, $unenrolledusers)) {
                  *    $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.
                  *       '/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
                  *}
                  *else {
                  *   $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
                  *      $attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
                  *}
                  */
                 if (!$download) {
                     $row = array('<input type="checkbox" name="attemptid[]" value="' . $attempt->attempt . '" />', $picture, $userlink, empty($attempt->attempt) ? '-' : '<a href="review.php?q=' . $game->id . '&amp;attempt=' . $attempt->attempt . '">' . userdate($attempt->timestart, $strtimeformat) . '</a>', empty($attempt->timefinish) ? '-' : '<a href="review.php?q=' . $game->id . '&amp;attempt=' . $attempt->attempt . '">' . userdate($attempt->timefinish, $strtimeformat) . '</a>', empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration)));
                 } else {
                     $row = array(fullname($attempt), empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat), empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat), empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration)));
                 }
                 if ($game->grade) {
                     if (!$download) {
                         $row[] = $attempt->score === null ? '-' : '<a href="review.php?q=' . $game->id . '&amp;attempt=' . $attempt->attempt . '">' . round($attempt->score * $game->grade, $game->decimalpoints) . '</a>';
                     } else {
                         $row[] = $attempt->score === null ? '-' : round($attempt->score * $game->grade, $game->decimalpoints);
                     }
                 }
                 if ($detailedmarks) {
                     if (empty($attempt->attempt)) {
                         foreach ($questionids as $questionid) {
                             $row[] = '-';
                         }
                     } else {
                         foreach ($questionids as $questionid) {
                             if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
                                 $grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $game->decimalpoints);
                             } else {
                                 $grade = '--';
                             }
                             if (!$download) {
                                 $row[] = link_to_popup_window('/mod/game/reviewquestion.php?state=' . $gradedstateid . '&amp;number=' . $questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
                             } else {
                                 $row[] = $grade;
                             }
                         }
                     }
                 }
                 if ($hasfeedback) {
                     if ($attempt->timefinish) {
                         $row[] = $attempt->feedbacktext;
                     } else {
                         $row[] = '-';
                     }
                 }
                 if (!$download) {
                     $table->add_data($row);
                 } else {
                     if ($download == 'Excel' or $download == 'ODS') {
                         $colnum = 0;
                         foreach ($row as $item) {
                             $myxls->write($rownum, $colnum, $item, $format);
                             $colnum++;
                         }
                         $rownum++;
                     } else {
                         if ($download == 'CSV') {
                             $text = implode("\t", $row);
                             echo $text . " \n";
                         }
                     }
                 }
             }
         }
         if (!$download) {
             // Start form.
             echo '<div id="tablecontainer">';
             echo '<form id="attemptsform" method="post" action="report.php" ' . 'onsubmit="var menu = document.getElementById(\'menuaction\'); ' . 'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\'' . $strreallydel . '\') : true);">';
             echo '<div>';
             echo '<input type="hidden" name="id" value="' . $cm->id . '" />';
             echo '<input type="hidden" name="mode" value="overview" />';
             // Print table.
             $table->print_html();
             // Print "Select all" etc..
             if (!empty($attempts)) {
                 echo '<table id="commands">';
                 echo '<tr><td>';
                 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'game') . '</a> / ';
                 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'game') . '</a> ';
                 echo '&nbsp;&nbsp;';
                 $options = array('delete' => get_string('delete'));
                 echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
                 echo '<noscript id="noscriptmenuaction" style="display: inline;"><div>';
                 echo '<input type="submit" value="' . get_string('go') . '" /></div></noscript>';
                 echo '<script type="text/javascript">' . "\n<!--\n" . 'document.getElementById("noscriptmenuaction").style.display = "none";' . "\n-->\n" . '</script>';
                 echo '</td></tr></table>';
             }
             // Close form.
             echo '</div>';
             echo '</form></div>';
             if (!empty($attempts)) {
                 echo '<table class="boxaligncenter"><tr>';
                 $options = array();
                 $options["id"] = "{$cm->id}";
                 $options["q"] = "{$game->id}";
                 $options["mode"] = "overview";
                 $options['sesskey'] = sesskey();
                 $options["noheader"] = "yes";
                 $options['noattempts'] = $noattempts;
                 $options['detailedmarks'] = $detailedmarks;
                 echo '<td>';
                 $options["download"] = "ODS";
                 print_single_button("report.php", $options, get_string("downloadods", 'game'));
                 echo "</td>\n";
                 echo '<td>';
                 $options["download"] = "Excel";
                 print_single_button("report.php", $options, get_string("downloadexcel"));
                 echo "</td>\n";
                 echo '<td>';
                 $options["download"] = "CSV";
                 print_single_button('report.php', $options, get_string("downloadtext"));
                 echo "</td>\n";
                 echo "<td>";
                 helpbutton('overviewdownload', get_string('overviewdownload', 'quiz'), 'game');
                 echo "</td>\n";
                 echo '</tr></table>';
             }
         } else {
             if ($download == 'Excel' or $download == 'ODS') {
                 $workbook->close();
                 exit;
             } else {
                 if ($download == 'CSV') {
                     exit;
                 }
             }
         }
     } else {
         if (!$download) {
             $table->print_html();
         }
     }
     // Print display options.
     echo '<div class="controls">';
     echo '<form id="options" action="report.php" method="get">';
     echo '<div>';
     echo '<p>' . get_string('displayoptions', 'game') . ': </p>';
     echo '<input type="hidden" name="id" value="' . $cm->id . '" />';
     echo '<input type="hidden" name="q" value="' . $game->id . '" />';
     echo '<input type="hidden" name="mode" value="overview" />';
     echo '<input type="hidden" name="noattempts" value="0" />';
     echo '<input type="hidden" name="detailedmarks" value="0" />';
     echo '<table id="overview-options" class="boxaligncenter">';
     echo '<tr align="left">';
     echo '<td><label for="pagesize">' . get_string('pagesize', 'game') . '</label></td>';
     echo '<td><input type="text" id="pagesize" name="pagesize" size="3" value="' . $pagesize . '" /></td>';
     echo '</tr>';
     echo '<tr align="left">';
     echo '<td colspan="2">';
     $options = array(0 => get_string('attemptsonly', 'game', $course->students));
     if ($course->id != SITEID) {
         $options[1] = get_string('noattemptsonly', 'game', $course->students);
         $options[2] = get_string('allstudents', 'game', $course->students);
         $options[3] = get_string('allattempts', 'game');
     }
     choose_from_menu($options, 'noattempts', $noattempts, '');
     echo '</td></tr>';
     echo '<tr align="left">';
     echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" ' . ($detailedmarks ? 'checked="checked" ' : '') . 'value="1" /> <label for="checkdetailedmarks">' . get_string('showdetailedmarks', 'game') . '</label> ';
     echo '</td></tr>';
     echo '<tr><td colspan="2" align="center">';
     echo '<input type="submit" value="' . get_string('go') . '" />';
     echo '</td></tr></table>';
     echo '</div>';
     echo '</form>';
     echo '</div>';
     echo "\n";
     return true;
 }
Esempio n. 20
0
/**
 * authorize_print_orders
 *
 */
function authorize_print_orders($courseid, $userid)
{
    global $CFG, $USER, $SITE;
    global $strs, $authstrs;
    require_once $CFG->libdir . '/tablelib.php';
    $perpage = 10;
    $status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
    $searchtype = optional_param('searchtype', 'id', PARAM_ALPHA);
    $idortransid = optional_param('idortransid', '0', PARAM_INT);
    $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL);
    $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid));
    if ($showonlymy || !$canmanagepayments) {
        $userid = $USER->id;
    }
    $baseurl = $CFG->wwwroot . "/enrol/authorize/index.php?user={$userid}";
    $statusmenu = array(AN_STATUS_NONE => $strs->all, AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, AN_STATUS_CREDIT => $authstrs->refunded, AN_STATUS_VOID => $authstrs->cancelled, AN_STATUS_EXPIRE => $authstrs->expired, AN_STATUS_UNDERREVIEW => $authstrs->underreview, AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, AN_STATUS_TEST => $authstrs->tested);
    $sql = "SELECT c.id, c.fullname FROM {$CFG->prefix}course c INNER JOIN {$CFG->prefix}enrol_authorize e ON c.id = e.courseid ";
    if ($userid > 0) {
        $sql .= "WHERE (e.userid='{$userid}') ";
    }
    $sql .= "ORDER BY c.sortorder, c.fullname";
    if ($popupcrs = get_records_sql_menu($sql)) {
        $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs;
        echo "<table border='0' width='100%' cellspacing='0' cellpadding='3' class='generaltable generalbox'>";
        echo "<tr>";
        echo "<td width='5%' valign='top'>{$strs->status}: </td><td width='10%'>";
        popup_form($baseurl . '&amp;course=' . $courseid . '&amp;status=', $statusmenu, 'statusmenu', $status, '', '', '', false);
        if ($canmanagepayments) {
            echo "<br />\n";
            print_checkbox('showonlymy', '1', $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), '', "var locationtogo = '{$CFG->wwwroot}/enrol/authorize/index.php?status={$status}&amp;course={$courseid}';\n                                  locationtogo += '&amp;user='******'{$USER->id}' : '0');\n                                  top.location.href=locationtogo;");
        }
        echo "</td>\n";
        echo "<td width='5%' valign='top'>{$strs->course}: </td><td width='10%' valign='top'>";
        popup_form($baseurl . '&amp;status=' . $status . '&amp;course=', $popupcrs, 'coursesmenu', $courseid, '', '', '', false);
        echo "</td>\n";
        if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
            echo "<form method='get' action='uploadcsv.php'>";
            echo "<td rowspan='2' align='right' valign='middle' width='50%'><div><input type='submit' value='" . get_string('uploadcsv', 'enrol_authorize') . "' /></div></td>";
            echo "</form>";
        } else {
            echo "<td rowspan=2 width='100%'>&nbsp;</td>";
        }
        echo "</tr>\n";
        echo "<tr><td>{$strs->search}: </td>";
        $searchmenu = array('id' => $authstrs->orderid, 'transid' => $authstrs->transid);
        echo "<form method='POST' action='index.php' autocomplete='off'>";
        echo "<td colspan='3'>";
        choose_from_menu($searchmenu, 'searchtype', $searchtype, '');
        echo " = <fieldset class=\"invisiblefieldset\"><input type='text' size='14' name='idortransid' value='' /> ";
        echo "<input type='submit' value='{$strs->search}' /></fieldset></td>";
        echo "</form>";
        echo "</tr>";
        echo "</table>";
    }
    $table = new flexible_table('enrol-authorize');
    $table->set_attribute('width', '100%');
    $table->set_attribute('cellspacing', '0');
    $table->set_attribute('cellpadding', '3');
    $table->set_attribute('id', 'orders');
    $table->set_attribute('class', 'generaltable generalbox');
    $table->define_columns(array('id', 'timecreated', 'userid', 'status', ''));
    $table->define_headers(array($authstrs->orderid, $strs->time, $authstrs->nameoncard, $strs->status, $strs->action));
    $table->define_baseurl($baseurl . "&amp;status={$status}&amp;course={$courseid}");
    $table->sortable(true, 'id', SORT_DESC);
    $table->pageable(true);
    $table->setup();
    $select = "SELECT e.id, e.paymentmethod, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime ";
    $from = "FROM {$CFG->prefix}enrol_authorize e ";
    $where = "WHERE (1=1) ";
    if ($status > AN_STATUS_NONE) {
        switch ($status) {
            case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW:
                $where .= 'AND (e.status IN(' . AN_STATUS_AUTH . ',' . AN_STATUS_UNDERREVIEW . ',' . AN_STATUS_APPROVEDREVIEW . ')) ';
                break;
            case AN_STATUS_CREDIT:
                $from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds r ON e.id = r.orderid ";
                $where .= "AND (e.status = '" . AN_STATUS_AUTHCAPTURE . "') ";
                break;
            case AN_STATUS_TEST:
                $newordertime = time() - 120;
                // -2 minutes. Order may be still in process.
                $where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < {$newordertime}) ";
                break;
            default:
                $where .= "AND (e.status = '{$status}') ";
                break;
        }
    } else {
        if (empty($CFG->an_test)) {
            $where .= "AND (e.status != '" . AN_STATUS_NONE . "') ";
        }
    }
    if ($courseid != SITEID) {
        $where .= "AND (e.courseid = '" . $courseid . "') ";
    }
    if (!empty($idortransid)) {
        // Ignore old where.
        if ($searchtype == 'transid') {
            $where = "WHERE (e.transid = {$idortransid}) ";
        } else {
            $where = "WHERE (e.id = {$idortransid}) ";
        }
    }
    // This must be always last where!!!
    if ($userid > 0) {
        $where .= "AND (e.userid = '" . $userid . "') ";
    }
    if ($sort = $table->get_sql_sort()) {
        $sort = ' ORDER BY ' . $sort;
    }
    $totalcount = count_records_sql('SELECT COUNT(*) ' . $from . $where);
    $table->initialbars($totalcount > $perpage);
    $table->pagesize($perpage, $totalcount);
    if ($records = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size())) {
        foreach ($records as $record) {
            $actionstatus = authorize_get_status_action($record);
            $color = authorize_get_status_color($actionstatus->status);
            $actions = '';
            if (empty($actionstatus->actions)) {
                $actions .= $strs->none;
            } else {
                foreach ($actionstatus->actions as $value) {
                    $actions .= "&nbsp;&nbsp;<a href='index.php?{$value}=y&amp;sesskey={$USER->sesskey}&amp;order={$record->id}'>{$authstrs->{$value}}</a> ";
                }
            }
            $table->add_data(array("<a href='index.php?order={$record->id}'>{$record->id}</a>", userdate($record->timecreated), $record->ccname, "<font style='color:{$color}'>" . $authstrs->{$actionstatus->status} . "</font>", $actions));
        }
    }
    $table->print_html();
}
Esempio n. 21
0
/// because it retrieves ALL users (without role checking) - MDL-14034
if ($table->get_sql_sort()) {
    $sort = ' ORDER BY ' . $table->get_sql_sort();
    if ($context->id != $frontpagectx->id or $roleid >= 0) {
        $sort .= ', r.hidden DESC';
    }
} else {
    $sort = '';
    if ($context->id != $frontpagectx->id or $roleid >= 0) {
        $sort .= ' ORDER BY r.hidden DESC';
    }
}
$matchcount = count_records_sql('SELECT COUNT(distinct u.id) ' . $from . $where . $wheresearch);
$table->initialbars(true);
$table->pagesize($perpage, $matchcount);
$userlist = get_recordset_sql($select . $from . $where . $wheresearch . $sort, $table->get_page_start(), $table->get_page_size());
if ($context->id == $frontpagectx->id) {
    $strallsiteusers = get_string('allsiteusers', 'role');
    if ($CFG->defaultfrontpageroleid) {
        if ($fprole = get_record('role', 'id', $CFG->defaultfrontpageroleid)) {
            $fprole = role_get_name($fprole, $frontpagectx);
            $strallsiteusers = "{$strallsiteusers} ({$fprole})";
        }
    }
    $rolenames = array(-1 => $strallsiteusers) + $rolenames;
}
/// If there are multiple Roles in the course, then show a drop down menu for switching
if (count($rolenames) > 1) {
    echo '<div class="rolesform">';
    echo '<label for="rolesform_jump">' . get_string('currentrole', 'role') . '&nbsp;</label>';
    if ($context->id != $frontpagectx->id) {
if (!empty($sort)) {
    $sql .= " ORDER BY {$sort}";
} else {
    $sql .= " ORDER BY resolutionpriority ASC";
}
/// set list length limits
/*
if ($limit > $numrecords){
    $offset = 0;
} else {
    $offset = $limit * ($page - 1);
}
$sql = $sql . ' LIMIT ' . $limit . ',' . $offset;
*/
//
$issues = get_records_sql($sql, $table->get_page_start(), $table->get_page_size());
$maxpriority = get_field_select('tracker_issue', 'MAX(resolutionpriority)', " trackerid = {$tracker->id} GROUP BY trackerid ");
if (!empty($issues)) {
    /// product data for table
    foreach ($issues as $issue) {
        $issuenumber = "<a href=\"view.php?id={$cm->id}&amp;issueid={$issue->id}\">{$tracker->ticketprefix}{$issue->id}</a>";
        $summary = "<a href=\"view.php?id={$cm->id}&amp;view=view&amp;screen=viewanissue&amp;issueid={$issue->id}\">" . format_string($issue->summary) . '</a>';
        $datereported = date('Y/m/d h:i', $issue->datereported);
        $user = get_record('user', 'id', $issue->reportedby);
        $reportedby = fullname($user);
        $user = get_record('user', 'id', $issue->assignedto);
        if (has_capability('mod/tracker:manage', $context)) {
            // managers can assign bugs
            $status = choose_from_menu($STATUSKEYS, "status{$issue->id}", $issue->status, '', "document.forms['manageform'].schanged{$issue->id}.value = 1;", '', true) . "<input type=\"hidden\" name=\"schanged{$issue->id}\" value=\"0\" />";
            $developers = tracker_getdevelopers($context);
            foreach ($developers as $developer) {
Esempio n. 23
0
     $table->pagesize($pagesize, $total);
     echo '<div class="quizattemptcounts">';
     if ($count->nbresults == $count->nbattempts) {
         echo get_string('reportcountattempts', 'scorm', $count);
     } else {
         if ($count->nbattempts > 0) {
             echo get_string('reportcountallattempts', 'scorm', $count);
         } else {
             echo $count->nbusers . ' ' . get_string('users');
         }
     }
     echo '</div>';
 }
 // Fetch the attempts
 if (!$download) {
     $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size());
     echo '<div id="scormtablecontainer">';
     if ($candelete) {
         // Start form
         $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
         echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) . '" onsubmit="return confirm(\'' . $strreallydel . '\');">';
         echo '<input type="hidden" name="action" value="delete"/>';
         echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
         echo '<div style="display: none;">';
         echo html_writer::input_hidden_params($reporturlwithdisplayoptions);
         echo '</div>';
         echo '<div>';
     }
     $table->initialbars($totalinitials > 20);
     // Build table rows
 } else {
Esempio n. 24
0
 /**
  * Prints a table with users and their attempts
  *
  * @return void
  * @todo Add current grade to the table
  *       Finnish documenting
  **/
 function view_question($quiz, $question)
 {
     global $CFG, $db;
     $users = get_course_students($quiz->course);
     $userids = implode(',', array_keys($users));
     $usercount = count($users);
     // set up table
     $tablecolumns = array('picture', 'fullname', 'timefinish', 'grade');
     $tableheaders = array('', get_string('name'), get_string("completedon", "quiz"), '');
     $table = new flexible_table('mod-quiz-report-grading');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/quiz/report.php?mode=grading&amp;q=' . $quiz->id . '&amp;action=viewquestion&amp;questionid=' . $question->id);
     $table->sortable(true);
     $table->initialbars($usercount > 20);
     // will show initialbars if there are more than 20 users
     $table->pageable(true);
     $table->collapsible(true);
     $table->column_suppress('fullname');
     $table->column_suppress('picture');
     $table->column_suppress('grade');
     $table->column_class('picture', 'picture');
     // attributes in the table tag
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'generaltable generalbox');
     $table->set_attribute('align', 'center');
     //$table->set_attribute('width', '50%');
     // get it ready!
     $table->setup();
     // this sql is a join of the attempts table and the user table.  I do this so I can sort by user name and attempt number (not id)
     $select = 'SELECT ' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS userattemptid, qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, u.id AS userid, u.firstname, u.lastname, u.picture ';
     $from = 'FROM ' . $CFG->prefix . 'user u LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = ' . $quiz->id . ') ';
     $where = 'WHERE u.id IN (' . $userids . ') ';
     $where .= 'AND ' . $db->IfNull('qa.attempt', '0') . ' != 0 ';
     $where .= 'AND ' . $db->IfNull('qa.timefinish', '0') . ' != 0 ';
     $where .= 'AND preview = 0 ';
     // ignore previews
     if ($table->get_sql_where()) {
         // forgot what this does
         $where .= 'AND ' . $table->get_sql_where();
     }
     // sorting of the table
     if ($sort = $table->get_sql_sort()) {
         $sort = 'ORDER BY ' . $sort;
         // seems like I would need to have u. or qa. infront of the ORDER BY attribues... but seems to work..
     } else {
         // my default sort rule
         $sort = 'ORDER BY u.firstname, u.lastname, qa.timefinish ASC';
     }
     // set up the pagesize
     $total = count_records_sql('SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ')) ' . $from . $where);
     $table->pagesize(10, $total);
     // get the attempts and process them
     if ($attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size())) {
         foreach ($attempts as $attempt) {
             $picture = print_user_picture($attempt->userid, $quiz->course, $attempt->picture, false, true);
             // link to student profile
             $userlink = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$attempt->userid}&amp;course={$quiz->course}\">" . fullname($attempt, true) . '</a>';
             if (!$this->is_graded($question, $attempt)) {
                 $style = 'class="manual-ungraded"';
             } else {
                 $style = 'class="manual-graded"';
             }
             // link for the attempt
             $attemptlink = "<a {$style} href=\"report.php?mode=grading&amp;action=grade&amp;q={$quiz->id}&amp;questionid={$question->id}&amp;attemptid={$attempt->attemptid}\">" . userdate($attempt->timefinish, get_string('strftimedatetime')) . '</a>';
             // grade all attempts for this user
             $gradelink = "<a href=\"report.php?mode=grading&amp;action=grade&amp;q={$quiz->id}&amp;questionid={$question->id}&amp;userid={$attempt->userid}\">" . get_string('grade') . '</a>';
             $table->add_data(array($picture, $userlink, $attemptlink, $gradelink));
         }
     }
     // grade all and "back" links
     $links = "<div class=\"boxaligncenter\"><a href=\"report.php?mode=grading&amp;action=grade&amp;q={$quiz->id}&amp;questionid={$question->id}&amp;gradeall=1\">" . get_string('gradeall', 'quiz') . '</a> | ' . "<a href=\"report.php?mode=grading&amp;q={$quiz->id}&amp;action=viewquestions\">" . get_string('backtoquestionlist', 'quiz') . '</a></div>' . print_heading($question->name);
     echo $links;
     echo '<div id="tablecontainer">';
     $table->print_html();
     echo '</div>';
     echo $links;
 }
Esempio n. 25
0
 /**
  *  Display all the submissions ready for grading
  *
  * @global object
  * @global object
  * @global object
  * @global object
  * @param string $message
  * @return bool|void
  */
 function display_submissions($message = '')
 {
     global $CFG, $DB, $USER, $DB, $OUTPUT;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->cm->id, $this->assignment->id, $this->cm->id);
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
         echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>';
     }
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Check to see if groups are being used in this assignment
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . get_string('submission', 'assignment') . ')', get_string('lastmodified') . ' (' . get_string('grade') . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '100%');
     //$table->set_attribute('align', 'center');
     $table->no_sorting('finalgrade');
     $table->no_sorting('outcome');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
     if (empty($users)) {
         echo $OUTPUT->heading(get_string('nosubmitusers', 'assignment'));
         return true;
     }
     /// Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                       s.id AS submissionid, s.grade, s.submissioncomment,
                       s.timemodified, s.timemarked,
                       COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
     $sql = 'FROM {user} u ' . 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                                                               AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     if (($ausers = $DB->get_records_sql($select . $sql . $sort, null, $table->get_page_start(), $table->get_page_size())) !== false) {
         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             $final_grade = $grading_info->items[0]->grades[$auser->id];
             $grademax = $grading_info->items[0]->grademax;
             $final_grade->formatted_grade = round($final_grade->grade, 2) . ' / ' . round($grademax, 2);
             $locked_overridden = 'locked';
             if ($final_grade->overridden) {
                 $locked_overridden = 'overridden';
             }
             /// Calculate user status
             $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified;
             $picture = $OUTPUT->user_picture(moodle_user_picture::make($auser, $course->id));
             if (empty($auser->submissionid)) {
                 $auser->grade = -1;
                 //no submission yet
             }
             if (!empty($auser->submissionid)) {
                 ///Prints student answer and student modified date
                 ///attach file or print link to student answer, depending on the type of the assignment.
                 ///Refer to print_student_answer in inherited classes.
                 if ($auser->timemodified > 0) {
                     $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>';
                 } else {
                     $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 }
                 ///Print grade, dropdown or text
                 if ($auser->timemarked > 0) {
                     $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                             $select->nothingvalue = '-1';
                             $select->tabindex = $tabindex++;
                             $menu = $OUTPUT->select($select);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 } else {
                     $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                             $select->nothingvalue = '-1';
                             $select->tabindex = $tabindex++;
                             $menu = $OUTPUT->select($select);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 }
                 ///Print Comment
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>';
                     }
                 }
             } else {
                 $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 if ($final_grade->locked or $final_grade->overridden) {
                     $grade = '<div id="g' . $auser->id . '">' . $final_grade->formatted_grade . '</div>';
                 } else {
                     if ($quickgrade) {
                         // allow editing
                         $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                         $select->nothingvalue = '-1';
                         $select->tabindex = $tabindex++;
                         $menu = $OUTPUT->select($select);
                         $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">-</div>';
                     }
                 }
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">&nbsp;</div>';
                     }
                 }
             }
             if (empty($auser->status)) {
                 /// Confirm we have exclusively 0 or 1
                 $auser->status = 0;
             } else {
                 $auser->status = 1;
             }
             $buttontext = $auser->status == 1 ? $strupdate : $strgrade;
             ///No more buttons, we use popups ;-).
             $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++;
             $link = html_link::make($popup_url, $buttontext);
             $link->add_action(new popup_action('click', $link->url, 'grade' . $auser->id, array('height' => 600, 'width' => 700)));
             $link->title = $buttontext;
             $button = $OUTPUT->link($link);
             $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>';
             $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>';
             $outcomes = '';
             if ($uses_outcomes) {
                 foreach ($grading_info->outcomes as $n => $outcome) {
                     $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>';
                     $options = make_grades_menu(-$outcome->scaleid);
                     if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                         $options[0] = get_string('nooutcome', 'grades');
                         $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>';
                     } else {
                         $outcomes .= ' ';
                         $select = html_select::make($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'));
                         $select->nothingvalue = '0';
                         $select->tabindex = $tabindex++;
                         $select->id = 'outcome_' . $n . '_' . $auser->id;
                         $outcomes .= $OUTPUT->select($select);
                     }
                     $outcomes .= '</div>';
                 }
             }
             $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser) . '</a>';
             $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
             if ($uses_outcomes) {
                 $row[] = $outcomes;
             }
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     if ($quickgrade) {
         echo '<form action="submissions.php" id="fastg" method="post">';
         echo '<div>';
         echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
         echo '<input type="hidden" name="mode" value="fastgrade" />';
         echo '<input type="hidden" name="page" value="' . $page . '" />';
         echo '</div>';
     }
     $table->print_html();
     /// Print the whole table
     if ($quickgrade) {
         $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? 'checked="checked"' : '';
         echo '<div class="fgcontrols">';
         echo '<div class="emailnotification">';
         echo '<label for="mailinfo">' . get_string('enableemailnotification', 'assignment') . '</label>';
         echo '<input type="hidden" name="mailinfo" value="0" />';
         echo '<input type="checkbox" id="mailinfo" name="mailinfo" value="1" ' . $lastmailinfo . ' />';
         echo $OUTPUT->help_icon(moodle_help_icon::make('emailnotification', get_string('enableemailnotification', 'assignment'), 'assignment')) . '</p></div>';
         echo '</div>';
         echo '<div class="fastgbutton"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>';
         echo '</div>';
         echo '</form>';
     }
     /// End of fast grading form
     /// Mini form for setting user preference
     echo '<div class="qgprefs">';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post"><div>';
     echo '<input type="hidden" name="updatepref" value="1" />';
     echo '<table id="optiontable">';
     echo '<tr><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo '</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     echo $OUTPUT->help_icon(moodle_help_icon::make('pagesize', get_string('pagesize', 'assignment'), 'assignment'));
     echo '</td></tr>';
     echo '<tr><td>';
     echo '<label for="quickgrade">' . get_string('quickgrade', 'assignment') . '</label>';
     echo '</td>';
     echo '<td>';
     $checked = $quickgrade ? 'checked="checked"' : '';
     echo '<input type="checkbox" id="quickgrade" name="quickgrade" value="1" ' . $checked . ' />';
     echo $OUTPUT->help_icon(moodle_help_icon::make('quickgrade', get_string('quickgrade', 'assignment'), 'assignment')) . '</p></div>';
     echo '</td></tr>';
     echo '<tr><td colspan="2">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</td></tr></table>';
     echo '</div></form></div>';
     ///End of mini form
     echo $OUTPUT->footer();
 }
Esempio n. 26
0
 /**
  * Display the report.
  */
 function display($quiz, $cm, $course)
 {
     global $CFG, $db;
     // Define some strings
     $strreallydel = addslashes(get_string('deleteattemptcheck', 'quiz'));
     $strtimeformat = get_string('strftimedatetime');
     $strreviewquestion = get_string('reviewresponse', 'quiz');
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     // Only print headers if not asked to download data
     if (!($download = optional_param('download', NULL))) {
         $this->print_header_and_tabs($cm, $course, $quiz, "overview");
     }
     if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
         //attempts need to be deleted
         require_capability('mod/quiz:deleteattempts', $context);
         $attemptids = optional_param('attemptid', array(), PARAM_INT);
         foreach ($attemptids as $attemptid) {
             add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, $attemptid, $cm->id);
             quiz_delete_attempt($attemptid, $quiz);
         }
         //No need for a redirect, any attemptids that do not exist are ignored.
         //So no problem if the user refreshes and tries to delete the same attempts
         //twice.
     }
     // Work out some display options - whether there is feedback, and whether scores should be shown.
     $hasfeedback = quiz_has_feedback($quiz->id) && $quiz->grade > 1.0E-7 && $quiz->sumgrades > 1.0E-7;
     $fakeattempt = new stdClass();
     $fakeattempt->preview = false;
     $fakeattempt->timefinish = $quiz->timeopen;
     $reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context);
     $showgrades = $quiz->grade && $quiz->sumgrades && $reviewoptions->scores;
     $pageoptions = array();
     $pageoptions['id'] = $cm->id;
     $pageoptions['q'] = $quiz->id;
     $pageoptions['mode'] = 'overview';
     /// find out current groups mode
     $currentgroup = groups_get_activity_group($cm, true);
     $reporturl = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions);
     $qmsubselect = quiz_report_qm_filter_select($quiz);
     $mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz', 'currentgroup'));
     if ($fromform = $mform->get_data()) {
         $attemptsmode = $fromform->attemptsmode;
         if ($qmsubselect) {
             //control is not on the form if
             //the grading method is not set
             //to grade one attempt per user eg. for average attempt grade.
             $qmfilter = $fromform->qmfilter;
         } else {
             $qmfilter = 0;
         }
         set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
         set_user_preference('quiz_report_pagesize', $fromform->pagesize);
         $detailedmarks = $fromform->detailedmarks;
         $pagesize = $fromform->pagesize;
     } else {
         $qmfilter = optional_param('qmfilter', 0, PARAM_INT);
         $attemptsmode = optional_param('attemptsmode', QUIZ_REPORT_ATTEMPTS_ALL, PARAM_INT);
         $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
         $pagesize = get_user_preferences('quiz_report_pagesize', 0);
     }
     if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup) {
         $attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
     }
     if (!$reviewoptions->scores) {
         $detailedmarks = 0;
     }
     if ($pagesize < 1) {
         $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE;
     }
     // We only want to show the checkbox to delete attempts
     // if the user has permissions and if the report mode is showing attempts.
     $candelete = has_capability('mod/quiz:deleteattempts', $context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
     $displayoptions = array();
     $displayoptions['attemptsmode'] = $attemptsmode;
     $displayoptions['qmfilter'] = $qmfilter;
     $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions + $displayoptions);
     if ($groupmode = groups_get_activity_groupmode($cm)) {
         // Groups are being used
         if (!$download) {
             groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
         }
     }
     // Print information on the number of existing attempts
     if (!$download) {
         //do not print notices when downloading
         if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
             echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
         }
     }
     $nostudents = false;
     if (!($students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', '', '', false))) {
         notify(get_string('nostudentsyet'));
         $nostudents = true;
         $studentslist = '';
     } else {
         $studentslist = join(',', array_keys($students));
     }
     if (empty($currentgroup)) {
         // all users who can attempt quizzes
         $groupstudentslist = '';
         $allowedlist = $studentslist;
     } else {
         // all users who can attempt quizzes and who are in the currently selected group
         if (!($groupstudents = get_users_by_capability($context, 'mod/quiz:attempt', '', '', '', '', $currentgroup, '', false))) {
             notify(get_string('nostudentsingroup'));
             $nostudents = true;
             $groupstudents = array();
         }
         $groupstudentslist = join(',', array_keys($groupstudents));
         $allowedlist = $groupstudentslist;
     }
     if (!$nostudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
         // Print information on the grading method and whether we are displaying
         //
         if (!$download) {
             //do not print notices when downloading
             if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
                 echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
             }
         }
         // Now check if asked download of data
         if ($download) {
             $filename = clean_filename("{$course->shortname} " . format_string($quiz->name, true));
         }
         // Define table columns
         $columns = array();
         $headers = array();
         if (!$download && $candelete) {
             $columns[] = 'checkbox';
             $headers[] = NULL;
         }
         if (!$download && $CFG->grade_report_showuserimage) {
             $columns[] = 'picture';
             $headers[] = '';
         }
         $columns[] = 'fullname';
         $headers[] = get_string('name');
         if ($CFG->grade_report_showuseridnumber) {
             $columns[] = 'idnumber';
             $headers[] = get_string('idnumber');
         }
         $columns[] = 'timestart';
         $headers[] = get_string('startedon', 'quiz');
         $columns[] = 'timefinish';
         $headers[] = get_string('timecompleted', 'quiz');
         $columns[] = 'duration';
         $headers[] = get_string('attemptduration', 'quiz');
         if ($showgrades) {
             $columns[] = 'sumgrades';
             $headers[] = get_string('grade', 'quiz') . '/' . $quiz->grade;
         }
         if ($detailedmarks) {
             // we want to display marks for all questions
             $questions = quiz_report_load_questions($quiz);
             foreach ($questions as $id => $question) {
                 // Ignore questions of zero length
                 $columns[] = 'qsgrade' . $id;
                 $headers[] = '#' . $question->number;
             }
         }
         if ($hasfeedback) {
             $columns[] = 'feedbacktext';
             $headers[] = get_string('feedback', 'quiz');
         }
         if (!$download) {
             // Set up the table
             $table = new flexible_table('mod-quiz-report-overview-report');
             $table->define_columns($columns);
             $table->define_headers($headers);
             $table->define_baseurl($reporturlwithdisplayoptions->out());
             $table->sortable(true);
             $table->collapsible(true);
             $table->column_suppress('picture');
             $table->column_suppress('fullname');
             $table->column_suppress('idnumber');
             $table->no_sorting('feedbacktext');
             $table->column_class('picture', 'picture');
             $table->column_class('fullname', 'bold');
             $table->column_class('sumgrades', 'bold');
             $table->set_attribute('cellspacing', '0');
             $table->set_attribute('id', 'attempts');
             $table->set_attribute('class', 'generaltable generalbox');
             // Start working -- this is necessary as soon as the niceties are over
             $table->setup();
         } else {
             if ($download == 'ODS') {
                 require_once "{$CFG->libdir}/odslib.class.php";
                 $filename .= ".ods";
                 // Creating a workbook
                 $workbook = new MoodleODSWorkbook("-");
                 // Sending HTTP headers
                 $workbook->send($filename);
                 // Creating the first worksheet
                 $sheettitle = get_string('reportoverview', 'quiz');
                 $myxls =& $workbook->add_worksheet($sheettitle);
                 // format types
                 $format =& $workbook->add_format();
                 $format->set_bold(0);
                 $formatbc =& $workbook->add_format();
                 $formatbc->set_bold(1);
                 $formatbc->set_align('center');
                 $formatb =& $workbook->add_format();
                 $formatb->set_bold(1);
                 $formaty =& $workbook->add_format();
                 $formaty->set_bg_color('yellow');
                 $formatc =& $workbook->add_format();
                 $formatc->set_align('center');
                 $formatr =& $workbook->add_format();
                 $formatr->set_bold(1);
                 $formatr->set_color('red');
                 $formatr->set_align('center');
                 $formatg =& $workbook->add_format();
                 $formatg->set_bold(1);
                 $formatg->set_color('green');
                 $formatg->set_align('center');
                 // Here starts workshhet headers
                 $colnum = 0;
                 foreach ($headers as $item) {
                     $myxls->write(0, $colnum, $item, $formatbc);
                     $colnum++;
                 }
                 $rownum = 1;
             } else {
                 if ($download == 'Excel') {
                     require_once "{$CFG->libdir}/excellib.class.php";
                     $filename .= ".xls";
                     // Creating a workbook
                     $workbook = new MoodleExcelWorkbook("-");
                     // Sending HTTP headers
                     $workbook->send($filename);
                     // Creating the first worksheet
                     $sheettitle = get_string('reportoverview', 'quiz');
                     $myxls =& $workbook->add_worksheet($sheettitle);
                     // format types
                     $format =& $workbook->add_format();
                     $format->set_bold(0);
                     $formatbc =& $workbook->add_format();
                     $formatbc->set_bold(1);
                     $formatbc->set_align('center');
                     $formatb =& $workbook->add_format();
                     $formatb->set_bold(1);
                     $formaty =& $workbook->add_format();
                     $formaty->set_bg_color('yellow');
                     $formatc =& $workbook->add_format();
                     $formatc->set_align('center');
                     $formatr =& $workbook->add_format();
                     $formatr->set_bold(1);
                     $formatr->set_color('red');
                     $formatr->set_align('center');
                     $formatg =& $workbook->add_format();
                     $formatg->set_bold(1);
                     $formatg->set_color('green');
                     $formatg->set_align('center');
                     $colnum = 0;
                     foreach ($headers as $item) {
                         $myxls->write(0, $colnum, $item, $formatbc);
                         $colnum++;
                     }
                     $rownum = 1;
                 } else {
                     if ($download == 'CSV') {
                         $filename .= ".txt";
                         header("Content-Type: application/download\n");
                         header("Content-Disposition: attachment; filename=\"{$filename}\"");
                         header("Expires: 0");
                         header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
                         header("Pragma: public");
                         echo implode("\t", $headers) . " \n";
                     }
                 }
             }
         }
         // Construct the SQL
         $select = 'SELECT ' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS uniqueid, ';
         if ($qmsubselect) {
             $select .= "(CASE " . "   WHEN {$qmsubselect} THEN 1" . "   ELSE 0 " . "END) AS gradedattempt, ";
         }
         $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' . 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, ' . 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
         // This part is the same for all cases - join users and quiz_attempts tables
         $from = 'FROM ' . $CFG->prefix . 'user u ';
         $from .= 'LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = ' . $quiz->id;
         if ($qmsubselect && $qmfilter) {
             $from .= ' AND ' . $qmsubselect;
         }
         switch ($attemptsmode) {
             case QUIZ_REPORT_ATTEMPTS_ALL:
                 // Show all attempts, including students who are no longer in the course
                 $where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0';
                 break;
             case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH:
                 // Show only students with attempts
                 $where = ' WHERE u.id IN (' . $allowedlist . ') AND qa.preview = 0 AND qa.id IS NOT NULL';
                 break;
             case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
                 // Show only students without attempts
                 $where = ' WHERE u.id IN (' . $allowedlist . ') AND qa.id IS NULL';
                 break;
             case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS:
                 // Show all students with or without attempts
                 $where = ' WHERE u.id IN (' . $allowedlist . ') AND (qa.preview = 0 OR qa.preview IS NULL)';
                 break;
         }
         $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)') . ')) ' . $from . $where;
         // Add table joins so we can sort by question grade
         // unfortunately can't join all tables necessary to fetch all grades
         // to get the state for one question per attempt row we must join two tables
         // and there is a limit to how many joins you can have in one query. In MySQL it
         // is 61. This means that when having more than 29 questions the query will fail.
         // So we join just the tables needed to sort the attempts.
         if (!$download && ($sort = $table->get_sql_sort())) {
             if (!$download && $detailedmarks) {
                 $from .= ' ';
                 $sortparts = explode(',', $sort);
                 $matches = array();
                 foreach ($sortparts as $sortpart) {
                     $sortpart = trim($sortpart);
                     if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)) {
                         $qid = intval($matches[1]);
                         $select .= ", qs{$qid}.grade AS qsgrade{$qid}, qs{$qid}.event AS qsevent{$qid}, qs{$qid}.id AS qsid{$qid}";
                         $from .= "LEFT JOIN {$CFG->prefix}question_sessions qns{$qid} ON qns{$qid}.attemptid = qa.uniqueid AND qns{$qid}.questionid = {$qid} ";
                         $from .= "LEFT JOIN  {$CFG->prefix}question_states qs{$qid} ON qs{$qid}.id = qns{$qid}.newgraded ";
                     } else {
                         $newsort[] = $sortpart;
                     }
                 }
                 $select .= ' ';
             }
         }
         if ($download) {
             $sort = '';
         }
         // Fix some wired sorting
         if (empty($sort)) {
             $sort = ' ORDER BY uniqueid';
         } else {
             $sort = ' ORDER BY ' . $sort;
         }
         if (!$download) {
             // Add extra limits due to initials bar
             if ($table->get_sql_where()) {
                 $where .= ' AND ' . $table->get_sql_where();
             }
             if (!empty($countsql)) {
                 $totalinitials = count_records_sql($countsql);
                 if ($table->get_sql_where()) {
                     $countsql .= ' AND ' . $table->get_sql_where();
                 }
                 $total = count_records_sql($countsql);
             }
             $table->pagesize($pagesize, $total);
         }
         // Fetch the attempts
         if (!$download) {
             $attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size());
         } else {
             $attempts = get_records_sql($select . $from . $where . $sort);
         }
         // Build table rows
         if (!$download) {
             $table->initialbars($totalinitials > 20);
         }
         if ($attempts) {
             if ($detailedmarks) {
                 //get all the attempt ids we want to display on this page
                 //or to export for download.
                 $attemptids = array();
                 foreach ($attempts as $attempt) {
                     if ($attempt->attemptuniqueid > 0) {
                         $attemptids[] = $attempt->attemptuniqueid;
                     }
                 }
                 $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
             }
             foreach ($attempts as $attempt) {
                 // Username columns.
                 $row = array();
                 if (in_array('checkbox', $columns)) {
                     if ($attempt->attempt) {
                         $row[] = '<input type="checkbox" name="attemptid[]" value="' . $attempt->attempt . '" />';
                     } else {
                         $row[] = '';
                     }
                 }
                 if (in_array('picture', $columns)) {
                     $attempt->id = $attempt->userid;
                     $picture = print_user_picture($attempt, $course->id, NULL, false, true);
                     $row[] = $picture;
                 }
                 if (!$download) {
                     $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $attempt->userid . '&amp;course=' . $course->id . '">' . fullname($attempt) . '</a>';
                     $row[] = $userlink;
                 } else {
                     $row[] = fullname($attempt);
                 }
                 if (in_array('idnumber', $columns)) {
                     $row[] = $attempt->idnumber;
                 }
                 // Timing columns.
                 if ($attempt->attempt) {
                     $startdate = userdate($attempt->timestart, $strtimeformat);
                     if (!$download) {
                         $row[] = '<a href="review.php?q=' . $quiz->id . '&amp;attempt=' . $attempt->attempt . '">' . $startdate . '</a>';
                     } else {
                         $row[] = $startdate;
                     }
                     if ($attempt->timefinish) {
                         $timefinish = userdate($attempt->timefinish, $strtimeformat);
                         $duration = format_time($attempt->duration);
                         if (!$download) {
                             $row[] = '<a href="review.php?q=' . $quiz->id . '&amp;attempt=' . $attempt->attempt . '">' . $timefinish . '</a>';
                         } else {
                             $row[] = $timefinish;
                         }
                         $row[] = $duration;
                     } else {
                         $row[] = '-';
                         $row[] = get_string('unfinished', 'quiz');
                     }
                 } else {
                     $row[] = '-';
                     $row[] = '-';
                     $row[] = '-';
                 }
                 // Grades columns.
                 if ($showgrades) {
                     if ($attempt->timefinish) {
                         $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
                         if (!$download) {
                             $gradehtml = '<a href="review.php?q=' . $quiz->id . '&amp;attempt=' . $attempt->attempt . '">' . $grade . '</a>';
                             if ($qmsubselect && $attempt->gradedattempt) {
                                 $gradehtml = '<div class="highlight">' . $gradehtml . '</div>';
                             }
                             $row[] = $gradehtml;
                         } else {
                             $row[] = $grade;
                         }
                     } else {
                         $row[] = '-';
                     }
                 }
                 if ($detailedmarks) {
                     if (empty($attempt->attempt)) {
                         foreach ($questions as $question) {
                             $row[] = '-';
                         }
                     } else {
                         foreach ($questions as $questionid => $question) {
                             $stateforqinattempt = $gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid];
                             if (question_state_is_graded($stateforqinattempt)) {
                                 $grade = quiz_rescale_grade($stateforqinattempt->grade, $quiz);
                             } else {
                                 $grade = '--';
                             }
                             if (!$download) {
                                 $grade = $grade . '/' . quiz_rescale_grade($question->grade, $quiz);
                                 $row[] = link_to_popup_window('/mod/quiz/reviewquestion.php?state=' . $stateforqinattempt->id . '&amp;number=' . $question->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
                             } else {
                                 $row[] = $grade;
                             }
                         }
                     }
                 }
                 // Feedback column.
                 if ($hasfeedback) {
                     if ($attempt->timefinish) {
                         $row[] = quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $quiz), $quiz->id);
                     } else {
                         $row[] = '-';
                     }
                 }
                 if (!$download) {
                     $table->add_data($row);
                 } else {
                     if ($download == 'Excel' or $download == 'ODS') {
                         $colnum = 0;
                         foreach ($row as $item) {
                             $myxls->write($rownum, $colnum, $item, $format);
                             $colnum++;
                         }
                         $rownum++;
                     } else {
                         if ($download == 'CSV') {
                             $text = implode("\t", $row);
                             echo $text . " \n";
                         }
                     }
                 }
             }
             //end of adding data from attempts data to table / download
             //now add averages :
             if (!$download && $attempts) {
                 $averagesql = "SELECT AVG(qg.grade) AS grade " . "FROM {$CFG->prefix}quiz_grades qg " . "WHERE quiz=" . $quiz->id;
                 $table->add_separator();
                 if ($groupstudentslist) {
                     $groupaveragesql = $averagesql . " AND qg.userid IN ({$groupstudentslist})";
                     $groupaverage = get_record_sql($groupaveragesql);
                     $groupaveragerow = array('fullname' => get_string('groupavg', 'grades'), 'sumgrades' => round($groupaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($groupaverage->grade, $quiz->id));
                     if ($detailedmarks && $qmsubselect) {
                         $avggradebyq = quiz_get_average_grade_for_questions($quiz, $groupstudentslist);
                         $groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
                     }
                     $table->add_data_keyed($groupaveragerow);
                 }
                 $overallaverage = get_record_sql($averagesql . " AND qg.userid IN ({$studentslist})");
                 $overallaveragerow = array('fullname' => get_string('overallaverage', 'grades'), 'sumgrades' => round($overallaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($overallaverage->grade, $quiz->id));
                 if ($detailedmarks && $qmsubselect) {
                     $avggradebyq = quiz_get_average_grade_for_questions($quiz, $studentslist);
                     $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
                 }
                 $table->add_data_keyed($overallaveragerow);
             }
             if (!$download) {
                 // Start form
                 echo '<div id="tablecontainer">';
                 echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) . '" onsubmit="return confirm(\'' . $strreallydel . '\');">';
                 echo '<div style="display: none;">';
                 echo $reporturlwithdisplayoptions->hidden_params_out();
                 echo '</div>';
                 echo '<div>';
                 // Print table
                 $table->print_html();
                 // Print "Select all" etc.
                 if (!empty($attempts) && $candelete) {
                     echo '<table id="commands">';
                     echo '<tr><td>';
                     echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'quiz') . '</a> / ';
                     echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'quiz') . '</a> ';
                     echo '&nbsp;&nbsp;';
                     echo '<input type="submit" value="' . get_string('deleteselected', 'quiz_overview') . '"/>';
                     echo '</td></tr></table>';
                 }
                 // Close form
                 echo '</div>';
                 echo '</form></div>';
                 if (!empty($attempts)) {
                     echo '<table class="boxaligncenter"><tr>';
                     echo '<td>';
                     print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'ODS'), get_string('downloadods'));
                     echo "</td>\n";
                     echo '<td>';
                     print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'Excel'), get_string('downloadexcel'));
                     echo "</td>\n";
                     echo '<td>';
                     print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'CSV'), get_string('downloadtext'));
                     echo "</td>\n";
                     echo "<td>";
                     helpbutton('overviewdownload', get_string('overviewdownload', 'quiz_overview'), 'quiz');
                     echo "</td>\n";
                     echo '</tr></table>';
                 }
             }
         } else {
             if (!$download) {
                 $table->print_html();
             }
         }
         if ($download == 'Excel' or $download == 'ODS') {
             $workbook->close();
             exit;
         } else {
             if ($download == 'CSV') {
                 exit;
             }
         }
     }
     if (!$download) {
         // Print display options
         $mform->set_data($displayoptions + compact('detailedmarks', 'pagesize'));
         $mform->display();
         //should be quicker than a COUNT to test if there is at least one record :
         if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)) {
             $imageurl = $CFG->wwwroot . '/mod/quiz/report/overview/overviewgraph.php?id=' . $quiz->id;
             print_heading(get_string('overviewreportgraph', 'quiz_overview'));
             echo '<div class="mdl-align"><img src="' . $imageurl . '" alt="' . get_string('overviewreportgraph', 'quiz_overview') . '" /></div>';
         }
     }
     return true;
 }
Esempio n. 27
0
 /**
  *  Display all the submissions ready for grading
  */
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $teacherattempts = true;
     /// Temporary measure
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     $navlinks = array();
     $navlinks[] = array('name' => $this->strassignments, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
     $navlinks[] = array('name' => format_string($this->assignment->name, true), 'link' => "view.php?a={$this->assignment->id}", 'type' => 'activityinstance');
     $navlinks[] = array('name' => $this->strsubmissions, 'link' => '', 'type' => 'title');
     $navigation = build_navigation($navlinks);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false);
     $users = array_keys($users);
     if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
         $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
         $users = array_intersect($users, array_keys($groupingusers));
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '90%');
     //$table->set_attribute('align', 'center');
     $table->no_sorting('finalgrade');
     $table->no_sorting('outcome');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
     /// Check to see if groups are being used in this assignment
     if (!$teacherattempts) {
         $teachers = get_course_teachers($course->id);
         if (!empty($teachers)) {
             $keys = array_keys($teachers);
         }
         foreach ($keys as $key) {
             unset($users[$key]);
         }
     }
     if (empty($users)) {
         print_heading(get_string('noattempts', 'assignment'));
         return true;
     }
     /// Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
                       s.id AS submissionid, s.grade, s.submissioncomment,
                       s.timemodified, s.timemarked,
                       COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
     $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid
                                                               AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             $final_grade = $grading_info->items[0]->grades[$auser->id];
             /// Calculate user status
             $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified;
             $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true);
             if (empty($auser->submissionid)) {
                 $auser->grade = -1;
                 //no submission yet
             }
             if (!empty($auser->submissionid)) {
                 ///Prints student answer and student modified date
                 ///attach file or print link to student answer, depending on the type of the assignment.
                 ///Refer to print_student_answer in inherited classes.
                 if ($auser->timemodified > 0) {
                     $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>';
                 } else {
                     $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 }
                 ///Print grade, dropdown or text
                 if ($auser->timemarked > 0) {
                     $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 } else {
                     $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 }
                 ///Print Comment
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>';
                     }
                 }
             } else {
                 $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 if ($final_grade->locked or $final_grade->overridden) {
                     $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                 } else {
                     if ($quickgrade) {
                         // allow editing
                         $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                         $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">-</div>';
                     }
                 }
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">&nbsp;</div>';
                     }
                 }
             }
             if (empty($auser->status)) {
                 /// Confirm we have exclusively 0 or 1
                 $auser->status = 0;
             } else {
                 $auser->status = 1;
             }
             $buttontext = $auser->status == 1 ? $strupdate : $strgrade;
             ///No more buttons, we use popups ;-).
             $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $auser->id . '&amp;mode=single' . '&amp;offset=' . $offset++;
             $button = link_to_popup_window($popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button' . $auser->id);
             $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>';
             $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>';
             $outcomes = '';
             if ($uses_outcomes) {
                 foreach ($grading_info->outcomes as $n => $outcome) {
                     $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>';
                     $options = make_grades_menu(-$outcome->scaleid);
                     if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                         $options[0] = get_string('nooutcome', 'grades');
                         $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>';
                     } else {
                         $outcomes .= ' ';
                         $outcomes .= choose_from_menu($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_' . $n . '_' . $auser->id);
                     }
                     $outcomes .= '</div>';
                 }
             }
             $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
             if ($uses_outcomes) {
                 $row[] = $outcomes;
             }
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     if ($quickgrade) {
         echo '<form action="submissions.php" id="fastg" method="post">';
         echo '<div>';
         echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
         echo '<input type="hidden" name="mode" value="fastgrade" />';
         echo '<input type="hidden" name="page" value="' . $page . '" />';
         echo '</div>';
         //echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>';
     }
     $table->print_html();
     /// Print the whole table
     if ($quickgrade) {
         echo '<div style="text-align:center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>';
         echo '</form>';
     }
     /// End of fast grading form
     /// Mini form for setting user preference
     echo '<br />';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">';
     echo '<div>';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<table id="optiontable" align="right">';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment');
     echo '</td></tr>';
     echo '<tr align="right">';
     echo '<td>';
     print_string('quickgrade', 'assignment');
     echo ':</td>';
     echo '<td>';
     if ($quickgrade) {
         echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
     } else {
         echo '<input type="checkbox" name="quickgrade" value="1" />';
     }
     helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment') . '</p></div>';
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</td></tr></table>';
     echo '</div>';
     echo '</form>';
     ///End of mini form
     print_footer($this->course);
 }
Esempio n. 28
0
 /**
  * Prints a table with users and their attempts
  *
  * @return void
  * @todo Add current grade to the table
  *       Finnish documenting
  **/
 function view_question($quiz, $question, $totalattempts, $ungraded)
 {
     global $CFG;
     $usercount = count($this->users);
     // set up table
     $tablecolumns = array('picture', 'fullname', 'timefinish', 'grade');
     $tableheaders = array('', get_string('name'), get_string("completedon", "quiz"), '');
     $table = new flexible_table('mod-quiz-report-grading');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($this->viewurl->out());
     $table->sortable(true);
     $table->initialbars($usercount > 20);
     // will show initialbars if there are more than 20 users
     $table->pageable(true);
     $table->collapsible(true);
     $table->column_suppress('fullname');
     $table->column_suppress('picture');
     $table->column_suppress('grade');
     $table->column_class('picture', 'picture');
     // attributes in the table tag
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'generaltable generalbox');
     $table->set_attribute('align', 'center');
     //$table->set_attribute('width', '50%');
     // get it ready!
     $table->setup();
     list($select, $from, $where) = $this->attempts_sql($quiz->id, true, $question->id);
     if ($table->get_sql_where()) {
         // forgot what this does
         $where .= 'AND ' . $table->get_sql_where();
     }
     // sorting of the table
     if ($sort = $table->get_sql_sort()) {
         $sort = 'ORDER BY ' . $sort;
         // seems like I would need to have u. or qa. infront of the ORDER BY attribues... but seems to work..
     } else {
         // my default sort rule
         $sort = 'ORDER BY u.firstname, u.lastname, qa.timefinish ASC';
     }
     // set up the pagesize
     $table->pagesize(QUIZ_REPORT_DEFAULT_PAGE_SIZE, $totalattempts);
     // get the attempts and process them
     if ($attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size())) {
         // grade all link
         $links = "<strong><a href=\"report.php?mode=grading&amp;gradeall=1&amp;q={$quiz->id}&amp;questionid={$question->id}\">" . get_string('gradeall', 'quiz_grading', $totalattempts) . '</a></strong>';
         if ($ungraded > 0) {
             $links .= "<br /><strong><a href=\"report.php?mode=grading&amp;gradeungraded=1&amp;q={$quiz->id}&amp;questionid={$question->id}\">" . get_string('gradeungraded', 'quiz_grading', $ungraded) . '</a></strong>';
             if ($ungraded > QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE) {
                 $links .= "<br /><strong><a href=\"report.php?mode=grading&amp;gradenextungraded=1&amp;q={$quiz->id}&amp;questionid={$question->id}\">" . get_string('gradenextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE) . '</a></strong>';
             }
         }
         $table->add_data_keyed(array('grade' => $links));
         $table->add_separator();
         foreach ($attempts as $attempt) {
             $picture = print_user_picture($attempt->userid, $quiz->course, $attempt->picture, false, true);
             // link to student profile
             $userlink = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$attempt->userid}&amp;course={$quiz->course}\">" . fullname($attempt, true) . '</a>';
             $gradedclass = question_state_is_graded($attempt) ? ' class="highlightgraded" ' : '';
             $gradedstring = question_state_is_graded($attempt) ? ' ' . get_string('graded', 'quiz_grading') : '';
             // link for the attempt
             $attemptlink = "<a {$gradedclass}href=\"report.php?mode=grading&amp;q={$quiz->id}&amp;questionid={$question->id}&amp;attemptid={$attempt->attemptid}\">" . userdate($attempt->timefinish, get_string('strftimedatetime')) . $gradedstring . '</a>';
             // grade all attempts for this user
             $gradelink = "<a href=\"report.php?mode=grading&amp;q={$quiz->id}&amp;questionid={$question->id}&amp;userid={$attempt->userid}\">" . get_string('grade') . '</a>';
             $table->add_data(array($picture, $userlink, $attemptlink, $gradelink));
         }
         $table->add_separator();
         $table->add_data_keyed(array('grade' => $links));
         // print everything here
         echo '<div id="tablecontainer">';
         $table->print_html();
         echo '</div>';
     } else {
         notify(get_string('noattemptstoshow', 'quiz'));
     }
 }
Esempio n. 29
0
$from = implode("\n", $joins);
if ($wheres) {
    $where = "WHERE " . implode(" AND ", $wheres);
} else {
    $where = "";
}
if ($table->get_sql_sort()) {
    $sort = ' ORDER BY ' . $table->get_sql_sort();
} else {
    $sort = '';
}
$matchcount = $DB->count_records_sql("SELECT COUNT(u.id) {$from} {$where}", $params);
$table->initialbars(true);
$table->pagesize($perpage, $matchcount);
// List of users at the current visible page - paging makes it relatively short.
$userlist = $DB->get_recordset_sql("{$select} {$from} {$where} {$sort}", $params, $table->get_page_start(), $table->get_page_size());
// If there are multiple Roles in the course, then show a drop down menu for switching.
if (count($rolenames) > 1) {
    echo '<div class="rolesform">';
    echo '<label for="rolesform_jump">' . get_string('currentrole', 'role') . '&nbsp;</label>';
    echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, 'rolesform');
    echo '</div>';
} else {
    if (count($rolenames) == 1) {
        // When all users with the same role - print its name.
        echo '<div class="rolesform">';
        echo get_string('role') . get_string('labelsep', 'langconfig');
        $rolename = reset($rolenames);
        echo $rolename;
        echo '</div>';
    }
    $checked = $showgraded ? ' checked="checked"' : '';
    echo '<input onchange="getElementById(\'showoptions\').submit(); return true;"  type="checkbox" value="1" name="showgraded" id="id_showgraded"' . $checked . '/>';
    echo '<label for="id_showgraded">' . get_string('showgraded', 'qcreate') . '</label>';
    $checked = $showneedsregrade ? ' checked="checked"' : '';
    echo '<input onchange="getElementById(\'showoptions\').submit(); return true;" type="checkbox" value="1" name="showneedsregrade" id="id_showneedsregrade"' . $checked . '/>';
    echo '<label for="id_showneedsregrade">' . get_string('showneedsregrade', 'qcreate') . '</label>';
    $checked = $showungraded ? ' checked="checked"' : '';
    echo '<input onchange="getElementById(\'showoptions\').submit(); return true;" type="checkbox" value="1" name="showungraded" id="id_showungraded"' . $checked . '/>';
    echo '<label for="id_showungraded">' . get_string('showungraded', 'qcreate') . '</label>';
    echo '<noscript>';
    echo '<input type="submit" name="go" value="' . get_string('go') . '" />';
    echo '</noscript>';
    echo '</div></form>';
}
$table->pagesize($perpage, $answercount);
if ($answercount && false !== ($answers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size()))) {
    $strupdate = get_string('update');
    $strgrade = get_string('grade');
    $grademenu = make_grades_menu($qcreate->grade);
    $grading_info = grade_get_grades($COURSE->id, 'mod', 'qcreate', $qcreate->id, $users);
    $qtypemenu = question_type_menu();
    foreach ($answers as $answer) {
        $final_grade = $grading_info->items[0]->grades[$answer->id];
        /// Calculate user status
        $answer->needsregrading = $answer->timemarked <= $answer->timemodified;
        $picture = print_user_picture($answer->id, $COURSE->id, $answer->picture, false, true);
        if (empty($answer->gradeid)) {
            $answer->grade = -1;
            //no grade yet
        }
        if ($grading_interface && !$answer->needsregrading && $answer->timemarked != 0) {