<?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 services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("classes/misc.class.php");
require_once ("classes/userside.class.php");
require_once ("includes/Pager/Pager.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/timespamp.php");
$ds = new FuzzyTime();
$message	= "";
$data		= array();
$array		= array();
$script		= "";
$pages		= "";
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$type		= isset($_REQUEST['type'])	?	trim($_REQUEST['type'])	:	"__";

$stamsg		= "";
if ($type == "RN")	$stamsg	= "read";
else if ($type == "DN")	$stamsg	= "declined";
else if ($type == "NN")	$stamsg	= "unread";

if (!$objDB) {
    $message	= "Unable to Locate Database Server.";
} else {
    $objU	= new userside($objDB);
    $objM	= new misc($objDB);
    if (isset($_POST['MAR'])) {
        $message	= $objM->mark_as_read_message($_POST);
    }
    if (isset($_POST['DM'])) {
        $message	= $objU->delete_messages($_POST);
    }
    $array		= $objM->get_messages($type, $_SESSION['user_id'], true);

    $params 	= array(
            'mode'      => 'Sliding',
            'perPage'   => PAGESIZE,
            'urlVar'    => 'page',
            'extraVars' => array('type'=>$type,'tab'=>'recieved'),
            'itemData'  => $array
    );
    $objP 		= & Pager::factory($params);
    $data  		= $objP->getPageData(); 
    $pages		= $objP->links;
    if (empty($data))
        $message	.= "No $stamsg message(s) in your inbox folder.<br>";
    $script		= $objU->get_script($message);
    $message	= $objU->remove_script($message);
    
    
    
     
	$array1		= $objM->get_messages($type, $_SESSION['user_id'], false);
	$params1 	= array(
		'mode'      => 'Sliding',
		'perPage'   => PAGESIZE,
		'urlVar'    => 'page',
		'extraVars' => array('type'=>$type,'tab'=>'sent'),
		'itemData'  => $array1
	);
	$objP 		= & Pager::factory($params1);
	$data1  		= $objP->getPageData();
	$pages1		= $objP->links;
	if (empty($data))
		$message1	.= "No $stamsg message(s) in your sent folder.<br>";
	$script1		= $objU->get_script($message1);
	$message1	= $objU->remove_script($message1);
    
    
    
}
//if($_GET['page'])
//$pagess = $_GET['page']-1;
//else
//$pagess = 0;    
//if($pagess)
//{
//    $stb = $pagess*PAGESIZE;
//}else{
//    $stb = 0;
//}

//echo 'Fuz : <pre>'; print_r($ds->getFuzzyTime($data[0]['dDate'])); echo '</pre>';

//updateing mail status as read
if(is_array($data)) {
foreach ($data as $k2=>$v2){
        //update tbl_message
        echo $data[$i][0].'<br>';
        mysql_query("UPDATE ".TABLEPREFIX."message SET vStatus = 'RN' WHERE nMessage_Id IN ('".$v2[0]."')") or die(mysql_error());
    }//end if
}//end if

include_once ("title.inc.php");
include_once ("tophtml.inc.php");
?>

<link rel="stylesheet" href="styles/jquery-ui.css">
<script src="js/jquery-ui-1.11.0.js"></script>
 <script language="javascript" type="text/javascript">
     var index         = '<?php echo ($_REQUEST['tab']=='sent')?1:0; ?>';

$(document).ready(function() {
    
$( "#tabs" ).tabs({ active: index });

});

</script>
<script language="javascript" type="text/javascript">
    function confirm_check()
    {
        var where_to= confirm("Do you really want to delete these messages for permenantly??");
        if (where_to== true)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
</script>
<!--<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>-->
<div class="row">
    
    
	<div class="eight columns" id="tabs">
            
            <ul>
<li><a href="#tabs-1">Received Messages</a></li>
<li><a href="#tabs-2">Send Messages</a></li>

</ul>
            
		<div class="search-rslts">
<!--			<div class="row"><div class="inenr-hd"><h2>Received Messages</h2></div></div>-->
			<div class="row" id="tabs-1">
				
					<div class="newdesignforinput maintext1">
						<?php if(isset($message) && trim($message)!='') {
                        ?>
						<div class="full_row">
							<div class="maintext1 warning"><?php echo $message;?></div>
						</div>
						<?php }//end if?>
											
						<form name="frmTell" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
                                                    
                                                    
                                                    <input name="form_type" type="hidden" value="recieved">
							<?php if (!empty($data)) {
							foreach ($data as $key => $value) { ?>
							
							<div class="full_row search-rslts-row">
								<div class="three columns">
									<a href="profile.php?id=<?php echo $value['nUser_Id']?>">
										<img src="<?php echo $objU->get_pimage_url(PROFILE_IMAGE_URL, $value['nPhoto_Id'], $value['vGender']);?>" width="165" height="125" title="<?php echo $value['vLogin']?>" alt="<?php echo $value['vLogin']?>" border="0">
									</a>
								</div>
								<!-- <tr>
								<td align="right" class="profilenumber"><table width="100%"  border="0" cellspacing="0" cellpadding="3">
								<tr>
								<td align="right"><?php echo $value['nUser_Id']?></td>
								</tr>
								</table></td>
								</tr>-->
								<div class="nine columns">
								<div class="profile_L eight columns">
									<div class="one columns"><input type="checkbox" name="ids[]" value="<?php echo $value['nMessage_Id']?>"></div>
									<div class="eight columns profile-name">
									
										From : <?php echo $value['vLogin']?>&nbsp;&nbsp;
										<a href="send_message.php?id=<?php echo $value['nUser_Id']?>&msgid=<?php echo $value['nMessage_Id']?>&page=<?php echo $page?>&type=<?php echo $type?>" class="replybutton" style="text-decoration: none;">
											Reply
										</a>
									</div>
									<div class="three columns right">
										<div class="twelve">
											<div class="seven columns"><?php echo $objU->get_bgcheck_image($value['nUser_Id'])?></div>
										</div>
									</div>
									<div class="clear"></div>
									<div class="twelve">
										
										<div class="eleven  columns gray_normal_txt">Received on:&nbsp;<strong><?php echo $ds->getFuzzyTime($value['dDate'])?></strong></div>
									</div>
									<!--<div class="full_row maintext1"><strong><?php// echo $value['dDay']?></strong></div>-->
									<div class="full_row gray_normal_txt">
										<?php echo $value['vAge']?>-year-old <?php echo $value['vGender']?> &nbsp;&nbsp;
										Height : <?php echo $value['nHeight'] <> "" ? $objU->get_height($value['nHeight']) : "--"?><br>
										<?php echo ($value['vCounty']!='')?$value['vCounty'].",":"";?>
										<?php echo ($value['vState']!='')?$value['vState'].",":"";?>
										<?php echo $value['vCountry']?>
									</div>
									
									<div class="clear"></div>
									<div class="full_row gray_normal_txt"><b>Message Details</b></div>
										<div class="full_row gray_normal_txt">
											<strong>Title: <?php echo $value['vTitle']?></strong><br>
											<?php echo nl2br(htmlspecialchars(stripslashes($value['tContent'])))?>
										</div>
										<div class="clear"></div>
									<div class="view-pro-row"><a href="profile.php?id=<?php echo $value['nUser_Id']?>" class="view-pro-btn" title="View Full Profile">View Profile</a></div>
									
								</div>
								<div class="profile_R four columns">
									<div class="twelve columns featured_icon"><?php echo $objU->get_featured_image($value['nUser_Id'])?></div>
									<div class="twelve">
										<?php if(isset($_SESSION['user_id']) && $_SESSION['user_id']!='') {
                                        ?>
										<div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&EI=yes" class="express-interest-btn" title="Express Interest">Express Interest</a></div>
										<div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&SM=yes" class="send-mail-btn" title="Send An Email">Send An Email</a></div>
										<!--<div class="full_row icon_txt"><a title="Add as favourite" href="profile.php?id=<?php echo $value['nUser_Id']?>&AF=yes"><img src="images/addasfav.gif" alt="Add to favourite list" width="23" height="22" border="0" title="Add to favourite list"></a></div>-->
										<div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&AH=yes" class="hotlist-btn" title="Add To Hot List">Add To Hot List</a></div>
										<div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&ATF=yes" class="im-btn" title="Add To IM List">Add To IM List</a></div>
										<?php }//end if?>
										
									</div>
									</div>
									
									<div class="clear"></div>
									
								</div>
								
								<div class="clear"></div>
							</div>
							<?php }//end foreach
							}//end if
							if (!empty($data)) {
							?>
												
							<div class="full_row">
								<div class="twelve">
									<input name="DM" type="submit" class="loginbutton" id="DM" value="Delete Message(s)" onClick="return confirm_check();">
									<?php if ($type <> "RN") { ?>
									<input type="hidden" name="page" value="<?php echo $page?>">
									<?php }//end if?><input type="hidden" name="type" value="<?php echo $type?>">
								</div>
							</div>
							<?php }//end if
							if ($pages <> "") {
							?>
							
							<div class="full_row pagenation"><?php echo $pages?></div>
												
							<?php } ?>
						</form>
					</div>
			</div>
      <div class="search-rslts" id="tabs-2">
			<div class="row">
				<div class="newdesignforinput maintext1">
					<?php if(isset($message1) && trim($message1)!='')
					  {
					?>
					<div class="full_row">
						<div class="maintext1 warning"><?php echo $message1;?></div>
					</div>
					<?php }//end if?>
					
					<form name="frmTell" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
                                            
                                             <input name="form_type" type="hidden" value="sent">
						<?php if (!empty($data1)) 
					   { 
					  		foreach ($data1 as $key => $value) 
							{ 
						?>
						<div class="full_row search-rslts-row">
							<div class="three columns">
								<a href="profile.php?id=<?php echo $value['nUser_Id']?>">
									<img src="<?php echo $objU->get_pimage_url(PROFILE_IMAGE_URL, $value['nPhoto_Id'], $value['vGender']);?>" width="165" height="125" title="<?php echo $value['vLogin']?>" alt="<?php echo $value['vLogin']?>" border="0">
								</a>
							</div>
							<!--<tr>
							<td align="right" class="profilenumber"><table width="100%"  border="0" cellspacing="0" cellpadding="3">
							<tr>
							<td align="right"><?php echo $value['nUser_Id']?></td>
							</tr>
							</table></td>
							</tr>-->
							<div class="nine columns">
								<div class="profile_L eight columns">
									<div class="full_row">
										<!--<div class="one columns"><input type="checkbox" name="ids[]" value="<?php echo $value['nMessage_Id']?>"></div>-->
										<div class="nine columns profile-name">To : <?php echo $value['vLogin']?> </div>
										<div class="three columns right">
											<div class="twelve">
												<div class="seven columns"><?php echo $objU->get_bgcheck_image($value['nUser_Id'])?></div>
											</div>
										</div>
										<div class="clear"></div>
									</div>
									<div class="clear"></div>
									<div class="twelve"> 
										<div class="ten columns gray_normal_txt">Sent on:&nbsp;<?php echo $ds->getFuzzyTime($value['dDate'])?></div>
									</div>
									<!--<div class="full_row maintext1"><strong><?php// echo $value['dDay']?></strong></div>-->
									<div class="full_row gray_normal_txt">
										<?php echo $value['vAge']?>-year-old <?php echo $value['vGender']?> &nbsp;&nbsp;
										Height : <?php echo $value['nHeight'] <> "" ? $objU->get_height($value['nHeight']) : "--"?><br>
										<?php echo ($value['vCounty']!='')?$value['vCounty'].",":"";?>
										<?php echo ($value['vState']!='')?$value['vState'].",":"";?>
										<?php echo $value['vCountry']?>
									</div>
								
									<div class="clear"></div>
									<div class="full_row gray_normal_txt"><b>Message Details</b></div>
									<div class="full_row gray_normal_txt">
										Title: <?php echo $value['vTitle']?><br>
										<?php echo nl2br(htmlspecialchars(stripslashes($value['tContent'])))?>
									</div>
									<div class="columns"><div class="view-pro-row"><a href="profile.php?id=<?php echo $value['nUser_Id']?>" class="view-pro-btn" title="View Full Profile">View Profile</a></div></div>
								</div>
								<div class="profile_R four columns">
									<div class="full_row profile_list_bottom_butn">
									<div class="twelve columns featured_icon"><?php echo $objU->get_featured_image($value['nUser_Id'])?></div>
									<?php if(isset($_SESSION['user_id']) && $_SESSION['user_id']!='')
										  {
									?>
									
									<div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&EI=yes" class="express-interest-btn" title="Express Interest">Express Interest</a></div>
                                      <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&SM=yes" class="send-mail-btn" title="Send An Email">Send An Email</a></div>
                                  <!--<div class="full_row icon_txt"><a title="Add as favourite" href="profile.php?id=<?php echo $value['nUser_Id']?>&AF=yes"><img src="images/addasfav.gif" alt="Add to favourite list" width="23" height="22" border="0" title="Add to favourite list"></a></td>-->
                                      <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&AH=yes" class="hotlist-btn" title="Add To Hot List">Add To Hot List</a></div>
                                      <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&ATF=yes" class="im-btn" title="Add To IM List">Add To IM List</a></div>
									 <?php }//end if?>
                                      
									  
								</div>
								</div>
								
								
													
								
							</div>
							
							<div class="clear"></div>
						</div>
						<?php }//end foreach
							}//end if
						   if ($pages1 <> "") 
						   {
					   	?>
						
						<div class="full_row"><?php echo $pages1?></div>

											
						<?php } ?>
					</form>
				</div>
			</div>
		</div>



		</div>
	</div>
	<div class="four columns right search_result_R"><?php include_once ("left.inc.php");?></div>
</div>

<?php include_once('bottomhtml.inc.php');?>
