header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
$path = "../libraries/";
$loadLanguage = false;
define("NO_OUTPUT_BUFFERING", true);
/** Configuration file.*/
require_once $path . "configuration.php";
if (empty($_SESSION['s_login']) || !eF_checkParameter($_SESSION['s_login'], 'login')) {
    echo json_encode(array('status' => 0, 'code' => -1));
    exit;
}
try {
    if ($GLOBALS['configuration']['last_reset_certificate'] + 24 * 60 * 60 < time()) {
        EfrontCourse::checkCertificateExpire();
        EfrontConfiguration::setValue('last_reset_certificate', time());
    }
    $currentTheme = new themes($_SESSION['s_theme']);
    $newTime = '';
    $jsonValues = array();
    if ($_SESSION['s_login']) {
        $entity = getUserTimeTarget($_GET['HTTP_REFERER']);
        //Update times for this entity
        if ($_SESSION['s_lesson_user_type'] == 'student' && isset($_POST['user_total_time_in_unit']) && current($entity) == 'unit' && eF_checkParameter(key($entity), 'id')) {
            $newTime = $_POST['user_total_time_in_unit'];
            $jsonValues['entity'] = current($entity);
            $jsonValues['entity_id'] = current($entity);
            if ($newTime && is_numeric($newTime)) {
                $result = eF_executeNew("insert into users_to_content (users_LOGIN, content_ID, lessons_ID) values('" . $_SESSION['s_login'] . "', " . key($entity) . ", " . $_SESSION['s_lessons_ID'] . ") on duplicate key update total_time={$newTime}");
                $jsonValues['time_in_unit'] = EfrontTimes::formatTimeForReporting($newTime);