/**
  * Print table with import errors.
  */
 public function error_report($offlinequiz, $courseid)
 {
     global $CFG, $USER, $DB, $OUTPUT;
     $nologs = optional_param('nologs', 0, PARAM_INT);
     $pagesize = optional_param('pagesize', 10, PARAM_INT);
     $sql = "SELECT *\n                  FROM {offlinequiz_scanned_p_pages}\n                 WHERE status = 'error'\n                   AND offlinequizid = :offlinequizid";
     $countsql = "SELECT COUNT(*)\n                       FROM {offlinequiz_scanned_p_pages}\n                      WHERE status = 'error'\n                        AND offlinequizid = :offlinequizid";
     $params = array('offlinequizid' => $offlinequiz->id);
     $cparams = array('offlinequizid' => $offlinequiz->id);
     $tableparams = array('q' => $offlinequiz->id, 'mode' => 'upload', 'pagesize' => $pagesize, 'action' => 'delete', 'strreallydel' => addslashes(get_string('deletepagecheck', 'offlinequiz')));
     $table = new offlinequiz_selectall_table('mod-offlinequiz-participants-error', 'participants.php', $tableparams);
     // Add extra limits due to initials bar.
     list($ttest, $tparams) = $table->get_sql_where();
     if (!empty($ttest)) {
         $sql .= ' AND ' . $ttest;
         $params = array_merge($params, $tparams);
     }
     if (!empty($countsql)) {
         $totalinitials = $DB->count_records_sql($countsql, $params);
         if (!empty($ttest)) {
             $countsql .= ' AND ' . $ttest;
             $cparams = array_merge($cparams, $tparams);
         }
         $total = $DB->count_records_sql($countsql, $cparams);
     }
     // Define table columns.
     $tablecolumns = array('checkbox', 'time', 'error', 'scan');
     $tableheaders = array('', get_string('importedon', 'offlinequiz_rimport'), get_string('error'), '');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $baseurl = new moodle_url('/mod/offlinequiz/participants.php', array('q' => $offlinequiz->id, 'mode' => 'upload'));
     $table->define_baseurl($baseurl);
     $table->sortable(true);
     $table->no_sorting('checkbox');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'logs');
     $table->set_attribute('class', 'generaltable generalbox');
     // Start working -- this is necessary as soon as the niceties are over.
     $table->setup();
     if ($sort = $table->get_sql_sort()) {
         $sql .= ' ORDER BY ' . $sort;
     }
     $table->initialbars($totalinitials > 20);
     $strtimeformat = get_string('strftimedatetime');
     if (!($pages = $DB->get_records_sql($sql, $params))) {
         return;
     }
     // Options for the popup_action.
     $options = array();
     $options['height'] = 1200;
     // Optional.
     $options['width'] = 1170;
     // Optional.
     $options['resizable'] = false;
     $counter = 1;
     foreach ($pages as $page) {
         $url = new moodle_url($CFG->wwwroot . '/mod/offlinequiz/participants_correct.php?pageid=' . $page->id);
         $title = get_string('correcterror', 'offlinequiz_rimport');
         $actionlink = $OUTPUT->action_link($url, $title, new popup_action('click', $url, 'correct' . $page->id, $options));
         $errorstr = '';
         if (!empty($page->error)) {
             $errorstr = get_string('error' . $page->error, 'offlinequiz_rimport');
         }
         $row = array('<input type="checkbox" name="pageid[]" value="' . $page->id . '" />', userdate($page->time, $strtimeformat), $errorstr, $actionlink);
         $table->add_data($row);
         $counter++;
     }
     echo $OUTPUT->heading(get_string('errorreport', 'offlinequiz'), 3, '');
     // Print table.
     $table->print_html();
 }
 private function print_error_report($offlinequiz)
 {
     global $CFG, $DB, $OUTPUT;
     offlinequiz_load_useridentification();
     $offlinequizconfig = get_config('offlinequiz');
     $nologs = optional_param('nologs', 0, PARAM_INT);
     $pagesize = optional_param('pagesize', 10, PARAM_INT);
     $letterstr = 'ABCDEFGHIJKL';
     require_once 'errorpages_table.php';
     $tableparams = array('q' => $offlinequiz->id, 'mode' => 'rimport', 'action' => 'delete', 'strreallydel' => addslashes(get_string('deletepagecheck', 'offlinequiz')));
     $table = new offlinequiz_selectall_table('mod_offlinequiz_import_report', 'report.php', $tableparams);
     $tablecolumns = array('checkbox', 'counter', 'userkey', 'groupnumber', 'pagenumber', 'time', 'error', 'info', 'link');
     $tableheaders = array('', '#', get_string($offlinequizconfig->ID_field, 'offlinequiz_rimport'), get_string('group'), get_string('page'), get_string('importedon', 'offlinequiz_rimport'), get_string('error'), get_string('info'), '');
     $table->initialbars(true);
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/offlinequiz/report.php?mode=rimport&amp;q=' . $offlinequiz->id . '&amp;nologs=' . $nologs . '&amp;pagesize=' . $pagesize);
     $table->sortable(true, 'time');
     // Sorted by lastname by default.
     $table->initialbars(true);
     $table->column_class('checkbox', 'checkbox');
     $table->column_class('counter', 'counter');
     $table->column_class('username', 'username');
     $table->column_class('group', 'group');
     $table->column_class('page', 'page');
     $table->column_class('time', 'time');
     $table->column_class('error', 'error');
     $table->column_class('link', 'link');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('cellpadding', '4');
     $table->set_attribute('id', 'errorpages');
     $table->set_attribute('class', 'errorpages');
     $table->set_attribute('align', 'center');
     $table->set_attribute('border', '1');
     $table->no_sorting('checkbox');
     $table->no_sorting('counter');
     $table->no_sorting('info');
     $table->no_sorting('link');
     // Start working -- this is necessary as soon as the niceties are over.
     $table->setup();
     // Construct the SQL.
     $sql = "SELECT *\n                  FROM {offlinequiz_scanned_pages}\n                 WHERE offlinequizid = :offlinequizid\n                   AND (status = 'error'\n                        OR status = 'suspended'\n                        OR error = 'missingpages')";
     $params = array('offlinequizid' => $offlinequiz->id);
     // Add extra limits due to sorting by question grade.
     if ($sort = $table->get_sql_sort()) {
         if (strpos($sort, 'checkbox') === false && strpos($sort, 'counter') === false && strpos($sort, 'info') === false && strpos($sort, 'link') === false) {
             $sql .= ' ORDER BY ' . $sort;
         }
     }
     $errorpages = $DB->get_records_sql($sql, $params);
     $strtimeformat = get_string('strftimedatetime');
     // Options for the popup_action.
     $options = array();
     $options['height'] = 1200;
     // Optional.
     $options['width'] = 1170;
     // Optional.
     $options['resizable'] = false;
     $counter = 1;
     foreach ($errorpages as $page) {
         if ($page->error == 'filenotfound') {
             $actionlink = '';
         } else {
             if ($page->error == 'missingpages') {
                 $url = new moodle_url($CFG->wwwroot . '/mod/offlinequiz/image.php?pageid=' . $page->id . '&resultid=' . $page->resultid);
                 $title = get_string('showpage', 'offlinequiz_rimport');
             } else {
                 $url = new moodle_url($CFG->wwwroot . '/mod/offlinequiz/correct.php?pageid=' . $page->id);
                 $title = get_string('correcterror', 'offlinequiz_rimport');
             }
             $actionlink = $OUTPUT->action_link($url, $title, new popup_action('click', $url, 'correct' . $page->id, $options));
         }
         $groupstr = '?';
         $groupnumber = $page->groupnumber;
         if ($groupnumber > 0 and $groupnumber <= $offlinequiz->numgroups) {
             $groupstr = $letterstr[$page->groupnumber - 1];
         }
         $errorstr = '';
         if (!empty($page->error)) {
             $errorstr = get_string('error' . $page->error, 'offlinequiz_rimport');
         }
         if ($page->status == 'suspended') {
             $errorstr = get_string('waitingforanalysis', 'offlinequiz_rimport');
         }
         $row = array('<input type="checkbox" name="p' . $page->id . '" value="' . $page->id . '" />', $counter . '&nbsp;', $page->userkey, $groupstr, empty($page->pagenumber) ? '?' : $page->pagenumber, userdate($page->time, $strtimeformat), $errorstr, $page->info, $actionlink);
         $table->add_data($row);
         $counter++;
     }
     if (!$table->print_nothing_to_display()) {
         // Print the table.
         $table->print_html();
     }
 }