Good work for a Sunday moodlers.
Here is a bigger hack modifying only file.php but correcting many ( it is not completed but it give a good idea on how to finish it that way ).
It use log to check from where came the student.
It also treat not visible resources.
Is there things that are not possible that way? ( please don't tell things that are not done it is not finished).
Have a good cogitation,
Bernard
p.s. I lost some indentation in the txt file
//bb
if (!isteacher($course->id) and !isadmin() ) {
$logs = get_records("log", "userid", $USER->id);
foreach ($logs as $log) { // sure it exist a better way to get the last one
}
switch ($log->module) {
case "course":
$label = get_records_sql("SELECT *
FROM {$CFG->prefix}label
WHERE course= $courseid
AND content
LIKE '%$filename%'");
$section = get_records_sql("SELECT *
FROM {$CFG->prefix}course_sections
WHERE course= $courseid
AND summary
LIKE '%$filename%'");
$resource = get_record_sql("SELECT *
FROM {$CFG->prefix}resource
WHERE course= $courseid
AND reference
LIKE '%$filename%'");
if ($resource ) {
$module = get_record("course_modules", "course", $courseid,"module", 6,"instance", $resource->id);
}
if (!$section and !$label and (!$resource or !$module->visible)) {
notice("<center>You cannot access this item directly until it appears in the course</center> ");
}
break;
case "resource":
if (!$resource = get_records_sql("SELECT *
FROM {$CFG->prefix}resource
WHERE course= $courseid
AND reference
LIKE '%$filename%'")) {
notice("<center>You cannot access this item directly until it appears in the course</center> ");
}
break;
case "quiz":
if (!$quiz = get_records_sql("SELECT *
FROM {$CFG->prefix}quiz_questions
WHERE 1
AND image LIKE '%$filename%'
OR
questiontext LIKE '%$filename%'") ) {
notice("<center>You cannot access this item directly until it appears in the course</center> ");
}
break;
default:
$resource = get_record_sql("SELECT *
FROM {$CFG->prefix}resource
WHERE course= $courseid
AND reference
LIKE '%$filename%'");
if ($resource ) {
$module = get_record("course_modules", "course", $courseid,"module", 6,"instance", $resource->id);
}
if (!$resource or !$module->visible) {
notice("<center>You cannot access this item directly until it appears in the course</center> ");
}
break;
}
}