]> git.mjollnir.org Git - moodle.git/commitdiff
Merged in the new resource structure to TRUNK
authormoodler <moodler>
Sun, 25 Jul 2004 14:32:05 +0000 (14:32 +0000)
committermoodler <moodler>
Sun, 25 Jul 2004 14:32:05 +0000 (14:32 +0000)
22 files changed:
mod/resource/config.html
mod/resource/coursefiles.php
mod/resource/db/mysql.php
mod/resource/db/mysql.sql
mod/resource/db/postgres7.php
mod/resource/db/postgres7.sql
mod/resource/lib.php
mod/resource/mod.html
mod/resource/type/common.html [new file with mode: 0644]
mod/resource/type/common_end.html [new file with mode: 0644]
mod/resource/type/directory/directory.html [new file with mode: 0644]
mod/resource/type/directory/resource.class.php [new file with mode: 0644]
mod/resource/type/file/file.html [new file with mode: 0644]
mod/resource/type/file/resource.class.php [new file with mode: 0644]
mod/resource/type/html/html.html [new file with mode: 0644]
mod/resource/type/html/resource.class.php [new file with mode: 0644]
mod/resource/type/reference/reference.html [new file with mode: 0644]
mod/resource/type/reference/resource.class.php [new file with mode: 0644]
mod/resource/type/text/resource.class.php [new file with mode: 0644]
mod/resource/type/text/text.html [new file with mode: 0644]
mod/resource/version.php
mod/resource/view.php

index b9234d508e1070833a17faadee5d52dadfc0e6ca..1380d66136067951ba7d78504d7c4b1a755f92b0 100644 (file)
     <?php print_string("configdefaulturl", "resource") ?>
     </td>
 </tr>
+<tr valign=top>
+       <td align=right><p>resource_secretphrase:</td>
+       <td>
+    <input name=resource_secretphrase type=text size=30 value="<?php p($CFG->resource_secretphrase) ?>">
+    </td>
+    <td>
+    <?php print_string("configsecretphrase", "resource") ?>
+    </td>
+</tr>
 <tr valign=top>
        <td align=right><p>resource_filterexternalpages:</td>
        <td>
index fafe88b07e5fec1d5d87a26ee3270c09edd3023a..f9d92a3b00105bf57566c942c54fe0a2b8042d1b 100644 (file)
@@ -67,7 +67,7 @@
            <script language="javascript" type="text/javascript">
            <!--
            function set_value(txt) {
-                   opener.document.forms['theform'].reference.value = txt;
+                   opener.document.forms['form'].reference.value = txt;
                    window.close();
            }
         -->
index ead3139d7026b6ade37a45d3be1afd7cbb33bcd8..bc13dd65dee0c25da8230b46c10352ca4fc26aac 100644 (file)
@@ -15,6 +15,41 @@ function resource_upgrade($oldversion) {
         modify_database("", "INSERT INTO prefix_log_display VALUES ('resource', 'add', 'resource', 'name');");
     }
 
+    if ($oldversion < 2004071000) {
+        table_column("resource", "", "popup", "text", "", "", "", "", "alltext");
+        if ($resources = get_records_select("resource", "type='3' OR type='5'", "", "id, alltext")) {
+            foreach ($resources as $resource) {
+                $resource->popup = addslashes($resource->alltext);
+                $resource->alltext = "";
+                if (!update_record("resource", $resource)) {
+                    notify("Error updating popup field for resource id = $resource->id");
+                }                
+            }
+        }
+        require("$CFG->dirroot/course/lib.php");
+        rebuild_course_cache();
+    }
+
+    if ($oldversion < 2004071300) {
+        table_column("resource", "", "options", "varchar", "255", "", "", "", "popup");
+    }
+
+    if ($oldversion < 2004071303) {
+        table_column("resource", "type", "type", "varchar", "30", "", "", "", "");
+
+        modify_database("", "UPDATE prefix_resource SET type='reference' WHERE type='1';");
+        modify_database("", "UPDATE prefix_resource SET type='url', options='frame' WHERE type='2';");
+        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='3';");
+        modify_database("", "UPDATE prefix_resource SET type='text', options='0' WHERE type='4';");
+        modify_database("", "UPDATE prefix_resource SET type='url' WHERE type='5';");
+        modify_database("", "UPDATE prefix_resource SET type='html' WHERE type='6';");
+        modify_database("", "UPDATE prefix_resource SET type='program' WHERE type='7';");
+        modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';");
+        modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';");
+    }
+
+    
+    
     return true;
 }
 
index 4571078a6058df813928fd726f61c45340da3b2e..9c8f69c231f84914cc47fe1bc8aa074c7661e35d 100755 (executable)
@@ -22,6 +22,8 @@ CREATE TABLE prefix_resource (
   reference varchar(255) default NULL,\r
   summary text NOT NULL,\r
   alltext text NOT NULL,\r
+  popup text NOT NULL,\r
+  options varchar(255) NOT NULL default '',\r
   timemodified int(10) unsigned NOT NULL default '0',\r
   PRIMARY KEY  (id),\r
   UNIQUE KEY id (id)\r
index 66e9f7a6367b276754e0650312637b96eacbd570..aba56e9dff7b0588375666023b0c1b81ec6fe00a 100644 (file)
@@ -9,6 +9,39 @@ function resource_upgrade($oldversion) {
         modify_database("", "INSERT INTO prefix_log_display VALUES ('resource', 'add', 'resource', 'name');");
     }
 
+    if ($oldversion < 2004071000) {
+        table_column("resource", "", "popup", "text", "", "", "", "", "alltext");
+        if ($resources = get_records_select("resource", "type='3' OR type='5'", "", "id, alltext")) {
+            foreach ($resources as $resource) {
+                $resource->popup = addslashes($resource->alltext);
+                $resource->alltext = "";
+                if (!update_record("resource", $resource)) {
+                    notify("Error updating popup field for resource id = $resource->id");
+                }                
+            }
+        }
+        require("$CFG->dirroot/course/lib.php");
+        rebuild_course_cache();
+    }
+    
+    if ($oldversion < 2004071300) {
+        table_column("resource", "", "options", "varchar", "255", "", "", "", "popup");
+    }
+    
+    if ($oldversion < 2004071303) {
+        table_column("resource", "type", "type", "varchar", "30", "", "", "", "");
+
+        modify_database("", "UPDATE prefix_resource SET type='reference' WHERE type='1';");
+        modify_database("", "UPDATE prefix_resource SET type='url', options='frame' WHERE type='2';");
+        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='3';");
+        modify_database("", "UPDATE prefix_resource SET type='text', options='0' WHERE type='4';");
+        modify_database("", "UPDATE prefix_resource SET type='url' WHERE type='5';");
+        modify_database("", "UPDATE prefix_resource SET type='html' WHERE type='6';");
+        modify_database("", "UPDATE prefix_resource SET type='program' WHERE type='7';");
+        modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';");
+        modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';");
+    }
+    
     return true;
 }
 
index 1ee767d6618fb0698b3fb0c72344680d2f242552..086feb093769ad9514777f9c19e9687593a36d72 100644 (file)
@@ -22,6 +22,8 @@ CREATE TABLE prefix_resource (
   reference varchar(255) default NULL,
   summary text NOT NULL default '',
   alltext text NOT NULL default '',
+  popup text NOT NULL default '',
+  options varchar(255) NOT NULL default '',
   timemodified integer NOT NULL default '0'
 );
 
index 16f021b2697f4486cda338c10b8e80e8c8b61280..d5cad951bfa427113fd3a8a8e8e6b87f97da4383 100644 (file)
@@ -1,25 +1,5 @@
 <?PHP  // $Id$
 
-define("REFERENCE",   "1");
-define("WEBPAGE",     "2");
-define("UPLOADEDFILE","3");
-define("PLAINTEXT",   "4");
-define("WEBLINK",     "5");
-define("HTML",        "6");
-define("PROGRAM",     "7");
-define("WIKITEXT",    "8");
-define("DIRECTORY",   "9");
-
-$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"),
-                        PROGRAM      => get_string("resourcetype7", "resource"),
-                        WIKITEXT     => get_string("resourcetype8", "resource"),
-                        DIRECTORY    => get_string("resourcetype9", "resource") );
-
 if (!isset($CFG->resource_framesize)) {
     set_config("resource_framesize", 130);
 } 
@@ -36,6 +16,10 @@ if (!isset($CFG->resource_filterexternalpages)) {
     set_config("resource_filterexternalpages", false);
 }  
 
+if (!isset($CFG->resource_secretphrase)) {
+    set_config("resource_secretphrase", random_string(20));
+}  
+
 $RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", 
                                  "menubar", "toolbar", "status", "height", "width");
 
@@ -56,7 +40,89 @@ foreach ($RESOURCE_WINDOW_OPTIONS as $popupoption) {
     }  
 }
 
-function resource_add_instance($resource) {
+/**
+* resource_base is the base class for resource types
+*
+* This class provides all the functionality for a resource
+*/
+
+class resource_base {
+
+var $cm;
+var $course;
+var $resource;
+
+
+/**
+* Constructor for the base resource class
+*
+* Constructor for the base resource class.
+* If cmid is set create the cm, course, resource objects.
+*
+* @param cmid   integer, the current course module id - not set for new resources
+*/
+function resource_base($cmid=0) {
+
+    if ($cmid) {
+        if (! $this->cm = get_record("course_modules", "id", $cmid)) {
+            error("Course Module ID was incorrect");
+        }
+
+        if (! $this->course = get_record("course", "id", $this->cm->course)) {
+            error("Course is misconfigured");
+        }
+
+        if (! $this->resource = get_record("resource", "id", $this->cm->instance)) {
+            error("Resource ID was incorrect");
+        }
+    } 
+}
+
+
+function display() {
+}
+
+
+function setup($form) {
+    global $CFG, $usehtmleditor;
+
+    if (! empty($form->course)) {
+        if (! $this->course = get_record("course", "id", $form->course)) {
+            error("Course is misconfigured");
+        }
+    }
+
+    if (empty($form->name)) {
+        $form->name = "";
+    }
+    if (empty($form->type)) {
+        $form->type = "";
+    }
+    if (empty($form->summary)) {
+        $form->summary = "";
+    }
+    if (empty($form->reference)) {
+        $form->reference = "";
+    }
+    if (empty($form->alltext)) {
+        $form->alltext = "";
+    }
+    $nohtmleditorneeded = true;
+
+    print_heading_with_help(get_string("resourcetype$form->type", 'resource'), $form->type, 'resource');
+
+    include("$CFG->dirroot/mod/resource/type/common.html");
+}
+
+
+function setup_end() {
+    global $CFG;
+
+    include("$CFG->dirroot/mod/resource/type/common_end.html");
+}
+
+
+function add_instance($resource) {
 // Given an object containing all the necessary data, 
 // (defined by the form in mod.html) this function 
 // will create a new instance and return the id number 
@@ -66,21 +132,31 @@ function resource_add_instance($resource) {
 
     $resource->timemodified = time();
 
-    if (isset($resource->setnewwindow)) {
+    if (isset($resource->windowpopup)) {
         $optionlist = array();
         foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
             if (isset($resource->$option)) {
                 $optionlist[] = $option."=".$resource->$option;
             }
         }
-        $resource->alltext = implode(',', $optionlist);
+        $resource->popup = implode(',', $optionlist);
+        $resource->options = "";
+
+    } else if (isset($resource->windowpage)) {
+
+        if (isset($resource->framepage)) {
+            $resource->options = "frame";
+        } else {
+            $resource->options = "";
+        }
+        $resource->popup = "";
     }
 
     return insert_record("resource", $resource);
 }
 
 
-function resource_update_instance($resource) {
+function update_instance($resource) {
 // Given an object containing all the necessary data, 
 // (defined by the form in mod.html) this function 
 // will update an existing instance with new data.
@@ -90,21 +166,30 @@ function resource_update_instance($resource) {
     $resource->id = $resource->instance;
     $resource->timemodified = time();
 
-    if (isset($resource->setnewwindow)) {
+    if (isset($resource->windowpopup)) {
         $optionlist = array();
         foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
             if (isset($resource->$option)) {
                 $optionlist[] = $option."=".$resource->$option;
             }
         }
-        $resource->alltext = implode(',', $optionlist);
+        $resource->popup = implode(',', $optionlist);
+        $resource->options = "";
+
+    } else if (isset($resource->windowpage)) {
+        if (isset($resource->framepage)) {
+            $resource->options = "frame";
+        } else {
+            $resource->options = "";
+        }
+        $resource->popup = "";
     }
 
     return update_record("resource", $resource);
 }
 
 
-function resource_delete_instance($id) {
+function delete_instance($id) {
 // Given an ID of an instance of this module, 
 // this function will permanently delete the instance 
 // and any data that depends on it.  
@@ -123,6 +208,43 @@ function resource_delete_instance($id) {
 }
 
 
+
+} /// end of class definition
+
+
+
+function resource_add_instance($resource) {
+    global $CFG;
+    
+    require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
+    $res = new resource();
+
+    return $res->add_instance($resource);
+}
+
+function resource_update_instance($resource) {
+    global $CFG;
+    
+    require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
+    $res = new resource();
+
+    return $res->update_instance($resource);
+}
+
+function resource_delete_instance($id) {
+    global $CFG;
+    
+    if (! $resource = get_record("resource", "id", "$id")) {
+        return false;
+    }
+    
+    require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
+    $res = new resource();
+
+    return $res->delete_instance($id);
+}
+
+
 function resource_user_outline($course, $user, $mod, $resource) {
     if ($logs = get_records_select("log", "userid='$user->id' AND module='resource' 
                                            AND action='view' AND info='$resource->id'", "time ASC")) {
@@ -177,23 +299,23 @@ function resource_get_coursemodule_info($coursemodule) {
    $info = NULL;
 
    if ($resource = get_record("resource", "id", $coursemodule->instance)) {
-       if (($resource->type == UPLOADEDFILE or $resource->type == WEBLINK) and !empty($resource->alltext)) {
+       if (($resource->type == UPLOADEDFILE or $resource->type == WEBLINK) and !empty($resource->popup)) {
            $info->extra =  urlencode("target=\"resource$resource->id\" onClick=\"return ".
                             "openpopup('/mod/resource/view.php?inpopup=true&id=".
                             $coursemodule->id.
-                            "','resource$resource->id','$resource->alltext');\"");
+                            "','resource$resource->id','$resource->popup');\"");
        }
 
        require_once("$CFG->dirroot/files/mimetypes.php");
 
-       if ($resource->type == UPLOADEDFILE or $resource->type == WEBLINK or $resource->type == WEBPAGE) {
+       if ($resource->type == 'file' or $resource->type == 'url') {
               $icon = mimeinfo("icon", $resource->reference);
            if ($icon != 'unknown.gif') {
                       $info->icon ="f/$icon";
-           } else if ($resource->type == WEBLINK or $resource->type == WEBPAGE) {
+           } else if ($resource->type == 'url') {
                       $info->icon ="f/web.gif";
            }
-       } else if ($resource->type == DIRECTORY) {
+       } else if ($resource->type == 'directory') {
                   $info->icon ="f/folder.gif";
        }
    }
@@ -339,4 +461,15 @@ function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix =
     return $text;
 }
 
+function resource_is_url($path) {
+    $path = strtolower($path);
+    if (substr($path, 0, 7) == "http://") {
+        return true;
+    }
+    if (substr($path, 0, 6) == "ftp://") {
+        return true;
+    }
+    return false;
+}
+
 ?>
index 28831b939d9e26ff4e21a76226e4bf9e9e755fb7..1a58d0a0a761f8a1bcea727b3b727a848c182261 100644 (file)
@@ -1,75 +1,13 @@
 <?php
-    if (empty($form->name)) {
-        $form->name = "";
-    }
-    if (empty($form->type)) {
-        $form->type = "";
-    }
-    if (empty($form->summary)) {
-        $form->summary = "";
-    }
-    if (empty($form->reference)) {
-        $form->reference = "";
-    }
-    if (empty($form->alltext)) {
-        $form->alltext = "";
-    }
-    $nohtmleditorneeded = true;
-?>
 
+require_once("$CFG->dirroot/mod/resource/lib.php");
+
+include_once("$CFG->dirroot/mod/resource/type/$form->type/resource.class.php");
+
+$resource = new resource();
 
-<form name="form" method="post" action="../mod/resource/details.php">
-<table cellpadding=5>
-<tr valign=top>
-    <td align=right><p><b><?php print_string("name") ?>:</b></p></td>
-    <td>
-        <input type="text" name="name" size=50 value="<?php p($form->name) ?>">
-    </td>
-</tr>
-<tr valign=top>
-    <td align=right><p><b><?php print_string("resourcetype", "resource") ?>:</b></p></td>
-    <td>
-    <?php
-       require("$CFG->dirroot/mod/resource/lib.php");
-       asort($RESOURCE_TYPE);
-       if (!$form->type) {
-          $form->type = 4;
-       }
-       choose_from_menu($RESOURCE_TYPE, "type", $form->type, "");
-       helpbutton("resourcetype", get_string("resourcetype", "resource"), "resource");
-    ?>
+$resource->setup($form);
 
-    </td>
-</tr>
-<tr valign=top>
-    <td align=right><p><b><?php print_string("summary") ?>:</b></p>
-     <font size="1">
-     <?php
-        helpbutton("summary", get_string("summary"), "resource", true, true);
-        echo "<br />";
-        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
-        echo "<br />";
-        helpbutton("text", get_string("helptext"), "moodle", true, true);
-     ?>
-     <br />
-     </font>
-    </td>
-    <td>
-        <?php print_textarea(false, 7, 50, 680, 400, "summary", $form->summary); ?>
-    </td>
-</tr>
-</table>
-<center>
-<input type="hidden" name=reference   value="<?php p($form->reference) ?>">
 
-<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) ?>">
-<input type="hidden" name=destination   value="<?php echo "$CFG->wwwroot/course/mod.php" ?>">
-<input type="submit" value="<?php print_string("continue") ?>">
-</center>
-</form>
+
+?>
diff --git a/mod/resource/type/common.html b/mod/resource/type/common.html
new file mode 100644 (file)
index 0000000..636ca11
--- /dev/null
@@ -0,0 +1,32 @@
+<form name="form" method="post" action="<?php echo "$CFG->wwwroot/course/mod.php" ?>">
+
+<input type="hidden" name="type"         value="<?php p($form->type) ?>">
+<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) ?>">
+
+<table cellpadding=5>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("name") ?>:</b></p></td>
+    <td>
+        <input type="text" name="name" size=65 value="<?php p($form->name) ?>">
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("summary") ?>:</b></p>
+     <font size="1">
+     <?php
+        helpbutton("summary", get_string("summary"), "resource", true, true);
+     ?>
+     <br />
+     </font>
+    </td>
+    <td>
+        <?php print_textarea($usehtmleditor, 10, 50, 680, 400, "summary", $form->summary); ?>
+    </td>
+</tr>
+
diff --git a/mod/resource/type/common_end.html b/mod/resource/type/common_end.html
new file mode 100644 (file)
index 0000000..d0ad113
--- /dev/null
@@ -0,0 +1,5 @@
+</table>
+<div align="center">
+<input type="submit" value="<?php print_string("savechanges") ?>">
+</div>
+</form>
diff --git a/mod/resource/type/directory/directory.html b/mod/resource/type/directory/directory.html
new file mode 100644 (file)
index 0000000..0d7a79b
--- /dev/null
@@ -0,0 +1,15 @@
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("resourcetypedirectory", "resource") ?>:</b></p>
+    </td>
+    <td>
+        <?php choose_from_menu($dirs, "reference", $form->reference, get_string("maindirectory", "resource"), '', '') ?>
+    </td>
+</tr>
+<tr valign="top">                                                                                                           <td align="right" nowrap>&nbsp;
+    </td>
+    <td>
+        <p><?php print_string("directoryinfo", "resource") ?></p>
+    </td>
+</tr>
+
diff --git a/mod/resource/type/directory/resource.class.php b/mod/resource/type/directory/resource.class.php
new file mode 100644 (file)
index 0000000..ae8526c
--- /dev/null
@@ -0,0 +1,168 @@
+<?php
+
+class resource extends resource_base {
+
+
+function resource($cmid=0) {
+    parent::resource_base($cmid);
+}
+
+
+function display() {
+    global $CFG, $THEME;
+
+
+    $strresource = get_string("modulename", "resource");
+    $strresources = get_string("modulenameplural", "resource");
+    $strlastmodified = get_string("lastmodified");
+
+    if ($this->course->category) {
+        require_login($this->course->id);
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> ->              
+                       <a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    } else {
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";             }                                                                                                             
+
+    require_once("../../files/mimetypes.php");
+
+    if (isset($_GET['subdir'])) {
+        $subdir = $_GET['subdir'];
+    }
+
+    add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+
+    if ($this->resource->reference) {
+        $relativepath = "{$this->course->id}/{$this->resource->reference}";
+    } else {
+        $relativepath = "{$this->course->id}";
+    }
+
+            if ($subdir) {
+                if (detect_munged_arguments($subdir)) {
+                    error("The value for 'subdir' contains illegal characters!");
+                }
+                $relativepath = "$relativepath$subdir";
+
+                $subs = explode('/', $subdir);
+                array_shift($subs);
+                $countsubs = count($subs);
+                $count = 0;
+                $subnav = "<a href=\"view.php?id={$this->cm->id}\">{$this->resource->name}</a>";
+                $backsub = '';
+                foreach ($subs as $sub) {
+                    $count++;
+                    if ($count < $countsubs) {
+                        $backsub .= "/$sub";
+                        $subnav  .= " -> <a href=\"view.php?id={$this->cm->id}&subdir=$backsub\">$sub</a>";
+                    } else {
+                        $subnav .= " -> $sub";
+                    }
+                }
+            } else {
+                $subnav = $this->resource->name;
+            }
+
+
+            print_header($pagetitle, $this->course->fullname, "$navigation $subnav",
+                         "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource),
+                         navmenu($this->course, $this->cm));
+
+            if (isteacheredit($this->course->id)) {
+                echo "<div align=\"right\"><img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\">&nbsp".
+                     "<a href=\"$CFG->wwwroot/files/index.php?id={$this->course->id}&wdir=/{$this->resource->reference}$subdir\">".
+                      get_string("editfiles")."...</a></div>";
+            }
+
+            if (trim($this->resource->summary)) {
+                print_simple_box(text_to_html($this->resource->summary), "center");
+                print_spacer(10,10);
+            }
+
+            $files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true);
+
+
+            if (!$files) {
+                print_heading(get_string("nofilesyet"));
+                print_footer($this->course);
+                exit;
+            }
+
+            print_simple_box_start("center", "", "$THEME->cellcontent", '0' );
+
+            $strftime = get_string('strftimedatetime');
+            $strname = get_string("name");
+            $strsize = get_string("size");
+            $strmodified = get_string("modified");
+
+            echo '<table cellpadding="4" cellspacing="1">';
+            echo "<tr><th colspan=\"2\">$strname</th>".
+                     "<th align=\"right\" colspan=\"2\">$strsize</th>".
+                     "<th align=\"right\">$strmodified</th>".
+                 "</tr>";
+            foreach ($files as $file) {
+                if (is_dir("$CFG->dataroot/$relativepath/$file")) {          // Must be a directory
+                    $icon = "folder.gif";
+                    $relativeurl = "/view.php?blah";
+                    $filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));
+
+                } else {
+                    $icon = mimeinfo("icon", $file);
+
+                    if ($CFG->slasharguments) {
+                        $relativeurl = "/file.php/$relativepath/$file";
+                    } else {
+                        $relativeurl = "/file.php?file=/$relativepath/$file";
+                    }
+                    $filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
+                }
+
+                echo '<tr>';
+                echo '<td>';
+                echo "<img src=\"$CFG->pixpath/f/$icon\" width=\"16\" height=\"16\">";
+                echo '</td>';
+                echo '<td nowrap="nowrap"><p>';
+                if ($icon == 'folder.gif') {
+                    echo "<a href=\"view.php?id={$this->cm->id}&subdir=$subdir/$file\">$file</a>";
+                } else {
+                    link_to_popup_window($relativeurl, "resourcedirectory{$this->resource->id}", "$file", 450, 600, '');
+                }
+                echo '</p></td>';
+                echo '<td>&nbsp;</td>';
+                echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
+                echo $filesize;
+                echo '</font></p></td>';
+                echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
+                echo userdate(filectime("$CFG->dataroot/$relativepath/$file"), $strftime);
+                echo '</font></p></td>';
+                echo '</tr>';
+            }
+            echo '</table>';
+
+            print_simple_box_end();
+
+            print_footer($this->course);
+
+}
+
+
+
+function setup($form) {
+    global $CFG;
+    
+    $rawdirs = get_directory_list("$CFG->dataroot/{$this->course->id}", 'moddata', true, true, false);
+    $dirs = array();
+    foreach ($rawdirs as $rawdir) {
+        $dirs[$rawdir] = $rawdir;
+    }
+    
+    parent::setup($form);
+    
+    include("$CFG->dirroot/mod/resource/type/directory/directory.html");
+
+    parent::setup_end();
+}
+
+
+}
+
+?>
diff --git a/mod/resource/type/file/file.html b/mod/resource/type/file/file.html
new file mode 100644 (file)
index 0000000..9a2da09
--- /dev/null
@@ -0,0 +1,141 @@
+
+<tr><td colspan="2"><hr /></td></tr>
+
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php echo $strfilename?>:</b></p>
+    </td>
+    <td>
+    <?php
+        echo "<input name=\"reference\" size=\"90\" value=\"$form->reference\"><br />";
+        button_to_popup_window ("/mod/resource/coursefiles.php?id=$form->course", "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
+        echo "<input type=\"button\" name=\"searchbutton\" value=\"$strsearch ...\" ".
+             "onClick=\"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');\">\n";
+    ?>
+    </td>
+</tr>
+
+<tr><td colspan="2"><hr /></td></tr>
+
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("pagewindow", "resource") ?>:</b></p>
+    </td>
+
+    <td>
+        <script>
+            var popupitems = [<?php echo $popupoptions; ?>];
+            var frameitem = [<?php echo $frameoption; ?>];
+            var allitems = [<?php echo $alloptions; ?>];
+        </script>
+        <input type="checkbox" name="windowpage" value=1 <?php echo ($windowtype == "page") ? "checked" : "" ?> onClick="lockoptions('form', 'windowpage', frameitem); document.form.windowpopup.checked=false; return lockoptions('form', 'windowpopup', popupitems);">
+        <?php print_string("pagedisplay", "resource") ?>
+        <ul>
+            <input type="hidden" name="hframepage" value=0>
+            <input type="checkbox" name="framepage" value=1 <?php echo ($form->options == "frame") ? "checked" : "" ?> >
+            <?php print_string("frameifpossible", "resource") ?>
+        </ul>
+    </td>
+</tr>
+
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php p($strnewwindow) ?>:</b></p>
+    </td>
+    
+    <td>
+        <input name="setnewwindow" type=hidden value=1>
+        <input name="windowpopup" type=checkbox value=1 onclick="lockoptions('form','windowpopup', popupitems); document.form.windowpage.checked=false; return lockoptions('form', 'windowpage', frameitem);">
+        <?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 ($windowtype == "page") {
+                echo "<script>";
+                echo "lockoptions('form','windowpopup', popupitems);";
+                echo "document.form.windowpage.checked=true;";
+                echo "document.form.windowpopup.checked=false;";
+                echo "</script>";
+            } else {
+                echo "<script>";
+                echo "lockoptions('form','windowpage', frameitem);";
+                echo "document.form.windowpopup.checked=true;";
+                echo "document.form.windowpage.checked=false;";
+                echo "</script>";
+            }
+        ?>
+        </ul>
+    </td>
+</tr>
+
+<tr><td colspan="2"><hr /></td></tr>
+
+<tr>
+    <td valign="top" align="right">
+        <p><b><?php print_string("parameters", "resource") ?>:</b></p>
+     <?php helpbutton("parameters", get_string("parameters", "resource"), "resource", true) ?>
+
+    </td>
+    <td valign="top" align="left">
+    
+        <table>
+        
+        <tr>
+            <td align="center"><p><?php print_string("parameter", "resource") ?></p></td>
+            <td align="center"><p><?php print_string("variablename", "resource") ?></p></td>
+        </tr>
+
+<?php
+
+for ($i=0; $i < $this->maxparameters; $i++) {
+    echo "<tr>\n";
+    echo "<td valign=\"top\">\n";
+    echo "<select name=\"parameter$i\">\n";
+    echo "<option value=\"-\">-- Choose Parameter --</option>\n";
+    foreach ($this->parameters as $field=>$fieldarr) {
+        if ($fieldarr['value'] === "optgroup") {
+            echo "<optgroup label=\"{$fieldarr['langstr']}\">\n";
+        } elseif ($fieldarr['value'] === "/optgroup") {
+            echo "</optgroup>\n";
+        } else {
+            echo "<option value=\"$field\"";
+            if ($alltextfield[$i]['parameter'] == $field) {
+                echo " selected";
+            }
+            echo ">{$fieldarr['langstr']}</option>\n";
+        }
+    }
+    echo "</td>\n";
+    echo "<td valign=\"top\">\n";
+    echo "<input type=\"text\" name=\"parse$i\" value=\"{$alltextfield[$i]['parse']}\">\n";
+    echo "</td>\n";
+    echo "</tr>\n";
+}
+
+?>
+
+        </table>
+    </td>
+</tr>
+
+<tr><td colspan="2"><hr /></td></tr>
+
+
diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php
new file mode 100644 (file)
index 0000000..2b04df7
--- /dev/null
@@ -0,0 +1,525 @@
+<?php
+
+/**
+* Extend the base resource class for file resources
+*
+* Extend the base resource class for file resources
+*
+*/
+class resource extends resource_base {
+
+var $parameters;
+var $maxparameters = 5;
+
+
+
+/**
+* Sets the parameters property of the extended class
+*
+* Sets the parameters property of the extended file resource class
+*
+* @param    USER  global object
+* @param    CFG   global object
+*/
+function set_parameters() {
+    global $USER, $CFG;
+    
+    if (! empty($this->course->lang)) {
+        $CFG->courselang = $this->course->lang;
+    }
+    $site = get_site();
+    
+
+    $this->parameters = array(
+
+            'label1'          => array('langstr' => get_string('user'),
+                                       'value'   => 'optgroup'),
+    
+            'userid'          => array('langstr' => 'id',
+                                       'value'   => $USER->id),
+            'userusername'    => array('langstr' => get_string('username'),
+                                       'value'   => $USER->username),
+            'useridnumber'    => array('langstr' => get_string('idnumber'),
+                                       'value'   => $USER->idnumber),
+            'userfirstname'   => array('langstr' => get_string('firstname'),
+                                       'value'   => $USER->firstname),
+            'userlastname'    => array('langstr' => get_string('lastname'),
+                                       'value'   => $USER->lastname),
+            'userfullname'    => array('langstr' => get_string('fullname'),
+                                       'value'   => fullname($USER)),
+            'useremail'       => array('langstr' => get_string('email'),
+                                       'value'   => $USER->email),
+            'usericq'         => array('langstr' => get_string('icqnumber'),
+                                       'value'   => $USER->icq),
+            'userphone1'      => array('langstr' => get_string('phone'),
+                                       'value'   => $USER->phone1),
+            'userinstitution' => array('langstr' => get_string('institution'),
+                                       'value'   => $USER->institution),
+            'userdepartment'  => array('langstr' => get_string('department'),
+                                       'value'   => $USER->department),
+            'useraddress'     => array('langstr' => get_string('address'),
+                                       'value'   => $USER->address),
+            'usercity'        => array('langstr' => get_string('city'),
+                                       'value'   => $USER->city),
+            'usertimezone'    => array('langstr' => get_string('timezone'),
+                                       'value'   => get_user_timezone()),
+            'userurl'         => array('langstr' => get_string('webpage'),
+                                       'value'   => $USER->url),
+
+            'label2'          => array('langstr' => "",
+                                       'value'   =>'/optgroup'),
+            'label3'          => array('langstr' => get_string('course'),
+                                       'value'   => 'optgroup'),
+                                                   
+            'courseid'        => array('langstr' => 'id',
+                                       'value'   => $this->course->id),
+            'coursefullname'  => array('langstr' => get_string('fullname'),
+                                       'value'   => $this->course->fullname),
+            'courseshortname' => array('langstr' => get_string('shortname'),
+                                       'value'   => $this->course->shortname),
+            'courseidnumber'  => array('langstr' => get_string('idnumber'),
+                                       'value'   => $this->course->idnumber),
+            'coursesummary'   => array('langstr' => get_string('summary'),
+                                       'value'   => $this->course->summary),
+            'courseformat'    => array('langstr' => get_string('format'),
+                                       'value'   => $this->course->format),
+            'courseteacher'   => array('langstr' => get_string('wordforteacher'),
+                                       'value'   => $this->course->teacher),
+            'courseteachers'  => array('langstr' => get_string('wordforteachers'),
+                                       'value'   => $this->course->teachers),
+            'coursestudent'   => array('langstr' => get_string('wordforstudent'),
+                                       'value'   => $this->course->student),
+            'coursestudents'  => array('langstr' => get_string('wordforstudents'),
+                                       'value'   => $this->course->students),
+                                    
+            'label4'          => array('langstr' => "",
+                                       'value'   =>'/optgroup'),
+            'label5'          => array('langstr' => get_string('miscellaneous'),
+                                       'value'   => 'optgroup'),
+                                                   
+            'lang'            => array('langstr' => get_string('preferredlanguage'),
+                                       'value'   => current_language()),
+            'sitename'        => array('langstr' => get_string('fullsitename'),
+                                       'value'   => $site->fullname),
+            'currenttime'     => array('langstr' => get_string('time'),
+                                       'value'   => time()),
+            'encryptedcode'   => array('langstr' => get_string('encryptedcode'),
+                                       'value'   => md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase)),
+                                                   
+            'label6'          => array('langstr' => "",
+                                       'value'   =>'/optgroup')
+            );
+                                                   
+}
+
+
+/**
+* Add new instance of file resource
+*
+* Create alltext field before calling base class function.
+*
+* @param    resource object
+*/
+function add_instance($resource) {
+    $optionlist = array();
+
+    for ($i = 0; $i < $this->maxparameters; $i++) {
+        $parametername = "parameter$i";
+        $parsename = "parse$i";
+        if (!empty($resource->$parsename) and $resource->$parametername != "-") {
+            $optionlist[] = $resource->$parametername."=".$resource->$parsename;
+        }
+    }
+    
+    $resource->alltext = implode(',', $optionlist);
+
+    return parent::add_instance($resource);
+}
+
+
+/**
+* Update instance of file resource
+*
+* Create alltext field before calling base class function.
+*
+* @param    resource object
+*/
+function update_instance($resource) {
+    $optionlist = array();
+    
+    for ($i = 0; $i < $this->maxparameters; $i++) {
+        $parametername = "parameter$i";
+        $parsename = "parse$i";
+        if (!empty($resource->$parsename) and $resource->$parametername != "-") {
+            $optionlist[] = $resource->$parametername."=".$resource->$parsename;
+        }
+    }
+    
+    $resource->alltext = implode(',', $optionlist);
+
+    return parent::update_instance($resource);
+}
+
+
+/**
+* Display the file resource
+*
+* Displays a file resource embedded, in a frame, or in a popup.
+* Output depends on type of file resource.
+*
+* @param    CFG     global object
+* @param    THEME   global object
+*/
+function display() {
+    global $CFG, $THEME;
+
+    $this->set_parameters(); // set the parameters array
+
+
+    $strresource = get_string("modulename", "resource");
+    $strresources = get_string("modulenameplural", "resource");
+    $strlastmodified = get_string("lastmodified");
+
+    if ($this->course->category) {
+        require_login($this->course->id);
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> ->              
+                       <a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    } else {
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    }
+
+
+
+///////////////////////////////////////////////
+
+    /// Possible display modes are:
+    /// File displayed in a frame in a normal window
+    /// File displayed embedded in a normal page
+    /// File displayed in a popup window
+    /// File displayed emebedded in a popup window
+            
+
+    /// First, find out what sort of file we are dealing with.
+    require_once("$CFG->dirroot/files/mimetypes.php");
+
+    $resourcetype = "";
+    $embedded = false;
+    $mimetype = mimeinfo("type", $this->resource->reference);
+
+    if ($this->resource->options != "frame") {
+        if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) {  // It's an image
+            $resourcetype = "image";
+            $embedded = true;
+                
+        } else if ($mimetype == "audio/mp3") {    // It's an MP3 audio file
+            $resourcetype = "mp3";
+            $embedded = true;
+                
+        } else if (substr($mimetype, 0, 10) == "video/x-ms") {   // It's a Media Player file
+            $resourcetype = "mediaplayer";
+            $embedded = true;
+                
+        } else if ($mimetype == "video/quicktime") {   // It's a Quicktime file
+            $resourcetype = "quicktime";
+            $embedded = true;
+
+        } else if ($mimetype == "text/html") {    // It's a web page
+            $resourcetype = "html";
+        }
+    }
+
+
+
+/// Form the parse string
+    if (!empty($this->resource->alltext)) {
+        $querys = array();
+        $parray = explode(',', $this->resource->alltext);
+        foreach ($parray as $fieldstring) {
+            $field = explode('=', $fieldstring);
+            $querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']);
+        }
+        $querystring = implode('&', $querys);
+    }
+
+    
+    /// Set up some variables
+
+    $inpopup = !empty($_GET["inpopup"]);
+
+    if (resource_is_url($this->resource->reference)) {
+        $fullurl = $this->resource->reference;
+        if ($querystring) {
+            $urlpieces = parse_url($this->resource->reference);
+            if (empty($urlpieces['query'])) {
+                $fullurl .= '?'.$querystring;
+            } else {
+                $fullurl .= '&'.$querystring;
+            }
+        }
+    } else {
+        if ($CFG->slasharguments) {
+            $relativeurl = "/file.php/{$this->course->id}/{$this->resource->reference}";
+            if ($querystring) {
+                $relativeurl .= '?'.$querystring;
+            }
+        } else {
+            $relativeurl = "/file.php?file=/{$this->course->id}/{$this->resource->reference}";
+            if ($querystring) {
+                $relativeurl .= '&'.$querystring;
+            }
+        }
+        $fullurl = "$CFG->wwwroot$relativeurl";
+    }
+
+
+    /// Check whether this is supposed to be a popup, but was called directly
+
+    if ($this->resource->popup and !$inpopup) {    /// Make a page and a pop-up window
+
+        print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm));
+
+
+        echo "\n<script language=\"Javascript\">";
+        echo "\n<!--\n";
+        echo "openpopup('/mod/resource/view.php?inpopup=true&id={$this->cm->id}','resource{$this->resource->id}','{$this->resource->popup}');\n";
+        echo "\n-->\n";
+        echo '</script>';
+
+        if (trim($this->resource->summary)) {
+            print_simple_box(text_to_html($this->resource->summary), "center");
+        }
+
+        $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$this->cm->id}\" target=\"resource{$this->resource->id}\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$this->cm->id}', 'resource{$this->resource->id}','{$this->resource->popup}');\">{$this->resource->name}</a>";
+
+        echo "<p>&nbsp</p>";
+        echo '<p align="center">';
+        print_string('popupresource', 'resource');
+        echo '<br />';
+        print_string('popupresourcelink', 'resource', $link);
+        echo "</p>";
+
+        print_footer($this->course);
+        exit;
+    }
+
+
+    /// Now check whether we need to display a frameset
+
+    if (empty($_GET['frameset']) and !$embedded and !$inpopup and $this->resource->options == "frame") {
+        echo "<head><title>{$this->course->shortname}: {$this->resource->name}</title></head>\n";
+        echo "<frameset rows=\"$CFG->resource_framesize,*\" border=\"2\">";
+        echo "<frame src=\"view.php?id={$this->cm->id}&type={$this->resource->type}&frameset=top\">";
+        echo "<frame src=\"$fullurl\">";
+        echo "</frameset>";
+        exit;
+    }
+
+
+    /// We can only get here once per resource, so add an entry to the log
+
+    add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+
+
+    /// If we are in a frameset, just print the top of it
+
+    if ($_GET['frameset'] == "top") {
+        print_header($pagetitle, $this->course->fullname, "$navigation <a target=\"$CFG->framename\" href=\"$fullurl\">{$this->resource->name}</a>", "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm, "parent"));
+
+        echo "<center><font size=-1>".text_to_html($this->resource->summary, true, false)."</font></center>";
+        echo "</body></html>";
+        exit;
+    }
+
+
+    /// Display the actual resource
+
+    if ($embedded) {       // Display resource embedded in page
+        $strdirectlink = get_string("directlink", "resource");
+
+        if ($inpopup) {
+            print_header($pagetitle);
+        } else {
+            print_header($pagetitle, $this->course->fullname, "$navigation <a title=\"$strdirectlink\" target=\"$CFG->framename\" href=\"$fullurl\"> {$this->resource->name}</a>", "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm, "self"));
+
+        }
+
+        if ($resourcetype == "image") {
+            echo "<center><p>";
+            echo "<img title=\"{$this->resource->name}\" class=\"resourceimage\" src=\"$fullurl\">";
+            echo "</p></center>";
+
+        } else if ($resourcetype == "mp3") {
+            echo "<center><p>";
+            echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
+            echo '        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
+            echo '        width="600" height="70" id="mp3player" align="">';
+            echo "<param name=movie value=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\">";
+            echo '<param name=quality value=high>';
+            echo '<param name=bgcolor value="#333333">';
+            echo "<embed src=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\" ";
+            echo " quality=high bgcolor=\"#333333\" width=\"600\" height=\"70\" name=\"mp3player\" ";
+            echo ' type="application/x-shockwave-flash" ';
+            echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
+            echo '</embed>';
+            echo '</object>';
+            echo "</p></center>";
+
+        } else if ($resourcetype == "mediaplayer") {
+            echo "<center><p>";
+            echo '<object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
+            echo '        codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
+            echo '        standby="Loading Microsoft® Windows® Media Player components..." ';
+            echo '        id="msplayer" align="" type="application/x-oleobject">';
+            echo "<param name=\"Filename\" value=\"$fullurl\">";
+            echo '<param name="ShowControls" value=true />';
+            echo '<param name="AutoRewind" value=true />';
+            echo '<param name="AutoStart" value=true />';
+            echo '<param name="Autosize" value=true />';
+            echo '<param name="EnableContextMenu" value=true />';
+            echo '<param name="TransparentAtStart" value=false />';
+            echo '<param name="AnimationAtStart" value=false />';
+            echo '<param name="ShowGotoBar" value=false />';
+            echo '<param name="EnableFullScreenControls" value=true />';
+            echo "\n<embed src=\"$fullurl\" name=\"msplayer\" type=\"$mimetype\" ";
+            echo ' ShowControls="1" AutoRewind="1" AutoStart="1" Autosize="0" EnableContextMenu="1"';
+            echo ' TransparentAtStart="0" AnimationAtStart="0" ShowGotoBar="0" EnableFullScreenControls="1"';
+            echo ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
+            echo '</embed>';
+            echo '</object>';
+            echo "</p></center>";
+
+        } else if ($resourcetype == "quicktime") {
+
+            echo "<center><p>";
+            echo '<object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
+            echo '        codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
+            echo '        height="450" width="600"';
+            echo '        id="quicktime" align="" type="application/x-oleobject">';
+            echo "<param name=\"src\" value=\"$fullurl\" />";
+            echo '<param name="autoplay" value=true />';
+            echo '<param name="loop" value=true />';
+            echo '<param name="controller" value=true />';
+            echo '<param name="scale" value="aspect" />';
+            echo "\n<embed src=\"$fullurl\" name=\"quicktime\" type=\"$mimetype\" ";
+            echo ' height="450" width="600" scale="aspect"';
+            echo ' autoplay="true" controller="true" loop="true" ';
+            echo ' pluginspage="http://quicktime.apple.com/">';
+            echo '</embed>';
+            echo '</object>';
+            echo "</p></center>";
+        }
+
+        if (trim($this->resource->summary)) {
+            print_simple_box(format_text($this->resource->summary), 'center');
+        }
+
+        if ($inpopup) {
+            echo "<center><p>(<a href=\"$fullurl\">$strdirectlink</a>)</p></center>";
+        } else {
+            print_spacer(20,20);
+            print_footer($this->course);
+        }
+    
+    } else {              // Display the resource on it's own
+        redirect($fullurl);
+    }
+    
+}
+
+
+
+/**
+* Setup a new file resource
+*
+* Display a form to create a new or edit an existing file resource
+*
+* @param    form                    object
+* @param    CFG                     global object
+* @param    usehtmleditor           global integer
+* @param    RESOURCE_WINDOW_OPTIONS global array
+*/
+function setup($form) {
+    global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS;
+
+    $this->set_parameters(); // set the parameter array for the form
+
+    
+    $strfilename = get_string("filename", "resource");
+    $strnote     = get_string("note", "resource");
+    $strchooseafile = get_string("chooseafile", "resource");
+    $strnewwindow     = get_string("newwindow", "resource");
+    $strnewwindowopen = get_string("newwindowopen", "resource");
+    $strsearch        = get_string("searchweb", "resource");
+
+    foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
+        $stringname = "str$optionname";
+        $$stringname = get_string("new$optionname", "resource");
+        $window->$optionname = "";
+        $jsoption[] = "\"$optionname\"";
+    }
+    
+    $frameoption = "\"framepage\"";
+    $popupoptions = implode(",", $jsoption);
+    $jsoption[] = $frameoption;
+    $alloptions = implode(",", $jsoption);
+
+
+
+    if ($form->instance) {     // Re-editing
+        if (!$form->popup) {
+            $windowtype = "page";   // No popup text => in page
+        } else {
+            $windowtype = "popup";
+            $rawoptions = explode(',', $form->popup);
+            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 {
+        foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
+            $defaultvalue = "resource_popup$optionname";
+            $window->$optionname = $CFG->$defaultvalue;
+        }
+
+        $windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
+        if (!isset($form->options)) {
+            $form->options = 'frame';
+            $form->reference = $CFG->resource_defaulturl;
+        }
+    }
+
+
+/// set the 5 parameter defaults
+    $alltextfield = array();
+    for ($i = 0; $i < $this->maxparameters; $i++) {
+        $alltextfield[] = array('parameter' => '',
+                                'parse'     => '');
+    }
+    /// load up any stored parameters
+    if (!empty($form->alltext)) {
+        $parray = explode(',', $form->alltext);
+        foreach ($parray as $key => $fieldstring) {
+            $field = explode('=', $fieldstring);
+            $alltextfield[$key]['parameter'] = $field[0];
+            $alltextfield[$key]['parse'] = $field[1];
+        }
+    }
+
+
+    parent::setup($form);
+
+    include("$CFG->dirroot/mod/resource/type/file/file.html");
+
+    parent::setup_end();
+}
+
+}
+
+?>
diff --git a/mod/resource/type/html/html.html b/mod/resource/type/html/html.html
new file mode 100644 (file)
index 0000000..53a279e
--- /dev/null
@@ -0,0 +1,14 @@
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("fulltext", "resource") ?>:</b></p><br />
+        <font size="1">
+            <?php  helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br />
+            <?php  helpbutton("text", get_string("helptext"), "moodle", true, true) ?> <br />
+            <?php  emoticonhelpbutton("theform", "alltext") ?> <br />
+        </font>
+    </td>
+    <td>
+        <?php print_textarea($usehtmleditor, 20, 60, 680, 400, "alltext", $form->alltext); ?>
+    </td>
+</tr> 
+
diff --git a/mod/resource/type/html/resource.class.php b/mod/resource/type/html/resource.class.php
new file mode 100644 (file)
index 0000000..59088d1
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+class resource extends resource_base {
+
+
+function resource($cmid=0) {
+    parent::resource_base($cmid);
+}
+
+
+function display() {
+    global $CFG, $THEME;
+
+
+    $strresource = get_string("modulename", "resource");
+    $strresources = get_string("modulenameplural", "resource");
+    $strlastmodified = get_string("lastmodified");
+
+    if ($this->course->category) {
+        require_login($this->course->id);
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> ->              
+                       <a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    } else {
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";             }                                                                                                             
+
+
+    add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+    print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}",
+                 "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm));
+
+    print_simple_box(format_text($this->resource->alltext, FORMAT_HTML), "center", "", "$THEME->cellcontent", "20");
+
+    echo "<center><p><font size=1>$strlastmodified: ".userdate($this->resource->timemodified)."</p></center>";
+
+    print_footer($this->course);
+}
+
+
+
+function setup($form) {
+    global $CFG, $usehtmleditor;
+    
+    parent::setup($form);
+
+    include("$CFG->dirroot/mod/resource/type/html/html.html");
+
+    parent::setup_end();
+}
+
+
+}
+
+?>
diff --git a/mod/resource/type/reference/reference.html b/mod/resource/type/reference/reference.html
new file mode 100644 (file)
index 0000000..d6e1971
--- /dev/null
@@ -0,0 +1,17 @@
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("resourcetypereference", "resource") ?>:</b></p>
+    </td>
+    <td>
+        <textarea name="reference" rows=3 cols=50 wrap="virtual"><?php  p($form->reference) ?></textarea>
+    </td>
+</tr>
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b>(<?php print_string("example", "resource") ?>)</b></p>
+    </td>
+    <td>
+        <p><?php print_string("examplereference", "resource") ?></p>
+    </td>
+</tr>
+
diff --git a/mod/resource/type/reference/resource.class.php b/mod/resource/type/reference/resource.class.php
new file mode 100644 (file)
index 0000000..ea9d8ec
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+class resource extends resource_base {
+
+
+function resource($cmid=0) {
+    parent::resource_base($cmid);
+}
+
+
+function display() {
+    global $CFG, $THEME;
+
+
+    $strresource = get_string("modulename", "resource");
+    $strresources = get_string("modulenameplural", "resource");
+    $strlastmodified = get_string("lastmodified");
+
+    if ($this->course->category) {
+        require_login($this->course->id);
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> ->              
+                       <a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    } else {
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";             }                                                                                                             
+
+
+    add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+    print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}",
+                 "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm));
+
+    print_simple_box($this->resource->reference, "center");
+    echo "<center><p>";
+    echo text_to_html($this->resource->summary);
+    echo "</p>";
+    echo "<p>&nbsp</p>";
+    echo "<p><font size=1>$strlastmodified: ".userdate($this->resource->timemodified)."</p>";
+    echo "</center>";
+    print_footer($this->course);
+}
+
+
+
+function setup($form) {
+    global $CFG;
+    
+    global $editorfields;
+    $editorfields = 'summary';
+    
+    parent::setup($form);
+    
+    include("$CFG->dirroot/mod/resource/type/reference/reference.html");
+
+    parent::setup_end();
+}
+
+
+}
+
+?>
diff --git a/mod/resource/type/text/resource.class.php b/mod/resource/type/text/resource.class.php
new file mode 100644 (file)
index 0000000..059f85d
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+class resource extends resource_base {
+
+
+function resource($cmid=0) {
+    parent::resource_base($cmid);
+}
+
+
+function display() {
+    global $CFG, $THEME;
+
+
+    $strresource = get_string("modulename", "resource");
+    $strresources = get_string("modulenameplural", "resource");
+    $strlastmodified = get_string("lastmodified");
+
+    if ($this->course->category) {
+        require_login($this->course->id);
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> ->              
+                       <a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";
+    } else {
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$strresources</a> ->";     }
+
+
+    add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+    print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}",
+                 "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm));
+
+    print_simple_box(format_text($this->resource->alltext, $this->resource->options), "center", "", "$THEME->cellcontent", "20");
+
+    echo "<center><p><font size=1>$strlastmodified: ".userdate($this->resource->timemodified)."</p></center>";
+
+    print_footer($this->course);
+}
+
+
+
+function setup($form) {
+    global $CFG;
+    
+    global $editorfields;
+    $editorfields = 'summary';
+    
+    parent::setup($form);
+    
+    $format_array = format_text_menu();
+    unset($format_array[FORMAT_HTML]);
+    include("$CFG->dirroot/mod/resource/type/text/text.html");
+
+    parent::setup_end();
+}
+
+
+}
+
+?>
diff --git a/mod/resource/type/text/text.html b/mod/resource/type/text/text.html
new file mode 100644 (file)
index 0000000..ae2334d
--- /dev/null
@@ -0,0 +1,24 @@
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("fulltext", "resource") ?>:</b></p><br />
+        <font size="1">
+            <?php  helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br />
+            <?php  emoticonhelpbutton("theform", "alltext") ?> <br />
+        </font>
+    </td>
+    <td>
+        <?php print_textarea(false, 30, 65, 680, 400, "alltext", $form->alltext); ?>
+    </td>
+</tr> 
+<tr valign="top">
+    <td align="right" nowrap>
+        <p><b><?php print_string("formattexttype") ?>:</b></p><br />
+    </td>
+    <td>
+        <?php choose_from_menu($format_array, "options", $form->options, '') ?>
+        <font size="1">
+            <?php  helpbutton("textformat", get_string("formattexttype")) ?><br />
+        </font>
+    </td>
+</tr> 
+
index f9049c7880e4d41b7a3f9a53d4b9c281340062b6..b9c945d7b7f63e876d506234b02575bf9450d97f 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004060400;
+$module->version  = 2004071303;
 $module->requires = 2004052501;  // Requires this Moodle version
 $module->cron     = 0;
 
index 12dcd6b530a90044b42a7aae03f686ee3e23d7be..4938781644be98b2aeebde4fba2c2096775442d4 100644 (file)
@@ -4,8 +4,8 @@
     require_once("lib.php");
  
     require_variable($id);    // Course Module ID
-    optional_variable($frameset, "");
-    optional_variable($subdir, "");
+//    optional_variable($frameset, "");
+//    optional_variable($subdir, "");
 
     if (!empty($CFG->forcelogin)) {
         require_login();
         error("Course Module ID was incorrect");
     }
 
-    if (! $course = get_record("course", "id", $cm->course)) {
-        error("Course is misconfigured");
-    }
-
     if (! $resource = get_record("resource", "id", $cm->instance)) {
         error("Resource ID was incorrect");
     }
 
-    $strresource = get_string("modulename", "resource");
-    $strresources = get_string("modulenameplural", "resource");
-    $strlastmodified = get_string("lastmodified");
-
-    if ($course->category) {
-        require_login($course->id);
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
-                       <a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strresources</a> ->";
-    } else {
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strresources</a> ->";
-    }
-
-    $pagetitle = strip_tags("$course->shortname: $resource->name");
-
-    if (!$cm->visible and !isteacher($course->id)) {
-        print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, 
-                     update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-        notice(get_string("activityiscurrentlyhidden"));
-    }
-
-    switch ($resource->type) {
-        case REFERENCE:
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, 
-                         update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-            print_simple_box($resource->reference, "center");
-            echo "<center><p>";
-            echo text_to_html($resource->summary);
-            echo "</p>";
-            echo "<p>&nbsp</p>";
-            echo "<p><font size=1>$strlastmodified: ".userdate($resource->timemodified)."</p>";
-            echo "</center>";
-            print_footer($course);
-            break;
-
-        case WEBLINK:
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-
-            $inpopup = !empty($_GET["inpopup"]);
-
-            if ($resource->alltext and !$inpopup) {    /// Make a page and a pop-up window
-                print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, 
-                             update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-                echo "\n<script language=\"Javascript\">";
-                echo "\n<!--\n";
-                echo "openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id',".
-                     "'resource$resource->id','$resource->alltext');\n";
-                echo "\n-->\n";
-                echo '</script>';
-
-                if (trim($resource->summary)) {
-                    print_simple_box(text_to_html($resource->summary), "center");
-                }
-
-                $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id=$cm->id\" target=\"resource$resource->id\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id', 'resource$resource->id','$resource->alltext');\">$resource->name</a>";
-
-                echo "<p>&nbsp</p>";
-                echo '<p align="center">';
-                print_string('popupresource', 'resource');
-                echo '<br />';
-                print_string('popupresourcelink', 'resource', $link);
-                echo "</p>";
-
-                print_footer($course);
-                die;
-            }
-
-            if ($CFG->resource_filterexternalpages) {
-                $url = "fetch.php?id=$cm->id&url=$resource->reference";
-            } else {
-                $url = "$resource->reference";
-            }
-            redirect($url, "", 0);
-            break;
-
-        case WEBPAGE:
-            if ($frameset == "top") {
-                print_header($pagetitle, "$course->fullname", 
-                  "$navigation <a target=\"{$CFG->framename}\" href=\"$resource->reference\" 
-                                title=\"$resource->reference\">$resource->name</a>", "", "", true, 
-                                update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm, "parent"));
-                echo "<center><font size=-1>".text_to_html($resource->summary, true, false)."</font></center>";
-
-            } else {
-                if ($CFG->resource_filterexternalpages) {
-                    $url = "fetch.php?id=$cm->id&url=$resource->reference";
-                } else {
-                    $url = "$resource->reference";
-                }
-                add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-                echo "<head><title>$course->shortname: $resource->name</title></head>\n";
-                echo "<frameset rows=\"$CFG->resource_framesize,*\" border=\"2\">";
-                echo "<frame src=\"view.php?id=$cm->id&frameset=top\">";
-                echo "<frame src=\"$url\">";
-                echo "</frameset>";
-            }
-            break;
-
-        case UPLOADEDFILE:
-            /// Possible display modes are:
-            /// File displayed in a frame in a normal window
-            /// File displayed embedded in a normal page
-            /// File displayed in a popup window
-            /// File displayed emebedded in a popup window
-           
-
-            /// First, find out what sort of file we are dealing with.
-            require_once("../../files/mimetypes.php");
-
-            $resourcetype = "";
-            $embedded = false;
-            $mimetype = mimeinfo("type", $resource->reference);
-
-            if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) {  // It's an image
-                $resourcetype = "image";
-                $embedded = true;
-
-            } else if ($mimetype == "audio/mp3") {    // It's an MP3 audio file
-                $resourcetype = "mp3";
-                $embedded = true;
-
-            } else if (substr($mimetype, 0, 10) == "video/x-ms") {   // It's a Media Player file
-                $resourcetype = "mediaplayer";
-                $embedded = true;
-
-            } else if ($mimetype == "video/quicktime") {   // It's a Quicktime file
-                $resourcetype = "quicktime";
-                $embedded = true;
-
-            } else if ($mimetype == "text/html") {    // It's a web page
-                $resourcetype = "html";
-            }
-
-
-            /// Set up some variables
-
-            $inpopup = !empty($_GET["inpopup"]);
-
-            if ($CFG->slasharguments) {
-                $relativeurl = "/file.php/$course->id/$resource->reference";
-            } else {
-                $relativeurl = "/file.php?file=/$course->id/$resource->reference";
-            }
-            $fullurl = "$CFG->wwwroot$relativeurl";
-
-
-            /// Check whether this is supposed to be a popup, but was called directly
-
-            if ($resource->alltext and !$inpopup) {    /// Make a page and a pop-up window
-                print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, 
-                             update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-                echo "\n<script language=\"Javascript\">";
-                echo "\n<!--\n";
-                echo "openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id','resource$resource->id','$resource->alltext');\n";
-                echo "\n-->\n";
-                echo '</script>';
-
-                if (trim($resource->summary)) {
-                    print_simple_box(text_to_html($resource->summary), "center");
-                }
-
-                $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id=$cm->id\" target=\"resource$resource->id\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id', 'resource$resource->id','$resource->alltext');\">$resource->name</a>";
-
-                echo "<p>&nbsp</p>";
-                echo '<p align="center">';
-                print_string('popupresource', 'resource');
-                echo '<br />';
-                print_string('popupresourcelink', 'resource', $link);
-                echo "</p>";
-
-                print_footer($course);
-                exit;
-            }
-
-
-            /// Now check whether we need to display a frameset
-
-            if (empty($frameset) and !$embedded and !$inpopup) { 
-                echo "<head><title>$course->shortname: $resource->name</title></head>\n";
-                echo "<frameset rows=\"$CFG->resource_framesize,*\" border=\"2\">";
-                echo "<frame src=\"view.php?id=$cm->id&frameset=top\">";
-                echo "<frame src=\"$fullurl\">";
-                echo "</frameset>";
-                exit;
-            }
-
-
-            /// We can only get here once per resource, so add an entry to the log
-
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-
-
-            /// If we are in a frameset, just print the top of it
-
-            if ($frameset == "top") { 
-                print_header($pagetitle, "$course->fullname", 
-                             "$navigation <a target=\"$CFG->framename\" href=\"$fullurl\">$resource->name</a>",
-                             "", "", true, update_module_button($cm->id, $course->id, $strresource), 
-                             navmenu($course, $cm, "parent"));
-                echo "<center><font size=-1>".text_to_html($resource->summary, true, false)."</font></center>";
-                echo "</body></html>";
-                exit;
-            }
-
-
-            /// Display the actual resource
-
-            if ($embedded) {       // Display resource embedded in page
-                $strdirectlink = get_string("directlink", "resource");
+    require ("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
 
-                if ($inpopup) {
-                    print_header($pagetitle);
-                } else {
-                    print_header($pagetitle, "$course->fullname", 
-                                 "$navigation <a title=\"$strdirectlink\" target=\"$CFG->framename\" ".
-                                 "href=\"$fullurl\">$resource->name</a>",
-                                 "", "", true, update_module_button($cm->id, $course->id, $strresource), 
-                                 navmenu($course, $cm, "self"));
-                }
+    $resourceinstance = new resource($id);
 
-                if ($resourcetype == "image") {  
-                    echo "<center><p>";
-                    echo "<img title=\"$resource->name\" class=\"resourceimage\" src=\"$fullurl\">";
-                    echo "</p></center>";
-
-                } else if ($resourcetype == "mp3") {  
-                    echo "<center><p>";
-                    echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
-                    echo '        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
-                    echo '        width="600" height="70" id="mp3player" align="">';
-                    echo "<param name=movie value=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\">";
-                    echo '<param name=quality value=high>';
-                    echo '<param name=bgcolor value="#333333">';
-                    echo "<embed src=\"$CFG->wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\" ";
-                    echo " quality=high bgcolor=\"#333333\" width=\"600\" height=\"70\" name=\"mp3player\" ";
-                    echo ' type="application/x-shockwave-flash" ';
-                    echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
-                    echo '</embed>';
-                    echo '</object>';
-                    echo "</p></center>";
-
-                } else if ($resourcetype == "mediaplayer") {  
-                    echo "<center><p>";
-                    echo '<object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
-                    echo '        codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
-                    echo '        standby="Loading Microsoft® Windows® Media Player components..." ';
-                    echo '        id="msplayer" align="" type="application/x-oleobject">';
-                    echo "<param name=\"Filename\" value=\"$fullurl\">";
-                    echo '<param name="ShowControls" value=true />';
-                    echo '<param name="AutoRewind" value=true />';
-                    echo '<param name="AutoStart" value=true />';
-                    echo '<param name="Autosize" value=true />';
-                    echo '<param name="EnableContextMenu" value=true />';
-                    echo '<param name="TransparentAtStart" value=false />';
-                    echo '<param name="AnimationAtStart" value=false />';
-                    echo '<param name="ShowGotoBar" value=false />';
-                    echo '<param name="EnableFullScreenControls" value=true />';
-                    echo "\n<embed src=\"$fullurl\" name=\"msplayer\" type=\"$mimetype\" ";
-                    echo ' ShowControls="1" AutoRewind="1" AutoStart="1" Autosize="0" EnableContextMenu="1"';
-                    echo ' TransparentAtStart="0" AnimationAtStart="0" ShowGotoBar="0" EnableFullScreenControls="1"';
-                    echo ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
-                    echo '</embed>';
-                    echo '</object>';
-                    echo "</p></center>";
-
-                } else if ($resourcetype == "quicktime") {  
-
-                    echo "<center><p>";
-                    echo '<object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
-                    echo '        codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
-                    echo '        height="450" width="600"';
-                    echo '        id="quicktime" align="" type="application/x-oleobject">';
-                    echo "<param name=\"src\" value=\"$fullurl\" />";
-                    echo '<param name="autoplay" value=true />';
-                    echo '<param name="loop" value=true />';
-                    echo '<param name="controller" value=true />';
-                    echo '<param name="scale" value="aspect" />';
-                    echo "\n<embed src=\"$fullurl\" name=\"quicktime\" type=\"$mimetype\" ";
-                    echo ' height="450" width="600" scale="aspect"';
-                    echo ' autoplay="true" controller="true" loop="true" ';
-                    echo ' pluginspage="http://quicktime.apple.com/">';
-                    echo '</embed>';
-                    echo '</object>';
-                    echo "</p></center>";
-                }
-
-                if (trim($resource->summary)) {
-                    print_simple_box(format_text($resource->summary), 'center');
-                }
-
-                if ($inpopup) {
-                    echo "<center><p>(<a href=\"$fullurl\">$strdirectlink</a>)</p></center>";
-                } else {
-                    print_spacer(20,20);
-                    print_footer($course);
-                }
-
-            } else {              // Display the resource on it's own
-                redirect($fullurl);
-            }
-            break;
-
-
-        case PLAINTEXT:
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
-                         "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-            print_simple_box(format_text($resource->alltext), "center", "", "$THEME->cellcontent", "20");
-
-            echo "<center><p><font size=1>$strlastmodified: ".userdate($resource->timemodified)."</p></center>";
-
-            print_footer($course);
-            break;
-
-        case HTML:
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
-                         "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-            print_simple_box_start("center", "", "$THEME->cellcontent", "20");
-
-            echo format_text($resource->alltext, FORMAT_HTML);
-
-            print_simple_box_end();
-
-            echo "<center><p><font size=1>$strlastmodified: ".userdate($resource->timemodified)."</p></center>";
-
-            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, $cm->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;
-
-        case WIKITEXT:
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
-                "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-
-            print_simple_box(format_text($resource->alltext, FORMAT_WIKI), "center", "", "$THEME->cellcontent", "20" );
-
-            echo "<center><p><font size=\"1\">$strlastmodified: ".userdate($resource->timemodified)."</p></center>";
-
-            print_footer($course);
-            break;
-
-        case DIRECTORY:
-            require_once("../../files/mimetypes.php");
-
-            add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-
-            if ($resource->reference) {
-                $relativepath = "$course->id/$resource->reference";
-            } else {
-                $relativepath = "$course->id";
-            }
-            
-            if ($subdir) {
-                if (detect_munged_arguments($subdir)) {
-                    error("The value for 'subdir' contains illegal characters!");
-                }
-                $relativepath = "$relativepath$subdir";
-
-                $subs = explode('/', $subdir);
-                array_shift($subs);
-                $countsubs = count($subs);
-                $count = 0;
-                $subnav = "<a href=\"view.php?id=$cm->id\">$resource->name</a>";
-                $backsub = '';
-                foreach ($subs as $sub) {
-                    $count++;
-                    if ($count < $countsubs) {
-                        $backsub .= "/$sub";
-                        $subnav  .= " -> <a href=\"view.php?id=$cm->id&subdir=$backsub\">$sub</a>";
-                    } else {
-                        $subnav .= " -> $sub";
-                    }
-                }
-            } else {
-                $subnav = $resource->name;
-            }
-
-            print_header($pagetitle, "$course->fullname", "$navigation $subnav",
-                         "", "", true, update_module_button($cm->id, $course->id, $strresource), 
-                         navmenu($course, $cm));
-
-            if (isteacheredit($course->id)) {
-                echo "<div align=\"right\"><img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\">&nbsp".
-                     "<a href=\"$CFG->wwwroot/files/index.php?id=$course->id&wdir=/$resource->reference$subdir\">".
-                      get_string("editfiles")."...</a></div>";
-            }
-
-
-            if (trim($resource->summary)) {
-                print_simple_box(text_to_html($resource->summary), "center");
-                print_spacer(10,10);
-            }
-
-            $files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true);
-
-
-            if (!$files) {
-                print_heading(get_string("nofilesyet"));
-                print_footer($course);
-                exit;
-            }
-
-            print_simple_box_start("center", "", "$THEME->cellcontent", '0' );
-
-            $strftime = get_string('strftimedatetime');
-            $strname = get_string("name");
-            $strsize = get_string("size");
-            $strmodified = get_string("modified");
-
-            echo '<table cellpadding="4" cellspacing="1">';
-            echo "<tr><th colspan=\"2\">$strname</th>". 
-                     "<th align=\"right\" colspan=\"2\">$strsize</th>".
-                     "<th align=\"right\">$strmodified</th>".
-                 "</tr>";
-            foreach ($files as $file) {
-                if (is_dir("$CFG->dataroot/$relativepath/$file")) {          // Must be a directory
-                    $icon = "folder.gif";
-                    $relativeurl = "/view.php?blah";
-                    $filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));
-
-                } else {
-                    $icon = mimeinfo("icon", $file);
-
-                    if ($CFG->slasharguments) {
-                        $relativeurl = "/file.php/$relativepath/$file";
-                    } else {
-                        $relativeurl = "/file.php?file=/$relativepath/$file";
-                    }
-                    $filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
-                }
-
-                echo '<tr>';
-                echo '<td>';
-                echo "<img src=\"$CFG->pixpath/f/$icon\" width=\"16\" height=\"16\">";
-                echo '</td>';
-                echo '<td nowrap="nowrap"><p>';
-                if ($icon == 'folder.gif') {
-                    echo "<a href=\"view.php?id=$cm->id&subdir=$subdir/$file\">$file</a>";
-                } else {
-                    link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, '');
-                }
-                echo '</p></td>';
-                echo '<td>&nbsp;</td>';
-                echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
-                echo $filesize;
-                echo '</font></p></td>';
-                echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
-                echo userdate(filectime("$CFG->dataroot/$relativepath/$file"), $strftime);
-                echo '</font></p></td>';
-                echo '</tr>';
-            }
-            echo '</table>';
-
-            print_simple_box_end();
-
-            print_footer($course);
-            break;
-
-        default:
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
-                         "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
-            print_heading($resource->name);
-
-            print_simple_box("Error: unknown type of resource", "center");
-
-            print_footer($course);
-            break;
-    }
+    $resourceinstance->display();
 
 ?>