/**
  * @param string $uniqueid a string identifying this table.Used as a key in
  *                          session  vars.
  */
 function ilp_table_sql($uniqueid)
 {
     parent::ilp_flexible_table($uniqueid);
     // some sensible defaults
     $this->set_attribute('cellspacing', '0');
     $this->set_attribute('class', 'generaltable generalbox');
 }
<?php

if (!defined('MOODLE_INTERNAL')) {
    // this must be included from a Moodle page
    die('Direct access to this script is forbidden.');
}
//include the ilp ajax table class
require_once $CFG->dirroot . '/blocks/ilp/classes/tables/ilp_tablelib.class.php';
//create the field table
//instantiate the flextable table class
$flextable = new ilp_flexible_table("report_id{$report_id}user_id" . $USER->id);
//define the base url that the table will return to
$flextable->define_baseurl($CFG->wwwroot . "/blocks/ilp/actions/edit_prompt.php?report_id={$report_id}");
//setup the array holding the column ids
$columns = array();
$columns[] = 'label';
$columns[] = 'type';
$columns[] = 'moveup';
$columns[] = 'movedown';
$columns[] = 'edit';
$columns[] = 'required';
$columns[] = 'delete';
//setup the array holding the header texts
$headers = array();
$headers[] = '';
$headers[] = get_string('type', 'block_ilp');
$headers[] = '';
$headers[] = '';
$headers[] = '';
$headers[] = '';
$headers[] = '';
 /**
  * @return string sql to add to where statement.
  */
 function get_sql_where()
 {
     $return = array();
     $where = parent::get_sql_where();
     if (!empty($where)) {
         $return[] = $where;
     }
     $filters = $this->get_sql_filters();
     if (!empty($filters)) {
         $return[] = $filters;
     }
     return implode(' AND ', $return);
 }
<?php

if (!defined('MOODLE_INTERNAL')) {
    // this must be included from a Moodle page
    die('Direct access to this script is forbidden.');
}
//include the ilp ajax table class
require_once $CFG->dirroot . '/blocks/ilp/classes/tables/ilp_tablelib.class.php';
//create the field table
//instantiate the flextable table class
$flextable = new ilp_flexible_table("configurationreport_id{$report_id}user_id" . $USER->id);
//define the base url that the table will return to
$flextable->define_baseurl($CFG->wwwroot . "/blocks/ilp/actions/edit_report_configuration.php?report_id={$report_id}");
//setup the array holding the column ids
$columns = array();
$columns[] = 'reportname';
$columns[] = 'moveup';
$columns[] = 'movedown';
$columns[] = 'editreport';
$columns[] = 'editprompts';
$columns[] = 'editpermission';
$columns[] = 'changestatus';
$columns[] = 'delete';
//setup the array holding the header texts
$headers = array();
$headers[] = '';
$headers[] = '';
$headers[] = '';
$headers[] = '';
$headers[] = '';
$headers[] = '';
 /**
  *
  * This function creates the register grid that is displayed
  * @param recordset $data recordset containing student register data
  * @param int          $term the term that will be displayed if not supplied all terms are shown
  * @param unknown_type $course
  */
 function term_attendance($data, $term = 0, $course = false)
 {
     global $CFG, $USER;
     $cidfield = get_config('block_ilp', 'mis_plugin_register_courseid');
     $cdatefield = get_config('block_ilp', 'mis_plugin_register_datetime');
     $markfield = get_config('block_ilp', 'mis_plugin_register_mark');
     $timefield = get_config('block_ilp', 'mis_plugin_register_starttime');
     $timefield = !empty($timefield) ? $timefield : 0;
     $cnamefield = get_config('block_ilp', 'mis_plugin_register_coursename');
     $startdate = $this->terms[0]['startts'];
     if (!empty($term)) {
         $yearstart = $this->terms[0]['start'];
         $termstart = $this->terms[$term - 1]['start'];
         $termend = $this->terms[$term - 1]['end'];
     } else {
         $yearstart = $this->terms[0]['start'];
         $termstart = $this->terms[0]['start'];
         $termend = $this->terms[$this->numterms - 1]['end'];
     }
     //these variables define the academic weeks of $termstart and $termend
     $academicstart = $this->academic_week($termstart, $yearstart);
     $academicend = $this->academic_week($termend, $yearstart);
     $weekofseconds = 604800;
     //assign the tables column names
     $tablecolumns = array('class', 'late', 'att', 'date', 'time');
     //set the displayed headers
     $tableheaders = array(get_string('ilp_mis_attendance_plugin_register_disp_class', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_late', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_att', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_day', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_time', 'block_ilp'));
     //assign the week column names and set the week display header
     for ($z = $academicstart; $z < $academicend + 1; $z++) {
         $tablecolumns[] = 'week' . $z;
         $tableheaders[] = $z;
     }
     require_once $CFG->dirroot . '/blocks/ilp/classes/tables/ilp_tablelib.class.php';
     $table = new ilp_flexible_table('user-attendence', true, 'ilp_mis_attendance_plugin_register');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/blocks/ilp/attendence.php?&id=1');
     $table->sortable(false);
     $table->collapsible(false);
     $table->initialbars(false);
     $table->set_attribute('cellpadding', '6');
     $table->set_attribute('id', 'ilp-attendance-grid');
     $table->set_attribute('class', 'generalbox');
     $table->set_attribute('width', '100%');
     $table->set_attribute('align', 'left');
     $table->set_attribute('font-size', '0.85em');
     $table->setup();
     //set the row displaying the week dates
     $dates = array('', '', '', '', '<div class="termweeks">Week:</div>');
     for ($z = $academicstart; $z < $academicend + 1; $z++) {
         $weekindays = ($z - 1) * 7;
         $timestampweek = strtotime("+{$weekindays} days", $startdate);
         //$timestampweek = $weekofseconds * ($z - 1);
         //$dates[] = '<div class="termweeks">' . $this->getMonday($startdate + $timestampweek) . '</div>';
         $dates[] = '<div class="termweeks">' . $this->getMonday($timestampweek) . '</div>';
     }
     $table->add_data($dates);
     $registers = array();
     //we will now take the attendance data and construct an array separating class on day and time basis
     foreach ($data as $att) {
         $tempday = $this->courseday($att[$cdatefield]);
         $temptime = isset($att[$timefield]) ? $this->coursetime($att[$timefield]) : 'N/A';
         $registers[$att[$cidfield]][$tempday][$temptime][] = $att;
     }
     $total = array();
     foreach (array_keys($registers) as $groupKey) {
         $class = array('', '', '', '', '');
         $termsweeks = array();
         for ($z = $academicstart; $z < $academicend + 1; $z++) {
             $base_class[] = '';
             $base_termsweeks[] = $z;
         }
         $class = $base_class;
         $termsweeks = $base_termsweeks;
         $total[$groupKey] = array();
         foreach ($registers[$groupKey] as $cday => $timeslot) {
             foreach ($timeslot as $ctime => $classtime) {
                 $total[$groupKey][$cday][$ctime] = array(array(0, 0, 0, 0), array(0, 0, 0, 0), array(0, 0, 0, 0), array(0, 0, 0, 0));
                 foreach ($classtime as $item) {
                     //$item['Week_No'] = $this->weekno($item[$cdatefield]);
                     $marktimestamp = strtotime($this->normalise_date($item[$cdatefield]));
                     $item['Week_No'] = $this->academic_week(date('W', $marktimestamp), $yearstart);
                     if (in_array($item['Week_No'], $termsweeks)) {
                         if (!in_array($item[$markfield], $this->noclasscodes) && strlen($mark[$markfield]) > 0) {
                             $total[$groupKey][$cday][$ctime][0][0]++;
                         }
                         if (in_array($item[$markfield], $this->presentcodes)) {
                             $total[$groupKey][$cday][$ctime][1][0]++;
                         }
                         if (in_array($item[$markfield], $this->absentcodes)) {
                             $total[$groupKey][$cday][$ctime][2][0]++;
                         }
                         if (in_array($item[$markfield], $this->latecodes)) {
                             $total[$groupKey][$cday][$ctime][3][0]++;
                         }
                         $class['class'] = $item[$cidfield] . ': ' . $item[$cnamefield];
                         $startdate = explode('-', $item[$cdatefield]);
                         $class['date'] = $this->courseday($item[$cdatefield]);
                         $class['time'] = $ctime;
                         $att_class = 'amber';
                         if (in_array($item[$markfield], $this->presentcodes)) {
                             $att_class = get_config('block_ilp', 'mis_plugin_register_presentcolour');
                         }
                         if (in_array($item[$markfield], $this->absentcodes)) {
                             $att_class = get_config('block_ilp', 'mis_plugin_register_absentcolour');
                         }
                         if (in_array($item[$markfield], $this->latecodes)) {
                             $att_class = get_config('block_ilp', 'mis_plugin_register_latecolour');
                         }
                         $class['week' . $item['Week_No']] = '<span style="display:block; text-align:center; background-color:' . $att_class . '" title="">' . $item[$markfield] . '</span>';
                     }
                 }
                 //calculate the attendance and late averages
                 if ($total[$groupKey][$cday][$ctime][0][$term] != 0) {
                     $class['late'] = round($total[$groupKey][$cday][$ctime][3][$term] / $total[$groupKey][$cday][$ctime][0][$term] * 100, 0) . '%';
                     $class['att'] = round($total[$groupKey][$cday][$ctime][1][$term] / $total[$groupKey][$cday][$ctime][0][$term] * 100, 0) . '%';
                 }
                 $classdata[] = $class;
                 //reset $class and $termsweeks to their original states
                 $class = $base_class;
                 $termsweeks = $base_termsweeks;
             }
         }
     }
     foreach ($classdata as $class) {
         $table->add_data_keyed($class);
     }
     $table->print_html();
 }