<?php
/************************************************************************
	UebiMiau is a GPL'ed software developed by 
	 - Aldoir Ventura - aldoir@users.sourceforge.net
	 - http://uebimiau.sourceforge.net SåÐ Paulo - Brasil
   		
	***********************************************************************
	Version 3.2.0 Upgrades and templates developed by
	 - Todd Henderson - Lead Developer - http://tdah.us 
	 - Dave Rodgers - Developer - http://www.manvel.net 
	 - Laurent (AdNovea) - Developer - http://adnovea.free.fr
	 
	***********************************************************************
	 - Special thanks to the developers at 
	codeworxtech.com, tinymce.moxiecode.com
	telaen.org, phptoys.com, winged.info, ngcoders.com
	without help this project wouldn't be possible 
	
	***********************************************************************
	- File:			logoutchat.php
	- Developer: 	Todd Henderson / Mods by Laurent (AdNovea)
	- Date:			November 4, 2008
	- version:		(3.2.0) 1.0
	- Description:  Exit the chat room

*************************************************************************/

 
	require_once('./inc/inc.php');
	require(PATH_LANGS."/$chat_language.php");
	$chat_data_file	= DB_CHAT_DATA;
  $chat_online_file	= DB_CHAT_ONLINE;
  $chat_upload_dir = DB_CHAT_UPLOAD;
	$nick = ($_SESSION['nickname']);
	$lid = $_GET['lid'];


	define("__BACK__","<br><br><input class='button' type='button' onclick=\"javascript:window.location.href='./startchat.php?lid=$lid&tid=$tid'\" value='".CHAT_BACK."'></center>");

	$date = date($chat_date_format);
	$line = "<p><span class=\"main\">$nick</span> <span class=\"logout\">".CHAT_LEFT."</span><span class=\"date\"> - $date</span></p>";
	$file = fopen($temporary_directory.DB_CHAT_DATA, 'a+');
	fwrite($file, $line);
	fclose($file);


// End the session (remove user from the users list)
	if (file_exists($temporary_directory.DB_CHAT_ONLINE)) {
		$f_text = file($temporary_directory.DB_CHAT_ONLINE);
		$file_handle = fopen($temporary_directory.DB_CHAT_ONLINE,"w");
		foreach( $f_text as $line ) {
			 if ( !strstr($line, $nick) )
				   fputs($file_handle, $line);
		}
		fclose($file_handle);
	}
	unset($_SESSION['nickname']);
	require_once('./inc/inc.php');
setlocale(LC_ALL, $languages[$lid]['locale']);

	header("Cache-control: private");
	echo "
		<link rel='stylesheet' type='text/css' href='./themes/$selected_theme/$chat_default_theme'>
		<script type='text/javascript'>
			<!--
			function delayer(){
				parent.document.location.href = './messages.php?lid=$lid&tid=$tid';	// Reload all to update the number of chat users
				//document.location = './startchat.php?lid=$lid&tid=$tid';
			}
			//-->
		</script>
	
	<body onLoad=\"setTimeout('delayer()', 0)\">
	";	
	echo "<br><center><b>$nick</b> ".CHAT_LOGOUT.__BACK__;

?>
