} $levels = implode(",", $levels); // Calculates the number of criteria assigned to current user $criteriafilter = "\n\tSELECT u.*,\n\t\tCASE WHEN S.comments = 0 AND S.status < 20 THEN 5\n\t\t\tWHEN S.comments = 0 AND S.status >= 20 THEN 20\n\t\t\tWHEN S.comments > 0 THEN 30 END AS status,\n\t\tS.submission\n\tFROM (SELECT\n\ts.id as submission,\n\ts.student,\n\tCOUNT(DISTINCT ec.id) AS comments,\n\ts.sort,\n\ts.status\n\tFROM {emarking_submission} AS s\n\tINNER JOIN {emarking_draft} as d ON (d.submissionid = s.id AND d.qualitycontrol = 0)\n\tINNER JOIN {emarking_page} AS p ON (s.emarking = {$emarking->id} AND p.submission = s.id)\n\tLEFT JOIN {emarking_comment} AS ec ON (ec.page = p.id AND ec.levelid IN ({$levels}))\n\tGROUP BY s.id) AS S\n\tINNER JOIN {user} AS u ON (S.student = u.id)"; // Check if activity is configured with separate groups to filter users if ($cm->groupmode == SEPARATEGROUPS && $usercangrade && !is_siteadmin($USER) && !$useristeacher) { $userfilter .= "\nAND u.id in (SELECT userid\n\t\tFROM {groups_members}\nWHERE groupid in (SELECT groupid\nFROM {groups_members} as gm\nINNER JOIN {groups} as g on (gm.groupid = g.id)\nWHERE gm.userid = {$USER->id} AND g.courseid = e.courseid))"; } // Define flexible table (can be sorted in different ways) $showpages = new flexible_table('emarking-kanban-' . $cmid); $showpages->define_headers(array(get_string('notcorrected', 'mod_emarking'), get_string('marking', 'mod_emarking'), get_string('corrected', 'mod_emarking'))); $showpages->define_columns(array('notcorrected', 'marking', 'corrected')); $showpages->define_baseurl($urlemarking); $defaulttsort = $emarking->anonymous ? null : 'status'; $showpages->sortable(false); $showpages->pageable(false); $showpages->setup(); // Decide on sorting depending on URL parameters and flexible table configuration $orderby = $emarking->anonymous ? 'ORDER BY sort ASC' : 'ORDER BY u.lastname ASC'; // Get submissions with extra info to show $sql = $criterionid == 0 ? "\nSELECT u.*, \n\t\tIFNULL(s.id,0) as submission,\n\t\tIFNULL(s.status,0) as status,\n\t\ts.sort\nFROM {emarking_submission} AS s\n\tINNER JOIN {user} AS u ON (s.emarking = ? AND s.student = u.id)\n{$userfilter}\n{$orderby}" : $criteriafilter . $userfilter . $orderby; // Run the query on the database $emarkingpages = $DB->get_records_sql($sql, array($emarking->id)); $notcorrected = ""; $marking = ""; $corrected = ""; // Prepare data for the table foreach ($emarkingpages as $pageinfo) { // Student info $userinfo = $emarking->anonymous ? get_string('anonymousstudent', 'mod_emarking') : $pageinfo->firstname . ' ' . $pageinfo->lastname . '</a>'; // eMarking popup url
/** * 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&gradeall=1&q={$quiz->id}&questionid={$question->id}\">" . get_string('gradeall', 'quiz_grading', $totalattempts) . '</a></strong>'; if ($ungraded > 0) { $links .= "<br /><strong><a href=\"report.php?mode=grading&gradeungraded=1&q={$quiz->id}&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&gradenextungraded=1&q={$quiz->id}&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}&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&q={$quiz->id}&questionid={$question->id}&attemptid={$attempt->attemptid}\">" . userdate($attempt->timefinish, get_string('strftimedatetime')) . $gradedstring . '</a>'; // grade all attempts for this user $gradelink = "<a href=\"report.php?mode=grading&q={$quiz->id}&questionid={$question->id}&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')); } }
$showpages->define_columns($columns); $showpages->define_baseurl($urlemarking); $showpages->column_class('actions', 'actions'); $showpages->column_class('lastname', 'lastname'); if ($emarking->type == EMARKING_TYPE_MARKER_TRAINING || $emarking->type == EMARKING_TYPE_PEER_REVIEW && $issupervisor) { $showpages->column_class('marker', 'lastname'); } $defaulttsort = $emarking->anonymous < 2 ? null : 'lastname'; $showpages->sortable(true, $defaulttsort, SORT_ASC); if ($emarking->anonymous < 2) { $showpages->no_sorting('lastname'); } $showpages->no_sorting('comment'); $showpages->no_sorting('actions'); $showpages->no_sorting('select'); $showpages->pageable(true); $showpages->pagesize($perpage, $totalstudents); $showpages->setup(); // Decide on sorting depending on URL parameters and flexible table configuration. $orderby = $emarking->anonymous < 2 ? 'ORDER BY sort ASC' : 'ORDER BY u.lastname ASC'; if ($showpages->get_sql_sort()) { $orderby = 'ORDER BY ' . $showpages->get_sql_sort(); $tsort = $showpages->get_sql_sort(); } // Get submissions with extra info to show. $sqldrafts .= $orderby; // Run the query on the database. $drafts = $DB->get_recordset_sql($sqldrafts, $params, $page * $perpage, $perpage); $unpublishedsubmissions = 0; // Prepare data for the table. foreach ($drafts as $draft) {
$stausimage_second = ' title="'.$refresh_txt.'">'.$statusicon.'</a>'; $stausimage = $stausimage_first.$stausimage_second; $status = 'Status'." ".$stausimage; $nameheding = get_string('nameheading', 'wiziq'); $deleteheading = get_string('deleteheading', 'wiziq'); $table->define_headers(array($nameheding, $status, $deleteheading)); $table->column_style_all('text-align', 'left'); $table->column_style('name', 'width', 'auto'); $table->column_style('status', 'text-align', 'center'); $table->column_style('delete', 'text-align', 'center'); $table->column_style('status', 'width', '180px'); $table->column_style('delete', 'width', '180px'); $table->define_baseurl($PAGE->url); $table->is_downloadable(false); $table->sortable(false); $table->pageable(true); echo $OUTPUT->header(); #--------------------------tabs for navigation----------- $schedulenewwiziqclass = new moodle_url("$CFG->wwwroot/course/modedit.php", array('add' => 'wiziq', 'type' => '', 'course' => $course->id, 'section' => '0', 'return' => '0')); $navigationtabsmanage = new moodle_url("$CFG->wwwroot/mod/wiziq/index.php", array('id' => $course->id, 'sesskey' => sesskey())); $navigationtabscontent = new moodle_url("$CFG->wwwroot/mod/wiziq/content.php", array('id' => $course->id, 'sesskey' => sesskey())); $tabs =array(); $row = array(); $row[] = new tabobject('wiziq_sch_class', $schedulenewwiziqclass, get_string('schedule_class', 'wiziq')); $row[] = new tabobject('wizq_mange_class', $navigationtabsmanage, get_string('manage_classes', 'wiziq'));
/** * 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&q=' . $quiz->id . '&action=viewquestion&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}&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&action=grade&q={$quiz->id}&questionid={$question->id}&attemptid={$attempt->attemptid}\">" . userdate($attempt->timefinish, get_string('strftimedatetime')) . '</a>'; // grade all attempts for this user $gradelink = "<a href=\"report.php?mode=grading&action=grade&q={$quiz->id}&questionid={$question->id}&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&action=grade&q={$quiz->id}&questionid={$question->id}&gradeall=1\">" . get_string('gradeall', 'quiz') . '</a> | ' . "<a href=\"report.php?mode=grading&q={$quiz->id}&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; }
/** * 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 . '&course=' . $courseid . '&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}&course={$courseid}';\n locationtogo += '&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 . '&status=' . $status . '&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%'> </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 . "&status={$status}&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 .= " <a href='index.php?{$value}=y&sesskey={$USER->sesskey}&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(); }
/** * 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 . "&status={$status}&course={$courseid}&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(); }
/** * 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}&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}\" /> "; 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}&pagesize=", 'changepagesize', $options, $pagesize); } print $OUTPUT->box_end(true); $tablehtml = ob_get_contents(); ob_end_clean(); return $tablehtml; }