Permalink
Browse files

Added new "Program" resource type, which allows Moodle to cooperate

with external web applications by passing info about the current
session to them.

Code contributed by Mark Kimes.
  • Loading branch information...
moodler
moodler committed Dec 24, 2002
1 parent 195ad21 commit f7a5c8fafd018819056926a46ed3d9ff10942c87
Showing with 52 additions and 3 deletions.
  1. +2 −1 mod/resource/details.php
  2. +3 −1 mod/resource/lib.php
  3. +47 −1 mod/resource/view.php
View
@@ -68,14 +68,15 @@
case WEBPAGE:
case WEBLINK:
+ 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=60 VALUE="<? p($form->reference) ?>">
+ <INPUT NAME="reference" SIZE=\"100\" VALUE="<? p($form->reference) ?>">
</TD>
</TR>
<TR VALIGN=top>
View
@@ -6,13 +6,15 @@
define("PLAINTEXT", "4");
define("WEBLINK", "5");
define("HTML", "6");
+define("PROGRAM", "7");
$RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"),
WEBPAGE => get_string("resourcetype2", "resource"),
UPLOADEDFILE => get_string("resourcetype3", "resource"),
PLAINTEXT => get_string("resourcetype4", "resource"),
WEBLINK => get_string("resourcetype5", "resource"),
- HTML => get_string("resourcetype6", "resource") );
+ HTML => get_string("resourcetype6", "resource"),
+ PROGRAM => get_string("resourcetype7", "resource") );
function resource_list_all_resources($courseid=0, $sort="name ASC", $recent=0) {
// Returns list of all resource links in an array of strings
View
@@ -117,6 +117,53 @@
print_footer($course);
break;
+ case PROGRAM: // Code provided by Mark Kimes <hectorp@buckfoodsvc.com>
+ add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
+
+ $temptime = gmdate("YmdHis",time());
+
+ $temproot = $CFG->wwwroot . "/mod/resource/";
+
+ // I tried to get around this. I really did. But here we
+ // are, redefining the navigation resources specifically anyway.
+ // On the plus side, you can change the format of the navigation
+ // strings above without worrying what it'll do to this code. On
+ // the negative side, you'll have to update this code if you
+ // change the structure of the navigation completely. Bonus
+ // is that now we can have a chain of cooperative sites, each
+ // adding to the navigation string as it moves down the line,
+ // which could be quite cool. -- Mark
+
+ if ($course->category) {
+ $tempref = "<$course->shortname><" . $temproot . "../../course/view.php?id=$course->id>" .
+ "<$strresources><" . $temproot . "index.php?id=$course->id>";
+ } else {
+ $tempref = "<$strresources><index.php?id=$course->id>";
+ }
+
+ $tempurl = trim($resource->reference);
+
+ if ($tempquerystring = strstr($tempurl,'?')) {
+ $tempquerystring = substr($tempquerystring,1);
+ $tempurl = substr($tempurl,0,strlen($tempurl) - strlen($tempquerystring));
+ }
+ if (!empty($tempquerystring)) {
+ $tempquerystring = preg_replace("/(.*=)([^&]*)/e",
+ "'\\1' . urlencode('\\2')",
+ $tempquerystring);
+ }
+ $temp = $tempurl . $tempquerystring .
+ ((strstr($tempurl,'?')) ? "&amp;" : "?") .
+ "extern_nav=" . urlencode($tempref) .
+ "&amp;extern_usr=" .
+ urlencode($USER->username) .
+ "&amp;extern_nam=" . urlencode("$USER->firstname $USER->lastname") .
+ "&amp;extern_tim=" . urlencode($temptime) .
+ "&amp;extern_pwd=" .
+ urlencode(md5($temptime . $USER->password));
+ redirect($temp);
+ break;
+
default:
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
@@ -128,5 +175,4 @@
break;
}
-
?>

0 comments on commit f7a5c8f

Please sign in to comment.