aicc_api.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?php // $Id: $
  2. /**
  3. ==============================================================================
  4. * API event handler functions for AICC / CMIv4 in API communication mode
  5. *
  6. * @author Denes Nagy <darkden@freemail.hu>
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @version v 1.0
  9. * @access public
  10. * @package dokeos.learnpath
  11. * @license GNU/GPL - See Dokeos license directory for details
  12. ==============================================================================
  13. */
  14. /**
  15. * This script is divided into three sections.
  16. * The first section (below) is the initialisation part.
  17. * The second section is the AICC object part
  18. * The third section defines the event handlers for Dokeos' internal messaging
  19. * and frames refresh
  20. *
  21. * This script implements the API messaging for AICC. The HACP messaging is
  22. * made by another set of scripts.
  23. */
  24. /*
  25. ==============================================================================
  26. INIT SECTION
  27. ==============================================================================
  28. */
  29. //flag to allow for anonymous user - needs to be set before global.inc.php
  30. $use_anonymous = true;
  31. //Load common libraries using a compatibility script to bridge between 1.6 and 1.8
  32. require_once('back_compat.inc.php');
  33. //Load learning path libraries so we can use the objects to define the initial values
  34. //of the API
  35. require_once('learnpath.class.php');
  36. require_once('learnpathItem.class.php');
  37. require_once('aicc.class.php');
  38. // Is this needed? This is probabaly done in the header file
  39. // $_user = $_SESSION['_user'];
  40. $file = $_SESSION['file'];
  41. $oLP = unserialize($_SESSION['lpobject']);
  42. $oItem = $oLP->items[$oLP->current];
  43. if(!is_object($oItem)){
  44. error_log('New LP - scorm_api - Could not load oItem item',0);
  45. exit;
  46. }
  47. $autocomplete_when_80pct = 0;
  48. /*
  49. ==============================================================================
  50. JavaScript Functions
  51. ==============================================================================
  52. */
  53. ?>var scorm_logs=<?php echo (empty($oLP->scorm_debug)?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
  54. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  55. //logit_lms('scormfunctions.php included',0);
  56. function APIobject() {
  57. this.LMSInitialize=LMSInitialize;
  58. this.LMSGetValue=LMSGetValue;
  59. this.LMSSetValue=LMSSetValue;
  60. this.LMSCommit=LMSCommit;
  61. this.LMSFinish=LMSFinish;
  62. this.LMSGetLastError=LMSGetLastError;
  63. this.LMSGetErrorString=LMSGetErrorString;
  64. this.LMSGetDiagnostic=LMSGetDiagnostic;
  65. }
  66. //it is not sure that the scos use the above declarations
  67. API = new APIobject(); //for scorm 1.2
  68. var G_NoError = 0;
  69. var G_GeneralException = 101;
  70. var G_ServerBusy = 102;
  71. var G_InvalidArgumentError = 201;
  72. var G_ElementCannotHaveChildren = 202;
  73. var G_ElementIsNotAnArray = 203;
  74. var G_NotInitialized = 301;
  75. var G_NotImplementedError = 401;
  76. var G_InvalidSetValue = 402;
  77. var G_ElementIsReadOnly = 403;
  78. var G_ElementIsWriteOnly = 404;
  79. var G_IncorrectDataType = 405;
  80. var G_LastError = G_NoError ;
  81. var commit = false ;
  82. //Strictly scorm variables
  83. var score=<?php echo $oItem->get_score();?>;
  84. var max=<?php echo $oItem->get_max();?>;
  85. var min=<?php echo $oItem->get_min();?>;
  86. var lesson_status='<?php echo $oItem->get_status();?>';
  87. var session_time='<?php echo $oItem->get_scorm_time('js');?>';
  88. var suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  89. var lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  90. var total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  91. //Dokeos internal variables
  92. var saved_lesson_status = 'not attempted';
  93. var lms_lp_id = <?php echo $oLP->get_id();?>;
  94. var lms_item_id = <?php echo $oItem->get_id();?>;
  95. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  96. var lms_been_synchronized = 0;
  97. var lms_initialized = 0;
  98. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  99. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  100. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  101. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  102. var lms_view_id = '<?php echo $oLP->get_view();?>';
  103. if(lms_view_id == ''){ lms_view_id = 1;}
  104. var lms_user_id = '<?php echo $_user['user_id'];?>';
  105. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  106. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  107. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  108. var lms_item_type = '<?php echo $oItem->get_type();?>';
  109. //Backup for old values
  110. var old_score = 0;
  111. var old_max = 0;
  112. var old_min = 0;
  113. var old_lesson_status = '';
  114. var old_session_time = '';
  115. var old_suspend_data = '';
  116. var lms_old_item_id = 0;
  117. function LMSInitialize() { //this is the initialize function of all APIobjects
  118. logit_scorm('LMSInitialise()',0);
  119. lms_initialized=1;
  120. return('true');
  121. }
  122. function LMSGetValue(param) {
  123. //logit_scorm("LMSGetValue('"+param+"')",1);
  124. var result='';
  125. if(param=='cmi.core._children' || param=='cmi.core_children'){
  126. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  127. }else if(param == 'cmi.core.entry'){
  128. result='';
  129. }else if(param == 'cmi.core.exit'){
  130. result='';
  131. }else if(param == 'cmi.core.lesson_status'){
  132. if(lesson_status != '') {
  133. result=lesson_status;
  134. }
  135. else{
  136. result='not attempted';
  137. }
  138. }else if(param == 'cmi.core.student_id'){
  139. result='<?php echo $_user['user_id']; ?>';
  140. }else if(param == 'cmi.core.student_name'){
  141. <?php
  142. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  143. echo "result='$who';";
  144. ?>
  145. }else if(param == 'cmi.core.lesson_location'){
  146. result=lesson_location;
  147. }else if(param == 'cmi.core.total_time'){
  148. result=total_time;
  149. }else if(param == 'cmi.core.score._children'){
  150. result='raw,min,max';
  151. }else if(param == 'cmi.core.score.raw'){
  152. result=score;
  153. }else if(param == 'cmi.core.score.max'){
  154. result=max;
  155. }else if(param == 'cmi.core.score.min'){
  156. result=min;
  157. }else if(param == 'cmi.core.score'){
  158. result=score;
  159. }else if(param == 'cmi.core.credit'){
  160. result='no-credit';
  161. }else if(param == 'cmi.core.lesson_mode'){
  162. result='normal';
  163. }else if(param == 'cmi.suspend_data'){
  164. result='<?php echo $oItem->get_suspend_data();?>';
  165. }else if(param == 'cmi.launch_data'){
  166. result='';
  167. }else if(param == 'cmi.objectives._count'){
  168. result='<?php echo $oItem->get_view_count();?>';
  169. }
  170. /*
  171. //Switch not working??? WTF???
  172. switch(param) {
  173. case 'cmi.core._children' :
  174. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  175. break;
  176. case 'cmi.core_children' :
  177. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  178. break;
  179. case 'cmi.core.entry' :
  180. result='';
  181. break;
  182. case 'cmi.core.exit' :
  183. result='';
  184. break;
  185. case 'cmi.core.lesson_status' :
  186. if(lesson_status != '') {
  187. result=lesson_status;
  188. }
  189. else{
  190. result='not attempted';
  191. }
  192. break;
  193. case 'cmi.core.student_id' :
  194. result='<?php echo $_user['user_id']; ?>';
  195. break;
  196. case 'cmi.core.student_name' :
  197. <?php
  198. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  199. echo "result='$who';";
  200. ?> break;
  201. case 'cmi.core.lesson_location' :
  202. result='';
  203. break;
  204. case 'cmi.core.total_time' :
  205. result=total_time;
  206. break;
  207. case 'cmi.core.score._children' :
  208. result='raw,min,max';
  209. break;
  210. case 'cmi.core.score.raw' :
  211. result=score;
  212. break;
  213. case 'cmi.core.score.max' :
  214. result=max;
  215. break;
  216. case 'cmi.core.score.min' :
  217. result=min;
  218. break;
  219. case 'cmi.core.score' :
  220. result=score;
  221. break;
  222. case 'cmi.core.credit' :
  223. result='no-credit';
  224. break;
  225. case 'cmi.core.lesson_mode' :
  226. result='normal';
  227. break;
  228. case 'cmi.suspend_data' :
  229. result='<?php echo $oItem->get_suspend_data();?>';
  230. break;
  231. case 'cmi.launch_data' :
  232. result='';
  233. break;
  234. case 'cmi.objectives._count':
  235. result='<?php echo $oItem->get_view_count();?>';
  236. break;
  237. default :
  238. result='';
  239. break;
  240. }
  241. */
  242. logit_scorm("LMSGetValue('"+param+"') returned '"+result+"'",1);
  243. return result;
  244. }
  245. function LMSSetValue(param, val) {
  246. logit_scorm("LMSSetValue('"+param+"','"+val+"')",0);
  247. switch(param) {
  248. case 'cmi.core.score.raw' : score= val ; break;
  249. case 'cmi.core.score.max' : max = val; break;
  250. case 'cmi.core.score.min' : min = val; break;
  251. case 'cmi.core.lesson_location' : lesson_location = val;break;
  252. case 'cmi.core.lesson_status' :
  253. saved_lesson_status = lesson_status;
  254. lesson_status = val;
  255. <?php if($oLP->mode != 'fullscreen'){ ?>
  256. //var update = update_toc(lesson_status,lms_item_id);
  257. <?php } ?>
  258. break;
  259. case 'cmi.completion_status' : lesson_status = val; break; //1.3
  260. case 'cmi.core.session_time' : session_time = val; break;
  261. case 'cmi.score.scaled' : score = val ; break; //1.3
  262. case 'cmi.success_status' : success_status = val; break; //1.3
  263. case 'cmi.suspend_data' : suspend_data = val; break;
  264. }
  265. //var update = update_toc();
  266. //var update_progress = update_progress_bar();
  267. <?php
  268. if ($oLP->force_commit == 1){
  269. echo " var mycommit = LMSCommit('force');";
  270. }
  271. ?>
  272. return(true);
  273. }
  274. function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
  275. <?php if ($autocomplete_when_80pct){ ?>
  276. if( ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ){
  277. lesson_status = 'completed';
  278. }
  279. <?php }?>
  280. param = 'id='+lms_item_id+'&origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
  281. url="http://<?php
  282. $self=api_get_self();
  283. $url=$_SERVER['HTTP_HOST'].$self;
  284. $url=substr($url,0,-14);//14 is the length of this file's name (/scorm_api.php)
  285. echo $url;
  286. ?>/lp_controller.php?cidReq=<?php echo api_get_course_id();?>&action=save&lp_id=<?php echo $oLP->get_id();?>&" + param + "";
  287. logit_lms('saving data (status='+lesson_status+')',1);
  288. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
  289. //xajax_update_pgs();
  290. //xajax_update_toc();
  291. }
  292. function LMSCommit(val) {
  293. logit_scorm('LMSCommit()',0);
  294. commit = true ;
  295. savedata('commit');
  296. return('true');
  297. }
  298. function LMSFinish(val) {
  299. if (( commit == false )) {
  300. logit_scorm('LMSFinish() (no LMSCommit())',1);
  301. }
  302. if ( commit == true ) {
  303. logit_scorm('LMSFinish() called',1);
  304. savedata('finish');
  305. }
  306. return('true');
  307. }
  308. function LMSGetLastError() {
  309. logit_scorm('LMSGetLastError()',1);
  310. return(G_LastError);
  311. }
  312. function LMSGetErrorString(errCode){
  313. logit_scorm('LMSGetErrorString()',1);
  314. return('No error !');
  315. }
  316. function LMSGetDiagnostic(errCode){
  317. logit_scorm('LMSGetDiagnostic()',1);
  318. return(API.LMSGetLastError());
  319. }
  320. <?php
  321. //--------------------------------------------------------------------//
  322. /**
  323. * Dokeos-specific code that deals with event handling and inter-frames
  324. * messaging/refreshing.
  325. * Note that from now on, the Dokeos JS code in this library will act as
  326. * a controller, of the MVC pattern, and receive all requests for frame
  327. * updates, then redispatch to any frame concerned.
  328. */
  329. ?>
  330. /**
  331. * Defining the AJAX-object class to be made available from other frames
  332. */
  333. function XAJAXobject() {
  334. this.xajax_switch_item_details=xajax_switch_item_details;
  335. this.switch_item=switch_item;
  336. }
  337. //it is not sure that the scos use the above declarations
  338. oXAJAX = new XAJAXobject();
  339. oxajax = new XAJAXobject();
  340. /**
  341. * Cross-browser event handling by Scott Andrew
  342. * @param element Element that needs an event attached
  343. * @param string Event type (load, unload, click, keyDown, ...)
  344. * @param string Function name (the event handler)
  345. * @param string used in addEventListener
  346. */
  347. function addEvent(elm, evType, fn, useCapture){
  348. if(elm.addEventListener){
  349. elm.addEventListener(evType, fn, useCapture);
  350. return true;
  351. }else if (elm.attachEvent){
  352. var r = elm.attachEvent('on' + evType, fn);
  353. }else{
  354. elm['on'+evType] = fn;
  355. }
  356. }
  357. /**
  358. * Add listeners to the page objects. This has to be defined for
  359. * the current context as it acts on objects that should exist
  360. * on the page
  361. */
  362. function addListeners(){
  363. //exit if the browser doesn't support ID or tag retrieval
  364. logit_lms('Entering addListeners()',2);
  365. if(!document.getElementsByTagName){
  366. logit_lms("getElementsByTagName not available",2);
  367. return;
  368. }
  369. if(!document.getElementById){
  370. logit_lms("getElementById not available",2);
  371. return;
  372. }
  373. //assign event handlers to objects
  374. if(lms_lp_type==1 || lms_item_type=='asset'){
  375. logit_lms('Dokeos LP or asset',2);
  376. //if this path is a Dokeos learnpath, then start manual save
  377. //when something is loaded in there
  378. var myelem = document.getElementById('content_id');
  379. if(!myelem){logit_lms("Impossible to find content_id element in document",2);}
  380. addEvent(myelem,'unload',dokeos_save_asset,false);
  381. logit_lms('Added event listener on content_id for unload',2);
  382. }
  383. logit_lms('Quitting addListeners()',2);
  384. }
  385. /**
  386. * Load an item into the content frame:
  387. * - making sure the previous item status have been saved
  388. * - first updating the current item ID (to save the right item)
  389. * - updating the frame src
  390. */
  391. function load_item(item_id,url){
  392. if(document.getElementById('content_id'))
  393. {
  394. logit_lms('Loading item '+item_id,2);
  395. var cont_f = document.getElementById('content_id');
  396. if(cont_f.src){
  397. lms_old_item_id = lms_item_id;
  398. var lms_new_item_id = item_id;
  399. //load new content page into content frame
  400. if(lms_lp_type==1 || lms_item_type=='asset'){
  401. dokeos_save_asset();
  402. }
  403. cont_f.src = url;
  404. update_toc('unhighlight',lms_old_item_id);
  405. update_toc('highlight',item_id);
  406. /* legacy code
  407. lms_been_synchronized = 0;
  408. lms_initialized = 0;
  409. if(lms_lp_type==1 || lms_item_type=='asset'){
  410. lms_item_id = lms_new_item_id;
  411. }*/
  412. return true;
  413. }
  414. logit_lms('cont_f.src has no properties',0);
  415. }
  416. logit_lms('content_id has no properties',0);
  417. return false;
  418. }
  419. /**
  420. * Save a Dokeos learnpath item's time and mark as completed upon
  421. * leaving it
  422. */
  423. function dokeos_save_asset(){
  424. //var linkparams = 'id='+lms_item_id+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
  425. //var url = "<?php echo api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php' ?>?action=save&" + linkparams + "";
  426. logit_lms('dokeos_save_asset: '+url,0);
  427. //frames["message_name"].src = url;
  428. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
  429. }
  430. /**
  431. * Logs information about SCORM messages into the log frame
  432. * @param string Message to log
  433. * @param integer Priority (0 for top priority, 3 for lowest)
  434. */
  435. function logit_scorm(message,priority){
  436. if(frames["lp_log_name"] && scorm_logs>priority){
  437. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "AICC: " + message + "<br/>";
  438. }
  439. }
  440. /**
  441. * Logs information about LMS activity into the log frame
  442. * @param string Message to log
  443. * @param integer Priority (0 for top priority, 3 for lowest)
  444. */
  445. function logit_lms(message,priority){
  446. if(frames["lp_log_name"] && lms_logs>priority){
  447. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "LMS: " + message + "<br/>";
  448. }
  449. }
  450. /**
  451. * update the Table Of Contents frame, by changing CSS styles, mostly
  452. * @param string Action to be taken
  453. * @param integer Item id to update
  454. */
  455. function update_toc(update_action,update_id)
  456. {
  457. <?php if($oLP->mode != 'fullscreen'){ ?>
  458. var myframe = frames["toc_name"];
  459. var myelem = myframe.document.getElementById("toc_"+update_id);
  460. var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
  461. logit_lms('update_toc('+update_action+','+update_id+')',2);
  462. if(update_id != 0){
  463. switch(update_action){
  464. case 'unhighlight':
  465. myelem.className = "scorm_item";
  466. break;
  467. case 'highlight':
  468. myelem.className = "scorm_item_highlight";
  469. break;
  470. case 'not attempted':
  471. if(myelemimg.src != '../img/notattempted.gif'){
  472. myelemimg.src = "../img/notattempted.gif";
  473. myelemimg.alt = "not attempted";
  474. }
  475. break;
  476. case 'incomplete':
  477. if(myelemimg.src != '../img/incomplete.gif'){
  478. myelemimg.src = "../img/incomplete.gif";
  479. myelemimg.alt = "incomplete";
  480. }
  481. break;
  482. case 'completed':
  483. if(myelemimg.src != '../img/completed.gif'){
  484. myelemimg.src = "../img/completed.gif";
  485. myelemimg.alt = "completed";
  486. }
  487. break;
  488. case 'failed':
  489. if(myelemimg.src != '../img/failed.gif'){
  490. myelemimg.src = "../img/failed.gif";
  491. myelemimg.alt = "failed";
  492. }
  493. break;
  494. case 'passed':
  495. if(myelemimg.src != '../img/completed.gif' && myelemimg.alt != 'passed'){
  496. myelemimg.src = "../img/completed.gif";
  497. myelemimg.alt = "passed";
  498. }
  499. break;
  500. case 'browsed':
  501. if(myelemimg.src != '../img/completed.gif' && myelemimg.alt != 'browsed'){
  502. myelemimg.src = "../img/completed.gif";
  503. myelemimg.alt = "browsed";
  504. }
  505. break;
  506. default:
  507. logit_lms('Update action unknown',2);
  508. break;
  509. }
  510. }
  511. return true;
  512. <?php } ?>
  513. return true;
  514. }
  515. /**
  516. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  517. * @param integer Number of completed items
  518. * @param integer Number of items in total
  519. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  520. */
  521. function update_progress_bar(nbr_complete, nbr_total, mode)
  522. {
  523. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  524. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  525. var myframe = frames["nav_name"];
  526. if(myframe){
  527. if(mode == ''){mode='%';}
  528. if(nbr_total == 0){nbr_total=1;}
  529. var percentage = (nbr_complete/nbr_total)*100;
  530. percentage = Math.round(percentage);
  531. var pr_text = myframe.document.getElementById('progress_text');
  532. var pr_full = myframe.document.getElementById('progress_img_full');
  533. var pr_empty = myframe.document.getElementById('progress_img_empty');
  534. pr_full.width = percentage;
  535. pr_empty.width = 100-percentage;
  536. var mytext = '';
  537. switch(mode){
  538. case 'abs':
  539. mytext = nbr_complete + '/' + nbr_total;
  540. break;
  541. case '%':
  542. default:
  543. mytext = percentage + '%';
  544. break;
  545. }
  546. pr_text.innerHTML = mytext;
  547. }
  548. return true;
  549. }
  550. function update_stats_page()
  551. {
  552. var myframe = document.getElementById('content_id');
  553. var mysrc = myframe.location.href;
  554. if(mysrc == 'lp_controller.php?action=stats'){
  555. if(myframe && myframe.src){
  556. var mysrc = myframe.src;
  557. myframe.src = mysrc;
  558. }
  559. // = mysrc; //refresh page
  560. }
  561. return true;
  562. }
  563. /**
  564. * Updates the message frame with the given string
  565. */
  566. function update_message_frame(msg_msg)
  567. {
  568. if(msg_msg==null){msg_msg='';}
  569. var msg_f = frames["message_name"];
  570. if(!msg_f.document || !msg_f.document.getElementById('msg_div_id')){
  571. logit_lms('In update_message_frame() - message frame has no document property',0);
  572. }else{
  573. logit_lms('In update_message_frame() - updating frame',0);
  574. msg_f.document.getElementById('msg_div_id').innerHTML= msg_msg;
  575. }
  576. }
  577. /**
  578. * Function that handles the saving of an item and switching from an item to another.
  579. * Once called, this function should be able to do the whole process of (1) saving the
  580. * current item, (2) refresh all the values inside the SCORM API object, (3) open the
  581. * new item into the content_id frame, (4) refresh the table of contents, (5) refresh
  582. * the progress bar (completion), (6) refresh the message frame
  583. * @param integer Dokeos ID for the current item
  584. * @param string This parameter can be a string specifying the next
  585. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  586. */
  587. function switch_item(current_item, next_item){
  588. /*
  589. if(!current_item){
  590. logit_lms('In switch - no current_item defined',0);
  591. }
  592. if(!next_item){
  593. logit_lms('In switch - no next_item defined',0);
  594. }
  595. */
  596. if(lms_item_id == next_item){
  597. return; //nothing to switch
  598. }
  599. //(1) save the current item
  600. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  601. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
  602. //(2) Refresh all the values inside this SCORM API object - use AJAX
  603. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  604. //(3) open the new item in the content_id frame
  605. var cont_f = document.getElementById('content_id');
  606. if(!cont_f){logit_lms('In switch - content frame not found',0);return false;}
  607. switch(next_item){
  608. case 'next':
  609. next_item = lms_next_item;
  610. break;
  611. case 'previous':
  612. next_item = lms_previous_item;
  613. break;
  614. default:
  615. break;
  616. }
  617. cont_f.src = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  618. //(4) refresh table of contents
  619. /*
  620. var toc_f = document.getElementById('toc_id');
  621. if(!toc_f){logit_lms('In switch - toc frame not found',0);return false;}
  622. var myrefresh = toc_f.src;
  623. toc_f.src = myrefresh;
  624. */
  625. //(5) refresh the progress bar
  626. /*
  627. var prg_f = document.getElementById('nav_id');
  628. if(!prg_f){logit_lms('In switch - navigation frame not found',0);return false;}
  629. var myrefresh = prg_f.src;
  630. prg_f.src = myrefresh;
  631. */
  632. //(6) refresh the message box (included in switch_item_details)
  633. return true;
  634. }
  635. /**
  636. * Save a specific item (with its interactions, if any) into the LMS through
  637. * an AJAX call. Originally, we used the xajax library. Now we use jQuery.
  638. * Because of the need to pass an array, we have to build the parameters
  639. * manually into GET[]
  640. */
  641. function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit) {
  642. params='';
  643. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  644. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  645. params += '&status='+lesson_status+'&t='+session_time;
  646. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  647. params += '&core_exit='+lms_item_core_exit;
  648. interact_string = '';
  649. for (i in interactions){
  650. interact_string += '&interact['+i+']=';
  651. interact_temp = '[';
  652. for (j in interactions[i]) {
  653. interact_temp += interactions[i][j]+',';
  654. }
  655. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  656. interact_string += encodeURIComponent(interact_temp);
  657. }
  658. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  659. params += interact_string;
  660. /*params = {
  661. 'lid': lms_lp_id,
  662. 'uid': lms_user_id,
  663. 'vid': lms_view_id,
  664. 'iid': lms_item_id,
  665. 's': score,
  666. 'max': max,
  667. 'min': min,
  668. 'status': lesson_status,
  669. 't': session_time,
  670. 'suspend': suspend_data,
  671. 'loc': lesson_location,
  672. 'interact': interac_string,
  673. 'core_exit': lms_item_core_exit
  674. }
  675. */
  676. $.ajax({
  677. type:"GET",
  678. data: params,
  679. url: "lp_ajax_save_item.php",
  680. dataType: "script",
  681. async: false
  682. }
  683. );
  684. }
  685. /**
  686. * Starts the timer with the server clock time.
  687. * Originally, we used the xajax library. Now we use jQuery
  688. */
  689. function xajax_start_timer() {
  690. $.ajax({
  691. type: "GET",
  692. url: "lp_ajax_start_timer.php",
  693. dataType: "script",
  694. async: false
  695. });
  696. }
  697. /**
  698. * Save a specific item's objectives into the LMS through
  699. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  700. */
  701. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  702. params='';
  703. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  704. params += '&iid='+lms_item_id;
  705. obj_string = '';
  706. for (i in item_objectives){
  707. obj_string += '&objectives['+i+']=';
  708. obj_temp = '[';
  709. for (j in item_objectives[i]) {
  710. obj_temp += item_objectives[i][j]+',';
  711. }
  712. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  713. obj_string += encodeURIComponent(obj_temp);
  714. }
  715. params += obj_string;
  716. $.ajax({
  717. type: "GET",
  718. data: params,
  719. url: "lp_ajax_save_objectives.php",
  720. dataType: "script",
  721. async: false
  722. });
  723. }
  724. /**
  725. * Switch between two items through
  726. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  727. */
  728. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  729. params = {
  730. 'lid': lms_lp_id,
  731. 'uid': lms_user_id,
  732. 'vid': lms_view_id,
  733. 'iid': lms_item_id,
  734. 'next': next_item
  735. }
  736. $.ajax({
  737. type: "GET",
  738. data: params,
  739. url: "lp_ajax_switch_item.php",
  740. dataType: "script",
  741. async: false
  742. });
  743. }
  744. addEvent(window,'load',addListeners,false);