Fixed some popup window problems (some still fixing)
authorbobopinna <bobopinna>
Mon, 28 Jun 2004 11:20:52 +0000 (11:20 +0000)
committerbobopinna <bobopinna>
Mon, 28 Jun 2004 11:20:52 +0000 (11:20 +0000)
mod/scorm/api1_2.php
mod/scorm/details.php
mod/scorm/lib.php
mod/scorm/mod.html
mod/scorm/playscorm.php
mod/scorm/scormAPI.php

index 360e981..f10e308 100644 (file)
@@ -177,8 +177,8 @@ function SCORMapi() {
            return "false";
        }
        if (Initialized) {
-           if (top.nav.cmi.document.theform) {
-               cmiform = top.nav.cmi.document.forms[0];
+           if (<?php echo $navObj ?>cmi.document.theform) {
+               cmiform = <?php echo $navObj ?>cmi.document.forms[0];
                cmiform.scoid.value = "<?php echo $sco->id; ?>";
                cmiform.cmi_core_lesson_location.value = cmi.core.lesson_location;
                cmiform.cmi_core_lesson_status.value = cmi.core.lesson_status;
@@ -211,7 +211,7 @@ function SCORMapi() {
             <?php
                 if ($scorm->auto) {
                     if ($sco != $last) {
-                        print "setTimeout('top.nav.document.navform.next.click();',500);\n";
+                        print "setTimeout('".$navObj."document.navform.next.click();',500);\n";
                     } else {
                         print "exitloc = '".$CFG->wwwroot."/mod/scorm/view.php?id=$cm->id';\n";
                         print "setTimeout('top.location = exitloc;',500);\n";
index f2bc1f5..9d29190 100755 (executable)
@@ -88,7 +88,7 @@
            }
            echo "<form name=\"theform\" method=\"post\" action=\"$form->destination\">\n";
            
-           $form->popup = $CFG->scorm_popup;
+           //$form->popup = $CFG->scorm_popup;
            $strnewwindow     = get_string("newwindow", "scorm");
             $strnewwindowopen = get_string("newwindowopen", "scorm");
            foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
@@ -98,7 +98,7 @@
                $jsoption[] = "\"$optionname\"";
             }
             $alljsoptions = implode(",", $jsoption);
-
+           
             if ($form->instance) {     // Re-editing
                if ($form->popup == "") {
                     $newwindow = "";   // Disable the new window
                     $rawoptions = explode(',', $form->popup); 
                     foreach ($rawoptions as $rawoption) {
                        $option = explode('=', trim($rawoption));
-                       if ((option != 'location') && (option != 'menubar') && (option != 'toolbar')) {
+                       if (($option[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) {
                            $optionname = $option[0];
                            $optionvalue = $option[1];
                            if ($optionname == "height" or $optionname == "width") {
                                $window->$optionname = $optionvalue;
-                           } else if ($optionvalue) {
+                           } else if ($optionvalue == 1) {
                                $window->$optionname = "checked";
                            }
                        }
                         else
                             document.theform.auto.disabled=false;
                     }
+                    
+                    <?php
+                        if ($newwindow == "checked")
+                            echo "document.theform.auto.disabled=true;\n";
+                    ?>
                 </script>
-                <input name="setnewwindow" type=hidden value=1>
-                <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?> 
-                        onclick="autowindow();return lockoptions('theform','newwindow', subitems);"> 
+                <input name="setnewwindow" type=hidden value=1 />
+                <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?> onclick="autowindow();return lockoptions('theform','newwindow', subitems);" /> 
                 <?php p($strnewwindowopen) ?>
                 <ul>
                 <?php
                         if ($name == "height" or $name == "width") {
                             continue;
                         }
-                        echo "\t\t<input name=\"h$name\" type=hidden value=0>\n";
-                        echo "\t\t<input name=\"$name\" type=checkbox value=1 ".$window->$name."> ";
+                        echo "\t\t<input name=\"h$name\" type=\"hidden\" value=\"0\" />\n";
+                        echo "\t\t<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." /> ";
                         $stringname = "str$name";
                         echo $$stringname."<br />\n";
                      }
-                 ?>
-
-                 <input name="hwidth" type=hidden value=0>
-                 <input name="width" type=text size=4 value="<?php p($window->width) ?>">
-                 <?php p($strwidth) ?><br />
+                ?>
 
-                 <input name="hheight" type=hidden value=0>
-                 <input name="height" type=text size=4 value="<?php p($window->height) ?>">
-                 <?php p($strheight) ?><br />
+                <input name="hwidth" type=hidden value="0" />
+                <input name="width" type=text size=4 value="<?php p($window->width) ?>" /> <?php p($strwidth) ?><br />
+                <input name="hheight" type=hidden value="0" />
+                <input name="height" type=text size=4 value="<?php p($window->height) ?>" /> <?php p($strheight) ?><br />
                  <?php
                      if (!$newwindow) {
-                         echo "<script>";
-                         echo "lockoptions('theform','newwindow', subitems);";
-                         echo "</script>";
+                         echo "<script>\n<!--\n";
+                         echo "\tlockoptions('theform','newwindow', subitems);";
+                         echo "\n-->\n</script>";
                      }
                  ?>
                  </ul>
              </td>
            </tr>
         </table>
-        <input type="hidden" name="reference"  value="<?php p($form->reference) ?>">
-        <input type="hidden" name="datadir"    value="<?php p(substr($tempdir,strlen($scormdir))) ?>">
-        <input type="hidden" name="summary"    value="<?php p($form->summary) ?>">
-        <input type="hidden" name="name"       value="<?php p($form->name) ?>">
-       <input type="hidden" name="launch"      value="<?php p($form->launch) ?>">
-        <input type="hidden" name="course"     value="<?php p($form->course) ?>">
-        <input type="hidden" name="coursemodule"       value="<?php p($form->coursemodule) ?>">
-        <input type="hidden" name="section"    value="<?php p($form->section) ?>">
-        <input type="hidden" name="module"     value="<?php p($form->module) ?>">
-        <input type="hidden" name="modulename" value="<?php p($form->modulename) ?>">
-        <input type="hidden" name="instance"   value="<?php p($form->instance) ?>">
-        <input type="hidden" name="mode"       value="<?php p($form->mode) ?>">
-       <center>
-           <input type="submit" value="<?php print_string("savechanges") ?>">
-           <input type="submit" name=cancel value="<?php print_string("cancel") ?>">
-       </center>
+        <input type="hidden" name="reference"  value="<?php p($form->reference) ?>" />
+        <input type="hidden" name="datadir"    value="<?php p(substr($tempdir,strlen($scormdir))) ?>" />
+        <input type="hidden" name="summary"    value="<?php p($form->summary) ?>" />
+        <input type="hidden" name="name"       value="<?php p($form->name) ?>" />
+       <input type="hidden" name="launch"      value="<?php p($form->launch) ?>" />
+        <input type="hidden" name="course"     value="<?php p($form->course) ?>" />
+        <input type="hidden" name="coursemodule"       value="<?php p($form->coursemodule) ?>" />
+        <input type="hidden" name="section"    value="<?php p($form->section) ?>" />
+        <input type="hidden" name="module"     value="<?php p($form->module) ?>" />
+        <input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
+        <input type="hidden" name="instance"   value="<?php p($form->instance) ?>" />
+        <input type="hidden" name="mode"       value="<?php p($form->mode) ?>" />
+       <div align="center">
+           <input type="submit" value="<?php print_string("savechanges") ?>" />
+           <input type="submit" name=cancel value="<?php print_string("cancel") ?>" />
+       </div>
         </form>
 <?php
        } else {
index 5340699..72ded91 100755 (executable)
@@ -37,17 +37,19 @@ function scorm_add_instance($scorm) {
     # 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 = "";
+    
+    $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';
     }
+    $scorm->popup = implode(',', $optionlist);
+    $scorm->auto = '0';
+
+    if ($scorm->popup != "")
+       $scorm->popup .= ',location=0,menubar=0,toolbar=0';
     
     return insert_record("scorm", $scorm);
 }
@@ -64,17 +66,19 @@ function scorm_update_instance($scorm) {
     # 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 = "";
+    
+    $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';
     }
+    $scorm->popup = implode(',', $optionlist);
+    $scorm->auto = '0';
+
+    if ($scorm->popup != "")
+       $scorm->popup .= ',location=0,menubar=0,toolbar=0';
 
     return update_record("scorm", $scorm);
 }
index b6f874d..0d9f1c9 100755 (executable)
@@ -60,6 +60,7 @@
     <input type="hidden" name=coursemodule     value="<?php p($form->coursemodule) ?>">
     <input type="hidden" name=datadir  value="<?php p($form->datadir) ?>">
     <input type="hidden" name=launch   value="<?php p($form->launch) ?>">
+    <input type="hidden" name=popup    value="<?php p($form->popup) ?>">
     <input type="hidden" name=section  value="<?php p($form->section) ?>">
     <input type="hidden" name=module   value="<?php p($form->module) ?>">
     <input type="hidden" name=modulename       value="<?php p($form->modulename) ?>">
index 8f7862a..f0d29bb 100755 (executable)
                      update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
         notice(get_string("activityiscurrentlyhidden"));
     }
-    if ($frameset == "top") {
+    
+    if (!empty($_POST["scoid"]))
+           $scoid = "&scoid=".$_POST["scoid"];
+    if (($scorm->popup != "") && (!empty($_POST["mode"])))
+       $mode = $_POST["mode"];
+    if (($scorm->popup == "") && (!empty($_GET["mode"])))
+       $mode = $_GET["mode"];
+    
+    if (($frameset == "top") || ($scorm->popup != "")) {
        add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id");
        //
        // Print the page header
                "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'));
        
        echo "<table width=\"100%\">\n    <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
-       if ($_GET["mode"] == "browse")
+       if ($mode == "browse")
            echo "<td align=\"right\" width=\"10%\" nowrap>".get_string("browsemode","scorm")."</td>\n";
        echo "     </tr>\n</table>\n";
        
-       
-           
-       echo "<table width=\"100%\">\n    <tr>\n";
-       echo "          <td align=\"center\" nowrap>
-                    <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden;\"></iframe>
-                    <form name=\"navform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
-                       <input name=\"scoid\" type=\"hidden\" />
-                       <input name=\"mode\" type=\"hidden\" value=\"".$_GET["mode"]."\" />
-                       <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('prev');\" />&nbsp;\n";
-                       
-       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."&gt; ".$sco->title;
-               }
-           }
-           choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
-       }
-       echo "          &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('next')\" />\n";
-       echo "       </form>
-               </td>\n";
-       
-       echo "</tr>\n</table>\n";
-        if ($scorm->popup != "") {
+       if ($scorm->popup != "") {
+           echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
            $currentSCO = "";
-            if (!empty($_GET['scoid']))
-                $currentSCO = $_GET['scoid'];
+            if (!empty($_POST['scoid']))
+                $currentSCO = $_POST['scoid'];
         ?>
             <br />
             <script language="Javascript">
                        $startbold = '';
                        $endbold = '';
                        if ($sco->id == $currentSCO) {
-                           $startbold = '<b><u>';
-                           $endbold = '</u></b>';
+                           $startbold = '-> <b><u>';
+                           $endbold = '</u></b> <-';
                        }
                        if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
                            if ( $sco_user->cmi_core_lesson_status == "")
                                if ($currentSCO == "") {
                                    $incomplete = true;
                                    $currentSCO = $sco->id;
-                                   $startbold = '<b><u>';
-                                   $endbold = '</u></b>';
+                                   $startbold = '-> <b><u>';
+                                   $endbold = '</u></b> <-';
                                }
                            }
                        } else {
            echo "</ul></td></tr>\n";
            echo "</table>\n";
            print_simple_box_end();
+           
+        }
+           
+       echo "<table width=\"100%\">\n    <tr>\n";
+       echo "          <td align=\"center\" nowrap>
+                    <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden;\"></iframe>
+                    <form name=\"navform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
+                       <input name=\"scoid\" type=\"hidden\" />
+                       <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
+                       <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('prev');\" />&nbsp;\n";
+                       
+       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."&gt; ".$sco->title;
+               }
+           }
+           choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
+       }
+       echo "          &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('next')\" />\n";
+       echo "       </form>
+               </td>\n";
+       
+       echo "</tr>\n</table>\n";
+       
+       if ($scorm->popup != "") {
+       ?>
+           <script language="Javascript">
+               top.main = window.open('','main','<?php echo $scorm->popup ?>');
+               SCOInitialize();
+            </script>
+        <?php
         }
+        
        echo "</body>\n</html>\n";
     } else {
-        if ($_POST["scoid"])
-           $scoid = "&scoid=".$_POST["scoid"];
-       echo "<html>\n";
-        echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
-        echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$_POST["mode"].$scoid."\"></script>\n";
-
         if ($scorm->popup == "") {
            // 
            // Frameset
            //
+           echo "<html>\n";
+            echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
+            echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
            echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n";
-            echo "         <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$_POST["mode"]."&frameset=top\">\n";
+            echo "         <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
             echo "         <frame name=\"main\" src=\"\">\n";
-        } else {
-            echo "<script language=\"Javascript\">\n";
-            echo '<!--';
-            echo "\nmain = window.open('','SCO Display','$scorm->popup');\n";
-            echo "-->\n";
-            echo '</script>';
-            echo "\n<frameset rows=\"*\" onLoad=\"SCOInitialize();\">\n";
-            echo "         <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$_POST["mode"]."&frameset=top".$scoid."\">\n";
+            echo "</frameset>\n";
+            echo "</html>\n";
         }
-        echo "</frameset>\n";
-        echo "</html>\n";
     }
 ?>
index 92880df..ac5e33b 100755 (executable)
            $result = "$CFG->wwwroot/file.php?file=/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch";
        }
     }
+    $navObj = "top.";
+    if ($scorm->popup == "")
+        $navObj = "top.nav.";
+        
     include("api1_2.php");
 
 ?>
@@ -146,26 +150,26 @@ function hilightcurrent(popupmenu) {
 function SCOInitialize() { 
 <?php
     if ( $sco->previous || $first) {
-       print "\ttop.nav.document.navform.prev.disabled = true;\n";
-       print "\ttop.nav.document.navform.prev.style.display = 'none';\n";
+       print "\t".$navObj."document.navform.prev.disabled = true;\n";
+       print "\t".$navObj."document.navform.prev.style.display = 'none';\n";
     }
     if ( $sco->next || $last) {
-       print "\ttop.nav.document.navform.next.disabled = true;\n";
-       print "\ttop.nav.document.navform.next.style.display = 'none';\n";
+       print "\t".$navObj."document.navform.next.disabled = true;\n";
+       print "\t".$navObj."document.navform.next.style.display = 'none';\n";
     }
 ?>
        top.main.location="<?php echo $result; ?>";
 <?php  if ($scorm->popup == "") { ?>
-       hilightcurrent(top.nav.document.navform.courseStructure);
+       hilightcurrent(<?php echo $navObj ?>document.navform.courseStructure);
 <?php   } ?>
 } 
 
 function changeSco(direction) {
        if (direction == "prev")
-           top.nav.document.navform.scoid.value="<?php echo $prevsco; ?>";
+           <?php echo $navObj ?>document.navform.scoid.value="<?php echo $prevsco; ?>";
        else
-           top.nav.document.navform.scoid.value="<?php echo $nextsco; ?>";
+           <?php echo $navObj ?>document.navform.scoid.value="<?php echo $nextsco; ?>";
            
-       //alert ("Prev: <?php echo $prevsco; ?>\nNext: <?php echo $nextsco; ?>\nNew SCO: "+top.nav.document.navform.scoid.value);
-       top.nav.document.navform.submit();
+       //alert ("Prev: <?php echo $prevsco; ?>\nNext: <?php echo $nextsco; ?>\nNew SCO: "+<?php echo $navObj ?>document.navform.scoid.value);
+       <?php echo $navObj ?>document.navform.submit();
 }   
\ No newline at end of file