libdir.'/weblib.php'); require_once($CFG->dirroot.'/grade/querylib.php'); require_once($CFG->dirroot.'/cohort/lib.php'); require_once($CFG->dirroot.'/cohort/locallib.php'); require_once("lib.php"); use local_treestudyplan; //admin_externalpage_setup('major'); $systemcontext = context_system::instance(); require_login(); require_capability('local/treestudyplan:viewothercards',$systemcontext); $PAGE->set_pagelayout('base'); $PAGE->set_context($systemcontext); $PAGE->set_title(get_string('report_index','local_treestudyplan')); $PAGE->set_heading(get_string('report_index','local_treestudyplan')); // Load javascripts //$PAGE->requires->js_call_amd('local_treestudyplan/fixlinks', 'init', ['div.tab-content']); $PAGE->requires->js_call_amd('block_gradelevel/renderbadge', 'init'); $PAGE->requires->js_call_amd('local_treestudyplan/report', 'init'); //$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/eqstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-toggle.min.css')); $userid = null; $studentid = optional_param('studentid', '', PARAM_INT); $cohortid = optional_param('cohortid', '', PARAM_INT); if(!empty($studentid)){ $PAGE->set_url("/local/treestudyplan/reports.php",array('studentid' => $studentid)); $student = $DB->get_record("user",['id' => $studentid]); $userlist = []; $nextstudent = null; $prevstudent = null; if(!empty($cohortid)) { $cohort = $DB->get_record("cohort",['id' => $cohortid]); $userlist = array_values(local_treestudyplan_find_cohortmembers($cohortid)); for($i = 0; $i < count($userlist); $i++) { if($userlist[$i]->userid == $studentid) { if($i > 0) { $prevstudent = (object)['id' => $userlist[$i - 1]->userid, 'name' => "{$userlist[$i - 1]->firstname} {$userlist[$i - 1]->lastname}"]; } if($i < count($userlist) - 1) { $nextstudent = (object)['id' => $userlist[$i + 1]->userid, 'name' => "{$userlist[$i + 1]->firstname} {$userlist[$i + 1]->lastname}"]; } break; } } $cohortpath = local_treestudyplan_get_cohort_path($cohort); $PAGE->set_title(get_string('report_invited','local_treestudyplan',"{$cohortpath}: {$student->firstname} {$student->lastname}")); $PAGE->set_heading(get_string('report_invited','local_treestudyplan',"{$cohortpath}: {$student->firstname} {$student->lastname}")); } else { $PAGE->set_title(get_string('report_invited','local_treestudyplan',"$cohort->{$student->firstname} {$student->lastname}")); $PAGE->set_heading(get_string('report_invited','local_treestudyplan',"{$student->firstname} {$student->lastname}")); } $gradewriter = new local_treestudyplan_cardwriter($studentid,true); $badgewriter = new local_treestudyplan_badgewriter($studentid); $calendarwriter = new local_treestudyplan_calendarwriter($studentid); print $OUTPUT->header(); print "
"; if(isset($prevstudent)) { print " {$prevstudent->name} "; } if(isset($nextstudent)) { print "{$nextstudent->name} "; } print "
"; print ""; print "
"; print ""; print ""; print ""; print "
"; print $OUTPUT->footer(); } else { $PAGE->set_url("/local/treestudyplan/reports.php",array()); // show student picker $cohortlist = $DB->get_records("cohort"); $cohorts = []; foreach($cohortlist as $c) { if($c->visible) { $cohortcontext = context::instance_by_id($c->contextid); if($cohortcontext) // TODO: add check if user has rights in this context { $users = local_treestudyplan_find_cohortmembers($c->id); $cohorts[$c->id] = (object)[ 'id' => $c->id, 'cohort' => $c, 'name' => $c->name, 'path' => local_treestudyplan_get_cohort_path($c), 'users' => $users, ]; } } } print $OUTPUT->header(); usort($cohorts,function($a,$b){ return $a->path <=> $b->path; }); $regex = get_config('local_treestudyplan', 'cohortidregex'); foreach($cohorts as $c) { $m = []; if(preg_match("/".$regex."/",$c->cohort->idnumber,$m) && $c->cohort->visible) { print ""; print "
"; print "
"; print "
"; } } print ""; print $OUTPUT->footer(); }