<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #
##################################################################
#               Developed On:   03-04-2008                       #
##################################################################
#  				Modified By:        	                         #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet ervices such #
# as webdesign etc.                                              #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");

if (!isset($_SESSION['userlogged']) OR $_SESSION['userlogged'] <> "YES") {
	header("Location: chatboxlogin.php");
	exit;
}
/*if (!in_array(basename($_SERVER['PHP_SELF']), $arrUserAllowedPages)) {
	if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false) {
		header("Location: chatboxlogout.php");
		exit;
	}
}*/
require_once ("classes/userside.class.php");
require_once ("classes/misc.class.php");

$message	= "";
$chatmsg	= "";
$arrTo		= array();
$arrFrom	= array();
$arrSmilies	= array();
$window		= isset($_REQUEST['window'])?	trim($_REQUEST['window'])				:	"";
$fid		= isset($_REQUEST['fid'])	?	stripslashes(trim($_REQUEST['fid']))	:	"0";
$comment	= isset($_POST['comment'])	?	stripslashes(trim($_POST['comment']))	:	"";

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objU		= new userside($objDB);
	$objM		= new misc($objDB);
        $objM->checkPremiumPermission();
	if ($window == "new") {
		$_SESSION['timeof']	= $objM->get_chat_timeof($_SESSION['user_id']);
	}
	if (!isset($_SESSION['timeof']) OR $_SESSION['timeof'] == "") {
		$_SESSION['timeof']	= date("YmdHis");
	}

	if (isset($_POST['SAY']) || isset($_POST['comment'])) {
		$message	= $objM->save_chat($_SESSION['user_id'], $fid, $comment);
                
	}
	$chatmsg	= $objM->get_chat_data($_SESSION['user_id'], $fid, $_SESSION['timeof']);
	$arrTo		= $objU->getuser(addslashes($fid));
	$arrFrom	= $objU->getuser($_SESSION['user_id']);
	$arrSmilies	= $objM->get_smilies();
	if ($message <> "")
		$chatmsg	.= $message;
}

include_once ("title_chat_box.inc.php");
?>
<style>
.popupLink { COLOR: red; outline: none }
.popup { POSITION: absolute; VISIBILITY: hidden; BACKGROUND-COLOR:#FFF; LAYER-BACKGROUND-COLOR: yellow; width:300px; BORDER-LEFT: 1px solid black; BORDER-TOP: 1px solid black; BORDER-BOTTOM: 3px solid black; BORDER-RIGHT: 3px solid black; PADDING: 3px; z-index:1010 }
</style>
<script src="js/boxover.js"></script>
<script src="js/utility.js"></script>
<script src="js/popup.js"></script>
<script type="text/javascript" src="js/jquery.nicescroll.js"></script>
<SCRIPT type="text/javascript">
  $(document).ready(function() { 
    
    
    $('#chatbox').niceScroll({cursorcolor:"#9fa2aa",cursoropacitymax:0.7,touchbehavior:false,oneaxismousemode:false});
    
  });
   function closeAllchildren()
{      
    
    
	
} 
 
  function getit_ascii(code) { 
		document.frmChat.comment.value = document.frmChat.comment.value + code;
		//hideCurrentPopup();
   }
</SCRIPT>
<script language="javascript">

function moveToBottom()
{ 
	if (document.getElementById('chatbox') != null) {
		document.getElementById('chatbox').scrollTop = document.getElementById('chatbox').scrollHeight;
	}
}

function passPress(d)
{
	if(d=="13")
	{            
           document.frmChat.submit();  
          // $("#comment").val('');
	}//end if
}//end function
</script>
		

<div class="row">
	<div class="eight columns">
		<div class="search-rslts">
			<div class="row"><div class="inenr-hd"><h2>Chat</h2></div></div>
			<div class="row">
					<div class="newdesignforinput maintext1">
						<div class="full_row">
							<div class="twelve columns">
								<div onclick='event.cancelBubble = true;' class='maintext7 popup' id='nameFieldPopup' style="overflow:auto;">
									<a class=closeLink href='#' onclick='hideCurrentPopup(); return false;'><img src="images/closewindow.jpg" border="0"></a> &nbsp;
									<?php if (!empty($arrSmilies)) {
									foreach ($arrSmilies as $key => $value) {?>
									<a href=javascript:getit_ascii('<?php echo htmlentities($value['code'])?>')><img src="smilies/<?php echo $value['smile_url']?>" title="<?php echo $value['emoticon']?>" alt="<?php echo $value['emoticon']?>" border="0" hspace="4" vspace="4")></a>
									<?php }
									}?>
									&nbsp;<a class=closeLink href='#' onclick='hideCurrentPopup(); return false;'><img src="images/closewindow.jpg" border="0"></a>
								</div>
							</div>
						</div>
						<form name="frmChat" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
						<div align="justify" id="moreSpan"> </div>
						<div class="full_row">
							<div class="full_row">
								<div class="twelve columns">
									<?php if (!empty($arrTo)) {?><?php if($arrTo['vOnline'] == "Online") { ?>
									<img src="images/chatonline.gif" width="12" height="12">
									<?php } elseif ($arrTo['vOnline'] == "Busy") { ?>
									<img src="images/chatbusy.gif" width="12" height="12">
									<?php } else { ?>
									<img src="images/chatoffline.gif" width="12" height="12">
									<?php } ?>&nbsp;&nbsp;<span title="header=[<img  style='vertical-align:middle' src='images/info.gif' width='20px' height='20px' border='0'>&nbsp;&nbsp;<?php echo $arrTo['vLogin']?> (<?php echo $arrTo['vOnline']?>)] body=[<?php echo $arrTo['vFirstName']?> <?php echo $arrTo['vMiddleName']?> <?php echo $arrTo['vLastName']?>, <?php echo $arrTo['Age']?> year old <?php echo $arrTo['vGender']?>]"><?php echo $arrTo['vLogin']?>
									</span> <?php } ?>
								</div>
							</div>
							<div class="full_row">
								<div class="twelve columns">
									<div style="overflow-y:auto; height:330px; width:100%; background-color:#FFFFFF; border:1px solid #FFFFFF; margin:4px 0 4px 0;" id="chatbox"> 
                                      <div align="justify" id="moreSpanss"><span class="maintext" id="chatmaintxt"><?php echo $chatmsg?></span></div>
                                    </div>
								</div>
							</div>
							<div class="full_row">
								<div class="twelve columns">
									<?php if (!empty($arrFrom)) { ?>
                              <?php if($arrFrom['vOnline'] == "Online") { ?>
                              <img src="images/chatonline.gif" width="12" height="12">
                              <?php } elseif ($arrFrom['vOnline'] == "Busy") { ?>
                              <img src="images/chatbusy.gif" width="12" height="12">
                              <?php } else { ?>
                              <img src="images/chatoffline.gif" width="12" height="12">
                              <?php } ?>
                              <span title="header=[<img  style='vertical-align:middle' src='images/info.gif' width='20px' height='20px' border='0'>&nbsp;&nbsp;<?php echo $arrFrom['vLogin']?>] body=[<?php echo $arrFrom['vFirstName']?> <?php echo $arrFrom['vMiddleName']?> <?php echo $arrFrom['vLastName']?>, <?php echo $arrFrom['Age']?> year old <?php echo $arrFrom['vGender']?>]">
                              <?php echo $arrFrom['vLogin']?>
                              </span>
                              <?php } ?>
								</div>
							</div>
							
							<div class="full_row">
								  <?php if (!empty($arrTo) AND !empty($arrFrom)) { ?>
                                      <div class="full_row">
                                        
                                        <div class="full_row chat_feild_outer"><textarea name="comment" id="comment" cols="26" rows="2" class="textbox_textarea" onKeyPress="javascript:passPress(event.keyCode);" style="width:95%; resize: none; height:20px; "></textarea>
                                          <span title="header=[<?php echo $arrTo['vLogin']?> (<?php echo $arrTo['vOnline']?>)] body=[<?php echo $arrTo['vFirstName']?> <?php echo $arrTo['vMiddleName']?> <?php echo $arrTo['vLastName']?>, <?php echo $arrTo['Age']?> year old <?php echo $arrTo['vGender']?>]">
                                          <input type="hidden" name="fid" value="<?php echo $fid?>">
                                        </span>
											<div class="chat_smile_outer">
												<!--<a href="#" class=popupLink onclick="return !showPopup('nameFieldPopup', event);">EDIT</a>-->
												<img src="images/icon_smile.png" width="15" height="15" title="Emotions" alt="Emotions" onClick="return !showPopup('nameFieldPopup', event);" >
											</div>
										</div>
                                        <!--<div class="three columns" scope="col"><input name="SAY" type="submit" class="send-btn" value="Send">
                                        <span title="header=[<?php echo $arrTo['vLogin']?> (<?php echo $arrTo['vOnline']?>)] body=[<?php echo $arrTo['vFirstName']?> <?php echo $arrTo['vMiddleName']?> <?php echo $arrTo['vLastName']?>, <?php echo $arrTo['Age']?> year old <?php echo $arrTo['vGender']?>]"> </span>
										</div>-->
                                      </div>
					  <?php } ?>
							</div>
							
						</div>
						</form>
					</div>
			</div>
		</div>
	</div>
</div>



<script language="javascript">
document.getElementById('comment').focus();
</script>
<?php //include_once('chat_bottomhtml.inc.php');?>
