Fixing query

skala
Julio Montoya 13 years ago
parent d9a8d8bf6c
commit e8060a685a
  1. 14
      main/inc/lib/main_api.lib.php

@ -1874,6 +1874,10 @@ function api_is_course_tutor() {
* @return boolean True if current user is a course or session coach * @return boolean True if current user is a course or session coach
*/ */
function api_is_coach($session_id = 0, $course_code = '') { function api_is_coach($session_id = 0, $course_code = '') {
//@todo Not sure about this one
/*if (api_is_platform_admin()) {
return true;
}*/
if (!empty($session_id)) { if (!empty($session_id)) {
$session_id = intval($session_id); $session_id = intval($session_id);
} else { } else {
@ -1885,10 +1889,12 @@ function api_is_coach($session_id = 0, $course_code = '') {
} else { } else {
$course_code = api_get_course_id(); $course_code = api_get_course_id();
} }
$session_table = Database::get_main_table(TABLE_MAIN_SESSION);
$session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionIsCoach = null;
if (!empty($course_code)) { if (!empty($course_code)) {
$sql = "SELECT DISTINCT id, name, date_start, date_end $sql = "SELECT DISTINCT id, name, date_start, date_end
FROM session INNER JOIN session_rel_course_rel_user session_rc_ru FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru
ON session_rc_ru.id_user = '".api_get_user_id()."' ON session_rc_ru.id_user = '".api_get_user_id()."'
WHERE session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id' WHERE session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id'
ORDER BY date_start, date_end, name"; ORDER BY date_start, date_end, name";
@ -1899,7 +1905,7 @@ function api_is_coach($session_id = 0, $course_code = '') {
if (!empty($session_id)) { if (!empty($session_id)) {
$sql = "SELECT DISTINCT id, name, date_start, date_end $sql = "SELECT DISTINCT id, name, date_start, date_end
FROM session FROM $session_table
WHERE session.id_coach = '".api_get_user_id()."' AND id = '$session_id' WHERE session.id_coach = '".api_get_user_id()."' AND id = '$session_id'
ORDER BY date_start, date_end, name"; ORDER BY date_start, date_end, name";
@ -1910,7 +1916,6 @@ function api_is_coach($session_id = 0, $course_code = '') {
$sessionIsCoach = Database::store_result($result); $sessionIsCoach = Database::store_result($result);
} }
} }
return (count($sessionIsCoach) > 0); return (count($sessionIsCoach) > 0);
} }
@ -2152,6 +2157,7 @@ function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach =
$session_visibility = api_get_session_visibility($my_session_id); $session_visibility = api_get_session_visibility($my_session_id);
$is_courseAdmin = api_is_course_admin() || api_is_platform_admin(); $is_courseAdmin = api_is_course_admin() || api_is_platform_admin();
if (!$is_courseAdmin && $tutor) { // If we also want to check if the user is a tutor... if (!$is_courseAdmin && $tutor) { // If we also want to check if the user is a tutor...
$is_courseAdmin = $is_courseAdmin || api_is_course_tutor(); $is_courseAdmin = $is_courseAdmin || api_is_course_tutor();
} }

Loading…
Cancel
Save