$context = get_context_instance(CONTEXT_COURSECAT, $id);
//end
if ($period == "all") {
    $printperiod = "";
}
echo '<div style="text-align: center; font-weight: bold;">' . strtoupper($printperiod) . ' USAGE REPORT  ' . '</div>';
echo '<div style="text-align: center; font-weight: bold;">  ' . $name . '</div>';
echo '<div style="text-align: left; padding-left: 20px; margin: 5px 0;">
<form method="post" style="display: inline; margin: 0; padding: 0;">';
//addedlater
if (isset($_POST['view']) && ($admin == 1 || has_capability('block/custom_reports:getusagereport', $context))) {
    echo '<input type="hidden" name="export" value="true" /><input type="submit" value="Download Excel" />';
}
echo '</form>';
//end
Print_form();
if (isset($_POST['view']) or $export) {
    if ($admin == 1 || has_capability('block/custom_reports:getusagereport', $context)) {
        //added
        $type = $_POST['stats'];
        $period = $_POST['period'];
        $selected_school = $_POST['school'];
        if (isset($_POST['view'])) {
            $_SESSION['type'] = $type;
            $_SESSION['period'] = $period;
            $_SESSION['school'] = $selected_school;
        }
        if ($export) {
            $type = $_SESSION['type'];
            $period = $_SESSION['period'];
            $selected_school = $_SESSION['school'];
$report = get_string('std_sem_report', 'block_custom_reports');
$navlinks[] = array('name' => get_string('std_sem_report', 'block_custom_reports'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
if (!$export) {
    print_header('Students Semester Report', 'Students Semester Report', $navigation, '', '', true, '', user_login_string($SITE) . $langmenu);
}
if ($courses && $categoryid == 2 or $export) {
    foreach ($courses as $course) {
        if ($courses_ == "") {
            $courses_ = $course->id;
        } else {
            $courses_ .= "," . $course->id;
        }
    }
    ////
    Print_form($courses_);
    if (isset($_POST['view']) or $export) {
        $user = $_POST['user'];
        if (isset($_POST['report']) or $export) {
            $_SESSION['user'] = $user;
        }
        if ($export) {
            $user = $_SESSION['user'];
        }
        $uid_name = explode("|", $user);
        $uid = $uid_name[0];
        // school id
        $uname = $uid_name[1];
        $uidnumber = $uid_name[2];
        $table = new html_table();
        $table->align[] = 'center';