--- locallib.old.php 2008-05-07 15:56:54.926899136 +0200 +++ locallib.php 2008-05-07 15:23:26.499226552 +0200 @@ -1832,4 +1832,30 @@ return false; } +/** + * Starts lesson (alters $USER object and inserts a record into lesson_time). + * If the lesson is timed, a time warning is set with lesson_set_message(). + * + */ +function lesson_start_lesson(&$USER, $lesson, $context) { + if(!isset($USER->startlesson[$lesson->id]) && !has_capability('mod/lesson:manage', $context)) { + $USER->startlesson[$lesson->id] = true; + if (!get_field('lesson_timer', 'id', 'userid', $USER->id, 'lessonid', $lesson->id)) { + // add a record showing that the lesson has been started + $startlesson = new stdClass; + $startlesson->lessonid = $lesson->id; + $startlesson->userid = $USER->id; + $startlesson->starttime = time(); + $startlesson->lessontime = time(); + + if (!insert_record('lesson_timer', $startlesson)) { + error('Error: could not insert row into lesson_timer table'); + } + } + if ($lesson->timed) { + lesson_set_message(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); + } + } +} + ?>