libdir.'/blocklib.php'); require_once('lib.php'); // define('DEFAULT_PAGE_SIZE', 15); define('DEFAULT_ROW_SIZE', 15); $courseid = required_param('course', PARAM_INTEGER); // Course ID $classid = optional_param('class', 0, PARAM_INTEGER); // Class ID $viewmode = optional_param('viewmode', 'all', PARAM_ALPHA); // View mode ('all', 'months', 'weeks') $current = optional_param('current', 0, PARAM_INTEGER); // shown date or time $sort = optional_param('sort', 'lastname', PARAM_ALPHA); $refresh = optional_param('refresh', '0', PARAM_INTEGER); // refresh sessions $action = optional_param('action', '', PARAM_ALPHA); if (($formdata = data_submitted()) and !confirm_sesskey()) { print_error('invalidsesskey'); } $sort = ($sort=='firstname' ? 'firstname' : 'lastname'); $urlparams['course'] = $courseid; if ($classid) $urlparams['class'] = $classid; if ($viewmode) $urlparams['viewmode'] = $viewmode; if ($current) $urlparams['current'] = $current; if ($sort) $urlparams['sort'] = $sort; if ($action) $urlparams['action'] = $action; if ($classid<0) $classid = 0; $PAGE->set_url('/blocks/autoattend/report.php', $urlparams); $wwwBlock = $CFG->wwwroot.'/blocks/autoattend'; $wwwMyURL = $wwwBlock.'/report.php'; $course = $DB->get_record('course', array('id'=>$courseid)); if (!$course) { print_error('courseidwrong', 'block_autoattend'); } require_login($course->id); $user = $DB->get_record('user', array('id'=>$USER->id)); if (!$user) { print_error('nosuchuser', 'block_autoattend'); } // add info to log //add_to_log($course->id, 'autoattend', 'view report', $wwwMyURL); // $context = get_context_instance(CONTEXT_COURSE, $course->id); $isassist = false; $isteacher = jbxl_is_teacher($USER->id, $context); if (!$isteacher) $isassist = jbxl_is_assistant($USER->id, $context); // DownLoad (Excel or Text Format) if ($isteacher or $isassist) { $classes = autoattend_get_session_classes($course->id); if($action=='excel') { autoattend_download('xls', $course->id, $classes, $classid, $viewmode, $current); die(); } else if($action=='text') { autoattend_download('txt', $course->id, $classes, $classid, $viewmode, $current); die(); } } ///////////////////////////////////////////////////// if ($refresh) { autoattend_update_sessions($courseid); } // Print header if ($course->category) { $title = $course->shortname.': '.get_string('autoattend','block_autoattend').' '.get_string('report','block_autoattend'); } else { $title = $course->shortname.': '.get_string('autoattend','block_autoattend'); } $PAGE->set_title($title); $PAGE->set_heading($course->fullname); $PAGE->set_cacheable(true); $PAGE->set_button(' '); $PAGE->set_headingmenu(navmenu($course)); echo $OUTPUT->header(); $currenttab = 'report'; include('tabs.php'); ////////////////////////////////////////////////////////////////////////////////////////////// // function report_make_header(&$table, $course_sess, $classes, $url_options) { global $CFG, $TIME_OFFSET; $wwwBlock = $CFG->wwwroot.'/blocks/autoattend'; $wwwMyURL = $wwwBlock.'/report.php'; $firstname = ''.get_string('firstname').''; $lastname = '' .get_string('lastname').''; if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk) $fullnamehead = "$lastname / $firstname"; } else { $fullnamehead = "$firstname / $lastname"; } unset($table->head); unset($table->align); unset($table->size); unset($table->wrap); // Header $table->head [] = ''; $table->align[] = ''; $table->size [] = '20px'; $table->wrap [] = 'nowrap'; $table->head [] = $fullnamehead; $table->align[] = 'left'; $table->size [] = '140px'; $table->wrap [] = 'nowrap'; if ($classes) { $table->head [] = get_string('classname','block_autoattend'); $table->align[] = 'center'; $table->size [] = '80px'; $table->wrap [] = 'nowrap'; } $table->head [] = get_string('attendgradeshort','block_autoattend'); $table->align[] = 'center'; $table->size [] = '20px'; $table->wrap [] = 'nowrap'; $table->head [] = '%'; $table->align[] = 'center'; $table->size [] = '40px'; $table->wrap [] = 'nowrap'; for ($i=0; $i<5; $i++) { $table->align[] = 'center'; $table->size [] = '20px'; $table->wrap [] = 'nowrap'; } array_push($table->head, get_string('Pacronym', 'block_autoattend'), get_string('Lacronym', 'block_autoattend'), get_string('Eacronym', 'block_autoattend'), get_string('Xacronym', 'block_autoattend'), get_string('Yacronym', 'block_autoattend')); if (!empty($course_sess)) { $i = 0; $j = 0; foreach($course_sess as $sessdata) { $i++; $j++; $table->head [] = ''. strftime(get_string('strftimedmshort','block_autoattend'), $sessdata->sessdate+$TIME_OFFSET).''; $table->align[] = 'center'; $table->size [] = '40px'; $table->wrap [] = 'nowrap'; if ($i%DEFAULT_ROW_SIZE==0) { $j++; $table->head [] = $fullnamehead; $table->align[] = 'left'; $table->size [] = '180px'; $table->wrap [] = 'nowrap'; } } } return; } // function report_show_table($course, $students, $course_sess, $classes, $url_options) { global $DB, $OUTPUT, $wwwBlock; $table = new html_table(); $i = 0; foreach($students as $student) { $i++; $pic_options = array('size'=>20, 'link'=>true, 'alttext'=>true, 'courseid'=>$course->id, 'popup'=>true); $table->data[$student->id][] = $OUTPUT->user_picture($student->user, $pic_options); $table->data[$student->id][] = ''.$student->fullname.''; $user_summary = autoattend_get_user_summary($student->id, $course->id); if ($classes) $table->data[$student->id][] = $user_summary['classname']; $table->data[$student->id][] = $user_summary['grade']; $table->data[$student->id][] = $user_summary['percent'].'%'; $table->data[$student->id][] = $user_summary['P']; $table->data[$student->id][] = $user_summary['L']; $table->data[$student->id][] = $user_summary['E']; $table->data[$student->id][] = $user_summary['X']; $table->data[$student->id][] = $user_summary['Y']; $j = 0; foreach($course_sess as $sessdata) { $j++; $att = $DB->get_record('autoattend_students', array('attsid'=>$sessdata->id, 'studentid'=>$student->id)); if ($att and ($sessdata->classid==$student->classid or $sessdata->classid==0)) { $table->data[$student->id][] = get_string($att->status.'acronym','block_autoattend'); } else { $table->data[$student->id][] = get_string('novalue','block_autoattend'); } if ($j%DEFAULT_ROW_SIZE==0) { $table->data[$student->id][] = ''.$student->fullname.''; } } // if ($i%DEFAULT_PAGE_SIZE==0) { report_make_header($table, $course_sess, $classes, $url_options); echo '
'; echo html_writer::table($table); echo '


'; unset($table->data); } } if ($i%DEFAULT_PAGE_SIZE!=0 or $i==0) { report_make_header($table, $course_sess, $classes, $url_options); echo '
'; echo html_writer::table($table); echo '


'; } return; } ////////////////////////////////////////////////////////////////////////////////////////////// // if ($isteacher or $isassist) { // if ($classid==0) $where_classid = ''; // ALL Class else if ($classid==NON_CLASSID) $where_classid = " AND classid=0"; else $where_classid = " AND (classid=$classid OR classid=0)"; $students = autoattend_get_attend_students($course->id, $classid, $context, $sort); $rec = $DB->get_record_sql("SELECT MIN(sessdate) AS min, MAX(sessdate) AS max ". " FROM {$CFG->prefix}autoattend_sessions WHERE courseid={$course->id}".$where_classid); $firstdate = $rec->min + $TIME_OFFSET; $lastdate = $rec->max + $TIME_OFFSET; if ($current==0) $current = time(); list(,,,$sday, $wday, $smonth, $syear) = array_values(getdate($firstdate)); if ($wday == 0) $wday = 7; $startdate = mktime(0, 0, 0, $smonth, $sday-$wday+1, $syear); // $options['all'] = get_string('alltaken', 'block_autoattend'); $options['weeks'] = get_string('everyweeks', 'block_autoattend'); $options['months'] = get_string('everymonths','block_autoattend'); $viewurl = $wwwMyURL.'?course='.$course->id.'&class='.$classid.'&sort='.$sort; $classurl = $wwwMyURL.'?course='.$course->id.'&viewmode='.$viewmode.'&sort='.$sort; $classes = autoattend_get_session_classes($course->id); // $date_title = ''; $weeks = array(); if ($viewmode==='weeks') { $startdate = mktime(0, 0, 0, $smonth, $sday-$wday+1, $syear); $format = get_string('strftimedmshort','block_autoattend'); // for ($i=1, $monday=$startdate; $monday<=$lastdate; $i++, $monday+=ONE_WEEK) { if ($DB->count_records_select('autoattend_sessions', "courseid={$course->id}".$where_classid. " AND sessdate >= ".($monday - $TIME_OFFSET)." AND sessdate < ".($monday + ONE_WEEK - $TIME_OFFSET))) { $weeks[] = $monday; } } } // elseif ($viewmode==='months') { $startdate = mktime(0, 0, 0, $smonth, 1, $syear); $format = '%B'; $monday = $startdate; // for ($i=1; $monday<=$lastdate; $i++, $monday=mktime(0, 0, 0, $smonth-1+$i, 1, $syear)) { if ($DB->count_records_select('autoattend_sessions', "courseid={$course->id}".$where_classid. " AND sessdate>=".($monday - $TIME_OFFSET)." AND sessdate<".(mktime(0, 0, 0, $smonth+$i, 1, $syear)-$TIME_OFFSET))) { $weeks[] = $monday; } } } $found = false; for ($i=count($weeks)-1; $i>=0; $i--) { if ($weeks[$i] <= $current+$TIME_OFFSET && !$found) { $found = true; $current = $weeks[$i] - $TIME_OFFSET; $date_title = ''.strftime($format, $weeks[$i]).' | '.$date_title; } else { $date_title = ''.strftime($format, $weeks[$i]).' | '."\n".$date_title; } } // $where = "courseid={$course->id}".$where_classid; if ($viewmode==='weeks') { $where .= " AND sessdate >= $current AND sessdate < ".($current + ONE_WEEK); } elseif ($viewmode==='months') { $nxtmon = mktime(0, 0, 0, date('m', $current+$TIME_OFFSET)+1, 1, date('Y', $current+$TIME_OFFSET)) - $TIME_OFFSET; $where .= " AND sessdate >= $current AND sessdate < ".$nxtmon; } $course_sess = ''; if ($students) { $course_sess = $DB->get_records_select('autoattend_sessions', $where, null, 'sessdate, starttime ASC'); } /////// Table $url_options_class = '?course='.$courseid.'&viewmode='.$viewmode.'&current='.$current.'&sort='.$sort; $url_options_table = '?course='.$courseid.'&viewmode='.$viewmode.'&current='.$current.'&class='.$classid; include('report.html'); } echo $OUTPUT->footer($course);