diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 36d1b8f9cc..1ca990af71 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -3000,4 +3000,50 @@ function api_get_status_of_user_in_course ($user_id,$course_code) { $result=api_sql_query($sql,__FILE__,__LINE__); $row_status=Database::fetch_array($result,'ASSOC'); return $row_status['status']; -} \ No newline at end of file +} + +/** + * Checks whether the curent user is in a course or not. + * + * @param string The course code - optional (takes it from session if not given) + * @return boolean + * @author Yannick Warnier + */ +function api_is_in_course($course_code = null) { + if (isset($_SESSION['_course']['sysCode'])) { + if (!empty($course_code)) { + if ($course_code == $_SESSION['_course']['sysCode']) return true; else return false; + } else { + return true; + } + } + return false; +} + +/** + * Checks whether the curent user is in a group or not. + * + * @param string The group id - optional (takes it from session if not given) + * @param string The course code - optional (no additional check by course if course code is not given) + * @return boolean + * @author Ivan Tcholakov + */ +function api_is_in_group($group_id = null, $course_code = null) { + + if (!empty($course_code)) { + if (isset($_SESSION['_course']['sysCode'])) { + if ($course_code != $_SESSION['_course']['sysCode']) return false; + } else { + return false; + } + } + + if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') { + if (!empty($group_id)) { + if ($group_id == $_SESSION['_gid']) return true; else return false; + } else { + return true; + } + } + return false; +}