<?php
include("includes/site_info.php");
include('session_handler.inc');

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];

$invite_query=mysql_query("SELECT *, DATE_FORMAT(date, '%M %d, %Y at %h:%i%p') as date FROM networkinvite WHERE User_id = '$WUserID'") or die(mysql_error());
$invite_TOTAL = mysql_num_rows($invite_query);

?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"><table width="100%" border="0" cellpadding="3" cellspacing="0" class="white_back_t_xb">
				<tr class="grey_12 orange_row_back solid_line_separator">
					<td> Member Status Report </td>
				</tr>
				<tr>
					<td><table width="100%" border="0" cellpadding="5" cellspacing="0" class="white_back_t_xb p5">
							<tr>
								<td valign="top" width="100%"><div id="msg_content" style="display:none"></div>
									<div id="sub_content">
										<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="white_back_t_xb p5">
											<tr>
												<td><div class="light_orang_h">
														<div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10"></div>
														Invitations History</div>
													<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
													<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
											</tr>
											<tr>
												<td><table width="100%" border="0" cellpadding="5" cellspacing="1" id="structureTable">
														<tr>
															<th width="25%">Email</th>
															<th width="15%">Date</th>
															<th width="40%">Status</th>
															<th width="10%">Action</th>
														</tr>
														<?php if ($invite_TOTAL > 0) { 
							 while ($invite = mysql_fetch_object($invite_query)) {
							 $query = "SELECT mem_userid FROM members WHERE mem_email='$invite->Email'";
							 $updateTOTAL = mysql_num_rows(mysql_query($query));
							 if ($updateTOTAL > 0) {
							 $update = mysql_fetch_object(mysql_query($query));
							 $query2 = "SELECT approved FROM my_friends WHERE uid='$WUserID' AND friend_uid='$update->mem_userid'";
//							 echo $query2;
							 $result = mysql_num_rows(mysql_query($query2));
							 if ($result > 0) {
							 $sql_array = mysql_fetch_object(mysql_query($query2));
							 if ($sql_array->approved == 0) {
							 $upd=mysql_query("UPDATE networkinvite set stat='i' where Email='$invite->Email' and inv_id='$invite->inv_id'");
							 $invite->stat = 'i';
							 }
							 if ($sql_array->approved == 1) {
							 $upd=mysql_query("UPDATE networkinvite set stat='f' where Email='$invite->Email' and inv_id='$invite->inv_id'");
							 $invite->stat = 'f';
							 }
							 } else {
							 $upd=mysql_query("UPDATE networkinvite set stat='j' where Email='$invite->Email' and inv_id='$invite->inv_id'");
							 $invite->stat = 'j';
							 }
							 }
							 ?>
														<tr id="<?=$invite->inv_id?>">
															<td valign="baseline" nowrap="nowrap"><?=$invite->Email?></td>
															<td valign="baseline" nowrap="nowrap"><?=$invite->date?></td>
															<td valign="baseline"><?php
									switch($invite->stat){

		case 'p':
			echo "Pending";
			break;

		case 'j':
			echo "User joined the site";
			break;

		case 'i':
			echo "User is already an existing site member. Your invitation was sent.";
			break;

		case 'f':
			echo "Member is your hahaper now.";
			break;

		case 'd':
			echo "Your invitation was declined by this user.";
			break;

	}//switch							 

								?></td>
															<td valign="baseline" nowrap="nowrap"><?php
															if ($invite->stat=="p") {
															echo "<a href=\"javascript: void(null)\" onclick=\"javascript: jQuery.facebox({ajax:'$CONST_LINK_ROOT/prop-me.php?mode=resend&inv_id=$invite->inv_id'}, 'Resend Invitation'); return false;\" rel=\"facebox\">resend</a> | ";
															}
															echo "<a href=\"javascript: void(null)\" onclick=\"javascript: jQuery.facebox({ajax:'$CONST_LINK_ROOT/prop-me.php?mode=delete&inv_id=$invite->inv_id'}, 'Delete Invitation'); return false;\" rel=\"facebox\">delete</a>";
															?></td>
														</tr>
														<?php } } else {?>
														<tr>
															<td colspan="4">No invitations were sent.</td>
														</tr>
														<?php } ?>
													</table></td>
											</tr>
											<tr>
												<td>&nbsp;</td>
											</tr>
										</table>
									</div></td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
			</table></td>
	</tr>
</table>
