]> git.mjollnir.org Git - moodle.git/commitdiff
New feature - "Web link" resources can now specify a popup window
authormoodler <moodler>
Sun, 20 Jul 2003 13:53:31 +0000 (13:53 +0000)
committermoodler <moodler>
Sun, 20 Jul 2003 13:53:31 +0000 (13:53 +0000)
fullscreen is currently the only feature left out of this .. I had
trouble getting it to work consistently so I've left it out as being
more troubles than it's worth.

course/lib.php
lib/javascript.php
lib/weblib.php
mod/resource/details.php
mod/resource/lib.php
mod/resource/version.php

index f8c02c938b28ae1503ccbdbd6bbffe42c4ec7690..02e39144c7cea48d79ba2bb304fdafa4a7079e30 100644 (file)
@@ -438,6 +438,7 @@ function get_array_of_activities($courseid) {
 //  section - the number of the section (eg week or topic)
 //  name - the name of the instance
 //  visible - is the instance visible or not
+//  extra - contains extra string to include in any link
 
     $mod = array();
 
@@ -458,6 +459,19 @@ function get_array_of_activities($courseid) {
                    $mod[$seq]->section = $section->section;
                    $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
                    $mod[$seq]->visible = $rawmods[$seq]->visible;
+                   $mod[$seq]->extra = "";
+                   
+                   // This part is an ugly hack that doesn't belong here//
+                   if ($mod[$seq]->mod == "resource") {
+                       if ($resource = get_record("resource", "id", $rawmods[$seq]->instance)) {
+                           if ($resource->type == 5 and $resource->alltext) {
+                               $mod[$seq]->extra = urlencode("onClick=\"return ".
+                                                   "openpopup('/mod/resource/view.php?id=".
+                                                   $mod[$seq]->cm.
+                                                   "','resource','$resource->alltext');\"");
+                           }
+                       }
+                   }
                }
             }
         }
@@ -650,10 +664,15 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                          " href=\"mod.php?moveto=$mod->id\">$strmovehere</a></font><br />\n";
                 }
                 $instancename = urldecode($modinfo[$modnumber]->name);
+                if (!empty($modinfo[$modnumber]->extra)) {
+                    $extra = urldecode($modinfo[$modnumber]->extra);
+                } else {
+                    $extra = "";
+                }
                 $link_css = $mod->visible ? "" : " class=\"dimmed\" ";
                 echo "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"".
                      " height=16 width=16 alt=\"$mod->modfullname\">".
-                     " <font size=2><a title=\"$mod->modfullname\" $link_css ".
+                     " <font size=2><a title=\"$mod->modfullname\" $link_css $extra".
                      " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>";
             }
             if (isediting($course->id)) {
index 1577dfc79276e49fb79c676baa05783ebc3f530d..74a51cb7d0556120bfc908cd741e9c6385670e03 100644 (file)
@@ -15,11 +15,15 @@ function fillmessagebox(text) {
   document.form.message.value = text;\r
 }\r
 \r
-function openpopup(url,name,height,width) {\r
+function openpopup(url,name,options,fullscreen) {\r
   fullurl = "<?php echo $CFG->wwwroot ?>" + url;\r
-  options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height;\r
-  windowobj = window.open(fullurl,name, options);\r
+  windowobj = window.open(fullurl,name,options);\r
+  if (fullscreen) {\r
+     windowobj.moveTo(0,0);\r
+     windowobj.resizeTo(screen.availWidth,screen.availHeight); \r
+  }\r
   windowobj.focus();\r
+  return false;\r
 }\r
 \r
 function copyrichtext(textname) { \r
@@ -43,15 +47,40 @@ function inserttext(text) {
     }\r
     echo "  text = ' ' + text + ' ';\n";\r
     echo "  if ( $insertfield.createTextRange && $insertfield.caretPos) {\n";\r
-    echo "      var caretPos = $insertfield.caretPos;\n";\r
-    echo "      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";\r
+    echo "    var caretPos = $insertfield.caretPos;\n";\r
+    echo "    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";\r
     echo "  } else {\n";\r
-    echo "      $insertfield.value  += text;\n";\r
+    echo "    $insertfield.value  += text;\n";\r
     echo "  }\n";\r
     echo "  $insertfield.focus();\n";\r
 ?>\r
 }\r
 \r
+function lockoptions(form, master, subitems) {\r
+  // subitems is an array of names of sub items\r
+  // requires that each item in subitems has a \r
+  // companion hidden item in the form with the \r
+  // same name but prefixed by "h"\r
+  if (eval("document."+form+"."+master+".checked")) {\r
+    for (i=0; i<subitems.length; i++) {\r
+      unlockoption(form, subitems[i]);\r
+    }\r
+  } else {\r
+    for (i=0; i<subitems.length; i++) {\r
+      lockoption(form, subitems[i]);\r
+    }\r
+  }\r
+  return(true);\r
+}\r
+function lockoption(form,item) {\r
+  eval("document."+form+"."+item+".disabled=true");/* IE thing */\r
+  eval("document."+form+".h"+item+".value=1");\r
+}\r
+function unlockoption(form,item) {\r
+  eval("document."+form+"."+item+".disabled=false");/* IE thing */\r
+  eval("document."+form+".h"+item+".value=0");\r
+}\r
+\r
 <?php if ($focus) { echo "function setfocus() { document.$focus.focus() }\n"; } ?>\r
 \r
 // done hiding -->\r
index 2c4f9adf5034bc9e95f45f50b735d99ad7ada349..1e847c95074784df7d9232d3c1ad4578401f8d5c 100644 (file)
@@ -247,7 +247,8 @@ function frmchecked(&$var, $true_value = "checked", $false_value = "") {
 }
 
 
-function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window") {
+function link_to_popup_window ($url, $name="popup", $linkname="click here", 
+                               $height=400, $width=500, $title="Popup window") {
 /// This will create a HTML link that will work on both 
 /// Javascript and non-javascript browsers.
 /// Relies on the Javascript function openpopup in javascript.php
@@ -255,21 +256,29 @@ function link_to_popup_window ($url, $name="popup", $linkname="click here", $hei
 
     global $CFG;
 
-    echo "\n<script language=\"javascript\">";
-    echo "\n<!--";
-    echo "\ndocument.write('<a title=\"".addslashes($title)."\" href=javascript:openpopup(\"$url\",\"$name\",\"$height\",\"$width\") >".addslashes($linkname)."</a>');";
-    echo "\n//-->";
-    echo "\n</script>";
-    echo "\n<noscript>\n<a target=\"$name\" title=\"$title\" href=\"$CFG->wwwroot/$url\">$linkname</a>\n</noscript>\n";
+    $options = "menubar=0,location=0,scrollbars,resizable,width=$width,height=$height";
+    $fullscreen = 0;
 
+    echo "<a target=\"$name\" title=\"$title\" href=\"$CFG->wwwroot/$url\" ".
+         "onClick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>\n";
 }
 
+
 function close_window_button() {
 /// Prints a simple button to close a window
 
-    echo "<form><center>";
-    echo "<input type=button onClick=\"self.close();\" value=\"".get_string("closewindow")."\">";
-    echo "</center></form>";
+    echo "<center>\n";
+    echo "<script>\n";
+    echo "<!--\n";
+    echo "document.write('<form>');\n";
+    echo "document.write('<input type=button onClick=\"self.close();\" value=\"".get_string("closewindow")."\">');\n";
+    echo "document.write('</form>');\n";
+    echo "-->\n";
+    echo "</script>\n";
+    echo "<noscript>\n";
+    echo "<a href=\"".$_SERVER['HTTP_REFERER']."\"><---</a>\n";
+    echo "</noscript>\n";
+    echo "</center>\n";
 }
 
 
index 41d4a7686f0cf54b083cef9bde5cef03a6d17aef..c044979f5730dce0f1ec14b1ee5dd655c70f539d 100644 (file)
@@ -73,8 +73,6 @@
                 break;
 
             case WEBPAGE:
-            case WEBLINK:
-            case PROGRAM:
                 $strexampleurl = get_string("exampleurl", "resource");
                 ?>
                 <tr valign="top">
                         <input name="reference" size="100" value="<? p($form->reference) ?>">
                     </td>
                 </tr>
+                <tr valign="top">
+                    <td align="right" nowrap>&nbsp;
+                    </td>
+                    <td>
+                        <p><?php echo "($strexample) $strexampleurl" ?></p>
+                    </td>
+                </tr>
+
+                <?
+                break;
+
+            case WEBLINK:
+
+                $strexampleurl    = get_string("exampleurl", "resource");
+                $strnewwindow     = get_string("newwindow", "resource");
+                $strnewwindowopen = get_string("newwindowopen", "resource");
+
+                foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
+                    $stringname = "str$optionname";
+                    $$stringname = get_string("new$optionname", "resource");
+                    $window->$optionname = "";
+                    $jsoption[] = "\"$optionname\"";
+                }
+                $alljsoptions = implode(",", $jsoption);
+
+                if ($form->instance) {     // Re-editing
+                    if (!$form->alltext) {
+                        $newwindow = "";
+                    } else {
+                        $newwindow = "checked";
+                        $rawoptions = explode(',', $form->alltext); 
+                        foreach ($rawoptions as $rawoption) {
+                            $option = explode('=', trim($rawoption));
+                            $optionname = $option[0];
+                            $optionvalue = $option[1];
+                            if ($optionname == "height" or $optionname == "width") {
+                                $window->$optionname = $optionvalue;
+                            } else if ($optionvalue) {
+                                $window->$optionname = "checked";
+                            }
+                        }
+                    }
+                } else {
+                    $newwindow = "checked";
+                    $window->resizable = "checked";
+                    $window->scrollbars = "checked";
+                    $window->status = "checked";
+                    $window->location = "checked";
+                    $window->width = 620;
+                    $window->height = 450;
+                }
+
+                echo $alloptions;
+
+                ?>
+
                 <tr valign="top">
                     <td align="right" nowrap>
-                        <p><b>(<?=$strexample?>)</b></p>
+                        <p><b><?php p($strtypename) ?>:</b></p>
+                    </td>
+                    <td>
+                        <input name="reference" size="100" value="<?php p($form->reference) ?>">
+                    </td>
+                </tr>
+                <tr valign="top">
+                    <td align="right" nowrap>&nbsp;
+                    </td>
+                    <td>
+                        <p><?php echo "($strexample) $strexampleurl" ?></p>
+                    </td>
+                </tr>
+                <tr valign="top">
+                    <td align="right" nowrap>
+                        <p><b><?php p($strnewwindow) ?></b></p>
                     </td>
                     <td>
-                    <p><?=$strexampleurl?>
+                      <script>
+                          var subitems = [<?php echo $alljsoptions; ?>];
+                      </script>
+                      <input name="setnewwindow" type=hidden value=1>
+                      <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?> 
+                        onclick="return lockoptions('theform','newwindow', subitems)"> 
+                      <?php p($strnewwindowopen) ?>
+                    <ul>
+                      <?php
+                          foreach ($window as $name => $value) {
+                              if ($name == "height" or $name == "width") {
+                                  continue;
+                              }
+                              echo "<input name=\"h$name\" type=hidden value=0>";
+                              echo "<input name=\"$name\" type=checkbox value=1 ".$window->$name.">";
+                              $stringname = "str$name";
+                              echo $$stringname."<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>";
+                        }
+                      ?>
+                    </ul>
                     </p>
                     </td>
                 </tr>
                 <?
                 break;
 
+            case PROGRAM:
+                $strexampleurl = get_string("exampleurl", "resource");
+                ?>
+                <tr valign="top">
+                    <td align="right" nowrap>
+                        <p><b><?=$strtypename?>:</b></p>
+                    </td>
+                    <td>
+                        <input name="reference" size="100" value="<? p($form->reference) ?>">
+                    </td>
+                </tr>
+                <tr valign="top">
+                    <td align="right" nowrap>&nbsp;
+                    </td>
+                    <td>
+                        <p><?php echo "($strexample) $strexampleurl" ?></p>
+                    </td>
+                </tr>
+
+                <?
+                break;
+
             case UPLOADEDFILE:
                 $strfilename = get_string("filename", "resource");
                 $strnote     = get_string("note", "resource");
index c72f4e49ca8150f4737747c3b3f76217d9c7010a..680cbcddd4c8da93bbb6f32b916d04669f259da1 100644 (file)
@@ -20,6 +20,8 @@ $RESOURCE_TYPE = array (REFERENCE    => get_string("resourcetype1", "resource"),
 
 $RESOURCE_FRAME_SIZE = 130;
 
+$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", 
+                                 "menubar", "toolbar", "status", "height", "width");
 
 function resource_add_instance($resource) {
 // Given an object containing all the necessary data, 
@@ -27,8 +29,20 @@ function resource_add_instance($resource) {
 // will create a new instance and return the id number 
 // of the new instance.
 
+    global $RESOURCE_WINDOW_OPTIONS;
+
     $resource->timemodified = time();
 
+    if (isset($resource->setnewwindow)) {
+        $optionlist = array();
+        foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
+            if (isset($resource->$option)) {
+                $optionlist[] = $option."=".$resource->$option;
+            }
+        }
+        $resource->alltext = implode(',', $optionlist);
+    }
+
     return insert_record("resource", $resource);
 }
 
@@ -38,9 +52,21 @@ function resource_update_instance($resource) {
 // (defined by the form in mod.html) this function 
 // will update an existing instance with new data.
 
+    global $RESOURCE_WINDOW_OPTIONS;
+
     $resource->id = $resource->instance;
     $resource->timemodified = time();
 
+    if (isset($resource->setnewwindow)) {
+        $optionlist = array();
+        foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
+            if (isset($resource->$option)) {
+                $optionlist[] = $option."=".$resource->$option;
+            }
+        }
+        $resource->alltext = implode(',', $optionlist);
+    }
+
     return update_record("resource", $resource);
 }
 
index a8433671888ced7f345edd002eef1bdb847a43ad..a3b4241f86b1fc68c8f3f36ab56165494520b883 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002122300;
+$module->version  = 2003072000;
 $module->cron     = 0;
 
 ?>