Location: PHPKode > projects > MyLANsite - lanparty organisation > mylansite-1.4a_RC5/functions.php
<?php

/**
 * myLANsite function
 * Name:	MLS_core_enc
 * Purpose:	encrypts a string
 *
 * @param string $data /string to be encrypted
 * @return string /encrypted string
 */
function MLS_core_enc($data) {
	//// Passwort verschlüsseln
	$newcryptpass ="";
	$newcryptpass = md5($data);
	return $newcryptpass;
};

/**
 * myLANsite function
 * Name:	MLS_core_format_timestamp
 * Purpose:	formats a timestamp
 *
 * @param timestamp $timestamp /timestamp to be formatted
 * @return array
 * [0] string: date DD.MM.YYYY
 * [1] string: time HH:MM:SS
 * [2] string: today, tomorrow or yesterday. else DD.MM.YYYY
 * [3] string: date YYYY-MM-DD
 * [4] int: hours
 * [5] int: seconds
 * [6] int: minutes
 * [7] int: 0 =  today, 1 = tomorroy, -1 = yesterday
 * [8] string: something like "2 days 5 hours 3 seconds"
 * [9] string: time HH:MM
 */
function MLS_core_format_timestamp($timestamp) {
	//// Timestamp formatieren
	$time = getdate($timestamp);
	$time_tag = $time['mday'];
  	if(strlen($time_tag) == 1) {
  		$time_tag = "0" . $time_tag;
  	}
	$time_monat = $time['mon'];
	if(strlen($time_monat) == 1) {
  		$time_monat = "0" . $time_monat;
  	}
	$time_jahr = $time['year'];
	$time_stunden = $time['hours'];
	if(strlen($time_stunden) == 1) {
  		$time_stunden = "0" . $time_stunden;
  	}
	$time_minuten = $time['minutes'];
	if(strlen($time_minuten) == 1) {
  		$time_minuten = "0" . $time_minuten;
  	}
	$time_sekunden = $time['seconds'];
	if(strlen($time_sekunden) == 1) {
  		$time_sekunden = "0" . $time_sekunden;
  	}
	
	$start_morgen = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
	$ende_morgen = mktime(24, 0, 0, date("m"), date("d") + 1, date("Y"));
	$start_heute = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
	$ende_heute = mktime(24, 0, 0, date("m"), date("d"), date("Y"));
	$start_gestern = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
	$ende_gestern = mktime(24, 0, 0, date("m"), date("d") - 1, date("Y"));
	
	$format = array();
	// heute, gestern, morgen
	if($timestamp > $start_gestern AND $timestamp < $ende_gestern) {
		$format[2] = $GLOBALS["GENERAL"]["YESTERDAY"];
		$format[7] = -1;
	} elseif($timestamp > $start_heute AND $timestamp < $ende_heute) {
		$format[2] = $GLOBALS["GENERAL"]["TODAY"];
		$format[7] = 0;
	} elseif($timestamp > $start_morgen AND $timestamp < $ende_morgen) {
		$format[2] = $GLOBALS["GENERAL"]["TOMORROW"];
		$format[7] = 1;
	} else {
		$format[2] = $time_tag . "." . $time_monat . "." . $time_jahr;
	}
	
	// DD.MM.JJJJ
	$format[0] = $time_tag . "." . $time_monat . "." . $time_jahr;
	// HH:MM:SS
	$format[1] = $time_stunden . ":" . $time_minuten . ":" . $time_sekunden;
	// HH:MM
	$format[9] = $time_stunden . ":" . $time_minuten;
	// JJJJ-MM-DD
	$format[3] = $time_jahr . "-" . $time_monat . "-" . $time_tag;
	// HH
	$format[4] = $time_stunden;
	// SS
	$format[5] = $time_sekunden;
	// MM
	$format[6] = $time_minuten;
	
	
	// Text-Ausgabe
	$timestamp_temp = $timestamp;
	$tage = 0;
	$stunden = 0;
	$minuten = 0;
	$sekunden = 0;
	$sekunden_tag = 60 * 60 * 24;
	while($timestamp_temp > $sekunden_tag) {
		$timestamp_temp = $timestamp_temp - $sekunden_tag;
		$tage++;
	}
	$sekunden_stunde = 60 * 60;
	while($timestamp_temp > $sekunden_stunde) {
		$timestamp_temp = $timestamp_temp - $sekunden_stunde;
		$stunden++;
	}
	$sekunden_minute = 60;
	while($timestamp_temp > $sekunden_minute) {
		$timestamp_temp = $timestamp_temp - $sekunden_minute;
		$minuten++;
	}
	$sekunden = $timestamp_temp;
	if($tage == 1) {
		$tage_string = "$tage ".$GLOBALS["GENERAL"]["DAY"]." ";
	} elseif($tage == 0) {
		$tage_string = "";
	} else {
		$tage_string = "$tage ".$GLOBALS["GENERAL"]["DAYS"]." ";
	}
	if($stunden == 1) {
		$stunden_string = "$stunden ".$GLOBALS["GENERAL"]["HOUR"]." ";
	} elseif($stunden == 0) {
		$stunden_string = "";
	} else {
		$stunden_string = "$stunden ".$GLOBALS["GENERAL"]["HOURS"]." ";
	}
	if($minuten == 1) {
		$minuten_string = "$minuten ".$GLOBALS["GENERAL"]["MINUTE"]." ";
	} elseif($minuten == 0) {
		$minuten_string = "";
	} else {
		$minuten_string = "$minuten ".$GLOBALS["GENERAL"]["MINUTES"]." ";
	}
	if($sekunden == 1) {
		$sekunden_string = "$sekunden ".$GLOBALS["GENERAL"]["SECOND"]." ";
	} elseif($sekunden == 0) {
		$sekunden_string = "";
	} else {
		$sekunden_string = "$sekunden ".$GLOBALS["GENERAL"]["SECONDS"]." ";
	}
	$format[8] = $tage_string . $stunden_string . $minuten_string . $sekunden_string;
	if($format[8] == "") { $format[8] = "0 ".$GLOBALS["GENERAL"]["SECONDS"]; };
	return $format;
}

/**
 * myLANsite function
 * Name:	MLS_core_check_config
 * Purpose:	returns a value from the config
 *
 * @param string $field /name of the field in config-table
 * @return string /value
 */
function MLS_core_check_config($field) {
	//// Wert aus Config holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	$table = $tbl_prefix . "config";
	$query = "SELECT `$field` FROM `$table`";
	$result_conf = mysql_query($query,$db);
	MLS_core_check_result($query,$result_conf);
	$myrow_conf = mysql_fetch_row($result_conf);
	$return = $myrow_conf[0];
	
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_core_get_nick
 * Purpose:	returns the nickname of a userID
 *
 * @param int $user_ID /a user-ID
 * @return string /nickname
 */
function MLS_core_get_nick($user_ID) {
	//// Nickname zu einer User-ID holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "users";
	$query_get_nick = "SELECT `nickname` FROM `$table` WHERE `ID`='$user_ID'";
	$result_get_nick = mysql_query($query_get_nick,$db);
	MLS_core_check_result($query_get_nick,$result_get_nick);
	$myrow_get_nick = mysql_fetch_row($result_get_nick);
	$nickname = $myrow_get_nick[0];
	unset($myrow_get_nick);
	unset($result_get_nick);
	if($nickname == "") {
		$nickname = MLS_core_check_config("website_anonymousnick");
	}
	return $nickname;
};

/**
 * myLANsite function
 * Name:	MLS_core_get_email
 * Purpose:	returns the email of a userID
 *
 * @param int $user_ID /a user-ID
 * @return string /email
 */
function MLS_core_get_email($user_ID) {
	//// Email zu einer User-ID holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "users";
	$query_get_email = "SELECT `email` FROM `$table` WHERE `ID`='$user_ID'";
	$result_get_email = mysql_query($query_get_email,$db);
	MLS_core_check_result($query_get_email,$result_get_email);
	$myrow_get_email = mysql_fetch_row($result_get_email);
	$email = $myrow_get_email[0];
	unset($myrow_get_email);
	unset($result_get_email);
	if($email == "") {
		$email = "[".$GLOBALS["GENERAL"]["NO_EMAIL"]."]";
	}
	return $email;
};

/**
 * myLANsite function
 * Name:	MLS_core_get_quote
 * Purpose:	returns the quote of a userID
 *
 * @param int $user_ID /a user-ID
 * @return string /quote
 */
function MLS_core_get_quote($user_ID) {
	//// Quote zu einer User-ID holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "users";
	$query_get_quote = "SELECT `quote` FROM `$table` WHERE `ID`='$user_ID'";
	$result_get_quote = mysql_query($query_get_quote,$db);
	MLS_core_check_result($query_get_quote,$result_get_quote);
	$myrow_get_quote = mysql_fetch_row($result_get_quote);
	$quote = $myrow_get_quote[0];
	unset($myrow_get_quote);
	unset($result_get_quote);
	
	return $quote;
};

/**
 * myLANsite function
 * Name:	MLS_board_parse_message
 * Purpose:	parses a board-formatted message into html
 *
 * @param string $message /a board-formatted message
 * @return string /html-formatted message
 */
function MLS_board_parse_message($message) {
	//// Parser fuer Board-formatierte Nachrichten
	$message = ereg_replace("<", "&lt;", $message);
	$message = ereg_replace(">", "&gt;", $message);
	
	$message = nl2br($message);
	
	$message = eregi_replace("\[code\]", "[CODE]", $message);
	$message = eregi_replace("\[/code\]", "[/CODE]", $message);
	$i = 0;
	$count1 = substr_count($message,"[CODE]");
	$count2 = substr_count($message,"[/CODE]");
	while($count1 > $count2) {
		$message .= "[/CODE]";
		$count1 = $count1 - 1;
	}
	
	$message = eregi_replace("\[B\]", "<B>", $message);
	$message = eregi_replace("\[/B\]", "</B>", $message);
	$i = 0;
	$count1 = substr_count($message,"<B>");
	$count2 = substr_count($message,"</B>");
	while($count1 > $count2) {
		$message .= "</B>";
		$count1 = $count1 - 1;
	}
	
	$message = eregi_replace("\[I\]", "<I>", $message);
	$message = eregi_replace("\[/I\]", "</I>", $message);
	$i = 0;
	$count1 = substr_count($message,"<I>");
	$count2 = substr_count($message,"</I>");
	while($count1 > $count2) {
		$message .= "</I>";
		$count1 = $count1 - 1;
	}
	
	$message = eregi_replace("\[U\]", "<U>", $message);
	$message = eregi_replace("\[/U\]", "</U>", $message);
	$i = 0;
	$count1 = substr_count($message,"<U>");
	$count2 = substr_count($message,"</U>");
	while($count1 > $count2) {
		$message .= "</U>";
		$count1 = $count1 - 1;
	}
	
	
	$message = eregi_replace("\[color", "[COLOR", $message);
	$message = eregi_replace("\[/color\]", "[/COLOR]", $message);
	$message = eregi_replace('\[COLOR ([^]]*)\]([^]]*)\[/COLOR\]','<FONT COLOR="\\1">\\2</FONT>',$message);
	
	$message = eregi_replace("\[url", "[URL", $message);
	$message = eregi_replace("\[/url\]", "[/URL]", $message);
	$message = eregi_replace('\[URL ([^]]*)\]([^]]*)\[/URL\]','<A HREF="\\1" TARGET="_blank">\\2</A>',$message);
	
	$message = eregi_replace("\[quote]", "[QUOTE]", $message);
	$message = eregi_replace("\[/quote\]", "[/QUOTE]", $message);
	$i = 0;
	$count1 = substr_count($message,"[QUOTE]");
	$count2 = substr_count($message,"[/QUOTE]");
	while($count1 > $count2) {
		$message .= "[/QUOTE]";
		$count1 = $count1 - 1;
	}
	$message = eregi_replace("\[QUOTE\]","<BLOCKQUOTE><I><B>Zitat:</B><BR />",$message);
	$message = eregi_replace("\[/QUOTE\]","</I></BLOCKQUOTE>",$message);
	
	//// [CODE] bearbeiten
	$offset = 0;
	$i = 0;
	$code = "";
	while($i < strlen($message)) {
		$pos = strpos($message,"[CODE]",$i);
		if($pos !== false) {
			//// Solange noch [CODE] in der message steht
			//Positionen und string vor- und nachher rausfinden
			$code_pos_start = strpos($message,"[CODE]",$offset);
			$vorher = substr($message,0,$code_pos_start);
			$code_pos_end = strpos($message,"[/CODE]",$offset);
			$nachher = substr($message,$code_pos_end + 7,strlen($message));
			
			//String zwischen [CODE] und [/CODE]
			$substring = substr($message,$code_pos_start,$code_pos_end - $code_pos_start + 7);
			
			//substring HTML-Formatieren
			$code = substr($substring,6,strlen($substring) - 13);
			$code = "<?php\n\r" . $code . "\n\r?>";
			$code = ereg_replace("<br />", "", $code);
			$code = ereg_replace("&lt;", "<", $code);
			$code = ereg_replace("&gt;", ">", $code);
			ob_start();
			highlight_string($code);
			$code2 = ob_get_contents();
			ob_end_clean();
			$code = "<DIV STYLE=\"COLOR: #000000; BACKGROUND-COLOR: #CCCCCC; BORDER-COLOR: #000000; BORDER: 1px solid; PADDING: 2px\"><b>Code:</b><br>$code2</DIV>";
			
			//Wieder zusammenfügen
			$message = $vorher . $code . $nachher;
		}
		$i++;
	}
	return $message;
};

/**
 * myLANsite function
 * Name:	MLS_board_get_rank
 * Purpose:	get the board-rank of a user
 *
 * @param int $user_ID /a user-ID
 * @return string /rank of the given user
 */
function MLS_board_get_rank($user_ID) {
	//// Board-Rang zu einer User-ID holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "board_posts";
	$query = "SELECT `ID` FROM `$table` WHERE `autor`='$user_ID'";
	$anz_posts = mysql_num_rows(mysql_query($query,$db));
	
	$table = $tbl_prefix . "board_ranks";
	$query = "SELECT `name` FROM `$table` WHERE `von`<='$anz_posts' AND `bis`>='$anz_posts'";
	$result_rank = mysql_query($query,$db);
	MLS_core_check_result($query,$result_rank);
	$myrow_rank = mysql_fetch_row($result_rank);
	
	$rank = array();
	$rank[0] = $myrow_rank[0];
	$rank[1] = $anz_posts;
	
	return $rank;
};

/**
 * myLANsite function
 * Name:	MLS_core_check_access
 * Purpose:	checks if a user has access to a page
 *		and echoes the error-message if he has
 *		no access
 *
 * @param int $userid /a user-ID
 * @param string $section /name of the section (site)
 * @param string $content /name of the content (page)
 * @return int /1 or 0
 */
function MLS_core_check_access($userid,$section,$content) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	$return = 0;
	
	//// ID's von section und content rausfinden, da ja namen gegeben sind
	$table = $tbl_prefix . "sections";
	$query_IDs1 = "SELECT `ID` FROM `$table` WHERE `name`='$section'";
	$result_IDs1 = mysql_query($query_IDs1,$db);
	MLS_core_check_result($query_IDs1,$result_IDs1);
	$myrow_IDs1 = mysql_fetch_row($result_IDs1);
	$section_ID = $myrow_IDs1[0];
	
	$table = $tbl_prefix . "content";
	$query_IDs2 = "SELECT `ID` FROM `$table` WHERE `name`='$content' AND `section`='$section_ID'";
	$result_IDs2 = mysql_query($query_IDs2,$db);
	MLS_core_check_result($query_IDs2,$result_IDs2);
	$myrow_IDs2 = mysql_fetch_row($result_IDs2);
	$content_ID = $myrow_IDs2[0];
	
	//// Access checken
	$table = $tbl_prefix . "access";
	$query_access = "SELECT `ID` FROM `$table` WHERE `content`='$content_ID'";
	$access_check = mysql_num_rows(mysql_query($query_access));
	
	if($access_check == 0) {
		//Es ist kein Access eingetragen
		//Zugriff für alle Benutzer
		$return = 1;
	} else {
		//Alle access-Einträge fetchen und mit
		//den Berechtigungen des Users prüfen
		$echo = "<b><font color=\"#FF0000\">".$GLOBALS["GENERAL"]["ACCESS_DENIED"]."</font></b><br><br>\n\n";
		$echo .= $GLOBALS["GENERAL"]["ONLY_THIS_GROUPS_HAVE_ACCESS"].":<br>\n";
		$table1 = $tbl_prefix . "access";
		$table2 = $tbl_prefix . "groups";
		$query_access = "SELECT a1.ID,a1.group,a1.content,a2.name FROM `$table1` AS a1 INNER JOIN `$table2` AS a2 ON a1.group=a2.ID WHERE a1.content='$content_ID'";
		$result_access = mysql_query($query_access,$db);
		MLS_core_check_result($query_access,$result_access);
		while($myrow_access = mysql_fetch_row($result_access)) {
			//Gruppentabelle checken
			$table = $tbl_prefix . "groups_users";
			$query_group = "SELECT * FROM `$table` WHERE `user`='$userid' AND `group`='$myrow_access[1]'";
			$check_group = mysql_num_rows(mysql_query($query_group,$db));
			
			//Wenn er Gruppenmitglied ist, return = 1
			if($check_group == 0) {
				if($return != 1) {
					//Nur wenn er noch nicht 1 ist
					//auf 0 setzen
					$return = 0;
					$echo .= "<b>$myrow_access[3]</b><br>\n";
				}
			} else {
				$return = 1;
			}
		}
	}
	if($return == 0) {
		$echo .= "<br>\n".$GLOBALS["GENERAL"]["ACCESS_NOTICE"]." <a href=\"?site=login&page=users&group=users\">users</a>.<br>\n";
		echo $echo;
	}
	return $return;

};

/**
 * myLANsite function
 * Name:	MLS_core_check_group
 * Purpose:	checks if the given user is in the specified group
 *
 * @param int $user /a user-ID
 * @param string $group /a group name
 * @return int /1 or 0
 */
function MLS_core_check_group($user,$group) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "groups";
	$query = "SELECT `ID` FROM `$table` WHERE `name`='$group'";
	$result_name = mysql_query($query,$db);
	$myrow_name = mysql_fetch_row($result_name);
	
	$table = $tbl_prefix . "groups_users";
	$query = "SELECT `user` FROM `$table` WHERE `group`='$myrow_name[0]' AND `user`='$user'";
	$inside = mysql_num_rows(mysql_query($query));
	
	return $inside;
};

/**
 * myLANsite function
 * Name:	MLS_message_send_message
 * Purpose:	sends a message
 *
 * @param int $from /the sender's ID
 * @param int $to /the recipients's ID
 * @param string $subject /the subject
 * @param string $subject /the message
 * @return int /0 if it fails or 1 if ok
 */
function MLS_message_send_message($from,$to,$subject,$message) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	unset($result);
	
	$table = $tbl_prefix . "messaging";
	$time = time();
	$query = "INSERT INTO `$table` (`ID`,`absender`,`empfaenger`,`time`,`subject`,`message`,`gelesen`) VALUES ('','$from','$to','$time','$subject','$message','nein')";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	if($result) {
		$return = 1;
	} else {
		$return = 0;
	}
	
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_core_check_page
 * Purpose:	checks if the given page is a virtual page
 *
 * @param string $section /name of the section (site)
 * @param string $content /name of the content (page)
 * @return int /0 if it's no page else the page-ID
 */
function MLS_core_check_page($section,$content) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	//// ID's von section und content rausfinden, da ja namen gegeben sind
	$table = $tbl_prefix . "sections";
	$query_IDs1 = "SELECT `ID` FROM `$table` WHERE `name`='$section'";
	$result_IDs1 = mysql_query($query_IDs1,$db);
	MLS_core_check_result($query_IDs1,$result_IDs1);
	$myrow_IDs1 = mysql_fetch_row($result_IDs1);
	$section_ID = $myrow_IDs1[0];
	
	$table = $tbl_prefix . "content";
	$query_IDs2 = "SELECT `ID`,`page_ID` FROM `$table` WHERE `name`='$content' AND `section`='$section_ID'";
	$result_IDs2 = mysql_query($query_IDs2,$db);
	$myrow_IDs2 = mysql_fetch_row($result_IDs2);
	MLS_core_check_result($query_IDs2,$result_IDs2);
	$content_ID = $myrow_IDs2[0];
	$page_ID = $myrow_IDs2[1];
	
	if($page_ID != 0) {
		$return = $page_ID;
	} else {
		$return = 0;
	}
	
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_files_format_bytes
 * Purpose:	formats a number of bytes to a
 * 		human-readable form
 *
 * @param int $bytes /number of bytes
 * @return string /formatted number of bytes
 */
function MLS_files_format_bytes($bytes) {
	if($bytes <= 1024) {
		$groesse_sort = " Bytes";
	} else {
		$i = 0;
		while($bytes > 1024) {
			$bytes = $bytes / 1024;
			if($i == 0) {
				$groesse_sort = " KB";
			} elseif($i == 1) {
				$groesse_sort = " MB";
			} elseif($i == 2) {
				$groesse_sort = " GB";
			} elseif($i == 3) {
				$groesse_sort = " TB";
			} elseif($i > 3) {
				$groesse_sort = " Bytes";
			}
			$i++;
		}
		if($groesse_sort == " Bytes") {
			//Bei Bytes Tausenderstrich machen
			$bytes = $myrow[6];
			$len = strlen($bytes);
			$tausender = array();
			$groesse_temp = $bytes;
			$i = 0;
			while(strlen($groesse_temp) > 0) {
				$tausender[$i] = substr($groesse_temp,strlen($groesse_temp) - 3,strlen($groesse_temp));
				$groesse_temp = substr($groesse_temp,0,strlen($groesse_temp) - 3);
				$i++;
			}
			$anz_tausender = count($tausender);
			
			$i = 1;
			$groesse_temp = $tausender[0];
			
			while($i < $anz_tausender) {
				$groesse_temp = $tausender[$i] . "'" . $groesse_temp;
				$i++;
			}
			$bytes = $groesse_temp;
		} else {
			$nachkomma = strstr($bytes,".");
			$vorkomma = substr($bytes,0,strlen($bytes) - strlen($nachkomma));
			$nachkomma_1 = substr($nachkomma,1,1);
			$nachkomma_2 = substr($nachkomma,2,1);
			if($nachkomma_2 >= 5) {
				$nachkomma_1 = $nachkomma_1 + 1;
			}
			$bytes = $vorkomma . "." . $nachkomma_1;
		}
	}
	
	$bytes = $bytes . $groesse_sort;
	return $bytes;
};

/**
 * myLANsite function
 * Name:	MLS_core_check_result
 * Purpose:	checks if a query will fail or not
 * 		if it fails, echo the error-message
 * 		and the bugreport-form
 *
 * @param string $query /the query to be executed
 * @param result $result /the result to be checked
 * @param int $output_err /1 if it should output errors
 *			   0 if not
 * @param int $output_ok  /1 if it should output ok-message
 *			   0 if not
 * @param string $message_err /the error-message to be displayed
 * @param string $message_ok /the ok-message to be displayed
 * @return int /0 if it fails, 1 if not
 */
 
function MLS_core_check_result($query,$result,$output_err=1,$output_ok=0,$message_err="",$message_ok="") {
	$error = mysql_errno().": ".mysql_error();
	if($message_ok == "") {
		$message_ok = $GLOBALS["GENERAL"]["CHECK_RESULT_OK"];
	}
	if($message_err == "") {
		$message_err = $GLOBALS["GENERAL"]["CHECK_RESULT_ERROR"];
	}
	$imagepath = "img/";
	$image = $imagepath . "error.gif";
	if(file_exists($image) == FALSE) {
		while(file_exists($image) == FALSE) {
			$imagepath = "../" . $imagepath;
			$image = $imagepath . "error.gif";
		}
	}
	$image_err = $imagepath . "error.gif";
	$image_ok = $imagepath . "ok.gif";
	$URL = $_SERVER["REQUEST_URI"];
	$time = time();
	
	$site = eregi_replace('([^]]*)?site=([^]]*)','\\2',$URL);
	$site = substr($site,0,strlen($site) - strlen(strchr($site,"&")));
	
	$page = eregi_replace('([^]]*)&page=([^]]*)','\\2',$URL);
	$page = substr($page,0,strlen($page) - strlen(strchr($page,"&")));
	
	if(!strchr($URL,"&page=")) {
		$page = "";
	}
	
	if(!$result) {
		$return = 0;
		if($output_err == 1) {
			printf("<table border=\"0\" cellspacing=\"2\" cellpadding=\"5\">\n");
			$action = "http://www.mylansite.org/index2.php?site=informationen&page=tickets";
			printf("<form method=\"POST\" action=\"$action\">");
			printf("<tr>\n");
			printf("<td style=\"border: 1px solid #FF8080\" width=\"30\" valign=\"middle\"><img src=\"$image_err\"></td>\n");
			printf("<td style=\"border: 1px solid #FF8080\" width=\"520\" valign=\"middle\"><b>$message_err<br>\n");
			printf("<input type=\"hidden\" name=\"userid\" value=\"%s\">", $_SESSION['sess_USERID']);
			printf("<input type=\"hidden\" name=\"ticket_query\" value=\"$query\">");
			printf("<input type=\"hidden\" name=\"url\" value=\"$URL\">");
			printf("<input type=\"hidden\" name=\"ticket_site\" value=\"$site\">");
			printf("<input type=\"hidden\" name=\"ticket_page\" value=\"$page\">");
			printf("<input type=\"hidden\" name=\"mysql_error\" value=\"%s\">", $error);
			$webmaster = MLS_core_check_config("general_webmaster");
			printf("<input type=\"hidden\" name=\"ticket_webmaster\" value=\"$webmaster\">");
			$website = MLS_core_check_config("general_URL");
			printf("<input type=\"hidden\" name=\"website\" value=\"$website\">");
			printf("<input type=\"submit\" name=\"submit_bug\" value=\"send Bugreport\"></td>");
			printf("</tr>\n");
			printf("</form>\n");
			printf("</table>\n");
		}
	} else {
		$return = 1;
		if($output_ok == 1) {
			printf("<table border=\"0\" cellspacing=\"2\" cellpadding=\"5\">\n");
			printf("<tr>\n");
			printf("<td style=\"border: 1px solid #80FF80\" width=\"30\" valign=\"middle\"><img src=\"$image_ok\"></td>\n");
			printf("<td style=\"border: 1px solid #80FF80\" width=\"520\" valign=\"middle\"><b>$message_ok<br></b></td>\n");
			printf("</tr>\n");
			printf("</table>\n");
		}
	}
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_core_show_error
 * Purpose:	echoes an error message
 *
 * @param string $message /message to be displayed
 * @return boolean /always true
 */
function MLS_core_show_error($message) {
	$imagepath = "img/";
	$image = $imagepath . "error.gif";
	if(file_exists($image) == FALSE) {
		while(file_exists($image) == FALSE) {
			$imagepath = "../" . $imagepath;
			$image = $imagepath . "error.gif";
		}
	}
	printf("<table border=\"0\" cellspacing=\"2\" cellpadding=\"5\">\n");
	printf("<tr>\n");
	printf("<td style=\"border: 1px solid #FF8080\" width=\"30\" valign=\"middle\"><img src=\"$image\"></td>\n");
	printf("<td style=\"border: 1px solid #FF8080\" width=\"520\" valign=\"middle\"><b>$message</b></td>\n");
	printf("</td>\n");
	printf("</tr>\n");
	printf("</table>\n");
	
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_core_show_ok
 * Purpose:	echoes an ok message
 *
 * @param string $message /message to be displayed
 * @return boolean /always true
 */
function MLS_core_show_ok($message) {
	$imagepath = "img/";
	$image = $imagepath . "ok.gif";
	if(file_exists($image) == FALSE) {
		while(file_exists($image) == FALSE) {
			$imagepath = "../" . $imagepath;
			$image = $imagepath . "ok.gif";
		}
	}
	printf("<table border=\"0\" cellspacing=\"2\" cellpadding=\"5\">\n");
	printf("<tr>\n");
	printf("<td style=\"border: 1px solid #80FF80\" width=\"30\" valign=\"middle\"><img src=\"$image\"></td>\n");
	printf("<td style=\"border: 1px solid #80FF80\" width=\"520\" valign=\"middle\"><b>$message</b></td>\n");
	printf("</td>\n");
	printf("</tr>\n");
	printf("</table>\n");
};

/**
 * myLANsite function
 * Name:	MLS_catering_get_avg_delivery_time
 * Purpose:	gets the average delivery time of
 * 		catering items
 *
 * @return string /formatted time
 */
function MLS_catering_get_avg_delivery_time() {
	//Mittlere Lieferzeit
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "pizza_einkauf";
	$query_liefer = "SELECT `einkauf_time`,`liefer_time` FROM `$table` WHERE `liefer_time`!='0'";
	$result_liefer = mysql_query($query_liefer,$db);
	MLS_core_check_result($query,$result_liefer);
	$anzahl = mysql_num_rows($result_liefer);
	
	$offset_total = 0;
	
	while($myrow_liefer = mysql_fetch_row($result_liefer)) {
		$offset = $myrow_liefer[1] - $myrow_liefer[0];
		$offset_total = $offset_total + $offset;
	}
	
	if($anzahl == 0) { $anzahl = 1; };
	$offset_mittel = $offset_total / $anzahl;
	$zeit = MLS_core_format_timestamp($offset_mittel);
	return $zeit[8];
};

/**
 * myLANsite function
 * Name:	MLS_core_get_country_name
 * Purpose:	gets the name of a country by its code
 *
 * @param string $code /the country code
 * @return string /the country name
 */
function MLS_core_get_country_name($code) {
	//Get coutry name by code
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$code = strtoupper($code);
	$table = $tbl_prefix . "countries";
	$query_country = "SELECT `name` FROM `$table` WHERE `code`='$code'";
	$result_country = mysql_query($query_country,$db);
	$myrow_country = mysql_fetch_row($result_country);
	if($myrow_country[0] == "") {
		$return = $code;
	} else {
		$return = $myrow_country[0];
	}

	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_central_auth
 * Purpose:	checks if the mylancentral-password
 * 		given in configuration is valid
 *
 * @return int /1 if auth is valid, 0 if not
 */
function MLS_central_auth() {
	//auth on central-server
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	include($GLOBALS['INCLUDE_BASE'] . "central_scripts/parsexmltable.php");
	$website_ID = MLS_core_check_config("mylancentral_website_ID");
	$password = MLS_core_enc(MLS_core_check_config("mylancentral_website_pass"));
	
	$url = MLS_core_check_config("mylancentral_url") . "central_scripts/website_auth.php?website_ID=$website_ID&website_pass=$password";
	$xmldata = parsexmltable("$url");
	if(count($xmldata) == 0) {
		return 0;
	} else {
		return 1;
	}
};

/**
 * myLANsite function
 * Name:	MLS_core_get_group_id
 * Purpose:	gets the ID of a group by its name
 *
 * @param string $groupname /name of the group
 * @return int /ID of the group
 */
function MLS_core_get_group_id($groupname) {
	//get the ID of a group
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "groups";
	$query = "SELECT `ID` FROM `$table` WHERE `name`='$groupname'";
	$result_group_id = mysql_query($query,$db);
	$myrow_group_id = mysql_fetch_row($result_group_id);
	
	return $myrow_group_id[0];
};

/**
 * myLANsite function
 * Name:	MLS_core_get_group_name
 * Purpose:	gets the name of a group by its ID
 *
 * @param int $groupid /ID of the group
 * @return string /name of the group
 */
function MLS_core_get_group_name($groupid) {
	//get the ID of a group
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "groups";
	$query = "SELECT `name` FROM `$table` WHERE `ID`='$groupid'";
	$result_group_name = mysql_query($query,$db);
	$myrow_group_name = mysql_fetch_row($result_group_name);
	
	return $myrow_group_name[0];
};

/**
 * myLANsite function
 * Name:	MLS_tournament_get_clan_name
 * Purpose:	gets the name of a clan by its ID
 *
 * @param ind $clan_ID /ID of the clan
 * @return string /name of the group
 */
function MLS_tournament_get_clan_name($clan_ID) {
	//// name eines Clans holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "clans";
	$query_clan_name = "SELECT `name` FROM `$table` WHERE `ID`='$clan_ID'";
	$result_clan_name = mysql_query($query_clan_name,$db);
	MLS_core_check_result($query_clan_name,$result_clan_name);
	$myrow_clan_name = mysql_fetch_row($result_clan_name);
	$clan_name = $myrow_clan_name[0];
	unset($myrow_clan_name);
	unset($result_clan_name);
	return $clan_name;
};


/**
 * myLANsite function
 * Name:	MLS_core_get_labels
 * Purpose:	get the labels of a page and
 * 		store them in $GLOBALS["LABELS"]
 *
 * @param string $section /section-name
 * @param string $content /content-name
 * @return boolean /always true
 */
function MLS_core_get_labels($section = FALSE,$content = FALSE) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$lang = MLS_core_check_config("website_lang");
	$default_lang = MLS_core_check_config("website_deflang");
	
	//// ID's von section und content rausfinden, da ja namen gegeben sind
	$table = $tbl_prefix . "sections";
	$query_IDs1 = "SELECT `ID` FROM `$table` WHERE `name`='$section'";
	$result_IDs1 = mysql_query($query_IDs1,$db);
	MLS_core_check_result($query_IDs1,$result_IDs1);
	$myrow_IDs1 = mysql_fetch_row($result_IDs1);
	$section_ID = $myrow_IDs1[0];
	
	$table = $tbl_prefix . "content";
	$query_IDs2 = "SELECT `ID` FROM `$table` WHERE `name`='$content' AND `section`='$section_ID'";
	$result_IDs2 = mysql_query($query_IDs2,$db);
	MLS_core_check_result($query_IDs2,$result_IDs2);
	$myrow_IDs2 = mysql_fetch_row($result_IDs2);
	$content_ID = $myrow_IDs2[0];
	
	//// Abfrage
	$table = $tbl_prefix . "texts";
	$query = "SELECT `ID`,`name` FROM `$table` WHERE `contentID`='$content_ID'";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	
	while($myrow = mysql_fetch_row($result)) {
		//// Alle texte der Seite werden gefetcht
		// Sprachen holen
		$table = $tbl_prefix . "texts_lang";
		$query = "SELECT `text` FROM `$table` WHERE `langCODE`='$lang' AND `textID`='$myrow[0]'";
		$result_lang = mysql_query($query,$db);
		if(mysql_num_rows($result_lang) == 0) {
			$query = "SELECT `text` FROM `$table` WHERE `langCODE`='$default_lang' AND `textID`='$myrow[0]'";
			$result_lang = mysql_query($query,$db);
		}
		MLS_core_check_result($query,$result_lang);
		$myrow_lang = mysql_fetch_row($result_lang);
		if($myrow_lang[0] == "") {
			$text = $myrow[1];
		} else {
			$text = $myrow_lang[0];
		}
		$GLOBALS["LABELS"]["$myrow[1]"] = $text;
	}
	
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_central_get_user
 * Purpose:	gets a user from the mylancentral-server
 * 		and stores it in the local database
 *
 * @param string $email /the user's email
 * @param int $userid /the user's ID
 * @return int /0 if it fails, else 1
 */
function MLS_central_get_user($email = "",$userid = 0) {
	// Eintrag von central holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "users";
	if($email != "") {
		$exeption = " WHERE `email`='$email'";
		$link = "email=$email";
	} elseif($userid != 0) {
		$exeption = " WHERE `ID`='$userid'";
		$link = "ID=$userid";
	}
	$query = "SELECT `ID` FROM `$table`" . $exeption;
	
	$result_check = mysql_query($query,$db);
	MLS_core_check_result($query,$result_check);
	if(mysql_num_rows($result_check) != 0) {
		//User existiert bereits
		MLS_core_show_error($GLOBALS["GENERAL"]["GET_USER_EXISTS"]);
	} else {
		$url = MLS_core_check_config("mylancentral_url") . "central_scripts/get_user.php?" . $link;
		include_once($GLOBALS['INCLUDE_BASE'] . "central_scripts/parsexmltable.php");
		$xmldata = parsexmltable("$url");
		if(count($xmldata) < 2) {
			return 0;
		} else {
			$table = $tbl_prefix . "users";
			$query = "INSERT INTO `$table` (";
			
			// Loop for fieldnames
			$fieldnames = "";
			for($i = 0; $i < count($xmldata[0]); $i++) {
				$fieldnames .= "`" . $xmldata[0][$i] . "`,";
			}
			$fieldnames = substr($fieldnames,0,strlen($fieldnames) - 1);
			
			// data-loop
			$data = "";
			for($i = 1; $i < count($xmldata); $i++) {
				for($k = 0; $k < count($xmldata[$i]); $k++) {
					$data .= "'" . $xmldata[$i][$k] . "',";
				}
			}
			$data = substr($data,0,strlen($data) - 1);
			$query = "INSERT INTO `$table` (" . $fieldnames . ") VALUES (" . $data . ")";
			$result_user = mysql_query($query,$db);
			MLS_core_check_result($query,$result_user);
			return 1;
		}
	}
};

/**
 * myLANsite function
 * Name:	MLS_central_update_user
 * Purpose:	updates a user from the mylancentral-server
 * 		and updates it in the local database
 *
 * @param string $email /the user's email
 * @param int $userid /the user's ID
 * @return int /0 if it fails, else 1
 */
function MLS_central_update_user($email = "", $userid = 0) {
	// Eintrag von central holen
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table = $tbl_prefix . "users";
	if($email != "") {
		$exeption = " WHERE `email`='$email'";
		$link = "email=$email";
	} elseif($userid != 0) {
		$exeption = " WHERE `ID`='$userid'";
		$link = "ID=$userid";
	}
	$query = "SELECT `ID` FROM `$table`" . $exeption;
	$result_check = mysql_query($query,$db);
	MLS_core_check_result($query,$result_check);
	if(mysql_num_rows($result_check) == 0) {
		//User existiert bereits
		MLS_core_show_error($GLOBALS["GENERAL"]["UPDATE_USER_NOT_EXITS"]);
	} else {
		$url = MLS_core_check_config("mylancentral_url") . "central_scripts/get_user.php?" . $link;
		include_once($GLOBALS['INCLUDE_BASE'] . "central_scripts/parsexmltable.php");
		$xmldata = parsexmltable("$url");
		
		if(count($xmldata) < 2) {
			return 0;
		} else {
			$table = $tbl_prefix . "users";
			
			// Loop for fieldnames
			$data = "";
			for($i = 0; $i < count($xmldata[0]); $i++) {
				$data .= "`" . $xmldata[0][$i] . "`='" . $xmldata[1][$i] . "',";
			}
			
			$data = substr($data,0,strlen($data) - 1);
			$query = "UPDATE `$table` SET" . $data . $exeption;
			$result_user = mysql_query($query,$db);
			MLS_core_check_result($query,$result_user);
			
			return 1;
		}
	}
};

/**
 * myLANsite function
 * Name:	MLS_core_print_link
 * Purpose:	returns the url of a page
 *
 * @param int $content_ID /content-ID
 * @return string /link like "?site=login&page=logout"
 */
function MLS_print_link($content_ID) {
	include($GLOBALS['INCLUDE_BASE'] . "connect.php");
	
	$table1 = $tbl_prefix . "sections";
	$table2 = $tbl_prefix . "content";
	$query = "SELECT a1.name,a2.name FROM `$table1` AS a1 INNER JOIN `$table2` AS a2 ON a1.ID=a2.section WHERE a2.ID='$content_ID'";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	$myrow = mysql_fetch_row($result);
	
	$retstr = "?site=" . $myrow[0] . "&page=" . $myrow[1];
	
	return $retstr;
};

/**
 * myLANsite function
 * Name:	MLS_event_registration
 * Purpose:	registers an user for an event
 *
 * @param int $user_ID /the user's ID
 * @param int $event_ID /the event's ID
 * @return boolean /always true
 */
function MLS_event_registration($user_ID,$event_ID) {
	include("connect.php");
	$table = $tbl_prefix . "events";
	$query = "SELECT `ID`,`name`,`anmelden` FROM `$table` WHERE `ID`='$event_ID'";
	$result_event = mysql_query($query,$db);
	MLS_core_check_result($query,$result_event);
	$myrow_event = mysql_fetch_row($result_event);
	if($myrow_event[2] == 'nein') {
		MLS_core_show_error($GLOBALS["LABELS"]["SUBSCRIPTION_NOT_STARTED"]);
	} else {
		$table = $tbl_prefix . "events_teilnehmer";
		$query = "SELECT `subscribed` FROM `$table` WHERE `event_ID`= '$event_ID' AND `user_ID`='$user_ID'";
		$result = mysql_query($query,$db);
		$anz = mysql_num_rows($result);
		if($anz != 0) {
			$myrow = mysql_fetch_row($result);
			$time = MLS_core_format_timestamp($myrow[0]);
			
			MLS_core_show_error($GLOBALS["LABELS"]["ALREADY_SUBSCRIBED"]."$time[0] um $time[1]!");
		} else {
			$time = time();
			$query = "INSERT INTO `$table` (`event_ID`,`user_ID`,`subscribed`,`bezahlt`) VALUES ('$event_ID','$user_ID','$time','nein')";
			$result = mysql_query($query,$db);
			MLS_core_check_result($query,$result,1,1,$GLOBALS["LABELS"]["SUBSCRIPTION_ERROR"],$GLOBALS["LABELS"]["SUBSCRIPTION_OK"]);
		}
	}
	
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_board_markasread
 * Purpose:	marks all threads in a board as 'read'
 *
 * @param int $userid /the user's ID
 * @param int $board /the board's ID
 * @return boolean /always true
 */
function MLS_board_markasread($userid,$board) {
	//mark all threads in a board as read
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	$table = $tbl_prefix . "board_threads";
	$query = "SELECT `ID` FROM `$table` WHERE `board`='$board'";
	$result_threads = mysql_query($query,$db);
	MLS_core_check_result($query,$result_threads);
	
	while($myrow_threads = mysql_fetch_row($result_threads)) {
		$table = $tbl_prefix . "board_visits";
		$query = "SELECT `time` FROM `$table` WHERE `thread_ID`='$myrow_threads[0]' AND `user_ID`='$userid'";
		$result = mysql_query($query,$db);
		MLS_core_check_result($query,$result);
		$time = time();
		if(mysql_num_rows($result) == 0) {
			$query = "INSERT INTO `$table` (`ID`,`user_ID`,`time`,`thread_ID`) VALUES ('','$userid','$time','$myrow_threads[0]')";
		} else {
			$query = "UPDATE `$table` SET `time`='$time' WHERE `thread_ID`='$myrow_threads[0]' AND `user_ID`='$userid'";
		}
		$newresult = mysql_query($query,$db);
		MLS_core_check_result($query,$newresult);
	}
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_board_add_notify
 * Purpose:	adds the given user to the notify
 * 		list of a given thread
 *
 * @param int $userid /the user's ID
 * @param int $thread /the thread's ID
 * @return boolean /always true
 */
function MLS_board_add_notify($userid,$thread) {
	//adds me to the notify list
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	$table = $tbl_prefix . "board_notify";
	$query = "SELECT `user_ID`,`thread_ID`,`time` FROM `$table` WHERE `user_ID`='$userid' AND `thread_ID`='$thread'";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	
	if(mysql_num_rows($result) == 0) {
		$time = time();
		$query = "INSERT INTO `$table` (`user_ID`,`thread_ID`,`time`) VALUES ('$userid','$thread','$time')";
		$newresult = mysql_query($query,$db);
		MLS_core_check_result($query,$newresult);
	}
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_board_notify
 * Purpose:	notifies all users of changes in the given thread
 *
 * @param int $thread /the thread's ID
 * @return boolean /always true
 */
function MLS_board_notify($thread) {
	//send notices to the specified users of new posts
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	$table1 = $tbl_prefix . "board_notify";
	$table2 = $tbl_prefix . "users";
	$query = "SELECT a1.user_ID,a1.time,a2.email,a2.vorname,a2.name,a2.nickname FROM `$table1` AS a1 INNER JOIN `$table2` AS a2 ON a1.user_ID=a2.ID WHERE a1.thread_ID='$thread'";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	while($myrow = mysql_fetch_row($result)) {
		//get last visit
		$table = $tbl_prefix . "board_visits";
		$query = "SELECT `time` FROM `$table` WHERE `thread_ID`='$thread' AND `user_ID`='$myrow[0]'";
		$result_visit = mysql_query($query,$db);
		MLS_core_check_result($query,$result_visit);
		$myrow_visit = mysql_fetch_row($result_visit);
		if($myrow_visit[0] > $myrow[1]) {
			//if my last visit was AFTER the last notice
			//send mail again
			
			//// Email senden
			include($GLOBALS["INCLUDE_BASE"]."lang/".MLS_core_check_config("website_lang")."/emails/lang_newthreads.php");
			$message = $GLOBALS["EMAILS"]["MESSAGE"];
			$message = ereg_replace("\[lan_name\]", $lan_name, $message);
			$message = ereg_replace("\[vorname\]", $myrow[3], $message);
			$message = ereg_replace("\[nachname\]", $myrow[4], $message);
			$message = ereg_replace("\[nickname\]", $myrow[5], $message);
			$link = MLS_core_check_config("general_url")."index2.php?site=board&page=posts&thread=$thread\n\n";
			$message = ereg_replace("\[link\]", $link, $message);
			$message = ereg_replace("\[URL\]", MLS_core_check_config("general_url"), $message);
			$message = ereg_replace("\[br\]", "\n", $message);
			$message = ereg_replace("\[tab\]", "\t", $message);
			$subject = $GLOBALS["EMAILS"]["SUBJECT"];
			$subject = ereg_replace("\[lan_name\]", $lan_name, $subject);
			$subject = ereg_replace("\[URL\]", MLS_core_check_config("general_url"), $subject);
			$from = MLS_core_check_config("emails_from");
			$replyto = MLS_core_check_config("emails_reply_to");
			mail($myrow[2], $subject, $message,
			"From: $from\r\n"
			."Reply-To: $replyto\r\n"
			."X-Mailer: PHP/" . phpversion());
			
			//update time in notify-table
			$table = $tbl_prefix . "board_notify";
			$time = time();
			$query = "UPDATE `$table` SET `time`='$time' WHERE `user_ID`='$myrow[0]' AND `thread_ID`='$thread'";
			$result_update = mysql_query($query,$db);
			MLS_core_check_result($query,$result_update);
		}
	}
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_board_visit
 * Purpose:	marks that the given user visited the given thread
 *
 * @param int $userid /the user's ID
 * @param int $thread /the thread's ID
 * @return boolean /always true
 */
function MLS_board_visit($userid,$thread) {
	//check a board as visited
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	
	$table = $tbl_prefix . "board_visits";
	$query = "SELECT `time` FROM `$table` WHERE `thread_ID`='$thread' AND `user_ID`='$userid'";
	$result = mysql_query($query,$db);
	MLS_core_check_result($query,$result);
	$time = time();
	if(mysql_num_rows($result) == 0) {
		$query = "INSERT INTO `$table` (`ID`,`user_ID`,`time`,`thread_ID`) VALUES ('','$userid','$time','$thread')";
	} else {
		$query = "UPDATE `$table` SET `time`='$time' WHERE `thread_ID`='$thread' AND `user_ID`='$userid'";
	}
	$newresult = mysql_query($query,$db);
	MLS_core_check_result($query,$newresult);
	return true;
};

/**
 * myLANsite function
 * Name:	MLS_board_check_new
 * Purpose:	checks if there are new posts in a board
 *
 * @param int $userid /the user's ID
 * @param int $board /the board's ID
 * @return int /1 if there are new posts, 0 if not
 */
function MLS_board_check_new($userid,$board = 0,$thread = 0) {
	//checks if there are new posts in a board
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	$table = $tbl_prefix . "board_threads";
	$query = "SELECT `ID` FROM `$table` WHERE";
	if($board != 0) {
		$query .= " `board`='$board'";
	} else {
		$query .= " `ID`='$thread'";
	}
	$result_threads = mysql_query($query,$db);
	MLS_core_check_result($query,$result_threads);
	
	$return = 0;
	while($myrow_threads = mysql_fetch_row($result_threads)) {
		$table = $tbl_prefix . "board_visits";
		$query = "SELECT `time` FROM `$table` WHERE `thread_ID`='$myrow_threads[0]' AND `user_ID`='$userid'";
		$result = mysql_query($query,$db);
		MLS_core_check_result($query,$result);
		if(mysql_num_rows($result) == 0) {
			//if I have never visited this thread
			$return = 1;
		} else {
			//only if I visited this thread once
			$myrow = mysql_fetch_row($result);
			
			$table = $tbl_prefix . "board_posts";
			$query = "SELECT `post_time` FROM `$table` WHERE `thread`='$myrow_threads[0]' ORDER BY `post_time` DESC LIMIT 1";
			$result_post = mysql_query($query,$db);
			MLS_core_check_result($query,$result_post);
			$myrow_post = mysql_fetch_row($result_post);
		
			if($myrow[0] < $myrow_post[0]) {
				//if my last visit was before the newest post
				$return = 1;
			}
		}
	}
	
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_board_check_mod
 * Purpose:	checks if the given user is a moderator
 * 		of the given board
 *
 * @param int $user /the user's ID
 * @param int $board /the board's ID
 * @return int /1 if he's a mod, 0 if not
 */
function MLS_board_check_mod($user,$board) {
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	
	$table = $tbl_prefix . "board_mods";
	$query = "SELECT `ID` FROM `$table` WHERE `user`='$user' AND `board`='$board'";
	$mod = mysql_num_rows(mysql_query($query,$db));
	
	$return = 0;
	if($mod != 0) {
		$return = 1;
	}
	return $return;	
};

/**
 * myLANsite function
 * Name:	MLS_board_check_board_access
 * Purpose:	checks if the given user has access to the given board
 *
 * @param int $userid /the user's ID
 * @param int $board /the board's ID
 * @param boolean $error /echo the error message or not
 * @return int /1 if he has access, 0 if not
 */
function MLS_board_check_board_access($userid,$board,$error = TRUE) {
	include($GLOBALS["INCLUDE_BASE"]."connect.php");
	$return = 0;
	
	//// Access checken
	$table = $tbl_prefix . "board_access";
	$query_access = "SELECT `group` FROM `$table` WHERE `board`='$board'";
	$access_check = mysql_num_rows(mysql_query($query_access));
	
	if($access_check == 0) {
		//Es ist kein Access eingetragen
		//Zugriff für alle Benutzer
		$return = 1;
	} else {
		//Alle access-Eintraege fetchen und mit
		//den Berechtigungen des Users pruefen
		$echo = "<b><font color=\"#FF0000\">".$GLOBALS["GENERAL"]["ACCESS_DENIED"]."</font></b><br><br>\n\n";
		$echo .= $GLOBALS["GENERAL"]["ONLY_THIS_GROUPS_HAVE_ACCESS"].":<br>\n";
		$table1 = $tbl_prefix . "board_access";
		$table2 = $tbl_prefix . "groups";
		$query_access = "SELECT a1.group,a1.board,a2.name FROM `$table1` AS a1 INNER JOIN `$table2` AS a2 ON a1.group=a2.ID WHERE a1.board='$board'";
		$result_access = mysql_query($query_access,$db);
		MLS_core_check_result($query_access,$result_access);
		while($myrow_access = mysql_fetch_row($result_access)) {
			//Gruppentabelle checken
			$table = $tbl_prefix . "groups_users";
			$query_group = "SELECT * FROM `$table` WHERE `user`='$userid' AND `group`='$myrow_access[0]'";
			$check_group = mysql_num_rows(mysql_query($query_group,$db));
			
			//Wenn er Gruppenmitglied ist, return = 1
			if($check_group == 0) {
				if($return != 1) {
					//Nur wenn er noch nicht 1 ist
					//auf 0 setzen
					$return = 0;
					$echo .= "<b>$myrow_access[2]</b><br>\n";
				}
			} else {
				$return = 1;
			}
		}
	}
	if($error == TRUE AND $return == 0) {
		$echo .= "<br>\n".$GLOBALS["GENERAL"]["ACCESS_NOTICE"]." <a href=\"?site=login&page=users&group=board\">board</a>.<br>\n";
		echo $echo;
	}
	return $return;
};

/**
 * myLANsite function
 * Name:	MLS_core_lang
 * Purpose:	includes the langfile for a given site/page
 *
 * @param string $folder /folder name
 * @param string $file /file name
 * @param string $subfolder /subfolder name
 * @return boolean
 */
 function MLS_core_lang($folder,$file,$subfolder = "") {
 	//first, I'm trying to include the user-choosen language-file
 	if($subfolder) {
 		$path_user = $GLOBALS["INCLUDE_BASE"]."lang/".$_COOKIE["cookie_lang"]."/".$folder."/".$subfolder."/lang_".$file.".php";
 		$path_default = $GLOBALS["INCLUDE_BASE"]."lang/".MLS_core_check_config("website_lang")."/".$folder."/".$subfolder."/lang_".$file.".php";
 	} else {
 		$path_user = $GLOBALS["INCLUDE_BASE"]."lang/".$_COOKIE["cookie_lang"]."/".$folder."/lang_".$file.".php";
 		$path_default = $GLOBALS["INCLUDE_BASE"]."lang/".MLS_core_check_config("website_lang")."/".$folder."/lang_".$file.".php";
	}
	
	if(@include($path_user)) {
 		return TRUE;
 	} elseif(@include($path_default)) {
 		return TRUE;
 	} else {
 		MLS_core_show_error("Languagefile not found!<br>Folder: ".$folder."<br>Subfolder: ".$subfolder."<br>File: ".$file);
 		return FALSE;
 	}
 };
 
?>
Return current item: MyLANsite - lanparty organisation