<?php

DisplayHeader(".:".ProgramTitle().":.");

if(!$_REQUEST['school_term_sn'])
	$_REQUEST['school_term_sn'] = get_user_school_term();

$sem = get_parent_school_term('SEM',get_user_school_term());
echo "<FORM action=modloader.php?servicemod=$_REQUEST[servicemod]&selected_menu=$_REQUEST[selected_menu]&link_menu=$_REQUEST[link_menu] method=POST>";
$mp_select = "<SELECT name=school_term_sn onchange='this.form.submit();'><OPTION value=".get_user_school_term().">".get_school_term(get_user_school_term())."</OPTION><OPTION value=".$sem.(($sem==$_REQUEST['school_term_sn'])?' SELECTED':'').">".get_school_term($sem)."</OPTION><OPTION value=E".$sem.(('E'.$sem==$_REQUEST['school_term_sn'])?' SELECTED':'').">".get_school_term($sem).' '._('Exam').'</OPTION></SELECT>';
DisplayHeader($mp_select);
echo '</FORM>';

$sql = "SELECT s.LAST_NAME".CCAT."', '".CCAT."s.FIRST_NAME as FULL_NAME,s.USER_ID,g.GRADES_CARD_ID FROM STUDENT_GRADES_CARD g,USERS s,COURSE_SECTIONS cp WHERE g.COURSE_SECTION_ID=cp.COURSE_SECTION_ID AND cp.TEACHER_ID=s.USER_ID AND cp.SCHOOL_YEAR=g.SCHOOL_YEAR AND cp.SCHOOL_YEAR='".get_school_year()."' AND g.SCHOOL_TERM_ID='".$_REQUEST['school_term_sn']."'";
$grouped_array = db_request(db_execute($sql),array(),array('USER_ID','GRADES_CARD_ID'));
$grades_array = db_request(db_execute("SELECT ID,TITLE FROM GRADES_CARD_SETTINGS WHERE SCHOOL_ID='".get_school_id()."' AND SCHOOL_YEAR='".get_school_year()."' ORDER BY SORT_ORDER"));
if(count($grouped_array))
{
	foreach($grouped_array as $user_id=>$grades)
	{
		$i++;
		$teachers_array[$i]['FULL_NAME'] = $grades[key($grades)][1]['FULL_NAME']; 
		foreach($grades_array as $grade)
			if ($grades[$grade['ID']]) {
				$teachers_array[$i][$grade['ID']] = count($grades[$grade['ID']]);
			}
			
	}
}

$columns = array('FULL_NAME'=>_('Teacher Name'));
foreach($grades_array as $grade)
	$columns[$grade['ID']] = $grade['TITLE'];
Gridoutput($teachers_array,$columns,_('Teachers'),_('Amount of Teachers'));	
?>