]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8262 fixed require_course_login and $COURSE logic
authorskodak <skodak>
Mon, 22 Jan 2007 18:49:42 +0000 (18:49 +0000)
committerskodak <skodak>
Mon, 22 Jan 2007 18:49:42 +0000 (18:49 +0000)
mod/resource/index.php
mod/resource/lib.php
mod/resource/view.php

index daef0b5ac5aeeef01809cdba186ce4e1b967640d..22cd156bc5698212544c8b9781e09b560c21ce89 100644 (file)
@@ -4,14 +4,12 @@
 
     $id = required_param( 'id', PARAM_INT ); // course
 
-    if (!empty($CFG->forcelogin)) {
-        require_login();
-    }
-
     if (! $course = get_record("course", "id", $id)) {
         error("Course ID is incorrect");
     }
 
+    require_course_login($course, true);
+
     if ($course->id != SITEID) {
         require_login($course->id);
         $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
index 381ab6c79774168bae7bc5c60622cd9124cf5f03..2ef5358fe44552275d452090c83187a249700362 100644 (file)
@@ -90,8 +90,7 @@ var $resource;
 */
 function resource_base($cmid=0) {
 
-    global $CFG;
-    global $course;   // Ugly hack, needed for course language ugly hack
+    global $CFG, $COURSE;
 
     if ($cmid) {
         if (! $this->cm = get_coursemodule_from_id('resource', $cmid)) {
@@ -102,10 +101,6 @@ function resource_base($cmid=0) {
             error("Course is misconfigured");
         }
 
-        $course = $this->course;  // Make it a global so we can see it later
-
-        require_course_login($this->course, true, $this->cm);
-
         if (! $this->resource = get_record("resource", "id", $this->cm->instance)) {
             error("Resource ID was incorrect");
         }
@@ -125,6 +120,8 @@ function resource_base($cmid=0) {
             print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strresource", "", "", true, '', navmenu($this->course, $this->cm));
             notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
         }
+    } else {
+        $this->course = $COURSE;
     }
 }
 
@@ -209,94 +206,14 @@ function display_course_blocks_end() {
 }
 
 
-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 = "";
-    }
-    if (empty($form->options)) {
-        $form->options = "";
-    }
-    $nohtmleditorneeded = true;
-
-    print_heading_with_help(get_string("resourcetype$form->type", 'resource'), $form->type, 'resource/type');
-
-    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
 // of the new instance.
 
-    global $RESOURCE_WINDOW_OPTIONS;
-
     $resource->timemodified = time();
 
-    if (isset($resource->windowpopup)) {
-        if ($resource->windowpopup) {
-            $optionlist = array();
-            foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
-                if (isset($resource->$option)) {
-                    $optionlist[] = $option."=".$resource->$option;
-                }
-            }
-            $resource->popup = implode(',', $optionlist);
-            $resource->options = "";
-        } else {
-            if (isset($resource->framepage)) {
-                $resource->options = "frame";
-            } else {
-                $resource->options = "";
-            }
-            $resource->popup = "";
-        }
-    }
-
-    if (isset($resource->parametersettingspref)) {
-        set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
-    }
-    if (isset($resource->windowsettingspref)) {
-        set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
-    }
-    
-    // fix for MDL-7300
-    if (!isset($resource->alltext)) { 
-        $resource->alltext = '';  
-    }
-
-    if (!isset($resource->popup)) {
-        $resource->popup = '';  
-    }    
-        
     return insert_record("resource", $resource);
 }
 
@@ -306,38 +223,9 @@ function update_instance($resource) {
 // (defined by the form in mod.html) this function
 // will update an existing instance with new data.
 
-    global $RESOURCE_WINDOW_OPTIONS;
-
     $resource->id = $resource->instance;
     $resource->timemodified = time();
 
-    if (isset($resource->windowpopup)) {
-        if ($resource->windowpopup) {
-            $optionlist = array();
-            foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
-                if (isset($resource->$option)) {
-                    $optionlist[] = $option."=".$resource->$option;
-                }
-            }
-            $resource->popup = implode(',', $optionlist);
-            $resource->options = "";
-        } else {
-            if (isset($resource->framepage)) {
-                $resource->options = "frame";
-            } else {
-                $resource->options = "";
-            }
-            $resource->popup = "";
-        }
-    }
-
-    if (isset($resource->parametersettingspref)) {
-        set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
-    }
-    if (isset($resource->windowsettingspref)) {
-        set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
-    }
-
     return update_record("resource", $resource);
 }
 
@@ -356,7 +244,13 @@ function delete_instance($resource) {
     return $result;
 }
 
+function setup_elements(&$mform) {
+    //override to add your own options
+}
 
+function setup_preprocessing(&$default_values){
+    //override to add your own options
+}
 
 } /// end of class definition
 
@@ -410,6 +304,7 @@ function resource_user_outline($course, $user, $mod, $resource) {
         $numviews = count($logs);
         $lastlog = array_pop($logs);
 
+        $result = new object();
         $result->info = get_string("numviews", "", $numviews);
         $result->time = $lastlog->time;
 
@@ -630,6 +525,8 @@ function resource_is_url($path) {
 }
 
 function resource_get_types() {
+    global $CFG;
+
     $types = array();
 
     $standardresources = array('text','html','file','directory');
index fb14875315a660f496ac40013ecd1fde929b7a51..5c04177d95fd737403fde616c11fe0939921b0fc 100644 (file)
@@ -6,10 +6,6 @@
     $id = optional_param('id', 0, PARAM_INT);    // Course Module ID
     $r  = optional_param('r', 0, PARAM_INT);  // Resource
 
-    if (!empty($CFG->forcelogin)) {
-        require_login();
-    }
-
     if ($r) {  // Two ways to specify the resource
         if (! $resource = get_record('resource', 'id', $r)) {
             error('Resource ID was incorrect');
@@ -31,6 +27,8 @@
         error('No valid parameters!!');
     }
 
+    require_course_login($course, true, $cm);
+
     require ($CFG->dirroot.'/mod/resource/type/'.$resource->type.'/resource.class.php');
     $resourceclass = 'resource_'.$resource->type;
     $resourceinstance = new $resourceclass($cm->id);