<?
  function checkTeaID($pty,$pid,$ppass){
    //pty=1:verify wif password , pty=2:without password
    switch($pty){
	  case 1:
        $query = "SELECT * FROM xoops_adm_teacher WHERE userID<>'1' AND id='$pid' AND `password`='$ppass'";
	    break;
	  case 2:
        $query = "SELECT * FROM xoops_adm_teacher WHERE userID<>'1' AND id='$pid'";
	}

    $result = mysql_query($query);
	$num = mysql_num_rows($result);
	
	if($num>0){
	  $output = mysql_result($result,0,"id");	
	}else{
	  $output = "false";
	}
	
    return $output;
  }
?>
<?
  function checkHoliday($pdate){
    $query = "SELECT * FROM xoops_pc_holiday 
               WHERE holDateFm <= '$pdate' AND holDateTo >= '$pdate'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
	if($num>0){
	  return true;
	}else{
	  return false;
	}
  }
?>
<?
  function checkMaxpunch($pid,$pdate,$pmax){
    $query = "SELECT * FROM xoops_pc_punchrecord WHERE staffId='$pid' AND punchDate='$pdate' AND punchOut<>'00:00:00'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    //--- max punch limit is over
    if( $num >= $pmax ){
	  return true;
	}else{
	  return false;
	}
  }
?>
<?
  function checkPunchOUT($pid,$pdate){
    $query = "SELECT * FROM xoops_pc_punchrecord 
                WHERE staffId='$pid' AND punchDate='$pdate' 
			      AND punchOut='00:00:00'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);

    if($num>0){
	  $output[0] = true;
	  $output[1] = mysql_result($result,0,"punchIn");
	}else{
	  $output[0] = false;
	  $output[1] = "";
	}
	return $output;
  }
?>
<?
  function updateLate($puid,$prid,$pdate){

    $query0 = "SELECT * FROM xoops_pc_remarkrecord WHERE staffId='$puid' AND remarkDate='$pdate'";
  
	$result0 = mysql_query($query0);
	$num0 = mysql_num_rows($result0);
	
	if($num0>0){
	  $tid = mysql_result($result0,0,"id");
	  $query = "UPDATE xoops_pc_remarkrecord SET eventId='$prid' WHERE id='$tid'";
	}else{
	  $query = "INSERT INTO xoops_pc_remarkrecord VALUES (NULL,'$puid','$pdate','$pdate','$prid','','1','admin','$pdate')";
	}
	mysql_query($query);

  }
?>