diff --git a/main/newscorm/lp_ajax_last_update_status.php b/main/newscorm/lp_ajax_last_update_status.php new file mode 100644 index 0000000000..76ca307206 --- /dev/null +++ b/main/newscorm/lp_ajax_last_update_status.php @@ -0,0 +1,125 @@ + + */ +//flag to allow for anonymous user - needs to be set before global.inc.php +$use_anonymous = true; +// name of the language file that needs to be included +$language_file[] = 'learnpath'; +require_once('back_compat.inc.php'); +/** + * Writes an item's new values into the database and returns the operation result + * @param integer Learnpath ID + * @param integer User ID + * @param integer View ID + * @param integer Item ID + * @return string JavaScript operations to execute as soon as returned + */ +function last_update_status($lp_id,$user_id,$view_id,$item_id) +{ + error_log(__LINE__); + global $_configuration; + $debug=0; + $return = ''; + if($debug>0){error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')',0);} + require_once('learnpath.class.php'); + require_once('scorm.class.php'); + require_once('learnpathItem.class.php'); + require_once('scormItem.class.php'); + $mylp = ''; + if(isset($_SESSION['lpobject'])) + { + if($debug>1){error_log('////$_SESSION[lpobject] is set',0);} + $oLP =& unserialize($_SESSION['lpobject']); + if(!is_object($oLP)){ + if($debug>2){error_log(print_r($oLP,true),0);} + if($debug>2){error_log('////Building new lp',0);} + unset($oLP); + $code = api_get_course_id(); + $mylp = & new learnpath($code,$lp_id,$user_id); + }else{ + if($debug>2){error_log('////Reusing session lp',0);} + $mylp = & $oLP; + } + } + error_log(__LINE__); + + // this function should only be used for SCORM paths + if ($mylp->get_type()!=2) { + return; + } + $prereq_check = $mylp->prerequisites_match($item_id); + $mystatus = ''; + if ($prereq_check === true) { + error_log(__LINE__); + //launch the prerequisites check and set error if needed + $mylpi =& $mylp->items[$item_id]; + + $mystatus_in_db = $mylpi->get_status(true); + error_log($mystatus_in_db); + if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') { + error_log(__LINE__); + $mystatus = 'completed'; + $mastery_score = $mylpi->get_mastery_score(); + if ($mastery_score != -1) { + error_log(__LINE__); + $score = $mylpi->get_score(); + if ($score != 0 && $score >= $mastery_score) { + error_log(__LINE__); + $mystatus = 'passed'; + } else { + error_log(__LINE__); + $mystatus = 'failed'; + } + } + error_log(__LINE__); + $mylpi->set_status($mystatus); + $mylp->save_item($item_id,false); + } else { + error_log(__LINE__); + return $return; + } + } else { + error_log(__LINE__); + return $return; + } + error_log(__LINE__); + $mytotal = $mylp->get_total_items_count_without_chapters(); + $mycomplete = $mylp->get_complete_items_count(); + $myprogress_mode = $mylp->get_progress_bar_mode(); + $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode); + $return .= "update_toc('".$mystatus."','".$item_id."','no');"; + error_log('Return is now '.$return); + $update_list = $mylp->get_update_queue(); + foreach ($update_list as $my_upd_id => $my_upd_status) { + if ($my_upd_id != $item_id) { //only update the status from other items (i.e. parents and brothers), do not update current as we just did it already + $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');"; + } + } + $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');"; + $return .="update_stats();"; + return $return; + //return $objResponse; +} +error_log(__LINE__); +echo last_update_status( + $_GET['lid'], + $_GET['uid'], + $_GET['vid'], + $_GET['iid']); \ No newline at end of file diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index edba0789c4..51cd758af7 100644 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1,4 +1,4 @@ -mode != 'fullscreen'){ ?> - //var myframe = frames["toc_name"]; - //var myelem = myframe.document.getElementById("toc_"+update_id); - //var myelemimg = myframe.document.getElementById("toc_img_"+update_id); - + if (!change_ids || change_ids != 'no') { + change_ids = 'yes'; + } var myelem = $("#toc_"+update_id); var myelemimg = $("#toc_img_"+update_id); logit_lms('update_toc("'+update_action+'",'+update_id+')',2); @@ -1085,8 +1083,10 @@ function update_toc(update_action,update_id) } break; case 'highlight': - lms_next_item = update_id; - lms_previous_item = update_id; + if (change_ids=='yes') { + lms_next_item = update_id; + lms_previous_item = update_id; + } myelem.attr('class',"scorm_item_highlight"); break; case 'not attempted': @@ -1131,8 +1131,6 @@ function update_toc(update_action,update_id) } } return true; - - //return true; } function update_stats() { @@ -1226,6 +1224,10 @@ function update_message_frame(msg_msg) */ function switch_item(current_item, next_item) { + //backup these params + var orig_current_item = current_item; + var orig_next_item = next_item; + var orig_lesson_status = lesson_status; //(1) save the current item logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0); if (lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){ @@ -1344,7 +1346,17 @@ function switch_item(current_item, next_item) { $("#media").html(tmp_data); } }); - +/* + if ( lms_lp_type==2 && (orig_lesson_status == 'not attempted' || orig_lesson_status == '') && orig_current_item != orig_next_item) { + params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+orig_current_item; + $.ajax({ + type:"GET", + data: params, + url: "lp_ajax_last_update_status.php", + dataType: "script" + }); + } +*/ return true; } /**