<?php
//define('AJAX_SCRIPT', true);
//echo ($_POST['startTimer']);
require('../../config.php');
require_once($CFG->dirroot.'/mod/lesson/locallib.php');
//require_once($CFG->dirroot.'/mod/lesson/view_form.php');
//require_once($CFG->libdir . '/completionlib.php');
//require_once($CFG->libdir . '/grade/constants.php');

$id      =  $_POST['cid'];

$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
//print_r($lesson);


$begin = ($_POST['endTimer']/1000)+1;
if(isset($startlastseen)){
    $continue = ($startlastseen !== '');
    $restart  = ($continue && $startlastseen == 'yes');
}



//$timer = $lesson->update_cstimer($begin, $continue, $restart); 
//print_r($timer);
$lesson->update_cstimer($begin);
?>