<?php
ini_set('session.cookie_domain', '.wowdoyou.com');
session_start();
require 'includes/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '132880206758943',
  'secret' => '16d42b51af2920ff3c03f9dbf7c0d5e2',
  'cookie' => true,
));


$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $me = $facebook->api('/me');

   //get the request ids from the query parameter
   $request_ids = explode(',', $_REQUEST['request_ids']);
	$requestData = $facebook->api($_REQUEST['request_ids'],'GET');
	$_SESSION['ref_id'] = $requestData['data'];

   //build the full_request_id from request_id and user_id 
   function build_full_request_id($request_id, $user) {
      return $request_id . '_' . $user; 
   }

   //for each request_id, build the full_request_id and delete request  
   foreach ($request_ids as $request_id)
   {
//      echo ("reqeust_id=".$request_id."<br>");
      $full_request_id = build_full_request_id($request_id, $user);  
//      echo ("full_reqeust_id=".$full_request_id."<br>");
  
      try {
			$delete_success = $facebook->api("/$full_request_id",'DELETE');
         if ($delete_success) {
//            echo "Successfully deleted " . $full_request_id;
         }else {
//           echo "Delete failed".$full_request_id;
			}
        }          
      catch (FacebookApiException $e) {
      //echo "error";
		}
    }
  } catch (FacebookApiException $e) {
    error_log($e);
    $me = null;
  }
}

?>
<script language="javascript">

function Validate_FrmLogin() {
   if (document.FrmLogin.WUsername.value.length < 5)
   {
     alert("Username limit to 5 characters and above.");
     document.FrmLogin.WUsername.focus();
     return (false);
   }

   if (document.FrmLogin.WUsername.value.length > 50)
   {
     alert("Username limit to 50 characters and below.");
  	 document.FrmLogin.WUsername.focus();
     return (false);
   }

   if ((document.FrmLogin.WPassword.value.length < 6) || (document.FrmLogin.WPassword.value.length > 20))
   {
     alert("Password limit between 6-20 characters.");
     document.FrmLogin.WPassword.focus();
     return (false);
   }
   return (true);
 }
</script>

<table width="241" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td width="14" valign="bottom"><img src="images/box_01.gif" width="14" height="15" /></td>
		<td width="212" valign="bottom" style="background-image:url(images/box_02.gif); background-repeat:repeat-x; background-position:bottom">&nbsp;</td>
		<td width="15" valign="bottom"><img src="images/box_04.gif" width="15" height="15" /></td>
	</tr>
	<tr>
		<td style="background-image:url(images/box_05.gif); background-repeat:repeat-y">&nbsp;</td>
		<td class="white_back"><form action="complete_login.php" method="post" name="FrmLogin" target="_self" id="FrmLogin" style="margin:0px; padding:0px" onsubmit="return Validate_FrmLogin()">
				<table width="100%" border="0" cellpadding="5" cellspacing="0" class="white_back">
					<tr>
						<td colspan="2" align="left" class="purple_14">Anyone can join !
							<input name="Button" type="button" id="submit" value="Sign Up" onclick="location.href='register1.php'" /></td>
					</tr>
					<tr>
						<td width="10%" align="center">Username&nbsp;:</td>
						<td width="90%"><input type="text" name="WUsername" tabindex="1" style="font-size:11px; width:120px" value="<?=$HTTP_COOKIE_VARS[WUsername_c]?>" /></td>
					</tr>
					<tr>
						<td valign="baseline">Password&nbsp;:</td>
						<td class="grey_10"><input name="WPassword" type="password" tabindex="2" size="15" style="font-size:11px; width:120px" />
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
								<tr>
									<td class="grey_12"><input name="save" id="save" type="checkbox" value="save"<?php if(isset($HTTP_COOKIE_VARS[WUsername_c])) echo ' checked' ?> />
										<label for="save" id="label_save">Remember Me</label>
									</td>
									<td align="right"><input name="submit" type="submit" id="submit" value="Login" /></td>
								</tr>
							</table></td>
					</tr>
					<tr>
						<td colspan="2" align="center" class="red_12"><a href="reset.php" target="_self">Forgotten your password?</a></td>
					</tr>
					<tr align="center">
						<td colspan="2">
							<fb:login-button scope="email,offline_access,user_birthday" onclick="loding_box();">Facebook Login</fb:login-button>
							<br />
							<span id="loading_box"></span></td>
					</tr>
				</table>
			</form></td>
		<td style="background-image:url(images/box_07.gif); background-repeat:repeat-y">&nbsp;</td>
	</tr>
	<tr>
		<td valign="top"><img src="images/box_10.gif" width="14" height="12" /></td>
		<td valign="top" style="background-image:url(images/box_11.gif); background-repeat:repeat-x; background-position:top">&nbsp;</td>
		<td valign="top"><img src="images/box_13.gif" width="15" height="12" /></td>
	</tr>
</table>
<div id="fb-root"></div>
<script>
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '<?php echo $facebook->getAppId(); ?>',
          status : true, // check login status
			 cookie: true,
          xfbml: true,
          oauth: true
        });
			
        // whenever the user logs in, we refresh the page
        FB.Event.subscribe('auth.login', function() {
		  		document.getElementById("loading_box").innerHTML = " ";
				window.location.reload();
        });
 
        FB.getLoginStatus(function(response) {
	  			if (response.status=="connected") {
					window.location.href = '<?=$CONST_LINK_ROOT?>/complete_login.php';
	  			}
			});

        // whenever the user logs out, we refresh the page
        FB.Event.subscribe('auth.logout', function() {
//				window.location.reload();
        });

      };

      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
		  
      }());
		
		function loding_box () {
		  document.getElementById("loading_box").innerHTML = "<font color=\"green\">Please wait...</font>";
			setTimeout(function() { document.getElementById("loading_box").innerHTML = "" }, 2000);
		}
    </script>
