<?php 
// Comment out next line to enable gzip
//if(ini_get('zlib.output_compression') != 1) { if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); }

$sumfingIncl=true;
require 'fb/facebook.php';
require 'config.thing.php';
// Data object from admin table
$set = get_adm_opts();
include 'incl/translate.php';

$user = '';

// Init the Facebook SDK
$facebook = new Facebook(array(
	'appId'  => FB_APPID,
    'secret' => FB_SECRET,
	'cookie' => true,
	'fileUpload' => true
));

// If page is outside of page tab
$data= $facebook->getSignedRequest();

// Get the current user
if(isset($_REQUEST['user']))
$user = trim(strip_tags($_REQUEST['user']));

$user = is_user_fakeid($user);
$user = $user->fb_id;

if(!$user) die(_("Access denied")); // Say no for unauthorized use

if(!isset($set->use_slot)) die(_("Not in use!")); // If Slot Machine is not turned ON
	
// Set timezone
date_default_timezone_set($set->timezone);

// Get user from database
$userdata = save_and_return('', $user);

// Check if interval allows to play
if($userdata->slot_int > time()) {
	die( _("No access") );
} else {
	set_slot_int($userdata->fb_id,$set->slot_ticket_int);	
}

// Make array for wins table
$winsarray = array('clover_2'=>$set->clover_2_win,'clover_3'=>$set->clover_3_win,'heart_2'=>$set->heart_2_win,'heart_3'=>$set->heart_3_win,'star_2'=>$set->star_2_win,'star_3'=>$set->star_3_win);
$winstable = make_win_table($winsarray);

// Get app path
$scriptpath = rtrim(MY_HTTPS_URL, "/");
$app_files_url = $scriptpath;
?>

<!DOCTYPE html>
<html>
  <head>
    <title><?php echo $set->slot_title;?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="js/jquery.js" type="text/javascript"></script>
	<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <?php include 'js/slot.php';?>
    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
    <style type="text/css">
		.wheel {float:left; width:128px; height:192px; margin-top:9px; margin-left:2px;}
		.l_wheel {margin-left:6px;}
		.slot_wrap {width:406px; height:206px; overflow:hidden;background-image:url(img/slot/machine.png); background-repeat:no-repeat;}
		.margpadd_z {padding:0; margin:0}
	</style>
  </head>
<body>
<!-- Facebook -->
<div id='fb-root'></div>
<script type='text/javascript'>
window.fbAsyncInit = function() {
	FB.init({
    	appId: '<?php echo FB_APPID;?>',
        status: true,
        cookie: true,
        oauth: true,
		xfbml: true,
		frictionlessRequests : true
    });
	FB.Canvas.setAutoGrow(91);
	FB.Canvas.scrollTo(0,0);
};
</script>
<script type='text/javascript'>
// Load the SDK Asynchronously
(function(d){
	var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = '//connect.facebook.net/en_US/all.js';
    ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<!-- Facebook -->  

<div class="container margpadd_z"> <!-- Main container -->
	<div class="text-right">
        <a href="<?php echo MY_APP_URL;?>" target="_parent" style="font-size:22px" title="Leave">&times;</a>
    </div>
    
	<div class="span7 pull-left"><!-- Left part -->
		
        <h3 class="text-center" style="line-height:24px"><?php echo $set->slot_title;?><br><small><?php echo $set->slot_description;?></small></h3>
        
        <!-- Slotmachine wheels -->
        <div class="slot_wrap">
            
            <div id="single_L" class="wheel l_wheel">
                <?php echo draw_wheels('L');?>
            </div>
            <div id="single_C" class="wheel">
                 <?php echo draw_wheels('C');?>
            </div>
            <div id="single_R" class="wheel">
                 <?php echo draw_wheels('R');?>
            </div>
            <div class="clearfix"></div>
        
        </div>
        <!-- Slotmachine wheels -->
        
                
        <div class="inline">
        <div class="alert alert-warning" id="no_win" style="display:none; width:356px; margin-top:10px; text-align:center"><?php echo _("No win this time. Sorry!");?></div>
        <?php if(isset($set->slot_timeline_toggle)) {?>
        <div class="alert alert-info" id="explain_post" style="display:none; width:356px; margin-top:10px; text-align:center"><?php echo _("You have to post to your timeline, in order to collect tickets. Dialog opens after clicking on 'Collect'!");?></div>
        <?php }?>
            <div class="pull-left" style="width:134px;text-align:center">
                <p style="margin:10px" class="things"><?php echo _("Credits");?> <span class="btn btn-inverse disabled" id="spins_left"><?php echo $set->slot_free_spins;?></span></p>
            </div>
            <div class="pull-left" style="width:128px; margin-top:10px; text-align:center" id="spin_btn_wrap">
                <a class="btn btn-primary btn-large" style="width:100px;" name="spin" id="spin_btn"><?php echo _("SPIN");?></a>
                <a class="btn btn-primary btn-large" style="width:100px; display:none" name="spin_ph" id="spin_btn_ph"><?php echo _("Wait");?></a>
                <a class="btn btn-success btn-large" style="width:100px;display:none" name="collect" id="collect_btn"><?php echo _("Collect");?></a>
                <a href="<?php echo MY_APP_URL;?>" target="_parent" class="btn btn-info btn-large" style="width:100px;display:none" name="back" id="back_btn"><?php echo _("Go Back");?></a>
            </div>
            <div class="pull-left" style="width:134px;text-align:center">
                <p style="margin:10px" class="things"><span class="btn btn-inverse disabled" id="wins">0</span> <?php echo _("Wins");?></p>
                <p id="lastwin" style="display:none"><?php echo _("Last win: ");?><span id="latestwin"></span></p>
            </div>
        </div>
    
        <!--<a href="#" data-toggle="tooltip" title="first tooltip" id="example">hover over me</a>-->
       
    </div><!-- Left part -->
    
    <div class="span4 pull-right"><!-- Right part -->
    	<div style="margin-top:44px">
        <h3><?php echo _("Wins Table");?></h3>
        <?php echo $winstable;?>
        </div>
    </div><!-- Right part -->
    
    <div class="clearfix"></div>
    
    <!-- Scoreboard with latest wins on slot machine -->
    <div class="span12">
    	<h3><?php echo _("Best Results");?></h3>
        <table class="table table-striped table-bordered">
          <thead>
            <tr>
              <th><?php echo _("#");?></th>
              <th><?php echo _("Name");?></th>
              <th><?php echo _("Tickets Won");?></th>
              <th><?php echo _("Date");?></th>
            </tr>
          </thead>
          <tbody>
          <?php slot_leaders();?>
          </tbody>
        </table>
    </div>

    <div class="footer">
        <?php echo $set->footer_info;?>
    </div>
    
</div><!-- Main container--> 
<script type="text/javascript">
    $(function () {
        $("[data-toggle='tooltip']").tooltip();
    });
</script>
</body>
</html>