2004-09-15 20:32:24 +00:00
< ? PHP // $Id$
2004-02-16 05:41:13 +00:00
/// This page prints a particular instance of lesson
/// (Replace lesson with the name of your module)
2004-09-24 23:10:49 +00:00
require_once ( '../../config.php' );
require_once ( 'locallib.php' );
require_once ( 'lib.php' );
2004-09-21 22:15:30 +00:00
2005-01-27 21:36:12 +00:00
$id = required_param ( 'id' , PARAM_INT ); // Course Module ID
$pageid = optional_param ( 'pageid' , NULL , PARAM_INT ); // Lesson Page ID
2004-02-16 05:41:13 +00:00
2004-09-24 23:10:49 +00:00
if ( ! $cm = get_record ( 'course_modules' , 'id' , $id )) {
error ( 'Course Module ID was incorrect' );
2004-02-16 05:41:13 +00:00
}
2004-09-24 23:10:49 +00:00
if ( ! $course = get_record ( 'course' , 'id' , $cm -> course )) {
error ( 'Course is misconfigured' );
2004-02-16 05:41:13 +00:00
}
2004-09-24 23:10:49 +00:00
if ( ! $lesson = get_record ( 'lesson' , 'id' , $cm -> instance )) {
error ( 'Course module is incorrect' );
2004-02-16 05:41:13 +00:00
}
2005-03-12 18:00:05 +00:00
require_login ( $course -> id , false , $cm );
2004-02-16 05:41:13 +00:00
/// Print the page header
2004-09-15 20:32:24 +00:00
if ( $course -> category ) {
2004-09-24 23:10:49 +00:00
$navigation = '<a href="../../course/view.php?id=' . $course -> id . '">' . $course -> shortname . '</a> ->' ;
2004-09-15 20:32:24 +00:00
}
2004-09-24 23:10:49 +00:00
$strlessons = get_string ( 'modulenameplural' , 'lesson' );
$strlesson = get_string ( 'modulename' , 'lesson' );
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
/// CDC-FLAG moved the action up because I needed to know what the action will be before the header is printed
if ( empty ( $action )) {
2004-09-15 20:32:24 +00:00
if ( isteacher ( $course -> id )) {
$action = 'teacherview' ;
2004-09-24 23:10:49 +00:00
} elseif ( time () < $lesson -> available ) {
2005-04-24 16:46:51 +00:00
print_header ( $course -> shortname . ': ' . format_string ( $lesson -> name ), $course -> fullname ,
2005-03-30 03:07:39 +00:00
$navigation . '<a href="index.php?id=' . $course -> id . '">' . $strlessons . '</a> -> ' .
2005-04-24 16:46:51 +00:00
'<a href="view.php?id=' . $cm -> id . '">' . format_string ( $lesson -> name , true ) . '</a>' ,
2005-03-30 03:07:39 +00:00
'' , '' , true , '' , navmenu ( $course , $cm ));
2004-09-24 23:10:49 +00:00
print_simple_box_start ( 'center' );
echo '<div align="center">' ;
echo get_string ( 'lessonopen' , 'lesson' , userdate ( $lesson -> available )) . '<br />' ;
echo '<a href="../../course/view.php?id=' . $course -> id . '">' . get_string ( 'returnmainmenu' , 'lesson' ) . '</a>' ;
echo '</div>' ;
print_simple_box_end ();
print_footer ( $course );
exit ();
} elseif ( time () > $lesson -> deadline ) {
2005-04-24 16:46:51 +00:00
print_header ( $course -> shortname . ': ' . format_string ( $lesson -> name ), $course -> fullname ,
" $navigation <a href= \" index.php?id= $course->id\ " > $strlessons </ a > -> < a href = \ " view.php?id= $cm->id\ " > " .format_string( $lesson->name ,true). " </ a > " , '', " " , true,
2004-11-04 09:24:51 +00:00
'' , navmenu ( $course , $cm ));
2004-09-24 23:10:49 +00:00
print_simple_box_start ( 'center' );
echo '<div align="center">' ;
echo get_string ( 'lessonclosed' , 'lesson' , userdate ( $lesson -> deadline )) . '<br />' ;
echo '<a href="../../course/view.php?id=' . $course -> id . '">' . get_string ( 'returnmainmenu' , 'lesson' ) . '</a>' ;
echo '</div>' ;
print_simple_box_end ();
print_footer ( $course );
exit ();
2005-05-06 23:57:20 +00:00
} elseif ( $lesson -> highscores && ! $lesson -> practice ) {
2004-09-24 23:10:49 +00:00
$action = 'highscores' ;
2004-09-15 20:32:24 +00:00
} else {
$action = 'navigation' ;
}
2005-02-23 00:52:29 +00:00
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
/// CDC-FLAG changed the update_module_button and added another button when a teacher is checking the navigation of the lesson
2004-09-15 20:32:24 +00:00
if ( isteacheredit ( $course -> id )) {
2004-09-24 23:10:49 +00:00
$button = '<table><tr><td>' ;
$button .= '<form target="' . $CFG -> framename . '" method="get" action="' . $CFG -> wwwroot . '/course/mod.php">' .
2005-01-27 21:36:12 +00:00
'<input type="hidden" name="sesskey" value="' . $USER -> sesskey . '" />' .
2004-09-24 23:10:49 +00:00
'<input type="hidden" name="update" value="' . $cm -> id . '" />' .
'<input type="hidden" name="return" value="true" />' .
'<input type="submit" value="' . get_string ( 'editlessonsettings' , 'lesson' ) . '" /></form>' ;
if ( $action == 'navigation' && $pageid != LESSON_EOL ) {
2005-10-03 19:46:44 +00:00
$currentpageid = $pageid ; // very important not to alter $pageid.
if ( empty ( $currentpageid )) {
if ( ! $currentpageid = get_field ( 'lesson_pages' , 'id' , 'lessonid' , $lesson -> id , 'prevpageid' , 0 )) {
error ( 'Navigation: first page not found' );
}
}
2004-09-24 23:10:49 +00:00
$button .= '</td><td>' .
'<form target="' . $CFG -> framename . '" method="get" action="' . $CFG -> wwwroot . '/mod/lesson/lesson.php">' .
'<input type="hidden" name="id" value="' . $cm -> id . '" />' .
'<input type="hidden" name="action" value="editpage" />' .
2005-10-03 19:46:44 +00:00
'<input type="hidden" name="pageid" value="' . $currentpageid . '" />' .
2004-09-24 23:10:49 +00:00
'<input type="submit" value="' . get_string ( 'editpagecontent' , 'lesson' ) . '" /></form>' ;
}
$button .= '</td></tr></table>' ;
} else {
$button = '' ;
}
2004-02-16 05:41:13 +00:00
2005-04-24 16:46:51 +00:00
print_header ( $course -> shortname . ': ' . format_string ( $lesson -> name ), $course -> fullname ,
" $navigation <a href= \" index.php?id= $course->id\ " > $strlessons </ a > -> < a href = \ " view.php?id= $cm->id\ " > " .format_string( $lesson->name ,true). " </ a > " , '', '', true,
2004-11-04 09:24:51 +00:00
$button , // took out update_module_button($cm->id, $course->id, $strlesson) and replaced it with $button
2004-02-16 05:41:13 +00:00
navmenu ( $course , $cm ));
// set up some general variables
$usehtmleditor = can_use_html_editor ();
2004-09-24 23:10:49 +00:00
$path = $CFG -> wwwroot . '/course' ;
2004-11-04 09:24:51 +00:00
2004-02-16 05:41:13 +00:00
/************** navigation **************************************/
if ( $action == 'navigation' ) {
2004-09-24 23:10:49 +00:00
/// CDC-FLAG /// password protected lesson code
2004-11-01 20:41:55 +00:00
if ( $lesson -> usepassword && ! isteacher ( $course -> id )) {
2004-09-24 23:10:49 +00:00
$correctpass = false ;
if ( isset ( $_POST [ 'userpassword' ])) {
2005-01-27 21:36:12 +00:00
if ( $lesson -> password == md5 ( trim ( clean_param ( $_POST [ 'userpassword' ], PARAM_CLEAN )))) {
2004-09-24 23:10:49 +00:00
$USER -> lessonloggedin [ $lesson -> id ] = true ;
$correctpass = true ;
}
} elseif ( isset ( $USER -> lessonloggedin [ $lesson -> id ])) {
$correctpass = true ;
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
if ( ! $correctpass ) {
print_simple_box_start ( 'center' );
echo '<form name="password" method="post" action="view.php">' . " \n " ;
2004-11-04 09:24:51 +00:00
echo '<input type="hidden" name="id" value="' . $cm -> id . '" />' . " \n " ;
echo '<input type="hidden" name="action" value="navigation" />' . " \n " ;
2004-09-24 23:10:49 +00:00
echo '<table cellpadding="7px">' ;
if ( isset ( $_POST [ 'userpassword' ])) {
echo " <tr align= \" center \" style='color:#DF041E;'><td> " . get_string ( 'loginfail' , 'lesson' ) . '</td></tr>' ;
}
2005-04-24 16:46:51 +00:00
echo '<tr align="center"><td>' . get_string ( 'passwordprotectedlesson' , 'lesson' , format_string ( $lesson -> name )) . '</td></tr>' ;
2004-11-04 09:24:51 +00:00
echo '<tr align="center"><td>' . get_string ( 'enterpassword' , 'lesson' ) . ' <input type="password" name="userpassword" /></td></tr>' ;
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
echo '<tr align="center"><td>' ;
2004-11-04 09:24:51 +00:00
echo '<input type="button" value="' . get_string ( 'cancel' , 'lesson' ) . '" onclick="parent.location=\'../../course/view.php?id=' . $course -> id . '\';" /> ' ;
echo '<input type="button" value="' . get_string ( 'continue' , 'lesson' ) . '" onclick="document.password.submit();" />' ;
2004-09-24 23:10:49 +00:00
echo '</td></tr></table>' ;
print_simple_box_end ();
exit ();
}
}
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
// this is called if a student leaves during a lesson
if ( $pageid == LESSON_UNSEENBRANCHPAGE ) {
$pageid = lesson_unseen_question_jump ( $lesson -> id , $USER -> id , $pageid );
}
2005-02-23 00:52:29 +00:00
2004-02-16 05:41:13 +00:00
// display individual pages and their sets of answers
// if pageid is EOL then the end of the lesson has been reached
2004-09-24 23:10:49 +00:00
// for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down
2005-03-05 00:09:39 +00:00
$timedflag = false ;
$attemptflag = false ;
2004-09-24 23:10:49 +00:00
if ( empty ( $pageid )) {
2005-06-30 21:11:02 +00:00
// check for dependencies first
if ( $lesson -> dependency and ! isteacher ( $course -> id )) {
if ( $dependentlesson = get_record ( 'lesson' , 'id' , $lesson -> dependency )) {
// lesson exists, so we can proceed
$conditions = unserialize ( $lesson -> conditions );
// assume false for all
$timespent = false ;
$completed = false ;
$gradebetterthan = false ;
// check for the timespent condition
if ( $conditions -> timespent ) {
if ( $attempttimes = get_records_select ( 'lesson_timer' , " userid = $USER->id AND lessonid = $dependentlesson->id " )) {
// go through all the times and test to see if any of them satisfy the condition
foreach ( $attempttimes as $attempttime ) {
$duration = $attempttime -> lessontime - $attempttime -> starttime ;
if ( $conditions -> timespent < $duration / 60 ) {
$timespent = true ;
}
}
}
} else {
$timespent = true ; // there isn't one set
}
// check for the gradebetterthan condition
if ( $conditions -> gradebetterthan ) {
if ( $studentgrades = get_records_select ( 'lesson_grades' , " userid = $USER->id AND lessonid = $dependentlesson->id " )) {
// go through all the grades and test to see if any of them satisfy the condition
foreach ( $studentgrades as $studentgrade ) {
if ( $studentgrade -> grade >= $conditions -> gradebetterthan ) {
$gradebetterthan = true ;
}
}
}
} else {
$gradebetterthan = true ; // there isn't one set
}
// check for the completed condition
if ( $conditions -> completed ) {
if ( count_records ( 'lesson_grades' , 'userid' , $USER -> id , 'lessonid' , $dependentlesson -> id )) {
$completed = true ;
}
} else {
$completed = true ; // not set
}
$errors = array ();
// collect all of our error statements
if ( ! $timespent ) {
$errors [] = get_string ( 'timespenterror' , 'lesson' , $conditions -> timespent );
}
if ( ! $completed ) {
$errors [] = get_string ( 'completederror' , 'lesson' );
}
if ( ! $gradebetterthan ) {
$errors [] = get_string ( 'gradebetterthanerror' , 'lesson' , $conditions -> gradebetterthan );
}
if ( ! empty ( $errors )) { // print out the errors if any
echo '<p>' ;
print_simple_box_start ( 'center' );
print_string ( 'completethefollowingconditions' , 'lesson' , $dependentlesson -> name );
echo '<p align="center">' . implode ( '<br />' . get_string ( 'and' , 'lesson' ) . '<br />' , $errors ) . '</p>' ;
print_simple_box_end ();
echo '</p>' ;
print_footer ( $course );
exit ();
}
}
}
2004-09-24 23:10:49 +00:00
add_to_log ( $course -> id , 'lesson' , 'start' , 'view.php?id=' . $cm -> id , $lesson -> id , $cm -> id );
2004-02-16 05:41:13 +00:00
// if no pageid given see if the lesson has been started
2004-09-24 23:10:49 +00:00
if ( $grades = get_records_select ( 'lesson_grades' , 'lessonid = ' . $lesson -> id . ' AND userid = ' . $USER -> id ,
'grade DESC' )) {
2004-02-16 05:41:13 +00:00
$retries = count ( $grades );
} else {
$retries = 0 ;
}
if ( $retries ) {
2005-03-05 00:09:39 +00:00
$attemptflag = true ;
2004-02-16 05:41:13 +00:00
}
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
unset ( $USER -> modattempts [ $lesson -> id ]); // if no pageid, then student is NOT reviewing
}
2004-02-16 05:41:13 +00:00
// if there are any questions have been answered correctly in this attempt
2005-02-23 00:52:29 +00:00
if ( $attempts = get_records_select ( 'lesson_attempts' ,
" lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND
2004-09-24 23:10:49 +00:00
correct = 1 " , 'timeseen DESC')) {
2005-04-05 22:42:34 +00:00
2004-02-16 05:41:13 +00:00
foreach ( $attempts as $attempt ) {
2004-09-24 23:10:49 +00:00
$jumpto = get_field ( 'lesson_answers' , 'jumpto' , 'id' , $attempt -> answerid );
2004-02-16 05:41:13 +00:00
// convert the jumpto to a proper page id
if ( $jumpto == 0 ) { // unlikely value!
$lastpageseen = $attempt -> pageid ;
2004-02-26 16:54:47 +00:00
} elseif ( $jumpto == LESSON_NEXTPAGE ) {
2005-02-23 00:52:29 +00:00
if ( ! $lastpageseen = get_field ( 'lesson_pages' , 'nextpageid' , 'id' ,
2004-02-16 05:41:13 +00:00
$attempt -> pageid )) {
// no nextpage go to end of lesson
2004-02-26 16:54:47 +00:00
$lastpageseen = LESSON_EOL ;
2004-02-16 05:41:13 +00:00
}
} else {
$lastpageseen = $jumpto ;
}
2005-02-23 00:52:29 +00:00
break ; // only look at the latest correct attempt
2004-02-16 05:41:13 +00:00
}
2005-05-16 22:41:19 +00:00
} else {
$attempts = NULL ;
}
2005-04-05 22:42:34 +00:00
2005-05-16 22:41:19 +00:00
if ( $branchtables = get_records_select ( 'lesson_branch' ,
" lessonid = $lesson->id AND userid = $USER->id AND retry = $retries " , 'timeseen DESC' )) {
// in here, user has viewed a branch table
$lastbranchtable = current ( $branchtables );
if ( $attempts != NULL ) {
foreach ( $attempts as $attempt ) {
if ( $lastbranchtable -> timeseen > $attempt -> timeseen ) {
// branch table was viewed later than the last attempt
$lastpageseen = $lastbranchtable -> pageid ;
}
break ;
}
} else {
// hasnt answered any questions but has viewed a branch table
$lastpageseen = $lastbranchtable -> pageid ;
}
}
2005-04-05 22:42:34 +00:00
//if ($lastpageseen != $firstpageid) {
if ( isset ( $lastpageseen ) and count_records ( 'lesson_attempts' , 'lessonid' , $lesson -> id , 'userid' , $USER -> id , 'retry' , $retries ) > 0 ) {
2005-05-16 22:41:19 +00:00
// get the first page
2005-04-05 22:42:34 +00:00
if ( ! $firstpageid = get_field ( 'lesson_pages' , 'id' , 'lessonid' , $lesson -> id ,
'prevpageid' , 0 )) {
error ( 'Navigation: first page not found' );
}
/// CDC-FLAG ///
if ( $lesson -> timed ) {
if ( $lesson -> retake ) {
echo '<form name="queryform" method ="post" action="view.php">' . " \n " ;
echo '<input type="hidden" name="id" value="' . $cm -> id . '" />' . " \n " ;
echo '<input type="hidden" name="action" value="navigation" />' . " \n " ;
echo '<input type="hidden" name="pageid" />' . " \n " ;
echo '<input type="hidden" name="startlastseen" />' . " \n " ; /// CDC-FLAG added this line
print_simple_box ( '<p align="center">' . get_string ( 'leftduringtimed' , 'lesson' ) . '</p>' , 'center' );
echo '<p align="center"><input type="button" value="' . get_string ( 'continue' , 'lesson' ) .
2004-11-04 09:24:51 +00:00
" \" onclick= \" document.queryform.pageid.value=' $firstpageid ';document.queryform.startlastseen.value='no';document.queryform.submit(); \" /></p> \n " ; /// CDC-FLAG added document.queryform.startlastseen.value='yes'
2005-04-05 22:42:34 +00:00
echo '</form>' . " \n " ;
2005-05-16 22:41:19 +00:00
echo '</div></div>' ; ///CDC Chris Berri added close div tag
2005-04-05 22:42:34 +00:00
} else {
print_simple_box_start ( 'center' );
echo '<div align="center">' ;
echo get_string ( 'leftduringtimednoretake' , 'lesson' );
echo '<br /><br /><a href="../../course/view.php?id=' . $course -> id . '">' . get_string ( 'returntocourse' , 'lesson' ) . '</a>' ;
echo '</div>' ;
print_simple_box_end ();
2004-09-24 23:10:49 +00:00
}
2005-04-05 22:42:34 +00:00
} else {
echo " <form name= \" queryform \" method = \" post \" action= \" view.php \" > \n " ;
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> \n " ;
echo " <input type= \" hidden \" name= \" action \" value= \" navigation \" /> \n " ;
echo " <input type= \" hidden \" name= \" pageid \" /> \n " ;
echo " <input type= \" hidden \" name= \" startlastseen \" /> \n " ; /// CDC-FLAG added this line
print_simple_box ( " <p align= \" center \" > " . get_string ( 'youhaveseen' , 'lesson' ) . '</p>' ,
" center " );
echo " <p align= \" center \" ><input type= \" button \" value= \" " . get_string ( 'yes' ) .
" \" onclick= \" document.queryform.pageid.value=' $lastpageseen ';document.queryform.startlastseen.value='yes';document.queryform.submit(); \" /> <input type= \" button \" value= \" " . get_string ( " no " ) . /// CDC-FLAG 6/11/04 ///
" \" onclick= \" document.queryform.pageid.value=' $firstpageid ';document.queryform.startlastseen.value='no';document.queryform.submit(); \" /></p> \n " ; /// CDC-FLAG added document.queryform.startlastseen.value='yes'
echo " </form> \n " ; echo " </div></div> " ; ///CDC Chris Berri added close div tag
2004-02-16 05:41:13 +00:00
}
2005-04-05 22:42:34 +00:00
print_footer ( $course );
2005-05-16 22:41:19 +00:00
exit ();
2004-02-16 05:41:13 +00:00
}
2005-03-05 00:09:39 +00:00
2004-02-16 05:41:13 +00:00
if ( $grades ) {
foreach ( $grades as $grade ) {
$bestgrade = $grade -> grade ;
break ;
}
if ( ! $lesson -> retake ) {
2004-09-24 23:10:49 +00:00
print_simple_box_start ( 'center' );
echo " <div align= \" center \" > " ;
echo get_string ( " noretake " , " lesson " );
echo " <br /><br /><a href= \" ../../course/view.php?id= $course->id\ " > " .get_string('returntocourse', 'lesson').'</a>';
echo " </div> " ;
print_simple_box_end ();
print_footer ( $course );
exit ();
//redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson"));
2004-02-16 05:41:13 +00:00
// allow student to retake course even if they have the maximum grade
// } elseif ($bestgrade == 100) {
2004-09-24 23:10:49 +00:00
// redirect("../../course/view.php?id=$course->id", get_string("maximumgradeachieved",
2004-02-16 05:41:13 +00:00
// "lesson"));
}
}
// start at the first page
2005-03-05 00:09:39 +00:00
if ( ! $pageid = get_field ( 'lesson_pages' , 'id' , 'lessonid' , $lesson -> id , 'prevpageid' , 0 )) {
error ( 'Navigation: first page not found' );
}
2005-06-15 23:35:11 +00:00
/// This is the code for starting a timed test
2005-02-25 19:10:17 +00:00
if ( ! isset ( $USER -> startlesson [ $lesson -> id ]) && ! isteacher ( $course -> id )) {
2004-09-24 23:10:49 +00:00
$USER -> startlesson [ $lesson -> id ] = true ;
2005-02-25 19:10:17 +00:00
$startlesson = new stdClass ;
2004-09-24 23:10:49 +00:00
$startlesson -> lessonid = $lesson -> id ;
$startlesson -> userid = $USER -> id ;
$startlesson -> starttime = time ();
$startlesson -> lessontime = time ();
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
if ( ! insert_record ( 'lesson_timer' , $startlesson )) {
error ( 'Error: could not insert row into lesson_timer table' );
}
if ( $lesson -> timed ) {
$timedflag = true ;
}
2004-02-16 05:41:13 +00:00
}
2005-06-15 23:35:11 +00:00
if ( ! empty ( $lesson -> mediafile )) {
// open our pop-up
$url = '/mod/lesson/mediafile.php?id=' . $cm -> id ;
2005-06-16 21:18:37 +00:00
$path_parts = pathinfo ( $lesson -> mediafile );
$name = substr ( $path_parts [ 'basename' ], 0 , strstr ( $path_parts [ 'basename' ], '.' ));
2005-06-15 23:35:11 +00:00
$options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width=' . 650 . ',height=' . 100 ;
echo " \n <script language= \" javascript \" type= \" text/javascript \" > " ;
echo " \n <!-- \n " ;
echo " openpopup(' $url ', ' $name ', ' $options ', 0); " ;
echo " \n --> \n " ;
echo '</script>' ;
}
2004-02-16 05:41:13 +00:00
}
2005-03-05 00:09:39 +00:00
2004-02-26 16:54:47 +00:00
if ( $pageid != LESSON_EOL ) {
2005-02-04 19:39:18 +00:00
/// This is the code updates the lessontime for a timed test
if ( isset ( $_POST [ 'startlastseen' ])) { /// this deletes old records not totally sure if this is necessary anymore
2004-09-24 23:10:49 +00:00
if ( $_POST [ 'startlastseen' ] == 'no' ) {
if ( $grades = get_records_select ( 'lesson_grades' , " lessonid = $lesson->id AND userid = $USER->id " ,
'grade DESC' )) {
$retries = count ( $grades );
} else {
$retries = 0 ;
}
// NoticeFix big fix on the two delete_records
if ( ! delete_records ( 'lesson_attempts' , 'userid' , $USER -> id , 'lessonid' , $lesson -> id , 'retry' , $retries )) {
error ( 'Error: could not delete old attempts' );
}
if ( ! delete_records ( 'lesson_branch' , 'userid' , $USER -> id , 'lessonid' , $lesson -> id , 'retry' , $retries )) {
error ( 'Error: could not delete old seen branches' );
}
}
}
2005-03-05 00:09:39 +00:00
2005-02-04 19:39:18 +00:00
add_to_log ( $course -> id , 'lesson' , 'view' , 'view.php?id=' . $cm -> id , $pageid , $cm -> id );
if ( ! $page = get_record ( 'lesson_pages' , 'id' , $pageid )) {
error ( 'Navigation: the page record not found' );
}
if ( $page -> qtype == LESSON_CLUSTER ) { //this only gets called when a user starts up a new lesson and the first page is a cluster page
2005-03-05 00:09:39 +00:00
if ( ! isteacher ( $course -> id )) {
// get new id
$pageid = lesson_cluster_jump ( $lesson -> id , $USER -> id , $pageid );
// get new page info
if ( ! $page = get_record ( 'lesson_pages' , 'id' , $pageid )) {
error ( 'Navigation: the page record not found' );
}
add_to_log ( $course -> id , 'lesson' , 'view' , 'view.php?id=' . $cm -> id , $pageid , $cm -> id );
2005-02-04 19:39:18 +00:00
} else {
// get the next page
$pageid = $page -> nextpageid ;
if ( ! $page = get_record ( 'lesson_pages' , 'id' , $pageid )) {
error ( 'Navigation: the page record not found' );
}
}
} elseif ( $page -> qtype == LESSON_ENDOFCLUSTER ) {
if ( $page -> nextpageid == 0 ) {
$nextpageid = LESSON_EOL ;
} else {
$nextpageid = $page -> nextpageid ;
}
redirect ( " view.php?id= $cm->id &action=navigation&pageid= $nextpageid " , get_string ( 'endofclustertitle' , 'lesson' ));
}
2005-03-05 00:09:39 +00:00
// start of left menu
if ( $lesson -> displayleft ) {
echo '<table><tr valign="top"><td>' ;
if ( $firstpageid = get_field ( 'lesson_pages' , 'id' , 'lessonid' , $lesson -> id , 'prevpageid' , 0 )) {
// print the pages
echo '<form name="lessonpages2" method="post" action="view.php">' ;
echo '<input type="hidden" name="id" value="' . $cm -> id . '" />' ;
echo '<input type="hidden" name="action" value="navigation" />' ;
echo '<input type="hidden" name="pageid" />' ;
echo " <table><tr><td valign= \" top \" > " ;
echo " <div class= \" leftmenutable \" > " . get_string ( 'lessonmenu' , 'lesson' ) . " <br /> " ;
echo " <div class= \" main \" > " ;
echo " <a href= \" ../../course/view.php?id= $course->id\ " > " .get_string( " mainmenu " , " lesson " ). " </ a >< br /> " ; echo " </ div > " ;
echo '<div class="leftmenu">' ;
lesson_print_tree_menu ( $lesson -> id , $firstpageid , $cm -> id );
echo '</div></div></td></tr></table>' ; //close lmlinks
echo '</form>' ;
}
echo '</td><td align="center" width="100%">' ;
} elseif ( $lesson -> slideshow && $page -> qtype == LESSON_BRANCHTABLE ) {
echo '<table align="center"><tr><td>' ; // only want this if no left menu
}
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
// starts the slideshow div
if ( $lesson -> slideshow && $page -> qtype == LESSON_BRANCHTABLE ) {
echo " <div style= \"
background - color : $lesson -> bgcolor ;
height : " . $lesson->height . " px ;
width : " . $lesson->width . " px ;
overflow : auto ;
border : 0 px solid #ccc;
padding - right : 16 px ; /* for the benefit of macIE5 only */
/* \ commented backslash hack - recover from macIE5 workarounds, it will ignore the following rule */
padding - right : 0 ;
padding : 15 px ;
\ " > \n " ;
2005-02-04 19:39:18 +00:00
echo " <table align= \" center \" width= \" 100% \" border= \" 0 \" ><tr><td> \n " ;
2005-03-05 00:09:39 +00:00
} else {
2005-02-04 19:39:18 +00:00
echo " <table align= \" center \" width= \" 100% \" border= \" 0 \" ><tr><td> \n " ;
2005-03-05 00:09:39 +00:00
$lesson -> slideshow = false ; // turn off slide show for all pages other than LESSON_BRANTCHTABLE
}
2005-02-04 19:39:18 +00:00
2005-03-05 00:09:39 +00:00
// This is where several messages (usually warnings) are displayed
// all of this is displayed above the actual page
2005-06-15 23:35:11 +00:00
if ( ! empty ( $lesson -> mediafile )) {
$url = '/mod/lesson/mediafile.php?id=' . $cm -> id ;
$options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width=' . 650 . ',height=' . 100 ;
2005-06-16 21:18:37 +00:00
$path_parts = pathinfo ( $lesson -> mediafile );
$name = substr ( $path_parts [ 'basename' ], 0 , strstr ( $path_parts [ 'basename' ], '.' ));
2005-06-15 23:35:11 +00:00
echo '<div align="right">' ;
2005-06-16 21:18:37 +00:00
link_to_popup_window ( $url , $name , get_string ( 'mediafilepopup' , 'lesson' ), '' , '' , get_string ( 'mediafilepopup' , 'lesson' ), $options );
2005-06-15 23:35:11 +00:00
helpbutton ( " mediafilestudent " , get_string ( " mediafile " , " lesson " ), " lesson " );
echo '</div>' ;
}
2005-03-05 00:09:39 +00:00
// clock code
// get time information for this user
if ( ! isteacher ( $course -> id )) {
if ( ! $timer = get_records_select ( 'lesson_timer' , " lessonid = $lesson->id AND userid = $USER->id " , 'starttime' )) {
error ( 'Error: could not find records' );
} else {
$timer = array_pop ( $timer ); // this will get the latest start time record
}
}
if ( isset ( $_POST [ 'startlastseen' ])) {
if ( $_POST [ 'startlastseen' ] == 'yes' ) { // continue a previous test, need to update the clock (think this option is disabled atm)
$timer -> starttime = time () - ( $timer -> lessontime - $timer -> starttime );
$timer -> lessontime = time ();
} elseif ( $_POST [ 'startlastseen' ] == 'no' ) { // starting over
// starting over, so reset the clock
$timer -> starttime = time ();
$timer -> lessontime = time ();
}
}
// for timed lessons, display clock
if ( $lesson -> timed ) {
if ( isteacher ( $course -> id )) {
echo '<p align="center">' . get_string ( 'teachertimerwarning' , 'lesson' ) . '<p>' ;
} else {
if ((( $timer -> starttime + $lesson -> maxtime * 60 ) - time ()) > 0 ) {
// code for the clock
print_simple_box_start ( " right " , " 150px " , " #ffffff " , 0 );
echo " <table border= \" 0 \" valign= \" top \" align= \" center \" class= \" generaltable \" width= \" 100% \" cellspacing= \" 0 \" > " .
" <tr><th valign= \" top \" class= \" generaltableheader \" > " . get_string ( " timeremaining " , " lesson " ) .
" </th></tr><tr><td align= \" center \" class= \" generaltablecell \" > " ;
echo " <script language= \" javascript \" > \n " ;
echo " var starttime = " . $timer -> starttime . " ; \n " ;
echo " var servertime = " . time () . " ; \n " ;
echo " var testlength = " . $lesson -> maxtime * 60 . " ; \n " ;
echo " document.write('<SCRIPT LANGUAGE= \" JavaScript \" SRC= \" timer.js \" >< \ /SCRIPT>'); \n " ;
echo " window.onload = function () { show_clock(); } \n " ;
echo " </script> \n " ;
echo " </td></tr></table> " ;
print_simple_box_end ();
echo " <br /><br /><br /> " ;
} else {
redirect ( " view.php?id= $cm->id &action=navigation&pageid= " . LESSON_EOL . " &outoftime=normal " , get_string ( " outoftime " , " lesson " ));
}
// update clock when viewing a new page... no special treatment
if ((( $timer -> starttime + $lesson -> maxtime * 60 ) - time ()) < 60 ) {
echo " <p align= \" center \" > " . get_string ( 'studentoneminwarning' , 'lesson' ) . " </p> " ;
}
if ( $timedflag ) {
print_simple_box ( get_string ( 'maxtimewarning' , 'lesson' , $lesson -> maxtime ), 'center' );
}
}
}
2005-02-25 19:10:17 +00:00
2005-03-05 00:09:39 +00:00
// update the clock
if ( ! isteacher ( $course -> id )) {
$timer -> lessontime = time ();
if ( ! update_record ( 'lesson_timer' , $timer )) {
error ( 'Error: could not update lesson_timer table' );
}
}
if ( $attemptflag ) {
print_heading ( get_string ( 'attempt' , 'lesson' , $retries + 1 ));
}
2005-02-23 00:52:29 +00:00
// before we output everything check to see if the page is a EOB, if so jump directly
2004-03-27 04:15:29 +00:00
// to it's associated branch table
if ( $page -> qtype == LESSON_ENDOFBRANCH ) {
2004-09-24 23:10:49 +00:00
if ( $answers = get_records ( 'lesson_answers' , 'pageid' , $page -> id , 'id' )) {
// print_heading(get_string('endofbranch', 'lesson'));
2004-03-27 04:15:29 +00:00
foreach ( $answers as $answer ) {
// just need the first answer
2004-09-24 23:10:49 +00:00
/// CDC-FLAG 6/21/04 ///
if ( $answer -> jumpto == LESSON_RANDOMBRANCH ) {
$answer -> jumpto = lesson_unseen_branch_jump ( $lesson -> id , $USER -> id );
} elseif ( $answer -> jumpto == LESSON_CLUSTERJUMP ) {
if ( ! isteacher ( $course -> id )) {
$answer -> jumpto = lesson_cluster_jump ( $lesson -> id , $USER -> id , $pageid );
} else {
2005-02-23 00:52:29 +00:00
if ( $page -> nextpageid == 0 ) {
2004-09-24 23:10:49 +00:00
$answer -> jumpto = LESSON_EOL ;
} else {
$answer -> jumpto = $page -> nextpageid ;
}
}
}
/// CDC-FLAG ///
2004-09-16 17:13:57 +00:00
redirect ( " view.php?id= $cm->id &action=navigation&pageid= $answer->jumpto " ,
2004-03-27 04:15:29 +00:00
get_string ( " endofbranch " , " lesson " ));
break ;
2005-02-23 00:52:29 +00:00
}
2004-03-27 04:15:29 +00:00
print_footer ( $course );
exit ();
} else {
2004-09-24 23:10:49 +00:00
error ( 'Navigation: No answers on EOB' );
2004-03-27 04:15:29 +00:00
}
}
2005-03-05 00:09:39 +00:00
/// This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher
if ( isteacher ( $course -> id )) {
if ( execute_teacherwarning ( $lesson -> id )) {
$warningvars -> cluster = get_string ( 'clusterjump' , 'lesson' );
$warningvars -> unseen = get_string ( 'unseenpageinbranch' , 'lesson' );
echo '<p align="center">' . get_string ( 'teacherjumpwarning' , 'lesson' , $warningvars ) . '</p>' ;
}
}
2005-02-04 19:39:18 +00:00
/// this calculates the ongoing score
2004-09-24 23:10:49 +00:00
if ( $lesson -> ongoing && ! empty ( $pageid )) {
if ( isteacher ( $course -> id )) {
2005-02-04 19:39:18 +00:00
echo " <p align= \" center \" > " . get_string ( 'teacherongoingwarning' , 'lesson' ) . '</p>' ;
2004-09-24 23:10:49 +00:00
} else {
2005-03-05 00:09:39 +00:00
$ntries = count_records ( " lesson_grades " , " lessonid " , $lesson -> id , " userid " , $USER -> id );
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
$ntries -- ;
}
lesson_calculate_ongoing_score ( $lesson , $USER -> id , $ntries );
2004-09-24 23:10:49 +00:00
}
}
2005-03-05 00:09:39 +00:00
2004-03-27 04:15:29 +00:00
if ( $page -> qtype == LESSON_BRANCHTABLE ) {
if ( $lesson -> minquestions and isstudent ( $course -> id )) {
// tell student how many questions they have seen, how many are required and their grade
$ntries = count_records ( " lesson_grades " , " lessonid " , $lesson -> id , " userid " , $USER -> id );
2005-02-23 00:52:29 +00:00
$nviewed = count_records ( " lesson_attempts " , " lessonid " , $lesson -> id , " userid " ,
2004-03-27 04:15:29 +00:00
$USER -> id , " retry " , $ntries );
if ( $nviewed ) {
echo " <p align= \" center \" > " . get_string ( " numberofpagesviewed " , " lesson " , $nviewed ) .
" ; ( " . get_string ( " youshouldview " , " lesson " , $lesson -> minquestions ) . " )<br /> " ;
// count the number of distinct correct pages
if ( $correctpages = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id
AND userid = $USER -> id AND retry = $ntries AND correct = 1 " )) {
foreach ( $correctpages as $correctpage ) {
$temp [ $correctpage -> pageid ] = 1 ;
}
$ncorrect = count ( $temp );
} else {
$nccorrect = 0 ;
}
if ( $nviewed < $lesson -> minquestions ) {
$nviewed = $lesson -> minquestions ;
}
echo get_string ( " numberofcorrectanswers " , " lesson " , $ncorrect ) . " <br /> \n " ;
$thegrade = intval ( 100 * $ncorrect / $nviewed );
2005-02-23 00:52:29 +00:00
echo get_string ( " yourcurrentgradeis " , " lesson " ,
2004-03-27 04:15:29 +00:00
number_format ( $thegrade * $lesson -> grade / 100 , 1 )) .
" ( " . get_string ( " outof " , " lesson " , $lesson -> grade ) . " )</p> \n " ;
}
}
}
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
// now starting to print the page's contents
echo " <div align= \" center \" > " ;
2005-02-04 19:39:18 +00:00
echo " <em><strong> " ;
2005-04-24 16:46:51 +00:00
echo format_string ( $lesson -> name ) . " </strong></em> " ;
2004-09-24 23:10:49 +00:00
if ( $page -> qtype == LESSON_BRANCHTABLE ) {
2005-02-04 19:39:18 +00:00
echo " :<br /> " ;
2005-04-26 22:30:40 +00:00
print_heading ( format_string ( $page -> title ));
2004-09-24 23:10:49 +00:00
}
2005-02-04 19:39:18 +00:00
echo " </div><br /> " ;
2005-02-23 00:52:29 +00:00
2005-09-28 21:55:05 +00:00
if ( ! $lesson -> slideshow ) {
2005-06-16 17:41:12 +00:00
print_simple_box ( format_text ( $page -> contents ), 'center' );
2004-09-24 23:10:49 +00:00
}
2004-02-16 05:41:13 +00:00
echo " <br /> \n " ;
2005-03-05 00:09:39 +00:00
// this is for modattempts option. Find the users previous answer to this page,
// and then display it below in answer processing
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
$retries = count_records ( 'lesson_grades' , " lessonid " , $lesson -> id , " userid " , $USER -> id );
$retries -- ;
if ( ! $attempts = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries " , " timeseen " )) {
error ( " Previous attempt record could not be found! " );
}
$attempt = end ( $attempts );
}
2004-04-01 16:56:56 +00:00
// get the answers in a set order, the id order
2004-02-26 16:54:47 +00:00
if ( $answers = get_records ( " lesson_answers " , " pageid " , $page -> id , " id " )) {
echo " <form name= \" answerform \" method = \" post \" action= \" lesson.php \" > " ;
2004-11-04 09:24:51 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> " ;
echo " <input type= \" hidden \" name= \" action \" value= \" continue \" /> " ;
echo " <input type= \" hidden \" name= \" pageid \" value= \" $pageid\ " /> " ;
2005-03-05 00:09:39 +00:00
echo " <input type= \" hidden \" name= \" sesskey \" value= \" " . $USER -> sesskey . " \" /> " ;
2005-02-04 19:39:18 +00:00
if ( ! $lesson -> slideshow ) {
2005-09-28 21:55:05 +00:00
if ( $page -> qtype != LESSON_BRANCHTABLE ) {
print_simple_box_start ( " center " );
}
2005-03-05 00:09:39 +00:00
echo '<table width="100%">' ;
2004-09-24 23:10:49 +00:00
}
2004-02-26 16:54:47 +00:00
switch ( $page -> qtype ) {
case LESSON_SHORTANSWER :
case LESSON_NUMERICAL :
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
$value = " value= \" $attempt->useranswer\ " " ;
} else {
$value = " " ;
}
2004-02-26 16:54:47 +00:00
echo " <tr><td align= \" center \" > " . get_string ( " youranswer " , " lesson " ) .
2004-11-04 09:24:51 +00:00
" : <label for= \" answer \" class= \" hidden-label \" >Answer</label><input type= \" text \" id= \" answer \" name= \" answer \" size= \" 50 \" maxlength= \" 200 \" $value /> \n " ; //CDC hidden label added.
2004-02-26 16:54:47 +00:00
echo '</table>' ;
print_simple_box_end ();
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleaseenteryouranswerinthebox " , " lesson " ) . " </a></div></p> \n " ;
2004-02-26 16:54:47 +00:00
break ;
case LESSON_TRUEFALSE :
shuffle ( $answers );
foreach ( $answers as $answer ) {
2004-09-15 20:32:24 +00:00
echo " <tr><td valign= \" top \" > " ;
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ]) && $answer -> id == $attempt -> answerid ) {
$checked = " checked= \" checked \" " ;
} else {
$checked = " " ;
}
2004-11-04 09:24:51 +00:00
echo " <label for= \" answerid \" class= \" hidden-label \" >Answer ID</label><input type= \" radio \" id= \" answerid \" name= \" answerid \" value= \" { $answer -> id } \" $checked /> " ; //CDC hidden label added.
2004-09-24 23:10:49 +00:00
echo " </td><td> " ;
2004-02-26 16:54:47 +00:00
$options -> para = false ; // no <p></p>
2004-08-04 18:13:09 +00:00
echo format_text ( trim ( $answer -> answer ), FORMAT_MOODLE , $options );
2004-02-26 16:54:47 +00:00
echo " </td></tr> " ;
2004-09-24 23:10:49 +00:00
if ( $answer != end ( $answers )) {
2005-03-05 00:09:39 +00:00
echo " <tr><td><br></td></tr> " ;
2005-02-23 00:52:29 +00:00
}
2004-02-26 16:54:47 +00:00
}
echo '</table>' ;
print_simple_box_end ();
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleasecheckoneanswer " , " lesson " ) . " </a></div> \n " ;
2004-02-26 16:54:47 +00:00
break ;
case LESSON_MULTICHOICE :
$i = 0 ;
shuffle ( $answers );
foreach ( $answers as $answer ) {
2004-09-15 20:32:24 +00:00
echo " <tr><td valign= \" top \" > " ;
2004-02-26 16:54:47 +00:00
if ( $page -> qoption ) {
2005-03-05 00:09:39 +00:00
$checked = " " ;
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
$answerids = explode ( " , " , $attempt -> useranswer );
if ( in_array ( $answer -> id , $answerids )) {
$checked = " checked= \" checked \" " ;
} else {
$checked = " " ;
}
}
2005-02-23 00:52:29 +00:00
// more than one answer allowed
2004-11-04 09:24:51 +00:00
echo " <label for= \" answer[ $i ] \" class= \" hidden-label \" >answer[ $i ]</label><input type= \" checkbox \" id= \" answer[ $i ] \" name= \" answer[ $i ] \" value= \" { $answer -> id } \" $checked /> " ; //CDC hidden label added.
2004-02-26 16:54:47 +00:00
} else {
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ]) && $answer -> id == $attempt -> answerid ) {
$checked = " checked= \" checked \" " ;
} else {
$checked = " " ;
}
2004-02-26 16:54:47 +00:00
// only one answer allowed
2004-11-04 09:24:51 +00:00
echo " <label for= \" answerid \" class= \" hidden-label \" >answer id</label><input type= \" radio \" id= \" answerid \" name= \" answerid \" value= \" { $answer -> id } \" $checked /> " ; //CDC hidden label added.
2004-02-26 16:54:47 +00:00
}
echo " </td><td> " ;
2005-09-28 21:55:05 +00:00
$options = new stdClass ;
2004-02-26 16:54:47 +00:00
$options -> para = false ; // no <p></p>
2005-02-23 00:52:29 +00:00
echo format_text ( trim ( $answer -> answer ), FORMAT_MOODLE , $options );
2004-02-26 16:54:47 +00:00
echo " </td></tr> " ;
2004-09-24 23:10:49 +00:00
if ( $answer != end ( $answers )) {
2005-03-05 00:09:39 +00:00
echo " <tr><td><br></td></tr> " ;
2005-02-23 00:52:29 +00:00
}
2004-02-26 16:54:47 +00:00
$i ++ ;
}
echo '</table>' ;
print_simple_box_end ();
2005-03-05 00:09:39 +00:00
if ( $page -> qoption ) {
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleasecheckoneormoreanswers " , " lesson " ) . " </a></div> \n " ;
2005-03-05 00:09:39 +00:00
} else {
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleasecheckoneanswer " , " lesson " ) . " </a></div> \n " ;
2005-03-05 00:09:39 +00:00
}
2004-02-26 16:54:47 +00:00
break ;
2005-02-23 00:52:29 +00:00
/// CDC-FLAG /// 6/14/04 --- changed how matching works
2004-02-26 16:54:47 +00:00
case LESSON_MATCHING :
echo " <tr><td><table width= \" 100% \" > " ;
// don't suffle answers (could be an option??)
foreach ( $answers as $answer ) {
2004-09-15 20:32:24 +00:00
// get all the response
2004-09-24 23:10:49 +00:00
if ( $answer -> response != NULL ) {
$responses [] = trim ( $answer -> response );
}
2004-02-26 16:54:47 +00:00
}
shuffle ( $responses );
2004-11-01 20:41:55 +00:00
$responses = array_unique ( $responses );
2005-04-26 20:37:34 +00:00
2004-11-01 20:41:55 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
2005-03-05 00:09:39 +00:00
$useranswers = explode ( " , " , $attempt -> useranswer );
$t = 0 ;
}
2004-02-26 16:54:47 +00:00
foreach ( $answers as $answer ) {
2004-09-24 23:10:49 +00:00
if ( $answer -> response != NULL ) {
echo " <tr><td align= \" right \" > " ;
2005-04-29 18:32:13 +00:00
$options -> para = false ;
echo " <b> " . format_text ( $answer -> answer , FORMAT_MOODLE , $options ) . " : </b></td><td valign= \" bottom \" > " ;
2004-09-24 23:10:49 +00:00
echo " <label for= \" response[ $answer->id ] \" class= \" hidden-label \" >response[ $answer->id ]</label><select id= \" response[ $answer->id ] \" name= \" response[ $answer->id ] \" > " ; //CDC hidden label added.
2004-11-01 20:41:55 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
2005-03-05 00:09:39 +00:00
$selected = trim ( $answers [ $useranswers [ $t ]] -> response );
2005-04-26 20:37:34 +00:00
echo " <option value= \" " . htmlspecialchars ( $response ) . " \" selected= \" selected \" > $selected </option> " ;
2005-03-05 00:09:39 +00:00
foreach ( $responses as $response ) {
if ( trim ( $answers [ $useranswers [ $t ]] -> response ) != $response ) {
2005-04-26 20:37:34 +00:00
echo " <option value= \" " . htmlspecialchars ( $response ) . " \" > $response </option> " ;
2005-03-05 00:09:39 +00:00
}
}
$t ++ ;
} else {
echo " <option value= \" 0 \" selected= \" selected \" >Choose...</option> " ;
foreach ( $responses as $response ) {
2005-04-26 20:37:34 +00:00
echo " <option value= \" " . htmlspecialchars ( $response ) . " \" > $response </option> " ;
2005-03-05 00:09:39 +00:00
}
}
2004-09-24 23:10:49 +00:00
echo " </select> " ;
echo " </td></tr> " ;
if ( $answer != end ( $answers )) {
2005-03-05 00:09:39 +00:00
echo " <tr><td><br></td></tr> " ;
2005-02-23 00:52:29 +00:00
}
2004-09-24 23:10:49 +00:00
}
}
2004-02-26 16:54:47 +00:00
echo '</table></table>' ;
print_simple_box_end ();
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleasematchtheabovepairs " , " lesson " ) . " </a></div> \n " ;
2004-02-26 16:54:47 +00:00
break ;
2005-09-28 21:55:05 +00:00
case LESSON_BRANCHTABLE :
$options = new stdClass ;
$options -> para = false ;
$buttons = array ( 'next' => '' , 'prev' => '' , 'other' => array ());
2005-03-05 00:09:39 +00:00
// seperate out next and previous jumps from the other jumps
foreach ( $answers as $answer ) {
2005-09-28 21:55:05 +00:00
if ( $answer -> jumpto == LESSON_NEXTPAGE ) {
$buttons [ 'next' ] = '<div class="lessonbutton nextbutton"><a href="javascript:document.answerform.jumpto.value=' . $answer -> jumpto . ';document.answerform.submit();">' .
strip_tags ( format_text ( $answer -> answer , FORMAT_MOODLE , $options )) . '</a></div>' ;
} else if ( $answer -> jumpto == LESSON_PREVIOUSPAGE ) {
$buttons [ 'prev' ] = '<div class="lessonbutton previousbutton"><a href="javascript:document.answerform.jumpto.value=' . $answer -> jumpto . ';document.answerform.submit();">' .
strip_tags ( format_text ( $answer -> answer , FORMAT_MOODLE , $options )) . '</a></div>' ;
2005-03-05 00:09:39 +00:00
} else {
2005-09-28 21:55:05 +00:00
$buttons [ 'other' ][] = '<div class="lessonbutton standardbutton"><a href="javascript:document.answerform.jumpto.value=' . $answer -> jumpto . ';document.answerform.submit();">' .
strip_tags ( format_text ( $answer -> answer , FORMAT_MOODLE , $options )) . '</a></div>' ;
2005-03-05 00:09:39 +00:00
}
}
2005-09-28 21:55:05 +00:00
if ( $lesson -> slideshow ) {
$px = $lesson -> width - 30 ; // give us some breathing room
$width = ' width="' . $px . 'px"' ;
} else {
$width = ' width="100%"' ;
}
$fullbuttonhtml = '<div class="branchbuttoncontainer">' . " \n " ;
2005-03-05 00:09:39 +00:00
if ( $page -> layout ) {
2005-09-28 21:55:05 +00:00
// tried to do this with CSS, but couldnt get it to work in MacIE browser. Using tables instead :(
// don't care if empty or not because we want to keep the table structure
$fullbuttonhtml .= '<table ' . $width . ' align="center"><tr><td align="left" width="20%">' . $buttons [ 'prev' ] . " </td> \n " ;
$fullbuttonhtml .= '<td><table align="center"><tr><td>' . implode ( " </td> \n <td> " , $buttons [ 'other' ]) . " </td></tr></table></td> \n " ;
$fullbuttonhtml .= '<td align="right" width="20%">' . $buttons [ 'next' ] . " </td></tr></table> \n " ;
} else {
// care about emptyness here
$temparray = array ();
if ( ! empty ( $buttons [ 'next' ])) {
$temparray [] = $buttons [ 'next' ];
2005-03-05 00:09:39 +00:00
}
2005-09-28 21:55:05 +00:00
if ( ! empty ( $buttons [ 'other' ])) {
$temparray = array_merge ( $temparray , $buttons [ 'other' ]);
2005-03-05 00:09:39 +00:00
}
2005-09-28 21:55:05 +00:00
if ( ! empty ( $buttons [ 'prev' ])) {
$temparray [] = $buttons [ 'prev' ];
2005-03-05 00:09:39 +00:00
}
2005-09-28 21:55:05 +00:00
$fullbuttonhtml .= '<table align="center" cellpadding="3px"><tr><td align="center">' .
implode ( " </td></tr> \n <tr><td align= \" center \" > " , $temparray ) .
" </td></tr></table> \n " ;
}
$fullbuttonhtml .= " </div> \n " ;
if ( $lesson -> slideshow ) {
echo $fullbuttonhtml . '<br />' ;
echo format_text ( $page -> contents );
echo " </table></div><table cellpadding= \" 5 \" cellspacing= \" 5 \" align= \" center \" > " ;
2005-03-05 00:09:39 +00:00
} else {
2005-09-28 21:55:05 +00:00
echo " <tr><td><table width= \" 100% \" > " ;
2005-03-05 00:09:39 +00:00
}
2005-09-28 21:55:05 +00:00
echo " <input type= \" hidden \" name= \" jumpto \" /> " ;
2005-03-05 00:09:39 +00:00
2005-02-04 19:39:18 +00:00
if ( ! $lesson -> slideshow ) {
2005-09-28 21:55:05 +00:00
if ( ! empty ( $buttons [ 'next' ]) or ! empty ( $buttons [ 'prev' ])) {
print_simple_box_start ( " center " , '100%' );
} else {
print_simple_box_start ( " center " );
}
echo $fullbuttonhtml ;
2005-03-05 00:09:39 +00:00
echo '</table></table>' ;
print_simple_box_end ();
2005-09-28 21:55:05 +00:00
} else {
echo $fullbuttonhtml ;
2005-03-05 00:09:39 +00:00
}
2004-09-24 23:10:49 +00:00
break ;
case LESSON_ESSAY :
2004-11-01 20:41:55 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
2005-03-05 00:09:39 +00:00
$essayinfo = unserialize ( $attempt -> useranswer );
$value = $essayinfo -> answer ;
} else {
$value = " " ;
}
2004-09-24 23:10:49 +00:00
echo " <tr><td align= \" center \" valign= \" top \" nowrap> " . get_string ( " youranswer " , " lesson " ) . " :</td><td> " .
2004-11-01 20:41:55 +00:00
" <label for= \" answer \" class= \" hidden-label \" >Answer</label><textarea id= \" answer \" name= \" answer \" rows= \" 15 \" cols= \" 60 \" > $value </textarea> \n " ; //CDC hidden label added.
2004-09-24 23:10:49 +00:00
echo " </td></tr></table> " ;
2004-03-27 04:15:29 +00:00
print_simple_box_end ();
2005-09-28 21:55:05 +00:00
echo " <div align= \" center \" class= \" lessonbutton standardbutton \" ><a href= \" javascript:document.answerform.submit(); \" > " .
get_string ( " pleaseenteryouranswerinthebox " , " lesson " ) . " </a></div> \n " ;
2004-03-27 04:15:29 +00:00
break ;
2004-02-16 05:41:13 +00:00
}
2005-03-05 00:09:39 +00:00
echo " </form> \n " ;
2004-02-16 05:41:13 +00:00
} else {
// a page without answers - find the next (logical) page
2004-02-17 00:54:10 +00:00
echo " <form name= \" pageform \" method = \" post \" action= \" view.php \" > \n " ;
2004-11-04 09:24:51 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> \n " ;
echo " <input type= \" hidden \" name= \" action \" value= \" navigation \" /> \n " ;
2004-04-01 16:56:56 +00:00
if ( $lesson -> nextpagedefault ) {
// in Flash Card mode...
// ...first get number of retakes
2005-02-23 00:52:29 +00:00
$nretakes = count_records ( " lesson_grades " , " lessonid " , $lesson -> id , " userid " , $USER -> id );
2004-04-01 16:56:56 +00:00
// ...then get the page ids (lessonid the 5th param is needed to make get_records play)
$allpages = get_records ( " lesson_pages " , " lessonid " , $lesson -> id , " id " , " id,lessonid " );
shuffle ( $allpages );
$found = false ;
if ( $lesson -> nextpagedefault == LESSON_UNSEENPAGE ) {
foreach ( $allpages as $thispage ) {
2005-02-23 00:52:29 +00:00
if ( ! count_records ( " lesson_attempts " , " pageid " , $thispage -> id , " userid " ,
2004-04-01 16:56:56 +00:00
$USER -> id , " retry " , $nretakes )) {
$found = true ;
break ;
}
}
} elseif ( $lesson -> nextpagedefault == LESSON_UNANSWEREDPAGE ) {
foreach ( $allpages as $thispage ) {
if ( ! count_records_select ( " lesson_attempts " , " pageid = $thispage->id AND
userid = $USER -> id AND correct = 1 AND retry = $nretakes " )) {
$found = true ;
break ;
}
}
}
if ( $found ) {
$newpageid = $thispage -> id ;
if ( $lesson -> maxpages ) {
// check number of pages viewed (in the lesson)
if ( count_records ( " lesson_attempts " , " lessonid " , $lesson -> id , " userid " , $USER -> id ,
" retry " , $nretakes ) >= $lesson -> maxpages ) {
$newpageid = LESSON_EOL ;
}
}
} else {
$newpageid = LESSON_EOL ;
}
} else {
// in normal lesson mode...
if ( ! $newpageid = get_field ( " lesson_pages " , " nextpageid " , " id " , $pageid )) {
// this is the last page - flag end of lesson
2004-04-02 15:54:07 +00:00
$newpageid = LESSON_EOL ;
2004-04-01 16:56:56 +00:00
}
2004-02-16 05:41:13 +00:00
}
2004-11-04 09:24:51 +00:00
echo " <input type= \" hidden \" name= \" pageid \" value= \" $newpageid\ " /> \n " ;
2004-09-24 23:10:49 +00:00
echo " <p align= \" center \" ><input type= \" submit \" name= \" continue \" value= \" " .
2004-11-04 09:24:51 +00:00
get_string ( " continue " , " lesson " ) . " \" /></p> \n " ;
2004-02-17 00:54:10 +00:00
echo " </form> \n " ;
2004-02-16 05:41:13 +00:00
}
2005-02-23 00:52:29 +00:00
echo " </table> \n " ;
2004-02-16 05:41:13 +00:00
} else {
// end of lesson reached work out grade
2004-09-24 23:10:49 +00:00
/// CDC-FLAG ///
2004-11-01 20:41:55 +00:00
if ( $lesson -> timed && ! isteacher ( $course -> id )) {
2004-09-24 23:10:49 +00:00
if ( isset ( $_GET [ " outoftime " ])) {
if ( $_GET [ " outoftime " ] == " normal " ) {
print_simple_box ( get_string ( " eolstudentoutoftime " , " lesson " ), " center " );
}
}
}
2005-04-26 21:24:06 +00:00
2005-03-05 00:09:39 +00:00
// Update the clock / get time information for this user
if ( ! isteacher ( $course -> id )) {
unset ( $USER -> startlesson [ $lesson -> id ]);
if ( ! $timer = get_records_select ( 'lesson_timer' , " lessonid = $lesson->id AND userid = $USER->id " , 'starttime' )) {
error ( 'Error: could not find records' );
} else {
$timer = array_pop ( $timer ); // this will get the latest start time record
}
$timer -> lessontime = time ();
if ( ! update_record ( " lesson_timer " , $timer )) {
error ( " Error: could not update lesson_timer table " );
}
}
2004-02-16 12:20:40 +00:00
add_to_log ( $course -> id , " lesson " , " end " , " view.php?id= $cm->id " , " $lesson->id " , $cm -> id );
2004-02-16 05:41:13 +00:00
print_heading ( get_string ( " congratulations " , " lesson " ));
print_simple_box_start ( " center " );
$ntries = count_records ( " lesson_grades " , " lessonid " , $lesson -> id , " userid " , $USER -> id );
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) {
$ntries -- ; // need to look at the old attempts :)
}
2004-02-16 05:41:13 +00:00
if ( isstudent ( $course -> id )) {
2005-02-23 00:52:29 +00:00
if ( $nviewed = count_records ( " lesson_attempts " , " lessonid " , $lesson -> id , " userid " ,
2004-03-27 04:15:29 +00:00
$USER -> id , " retry " , $ntries )) {
2004-09-24 23:10:49 +00:00
/// CDC-FLAG /// 6/11/04
if ( ! $lesson -> custom ) {
2005-03-05 00:09:39 +00:00
$ncorrect = 0 ;
$temp = array ();
2005-02-23 00:52:29 +00:00
if ( $pagesanswered = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND
2004-09-24 23:10:49 +00:00
userid = $USER -> id AND retry = $ntries order by timeseen " )) {
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
foreach ( $pagesanswered as $pageanswered ) {
2005-02-09 22:31:36 +00:00
if ( ! array_key_exists ( $pageanswered -> pageid , $temp )) {
2004-09-24 23:10:49 +00:00
$temp [ $pageanswered -> pageid ] = array ( $pageanswered -> correct , 1 );
} else {
if ( $temp [ $pageanswered -> pageid ][ 1 ] < $lesson -> maxattempts ) {
$n = $temp [ $pageanswered -> pageid ][ 1 ] + 1 ;
$temp [ $pageanswered -> pageid ] = array ( $pageanswered -> correct , $n );
}
}
}
foreach ( $temp as $value => $key ) {
if ( $key [ 0 ] == 1 ) {
$ncorrect += 1 ;
}
}
}
$nviewed = count ( $temp ); // this counts number of Questions the user viewed
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
echo " <p align= \" center \" > " . get_string ( " numberofpagesviewed " , " lesson " , $nviewed ) .
" </p> \n " ;
if ( $lesson -> minquestions ) {
if ( $nviewed < $lesson -> minquestions ) {
// print a warning and set nviewed to minquestions
2005-02-23 00:52:29 +00:00
echo " <p align= \" center \" > " . get_string ( " youshouldview " , " lesson " ,
2004-09-24 23:10:49 +00:00
$lesson -> minquestions ) . " " . get_string ( " pages " , " lesson " ) . " </p> \n " ;
$nviewed = $lesson -> minquestions ;
}
}
echo " <p align= \" center \" > " . get_string ( " numberofcorrectanswers " , " lesson " , $ncorrect ) .
" </p> \n " ;
2005-06-09 21:24:17 +00:00
$thegrade = round ( 100 * $ncorrect / $nviewed , 5 );
2005-02-23 00:52:29 +00:00
echo " <p align= \" center \" > " . get_string ( " gradeis " , " lesson " ,
2004-09-24 23:10:49 +00:00
number_format ( $thegrade * $lesson -> grade / 100 , 1 )) .
" ( " . get_string ( " outof " , " lesson " , $lesson -> grade ) . " )</p> \n " ;
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
} else {
$score = 0 ;
2004-11-17 01:02:14 +00:00
$essayquestions = 0 ;
2005-03-05 00:09:39 +00:00
$essayquestionpoints = 0 ;
2004-11-17 01:02:14 +00:00
2005-02-23 00:52:29 +00:00
if ( $useranswers = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND
2004-09-24 23:10:49 +00:00
userid = $USER -> id AND retry = $ntries " , " timeseen " )) {
2005-03-05 00:09:39 +00:00
// group each try with its page
2004-09-24 23:10:49 +00:00
foreach ( $useranswers as $useranswer ) {
2005-03-05 00:09:39 +00:00
$attemptset [ $useranswer -> pageid ][] = $useranswer ;
}
$pageids = array_keys ( $attemptset );
$pageids = implode ( " , " , $pageids );
// get only the pages and their answers that the user answered
$answeredpages = get_records_select ( " lesson_pages " , " lessonid = $lesson->id AND id IN( $pageids ) " );
$pageanswers = get_records_select ( " lesson_answers " , " lessonid = $lesson->id AND pageid IN( $pageids ) " );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
foreach ( $attemptset as $attempts ) {
if ( count ( $attempts ) > $lesson -> maxattempts ) { // if there are more tries than the max that is allowed, grab the last "legal" attempt
$attempt = $attempts [ $lesson -> maxattempts - 1 ];
} else {
// else, user attempted the question less than the max, so grab the last one
$attempt = end ( $attempts );
}
// if essay question, handle it, otherwise add to score
if ( $answeredpages [ $attempt -> pageid ] -> qtype == LESSON_ESSAY ) {
$essayinfo = unserialize ( $attempt -> useranswer );
$score += $essayinfo -> score ;
$essayquestions ++ ;
$essayquestionpoints += $pageanswers [ $attempt -> answerid ] -> score ;
} else {
2005-08-29 22:04:13 +00:00
if ( array_key_exists ( $attempt -> answerid , $pageanswers )) {
$score += $pageanswers [ $attempt -> answerid ] -> score ;
}
2005-03-05 00:09:39 +00:00
}
}
$bestscores = array ();
// find the highest possible score per page
foreach ( $pageanswers as $pageanswer ) {
if ( isset ( $bestscores [ $pageanswer -> pageid ])) {
if ( $bestscores [ $pageanswer -> pageid ] < $pageanswer -> score ) {
$bestscores [ $pageanswer -> pageid ] = $pageanswer -> score ;
}
} else {
$bestscores [ $pageanswer -> pageid ] = $pageanswer -> score ;
}
}
$bestscore = array_sum ( $bestscores );
}
2005-06-09 21:24:17 +00:00
$thegrade = round ( 100 * $score / $bestscore , 5 );
2005-02-09 22:31:36 +00:00
$a = new stdClass ;
2004-09-24 23:10:49 +00:00
if ( $essayquestions > 0 ) {
$a -> score = $score ;
2004-11-17 01:02:14 +00:00
$a -> tempmaxgrade = $bestscore - $essayquestionpoints ;
2004-09-24 23:10:49 +00:00
$a -> essayquestions = $essayquestions ;
2004-11-17 01:02:14 +00:00
$a -> grade = $bestscore ;
echo " <div align= \" center \" > " . get_string ( " displayscorewithessays " , " lesson " , $a ) . " </div> " ;
2004-09-24 23:10:49 +00:00
} else {
$a -> score = $score ;
2004-11-17 01:02:14 +00:00
$a -> grade = $bestscore ;
2005-03-05 00:09:39 +00:00
echo " <div align= \" center \" > " . get_string ( " displayscorewithoutessays " , " lesson " , $a ) . " </div> " ;
2004-09-24 23:10:49 +00:00
}
2005-03-05 00:09:39 +00:00
echo " <p align= \" center \" > " . get_string ( " gradeis " , " lesson " ,
2004-11-17 01:02:14 +00:00
number_format ( $thegrade * $lesson -> grade / 100 , 1 )) .
" ( " . get_string ( " outof " , " lesson " , $lesson -> grade ) . " )</p> \n " ;
2004-09-24 23:10:49 +00:00
}
2005-03-05 00:09:39 +00:00
/// CDC-FLAG ///
2004-09-24 23:10:49 +00:00
$grade -> lessonid = $lesson -> id ;
$grade -> userid = $USER -> id ;
$grade -> grade = $thegrade ;
$grade -> completed = time ();
if ( ! $lesson -> practice ) {
2005-03-05 00:09:39 +00:00
if ( isset ( $USER -> modattempts [ $lesson -> id ])) { // if reviewing, make sure update old grade record
if ( ! $grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id and userid = $USER->id " , " completed " )) {
error ( " Could not find Grade Records " );
}
$oldgrade = end ( $grades );
$grade -> id = $oldgrade -> id ;
if ( ! $update = update_record ( " lesson_grades " , $grade )) {
error ( " Navigation: grade not updated " );
}
} else {
if ( ! $newgradeid = insert_record ( " lesson_grades " , $grade )) {
error ( " Navigation: grade not inserted " );
}
}
2004-09-24 23:10:49 +00:00
} else {
if ( ! delete_records ( " lesson_attempts " , " lessonid " , $lesson -> id , " userid " , $USER -> id , " retry " , $ntries )) {
error ( " Could not delete lesson attempts " );
}
}
2004-02-16 05:41:13 +00:00
} else {
2004-09-24 23:10:49 +00:00
if ( $lesson -> timed ) {
if ( isset ( $_GET [ " outoftime " ])) {
if ( $_GET [ " outoftime " ] == " normal " ) {
2005-03-05 00:09:39 +00:00
$grade = new stdClass ;
2004-09-24 23:10:49 +00:00
$grade -> lessonid = $lesson -> id ;
$grade -> userid = $USER -> id ;
$grade -> grade = 0 ;
$grade -> completed = time ();
if ( ! $lesson -> practice ) {
if ( ! $newgradeid = insert_record ( " lesson_grades " , $grade )) {
error ( " Navigation: grade not inserted " );
}
}
echo get_string ( " eolstudentoutoftimenoanswers " , " lesson " );
}
}
} else {
echo get_string ( " welldone " , " lesson " );
}
2005-02-23 00:52:29 +00:00
}
} else {
2004-02-16 05:41:13 +00:00
// display for teacher
echo " <p align= \" center \" > " . get_string ( " displayofgrade " , " lesson " ) . " </p> \n " ;
}
2004-09-15 20:32:24 +00:00
print_simple_box_end (); //End of Lesson button to Continue.
2005-04-05 22:42:34 +00:00
// after all the grade processing, check to see if "Show Grades" is off for the course
// if yes, redirect to the course page
if ( ! $course -> showgrades ) {
2005-05-16 22:41:19 +00:00
redirect ( $CFG -> wwwroot . '/course/view.php?id=' . $course -> id );
2005-04-05 22:42:34 +00:00
}
2004-09-24 23:10:49 +00:00
///CDC-FLAG /// high scores code
2005-05-06 23:57:20 +00:00
if ( $lesson -> highscores && ! isteacher ( $course -> id ) && ! $lesson -> practice ) {
2004-09-24 23:10:49 +00:00
echo " <div align= \" center \" ><br> " ;
if ( ! $grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id " , " completed " )) {
echo get_string ( " youmadehighscore " , " lesson " , $lesson -> maxhighscores ) . " <br> " ;
2004-11-04 09:24:51 +00:00
echo " <a href= \" view.php?id= $cm->id &action=nameforhighscores \" > " . get_string ( " clicktopost " , " lesson " ) . " </a><br> " ;
2004-09-24 23:10:49 +00:00
} else {
if ( ! $highscores = get_records_select ( " lesson_high_scores " , " lessonid = $lesson->id " )) {
echo get_string ( " youmadehighscore " , " lesson " , $lesson -> maxhighsores ) . " <br> " ;
2004-11-04 09:24:51 +00:00
echo " <a href= \" view.php?id= $cm->id &action=nameforhighscores \" > " . get_string ( " clicktopost " , " lesson " ) . " </a><br> " ;
2004-09-24 23:10:49 +00:00
} else {
// get all the high scores into an array
foreach ( $highscores as $highscore ) {
$grade = $grades [ $highscore -> gradeid ] -> grade ;
$topscores [] = $grade ;
}
// sort to find the lowest score
sort ( $topscores );
$lowscore = $topscores [ 0 ];
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
if ( $thegrade >= $lowscore || count ( $topscores ) <= $lesson -> maxhighscores ) {
echo get_string ( " youmadehighscore " , " lesson " , $lesson -> maxhighscores ) . " <br> " ;
2004-11-04 09:24:51 +00:00
echo " <a href= \" view.php?id= $cm->id &action=nameforhighscores \" > " . get_string ( " clicktopost " , " lesson " ) . " </a><br> " ;
2004-09-24 23:10:49 +00:00
} else {
echo get_string ( " nothighscore " , " lesson " , $lesson -> maxhighscores ) . " <br> " ;
}
}
}
2004-11-04 09:24:51 +00:00
echo " <br><a href= \" view.php?id= $cm->id &action=highscores&link=1 \" > " . get_string ( " viewhighscores " , " lesson " ) . " </a> " ;
2005-03-05 00:09:39 +00:00
echo " </div> " ;
}
/// CDC-FLAG ///
if ( $lesson -> modattempts && ! isteacher ( $course -> id )) {
// make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
// look at the attempt records to find the first QUESTION page that the user answered, then use that page id
// to pass to view again. This is slick cause it wont call the empty($pageid) code
// $ntries is decremented above
2005-06-29 18:08:37 +00:00
if ( ! $attempts = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries " , " timeseen " )) {
$attempts = array ();
}
2005-03-05 00:09:39 +00:00
$firstattempt = current ( $attempts );
$pageid = $firstattempt -> pageid ;
// IF the student wishes to review, need to know the last question page that the student answered. This will help to make
// sure that the student can leave the lesson via pushing the continue button.
$lastattempt = end ( $attempts );
$USER -> modattempts [ $lesson -> id ] = $lastattempt -> pageid ;
echo " <form name= \" reviewform \" method= \" post \" action= \" view.php?id= $cm->id\ " > " ;
echo " <input type= \" hidden \" name= \" pageid \" value= \" $pageid\ " /> " ;
echo " </form> " ;
echo " <p align= \" center \" ><a href= \" javascript:document.reviewform.submit(); \" > " . get_string ( " reviewlesson " , " lesson " ) . " </a></p> \n " ;
} elseif ( $lesson -> modattempts && isteacher ( $course -> id )) {
echo " <p align= \" center \" > " . get_string ( " modattemptsnoteacher " , " lesson " ) . " </p> " ;
2004-09-24 23:10:49 +00:00
}
echo " <p align= \" center \" ><a href= \" ../../course/view.php?id= $course->id\ " > " .get_string( " mainmenu " , " lesson " ). " </ a ></ p > \n " ; //CDC Back to the menu (course view).
2005-06-06 17:23:35 +00:00
echo " <p align= \" center \" ><a href= \" ../../grade/index.php?id= $course->id\ " > " .get_string( " viewgrades " , " lesson " ). " </ a ></ p > \n " ; //CDC view grades
2004-09-24 23:10:49 +00:00
}
2004-09-15 20:32:24 +00:00
2005-02-04 19:39:18 +00:00
if ( $lesson -> displayleft || $lesson -> slideshow ) { // this ends the table cell and table for the leftmenu or for slideshow
2005-03-05 00:09:39 +00:00
echo " </td></tr></table> " ;
2005-02-23 00:52:29 +00:00
}
2004-02-16 05:41:13 +00:00
}
/*******************teacher view **************************************/
elseif ( $action == 'teacherview' ) {
2005-05-03 22:26:01 +00:00
/// CDC-FLAG /// link to grade essay questions and to report
if ( $userattempts = get_records ( " lesson_attempts " , " lessonid " , $lesson -> id )) { // just check to see if anyone has answered any questions.
2005-05-16 22:41:19 +00:00
$usercount = array ();
foreach ( $userattempts as $userattempts ) {
$usercount [ $userattempts -> userid ] = 0 ;
}
$a = new stdClass ;
$a -> users = count ( $usercount );
$a -> usersname = $course -> students ;
echo " <div align= \" right \" ><a href= \" report.php?id= $cm->id\ " > " .get_string( " viewlessonstats " , " lesson " , $a ). " </ a ></ div > " ;
}
2005-05-03 22:26:01 +00:00
if ( $essaypages = get_records_select ( " lesson_pages " , " lessonid = $lesson->id AND qtype = " . LESSON_ESSAY )) { // get pages that are essay
2005-05-16 22:41:19 +00:00
// get only the attempts that are in response to essay questions
$essaypageids = implode ( " , " , array_keys ( $essaypages )); // all the pageids in comma seperated list
if ( $essayattempts = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND pageid IN( $essaypageids ) " )) {
$studentessays = array ();
// makes an array that organizes essayattempts by grouping userid, then pageid, then try count
foreach ( $essayattempts as $essayattempt ) {
$studentessays [ $essayattempt -> userid ][ $essayattempt -> pageid ][ $essayattempt -> retry ][] = $essayattempt ;
}
$a = new stdClass ;
$a -> notgradedcount = 0 ;
$a -> notsentcount = 0 ;
foreach ( $studentessays as $pages ) { // students
foreach ( $pages as $tries ) { // pages
// go through each essay per page
foreach ( $tries as $try ) { // actual attempts
// make sure they didn't answer it more than the max number of attmepts
if ( count ( $try ) > $lesson -> maxattempts ) {
$essay = $try [ $lesson -> maxattempts - 1 ];
} else {
$essay = end ( $try );
}
$essayinfo = unserialize ( $essay -> useranswer );
if ( $essayinfo -> graded == 0 ) {
$a -> notgradedcount ++ ;
}
if ( $essayinfo -> sent == 0 ) {
$a -> notsentcount ++ ;
}
}
}
}
echo " <div align= \" right \" ><a href= \" view.php?id= $cm->id &action=essayview \" > " . get_string ( " gradeessay " , " lesson " , $a ) . " </a></div><br /> " ;
}
}
2005-05-03 22:26:01 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2005-05-16 22:41:19 +00:00
// get number of pages
2004-02-16 05:41:13 +00:00
if ( $page = get_record_select ( " lesson_pages " , " lessonid = $lesson->id AND prevpageid = 0 " )) {
$npages = 1 ;
while ( true ) {
if ( $page -> nextpageid ) {
if ( ! $page = get_record ( " lesson_pages " , " id " , $page -> nextpageid )) {
error ( " Teacher view: Next page not found! " );
}
} else {
// last page reached
break ;
}
$npages ++ ;
}
}
if ( ! $page = get_record_select ( " lesson_pages " , " lessonid = $lesson->id AND prevpageid = 0 " )) {
2004-09-24 23:10:49 +00:00
/// CDC-FLAG ///
2004-09-15 20:32:24 +00:00
// if there are no pages give teacher the option to create a new page or a new branch table
2004-09-24 23:10:49 +00:00
echo " <div align= \" center \" > " ;
if ( isteacheredit ( $course -> id )) {
print_simple_box ( " <table cellpadding= \" 5 \" border= \" 0 \" > \n <tr><th> " . get_string ( " whatdofirst " , " lesson " ) . " </th></tr><tr><td> " .
" <a href= \" import.php?id= $cm->id &pageid=0 \" > " .
get_string ( " importquestions " , " lesson " ) . " </a></td></tr><tr><td> " .
2005-05-24 20:28:20 +00:00
" <a href= \" importppt.php?id= $cm->id &pageid=0 \" > " .
get_string ( " importppt " , " lesson " ) . " </a></td></tr><tr><td> " .
2004-09-24 23:10:49 +00:00
" <a href= \" lesson.php?id= $cm->id &action=addbranchtable&pageid=0&firstpage=1 \" > " .
get_string ( " addabranchtable " , " lesson " ) . " </a></td></tr><tr><td> " .
" <a href= \" lesson.php?id= $cm->id &action=addpage&pageid=0&firstpage=1 \" > " .
get_string ( " addaquestionpage " , " lesson " ) . " " . get_string ( " here " , " lesson " ) .
2005-05-24 21:21:21 +00:00
" </a></td></tr></table> \n " );
2004-09-24 23:10:49 +00:00
}
print_simple_box_end ();
echo " </div> " ; //CDC Chris Berri added.
2005-03-05 00:09:39 +00:00
/// CDC-FLAG ///
2004-02-16 05:41:13 +00:00
} else {
2005-03-05 00:09:39 +00:00
print_heading ( " <a href= \" view.php?id= $cm->id &action=navigation \" > " . get_string ( " checknavigation " ,
" lesson " ) . " </a> \n " );
2004-02-16 05:41:13 +00:00
// print the pages
2004-02-26 16:54:47 +00:00
echo " <form name= \" lessonpages \" method= \" post \" action= \" view.php \" > \n " ;
2004-09-16 17:13:57 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> \n " ;
echo " <input type= \" hidden \" name= \" action \" value= \" navigation \" /> \n " ;
echo " <input type= \" hidden \" name= \" pageid \" /> \n " ;
2004-09-24 23:10:49 +00:00
/// CDC-FLAG /// tree code - in final release, will use lang file for all text output.
// NoticeFix next two lines and bowth viewAlls
$branch = false ;
$singlePage = false ;
2005-02-23 00:52:29 +00:00
if ( $lesson -> tree && ! isset ( $_GET [ 'display' ]) && ! isset ( $_GET [ 'viewAll' ])) {
2004-09-24 23:10:49 +00:00
echo " <div align= \" center \" > " ;
echo get_string ( " treeview " , " lesson " ) . " <br /><br /> " ;
echo " <a href= \" view.php?id= $id &viewAll=1 \" > " . get_string ( " viewallpages " , " lesson " ) . " </a><br /><br /> \n " ;
echo " <table><tr><td> " ;
2005-02-09 15:36:29 +00:00
lesson_print_tree ( $page -> id , $lesson -> id , $cm -> id , $CFG -> pixpath );
2004-09-24 23:10:49 +00:00
echo " </td></tr></table> " ;
echo " <br /><a href= \" view.php?id= $id &viewAll=1 \" > " . get_string ( " viewallpages " , " lesson " ) . " </a> \n " ;
echo " </div> " ;
} else {
if ( isset ( $_GET [ 'display' ]) && ! isset ( $_GET [ 'viewAll' ])) {
2005-03-05 00:09:39 +00:00
$display = clean_param ( $_GET [ 'display' ], PARAM_INT );
2004-09-24 23:10:49 +00:00
while ( true )
{
2005-01-27 21:36:12 +00:00
if ( $page -> id == $display && $page -> qtype == LESSON_BRANCHTABLE ) {
2004-09-24 23:10:49 +00:00
$branch = true ;
$singlePage = false ;
break ;
2005-01-27 21:36:12 +00:00
} elseif ( $page -> id == $display ) {
2004-09-24 23:10:49 +00:00
$branch = false ;
2005-03-05 00:09:39 +00:00
$singlePage = true ;
2004-09-24 23:10:49 +00:00
break ;
} elseif ( $page -> nextpageid ) {
if ( ! $page = get_record ( " lesson_pages " , " id " , $page -> nextpageid )) {
error ( " Teacher view: Next page not found! " );
}
} else {
// last page reached
break ;
}
2005-01-27 21:36:12 +00:00
}
2004-09-24 23:10:49 +00:00
echo " <center><a href= \" view.php?id= $id &viewAll=1 \" > " . get_string ( " viewallpages " , " lesson " ) . " </a><br /> \n " ;
echo " <a href= \" view.php?id= $id\ " > " .get_string( " backtreeview " , " lesson " ). " </ a >< br /> \n " ;
echo " <table cellpadding= \" 5 \" border= \" 0 \" width= \" 80% \" > \n " ;
if ( isteacheredit ( $course -> id )) {
2005-03-05 00:09:39 +00:00
/// CDC-FLAG 6/16/04 ///
2005-01-27 21:36:12 +00:00
echo " <tr><td align= \" left \" ><small><a href= \" import.php?id= $cm->id &pageid= $page->prevpageid\ " > " .
2004-09-24 23:10:49 +00:00
get_string ( " importquestions " , " lesson " ) . " </a> | " .
2005-01-27 21:36:12 +00:00
" <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addcluster&pageid= $page->prevpageid\ " > " .
2004-09-24 23:10:49 +00:00
get_string ( " addcluster " , " lesson " ) . " </a> | " .
2005-01-27 21:36:12 +00:00
" <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addendofcluster&pageid= $page->prevpageid\ " > " .
2004-09-24 23:10:49 +00:00
get_string ( " addendofcluster " , " lesson " ) . " </a> | " .
" <a href= \" lesson.php?id= $cm->id &action=addbranchtable&pageid= $page->prevpageid\ " > " .
get_string ( " addabranchtable " , " lesson " ) . " </a> | " .
" <a href= \" lesson.php?id= $cm->id &action=addpage&pageid= $page->prevpageid\ " > " .
get_string ( " addaquestionpage " , " lesson " ) . " " . get_string ( " here " , " lesson " ) .
" </a></small></td></tr> \n " ;
2005-03-05 00:09:39 +00:00
/// CDC-FLAG ///
}
2004-09-24 23:10:49 +00:00
} else {
if ( $lesson -> tree ) {
echo " <center><a href= \" view.php?id= $id\ " > " .get_string( " backtreeview " , " lesson " ). " </ a >< br /></ center > \n " ;
2005-03-05 00:09:39 +00:00
}
2005-01-27 21:36:12 +00:00
echo " <table align= \" center \" cellpadding= \" 5 \" border= \" 0 \" width= \" 80% \" > \n " ;
2004-09-24 23:10:49 +00:00
if ( isteacheredit ( $course -> id )) {
/// CDC-FLAG 6/16/04 ///
echo " <tr><td align= \" left \" ><small><a href= \" import.php?id= $cm->id &pageid=0 \" > " .
get_string ( " importquestions " , " lesson " ) . " </a> | " .
2005-01-27 21:36:12 +00:00
" <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addcluster&pageid=0 \" > " .
2004-09-28 19:22:30 +00:00
get_string ( " addcluster " , " lesson " ) . " </a> | " .
2004-11-04 09:24:51 +00:00
" <a href= \" lesson.php?id= $cm->id &action=addbranchtable&pageid=0 \" > " .
2004-09-24 23:10:49 +00:00
get_string ( " addabranchtable " , " lesson " ) . " </a> | " .
2004-09-16 17:13:57 +00:00
" <a href= \" lesson.php?id= $cm->id &action=addpage&pageid=0 \" > " .
2004-09-24 23:10:49 +00:00
get_string ( " addaquestionpage " , " lesson " ) . " " . get_string ( " here " , " lesson " ) .
" </a></small></td></tr> \n " ;
/// CDC-FLAG ///
}
}
2005-03-05 00:09:39 +00:00
/// CDC-FLAG /// end tree code (note, there is an "}" below for an else above)
2004-02-16 05:41:13 +00:00
while ( true ) {
2005-03-05 00:09:39 +00:00
echo " <tr><td> \n " ;
2005-05-03 23:30:40 +00:00
echo " <table width= \" 100% \" border= \" 1 \" class= \" generalbox \" ><tr><th colspan= \" 2 \" > " . format_string ( $page -> title ) . " \n " ;
2004-02-17 00:54:10 +00:00
if ( isteacheredit ( $course -> id )) {
if ( $npages > 1 ) {
2004-09-16 17:13:57 +00:00
echo " <a title= \" " . get_string ( " move " ) . " \" href= \" lesson.php?id= $cm->id &action=move&pageid= $page->id\ " > \n " .
2005-02-09 15:36:29 +00:00
" <img src= \" $CFG->pixpath /t/move.gif \" hspace= \" 2 \" height= \" 11 \" width= \" 11 \" border= \" 0 \" alt= \" move \" /></a> \n " ;
2004-02-17 00:54:10 +00:00
}
2004-09-16 17:13:57 +00:00
echo " <a title= \" " . get_string ( " update " ) . " \" href= \" lesson.php?id= $cm->id &action=editpage&pageid= $page->id\ " > \n " .
2005-02-09 15:36:29 +00:00
" <img src= \" $CFG->pixpath /t/edit.gif \" hspace= \" 2 \" height= \" 11 \" width= \" 11 \" border= \" 0 \" alt= \" edit \" /></a> \n " .
2005-01-27 21:36:12 +00:00
" <a title= \" " . get_string ( " delete " ) . " \" href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=confirmdelete&pageid= $page->id\ " > \n " .
2005-02-09 15:36:29 +00:00
" <img src= \" $CFG->pixpath /t/delete.gif \" hspace= \" 2 \" height= \" 11 \" width= \" 11 \" border= \" 0 \" alt= \" delete \" /></a> \n " ;
2004-11-04 09:24:51 +00:00
}
2005-02-23 00:52:29 +00:00
echo " </th></tr> \n " ;
2004-02-16 05:41:13 +00:00
echo " <tr><td colspan= \" 2 \" > \n " ;
2005-05-06 23:57:20 +00:00
print_simple_box ( format_text ( $page -> contents , FORMAT_HTML ), " center " );
2004-02-16 05:41:13 +00:00
echo " </td></tr> \n " ;
2004-04-01 16:56:56 +00:00
// get the answers in a set order, the id order
2004-02-16 05:41:13 +00:00
if ( $answers = get_records ( " lesson_answers " , " pageid " , $page -> id , " id " )) {
2005-02-09 15:36:29 +00:00
echo " <tr><td colspan= \" 2 \" align= \" center \" ><b> \n " ;
2004-04-01 16:56:56 +00:00
switch ( $page -> qtype ) {
2004-09-24 23:10:49 +00:00
case LESSON_ESSAY : /// CDC-FLAG /// 6/16/04 this line and the next
echo $LESSON_QUESTION_TYPE [ $page -> qtype ];
break ;
2004-04-01 16:56:56 +00:00
case LESSON_SHORTANSWER :
echo $LESSON_QUESTION_TYPE [ $page -> qtype ];
if ( $page -> qoption ) {
echo " - " . get_string ( " casesensitive " , " lesson " );
}
break ;
case LESSON_MULTICHOICE :
echo $LESSON_QUESTION_TYPE [ $page -> qtype ];
if ( $page -> qoption ) {
echo " - " . get_string ( " multianswer " , " lesson " );
}
break ;
case LESSON_MATCHING :
echo $LESSON_QUESTION_TYPE [ $page -> qtype ];
2004-11-01 20:41:55 +00:00
echo get_string ( " firstanswershould " , " lesson " );
2004-04-01 16:56:56 +00:00
break ;
case LESSON_TRUEFALSE :
case LESSON_NUMERICAL :
echo $LESSON_QUESTION_TYPE [ $page -> qtype ];
break ;
2005-02-23 00:52:29 +00:00
case LESSON_BRANCHTABLE :
2004-04-01 16:56:56 +00:00
echo get_string ( " branchtable " , " lesson " );
break ;
case LESSON_ENDOFBRANCH :
echo get_string ( " endofbranch " , " lesson " );
break ;
}
2004-11-04 09:24:51 +00:00
echo " </b></td></tr> \n " ;
2004-02-16 05:41:13 +00:00
$i = 1 ;
2004-09-24 23:10:49 +00:00
$n = 0 ;
2004-02-16 05:41:13 +00:00
foreach ( $answers as $answer ) {
2004-03-27 04:15:29 +00:00
switch ( $page -> qtype ) {
case LESSON_MULTICHOICE :
case LESSON_TRUEFALSE :
case LESSON_SHORTANSWER :
case LESSON_NUMERICAL :
2005-02-09 15:36:29 +00:00
echo " <tr><td align= \" right \" valign= \" top \" width= \" 20% \" > \n " ;
2004-09-15 20:32:24 +00:00
/// CDC-FLAG /// 6/11/04
2004-09-24 23:10:49 +00:00
if ( $lesson -> custom ) {
// if the score is > 0, then it is correct
if ( $answer -> score > 0 ) {
echo " <b><u> " . get_string ( " answer " , " lesson " ) . " $i :</u></b> \n " ;
} else {
echo " <b> " . get_string ( " answer " , " lesson " ) . " $i :</b> \n " ;
}
} else {
if ( lesson_iscorrect ( $page -> id , $answer -> jumpto )) {
// underline correct answers
echo " <b><u> " . get_string ( " answer " , " lesson " ) . " $i :</u></b> \n " ;
} else {
echo " <b> " . get_string ( " answer " , " lesson " ) . " $i :</b> \n " ;
}
}
/// CDC-FLAG ///
2004-03-27 04:15:29 +00:00
echo " </td><td width= \" 80% \" > \n " ;
echo format_text ( $answer -> answer );
echo " </td></tr> \n " ;
2005-01-27 21:36:12 +00:00
echo " <tr><td align= \" right \" valign= \" top \" ><b> " . get_string ( " response " , " lesson " ) . " $i :</b> \n " ;
2004-03-27 04:15:29 +00:00
echo " </td><td> \n " ;
2005-02-23 00:52:29 +00:00
echo format_text ( $answer -> response );
2004-03-27 04:15:29 +00:00
echo " </td></tr> \n " ;
2005-03-05 00:09:39 +00:00
break ;
2004-09-24 23:10:49 +00:00
case LESSON_MATCHING :
if ( $n < 2 ) {
if ( $answer -> answer != NULL ) {
if ( $n == 0 ) {
echo " <tr><td align= \" right \" valign= \" top \" ><b> " . get_string ( " correctresponse " , " lesson " ) . " :</b> \n " ;
echo " </td><td> \n " ;
2005-02-23 00:52:29 +00:00
echo format_text ( $answer -> answer );
2004-09-24 23:10:49 +00:00
echo " </td></tr> \n " ;
} else {
echo " <tr><td align= \" right \" valign= \" top \" ><b> " . get_string ( " wrongresponse " , " lesson " ) . " :</b> \n " ;
echo " </td><td> \n " ;
2005-02-23 00:52:29 +00:00
echo format_text ( $answer -> answer );
2004-09-24 23:10:49 +00:00
echo " </td></tr> \n " ;
}
}
$n ++ ;
$i -- ;
} else {
2005-02-09 15:36:29 +00:00
echo " <tr><td align= \" right \" valign= \" top \" width= \" 20% \" > \n " ;
2004-09-24 23:10:49 +00:00
if ( $lesson -> custom ) {
// if the score is > 0, then it is correct
if ( $answer -> score > 0 ) {
echo " <b><u> " . get_string ( " answer " , " lesson " ) . " $i :</u></b> \n " ;
} else {
echo " <b> " . get_string ( " answer " , " lesson " ) . " $i :</b> \n " ;
}
} else {
if ( lesson_iscorrect ( $page -> id , $answer -> jumpto )) {
// underline correct answers
echo " <b><u> " . get_string ( " answer " , " lesson " ) . " $i :</u></b> \n " ;
} else {
echo " <b> " . get_string ( " answer " , " lesson " ) . " $i :</b> \n " ;
}
}
echo " </td><td width= \" 80% \" > \n " ;
echo format_text ( $answer -> answer );
echo " </td></tr> \n " ;
echo " <tr><td align= \" right \" valign= \" top \" ><b> " . get_string ( " matchesanswer " , " lesson " ) . " $i :</b> \n " ;
echo " </td><td> \n " ;
2005-02-23 00:52:29 +00:00
echo format_text ( $answer -> response );
2004-09-24 23:10:49 +00:00
echo " </td></tr> \n " ;
}
break ;
2004-03-27 04:15:29 +00:00
case LESSON_BRANCHTABLE :
echo " <tr><td align= \" right \" valign= \" top \" width= \" 20% \" > \n " ;
echo " <b> " . get_string ( " description " , " lesson " ) . " $i :</b> \n " ;
echo " </td><td width= \" 80% \" > \n " ;
echo format_text ( $answer -> answer );
echo " </td></tr> \n " ;
break ;
2004-02-16 05:41:13 +00:00
}
if ( $answer -> jumpto == 0 ) {
$jumptitle = get_string ( " thispage " , " lesson " );
2004-02-26 16:54:47 +00:00
} elseif ( $answer -> jumpto == LESSON_NEXTPAGE ) {
2004-02-16 05:41:13 +00:00
$jumptitle = get_string ( " nextpage " , " lesson " );
2004-02-26 16:54:47 +00:00
} elseif ( $answer -> jumpto == LESSON_EOL ) {
2004-02-16 05:41:13 +00:00
$jumptitle = get_string ( " endoflesson " , " lesson " );
2005-03-05 00:09:39 +00:00
/* CDC-FLAG 6/17/04 */ } elseif ( $answer -> jumpto == LESSON_UNSEENBRANCHPAGE ) {
2005-02-23 00:52:29 +00:00
$jumptitle = get_string ( " unseenpageinbranch " , " lesson " ); // a better way is get_string("unseenbranchpage", "lesson"); and define in lang file
2004-09-24 23:10:49 +00:00
} elseif ( $answer -> jumpto == LESSON_PREVIOUSPAGE ) {
2004-09-15 20:32:24 +00:00
$jumptitle = get_string ( " previouspage " , " lesson " );
2004-09-24 23:10:49 +00:00
} elseif ( $answer -> jumpto == LESSON_RANDOMPAGE ) {
$jumptitle = get_string ( " randompageinbranch " , " lesson " );
} elseif ( $answer -> jumpto == LESSON_RANDOMBRANCH ) {
$jumptitle = get_string ( " randombranch " , " lesson " );
} elseif ( $answer -> jumpto == LESSON_CLUSTERJUMP ) {
2005-03-05 00:09:39 +00:00
$jumptitle = get_string ( " clusterjump " , " lesson " ); /// CDC-FLAG ///
2004-02-16 05:41:13 +00:00
} else {
if ( ! $jumptitle = get_field ( " lesson_pages " , " title " , " id " , $answer -> jumpto )) {
$jumptitle = " <b> " . get_string ( " notdefined " , " lesson " ) . " </b> " ;
}
}
2005-04-29 18:32:13 +00:00
$jumptitle = format_string ( $jumptitle , true );
2004-09-24 23:10:49 +00:00
/// CDC-FLAG ///
if ( $page -> qtype == LESSON_MATCHING ) {
if ( $i == 1 ) {
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " correctanswerscore " , " lesson " ) . " : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $answer->score </td></tr> \n " ;
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " correctanswerjump " , " lesson " ) . " : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $jumptitle </td></tr> \n " ;
} elseif ( $i == 2 ) {
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " wronganswerscore " , " lesson " ) . " : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $answer->score </td></tr> \n " ;
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " wronganswerjump " , " lesson " ) . " : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $jumptitle </td></tr> \n " ;
}
} else {
2005-03-05 00:09:39 +00:00
if ( $lesson -> custom && $page -> qtype != LESSON_BRANCHTABLE && $page -> qtype != LESSON_ENDOFBRANCH ) {
2004-09-24 23:10:49 +00:00
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " score " , " lesson " ) . " $i : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $answer->score </td></tr> \n " ;
}
echo " <tr><td align= \" right \" width= \" 20% \" ><b> " . get_string ( " jump " , " lesson " ) . " $i : " ;
echo " </b></td><td width= \" 80% \" > \n " ;
echo " $jumptitle </td></tr> \n " ;
}
2004-02-16 05:41:13 +00:00
$i ++ ;
}
2004-09-15 20:32:24 +00:00
// print_simple_box_end(); /// CDC-FLAG /// not sure if i commented this out... hehe
2005-02-09 15:36:29 +00:00
echo " <tr><td colspan= \" 2 \" align= \" center \" > " ;
2004-03-27 04:15:29 +00:00
if ( $page -> qtype != LESSON_ENDOFBRANCH ) {
echo " <input type= \" button \" value= \" " ;
if ( $page -> qtype == LESSON_BRANCHTABLE ) {
echo get_string ( " checkbranchtable " , " lesson " );
} else {
echo get_string ( " checkquestion " , " lesson " );
}
echo " \" onclick= \" document.lessonpages.pageid.value= $page->id ; " .
2004-11-04 09:24:51 +00:00
" document.lessonpages.submit(); \" /> " ;
2004-03-27 04:15:29 +00:00
}
echo " </td></tr> \n " ;
2004-02-16 05:41:13 +00:00
}
2004-11-04 09:24:51 +00:00
echo " </table></td></tr> \n " ;
2004-02-17 00:54:10 +00:00
if ( isteacheredit ( $course -> id )) {
2005-03-05 00:09:39 +00:00
/// CDC-FLAG /// 6/16/04
2004-09-16 17:13:57 +00:00
echo " <tr><td align= \" left \" ><small><a href= \" import.php?id= $cm->id &pageid= $page->id\ " > " .
2005-02-23 00:52:29 +00:00
get_string ( " importquestions " , " lesson " ) . " </a> | " .
2005-01-27 21:36:12 +00:00
" <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addcluster&pageid= $page->id\ " > " .
2004-09-15 20:32:24 +00:00
get_string ( " addcluster " , " lesson " ) . " </a> | " .
2005-01-27 21:36:12 +00:00
" <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addendofcluster&pageid= $page->id\ " > " .
2004-09-15 20:32:24 +00:00
get_string ( " addendofcluster " , " lesson " ) . " </a> | " .
2004-09-24 23:10:49 +00:00
" <a href= \" lesson.php?id= $cm->id &action=addbranchtable&pageid= $page->id\ " > " .
2004-09-16 17:13:57 +00:00
get_string ( " addabranchtable " , " lesson " ) . " </a><br /> " ;
2005-03-05 00:09:39 +00:00
/// CDC-FLAG ///
2004-03-27 04:15:29 +00:00
// the current page or the next page is an end of branch don't show EOB link
2004-09-24 23:10:49 +00:00
$nextqtype = 0 ; // set to anything else EOB
2004-03-27 04:15:29 +00:00
if ( $page -> nextpageid ) {
$nextqtype = get_field ( " lesson_pages " , " qtype " , " id " , $page -> nextpageid );
}
if (( $page -> qtype != LESSON_ENDOFBRANCH ) and ( $nextqtype != LESSON_ENDOFBRANCH )) {
2005-01-27 21:36:12 +00:00
echo " <a href= \" lesson.php?id= $cm->id &sesskey= " . $USER -> sesskey . " &action=addendofbranch&pageid= $page->id\ " > " .
2004-03-27 04:15:29 +00:00
get_string ( " addanendofbranch " , " lesson " ) . " </a> | " ;
}
2004-09-16 17:13:57 +00:00
echo " <a href= \" lesson.php?id= $cm->id &action=addpage&pageid= $page->id\ " > " .
2004-03-27 04:15:29 +00:00
get_string ( " addaquestionpage " , " lesson " ) . " " . get_string ( " here " , " lesson " ) .
" </a></small></td></tr> \n " ;
2004-02-17 00:54:10 +00:00
}
2004-11-04 09:24:51 +00:00
// echo "<tr><td>\n";
2004-03-27 04:15:29 +00:00
// check the prev links - fix (silently) if necessary - there was a bug in
// versions 1 and 2 when add new pages. Not serious then as the backwards
// links were not used in those versions
if ( isset ( $prevpageid )) {
if ( $page -> prevpageid != $prevpageid ) {
// fix it
set_field ( " lesson_pages " , " prevpageid " , $prevpageid , " id " , $page -> id );
if ( $CFG -> debug ) {
echo " <p>***prevpageid of page $page->id set to $prevpageid *** " ;
}
}
}
$prevpageid = $page -> id ;
2004-08-04 18:13:09 +00:00
// move to next page
2004-09-24 23:10:49 +00:00
/// CDC-FLAG ///
if ( $singlePage ) { // this will make sure only one page is displayed if needed
break ;
} elseif ( $branch && $page -> qtype == LESSON_ENDOFBRANCH ) { // this will display a branch table and its contents
break ;
2004-09-15 20:32:24 +00:00
} elseif ( $page -> nextpageid ) { /// CDC-FLAG ///
2004-02-16 05:41:13 +00:00
if ( ! $page = get_record ( " lesson_pages " , " id " , $page -> nextpageid )) {
error ( " Teacher view: Next page not found! " );
}
} else {
// last page reached
break ;
}
}
2004-09-24 23:10:49 +00:00
} /// CDC-FLAG /// end of else from above tree code!!!
2005-02-23 00:52:29 +00:00
2005-01-29 10:17:59 +00:00
echo " </table></form> \n " ;
2004-09-24 23:10:49 +00:00
/// CDC-FLAG ///
// NoticeFix both viewAll's
if ( isset ( $_GET [ 'display' ]) && ! isset ( $_GET [ 'viewAll' ])) {
echo " <center><a href= \" view.php?id= $id &viewAll=1 \" > " . get_string ( " viewallpages " , " lesson " ) . " </a><br /> \n " ;
}
if ( $lesson -> tree && ( isset ( $_GET [ 'display' ]) || isset ( $_GET [ 'viewAll' ]))) {
echo " <center><a href= \" view.php?id= $id\ " > " .get_string( " backtreeview " , " lesson " ). " </ a >< br /></ center > \n " ;
}
2005-03-05 00:09:39 +00:00
/// CDC-FLAG ///
2004-09-16 17:13:57 +00:00
print_heading ( " <a href= \" view.php?id= $cm->id &action=navigation \" > " . get_string ( " checknavigation " ,
2004-02-16 05:41:13 +00:00
" lesson " ) . " </a> \n " );
2005-02-23 00:52:29 +00:00
}
2004-02-16 05:41:13 +00:00
}
2004-09-15 20:32:24 +00:00
/*******************essay view **************************************/ // 6/29/04
elseif ( $action == 'essayview' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2004-11-01 20:41:55 +00:00
2005-03-05 00:09:39 +00:00
// get lesson pages that are essay
2004-11-01 20:41:55 +00:00
if ( ! $pages = get_records_select ( " lesson_pages " , " lessonid = $lesson->id AND qtype = " . LESSON_ESSAY )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find lesson pages " );
}
2005-03-05 00:09:39 +00:00
// get all the users who have taken this lesson, order by their last name
if ( ! $users = get_records_sql ( " SELECT DISTINCT u.*
2004-11-01 20:41:55 +00:00
FROM { $CFG -> prefix } user u ,
{ $CFG -> prefix } lesson_attempts a
WHERE a . lessonid = '$lesson->id' and
u . id = a . userid
2005-03-05 00:09:39 +00:00
ORDER BY u . lastname " )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find users " );
}
2005-03-05 00:09:39 +00:00
// get only the attempts that are in response to essay questions
$pageids = implode ( " , " , array_keys ( $pages )); // all the pageids in comma seperated list
if ( ! $essayattempts = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND pageid IN( $pageids ) " )) {
error ( " No one has answered essay questions yet... " );
}
// group all the essays by userid
$studentessays = array ();
foreach ( $essayattempts as $essay ) {
// not very nice :) but basically
// this organizes the essays so I know how many times a student answered an essay per try and per page
$studentessays [ $essay -> userid ][ $essay -> pageid ][ $essay -> retry ][] = $essay ;
2004-09-24 23:10:49 +00:00
}
2004-09-15 20:32:24 +00:00
2005-03-05 00:09:39 +00:00
print_heading ( " <a href= \" view.php?id= $cm->id\ " > " .get_string( " gobacktolesson " , " lesson " ). " </ a > " );
$table = new stdClass ;
$table -> head = array ( $course -> students , get_string ( " essays " , " lesson " ), get_string ( " email " , " lesson " ));
2004-11-01 20:41:55 +00:00
$table -> align = array ( " left " , " left " , " left " );
$table -> wrap = array ( " nowrap " , " wrap " , " nowrap " );
$table -> width = " 90% " ;
2005-03-05 00:09:39 +00:00
$table -> size = array ( " * " , " 70% " , " * " );
2004-11-01 20:41:55 +00:00
2005-03-05 00:09:39 +00:00
// get the student ids of the students who have answered the essay question
$studentids = array_keys ( $studentessays );
// cycle through all the ids
2004-11-01 20:41:55 +00:00
foreach ( $studentids as $id ) {
$studentname = $users [ $id ] -> lastname . " , " . $users [ $id ] -> firstname ;
2005-03-05 00:09:39 +00:00
$essaylinks = array ();
// go through each essay
2004-11-01 20:41:55 +00:00
foreach ( $studentessays [ $id ] as $page => $tries ) {
2005-03-05 00:09:39 +00:00
// go through each essay per page
foreach ( $tries as $try ) {
// make sure they didn't answer it more than the max number of attmepts
if ( count ( $try ) > $lesson -> maxattempts ) {
$essay = $try [ $lesson -> maxattempts - 1 ];
} else {
$essay = end ( $try );
}
$essayinfo = unserialize ( $essay -> useranswer );
// different colors for all the states of an essay (graded, if sent, not graded)
if ( ! $essayinfo -> graded ) {
$style = " style='color:#DF041E;text-decoration:underline;' " ;
} elseif ( ! $essayinfo -> sent ) {
$style = " style='color:#006600;text-decoration:underline;' " ;
} else {
$style = " style='color:#999999;' " ;
}
// link for each essay
2005-04-26 22:30:40 +00:00
$essaylinks [] = " <a $style href= \" view.php?id= $cm->id &action=essaygrade&attemptid= $essay->id\ " > " .format_string( $pages[$essay->pageid] ->title,true). " </ a > " ;
2005-03-05 00:09:39 +00:00
}
2004-09-24 23:10:49 +00:00
}
2005-03-05 00:09:39 +00:00
// email link for this user
$emaillink = " <a href= \" view.php?id= $cm->id &action=emailessay&userid= " . $id . " &sesskey= " . $USER -> sesskey . " \" > " . get_string ( " emailgradedessays " , " lesson " ) . " </a> " ;
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$table -> data [] = array ( $studentname , implode ( " , " , $essaylinks ), $emaillink );
}
// email link for all users
$emailalllink = " <a href= \" view.php?id= $cm->id &action=emailessay&sesskey= " . $USER -> sesskey . " \" > " . get_string ( " emailallgradedessays " , " lesson " ) . " </a> " ;
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$table -> data [] = array ( " " , " " , $emailalllink );
print_table ( $table );
2004-09-24 23:10:49 +00:00
}
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
/*******************grade essays **************************************/ // 6/29/04
2004-09-15 20:32:24 +00:00
elseif ( $action == 'essaygrade' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2005-03-05 00:09:39 +00:00
$attemptid = required_param ( 'attemptid' , PARAM_INT );
2004-11-01 20:41:55 +00:00
if ( ! $essay = get_record ( " lesson_attempts " , " id " , $attemptid )) {
2005-02-04 19:39:18 +00:00
error ( " Error: could not find attempt " );
2004-09-24 23:10:49 +00:00
}
2004-11-01 20:41:55 +00:00
if ( ! $page = get_record ( " lesson_pages " , " id " , $essay -> pageid )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find lesson pages " );
}
2004-11-01 20:41:55 +00:00
if ( ! $student = get_record ( " user " , " id " , $essay -> userid )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find users " );
}
2004-11-01 20:41:55 +00:00
if ( ! $answer = get_record ( " lesson_answers " , " lessonid " , $lesson -> id , " pageid " , $page -> id )) {
error ( " Error: could not find answer " );
2004-09-24 23:10:49 +00:00
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
echo " <form name= \" essaygrade \" method= \" post \" action= \" view.php \" > \n " ;
2004-11-04 09:24:51 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> \n " ;
echo " <input type= \" hidden \" name= \" action \" /> \n " ;
echo " <input type= \" hidden \" name= \" attemptid \" value= \" $attemptid\ " /> \n " ;
2005-03-05 00:09:39 +00:00
echo " <input type= \" hidden \" name= \" sesskey \" value= \" " . $USER -> sesskey . " \" /> \n " ;
// all tables will have these
$table = new stdClass ;
2004-11-01 20:41:55 +00:00
$table -> align = array ( " left " );
2005-07-12 23:07:31 +00:00
$table -> wrap = array ();
2004-11-01 20:41:55 +00:00
$table -> width = " 70% " ;
2005-03-05 00:09:39 +00:00
$table -> size = array ( " 100% " );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$table -> head = array ( get_string ( " question " , " lesson " ));
2004-11-01 20:41:55 +00:00
$table -> data [] = array ( format_text ( $page -> contents ));
2004-09-15 20:32:24 +00:00
2005-03-05 00:09:39 +00:00
print_table ( $table );
echo " <br /> " ;
2004-11-01 20:41:55 +00:00
2005-03-05 00:09:39 +00:00
unset ( $table -> data );
$essayinfo = unserialize ( $essay -> useranswer );
2004-11-01 20:41:55 +00:00
$studentname = $student -> firstname . " " . $student -> lastname ;
$table -> head = array ( get_string ( " studentresponse " , " lesson " , $studentname ));
2005-03-05 00:09:39 +00:00
$table -> data [] = array ( format_text ( $essayinfo -> answer ));
print_table ( $table );
echo " <br /> " ;
unset ( $table -> data );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$table -> head = array ( get_string ( " comments " , " lesson " ));
2005-04-29 18:32:13 +00:00
$table -> data [] = array ( " <textarea id= \" answer \" name= \" response \" rows= \" 15 \" cols= \" 60 \" > " . $essayinfo -> response . " </textarea> \n " );
2004-09-24 23:10:49 +00:00
if ( $lesson -> custom ) {
2004-11-01 20:41:55 +00:00
for ( $i = $answer -> score ; $i >= 0 ; $i -- ) {
$options [ $i ] = $i ;
2004-09-24 23:10:49 +00:00
}
} else {
2005-02-04 19:39:18 +00:00
$options [ 0 ] = " incorrect " ;
2005-03-05 00:09:39 +00:00
$options [ 1 ] = " correct " ;
2004-09-24 23:10:49 +00:00
}
2005-03-05 00:09:39 +00:00
$table -> data [] = array ( get_string ( " essayscore " , " lesson " ) . " : " . lesson_choose_from_menu ( $options , " score " , $essayinfo -> score , " " , " " , " " , true ));
print_table ( $table );
echo " <br /> " ;
2004-09-24 23:10:49 +00:00
echo " <table align= \" center \" ><tr><td> " ;
echo " <input type= \" button \" value= \" Cancel \" onclick= \" document.essaygrade.action.value='essayview'; " .
2004-11-04 09:24:51 +00:00
" document.essaygrade.submit(); \" /> " ;
2004-09-24 23:10:49 +00:00
echo " </td><td> " ;
echo " <input type= \" button \" value= \" Submit Grade \" onclick= \" document.essaygrade.action.value='updategrade'; " .
2004-11-04 09:24:51 +00:00
" document.essaygrade.submit(); \" /> " ;
2004-09-24 23:10:49 +00:00
echo " </td></tr></table> " ;
2005-03-05 00:09:39 +00:00
echo " </form> " ;
2004-09-24 23:10:49 +00:00
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
/*******************update grade**************************************/ // 6/29/04
2004-09-15 20:32:24 +00:00
elseif ( $action == 'updategrade' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
confirm_sesskey ();
2005-03-10 20:42:09 +00:00
$form = data_submitted ();
2005-02-23 00:52:29 +00:00
2005-03-10 20:42:09 +00:00
if ( ! $essay = get_record ( " lesson_attempts " , " id " , clean_param ( $form -> attemptid , PARAM_INT ))) {
2004-11-01 20:41:55 +00:00
error ( " Error: could not find essay " );
2004-09-24 23:10:49 +00:00
}
2004-11-01 20:41:55 +00:00
if ( ! $grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id and userid = $essay->userid " , " completed " , " * " , $essay -> retry , 1 )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find grades " );
}
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$essayinfo = new stdClass ;
$essayinfo = unserialize ( $essay -> useranswer );
2004-02-16 05:41:13 +00:00
2005-03-10 20:42:09 +00:00
$essayinfo -> graded = 1 ;
$essayinfo -> score = clean_param ( $form -> score , PARAM_INT );
$essayinfo -> response = clean_param ( stripslashes_safe ( $form -> response ), PARAM_CLEANHTML );
2005-03-05 00:09:39 +00:00
$essayinfo -> sent = 0 ;
2005-03-10 20:42:09 +00:00
if ( ! $lesson -> custom && $essayinfo -> score == 1 ) {
2005-03-05 00:09:39 +00:00
$essay -> correct = 1 ;
} else {
$essay -> correct = 0 ;
}
2004-11-17 01:02:14 +00:00
2005-03-05 00:09:39 +00:00
$essay -> useranswer = addslashes ( serialize ( $essayinfo ));
2004-11-17 01:02:14 +00:00
2005-03-05 00:09:39 +00:00
if ( ! update_record ( " lesson_attempts " , $essay )) {
error ( " Could not update essay score " );
}
2004-11-17 01:02:14 +00:00
2005-03-05 00:09:39 +00:00
$grade = current ( $grades );
2004-11-17 01:02:14 +00:00
2005-03-05 00:09:39 +00:00
// I modded this function a bit so it would work here... :) ;) :P
$updategrade -> grade = lesson_calculate_ongoing_score ( $lesson , $essay -> userid , $essay -> retry , true );
$updategrade -> id = $grade -> id ;
2005-02-04 19:39:18 +00:00
if ( update_record ( " lesson_grades " , $updategrade )) {
2004-11-04 09:24:51 +00:00
redirect ( " view.php?id= $cm->id &action=essayview " , get_string ( " updatesuccess " , " lesson " ));
2004-09-24 23:10:49 +00:00
} else {
echo get_string ( " updatefailed " , " lesson " ) . " !<br> " ;
2004-11-04 09:24:51 +00:00
echo " <a href= \" view.php?id= $cm->id &action=essayview \" > " . get_string ( " continue " , " lesson " ) . " </a> " ;
2004-09-24 23:10:49 +00:00
exit ();
}
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
/*******************email essay **************************************/ // 6/29/04
2004-09-15 20:32:24 +00:00
elseif ( $action == 'emailessay' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
confirm_sesskey ();
2005-01-27 21:36:12 +00:00
if ( isset ( $_GET [ 'userid' ])) {
2005-03-05 00:09:39 +00:00
$userid = clean_param ( $_GET [ 'userid' ], PARAM_INT );
2005-01-27 21:36:12 +00:00
$queryadd = " AND userid = " . $userid ;
2005-03-05 00:09:39 +00:00
if ( ! $users = get_records ( " user " , " id " , $userid )) {
error ( " Error: could not find users " );
}
2004-09-24 23:10:49 +00:00
} else {
$queryadd = " " ;
2005-03-05 00:09:39 +00:00
if ( ! $users = lesson_get_participants ( $lesson -> id )) {
error ( " Error: could not find users " );
}
2004-09-24 23:10:49 +00:00
}
2005-03-05 00:09:39 +00:00
// get lesson pages that are essay
2004-11-01 20:41:55 +00:00
if ( ! $pages = get_records_select ( " lesson_pages " , " lessonid = $lesson->id AND qtype = " . LESSON_ESSAY )) {
2004-09-24 23:10:49 +00:00
error ( " Error: could not find lesson pages " );
}
2005-03-05 00:09:39 +00:00
// get only the attempts that are in response to essay questions
$pageids = implode ( " , " , array_keys ( $pages )); // all the pageids in comma seperated list
if ( ! $essayattempts = get_records_select ( " lesson_attempts " , " lessonid = $lesson->id AND pageid IN( $pageids ) " . $queryadd )) {
error ( " No one has answered essay questions yet... " );
}
if ( ! $essayanswers = get_records_select ( " lesson_answers " , " lessonid = $lesson->id AND pageid IN( $pageids ) " , " " , " pageid, score " )) {
error ( " Could not find answer records. " );
}
2004-11-01 20:41:55 +00:00
2004-09-24 23:10:49 +00:00
// NoticeFix big fix, change $essay[]'s that use $USER to just $USER
2004-11-01 20:41:55 +00:00
foreach ( $essayattempts as $essay ) {
2005-03-05 00:09:39 +00:00
$essayinfo = unserialize ( $essay -> useranswer );
2004-11-01 20:41:55 +00:00
if ( $essayinfo -> graded && ! $essayinfo -> sent ) {
2005-04-26 22:30:40 +00:00
$subject = get_string ( 'essayemailsubject' , 'lesson' , format_string ( $pages [ $essay -> pageid ] -> title , true ));
2004-11-01 20:41:55 +00:00
$message = get_string ( 'question' , 'lesson' ) . " :<br> " ;
2004-09-24 23:10:49 +00:00
$message .= $pages [ $essay -> pageid ] -> contents ;
2005-03-05 00:09:39 +00:00
$message .= " <br><br> " ;
2004-11-01 20:41:55 +00:00
$message .= get_string ( 'yourresponse' , 'lesson' ) . " :<br> " ;
2005-04-29 18:32:13 +00:00
$message .= format_text ( $essayinfo -> answer );
2005-03-05 00:09:39 +00:00
$message .= " <br><br> " ;
$message .= get_string ( 'commentswithname' , 'lesson' , $USER ) . " :<br> " ;
2005-04-29 18:32:13 +00:00
$message .= format_text ( $essayinfo -> response );
2005-03-05 00:09:39 +00:00
$message .= " <br><br> " ;
$grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id and userid = $essay->userid " , " completed " , " * " , $essay -> retry , 1 );
$grade = current ( $grades );
2004-09-24 23:10:49 +00:00
if ( $lesson -> custom ) {
2005-03-05 00:09:39 +00:00
$points -> score = $essayinfo -> score ;
$points -> outof = $essayanswers [ $essay -> pageid ] -> score ;
2004-11-17 01:02:14 +00:00
$message .= get_string ( " youhavereceived " , " lesson " , $points );
2005-03-05 00:09:39 +00:00
} else {
$points -> score = $essayinfo -> score ;
$points -> outof = 1 ;
2004-11-17 01:02:14 +00:00
$message .= get_string ( " youhavereceived " , " lesson " , $points );
2005-03-05 00:09:39 +00:00
}
$message .= " <br><br> " ;
$message .= get_string ( " yourgradeisnow " , " lesson " , $grade -> grade ) . " %. " ;
$plaintxt = format_text_email ( $message , FORMAT_HTML );
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
if ( email_to_user ( $users [ $essay -> userid ], $USER , $subject , $plaintxt , $message )) {
$essayinfo -> sent = 1 ;
$essay -> useranswer = addslashes ( serialize ( $essayinfo ));
2004-11-01 20:41:55 +00:00
update_record ( " lesson_attempts " , $essay );
2004-09-24 23:10:49 +00:00
} else {
echo " Email Failed!<br> " ;
2004-11-04 09:24:51 +00:00
echo " <a href= \" view.php?id= $cm->id &action=essayview \" > " . get_string ( " continue " , " lesson " ) . " </a> " ;
2004-09-24 23:10:49 +00:00
echo " </div> " ;
exit ();
}
}
}
2004-11-04 09:24:51 +00:00
redirect ( " view.php?id= $cm->id &action=essayview " , get_string ( " emailsuccess " , " lesson " ));
2004-09-24 23:10:49 +00:00
}
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
/*******************high scores **************************************/
2004-09-15 20:32:24 +00:00
elseif ( $action == 'highscores' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
if ( ! $grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id " , " completed " )) {
$grades = array ();
}
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
echo " <div align= \" center \" > " ;
$titleinfo -> maxhighscores = $lesson -> maxhighscores ;
2005-04-24 16:46:51 +00:00
$titleinfo -> name = format_string ( $lesson -> name );
2004-09-24 23:10:49 +00:00
echo get_string ( " topscorestitle " , " lesson " , $titleinfo ) . " <br><br> " ;
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
if ( ! $highscores = get_records_select ( " lesson_high_scores " , " lessonid = $lesson->id " )) {
echo get_string ( " nohighscores " , " lesson " ) . " <br> " ;
} else {
foreach ( $highscores as $highscore ) {
$grade = $grades [ $highscore -> gradeid ] -> grade ;
$topscores [ $grade ][] = $highscore -> nickname ;
}
krsort ( $topscores );
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
echo " <table cellspacing= \" 10px \" > " ;
2005-02-09 15:36:29 +00:00
echo " <tr align= \" center \" ><td> " . get_string ( " rank " , " lesson " ) . " </td><td> $course->students </td><td> " . get_string ( " scores " , " lesson " ) . " </td></tr> " ;
2004-09-24 23:10:49 +00:00
$printed = 0 ;
while ( true ) {
$temp = current ( $topscores );
$score = key ( $topscores );
$rank = $printed + 1 ;
2005-02-23 00:52:29 +00:00
sort ( $temp );
2004-09-24 23:10:49 +00:00
foreach ( $temp as $student ) {
echo " <tr><td align= \" right \" > $rank </td><td> $student </td><td align= \" right \" > $score </td></tr> " ;
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
}
$printed ++ ;
2005-02-23 00:52:29 +00:00
if ( ! next ( $topscores ) || ! ( $printed < $lesson -> maxhighscores )) {
2004-09-24 23:10:49 +00:00
break ;
}
}
echo " </table> " ;
}
if ( isset ( $_GET [ 'link' ])) {
echo " <br><a href= \" ../../course/view.php?id= $course->id\ " > " .get_string( " returntocourse " , " lesson " ). " </ a > " ;
} else {
2004-11-04 09:24:51 +00:00
echo " <br><a href= \" ../../course/view.php?id= $course->id\ " > " .get_string( " cancel " , " lesson " ). " </ a > | < a href = \ " view.php?id= $cm->id &action=navigation \" > " . get_string ( " startlesson " , " lesson " ) . " </a> " ;
2004-09-24 23:10:49 +00:00
}
echo " </div> " ;
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
}
/*******************update high scores **************************************/
2004-09-15 20:32:24 +00:00
elseif ( $action == 'updatehighscores' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2005-03-05 00:09:39 +00:00
confirm_sesskey ();
2004-09-15 20:32:24 +00:00
2004-09-24 23:10:49 +00:00
if ( ! $grades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id " , " completed " )) {
error ( " Error: could not find grades " );
}
if ( ! $usergrades = get_records_select ( " lesson_grades " , " lessonid = $lesson->id and userid = $USER->id " , " completed DESC " )) {
error ( " Error: could not find grades " );
}
echo " <div align= \" center \" > " ;
echo get_string ( " waitpostscore " , " lesson " ) . " <br> " ;
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
foreach ( $usergrades as $usergrade ) {
// get their latest grade
$newgrade = $usergrade ;
break ;
}
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
if ( $pasthighscore = get_record_select ( " lesson_high_scores " , " lessonid = $lesson->id and userid = $USER->id " )) {
$pastgrade = $grades [ $pasthighscore -> gradeid ] -> grade ;
if ( $pastgrade >= $newgrade -> grade ) {
2004-11-04 09:24:51 +00:00
redirect ( " view.php?id= $cm->id &action=highscores&link=1 " , " Update Successful " );
2004-09-24 23:10:49 +00:00
} else {
// delete old and find out where new one goes
if ( ! delete_records ( " lesson_high_scores " , " id " , $pasthighscore -> id )) {
error ( " Error: could not delete old high score " );
}
}
}
// find out if we need to delete any records
if ( $highscores = get_records_select ( " lesson_high_scores " , " lessonid = $lesson->id " )) { // if no high scores... then just insert our new one
foreach ( $highscores as $highscore ) {
$grade = $grades [ $highscore -> gradeid ] -> grade ;
$topscores [ $grade ][] = $highscore -> userid ;
}
if ( ! ( count ( $topscores ) < $lesson -> maxhighscores )) { // if the top scores list is not full then dont need to worry about removing old scores
$scores = array_keys ( $topscores );
2005-03-05 00:09:39 +00:00
$flag = true ;
2004-09-24 23:10:49 +00:00
// see if the new score is already listed in the top scores list
// if it is listed, then dont need to delete any records
foreach ( $scores as $score ) {
if ( $score = $newgrade -> grade ) {
$flag = false ;
}
2005-03-05 00:09:39 +00:00
}
2004-09-24 23:10:49 +00:00
if ( $flag ) { // if the score does not exist in the top scores list, then the lowest scores get thrown out.
ksort ( $topscores ); // sort so the lowest score is first element
$lowscore = current ( $topscores );
// making a delete statement to delete all users with the lowest score
$deletestmt = 'lessonid = ' . $lesson -> id . ' and userid = ' ;
$deletestmt .= current ( $lowscore );
while ( next ( $lowscore )) {
$deletestmt .= " or userid = " . current ( $lowscore );
}
if ( ! delete_records_select ( 'lesson_high_scores' , $deletestmt )) {
/// not a big deal...
error ( 'Did not delete extra high score(s)' );
}
}
}
}
2005-02-23 00:52:29 +00:00
2005-03-05 00:09:39 +00:00
$newhighscore = new stdClass ;
2004-09-24 23:10:49 +00:00
$newhighscore -> lessonid = $lesson -> id ;
$newhighscore -> userid = $USER -> id ;
$newhighscore -> gradeid = $newgrade -> id ;
if ( isset ( $_GET [ 'name' ])) {
2005-01-27 21:36:12 +00:00
$newhighscore -> nickname = clean_param ( $_GET [ 'name' ], PARAM_CLEAN );
2004-09-24 23:10:49 +00:00
}
if ( ! insert_record ( " lesson_high_scores " , $newhighscore )) {
error ( " Insert of new high score Failed! " );
}
2005-02-23 00:52:29 +00:00
2004-11-04 09:24:51 +00:00
redirect ( " view.php?id= $cm->id &action=highscores&link=1 " , get_string ( " postsuccess " , " lesson " ));
2004-09-24 23:10:49 +00:00
echo " </div> " ;
}
/*******************name for highscores **************************************/
2004-09-15 20:32:24 +00:00
elseif ( $action == 'nameforhighscores' ) {
2005-04-24 16:46:51 +00:00
print_heading_with_help ( format_string ( $lesson -> name , true ), " overview " , " lesson " );
2004-09-24 23:10:49 +00:00
echo " <div align= \" center \" > " ;
if ( isset ( $_POST [ 'name' ])) {
2005-03-05 00:09:39 +00:00
$name = trim ( clean_param ( $_POST [ 'name' ], PARAM_CLEAN ));
2005-01-27 21:36:12 +00:00
if ( lesson_check_nickname ( $name )) {
redirect ( " view.php?id= $cm->id &action=updatehighscores&name= $name &sesskey= " . $USER -> sesskey , get_string ( " nameapproved " , " lesson " ));
2004-09-24 23:10:49 +00:00
} else {
echo get_string ( " namereject " , " lesson " ) . " <br><br> " ;
}
}
2005-02-23 00:52:29 +00:00
2004-09-24 23:10:49 +00:00
echo " <form name= \" nickname \" method = \" post \" action= \" view.php \" > " ;
2004-11-04 09:24:51 +00:00
echo " <input type= \" hidden \" name= \" id \" value= \" $cm->id\ " /> " ;
echo " <input type= \" hidden \" name= \" action \" value= \" nameforhighscores \" /> " ;
2005-02-23 00:52:29 +00:00
2004-11-04 09:24:51 +00:00
echo get_string ( " entername " , " lesson " ) . " : <input type= \" text \" name= \" name \" maxlength= \" 5 \" ><br /> " ;
echo " <input type= \" submit \" value= \" " . get_string ( " submitname " , " lesson " ) . " \" /> " ;
2004-09-24 23:10:49 +00:00
echo " </form> " ;
echo " </div> " ;
2005-03-05 00:09:39 +00:00
}
2004-09-15 20:32:24 +00:00
/*************** no man's land **************************************/
2004-09-24 23:10:49 +00:00
else {
error ( " Fatal Error: Unknown Action: " . $action . " \n " );
}
2004-02-16 05:41:13 +00:00
/// Finish the page
print_footer ( $course );
?>