<?php
  class CTEACHER{

    var $id;
    var $eName;
    var $pfx;
    var $cName;
    var $section;
    var $position;
    var $password;
    var $administrator;
    var $level;

	function __construct(){}

    function setTeacher($pfield,$pval){
	  global $conn;
      $query = "SELECT * FROM punchsys_staff WHERE $pfield='$pval'";
      $result = mysqli_query($conn,$query);
      $num = mysqli_num_rows($result);
	  
	  if($num>0){
	  while($myrow = mysqli_fetch_array($result)){
		  $this->id = $myrow["id"];
		  $this->eName = $myrow["eName"];
		  $this->pfx = $myrow["pfx"];
		  $this->cName = $myrow["cName"];
		  $this->section = $myrow["section"];
		  $this->position = $myrow["position"];
		  $this->password = $myrow["password"];
		  $this->administrator = $myrow["administrator"];
		  $this->level=$this->getLevel($this->administrator);
	  }
	  }
    }

    function getLevel($lvl){
	  global $conn;
      $query = "SELECT * FROM xoops_sps_level WHERE level='$lvl'";
      $result = mysqli_query($conn,$query);
	  while($myrow = mysqli_fetch_array($result)){
		  $level =  $myrow["level"];
		  if($level==""){
			$level = "0";
		  }
	  }
      return $level;
    }

//----------------

/*

    function chkFormTea(){
      $query = "SELECT * FROM xoops_rs_class WHERE teaId='" . $this->id . "'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);

      if($num>0){//--- is form teacher
        $i=0;
        while($i<$num){
          $temparrcid[$i] = mysql_result($result,$i,"id");
          $i++;
        }
        $strClass = implode(",",$temparrcid);
      }else{//--- not form teacher
        $strClass = "";
      }

      return $strClass;
    }

    function chkClassTeaById($pclass){
      $query = "SELECT * FROM xoops_rs_class WHERE id='$pclass'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);

      $tempteaid = mysql_result($result,0,"teaId");
      if($tempteaid === $this->id){//-- correct, is class teacher of that class
        $output = "1";
      }else{
        $output = "";//-- not class teacher of that class
      }

      return $output;
    }

    function chkClassTeaByName($pclass){
      $std = substr($pclass,0,1);
      $ccode = substr($pclass,1);
      $query = "SELECT * FROM xoops_rs_class WHERE standard='$std' AND classCode='$ccode' AND teaid='".$this->id."'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);

//      $tempclass = mysql_result($result,0,"standard") . mysql_result($result,0,"classCode");
      if($num>0){//-- correct, is class teacher of that class
        $output = "1";
      }else{
        $output = "0";//-- not class teacher of that class
      }

      return $output;
    }

    function getMyTchClass(){
      $query = "SELECT DISTINCT classId FROM xoops_rs_classsub WHERE teaid='".$this->id."'";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);
      $i=0;
      while($i<$num){

        $tid = mysql_result($result,$i,"classId");
        $arrClassId[$i]=$tid;

        $i++;
      }
      return $arrClassId;
    }

    function getMyTchSub($pcid){
      $query = "SELECT DISTINCT subId FROM xoops_rs_classsub WHERE teaid='".$this->id."' AND classId IN ($pcid)";
      $result = mysql_query($query);
      $num = mysql_num_rows($result);
      $i=0;
      while($i<$num){

        $tid = mysql_result($result,$i,"subId");
        $arrSubId[$i]=$tid;

        $i++;
      }
      return $arrSubId;
    }
*/
	//++++++++++++++++++++++++++++++++++++++++++++++
	//+++++  punch card system +++++++++++++++++++++
	//++++++++++++++++++++++++++++++++++++++++++++++
	
	
	//----- start time of punchin ----------
	function getStartT($wk){
	
      global $conn;
        
	  $query = "SELECT * FROM punchsys_timetable WHERE secid='" . $this->section . "' AND wkDay=$wk";
	  $result = mysqli_query($conn,$query);
	  $num = mysqli_num_rows($result);
	  
	  if($num>0){
        while($myrow = mysqli_fetch_array($result)){
            $output = $myrow["pcInTime"];
        }
	    return $output;
	  }else{
	    return "";
	  }
	
	}
	
	//------- end time of punchin ---------
	function getEndT($wk){
	
      global $conn;
	  $query = "SELECT * FROM punchsys_timetable WHERE secid='" . $this->section . "' AND wkDay=$wk";
	  $result = mysqli_query($conn,$query);
	  $num = mysqli_num_rows($result);
	  
	  if($num>0){
          while($myrow = mysqli_fetch_array($result)){
              $output = $myrow["pcOutTime"];
          }
	    return $output;
	  }else{
	    return "";
	  }
	
	}

  }
?>
<?
  function getTeaList(){
      global $conn;
    $query = "SELECT * FROM punchsys_staff WHERE id NOT IN ('admin','pejabat') AND userID<>'1' ORDER BY ename";
    $result = mysqli_query($conn,$query);
    $num = mysqli_num_rows($result);
    $i=0;
    while($myrow = mysqli_fetch_array($result)){

      $tid = $myrow["id"];
      $tename = $myrow["eName"];
      $tcname = $myrow["cName"];
	  $tsection = $myrow["section"];

      $arrOutput[$tid]["ename"] = $tename;
      $arrOutput[$tid]["cname"] = $tcname;
	  $arrOutput[$tid]["section"] = $tsection;

      $i++;
    }

    return $arrOutput;
  }
?>
<?
  function getTeaListOfDate($pdate){
      global $conn;
    $query = "SELECT * FROM punchsys_punchrecord WHERE staffId NOT IN ('admin','pejabat') AND punchDate='$pdate'";
    $result = mysqli_query($conn,$query);
    $num = mysqli_num_rows($result);
    $i=0;
    while($myrow = mysqli_fetch_array($result)){

      $tid = $myrow["staffId"];
      $arrOutput[$i] = $tid;

      $i++;
    }

    return $arrOutput;
  }
?>