<?php
$sumfingIncl=true;
if(file_exists('../config.thing.php')) {
	require '../fb/facebook.php';
	require '../config.thing.php';
	// Get data
	$set = get_adm_opts();
	include '../incl/translate.php';
} else {
	die("Access denied");
}
	//set your timezone
	date_default_timezone_set($set->timezone);
	
	// Check for url parameters
	$datavar = '';
	if(isset($_GET['app_data'])) {
		$datavar = $_GET['app_data'];	
	}
	if(isset($_GET['request_ids'])) {
		$datavar = $_GET['request_ids'];	
	}
	
	// Detect raffle status, NOT STARTED, ON, OVER
	$status = '';
	// If TIMER
	if($set->select_counter == 'time') {
		$timestatus = true;
		$likestatus = false;
		if(strtotime($set->ends) < time()) {
			$status = 'OVER';
		}
	}
	
	// If LIKES
	if($set->select_counter == 'like') {
		$timestatus = false;
		$likestatus = true;
		if(isset($set->end_likes) && ($set->end_likes <= $pagelikes)) {
			$status = 'OVER';
		}
	}
	
	$description = nl2br($set->mob_page_description);
	$description = str_replace('[TICKETAMOUNT]',$set->mob_page_tickets,$description);
	
	$description = str_replace('[ENDTIME]',$set->ends,$description);
	
	$description = nl2br($description);
	
	
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $set->title;?></title>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen">
<!-- Javascripts -->
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>

<!-- Load the Facebook JavaScript SDK -->
    <div id="fb-root"></div>
    <script src="//connect.facebook.net/en_US/all.js"></script>

    <script type="text/javascript">

      // Initialize the Facebook JavaScript SDK
      FB.init({
        appId: '<?php echo FB_APPID;?>',
        xfbml: true,
        status: true,
        cookie: true,
      });

      // Check if the current user is logged in and has authorized the app
      FB.getLoginStatus(checkLoginStatus);
	  
	  

      // Login in the current user via Facebook and ask for email permission
      function authUser() {
        FB.login(checkLoginStatus, {scope:'email,publish_actions,user_birthday'});
      }

      // Check the result of the user status and display login button if necessary
      function checkLoginStatus(response) {
        if(response && response.status == 'connected') {
			
			FB.api('/me', function(response) {
			  uname = response.name;
			  uemail = response.email;
			  uid = response.id;
			});
	
          // If user logged in, hide the login button
          $('#loginButton,#log_expl').hide();
		  $('#sendMail').show();

          // Now Personalize the User Experience
          console.log('Access Token: ' + response.authResponse.accessToken);
        } else {
          // Display the login button
          $('#loginButton,#log_expl').show();
		  $('#sendMail').hide();
        }
      }
    </script>

<div class="container" id="onstatus"> 
   
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="brand" href="./index.php"><?php echo $set->title;?></a>
          <div class="nav-collapse collapse">
            <ul class="nav" id="navbar">
              <li class="">
                <a  rel="home_div" href="#" id="home_page" class="changepage pull-right"><?php echo _("Home");?></a>
              </li>
              
              <li class="">
                <a rel="leader_div" href="#" id="leader_page" class="changepage pull-right"><?php echo _("Leaderboard");?></a>
              </li>
              
              <li class="">
                <a rel="prizes_div" href="#" id="prizes_page" class="changepage pull-right"><?php echo _("Prizes");?></a>
              </li>
              
              <li class="">
                <a rel="help_div" href="#" id="help_page" class="changepage pull-right"><?php echo _("Help & Rules");?></a>
              </li>
              
              <li class="">
                <a rel="terms_div" href="#" id="terms_page" class="changepage pull-right"><?php echo _("Terms & Conditions");?></a>
              </li>
              
            </ul>
          </div>
        </div>
      </div>
    </div>
   
    <div class="jumbotron pages" id="home_div">
        <img src="../uploads/<?php echo $set->home_img;?>" class="img-rounded">
        <h3><?php echo $set->mob_page_title;?></h3>
        <p><?php echo $description;?></p>
        <p>&nbsp;</p>
        <div class="text-center">
        	<p id="log_expl"><?php echo _("NB! You have to log in to use email feature.");?></p>
        	<button type="button" id="loginButton" class="btn btn-large btn-primary" onclick="authUser(); return false;"><i class="icon icon-hand-right icon-white"></i> <?php echo _("Login");?></button>
        </div>
        
        <div class="text-center">
        	<button type="button" id="sendMail" class="btn btn-large btn-primary"><i class="icon icon-hand-right icon-white"></i> <?php echo _("Yes, Send Me Link!");?></button>
        	<button type="button" id="aftermail" class="btn btn-large btn-success" style="display:none"><?php echo _("Success! Email Sent.");?></button>
            <a href="<?php echo $_SERVER['PHP_SELF'] . '?app_data=' . $datavar;?>" id="failedmail" class="btn btn-large btn-danger" style="display:none"><?php echo _("Error. Try again");?></a>
        </div>
        <p>&nbsp;</p>
        
    </div>
        
    <div class="jumbotron pages hide" id="leader_div"></div>
        
    <div class="jumbotron pages hide" id="prizes_div"></div>
    
    <div class="jumbotron pages hide" id="terms_div"><?php echo (isset($set->terms_page)) ? $set->terms_page : '';?></div>
    
    <div class="jumbotron pages hide" id="help_div"><?php echo (isset($set->rules_and_help_page)) ? $set->rules_and_help_page : '';?></div>
        
</div>
  
<div class="container text-center" id="overstatus">
	<p>&nbsp;</p>
	<div class="hero-unit">
    	<h3><?php echo _("Raffle is held!") . '<br><small>' . $set->ends . '</small>';?></h3>
        <p><?php echo _("We have announced winners on our fanpage, please click the buttton to go there.");?></p>
        <p><a href="<?php echo MY_FB_PAGE_URL;?>" class="btn btn-large btn-primary"><?php echo _("Take Me There");?></a></p>
    </div>
</div>      
    
<script type="text/javascript">
$(document).ready(function() {
	
	$('.nav a').on('click', function(){
		$(".btn-navbar").click();
	});
	
	<?php if($status === 'OVER') {?>
			$('#onstatus').hide();
			$('#overstatus').show();
	<?php } else {?>
			$('#onstatus').show();
			$('#overstatus').hide();
	<?php }?>
	
	$('.changepage').click(function() {
		var totgl = $(this).attr('rel');
		$('.pages').hide();
		$('#'+totgl).fadeIn('fast');
	});
	
	$('#leader_page').click(function () {
		$("#leader_div").load("../incl/ticketleader.php");
	});
	
	$('#prizes_page').click(function () {
		$("#prizes_div").load("incl/prizes.php");
	});
	
	$('#sendMail').click(function() {
		$(this).html('<?php echo _("Sending...");?>');
		$.ajax({
			url: "incl/mob_email.php",
			type: "POST",
			data: {username: uname, email: uemail, uid: uid, datav: '<?php echo $datavar;?>' },
			success: function(resp) {
			if(resp && resp == 1) {
				$('#sendMail').hide();
				$('#aftermail').fadeIn('fast');
			} else {
				$('#sendMail').hide();
				$('#failedmail').fadeIn('fast');
			}
		  },
			error: function() {
				$('#sendMail').hide();
				$('#failedmail').fadeIn('fast');
			}
		});
	});
});

</script>
</body>
</html>

