get_record('course_modules', array('id'=> $id))) { error('Course Module ID was incorrect'); } if (! $course = $DB->get_record('course', array('id'=> $cm->course))) { error("Course is misconfigured"); } if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) { error("Course module is incorrect"); } require_login($course->id); if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) { error("No such user in this course"); } if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { print_error('badcontext'); } if ($view) set_current_view($course->id, $_GET['view']); else $view = get_current_view($course->id); if (!has_capability('mod/attforblock:manageattendances', $context) AND !has_capability('mod/attforblock:takeattendances', $context) AND !has_capability('mod/attforblock:changeattendances', $context)) { redirect("view.php?id=$cm->id"); } set_user_preference("attforblock_showendtime",$showendtime); //if teacher is coming from block, then check for a session exists for today if($from === 'block') { $today = time(); // because we compare with database, we don't need to use usertime() $sql = "SELECT id, groupid, lasttaken FROM {attendance_sessions} WHERE ? BETWEEN sessdate AND (sessdate + duration) AND courseid = ? AND attendanceid = ?"; if($atts = $DB->get_records_sql($sql, array($today, $course->id, $attforblock->id))) { $size = count($atts); if ($size == 1) { $att = reset($atts); if ((!$att->lasttaken and has_capability('mod/attforblock:takeattendances', $context)) or ($att->lasttaken and has_capability('mod/attforblock:changeattendances', $context))) { redirect('attendances.php?id='.$id.'&sessionid='.$att->id.'&grouptype='.$att->groupid); } } elseif ($size > 1) { $current = $today; //temporally set $view for single access to page from block $view = 'days'; } } } /// Print headers $url = new moodle_url('/mod/attforblock/manage.php', array('id'=> $id, 'from'=> $from, 'view' => $view, 'current' => $current, 'showendtime' => $showendtime)); $PAGE->set_url($url); $PAGE->set_title($course->shortname. ": ".$attforblock->name); $PAGE->set_heading($course->fullname); $PAGE->set_focuscontrol(''); $PAGE->set_cacheable(true); $PAGE->set_button($OUTPUT->update_module_button($cm->id,'attforblock')); $PAGE->navbar->add($attforblock->name); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname); if(!$DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate >= ?", array($course->id, $attforblock->id, $course->startdate))) { // no session exists for this course show_tabs($cm, $context); print_heading(get_string('nosessionexists','attforblock')); $hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate < ?", array($course->id, $attforblock->id, $course->startdate)); echo '
'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: fix '--' echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'
'; } else { //sessions generated , display them add_to_log($course->id, 'attendance', 'manage attendances', 'mod/attforblock/manage.php?course='.$course->id, $user->lastname.' '.$user->firstname); show_tabs($cm, $context); print_sessions_list($course, $attforblock); } // require_once('lib.php'); // $t = attforblock_get_user_grades($attforblock); //////////////////////////////////////////// $OUTPUT->footer();//print_footer($course); function print_sessions_list($course, $attforblock) { global $CFG, $context, $cm, $current, $view, $id, $showendtime, $DB, $OUTPUT; $strhours = get_string('hours'); $strmins = get_string('min'); if ($current == 0) $current = get_current_date($course->id); else set_current_date ($course->id, $current); $ret = print_filter_controls("manage.php", $id, 0, NULL, SESSION_TYPE_SELECTOR); $startdate = $ret['startdate']; $enddate = $ret['enddate']; $currentgroup = $ret['currentgroup']; if ($startdate && $enddate) { $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate AND sessdate >= :sdate2 AND sessdate < :edate"; } else { $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :sdate"; } if ($currentgroup > -1) { $where .= " AND groupid=:cgroup"; } $qry = $DB->get_records_select('attendance_sessions', $where, array('cid' => $course->id, 'aid' => $attforblock->id, 'sdate' => $course->startdate,'sdate2' => $startdate, 'edate'=> $enddate, 'cgroup'=> $currentgroup), 'sessdate asc'); $i = 0; $table = new html_table(); $table->width = '100%'; //$table->tablealign = 'center'; $table->head = array('#', get_string('sessiontypeshort', 'attforblock'), get_string('date'), get_string('from'), ($showendtime=='0') ? get_string('duration', 'attforblock') : get_string('to'), get_string('description','attforblock'), get_string('actions'), get_string('select')); $table->align = array('', '', '', 'right', 'left', 'center', 'center'); $table->size = array('1px', '', '1px', '1px', '1px', '*', '1px', '1px'); $allowtake = has_capability('mod/attforblock:takeattendances', $context); $allowchange = has_capability('mod/attforblock:changeattendances', $context); $allowmanage = has_capability('mod/attforblock:manageattendances', $context); $groups = groups_get_all_groups($course->id); if ($qry) { foreach($qry as $key=>$sessdata) { $i++; $actions = ''; // if ($allowtake) { if($sessdata->lasttaken > 0) //attendance has taken { if ($allowchange) { $desc = "id&sessionid={$sessdata->id}&grouptype={$sessdata->groupid}\">". ($sessdata->description ? $sessdata->description : get_string('nodescription', 'attforblock')). ''; } else { $desc = ''.(empty($sessdata->description) ? get_string('nodescription', 'attforblock') : $sessdata->description).''; } } else { $desc = empty($sessdata->description) ? get_string('nodescription', 'attforblock') : $sessdata->description; if ($allowtake) { $title = get_string('takeattendance','attforblock'); $actions = "id&sessionid={$sessdata->id}&grouptype={$sessdata->groupid}\">". "pix_url('t/go') . "\" alt=\"$title\" /> "; } } // } if($allowmanage) { $title = get_string('editsession','attforblock'); $actions .= "id&sessionid={$sessdata->id}&action=update\">". "pix_url('t/edit') . "\" alt=\"$title\" /> "; $title = get_string('deletesession','attforblock'); $actions .= "id&sessionid={$sessdata->id}&action=delete\">". "pix_url('t/delete') . "\" alt=\"$title\" /> "; } $table->data[$sessdata->id][] = $i; $table->data[$sessdata->id][] = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock'); $table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimedmyw', 'attforblock')); $table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimehm', 'attforblock')); $hours = floor($sessdata->duration / HOURSECS); $mins = floor(($sessdata->duration - $hours * HOURSECS) / MINSECS); $mins = $mins < 10 ? "0$mins" : "$mins"; $table->data[$sessdata->id][] = ($showendtime=='0') ? ($hours ? "{$hours} {$strhours} {$mins} {$strmins}" : "{$mins} {$strmins}") : userdate($sessdata->sessdate+$sessdata->duration, get_string('strftimehm', 'attforblock'));; $table->data[$sessdata->id][] = $desc; $table->data[$sessdata->id][] = $actions; $table->data[$sessdata->id][] = ''; unset($desc, $actions); } } echo '
'; echo "
id}\">"; //&sessionid={$sessdata->id} print_table($table);//echo $OUTPUT->table($table); $hiddensess = $DB->count_records_select('attendance_sessions', "courseid = ? AND attendanceid = ? AND sessdate < ?", array($course->id, $attforblock->id, $course->startdate)); echo ''; echo '
'; echo '
'.helpbutton('hiddensessions', '--', 'attforblock', true, true, '', true); //TODO: Change '--' echo get_string('hiddensessions', 'attforblock').': '.$hiddensess.'
'.get_string('selectall').' /'. ' '.get_string('deselectall').'

'; echo ''.get_string('withselected', 'quiz').': '; if ($allowmanage) { $actionlist = array('deleteselected' => get_string('delete'), 'changeduration' => get_string('changeduration', 'attforblock')); choose_from_menu($actionlist, 'action'); echo '\n"; } else { echo get_string('youcantdo', 'attforblock'); //You can't do anything } echo '
'.helpbutton ('sessions', get_string('help'), 'attforblock', true, true, '', true).'
'; echo '
'; echo '
'; } ?>