<?
  include "../../mainfile.php";
?>
<?
  $pdate = $_POST["pdate"];
  $notice = $_POST["notice"];
  $arrTeaid0 = $_POST["arrTeaid0"];
  $arrTeaid1 = $_POST["arrTeaid1"];
  $attdonly = $_POST["attdonly"];
?>
<?
  if($attdonly==1){
    foreach($arrTeaid1 as $tid){
      $query = "UPDATE xoops_pc_punchrecord SET message='$notice' WHERE staffId='$tid' AND punchDate='$pdate'";
      mysql_query($query);
    }
  }else{
    $strTeaid = "'".implode("','",$arrTeaid0)."'";
    $qchk = "SELECT * FROM xoops_pc_punchrecord WHERE staffId IN ($strTeaid) AND punchDate='$pdate'";
	$rchk = mysql_query($qchk);
	$nchk = mysql_num_rows($rchk);
	$i=0;
	while($i<$nchk){
	  $tstaffid = mysql_result($rchk,$i,"staffId");
	  $arrChk[$tstaffid] = $tstaffid;
	  $i++;
	}

    foreach($arrTeaid0 as $tid){
	  if( isset($arrChk[$tid]) ){
        $query = "UPDATE xoops_pc_punchrecord SET message='$notice' WHERE staffId='$tid' AND punchDate='$pdate'";
	  }else{
        $query = "INSERT INTO xoops_pc_punchrecord VALUES
                    (NULL,'$tid','$pdate','00:00:00','$pdate','00:00:00','$notice','00:00:00','00:00:00')";
	  }
      mysql_query($query);
//	  echo $query . "<br>";
    }
  }
?>
<?
  header("Location: main.php?pg=rmk&ac=tska&dt=$pdate&btnDate=...");
?>