From f7a5c8fafd018819056926a46ed3d9ff10942c87 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 24 Dec 2002 07:01:03 +0000 Subject: [PATCH] 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. --- mod/resource/details.php | 3 ++- mod/resource/lib.php | 4 +++- mod/resource/view.php | 48 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/mod/resource/details.php b/mod/resource/details.php index d63dda078f..cdc2720f61 100644 --- a/mod/resource/details.php +++ b/mod/resource/details.php @@ -68,6 +68,7 @@ case WEBPAGE: case WEBLINK: + case PROGRAM: $strexampleurl = get_string("exampleurl", "resource"); ?> @@ -75,7 +76,7 @@

:

- + diff --git a/mod/resource/lib.php b/mod/resource/lib.php index c3f65ca522..c7595dc450 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -6,13 +6,15 @@ define("UPLOADEDFILE","3"); 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 diff --git a/mod/resource/view.php b/mod/resource/view.php index e495c07a80..95768270f6 100644 --- a/mod/resource/view.php +++ b/mod/resource/view.php @@ -117,6 +117,53 @@ print_footer($course); break; + case PROGRAM: // Code provided by Mark Kimes + 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>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,'?')) ? "&" : "?") . + "extern_nav=" . urlencode($tempref) . + "&extern_usr=" . + urlencode($USER->username) . + "&extern_nam=" . urlencode("$USER->firstname $USER->lastname") . + "&extern_tim=" . urlencode($temptime) . + "&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; } - ?> -- 2.39.5