From 76d3542313253ccb5dca3fe412aee2165e20897b Mon Sep 17 00:00:00 2001 From: bobopinna Date: Mon, 21 Jun 2004 11:27:52 +0000 Subject: [PATCH] Added popup window scorm player and its settings --- mod/scorm/api1_2.php | 76 ++++++++------- mod/scorm/config.html | 50 ++++++++++ mod/scorm/db/mysql.php | 9 +- mod/scorm/db/mysql.sql | 3 +- mod/scorm/db/postgres7.php | 12 ++- mod/scorm/db/postgres7.sql | 3 +- mod/scorm/details.php | 107 ++++++++++++++++++++- mod/scorm/lib.php | 50 +++++++++- mod/scorm/mod.html | 13 --- mod/scorm/playscorm.php | 184 ++++++++++++++++++++++++++++++------- mod/scorm/report.php | 2 + mod/scorm/scormAPI.php | 4 +- mod/scorm/version.php | 2 +- mod/scorm/view.php | 8 +- 14 files changed, 420 insertions(+), 103 deletions(-) create mode 100755 mod/scorm/config.html diff --git a/mod/scorm/api1_2.php b/mod/scorm/api1_2.php index 6b5e8b1137..360e981a6c 100644 --- a/mod/scorm/api1_2.php +++ b/mod/scorm/api1_2.php @@ -1,47 +1,11 @@ -// -// CMI Initialization SCORM 1.2 -// - var cmi= new Object(); - - cmi.core = new Object(); - cmi.core._children = "student_id,student_name,lesson_location,credit,lesson_status,exit,entry,session_time,total_time,lesson_mode,score,suspend_data,launch_data"; - cmi.core.student_id = "username; ?>"; - cmi.core.student_name = "firstname." ".$USER->lastname; ?>"; - cmi.core.lesson_location = "cmi_core_lesson_location; ?>"; - cmi.core.credit = "credit"; - cmi.core.lesson_status = "cmi_core_lesson_status; ?>"; - cmi.core.exit = "cmi_core_exit ?>"; - cmi.core.entry = "cmi_core_lesson_status=="not attempted") - echo 'ab-initio'; - else - if ($sco_user->cmi_core_lesson_status!="completed") - echo 'resume'; - else - echo '';?>"; - cmi.core.session_time = "cmi_core_session_time; ?>"; - cmi.core.total_time = "cmi_core_total_time; ?>"; - cmi.core.lesson_mode = ""; - - cmi.core.score = new Object(); - cmi.core.score._children = "raw,min,max"; - cmi.core.score.raw = "cmi_core_score_raw; ?>"; - cmi.suspend_data = "cmi_suspend_data; ?>"; - cmi.launch_data = "cmi_launch_data; ?>"; -/* cmi.interactions = new Object(); - cmi.interactions._children = "id,objectives,time,type,correct_responses,weighting,student_response,result,latency"; - cmi.interactions._count = 0; -*/ - var errorCode = 0; - -// -// end CMI Initialization -// - - // // SCORM API 1.2 Implementation // function SCORMapi() { + var cmi= new Object(); + + var errorCode = 0; + var Initialized = false; function LMSInitialize (param) { @@ -52,6 +16,37 @@ function SCORMapi() { if (!Initialized) { Initialized = true; errorCode = 0; + + // + // CMI Initialization SCORM 1.2 + // + cmi.core = new Object(); + cmi.core._children = "student_id,student_name,lesson_location,credit,lesson_status,exit,entry,session_time,total_time,lesson_mode,score,suspend_data,launch_data"; + cmi.core.student_id = "username; ?>"; + cmi.core.student_name = "firstname." ".$USER->lastname; ?>"; + cmi.core.lesson_location = "cmi_core_lesson_location; ?>"; + cmi.core.credit = "credit"; + cmi.core.lesson_status = "cmi_core_lesson_status; ?>"; + cmi.core.exit = "cmi_core_exit ?>"; + cmi.core.entry = "cmi_core_lesson_status=="not attempted") + echo 'ab-initio'; + else + if ($sco_user->cmi_core_lesson_status!="completed") + echo 'resume'; + else + echo '';?>"; + cmi.core.session_time = ""; + cmi.core.total_time = "cmi_core_total_time; ?>"; + cmi.core.lesson_mode = ""; + cmi.core.score = new Object(); + cmi.core.score._children = "raw,min,max"; + cmi.core.score.raw = "cmi_core_score_raw; ?>"; + cmi.suspend_data = "cmi_suspend_data; ?>"; + cmi.launch_data = "cmi_launch_data; ?>"; + // + // end CMI Initialization + // + return "true"; } else { errorCode = 101; @@ -277,6 +272,7 @@ function SCORMapi() { return hours + ":" + mins + ":" + secs; } + this.LMSInitialize = LMSInitialize; this.LMSGetValue = LMSGetValue; this.LMSSetValue = LMSSetValue; diff --git a/mod/scorm/config.html b/mod/scorm/config.html new file mode 100755 index 0000000000..b4c8e24829 --- /dev/null +++ b/mod/scorm/config.html @@ -0,0 +1,50 @@ +
+ + + + + + + + + + + + +"; + echo ""; + echo ""; + echo ""; + echo ""; + } +?> + + + +

scorm_framesize:

+ + + +

scorm_popup:

+ scorm_popup, ""); + ?> + + +

$defaultvalue:

"; + if ($optionname == "height" or $optionname == "width") { + echo "$defaultvalue."\">"; + } else { + choose_from_menu ($choices, $defaultvalue, $CFG->$defaultvalue, ""); + } + echo ""; + print_string("configpopup$optionname", "scorm"); + echo "
+ ">
+ +
diff --git a/mod/scorm/db/mysql.php b/mod/scorm/db/mysql.php index d9ae381bb2..d1aaf486fd 100755 --- a/mod/scorm/db/mysql.php +++ b/mod/scorm/db/mysql.php @@ -5,14 +5,17 @@ function scorm_upgrade($oldversion) { /// older versions to match current functionality global $CFG; if ($oldversion < 2004033000) { - execute_sql(" ALTER TABLE `{$CFG->prefix}scorm` ADD `auto` TINYINT( 1 ) UNSIGNED DEFAULT '0' NOT NULL AFTER `summary`"); + table_column("scorm", "", "auto", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "summary"); } if ($oldversion < 2004040900) { - execute_sql(" ALTER TABLE `{$CFG->prefix}scorm_sco_users` ADD `cmi_core_score_raw` FLOAT( 3 ) DEFAULT '0' NOT NULL AFTER `cmi_core_session_time`"); + table_column("scorm_sco_users", "", "cmi_core_score_raw", "FLOAT", "3", "", "0", "NOT NULL", "cmi_core_session_time"); + } + if ($oldversion < 2004061800) { + table_column("scorm", "", "popup", "VARCHAR", "255", "", "", "NOT NULL", "auto"); + table_column("scorm", "reference", "reference", "VARCHAR", "255", "", "", "NOT NULL"); } return true; } ?> - diff --git a/mod/scorm/db/mysql.sql b/mod/scorm/db/mysql.sql index 58b2046730..4a19a1cf1f 100755 --- a/mod/scorm/db/mysql.sql +++ b/mod/scorm/db/mysql.sql @@ -6,11 +6,12 @@ CREATE TABLE prefix_scorm ( id int(10) unsigned NOT NULL auto_increment, course int(10) unsigned NOT NULL default '0', name varchar(255) NOT NULL default '', - reference varchar(255) default NULL, + reference varchar(255) NOT NULL default '', datadir varchar(255) NOT NULL default '', launch int(10) unsigned NOT NULL default 0, summary text NOT NULL, auto tinyint(1) unsigned NOT NULL default '0', + popup varchar(255) NOT NULL default '', timemodified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), UNIQUE KEY id (id) diff --git a/mod/scorm/db/postgres7.php b/mod/scorm/db/postgres7.php index 90c53dd8d8..b56d414d1e 100755 --- a/mod/scorm/db/postgres7.php +++ b/mod/scorm/db/postgres7.php @@ -3,7 +3,17 @@ function scorm_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality - + global $CFG; + if ($oldversion < 2004033000) { + table_column("scorm", "", "auto", "integer", "1", "", "0", "NOT NULL", "summary"); + } + if ($oldversion < 2004040900) { + table_column("scorm_sco_users", "", "cmi_core_score_raw", "real", "3", "", "0", "NOT NULL", "cmi_core_session_time"); + } + if ($oldversion < 2004061800) { + table_column("scorm", "", "popup", "varchar", "255", "", "", "NOT NULL", "auto"); + table_column("scorm", "reference", "reference", "varchar", "255", "", "", "NOT NULL"); + } return true; } diff --git a/mod/scorm/db/postgres7.sql b/mod/scorm/db/postgres7.sql index aa2df46c22..8d0d21c48c 100755 --- a/mod/scorm/db/postgres7.sql +++ b/mod/scorm/db/postgres7.sql @@ -6,11 +6,12 @@ CREATE TABLE prefix_scorm ( id SERIAL PRIMARY KEY, course integer NOT NULL default '0', name varchar(255) NOT NULL default '', - reference varchar(255) default NULL, + reference varchar(255) NOT NULL default '', datadir varchar(255) NOT NULL default '', launch integer NOT NULL default '0', summary text NOT NULL default '', auto integer NOT NULL default '0', + popup varchar(255) NOT NULL default '', timemodified integer NOT NULL default '0' ); diff --git a/mod/scorm/details.php b/mod/scorm/details.php index f4e60fac1e..f2bc1f59c5 100755 --- a/mod/scorm/details.php +++ b/mod/scorm/details.php @@ -79,16 +79,119 @@ echo "\n"; echo " \n"; echo " \n"; - if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_user","scormid",$form->instance))) + if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance))) echo " \n"; echo "

$strname:

$form->name

".get_string("validation","scorm").":

".get_string($result,"scorm")."

".get_string("trackingloose","scorm")."

\n"; if ($result == "regular") { + if (empty($form->auto)) { + $form->auto = ""; + } echo "
destination\">\n"; + + $form->popup = $CFG->scorm_popup; + $strnewwindow = get_string("newwindow", "scorm"); + $strnewwindowopen = get_string("newwindowopen", "scorm"); + foreach ($SCORM_WINDOW_OPTIONS as $optionname) { + $stringname = "str$optionname"; + $$stringname = get_string("new$optionname", "scorm"); + $window->$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + $alljsoptions = implode(",", $jsoption); + + if ($form->instance) { // Re-editing + if ($form->popup == "") { + $newwindow = ""; // Disable the new window + } else { + $newwindow = "checked"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + if ((option != 'location') && (option != 'menubar') && (option != 'toolbar')) { + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = "checked"; + } + } + } + } + } else { + foreach ($SCORM_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "scorm_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + $newwindow = $CFG->scorm_popup; + } + ?> + + + + + + + + + +

:

+ auto); + ?> +
+

+
+ + + + onclick="autowindow();return lockoptions('theform','newwindow', subitems);"> + +
    + $value) { + if ($name == "height" or $name == "width") { + continue; + } + echo "\t\t\n"; + echo "\t\t$name."> "; + $stringname = "str$name"; + echo $$stringname."
    \n"; + } + ?> + + + +
    + + + +
    + "; + echo "lockoptions('theform','newwindow', subitems);"; + echo ""; + } + ?> +
+

+
- diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 5aa5e02865..5340699562 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -3,8 +3,28 @@ /// Library of functions and constants for module scorm /// (replace scorm with the name of your module and delete this line) +$SCORM_WINDOW_OPTIONS = array("resizable", "scrollbars", "status", "height", "width"); + +if (!isset($CFG->scorm_popup)) { + set_config("scorm_popup", ""); +} + +foreach ($SCORM_WINDOW_OPTIONS as $popupoption) { + $popupoption = "scorm_popup$popupoption"; + if (!isset($CFG->$popupoption)) { + if ($popupoption == "scorm_popupheight") { + set_config($popupoption, 450); + } else if ($popupoption == "scorm_popupwidth") { + set_config($popupoption, 620); + } else { + set_config($popupoption, "checked"); + } + } +} -$SCORM_FRAME_SIZE = 140; +if (!isset($CFG->scorm_framesize)) { + set_config("scorm_framesize", 140); +} function scorm_add_instance($scorm) { /// Given an object containing all the necessary data, @@ -15,6 +35,19 @@ function scorm_add_instance($scorm) { $scorm->timemodified = time(); # May have to add extra stuff in here # + global $SCORM_WINDOW_OPTIONS; + + if (isset($scorm->setnewwindow)) { + $optionlist = array(); + foreach ($SCORM_WINDOW_OPTIONS as $option) { + if (isset($scorm->$option)) { + $optionlist[] = $option."=".$scorm->$option; + } + } + $scorm->popup = implode(',', $optionlist); + $scorm->popup .= ',location=0,menubar=0,toolbar=0'; + $scorm->auto = '0'; + } return insert_record("scorm", $scorm); } @@ -24,11 +57,24 @@ function scorm_update_instance($scorm) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function /// will update an existing instance with new data. - + $scorm->timemodified = time(); $scorm->id = $scorm->instance; # May have to add extra stuff in here # + global $SCORM_WINDOW_OPTIONS; + + if (isset($scorm->setnewwindow)) { + $optionlist = array(); + foreach ($SCORM_WINDOW_OPTIONS as $option) { + if (isset($scorm->$option)) { + $optionlist[] = $option."=".$scorm->$option; + } + } + $scorm->popup = implode(',', $optionlist); + $scorm->popup .= ',location=0,menubar=0,toolbar=0'; + $scorm->auto = '0'; + } return update_record("scorm", $scorm); } diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index efd858e0dd..b6f874d8f6 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -11,9 +11,6 @@ if (empty($form->launch)) { $form->launch = ""; } - if (empty($form->auto)) { - $form->auto = ""; - } ?> @@ -58,16 +55,6 @@ summary); ?> - -

:

- - auto); - ?> - - diff --git a/mod/scorm/playscorm.php b/mod/scorm/playscorm.php index 88b70ff6e3..8f7862a32e 100755 --- a/mod/scorm/playscorm.php +++ b/mod/scorm/playscorm.php @@ -64,55 +64,171 @@ "$navigation framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name", "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top')); - echo "\n
".text_to_html($scorm->summary, true, false)."
\n"; + echo "\n \n"; + if ($_GET["mode"] == "browse") + echo "\n"; + echo " \n
".text_to_html($scorm->summary, true, false)."".get_string("browsemode","scorm")."
\n"; + - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){ - $level=0; - $parents[$level]="/"; - foreach ($scoes as $sco) { - if ($parents[$level]!=$sco->parent) { - if ($level>0 && $parents[$level-1]==$sco->parent) { - $level--; - } else { - $level++; - $parents[$level]=$sco->parent; - } - } - $indenting = ""; - for ($i=0;$i<$level;$i++) { - $indenting .= "-"; - } - $options[$sco->id] = $indenting."> ".$sco->title; - } - } echo "\n \n"; - echo " \n"; - if ($_GET["mode"] == "browse") - echo "\n"; + echo "\n
+ echo " id\" target=\"_top\">  \n"; - choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();"); - echo "   - + + if ($scorm->popup == "") { + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){ + $level=0; + $parents[$level]="/"; + foreach ($scoes as $sco) { + if ($parents[$level]!=$sco->parent) { + if ($level>0 && $parents[$level-1]==$sco->parent) { + $level--; + } else { + $level++; + $parents[$level]=$sco->parent; + } + } + $indenting = ""; + for ($i=0;$i<$level;$i++) { + $indenting .= "-"; + } + $options[$sco->id] = $indenting."> ".$sco->title; + } + } + choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();"); + } + echo "  \n"; + echo " ".get_string("browsemode","scorm")."
\n"; + if ($scorm->popup != "") { + $currentSCO = ""; + if (!empty($_GET['scoid'])) + $currentSCO = $_GET['scoid']; + ?> +
+ + + \n"; + echo " ".get_string("coursestruct","scorm")."\n"; + echo " \n\n"; + $level--; + } else { + echo "
    • \n"; + $level++; + $parents[$level]=$sco->parent; + } + } + echo "
    • \n"; + $nextsco = next($scoes); + if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent != $parents[$level-1])))) { + $sublist++; + echo " \n"; + } else { + echo " \n"; + } + + if ($sco->launch) { + $startbold = ''; + $endbold = ''; + if ($sco->id == $currentSCO) { + $startbold = ''; + $endbold = ''; + } + if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) { + if ( $sco_user->cmi_core_lesson_status == "") + $sco_user->cmi_core_lesson_status = "not attempted"; + echo " cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n"; + if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) { + if ($currentSCO == "") { + $incomplete = true; + $currentSCO = $sco->id; + $startbold = ''; + $endbold = ''; + } + } + } else { + echo " \"".get_string("notattempted","scorm")."\""; + $incomplete = true; + } + echo "  $startboldid.");\">$sco->title$endbold\n
    • \n"; + } else { + echo "  $sco->title\n \n"; + } + } + for ($i=0;$i<$level;$i++){ + echo "
  • \n"; + } + } + echo "\n"; + echo "\n"; + print_simple_box_end(); + } echo "\n\n"; } else { - // - // Frameset - // - if ($_POST["scoid"]) + if ($_POST["scoid"]) $scoid = "&scoid=".$_POST["scoid"]; - echo "\n"; + echo "\n"; echo "$course->shortname: $scorm->name\n"; echo "\n"; - echo "\n"; - echo " id&mode=".$_POST["mode"]."&frameset=top\">\n"; - echo " \n"; + + if ($scorm->popup == "") { + // + // Frameset + // + echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n"; + echo " id&mode=".$_POST["mode"]."&frameset=top\">\n"; + echo " \n"; + } else { + echo "'; + echo "\n\n"; + echo " id&mode=".$_POST["mode"]."&frameset=top".$scoid."\">\n"; + } echo "\n"; echo "\n"; } diff --git a/mod/scorm/report.php b/mod/scorm/report.php index c5dbaf179e..42c7a43b81 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -90,6 +90,8 @@ $scoreview = ""; if ($data->cmi_core_score_raw > 0) $scoreview = "
    ".get_string("score","scorm").": ".$data->cmi_core_score_raw; + if ( $data->cmi_core_lesson_status == "") + $data->cmi_core_lesson_status = "not attempted"; $row[]="cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($data->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($data->cmi_core_lesson_status),"scorm")."\"> " diff --git a/mod/scorm/scormAPI.php b/mod/scorm/scormAPI.php index e61621b8b5..92880dfa6b 100755 --- a/mod/scorm/scormAPI.php +++ b/mod/scorm/scormAPI.php @@ -135,6 +135,7 @@ include("api1_2.php"); ?> + function hilightcurrent(popupmenu) { for (i=0;i < popupmenu.options.length;i++) { if ( popupmenu.options[i].value == id; ?> ) @@ -154,8 +155,9 @@ function SCOInitialize() { } ?> top.main.location=""; +popup == "") { ?> hilightcurrent(top.nav.document.navform.courseStructure); - + } function changeSco(direction) { diff --git a/mod/scorm/version.php b/mod/scorm/version.php index 26e5a16cfd..d1a9144f1e 100755 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004060400; // The (date) version of this module +$module->version = 2004061800; // The (date) version of this module $module->requires = 2004051600; // The version of Moodle that is required $module->cron = 0; // How often should cron check this module (seconds)? diff --git a/mod/scorm/view.php b/mod/scorm/view.php index f89a5627b4..97eae95c3b 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -93,7 +93,7 @@ print_simple_box_start("CENTER"); echo "\n"; echo " \n"; - echo " \n"; -- 2.39.5
    ".get_string("coursestruct","scorm")."
    \n
      \n"; + echo "
    \n
      \n"; $incomplete = false; if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){ $level=0; @@ -102,10 +102,10 @@ foreach ($scoes as $sco) { if ($parents[$level]!=$sco->parent) { if ($level>0 && $parents[$level-1]==$sco->parent) { - echo "
    \n"; + echo " \n"; $level--; } else { - echo "
      \n"; + echo "
      • \n"; $level++; $parents[$level]=$sco->parent; } @@ -135,7 +135,7 @@ } } for ($i=0;$i<$level;$i++){ - echo "
      \n"; + echo "
    \n"; } } echo "