[svn r17793] Added CourseManager::get_course_id_from_path() and added a check on $_GET['cDir'] as it is set by courses/.htaccess for download.php

skala
Yannick Warnier 16 years ago
parent 65050c5c8b
commit 637d9d199c
  1. 17
      main/inc/lib/course.lib.php
  2. 10
      main/inc/local.inc.php

@ -1887,5 +1887,22 @@ class CourseManager
return $course_list;
}
/**
* Get course ID from a given course directory name
* @param string Course directory (without any slash)
* @return string Course code, or false if not found
*/
function get_course_id_from_path($path) {
$path = str_replace('/','',$path);
$path = str_replace('.','',$path);
$path = Database::escape_string($path);
$t_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT code FROM $t_course WHERE directory LIKE BINARY '$path'";
$res = api_sql_query($sql,__FILE__,__LINE__);
if ($res === false) {return false;}
if (Database::num_rows() != 1) {return false;}
$row = Database::fetch_array($res);
return $row['code'];
}
} //end class CourseManager

@ -172,6 +172,9 @@ $cidReset = isset($cidReset) ? Database::escape_string($cidReset) : '';
// $cidReset can be set in URL-parameter
$cidReset = (isset($_GET['cidReq']) && ((isset($_SESSION['_cid']) && $_GET['cidReq']!=$_SESSION['_cid']) || (!isset($_SESSION['_cid'])))) ? Database::escape_string($_GET["cidReq"]) : $cidReset;
// $cDir is a special url param sent by courses/.htaccess
$cDir = (!empty($_GET['cDir']) ? $_GET['cDir'] : null);
$gidReset = isset($gidReset) ? $gidReset : '';
// $gidReset can be set in URL-parameter
@ -468,6 +471,13 @@ else
api_clear_anonymous();
}
// if there is a cDir parameter in the URL (coming from courses/.htaccess redirection)
if (!empty($cDir)) {
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
$c = CourseManager::get_course_id_from_path($cDir);
if ($c != false) { $cidReq = $c; }
}
// if the requested course is different from the course in session
if (!empty($cidReq) && (!isset($_SESSION['_cid']) or (isset($_SESSION['_cid']) && $cidReq != $_SESSION['_cid'])))

Loading…
Cancel
Save