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

📄 course.lib.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			if (Database::num_rows($handle) == 0)			{				return false; // the user isn't registered to the platform			}			else			{				//check if user isn't already subscribed to the course				$handle = api_sql_query("SELECT * FROM ".$course_user_table."																	WHERE `user_id` = '$user_id'																	AND `course_code` ='$course_code'", __FILE__, __LINE__);				if (Database::num_rows($handle) > 0)				{					return false; // the user is already subscribed to the course				}				else				{					$course_sort = CourseManager :: userCourseSort($user_id,$course_code);					$add_course_user_entry_sql = "INSERT INTO ".$course_user_table."										SET `course_code` = '$course_code',										`user_id`    = '$user_id',											`status`    = '".$status."',											`sort`  =   '". ($course_sort)."'";					$result = api_sql_query($add_course_user_entry_sql, __FILE__, __LINE__);					if ($result)					{						return true;					}					else					{						return false;					}				}			}		}	}	/**	* Subscribe a user $user_id to a course $course_code.	* @author Hugues Peeters	* @author Roan Embrechts	*	* @param  int $user_id the id of the user	* @param  string $course_code the course code	* @param string $status (optional) The user's status in the course	*	* @return boolean true if subscription succeeds, boolean false otherwise.	* @todo script has ugly ifelseifelseifelseif structure, improve	*/	function add_user_to_course($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);		$status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;		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__);			if (Database::num_rows($handle) == 0)			{				return false; // the user isn't registered to the platform			}			else			{				//check if user isn't already subscribed to the course				$handle = api_sql_query("SELECT * FROM ".$course_user_table."																	WHERE `user_id` = '$user_id'																	AND `course_code` ='$course_code'", __FILE__, __LINE__);				if (Database::num_rows($handle) > 0)				{					return false; // the user is already subscribed to the course				}				else				{					// previously check if subscription is allowed for this course					$handle = api_sql_query("SELECT code, visibility FROM ".$course_table."											WHERE  `code` = '$course_code'											AND  `subscribe` = '".SUBSCRIBE_NOT_ALLOWED."'", __FILE__, __LINE__);					if (Database::num_rows($handle) > 0)					{						return false; // subscription not allowed for this course					}					else					{						$max_sort = api_max_sort_value('0', $user_id);						$add_course_user_entry_sql = "INSERT INTO ".$course_user_table."											SET `course_code` = '$course_code',												`user_id`    = '$user_id',												`status`    = '".$status."',												`sort`  =   '". ($max_sort +1)."'";						$result=api_sql_query($add_course_user_entry_sql, __FILE__, __LINE__);						if ($result)						{							return true;						}						else						{							return false;						}					}				}			}		}	}	/**	*	This code creates a select form element to let the user	*	choose a real course to link to.	*	*	A good non-display library should not use echo statements, but just return text/html	*	so users of the library can choose when to display.	*	*	We display the course code, but internally store the course id.	*	*	@param boolean $has_size, true the select tag gets a size element, false it stays a dropdownmenu	*	@param boolean $only_current_user_courses, true only the real courses of which the	*	current user is course admin are displayed, false all real courses are shown.	*	@param string $element_name the name of the select element	*	@return a string containing html code for a form select element.	* @deprecated Function not in use	*/	function get_real_course_code_select_html($element_name, $has_size = true, $only_current_user_courses = true, $user_id)	{		if ($only_current_user_courses == true)		{			$real_course_list = CourseManager :: get_real_course_list_of_user_as_course_admin($user_id);		}		else		{			$real_course_list = CourseManager :: get_real_course_list();		}		if ($has_size == true)		{			$size_element = "size=\"".SELECT_BOX_SIZE."\"";		}		else		{			$size_element = "";		}		$html_code = "<select name=\"$element_name\" $size_element >\n";		foreach ($real_course_list as $real_course)		{			$course_code = $real_course["code"];			$html_code .= "<option value=\"".$course_code."\">";			$html_code .= $course_code;			$html_code .= "</option>\n";		}		$html_code .= "</select>\n";		return $html_code;	}	/**	*	Checks wether a parameter exists.	*	If it doesn't, the function displays an error message.	*	*	@return true if parameter is set and not empty, false otherwise	*	@todo move function to better place, main_api ?	*/	function check_parameter($parameter, $error_message)	{		if (!isset ($parameter) || empty ($parameter))		{			Display :: display_normal_message($error_message);			return false;		}		return true;	}	/**	*	Lets the script die when a parameter check fails.	*	@todo move function to better place, main_api ?	*/	function check_parameter_or_fail($parameter, $error_message)	{		if (!CourseManager :: check_parameter($parameter, $error_message))			die();	}	/**	*	@return true if there already are one or more courses	*	with the same code OR visual_code (visualcode), false otherwise	*/	function is_existing_course_code($wanted_course_code)	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$sql_query = "SELECT COUNT(*) as number FROM ".$course_table."WHERE `code` = '$wanted_course_code' OR `visual_code` = '$wanted_course_code' ";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		$result = Database::fetch_array($sql_result);		if ($result["number"] > 0)		{			return true;		}		else		{			return false;		}	}	/**	*	@return an array with the course info of all real courses on the platform	*/	function get_real_course_list()	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$sql_query = "SELECT * FROM $course_table WHERE `target_course_code` IS NULL";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		while ($result = Database::fetch_array($sql_result))		{			$real_course_list[] = $result;		}		return $real_course_list;	}	/**	*	@return an array with the course info of all virtual courses on the platform	*/	function get_virtual_course_list()	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$sql_query = "SELECT * FROM $course_table WHERE `target_course_code` IS NOT NULL";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		while ($result = Database::fetch_array($sql_result))		{			$virtual_course_list[] = $result;		}		return $virtual_course_list;	}	/**	*	@return an array with the course info of the real courses of which	*	the current user is course admin	*/	function get_real_course_list_of_user_as_course_admin($user_id)	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$sql_query = "	SELECT *										FROM $course_table course										LEFT JOIN $course_user_table course_user										ON course.`code` = course_user.`course_code`										WHERE course.`target_course_code` IS NULL											AND course_user.`user_id` = '$user_id'											AND course_user.`status` = '1'";		//api_display_debug_info($sql_query);		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		while ($result = Database::fetch_array($sql_result))		{			$result_array[] = $result;		}		return $result_array;	}	/**	*	@return an array with the course info of all the courses (real and virtual) of which	*	the current user is course admin	*/	function get_course_list_of_user_as_course_admin($user_id)	{		$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);		$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$sql_query = "	SELECT *										FROM $course_table course										LEFT JOIN $course_user_table course_user										ON course.`code` = course_user.`course_code`										WHERE course_user.`user_id` = '$user_id'											AND course_user.`status` = '1'";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		while ($result = Database::fetch_array($sql_result))		{			$result_array[] = $result;		}		return $result_array;	}	/**	* Find out for which courses the user is registered and determine a visual course code and course title from that.	* Takes virtual courses into account	*	* Default case: the name and code stay what they are.	*	* Scenarios:	* - User is registered in real course and virtual courses; name / code become a mix of all	* - User is registered in real course only: name stays that of real course	* - User is registered in virtual course only: name becomes that of virtual course	* - user is not registered to any of the real/virtual courses: name stays that of real course	* (I'm not sure about the last case, but this seems not too bad)	*	* @author Roan Embrechts	* @param $user_id, the id of the user	* @param $course_info, an array with course info that you get using Database::get_course_info($course_system_code);	* @return an array with indices	*    $return_result["title"] - the course title of the combined courses	*    $return_result["code"]  - the course code of the combined courses	*/	function determine_course_title_from_course_info($user_id, $course_info)	{		$real_course_id = $course_info['system_code'];		$real_course_info = Database :: get_course_info($real_course_id);		$real_course_name = $real_course_info["title"];		$real_course_visual_code = $real_course_info["visual_code"];		$real_course_real_code = $course_info['system_code'];		//is the user registered in the real course?		$table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);		$sql_query = "SELECT * FROM $table WHERE `user_id` = '$user_id' AND `course_code` = '$real_course_real_code'";		$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);		$result = Database::fetch_array($sql_result);		if (!isset ($result) || empty ($result))		{			$user_is_registered_in_real_course = false;		}		else		{			$user_is_registered_in_real_course = true;		}		//get a list of virtual courses linked to the current real course		//and to which the current user is subscribed		$user_subscribed_virtual_course_list = CourseManager :: get_list_of_virtual_courses_for_specific_user_and_real_course($user_id, $real_course_id);		if (count($user_subscribed_virtual_course_list) > 0)		{			$virtual_courses_exist = true;		}		else		{

⌨️ 快捷键说明

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