Step 53 – Delaying the Closing Sequence

I’m still trying to fix the problem that my reader’s SCO highlighted (described in this post). I’ve implemented the optional data element that it’s trying to use – cmi.comments – but that hasn’t fixed the problem. So I need to look elsewhere.

The SCO is trying to save the user’s comments to the LMS database when the SCO is closed. So, perhaps, the API code isn’t being given enough time to commit all of the data values to the database before everything shuts down.

To try to fix this, I’m going to add a delay to the closing sequence. As a reminder, here’s what my rte.php looks like right now.

<?php 

/*

VS SCORM 1.2 RTE - rte.php
Rev 2009-11-30-01
Copyright (C) 2009, Addison Robson LLC

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA	02110-1301, USA.

*/

// read SCOInstanceID from the GET parameters
$SCOInstanceID = $_GET['SCOInstanceID'] * 1;

?>
<html>
<head>
	<title>VS SCORM</title>
</head>
<frameset 
  frameborder="0" 
  framespacing="0" 
  border="0" 
  rows="100,*" 
  cols="*" 
  onbeforeunload="API.LMSFinish('');" 
  onunload="API.LMSFinish('');">
	<frame src="api.php?SCOInstanceID=<?php print $SCOInstanceID; ?>" name="API">
	<frame src="... location of the course ..." name="course">
</frameset>
</html>

In lines 40 and 41 of the listing above, you’ll see that I’ve arranged for the LMSFinish() function to be called directly when the frameset tries to close down. I’m now going to change this by making the frameset call a Javascript function called unloadSCO() which, in turn, calls LMSFinish() after a delay. I’ve also taken the opportunity to re-name the frame from ‘course’ to ‘SCO’ to make the SCORM purists happy!

<?php 

/*

VS SCORM 1.2 RTE - rte.php
Rev XXXXXXXXXXX was 2009-11-30-01
Copyright (C) 2010, Addison Robson LLC

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA	02110-1301, USA.

*/

// read SCOInstanceID from the GET parameters
$SCOInstanceID = $_GET['SCOInstanceID'] * 1;

?>
<html>
<head>
	<title>VS SCORM</title>
	<script language="javascript">
		function unloadSCO() {
			setTimeout('API.LMSFinish("");',2000);
		}
	</script>
</head>
<frameset 
  frameborder="0" 
  framespacing="0" 
  border="0" 
  rows="50,*" 
  cols="*" 
  onbeforeunload="unloadSCO();" 
  onunload="unloadSCO();">
	<frame src="api.php?SCOInstanceID=<?php print $SCOInstanceID; ?>" name="API" id="API" noresize">
	<frame src="... location of the course ..." name="SCO" id="SCO">
</frameset>
</html>

I now try it again, and it works! The students can write notes and they’re successfully saved to the database when the course closes.

But that’s not the end of things …

This entry was posted in Run Time Environment. Bookmark the permalink.

4 Responses to Step 53 – Delaying the Closing Sequence

  1. Dilson Beltran says:

    When you load the browser flash SCO can not find the API.
    To fix the problem with the following code:

    HTML.

    <frame src="loadSCO.php?url= " name="SCO" id="SCO">

    PHP. loadSCO.php

    $url = $_GET['url'];
    sleep(3);
    header("location: $url");

    Thanks for the vsscorm. it’s great.

  2. Steve Addison says:

    Thanks, Dilson. I wonder if this is the same problem that was being experienced by reader ‘deighvan’ (see his comment here)? deighvan’s comment included a fix that seems to work pretty well, and I plan to incorporate it in a future release of the VSSCORM RTE.

  3. xabi says:

    HI!
    is onbeforeunload (or just unload) working in chrome?i can´t save my data when the learner is closing if it´s not working, any ideas?Thank you very much in advance!

  4. Steve Addison says:

    Sorry – can’t help on this one. I don’t use Chrome myself, and can’t find a definitive statement on the Web. Maybe another reader can help.

Leave a Reply

Your email address will not be published. Required fields are marked *