MDL-7821 wrong use of cm in data mod and added proper require_login(); backported from HEAD

This commit is contained in:
skodak
2006-12-06 20:24:19 +00:00
parent 5ceee287f3
commit 3bd8388689
7 changed files with 19 additions and 28 deletions
+5 -3
View File
@@ -24,10 +24,12 @@
if (! $course = get_record('course', 'id', $data->course)) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
error('Course Module ID was incorrect');
}
require_login($course->id);
require_login($course->id, false, $cm);
$cm = data_get_cm($data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($commentid) {
@@ -111,7 +113,7 @@
default: //print all listing, and add comment form
print_header();
data_print_comments($data, $record, $search, $template, $sort, $page, $rid, $order, $group);
data_print_comments($data, $record, $page);
print_footer();
break;
+1 -1
View File
@@ -56,7 +56,7 @@
}
}
require_course_login($course, false, $cm);
require_login($course->id, false, $cm);
if (!isloggedin() or isguest()) {
redirect('view.php?d='.$data->id);
+2 -2
View File
@@ -41,7 +41,7 @@
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
error('Course Module ID was incorrect');
}
if (! $course = get_record('course', 'id', $cm->course)) {
@@ -63,7 +63,7 @@
}
}
require_course_login($course, true, $cm);
require_login($course->id, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:managetemplates', $context);
+5 -16
View File
@@ -545,8 +545,8 @@ function data_numentries($data){
****************************************************************/
function data_add_record($data, $groupid=0){
global $USER;
$cm = data_get_cm($data);
$cm = get_coursemodule_from_instance('data', $data->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$record->userid = $USER->id;
@@ -835,7 +835,7 @@ function data_get_coursemodule_info($coursemodule) {
function data_print_template($template, $records, $data, $search='',$page=0, $return=false) {
global $CFG;
$cm = data_get_cm($data);
$cm = get_coursemodule_from_instance('data', $data->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
static $fields = NULL;
@@ -987,7 +987,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
function data_print_ratings($data, $record) {
global $USER;
$cm = data_get_cm($data);
$cm = get_coursemodule_from_instance('data', $data->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$ratingsmenuused = false;
@@ -1160,7 +1160,7 @@ function data_print_comment($data, $comment, $page=0) {
global $USER, $CFG;
$cm = data_get_cm($data);
$cm = get_coursemodule_from_instance('data', $data->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$stredit = get_string('edit');
@@ -1249,17 +1249,6 @@ function data_convert_arrays_to_strings(&$fieldinput) {
}
}
// returns the $cm given $data
function data_get_cm($data) {
global $CFG, $course;
$datamod = get_record('modules', 'name', 'data');
$SQL = "select * from {$CFG->prefix}course_modules
where course = $course->id and
module = $datamod->id and
instance = $data->id";
return get_record_sql($SQL);
}
/**
* Converts a database (module instance) to use the Roles System
+3 -3
View File
@@ -19,8 +19,8 @@ $shortname = optional_param('shortname', '', PARAM_FILE); // directory the pres
$file = optional_param('file', '', PARAM_FILE); // uploaded file
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
error('Course Module ID Incorrect');
if (! $cm = get_coursemodule_from_id('data', $id)) {
error('Course Module ID was incorrect');
}
if (! $course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured');
@@ -46,7 +46,7 @@ if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
error('Could not find context');
}
require_login($course->id);
require_login($course->id, false, $cm);
require_capability('mod/data:managetemplates', $context);
-1
View File
@@ -29,7 +29,6 @@
error('You cannot call this script in that way');
}
$cm = data_get_cm($data);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$inactive = NULL;
+3 -2
View File
@@ -33,7 +33,7 @@
$mode = optional_param('mode', 'singletemplate', PARAM_ALPHA);
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
error('Course Module ID was incorrect');
}
if (! $course = get_record('course', 'id', $cm->course)) {
@@ -55,7 +55,8 @@
}
}
require_course_login($course, true, $cm);
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:managetemplates', $context);