<?php
//--Class ClassInStructor--------------------------

include_once "clsbase_ClassInStructor.php";

class 
ClassInStructor extends base_ClassInStructor{

function 
RSClassInStructorBySeqAndClId($xKey$yKey){
    
$this->SetQuery("select * from ClassInStructor where sequenceId='$xKey' and classId='$yKey' order by sequenceId");
}

function 
RSClassInStructorByClId($xKey){
    
$this->SetQuery("select officerId from ClassInStructor where classId='$xKey' group by officerId");
}

function 
RSClassInStructorDistinctClIdOfIdByClId($xKey){
    
$this->SetQuery("select distinct classId, officerId from ClassInStructor where classId='$xKey'");
}

function 
RSClassInStructorByClIdAndOfId($xKey$yKey){
    
$this->SetQuery("select * from ClassInStructor where classId='$xKey' and officerId='$yKey'");
}

function 
RSClassInStructorByClIdAndResponsibilityIsY($xKey){
    
$this->SetQuery("select * from ClassInStructor where classId='$xKey' and responsibility='Y'");
}

function 
RSClassInStructorByClIdAndOfIdAndResponsibilityIsY($xKey$yKey){
    
$this->SetQuery("select * from ClassInStructor where classId='$xKey' and officerId='$yKey' and responsibility='Y'");
}

// Use on page addGrade.php
function SearchByClassId($xKey){
    if (
$this->SetQuery("select distinct(officerId) from ClassInStructor where classId='$xKey'")){
        return 
1;
    }else {
        return 
0;
    }
}
//-- The End --

//-- Use on page beforeShowClassTeach.php --
function SearchCISByOfId($OfId){
    
$this->SetQuery("select * from ClassInStructor where officerId='$OfId' ");
}    
//-- The end --

//-- Use on page classTable.php of teacher --
function SearchCISByOfIdAndClassId($OfId,$ClsId){
    
$this->SetQuery("select count(officerId) as num from ClassInStructor where officerId='$OfId' and classId='$ClsId'");
    
/*    if($this->SetQuery("select * from ClassInStructor where officerId='$OfId' and classId='$ClsId'")){    
        return 1;    
    }else{
        return 0;
    }*/
    
$result=$this->GetResult();
    return 
$result['num'];    
}    
//-- The end --

//--  Use on page processClass.php --
function SearchCISByAcYSeMClsIdWdRmIdS1E1OfId($AcY$SeM$WD$rmId$S1$E1$OfId){
    
$sql "SELECT count(*) as num 
            from Class c, ClassTimeTable t, ClassInStructor s 
            where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=s.classId 
            and c.classId=t.classId and t.sequenceId=s.sequenceId 
            and t.weekDay='$WD' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1') 
            and s.officerId='$OfId'"
;
    
$this->SetQuery($sql);
    
/*$this->SetQuery("SELECT count(*) as num 
                                from Class c, ClassTimeTable t, ClassInStructor s 
                                where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=s.classId and 
                                c.classId=t.classId and t.weekDay='$WD' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1') 
                                and s.officerId='$OfId'");*/
    
$result=$this->GetResult();
    return 
$result['num'];
}

function 
SearchCISByAcYSeMClsIdWdRmIdS1E1OfIdAndCoIdAndSectionAndOVL($AcY$SeM$WD$rmId$S1$E1$OfId$coId$section){
    
$sql "SELECT count(*) as num 
            from Class c, ClassTimeTable t, ClassInStructor s 
            where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=s.classId 
            and c.classId=t.classId and t.sequenceId=s.sequenceId 
            and t.weekDay='$WD' and t.timeSlotStart='$S1' and t.timeSlotEnd='$E1' 
            and s.officerId='$OfId' 
            and c.courseId='$coId' and c.section!='$section' and t.overlap='Y'"
;
    
$this->SetQuery($sql);
    
$result=$this->GetResult();
    return 
$result['num'];
}

function 
CheckTeachOfficer($Seq$ClsId$OfId){
    
$this->SetQuery("SELECT count(officerId) as num from ClassInStructor where sequenceId='$Seq' and classId='$ClsId' and officerId='$OfId' ");
    
$result=$this->GetResult();
    return 
$result['num'];
}
//--  The end --

//--End class ClassInStructor--
?>