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

📄 main_api.lib.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	 // to the user_portal				 	if(!headers_sent() or $print_headers){Display::display_header('');}		echo '<div align="center">';		Display :: display_error_message(get_lang('NotAllowedClickBack').'<br/><br/><a href="'.$_SERVER['HTTP_REFERRER'].'">'.get_lang('BackToPreviousPage').'</a><br/>',false);		echo '</div>';		if($print_headers){Display::display_footer();}		die();	}	elseif(!empty($_SERVER['REQUEST_URI']) && !empty($_GET['cidReq']))	{		//only display form and return to the previous URL if there was a course ID included		if(!empty($user) && !api_is_anonymous())		{			if(!headers_sent() or $print_headers){Display::display_header('');}			echo '<div align="center">';			Display :: display_error_message(get_lang('NotAllowedClickBack').'<br/><br/><a href="'.$_SERVER['HTTP_REFERRER'].'">'.get_lang('BackToPreviousPage').'</a><br/>',false);			echo '</div>';			if($print_headers){Display::display_footer();}			die();					}		else		{			include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');$form = new FormValidator('formLogin','post',api_get_self().'?'.$_SERVER['QUERY_STRING']);			$form->addElement('static',null,null,'Username');			$form->addElement('text','login','',array('size'=>15));			$form->addElement('static',null,null,'Password');			$form->addElement('password','password','',array('size'=>15));			$form->addElement('submit','submitAuth',get_lang('Ok'));			$test = $form->return_form();			if(!headers_sent() or $print_headers){Display::display_header('');}			echo '<div align="center">';			Display :: display_error_message(get_lang('NotAllowed').'<br/><br/>'.get_lang('PleaseLoginAgainFromFormBelow').'<br/>'.$test,false);			echo '</div>';			$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];			if($print_headers){Display::display_footer();}			die();		}	}	else	{		if(!empty($user) && !api_is_anonymous())		{			if(!headers_sent() or $print_headers){Display::display_header('');}			echo '<div align="center">';			Display :: display_error_message(get_lang('NotAllowedClickBack').'<br/><br/><a href="'.$_SERVER['HTTP_REFERRER'].'">'.get_lang('BackToPreviousPage').'</a><br/>',false);			echo '</div>';			if($print_headers){Display::display_footer();}			die();					}		else		{			//if no course ID was included in the requested URL, redirect to homepage			if($print_headers){Display::display_header('');}			echo '<div align="center">';			Display :: display_error_message(get_lang('NotAllowed').'<br/><br/><a href="'.$home_url.'">'.get_lang('PleaseLoginAgainFromHomepage').'</a><br/>',false);			echo '</div>';			if($print_headers){Display::display_footer();}			die();		}	}}/*==============================================================================		WHAT'S NEW		functions for the what's new icons		in the user course list==============================================================================*//** * @param $last_post_datetime standard output date in a sql query * @return unix timestamp * @author Toon Van Hoecke <Toon.VanHoecke@UGent.be> * @version October 2003 * @desc convert sql date to unix timestamp*/function convert_mysql_date($last_post_datetime){	list ($last_post_date, $last_post_time) = split(" ", $last_post_datetime);	list ($year, $month, $day) = explode("-", $last_post_date);	list ($hour, $min, $sec) = explode(":", $last_post_time);	$announceDate = mktime($hour, $min, $sec, $month, $day, $year);	return $announceDate;}/** * Gets item visibility from the item_property table * @param	array	Course properties array (result of api_get_course_info()) * @param	string	Tool (learnpath, document, etc) * @param	int		The item ID in the given tool * @return	int		-1 on error, 0 if invisible, 1 if visible  */function api_get_item_visibility($_course,$tool,$id){	if(!is_array($_course) or count($_course)==0 or empty($tool) or empty($id)) return -1;	$tool = Database::escape_string($tool);	$id = Database::escape_string($id);	$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);	$sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $id";	$res = api_sql_query($sql);	if($res === false or Database::num_rows($res)==0) return -1;	$row = Database::fetch_array($res);	return $row['visibility'];  	}/** * Updates or adds item properties to the Item_propetry table * Tool and lastedit_type are language independant strings (langvars->get_lang!) * * @param $_course : array with course properties * @param $tool : tool id, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!) * @param $item_id : id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool * @param $lastedit_type : add or update action (1) message to be translated (in trad4all) : e.g. DocumentAdded, DocumentUpdated; * 												(2) "delete"; (3) "visible"; (4) "invisible"; * @param $user_id : id of the editing/adding user * @param $to_group_id : id of the intended group ( 0 = for everybody), only relevant for $type (1) * @param $to_user_id : id of the intended user (always has priority over $to_group_id !), only relevant for $type (1) * @param string $start_visible 0000-00-00 00:00:00 format * @param unknown_type $end_visible 0000-00-00 00:00:00 format * @return boolean False if update fails. * @author Toon Van Hoecke <Toon.VanHoecke@UGent.be>, Ghent University * @version January 2005 * @desc update the item_properties table (if entry not exists, insert) of the course */function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $user_id, $to_group_id = 0, $to_user_id = NULL, $start_visible = 0, $end_visible = 0){	$tool = Database::escape_string($tool);	$item_id = Database::escape_string($item_id);	$lastedit_type = Database::escape_string($lastedit_type);	$user_id = Database::escape_string($user_id);	$to_group_id = Database::escape_string($to_group_id);	$to_user_id = Database::escape_string($to_user_id);	$start_visible = Database::escape_string($start_visible);	$end_visible = Database::escape_string($end_visible);	$time = time();	$time = date("Y-m-d H:i:s", $time);	$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);	if ($to_user_id <= 0)		$to_user_id = NULL; //no to_user_id set	$start_visible = ($start_visible == 0) ? "0000-00-00 00:00:00" : $start_visible;	$end_visible = ($end_visible == 0) ? "0000-00-00 00:00:00" : $end_visible;	// set filters for $to_user_id and $to_group_id, with priority for $to_user_id	$filter = "tool='$tool' AND ref='$item_id'";	if ($item_id == "*")		$filter = "tool='$tool' AND visibility<>'2'"; // for all (not deleted) items of the tool	// check if $to_user_id and $to_group_id are passed in the function call	// if both are not passed (both are null) then it is a message for everybody and $to_group_id should be 0 !	if (is_null($to_user_id) && is_null($to_group_id))		$to_group_id = 0;	if (!is_null($to_user_id))		$to_filter = " AND to_user_id='$to_user_id'"; // set filter to intended user	else		if (!is_null($to_group_id) and $to_group_id == strval(intval($to_group_id)))			$to_filter = " AND to_group_id='$to_group_id'"; // set filter to intended group	// update if possible	$set_type = "";	switch ($lastedit_type)	{		case "delete" : // delete = make item only visible for the platform admin			$visibility = '2';			$sql = "UPDATE $TABLE_ITEMPROPERTY										SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type										WHERE $filter";			break;		case "visible" : // change item to visible			$visibility = '1';			$sql = "UPDATE $TABLE_ITEMPROPERTY										SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type										WHERE $filter";			break;		case "invisible" : // change item to invisible			$visibility = '0';			$sql = "UPDATE $TABLE_ITEMPROPERTY										SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type										WHERE $filter";			break;		default : // item will be added or updated			$set_type = ", lastedit_type='$lastedit_type' ";			$visibility = '1';			$filter .= $to_filter;			$sql = "UPDATE $TABLE_ITEMPROPERTY										SET lastedit_date='$time', lastedit_user_id='$user_id' $set_type										WHERE $filter";	}	$res = mysql_query($sql);	// insert if no entries are found (can only happen in case of $lastedit_type switch is 'default')	if (mysql_affected_rows() == 0)	{		if (!is_null($to_user_id)) // $to_user_id has more priority than $to_group_id		{			$to_field = "to_user_id";			$to_value = $to_user_id;		}		else // $to_user_id is not set			{			$to_field = "to_group_id";			$to_value = $to_group_id;		}		$sql = "INSERT INTO $TABLE_ITEMPROPERTY						   		  			(tool,   ref,       insert_date,insert_user_id,lastedit_date,lastedit_type,   lastedit_user_id,$to_field,  visibility,   start_visible,   end_visible)						         	VALUES 	('$tool','$item_id','$time',    '$user_id',	   '$time',		 '$lastedit_type','$user_id',	   '$to_value','$visibility','$start_visible','$end_visible')";		$res = mysql_query($sql);		if (!$res)			return FALSE;	}	return TRUE;}/*==============================================================================		Language Dropdown==============================================================================*//***	Displays a form (drop down menu) so the user can select his/her preferred language.*	The form works with or without javascript*/function api_display_language_form(){	$platformLanguage = api_get_setting('platformLanguage');	$dirname = api_get_path(SYS_PATH)."main/lang/"; // this line is probably no longer needed	// retrieve a complete list of all the languages.	$language_list = api_get_languages();	// the the current language of the user so that his/her language occurs as selected in the dropdown menu	if(isset($_SESSION['user_language_choice']))	{		$user_selected_language = $_SESSION['user_language_choice'];	}	if (!isset ($user_selected_language))		$user_selected_language = $platformLanguage;	$original_languages = $language_list['name'];	$folder = $language_list['folder']; // this line is probably no longer needed?>	<script language="JavaScript" type="text/JavaScript">	<!--	function jumpMenu(targ,selObj,restore){ //v3.0	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");	  if (restore) selObj.selectedIndex=0;	}	//-->	</script>	<?php	echo "<form id=\"lang_form\" name=\"lang_form\" method=\"post\" action=\"".api_get_self()."\">", "<select name=\"language_list\"  onchange=\"jumpMenu('parent',this,0)\">";	foreach ($original_languages as $key => $value)	{		if ($folder[$key] == $user_selected_language)			$option_end = " selected=\"selected\" >";		else			$option_end = ">";		echo "<option value=\"".api_get_self()."?language=".$folder[$key]."\"$option_end";		#echo substr($value,0,16); #cut string to keep 800x600 aspect		echo $value;		echo "</option>\n";	}	echo "</select>";	echo "<noscript><input type=\"submit\" name=\"user_select_language\" value=\"".get_lang("Ok")."\" /></noscript>";	echo "</form>";}/*** Return a list of all the languages that are made available by the admin.* @return array An array with all languages. Structure of the array is*  array['name'] = An array with the name of every language*  array['folder'] = An array with the corresponding dokeos-folder*/function api_get_languages(){	$tbl_language = Database :: get_main_table(TABLE_MAIN_LANGUAGE);	$sql = "SELECT * FROM $tbl_language WHERE available='1' ORDER BY original_name ASC";	$result = api_sql_query($sql, __FILE__, __LINE__);	while ($row = mysql_fetch_array($result))	{		$language_list['name'][] = $row['original_name'];		$language_list['folder'][] = $row['dokeos_folder'];	}	return $language_list;}/** * Get language isocode column from the language table, taking the current language as a query * @return	string	The isocode (two-letters code or 5 letters code, fr or fr-BE) or null if error */function api_get_language_isocode(){	$tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);	$sql = "SELECT isocode FROM $tbl_language WHERE dokeos_folder = '".api_get_interface_language()."'";	$res = api_sql_query($sql,__FILE__,__LINE__);	if(mysql_num_rows($res))	{		$row = mysql_fetch_array($res);		return $row['isocode'];	}	return null;}/** * Returns a list of CSS themes currently available in the CSS folder * @return	array	List of themes directories from the css folder */function api_get_themes(){	$cssdir = api_get_path(SYS_PATH).'main/css/';	$list_dir= array();	$list_name= array();		if (@is_dir($cssdir))	{		$themes = @scandir($cssdir);				if (is_array($themes))		{			if($themes !== false)			{				sort($themes);								foreach($themes as $theme)				{					if(substr($theme,0,1)=='.')					{						//ignore						continue;					}					else					{						if(@is_dir($cssdir.$theme))						{							$list_dir[] = $theme;							$list_name[] = ucwords(str_replace('_',' ',$theme));						}						}				}			}		}			}	$return=array();	$return[]=$list_dir;	$return[]=$list_name;		return $return;}/*==============================================================================		WYSIWYG HTML AREA		functions for the WYSIWYG html editor, TeX parsing...==============================================================================*//*** Displays the FckEditor WYSIWYG editor for online editing of html* @param string $name The name of the form-element* @param string $content The default content of the html-editor* @param int $height The height of the form element* @param int $width The width of the form element* @param string $optAttrib optional attributes for the form element*/function api_disp_html_area($name, $content = '', $height = '', $width = '100%', $optAttrib = ''){	global $_configuration, $_course, $fck_attribute;	require_once(dirname(__FILE__).'/formvalidator/Element/html_editor.php');	$editor = new HTML_QuickForm_html_editor($name);	$editor->setValue($content);	if( $height != '')	{		$fck_attribute['Height'] = $height;	}	if( $width != '')	{		$fck_attribute['Width'] = $width;	}	echo $editor->toHtml();}function api_return_html_area($name, $content = '', $height = '', $width = '100%', $optAttrib = ''){	global $_configuration, $_course, $fck_attribute;	require_once(dirname(__FILE__).'/formvalidator/Element/html_editor.php');	$editor = new HTML_QuickForm_html_editor($name);	$editor->setValue($content);	if( $height != '')	{		$fck_attribute['Height'] = $height;	}	if( $width != '')	{		$fck_attribute['Width'] = $width;	}	return $editor->toHtml();}/** * Send an email. * * Wrapper function for the standard php mail() function. Change this function * to your needs. The parameters must follow the same rules as the standard php * mail() function. Please look at the documentation on http: //www. php. * net/manual/en/function. mail.php * @param string $to * @param string $subject * @param string $message * @param string $additional_headers * @param string $additional_parameters */function api_send_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null){	return mail($to, $subject, $message, $additional_headers, $additional_parameters);}/** * Find the largest sort value in a given user_course_category * This function is used when we are moving a course to a different category * and also when a user subscribes to a courses (the new courses is added to the end * of the main category * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University *

⌨️ 快捷键说明

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