mirror of
https://github.com/moodle/moodle.git
synced 2025-06-05 23:55:21 +02:00
New feature - "Web link" resources can now specify a popup window
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.
This commit is contained in:
parent
d769d2ee51
commit
86aa7ccfdf
@ -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)) {
|
||||
|
@ -15,11 +15,15 @@ function fillmessagebox(text) {
|
||||
document.form.message.value = text;
|
||||
}
|
||||
|
||||
function openpopup(url,name,height,width) {
|
||||
function openpopup(url,name,options,fullscreen) {
|
||||
fullurl = "<?php echo $CFG->wwwroot ?>" + url;
|
||||
options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height;
|
||||
windowobj = window.open(fullurl,name, options);
|
||||
windowobj = window.open(fullurl,name,options);
|
||||
if (fullscreen) {
|
||||
windowobj.moveTo(0,0);
|
||||
windowobj.resizeTo(screen.availWidth,screen.availHeight);
|
||||
}
|
||||
windowobj.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
function copyrichtext(textname) {
|
||||
@ -43,15 +47,40 @@ function inserttext(text) {
|
||||
}
|
||||
echo " text = ' ' + text + ' ';\n";
|
||||
echo " if ( $insertfield.createTextRange && $insertfield.caretPos) {\n";
|
||||
echo " var caretPos = $insertfield.caretPos;\n";
|
||||
echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";
|
||||
echo " var caretPos = $insertfield.caretPos;\n";
|
||||
echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";
|
||||
echo " } else {\n";
|
||||
echo " $insertfield.value += text;\n";
|
||||
echo " $insertfield.value += text;\n";
|
||||
echo " }\n";
|
||||
echo " $insertfield.focus();\n";
|
||||
?>
|
||||
}
|
||||
|
||||
function lockoptions(form, master, subitems) {
|
||||
// subitems is an array of names of sub items
|
||||
// requires that each item in subitems has a
|
||||
// companion hidden item in the form with the
|
||||
// same name but prefixed by "h"
|
||||
if (eval("document."+form+"."+master+".checked")) {
|
||||
for (i=0; i<subitems.length; i++) {
|
||||
unlockoption(form, subitems[i]);
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<subitems.length; i++) {
|
||||
lockoption(form, subitems[i]);
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
function lockoption(form,item) {
|
||||
eval("document."+form+"."+item+".disabled=true");/* IE thing */
|
||||
eval("document."+form+".h"+item+".value=1");
|
||||
}
|
||||
function unlockoption(form,item) {
|
||||
eval("document."+form+"."+item+".disabled=false");/* IE thing */
|
||||
eval("document."+form+".h"+item+".value=0");
|
||||
}
|
||||
|
||||
<?php if ($focus) { echo "function setfocus() { document.$focus.focus() }\n"; } ?>
|
||||
|
||||
// done hiding -->
|
||||
|
@ -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";
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,134 @@
|
||||
break;
|
||||
|
||||
case WEBPAGE:
|
||||
$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>
|
||||
</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><?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>
|
||||
</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>
|
||||
<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");
|
||||
?>
|
||||
@ -86,12 +213,10 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right" nowrap>
|
||||
<p><b>(<?=$strexample?>)</b></p>
|
||||
<td align="right" nowrap>
|
||||
</td>
|
||||
<td>
|
||||
<p><?=$strexampleurl?>
|
||||
</p>
|
||||
<p><?php echo "($strexample) $strexampleurl" ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// This fragment is called by /admin/index.php
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2002122300;
|
||||
$module->version = 2003072000;
|
||||
$module->cron = 0;
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user