<?php
//  essential functions
require "subs.php";

//  read database login information and connect
require "../config/database.php";
dbConnect();
include_once "../resources/assessment.php";
$assessment = new Assessment();

// read scorm_id
$scorm_id = $_REQUEST['scorm_id'] * 1;
$contentdtl_id = $_REQUEST['contentdtl_id'];
$oid = $_REQUEST['oid'];
$id = $_REQUEST['uid'];
$end_date = $_REQUEST['end_date'];
$rslt = $_REQUEST['rslt'];
$date_time = $date_time;
$date = $date;

//$results = print_r($rslt,true); 
//$handle = fopen("debug.txt",'w');
//fwrite($handle,$results);
//fclose($handle);
//$is_passes = false;
//if (!is_array($data)) {
//    $data = array($data);
//}
// iterate through the data elements
foreach (data_submitted() as $varname => $varvalue) {
    $varname = str_replace('__', '.', $varname);
    // save data to the 'scormvars' table
    if (substr($varname, 0, 3) == 'cmi') {
        $netelement = preg_replace('/\.N(\d+)\./', "\.\$1\.", $varname);
        writeElement($netelement, $varvalue);
    }
}

if ($end_date >= $date && $rslt == "N") {
	require '../cal_result.php';
    if (readElement('cmi.core.lesson_status') == "passed" || readElement('cmi.core.lesson_status') == "completed") {
        $rslt = "Y";
        updateContentTrack();
        //require '../cal_result.php';
    } else {
        updateScormContentTrack();
    }
}

// return value to the calling program
print "true";
?>