<?php
require "querys.php";
include_once "../config/database.php";
include_once "../resources/offering.php";
include_once '../config/properties.php';
dbConnect();

// read xapi_id
$xapi_id = $_REQUEST['xapi_id'];
$cid = $_REQUEST['cid'];
$oid = $_REQUEST['oid'];
$id = $_REQUEST['uid'];
$rslt = $_REQUEST['rslt'];
$end_date = $_REQUEST['end_date'];
$date_time = $date_time;
$reg_id = $_REQUEST['rid'];

if ($end_date >= $date && $rslt == "N") {
   try {
            $result1 = mysqli_query($link, "select * from xapi_track where offering_id=$oid and user_id=$id and xapi_id=$xapi_id and contentdtl_id=$cid");
			if (!mysqli_num_rows($result1)) {
                           mysqli_query($link, "insert into xapi_track(offering_id,user_id,contentdtl_id,xapi_id,registration_id,status,xapi_batch,actual_score,score_min,score_max,last_updated_user,last_updated_ts) values ($oid,$id,$cid,$xapi_id,'$reg_id','initialized','W',0,0,0,$id,'$date_time')");
			} else {
                           mysqli_query($link, "update xapi_track set xapi_batch='W',last_updated_ts='$date_time' where offering_id=$oid and user_id=$id and xapi_id=$xapi_id and contentdtl_id=$cid");
			}
                     
        } catch (Exception $e) {
            error_log("Caught $e");
        }
}
?>