⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 course.lib.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php/*==============================================================================	Dokeos - elearning and course management software	Copyright (c) 2004-2008 Dokeos SPRL	Copyright (c) 2001 Universite catholique de Louvain (UCL)	Copyright (c) Roan Embrechts, Vrije Universiteit Brussel	Copyright (c) Bart Mollet, Hogeschool Gent	Copyright (c) Yannick Warnier, Dokeos S.A.	For a full list of contributors, see "credits.txt".	The full license can be read in "license.txt".	This program is free software; you can redistribute it and/or	modify it under the terms of the GNU General Public License	as published by the Free Software Foundation; either version 2	of the License, or (at your option) any later version.	See the GNU General Public License for more details.	Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium	Mail: info@dokeos.com==============================================================================*//**==============================================================================* This is the course library for Dokeos.** All main course functions should be placed here.* Many functions of this library deal with providing support for* virtual/linked/combined courses (this was already used in several universities* but not available in standard Dokeos).** The implementation changed, initially a course was a real course* if target_course_code was 0 , this was changed to NULL.* There are probably some places left with the wrong code.** @package dokeos.library==============================================================================*//*==============================================================================	DOCUMENTATION	(list not up to date, you can auto generate documentation with phpDocumentor)	CourseManager::get_real_course_code_select_html($element_name, $has_size=true, $only_current_user_courses=true)	CourseManager::check_parameter($parameter, $error_message)	CourseManager::check_parameter_or_fail($parameter, $error_message)	CourseManager::is_existing_course_code($wanted_course_code)	CourseManager::get_real_course_list()	CourseManager::get_virtual_course_list()	GENERAL COURSE FUNCTIONS	CourseManager::get_access_settings($course_code)	CourseManager::set_course_tool_visibility($tool_table_id, $visibility)	CourseManager::get_user_in_course_status($user_id, $course_code)	CourseManager::add_user_to_course($user_id, $course_code)	CourseManager::get_virtual_course_info($real_course_code)	CourseManager::is_virtual_course_from_visual_code($visual_code)	CourseManager::is_virtual_course_from_system_code($system_code)	CourseManager::get_virtual_courses_linked_to_real_course($real_course_code)	CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($user_id, $real_course_code)	CourseManager::has_virtual_courses_from_code($real_course_code, $user_id)	CourseManager::get_target_of_linked_course($virtual_course_code)	TITLE AND CODE FUNCTIONS	CourseManager::determine_course_title_from_course_info($user_id, $course_info)	CourseManager::create_combined_name($user_is_registered_in_real_course, $real_course_name, $virtual_course_list)	CourseManager::create_combined_code($user_is_registered_in_real_course, $real_course_code, $virtual_course_list)	USER FUNCTIONS	CourseManager::get_real_course_list_of_user_as_course_admin($user_id)	CourseManager::get_course_list_of_user_as_course_admin($user_id)	CourseManager::is_user_subscribed_in_course($user_id, $course_code)	CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code)	CourseManager::get_user_list_from_course_code($course_code)	CourseManager::get_real_and_linked_user_list($course_code);	GROUP FUNCTIONS	CourseManager::get_group_list_of_course($course_code)	CREATION FUNCTIONS	CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category)==============================================================================*//*==============================================================================		INIT SECTION==============================================================================*//*-----------------------------------------------------------		Configuration files-----------------------------------------------------------*/include_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');/*-----------------------------------------------------------		Libraries		we assume main_api is also included...-----------------------------------------------------------*/include_once (api_get_path(LIBRARY_PATH).'database.lib.php');include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');/*-----------------------------------------------------------		Constants-----------------------------------------------------------*///LOGIC: course visibility and registration settings/*	COURSE VISIBILITY	MAPPING OLD SETTINGS TO NEW SETTINGS	-----------------------	NOT_VISIBLE_NO_SUBSCRIPTION_ALLOWED	--> COURSE_VISIBILITY_REGISTERED, SUBSCRIBE_NOT_ALLOWED	NOT_VISIBLE_SUBSCRIPTION_ALLOWED	--> COURSE_VISIBILITY_REGISTERED, SUBSCRIBE_ALLOWED	VISIBLE_SUBSCRIPTION_ALLOWED	--> COURSE_VISIBILITY_OPEN_PLATFORM, SUBSCRIBE_ALLOWED	VISIBLE_NO_SUBSCRIPTION_ALLOWED	--> COURSE_VISIBILITY_OPEN_PLATFORM, SUBSCRIBE_NOT_ALLOWED*///OLD SETTINGSdefine("NOT_VISIBLE_NO_SUBSCRIPTION_ALLOWED", 0);define("NOT_VISIBLE_SUBSCRIPTION_ALLOWED", 1);define("VISIBLE_SUBSCRIPTION_ALLOWED", 2);define("VISIBLE_NO_SUBSCRIPTION_ALLOWED", 3);//NEW SETTINGS//these are now defined in the main_api.lib.php/*	COURSE_VISIBILITY_CLOSED	COURSE_VISIBILITY_REGISTERED	COURSE_VISIBILITY_OPEN_PLATFORM	COURSE_VISIBILITY_OPEN_WORLD	SUBSCRIBE_ALLOWED	SUBSCRIBE_NOT_ALLOWED	UNSUBSCRIBE_ALLOWED	UNSUBSCRIBE_NOT_ALLOWED*//*-----------------------------------------------------------	Variables-----------------------------------------------------------*/$TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);$TABLECOURSDOMAIN = Database :: get_main_table(TABLE_MAIN_CATEGORY);$TABLEUSER = Database :: get_main_table(TABLE_MAIN_USER);$TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);$TABLEANNOUNCEMENTS = "announcement";$coursesRepositories = $_configuration['root_sys'];/*==============================================================================		CourseManager CLASS==============================================================================*//** *	@package dokeos.library */class CourseManager{	/**	* Returns all the information of a given coursecode	* @param string $course_code, the course code	* @return an array with all the fields of the course table	* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University	*/	function get_course_information($course_code)	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$sql="SELECT * FROM ".$course_table." WHERE code='".$course_code."'";		$sql_result = api_sql_query($sql, __FILE__, __LINE__);		$result = Database::fetch_array($sql_result);		return $result;	}	/**	 * Returns a list of courses. Should work with quickform syntax	 * @param	integer	Offset (from the 7th = '6'). Optional.	 * @param	integer	Number of results we want. Optional.	 * @param	string	The column we want to order it by. Optional, defaults to first column.	 * @param	string	The direction of the order (ASC or DESC). Optional, defaults to ASC.	 * @param	string	The visibility of the course, or all by default.	 * @param	string	If defined, only return results for which the course *title* begins with this string	 */	function get_courses_list($from=0,$howmany=0,$orderby=1,$orderdirection='ASC',$visibility=-1,$startwith='')	{		$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);		$sql = "SELECT code, title " .				"FROM $tbl_course ";		if(!empty($startwith))		{			$sql .= "WHERE LIKE title '".Database::escape_string($startwith)."%' ";		}		else		{			$sql .= "WHERE 1 ";		}		if(!empty($orderby))		{			$sql .= " ORDER BY ".Database::escape_string($orderby)." ";		}		else		{			$sql .= " ORDER BY 1 ";		}		if(!empty($orderdirection))		{			$sql .= Database::escape_string($orderdirection);		}		else		{			$sql .= 'ASC';		}		if(!empty($howmany) and is_int($howmany) and $howmany>0)		{			$sql .= ' LIMIT '.Database::escape_string($howmany);		}		else		{			$sql .= ' LIMIT 1000000'; //virtually no limit		}		if(!empty($from))		{			$sql .= ' OFFSET '.Database::escape_string($from);		}		else		{			$sql .= ' OFFSET 0';		}		$res = api_sql_query($sql,__FILE__,__LINE__);		return api_store_result($res);	}	/**	* Returns the access settings of the course:	* which visibility;	* wether subscribing is allowed;	* wether unsubscribing is allowed.	*	* @param string $course_code, the course code	* @todo for more consistency: use course_info call from database API	* @return an array with int fields "visibility", "subscribe", "unsubscribe"	*/	function get_access_settings($course_code)	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$sql = "SELECT `visibility`, `subscribe`, `unsubscribe` from ".$course_table." where `code` = '".$course_code."'";		$sql_result = api_sql_query($sql, __FILE__, __LINE__);		$result = Database::fetch_array($sql_result);		return $result;	}	/**	* Returns the status of a user in a course, which is COURSEMANAGER or STUDENT.	*	* @return int the status of the user in that course	*/	function get_user_in_course_status($user_id, $course_code)	{		$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$sql_query = "SELECT * FROM $course_user_table WHERE `course_code` = '$course_code' AND `user_id` = '$user_id'";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		$result = Database::fetch_array($sql_result);		return $result["status"];	}	/**	 * Unsubscribe one or more users from a course	 * @param int|array $user_id	 * @param string $course_code	 */	function unsubscribe_user($user_id, $course_code)	{		if(!is_array($user_id))		{			$user_id = array($user_id);		}		if(count($user_id) == 0)		{			return;		}		$user_ids = implode(',', $user_id);		$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);		// Unsubscribe user from all groups in the course		$sql = "SELECT * FROM $table_course WHERE code = '".$course_code."'";		$res = api_sql_query($sql, __FILE__, __LINE__);		$course = Database::fetch_object($res);		$table_group = Database :: get_course_table(TABLE_GROUP_USER, $course->db_name);		$sql = "DELETE FROM $table_group WHERE user_id IN (".$user_ids.")";		api_sql_query($sql, __FILE__, __LINE__);		// Unsubscribe user from all blogs in the course		$table_blog_user = Database::get_course_table(TABLE_BLOGS_REL_USER, $course->db_name);		$sql = "DELETE FROM  ".$table_blog_user." WHERE user_id IN (".$user_ids.")";		api_sql_query($sql,__FILE__,__LINE__);		$table_blogtask_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER, $course->db_name);		$sql = "DELETE FROM  ".$table_blogtask_user." WHERE user_id IN (".$user_ids.")";		api_sql_query($sql,__FILE__,__LINE__);		// Unsubscribe user from the course		$sql = "DELETE FROM $table_course_user WHERE user_id IN (".$user_ids.") AND course_code = '".$course_code."'";		api_sql_query($sql, __FILE__, __LINE__);	}	/**	 * Subscribe a user to a course. No checks are performed here to see if	 * course subscription is allowed.	 * @see add_user_to_course	 */	function subscribe_user($user_id, $course_code, $status = STUDENT)	{		$user_table = Database :: get_main_table(TABLE_MAIN_USER);		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$location_table = Database :: get_main_table(MAIN_LOCATION_TABLE);		$user_role_table = Database :: get_main_table(MAIN_USER_ROLE_TABLE);		$status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;		$role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;		if (empty ($user_id) || empty ($course_code))		{			return false;		}		else		{			// previously check if the user are already registered on the platform			$handle = api_sql_query("SELECT status FROM ".$user_table."														WHERE `user_id` = '$user_id' ", __FILE__, __LINE__);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -