<?php
  include "include/dbcon.php";
  include "apidbcon.php";

//  $API_IMPORTPATH = "http://clientsite.skyppr.com/api/punch_import.php?psch=$SCHOOLCODE";
?>
<?php
  class RECORD{
	  var $staffId, $punchDate, $punchIn, $punchOutDate, $punchOut, $message, $comLate, $levEarly;
	  function __construct(){
	  }
  }
?>
<?php
  $pdate2 = date("Y-m-d");
  $pdate1 = date("Y-m-d",strtotime("-7 days",strtotime($pdate2)));

  $qrecord = "SELECT * FROM punchsys_punchrecord WHERE punchDate BETWEEN '$pdate1' AND '$pdate2'";
echo $qrecord;
  $rrecord = mysqli_query($conn,$qrecord);
  $nrecord = mysqli_num_rows($rrecord);
  if($nrecord>0){
	  $i=0;
	  while($myrow = mysqli_fetch_array($rrecord)){
		  
		  $myrecord[$i]->staffId = $myrow["staffId"];
		  $myrecord[$i]->punchDate = $myrow["punchDate"];
		  $myrecord[$i]->punchIn = $myrow["punchIn"];
		  $myrecord[$i]->punchOutDate = $myrow["punchOutDate"];
		  $myrecord[$i]->punchOut = $myrow["punchOut"];
		  $myrecord[$i]->message = $myrow["message"];
		  $myrecord[$i]->comLate = $myrow["comLate"];
		  $myrecord[$i]->levEarly = $myrow["levEarly"];
		  
		  $i++;
	  }
  }
?>
<?php
  $json_record = json_encode($myrecord);
  $pval = array('precord'=>$json_record);
//  echo json_encode($pval);
?>
<?php
  $url = $API_IMPORTPATH;
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $pval);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $pid = curl_exec($ch);
  if( curl_errno($ch) ){
	  echo curl_error($ch);
  }else{
//	  echo "data uploaded";
	  curl_close($ch);
  }
  
?>
<script>
	//window.location = "vb_index_report.php";
	window.location = "vb_index_report.php";
</script>