Source for file filter_user.lib.php
Documentation is available at filter_user.lib.php
* This script declares a set of functions that will enable authorization check
* for a user's access to a course directory, as well as course name
* translations for search results display.
* @author Yannick Warnier <yannick.warnier@dokeos.com>
* @uses The Dokeos database library, to access the tables using its facilities
* @uses The Dokeos main api library to execute database queries
* Checks if a user can access a given course
* The function gets the course code from the course directory, then
* checks in the course_user table if the user has access to that course.
* @param integer User ID (inside Dokeos)
* @param string Course directory
* @return boolean True if user has access, false otherwise
$sql = "SELECT code FROM $course WHERE directory = '$course_dir'";
//Course found. Get the course code.
$course_code = $row['code'];
$sql = "SELECT * FROM $course_user
WHERE course_code = '$course_code'
AND user_id = '$user_id'";
//User permission found, go further and check there is a status
//Status found (we may later check this further to refine permissions)
//Sometimes for now it appears that the status can be 0, though.
//Status not found, problem, return false.
//No course-user relation found, return false
//No course found, return false
* Check course URL to get a course code and check it against user permissions
* Make this function always return true when no check is to be done
* @param string URL to check
* @return boolean True on user having access to the course or course not found, false otherwise
$match1 = preg_match('/courses\/([^\/]*)\//',$url,$matches);
$match2 = preg_match('/cidReq=([^&]*)/',$url,$matches);
//user has no access to this course, skip it
* Translates a course code into a course name into a string
* This function should only be used if needed by a funny course-name rule
* @param string The string to transform
* @result string The transformed string
if(preg_match('/(PORTAL_[0-9]{1,4})/',$string,$matches)){
$sql = "SELECT title FROM $course WHERE code = '". $matches[1]. "'";
$string = preg_replace('/(.*)\?cidReq=('. $matches[1]. ')(.*)/',' '. $row['title']. ' - \1 \3',$string);
$string = preg_replace('/'. $matches[1]. '/',$row['title'],$string);
|