<?php 
// Comment out next line for gzip. Also comment out ob_flush at the bottom of the page
//if(ini_get('zlib.output_compression') != 1) { if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); }

##########################################################################################################################
/*
LICENCE AGREEMENT/EULA

Viral Lottery - Facebook App
Copyright 2013 CodeCafe/Codecanyon 
www.facebook.com/codecafeapps

REGULAR LICENCE

1. You have to own personal REGULAR LICENCE CERTIFICATE from Envato Marketplace for Viral Lottery - Facebook App. You are agree 
that developer, CodeCafe from Codecanyon, has right to ask for PURCHASE CODE from you.

2. You may install Viral Lottery - Facebook App ONLY on domains that you own.

3. You must not directly or indirectly license, sub-license, sell or resell the Viral Lottery - Facebook App,
or redistribute the Viral Lottery - Facebook App alone (even for free), or offer to do any of these things. 
All of these things are referred to as Resale.

4. If the current LICENSE AGREEMENT has not been followed, then developer ,CodeCafe from Codecanyon and the purchaser will endeavor to 
settle their disputes acquiescently in negotiation. If an agreement cannot be reached, the dispute will be settled in court.

EXTENDED LICENCE

1. You have to own personal EXTENDED LICENCE CERTIFICATE from Envato Marketplace for Viral Lottery - Facebook App. You are agree 
that developer, CodeCafe from Codecanyon, has right to ask for PURCHASE CODE from you.

2.You may display the Viral Lottery - Facebook App, and make the Viral Lottery - Facebook App available for use 
by an unlimited number of your clients, in conjunction with a web site service that you host on behalf of your clients. 
When using the Viral Lottery - Facebook App through a web site service, you may make unlimited copies of the 
Viral Lottery - Facebook App but you must procure that your clients do not reproduce or use the Viral Lottery - Facebook App in another application.

3.You may use the Viral Lottery - Facebook App in a work which you are creating for your own purposes or for your client who has asked you to create it.

4. If the current LICENSE AGREEMENT has not been followed, then developer ,CodeCafe from Codecanyon and the purchaser will endeavor to 
settle their disputes acquiescently in negotiation. If an agreement cannot be reached, the dispute will be settled in court.

*/
##########################################################################################################################

$sumfingIncl=true;
if(file_exists('config.thing.php')) {
	require 'fb/facebook.php';
	require 'config.thing.php';
	// Get settings
	$set = get_adm_opts();
	include 'incl/translate.php';
} else {
	echo ('<script> location.href=\'install/install.php\'</script>');
	die;
}

// FOR DEBUGING
if(DEBUG_APP === true) {
error_reporting(~0);
ini_set('display_errors', 1);
ini_set('display_errors', true);
}


$app_namespace = '?sk=app_'.FB_APPID;
$app_url = MY_FB_PAGE_URL . $app_namespace;
   
$scope = 'email,publish_actions,user_birthday';

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

// Get the current user
$user = $facebook->getUser();

// Extended access token
$facebook->setExtendedAccessToken();
// User token
$usertoken = $facebook->getAccessToken();

//get app_data into variable if available
$data= $facebook->getSignedRequest();
$partdata=array();
$datavar='';
// Get app_data from url
if(isset($data['app_data'])) {
	$datavar = '&app_data='.$data['app_data'];
}

if(isset($_REQUEST['app_data'])) {
	$datavar = '&app_data='.$_REQUEST['app_data'];
}

// Get request ids
if(isset($_REQUEST['request_ids'])) {
	$datavar = '&app_data=2_'.$_REQUEST['request_ids'];
}

// Detect device
require_once 'mobile/detect/Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if($deviceType !== 'computer') {
	echo ("<script> top.location.href='mobile/index.php?x=ok".$datavar."'</script>'");
}

// If the user has not installed the app, redirect them to the Auth Dialog
if (!$user) {
	$loginUrl = $facebook->getLoginUrl(array(
    	'scope' => $scope,
    	'redirect_uri' => $app_url.$datavar,
    ));

	echo ('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}
   
//check if app runs on your fbpage and redirect if needed
if(empty($data['page']['id'])) {
	echo ('<script> top.location.href=\'' . $app_url.$datavar . '\'</script>');
} 
   
if ($user) {
	
	// Is user fan or not
	$fan = (empty($data['page']['liked'])) ? 'notfan' : 'fan';
	
	// Get admin user
	$admin = (isset($data['page']['admin']) && ($data['page']['admin'] == 1)) ? 1 : 0;
	// Get current page Likes
	if (ini_get('allow_url_fopen') == 1) {
		$pagelikes = json_decode(@file_get_contents('https://graph.facebook.com/'.$data['page']['id'].'/'));
		if(is_object($pagelikes)) {
			$pagelikes = $pagelikes->likes;
		}
	} else {
		$pagelikes = 0;	
	}
	
	// Get all requested user data
	try {
		$userd = $facebook->api('/me');
	} catch (FacebookApiException $e) {
		error_log($e);
		$user = null;
	}
	
	//set your timezone
	date_default_timezone_set($set->timezone);
	
	// Admin user
	if($admin === 1) {
		$adminuser = 1;
		
		// Delete all admin tickets if disabled from admin panel
		if(!isset($set->give_admin_tickets)) {
			delete_admin_tickets($user);
		}
		
	} else {
		$adminuser = 0;
	}
	
	// If no email presented, seems like user is using facebook as page
	//if(!isset($userd['email']) && ($user != null)) {
		//die("Error! Can't detect 'email address', you have to use Facebook from your personal account!");	
	//} else {
	
	// Save user data and fetch already saved user
	$params = "'".$user."','".$adminuser."','".$usertoken."','".$userd['name']."','".$userd['email']."','".$userd['birthday']."','".date('Y-m-d H:i:s', time())."','n','','','".sha1($usertoken . '|' . $user)."','no','0','0','0'";
	//}
	
	//userdata object from db
	$userdata = save_and_return($params, $user);
	
	// Message for banned user
	if($userdata->banned == 'y') echo _("You are banned from admin. Contact us if you need more information.");
	
	// Delete app requests older than set days
	if($admin === 1) {
		if(isset($set->use_app_requests)) {
			if (ini_get('allow_url_fopen') == 1) {
				$pendingrequests = array();
				$pendingrequests = get_pending_request($set->request_delete_day); // Will return full requests
				// Loop over requests and delete
				//print_r($pendingrequests);
				if(!empty($pendingrequests)) {
				$app_token = get_app_token(FB_APPID, FB_SECRET);
					foreach ($pendingrequests as $request_id) {
						@file_get_contents('https://graph.facebook.com/'.$request_id.'?'.$app_token.'&method=DELETE');	
					}
				}
			}
		}
	}
	// Delete requests ends 
		
	// Detect raffle status, NOT STARTED, ON, OVER
	$status = '';
	// If TIMER
	if($set->select_counter == 'time') {
		$timestatus = true;
		$likestatus = false;
		if(strtotime($set->starts) > time()) {
			$status = 'NOT STARTED';
		}
		if(strtotime($set->starts) < time()) {
			$status = 'ON';
		}
		if(strtotime($set->ends) < time()) {
			$status = 'OVER';
		}
	}
	
	// If LIKES
	if($set->select_counter == 'like') {
		$timestatus = false;
		$likestatus = true;
		if(isset($set->start_likes) && ($set->start_likes > $pagelikes)) {
			$status = 'NOT STARTED';
		}
		if(isset($set->start_likes) && ($set->start_likes <= $pagelikes)) {
			$status = 'ON';
		}
		if(isset($set->end_likes) && ($set->end_likes <= $pagelikes)) {
			$status = 'OVER';
		}
	}
	
	// Update longterm token if needed
	// Check if switched on from admin first
	if(isset($set->long_token)  && (isset($usertoken)) && ($user != null)) {
		if($usertoken != $userdata->offline_access) {
			// Update data
			update_user_token($usertoken, $user);
		}
	}

	// When user comes with link from  another user
	//signed request for page data
	$signed_request = $_REQUEST['signed_request'];
	list($encoded_sig, $payload) = explode('.', $signed_request, 2);
	$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
	if(isset($data['app_data'])) {
		$app_data = $data['app_data'];
		$partdata = explode("_",$app_data);
	}
	
	if( (isset($partdata[0]) && ($partdata[0] == 1)) && ($status == 'ON') && ($fan == 'fan') && (isset($set->use_share_tickets))) {
		
		// If user id is different from current user
		if($userdata->fake_id != $partdata[1]) 
		{
			// User object, this user will get the ticket(s)
			$ref_user = get_ref_user($partdata[1]);
				
				if (!get_ref_tickets($ref_user->fb_id,$userdata->fake_id))  { 
						
					// Give tickets	
					make_tickets($set->share_ticket_amount,$ref_user->fb_id,$userdata->fake_id,$ref_user->name,$ref_user->email);						
					
					// Send email to user if set
					if(isset($set->send_ref_email)) {
						// Subject and message
						$subject = str_replace("[NAME]",$ref_user->name, $set->ref_email_subject);
						$message = str_replace("[NAME]",$ref_user->name, $set->ref_email_body);
						$message = str_replace("[APPLINK]","<a href='".MY_APP_URL."'>" . MY_APP_URL . "</a>", $message);
						$message = str_replace("[REFNAME]","<a href='https://facebook.com/".$userdata->fb_id."/'>" . $userdata->name . "</a>", $message);
						$message = nl2br($message);
						if(!ref_note_email('',$ref_user->email,$subject,$message)) {
							error_log(_("Error! Referrer email not sent."));	
						}
					}
				}				
		}//check if user posted his/her own link
		else 
		{
			echo _("Wow, you are a Genius, it is your own link:) Can't help here! Go to app <a href='".MY_APP_URL."'  target='_parent'>page</a>");
			die;
		}
		
	}// Ref link check ends

	// Referrer link for sharing   MY_APP_URL
	$refflink = MY_APP_URL . '?app_data=1_' . $userdata->fake_id;
	
	// Get app requests, add tickets if needed and delete requests
	// Request ids from the query parameter
	if((isset($partdata[0]) && ($partdata[0] == 2)) && ($status == 'ON') && ($fan == 'fan') && (isset($set->use_app_requests))) {
		
		  // Build the full_request_id and delete request  
		  $full_request_id = build_full_request_id($partdata[1], $user);  
		  try {
			 if($facebook->api("/".$full_request_id, 'DELETE')) {
				// Change request status on database and give tickets
				if(!update_request($partdata[1],$set->request_ticket_amount,$user,$userdata->fake_id)) {
					error_log(_("Can not update request and share tickets. Request id - " . $partdata[1]));					
				}
				
			 }
		  }          
		  catch (FacebookApiException $e) {
			 error_log($e);
		  }
		
	} // isset request ids
	
	// Check for mobile page email link
	if((isset($partdata[0]) && ($partdata[0] == 3)) && ($status == 'ON') && ($fan == 'fan')) {
		
		  // Check if link exists and is it answered or not
		  $moblinkcheck = check_mob_link($partdata[1],$user);
		  
		  // When mob link check is successful, it means answer is updated, give tickets to user if set over 0 from admin
		  if(($moblinkcheck === true) && ($set->mob_page_tickets > 0)) {
			  // Give tickets	
			  make_tickets($set->mob_page_tickets,$user,'admin',$userdata->name,$userdata->email);
			  
			  // CHECK FOR REFERR AND REQUEST
			  if(isset($partdata[2]) && isset($partdata[3])) {
				  
				  if($partdata[2] == 2) {
					  // Build the full_request_id and delete request  
					  $full_request_id = build_full_request_id($partdata[3], $user);  
					  try {
						 if($facebook->api("/".$full_request_id, 'DELETE')) {
							// Change request status on database and give tickets
							if(!update_request($partdata[3],$set->request_ticket_amount,$user,$userdata->fake_id)) {
								error_log(_("Can not update request and share tickets. Request id - " . $partdata[3]));					
							}
							
						 }
					  }          
					  catch (FacebookApiException $e) {
						 error_log($e);
					  }  
				  }
				  
				  
				  if($partdata[2] == 1) {
					  
					    // If user id is different from current user
						if($userdata->fake_id != $partdata[3]) 
						{
							// User object, this user will get the ticket(s)
							$ref_user = get_ref_user($partdata[3]);
								
								if (!get_ref_tickets($ref_user->fb_id,$userdata->fake_id))  { 
										
									// Give tickets	
									make_tickets($set->share_ticket_amount,$ref_user->fb_id,$userdata->fake_id,$ref_user->name,$ref_user->email);						
									
									// Send email to user if set
									if(isset($set->send_ref_email)) {
										// Subject and message
										$subject = str_replace("[NAME]",$ref_user->name, $set->ref_email_subject);
										$message = str_replace("[NAME]",$ref_user->name, $set->ref_email_body);
										$message = str_replace("[APPLINK]","<a href='".MY_APP_URL."'>" . MY_APP_URL . "</a>", $message);
										$message = str_replace("[REFNAME]","<a href='https://facebook.com/".$userdata->fb_id."/'>" . $userdata->name . "</a>", $message);
										$message = nl2br($message);
										if(!ref_note_email('',$ref_user->email,$subject,$message)) {
											error_log(_("Error! Referrer email not sent."));	
										}
									}
								}				
						}//check if user posted his/her own link
					  
				  }
				  
			  }// CHECK FOR REFERR AND REQUEST
		  
			  
		  } //  
		  
	} //  mobile page email link
   
	// Counter time for time based counter
	$count_time = (strtotime($set->ends) - time());
	
	// Get app path
	$app_files_url = MY_HTTPS_URL;
	
	// Security form data
	$secdata = '';
	if ( isset($set->txt_1) ) {	$secdata .= $set->txt_1.';:;'; if(isset($set->txt1_mand)) $secdata .= $set->txt1_mand.':;:'; else $secdata .= 'N:;:';}
	if ( isset($set->txt_2) ) {	$secdata .= $set->txt_2.';:;'; if(isset($set->txt2_mand)) $secdata .= $set->txt2_mand.':;:'; else $secdata .= 'N:;:';}
	if ( isset($set->txt_3) ) {	$secdata .= $set->txt_3.';:;'; if(isset($set->txt3_mand)) $secdata .= $set->txt3_mand.':;:'; else $secdata .= 'N:;:';}
	if ( isset($set->txt_4) ) { $secdata .= $set->txt_4.';:;'; if(isset($set->txt4_mand)) $secdata .= $set->txt4_mand.':;:'; else $secdata .= 'N:;:';}
	if ( isset($set->txt_5) ) {	$secdata .= $set->txt_5.';:;'; if(isset($set->txt5_mand)) $secdata .= $set->txt5_mand.':;:'; else $secdata .= 'N:;:';}
																																	
	$sec_fields = explode(':;:',$secdata);
	$sec_fields = array_filter($sec_fields);
	$numofelements = count($sec_fields);
	
	if($set->request_limit > 0) {
	//get count of requests from requests table
	$reqcount = get_request_count($user);	
	}
?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $set->title;?></title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen">
<!-- Javascripts -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<?php if($admin === 1) {?>
<script src="timepick/build/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link href="timepick/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" media="screen">
<?php }
//<!-- Sharethis-->
if(isset($set->use_share_tickets)) {
	if($userdata->share_int < time()) {?>
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "<?php echo $set->sharethis_pubkey;?>", doneScreen: false, doNotHash: true, doNotCopy: true, hashAddressBar: false, onhover: false,});</script>
<!-- Sharethis-->
<?php }
}

include 'incl/somejs.php';

?>

<style type="text/css">
.st_sharethis_custom, #next_step_btn, #requests_btn, #slot_btn, #rp_sharethis_btn, #rp_req_btn, #rp_slot_btn {
	font-size:18px;
	padding:12px;
	font-weight:bold;
	margin-bottom:8px;
}
</style>

</head>
<body oncontextmenu="return false;">
<!-- 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);
};
</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 id='container'>
<?php 

if(isset($set->maintenance)){
	  echo $set->maint_msg;
	  echo '<p>&nbsp;</p>';
	  if($admin != 1) die;
  }

// Banner for header
if(((trim($set->head_ad) != '')) && ($fan == 'fan')) {
	echo '<div class="row-fluid text-center">' . $set->head_ad . '</div>
	<div class="clear-fix"><p>&nbsp;</p></div>';
}

if($status == 'NOT STARTED') {
	// Show message and counter to the start if set so
	// If time set as counter
	if($timestatus || $likestatus) { ?>
	
            <div class='hero-unit text-center'>
                <h2><?php echo $set->not_start_title;?></h2>
                
                <?php if(isset($set->show_start_timer)) {?>
                	<div class='text-center'>
                        <hr>
                        <button id='start_counter' class='btn btn-large <?php echo $set->counter_classes;?>' style='min-width:180px;font-size:44px; font-weight:bold; cursor:pointer; padding:16px' 
                        title='<?php echo ($timestatus) ? _("Time Left") . ' ' . _('DD : HH : MM : SS') : _("Needed likes for start");?>'></button>
                        <hr>
                    </div>
				<?php }?>
                
                <p><?php echo $set->not_start_msg;?></p>
                
            </div>
        
        </div><!--MAIN CONTAINER ENDS-->
    
        </body>
        </html>
        
                
    <?php  
        if($admin != 1)
        die;
	}
	
} 

if($status === 'OVER') {
	
  // Check for needed amount of participants
  if($set->min_participants <= get_participants()) {
	  
	// Make prizes and winners
	$prizesarray = (array)$set;
	$amttoloop = 0;
	$winarray = array();
	if(isset($prizesarray['prize1_amount']) && ($prizesarray['prize1_amount'] != 0)) {
		$amttoloop = 1;
		$winarray[] = $prizesarray['prize1_amount'];
	}
	if(isset($prizesarray['prize2_amount']) && ($prizesarray['prize2_amount'] != 0)) {
		$amttoloop = 2;
		$winarray[] = $prizesarray['prize2_amount'];
	}
	if(isset($prizesarray['prize3_amount']) && ($prizesarray['prize3_amount'] != 0)) {
		$amttoloop = 3;
		$winarray[] = $prizesarray['prize3_amount'];
	}
	
	$winners = setwinners($winarray,$set->winner_pick);
	
	if($amttoloop != 0) {
		
		echo '<h3>'. _("And the Winners Are ...").'</h3>';
		
		for($i=1;$i<=$amttoloop;++$i) { ?>
			<div class="row-fluid">
			
				<ul class="thumbnails">
									 
					<!-- Title -->
					<li class="span6">
							<?php 
							echo "<h3 class='text-info'>" . $prizesarray["prize".$i."_title"] . "</h3>";
							
							// Winners out here
							$win = explode(",",$winners[($i-1)]);
							$win = unserialize($win[1]);
							foreach($win as $k=>$w) {
								$output = explode(":;:",$w);
								echo "<p style='font-size:18px'><img src='https://graph.facebook.com/".$output[0]."/picture' class='img-polaroid img-rounded'> " . $output[1] . "</p>";
							}							
							
							?>
					</li>
					<!-- Title -->
					
					<!-- Picture -->
					 <?php if($prizesarray["prize".$i."_img"] != "") {?>     
					 <li class="span5 pull-right">
						 <div class="thumbnail">
							 <img src="uploads/<?php echo $prizesarray["prize".$i."_img"];?>" alt="">
						 </div>
					 </li>
					 <?php }?>
					<!-- Picture -->
					
				</ul>
              
			</div>
		
		<?php } // For loop end
	
		} else { // If amount not 0 end
			echo _("No prizes set or prizes amount(winners amount for current prize) is 0(zero)");
		}
  } else { // Amount of participants were not reached ?>
	
	<div class='tabbable'>
		
            <div class="alert alert-block">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            	<?php echo $set->min_part_msg;?>
            </div>
            
      
    </div>

  <?php }
} 
?>

<?php 
// If user is not liked page, show fangate content
if(isset($set->fangate) &&  ($fan == 'notfan') && ($status == 'ON')) { 
    
	if(isset($set->fangate_use_img) && $set->fangate_img != '') {
		echo '<img src="uploads/'.$set->fangate_img.'" class="img-rounded">';
	} else {
		echo $set->fangate_description;
	}
	
// If fan, then show full content
} else {
  
  // Extra security form if checked from admin. Stops users behind the verification form
  if(isset($set->sec_form) && ($userdata->verified == 'no') && ($status == 'ON')) { ?>
  
  <!-- Verification form starts -->
  <div class='hero-unit'>
      <h2><?php echo $set->sec_form_title;?></h2>
      <p><?php echo $set->sec_form_description;?></p>
      <hr>
      <form class='form-horizontal' id='sec_form'>
      
      	  <label class='alert alert-error' id='mand_err' style='display:none'>
			<?php echo _("Attention! Fields with * mark are mandatory.");?>
          </label>
          
          <label class='alert alert-error' id='exists_err' style='display:none'></label>
          
          <label class='alert alert-success' id='succ_sec' style='display:none'>
            <?php echo _("Success! Your data has been added to your account.");?>
          </label>
          
          <input type='hidden' name='sec_data_form' value='<?php echo $userdata->fake_id;?>'>
          <?php
          $frmn = 1;
          foreach($sec_fields as $key=>$field) {
            $parts = explode(';:;',$field);
            $fieldname = $parts[0];
            $checkbox = $parts[1];
            $numbr = $key+1;
            $mand = '';
            // $checkbox=='mandatory	&  $fieldname				
            if($checkbox == 'mandatory') $mand = '<span style="color:red">*</span> ';
            echo '<div class="control-group">';
              echo '<label class="control-label" for="secid_'.$frmn.'">'.$mand . $fieldname.'</label>';
                echo '
                <div class="controls">
                  <input type="text" id="secid_'.$frmn.'" name="'.str_replace(" ","++",$fieldname).'_'.$checkbox.'">
                </div>
            </div>';
            $frmn++;									
          }
          ?>
          <hr>
          <div class='control-group'>
            <div class='controls'>
              <button type='button' name='sec_fsub' id='sec_form_btn' class='btn'><?php echo $set->sec_form_btn;?></button>
            </div>
          </div>  
      </form>
      
      
      
  </div>
  
  <!-- Verification form ends --> 
  
  <?php 
  } else {
  // Fan and verified content 

?>

  <div class='tabbable'> <!-- Only required for left/right tabs -->
  
     <ul class='nav nav-tabs'>
    	<li class='active'><a href='#tab1' data-toggle='tab'><i class='icon icon-fire'></i> <?php echo _("LOTTERY");?></a></li>
    	<?php if(is_tickets()) { ?>
    	<li><a href='#tab2' data-toggle='tab' id='lboard'><i class='icon icon-list'></i> <?php echo _("LEADERBOARD");?></a></li>
        <?php }?>
    	<li><a href='#tab5' data-toggle='tab' id='lprizes'><i class='icon icon-gift'></i> <?php echo _("PRIZES");?></a></li>
     	<li><a href='#tab3' data-toggle='tab'><i class='icon icon-file'></i> <?php echo _("HELP & RULES");?></a></li>
     <?php if ($admin === 1) {?> <li style='float:right'><a href='#tab4' data-toggle='tab'><i class='icon icon-wrench'></i> <?php echo _("ADMIN");?></a></li><?php }?>
     </ul> 
                                      
     <div class='tab-content'>
    		
         <div class='tab-pane active' id='tab1'>
                 
             <div class='span8'>
                  <div class='thumbnails caption'>
                  <?php if(isset($set->homepage_show_stats)){ ?>
                  <p id="joined_and_tickets" style="display:none"></p>
                  <?php }?>
                    	<h3><?php echo $set->title;?></h3>
                    	<p><?php echo $set->subtitle;?></p>
                  </div>
             </div>
             
             <div class='span4 text-center pull-right' style='margin-right:6px;'><!--COUNTER, counts time backwards to the end of the lottery-->
             	
                <?php 
				if($status == 'ON') {
					if($set->select_counter == 'time') {?>
					<small><i class='icon icon-time'></i> <?php echo _("TIME LEFT FOR DRAW");?></small>
					<button id='counter' class='btn btn-large <?php echo $set->counter_classes;?>' style='font-size:36px; font-weight:bold; cursor:pointer; padding:14px' title='<?php echo _("DD : HH : MM : SS");?>'></button>
					<small><?php echo _("Started") . ' ' . $set->starts;?></small>
					<?php } else {?>
					 <small><i class='icon icon-thumbs-up'></i> <?php echo _("LIKES TO GO");?></small>
					<button id='like_counter' class='btn btn-large <?php echo $set->counter_classes_ch;?>' style='font-size:36px; min-width:200px; font-weight:bold; cursor:pointer; padding:14px' title='<?php echo _("Amount of more likes needed");?>'></button>
					<small><?php echo _("Started from") . ' ' . $set->start_likes;?></small>
					<?php 
					}
				}?>
             </div><!--COUNTER ENDS HERE-->
             
             <div class='clearfix' style='margin:0'></div>
             
             
             <div class='row-fluid'>
                <ul class='thumbnails'>
                
                  <li class='span7'><!-- Picture and description -->
                    <div class='thumbnail'>
                      <?php if(isset($set->homepage_use_img)) {?>
                      	<img src='uploads/<?php echo $set->home_img;?>' alt=''>
                      <?php }?>
                      <div class='caption'>
                        <?php echo $set->description;?>
                      
                      </div>
                     
                    </div>
                    
                  </li>
                  
                  <!-- Sidebar ad -->
					<?php if(trim($set->sidebar_ad) != '') {
                        echo '<li class="span5 thumbnail text-center" id="side_ban">' . $set->sidebar_ad . '</li>';
                    } ?>
                  <!-- Sidebar ad -->
                  
                  <li class='span5' id="more_tickets_opt"> <!-- More tickets options -->
                    <div class='thumbnail'>
                      <div class='caption'>
                      
                        <i class="icon icon-info-sign pull-right" data-trigger="hover" data-toggle="popover" id="ticket_info" data-placement="left" data-content="<?php echo $set->btns_info_bubble;?>"></i>
                        <h4><?php echo _("Get More Tickets");?></h4>
                        
                          <!-- Button Group for tickets -->
                          <div id="steps_content">
								
                                <!-- Share step for tickets -->
									<div id="step_1" class="steps_panel">
                                    	<?php if(isset($set->use_share_tickets) && ($userdata->share_int < time())) {?>
                                        <div id='st_sharethis_btn'
                                        class='st_sharethis_custom btn btn-block <?php echo $set->share_btn_color;?>' 
                                        st_url='<?php echo $refflink;?>' 
                                        st_image='<?php echo $app_files_url . 'uploads/' . $set->share_img;?>' 
                                        st_summary='<?php echo (isset($set->share_content)) ? $set->share_content : '';?>' 
                                        cdisplayText='<?php echo _("Share");?>'
                                        style="font-size:18px; padding:12px;font-weight:bold;margin-bottom:8px;">
                                            <?php if(isset($set->share_btn_txt)) echo $set->share_btn_txt;?>
                                        </div>
                                        <?php }?>
                                        <div id='rp_sharethis_btn'  class='btn btn-block <?php echo $set->share_btn_color;?>' style="display:none"></div>
                                    </div>
                      			<!-- Share step for tickets -->
                                
                                <!-- Requests step for tickets -->
									<div id="step_2" class="steps_panel">
                                    	<?php
									  if(isset($set->use_app_requests) && ($userdata->req_int < time())) { // App requests ?>
                                            <div id="requests_btn" class="btn btn-block <?php echo $set->req_btn_color;?>">
                                                <?php if(isset($set->req_btn_txt)) echo $set->req_btn_txt;
                                                if(($set->request_limit > 0))
                                                echo ' <small id="req_limit-show" style="font-size:13px; font-weight:normal;" title="' . _("Sent/Limit") . '">' . $reqcount . '/' . $set->request_limit . '</small>';
                                                ?>
                                            </div>
                                            <?php }?>
                                            
                                        	<div id='rp_req_btn'  class='btn btn-block <?php echo $set->req_btn_color;?>' style="display:none"></div>
                                            
                                    </div>
                      			<!-- Requests step for tickets -->
                                
                                <!-- Slot step for tickets -->
									<div id="step_3" class="steps_panel">
                                    <?php if(isset($set->use_slot) && ($userdata->slot_int < time())) {?>
                                        <a href="slot.php?user=<?php echo $userdata->fake_id;?>" id="slot_btn" class="btn btn-block <?php echo $set->slot_btn_color;?>">
                                            <?php if(isset($set->slot_btn_txt)) echo $set->slot_btn_txt;?>
                                        </a>
                                    <?php }?>
                                    <div id='rp_slot_btn'  class='btn btn-block <?php echo $set->slot_btn_color;?>' style="display:none"></div>
                                    </div>
                      			<!-- Slot step for tickets -->
                                
                          </div> 
						  <!-- Button Group for tickets -->		
                      </div>
                    </div>
                  </li> <!-- More tickets options -->
                  
                  
                  <li class="span5"> <!-- User data -->
                    <div class="thumbnail">
                      <div class="caption">
                        <img src="https://graph.facebook.com/<?php echo $user;?>/picture" alt="" align="left" class="img-rounded img-polaroid">
                        &nbsp;&nbsp;<i class="icon icon-user"></i> <?php echo $userdata->name;?><br>
                        &nbsp;&nbsp;<?php echo _("Joined:").' ' . $userdata->regdate;?><br>
                        &nbsp;&nbsp;<?php echo _("Tickets:");?> <span id="totaltickets" class="badge badge-info"></span>&nbsp;<i class="icon icon-chevron-up" id="user_show_tickets" style="cursor:pointer"></i><br>
                      </div>
                                            
                      <div id="tickets_panel"  style="max-height:360px; overflow:auto">
                      
                      	<div>
                            <span class="label label-success"><?php echo _("BONUS");?></span>&nbsp;&nbsp;
                            <span class="label label-info"><?php echo _("SLOT MACHINE");?></span>&nbsp;&nbsp;
                            <span class="label label-important"><?php echo _("REFERRED");?></span>
                            <span class="label label-warning"><?php echo _("WINNER");?></span>
                        </div>
                        <hr>
                          <?php
						  	$usertickets = get_user_tickets($user);
								if(isset($usertickets)) {
									$makeitclick = '';
									$maketitle = '';
									foreach($usertickets as $tic) {
										$ticket = explode("|",$tic);
										switch($ticket[3]) {
											case 'admin':
											$tickclass =  'success';
											break;
											case 'slot':
											$tickclass = 'info';
											break;
											default:
											$tickclass = 'important';
										}
										
										if(($ticket[4] == 1) && ($status === 'OVER')) {
											
											$maketitle = _("You Won! Click to claim your prize!");
											$tickclass = 'warning winclick';
												
										}
										if(($ticket[4] == 2) && ($status === 'OVER')) {
											$tickclass = 'inverse madeclick';
											$maketitle = _("This ticket has been approved as winning ticket.!");
										}
											?>
											<div>
												<div class="label label-<?php echo $tickclass;?>" id="win_<?php echo $ticket[0];?>" style="margin:5px; width:94%; padding:3px; font-weight:normal;" data-trigger="hover" data-toggle="popover" data-placement="top" data-content="<?php echo $maketitle;?>">
													<?php echo '#'. $ticket[0] . ' &bull; ' . $ticket[1] . ' &bull; ' . _("Code: ") . $ticket[2];?>
												</div>
											</div>
											<?php
										
									}
								} else {
									echo _("No tickets yet");	
								}
								//print_r($usertickets);
						  ?>
                      </div>
                      
                    </div>
                  </li> <!-- User data -->
                  
                </ul>
                
              </div>
              
             <?php if(isset($set->homepage_show_users_thumbs)) {?>  
             
                    <div class="thumbnail">
                      <div id="users-joined"></div>
                    </div>
                  
             <?php }
			 if(isset($set->homepage_show_comments)) {?>
             	<p>&nbsp;</p>
                    <div class="thumbnail"><!-- Comments -->
                      <div class="fb-comments" data-href="<?php echo MY_FB_PAGE_URL;?>" data-num-posts="10" data-width="800px"></div>
                    </div>
                 
              <?php }?>
                      
        </div><!-- #tab1 -->
         
         <!-- #tab4 -->
         <?php if ($admin === 1) {?>
         
         <div id="tab4" class="tab-pane">
         
         	<?php // Admin alerts
            	  if (ini_get('allow_url_fopen') != 1) {?>
					<div class="alert">
  						<button type="button" class="close" data-dismiss="alert">&times;</button>
  						<strong><?php echo _("Warning!");?></strong> <?php echo _("'allow_url_fopen' function is not allowed on this host. Affects on users 'longlive' tokens and 'Likes' counting.");?>
					</div>
			<?php }
				  if(!isset($set->use_share_tickets) && !isset($set->use_app_requests) && !isset($set->use_slot)) { ?>
				  <div class="alert">
  						<button type="button" class="close" data-dismiss="alert">&times;</button>
  						<strong><?php echo _("Warning!");?></strong> <?php echo _("No options for tickets has been set. Do so in Tickets section.");?>
					</div>
			<?php }
			?>
            
            <div class="alert alert-error" id="adm_save_err" style="display:none;position:absolute">
  				<strong><?php echo _("Error!");?></strong> <?php echo _("Can't save settings, try again later.");?>
			</div>
            <div class="alert alert-success " id="adm_save_succ" style="display:none; position:absolute">

  				<strong><?php echo _("Settings saved!");?></strong> <?php echo _("Refresh page to see changes.");?>
			</div>
                    
            <div class="span8">
            	<p>
                	Viral Lottery v2.0
                </p>
            </div>
            
		  	<div class="span4 pull-right">
                <div class="btn-group" data-toggle="buttons-radio">
                	<button type="button" id="loto-settings" class="btn btn-default active"><?php echo _("Settings");?></button>
                    <button type="button" id="user-settings" class="btn btn-default"><?php echo _("Users");?></button>
                    <button type="button" id="winners-settings" class="btn btn-default"><?php echo _("Winners");?></button>
                </div>
            </div>
            
            <div class="clearfix"></div>
            
            <hr>
          
          	<div id="lottery-cont">
          	
                <div class="span8 pull-left">
                    <div class="btn-group" data-toggle="buttons-radio">
                        <button type="button" id="set1" rel="set1_1" class="set_btn btn btn-default btn-small active"><?php echo _("Main");?></button>
                        <button type="button" id="set2" rel="set2_2" class="set_btn btn btn-default btn-small"><?php echo _("Prizes");?></button>
                        <button type="button" id="set3" rel="set3_3" class="set_btn btn btn-default btn-small"><?php echo _("Messages");?></button>
                        <button type="button" id="set4" rel="set4_4" class="set_btn btn btn-default btn-small"><?php echo _("Tickets");?></button>
                        <button type="button" id="set5" rel="set5_5" class="set_btn btn btn-default btn-small"><?php echo _("Other");?></button>
                        <button type="button" id="set6" rel="set6_6" class="set_btn btn btn-default btn-small"><?php echo _("Mobile");?></button>
                    </div>
                </div>
            
                <div class="span4 pull-right inline">
                	<button type="button" id="reset_btn" class="btn btn-danger btn-small"><?php echo _("Reset / Start New");?></button>
                    
                        <button type="button" id="save_admin" class="btn btn-success btn-small"><?php echo _("Save Settings");?></button>
                    
                </div>
            
                <div class="clearfix"></div>
                
                <form name="saveloto" id="save-lottery">
                	
                    <input type="hidden" name="check-source" value="<?php echo $userdata->fake_id;?>_admset">
            
            		<!-- Main settings tab -->
                	<div id="set1_1" class="set_cont">
            		
                    	<hr>
                    	<legend><?php echo _("Main settings");?></legend>
                    	
                    	<!-- Timedate settings -->
                    	<div class="well">
                     
                        	<legend><?php echo _("Counter setup");?></legend>
                        	<fieldset>
                         		<label class="radio inline">
                              		<input type="radio" name="select_counter" id="select_time" class="count_sel" value="time" <?php echo ($set->select_counter == 'time') ? 'checked' : '';?>>
                              		<?php echo _("Use time for counter");?>
                            	</label>
                            	<label class="radio inline">
                            		<input type="radio" name="select_counter" id="select_like" class="count_sel" value="like" <?php echo ($set->select_counter == 'like') ? 'checked' : '';?>>
                            		<?php echo _("Use page Likes for counter");?>
                            	</label>
                         	</fieldset>
                         	<hr>
                        
                         	<fieldset id="time_cnt" class="count_field">
                            
                            	<h4><?php echo _("Time counter setup.");?></h4>
                            	<label><?php echo _("Starting date and time");?></label>
                            	<div id="datetimepicker1" class="input-prepend date">
                            		<span class="add-on">
                                		<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                              		</span>
                              		<input type="text" name="starts" value="<?php echo $set->starts;?>">
                            	</div>
                            
                            	<label><?php echo _("Ending date and time");?></label>
                            	<div id="datetimepicker2" class="input-append date">
                              		<input type="text" name="ends" value="<?php echo $set->ends;?>">
                              		<span class="add-on">
                                		<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                              		</span>
                            	</div>
                            	<script type="text/javascript">
                                	$('#datetimepicker1,#datetimepicker2').datetimepicker({
                                    	format: 'dd-MM-yyyy hh:mm:ss',
										weekStart: 1
                                	});
                            	</script>
                            
                            	<label><?php echo _("Select your timezone");?></label>
                            	<select name="timezone" class="span5">
                              		<?php tz_list($set->timezone);?>
                            	</select>
                                
                          </fieldset>
                        
                          <fieldset id="like_cnt" class="count_field">
                          
                              <h4><?php echo _("Like counter setup.");?></h4>
                          	  <label><?php echo _("Set Like count to start from.") . _("Your fanpage current Like Count is ") . $pagelikes;?></label>
                              <input type="text" name="start_likes" class="input-small" value="<?php echo $set->start_likes;?>">
                            
                          	  <label><?php echo _("Set Like count to reach for the end");?></label>
                              <input type="text" name="end_likes" class="input-small" value="<?php echo $set->end_likes;?>">
                            
                          </fieldset>
                          <hr>
                          <fieldset>
                          	<label><?php echo _("Counter background. Bootstrap classes for counter.");?></label>
                                <select name="counter_classes" id="counter_classes" class="input-medium">
                              		<option value="" <?php echo ($set->counter_classes == "") ? "selected" : "";?>><?php echo _("Default(grey)");?></option>
                                    <option value="btn-primary" <?php echo ($set->counter_classes == "btn-primary") ? "selected" : "";?>><?php echo _("Primary(blue)");?></option>
                                    <option value="btn-info" <?php echo ($set->counter_classes == "btn-info") ? "selected" : "";?>><?php echo _("Info(lighter blue)");?></option>
                                    <option value="btn-success" <?php echo ($set->counter_classes == "btn-success") ? "selected" : "";?>><?php echo _("Success(green)");?></option>
                                    <option value="btn-warning" <?php echo ($set->counter_classes == "btn-warning") ? "selected" : "";?>><?php echo _("Warning(orange)");?></option>
                                    <option value="btn-danger" <?php echo ($set->counter_classes == "btn-danger") ? "selected" : "";?>><?php echo _("Danger(red)");?></option>
                                    <option value="btn-inverse" <?php echo ($set->counter_classes == "btn-inverse") ? "selected" : "";?>><?php echo _("Inverse(black)");?></option>
                            	</select>
                                &nbsp;&nbsp;
                                <button type="button" id='sample_counter' class='btn btn-large <?php echo $set->counter_classes;?>' title='<?php echo $set->counter_classes;?>'
                                style='font-size:30px; min-width:180px; font-weight:bold; cursor:pointer; padding:12px'>
                                00:00:00:00
                                </button>
                                
                                <label><?php echo _("Change counter background x amount of likes or minutes before 0.");?></label>
                                
                                <div class="form-inline">
                                    <input type="text" class="input-mini" name="xbefore_end" value="<?php echo $set->xbefore_end;?>"> <?php echo _("minutes/likes");?>
                                    <select name="counter_classes_ch" id="counter_classes_ch" class="input-medium">
                                        <option value="" <?php echo ($set->counter_classes_ch == "") ? "selected" : "";?>><?php echo _("Default(grey)");?></option>
                                        <option value="btn-primary" <?php echo ($set->counter_classes_ch == "btn-primary") ? "selected" : "";?>><?php echo _("Primary(blue)");?></option>
                                        <option value="btn-info" <?php echo ($set->counter_classes_ch == "btn-info") ? "selected" : "";?>><?php echo _("Info(lighter blue)");?></option>
                                        <option value="btn-success" <?php echo ($set->counter_classes_ch == "btn-success") ? "selected" : "";?>><?php echo _("Success(green)");?></option>
                                        <option value="btn-warning" <?php echo ($set->counter_classes_ch == "btn-warning") ? "selected" : "";?>><?php echo _("Warning(orange)");?></option>
                                        <option value="btn-danger" <?php echo ($set->counter_classes_ch == "btn-danger") ? "selected" : "";?>><?php echo _("Danger(red)");?></option>
                                        <option value="btn-inverse" <?php echo ($set->counter_classes_ch == "btn-inverse") ? "selected" : "";?>><?php echo _("Inverse(black)");?></option>
                                    </select>
                                    &nbsp;&nbsp;
                                    <button type="button" id='sample_counter_change' class='btn btn-large <?php echo $set->counter_classes_ch;?>' title='<?php echo $set->counter_classes_ch;?>'
                                    style='font-size:30px; min-width:180px; font-weight:bold; cursor:pointer; padding:12px'>
                                    00:00:00:00
                                    </button>
                                </div>
                          </fieldset>
                          <hr>
                          <legend><?php echo _("Before the start");?></legend>
                          
                          <fieldset>
                          
                              <label><?php echo _("Message to show, when lottery is not started yet");?></label>
                            
                              <label><?php echo _("Title");?></label>
                              <input type="text" name="not_start_title" class="input-xxlarge" value="<?php echo $set->not_start_title;?>">
                            
                              <label><?php echo _("Message");?></label>
                        	  <textarea name="not_start_msg" rows="10" class="input-xxlarge"><?php echo $set->not_start_msg;?></textarea>
                            
                              <label class="checkbox">
                              <input type="checkbox" id="toggle_no_start_timer" name="show_start_timer" value="ON" <?php echo (isset($set->show_start_timer) ? "checked" : "");?>>
                              <?php echo _("Show counter with the amount of time or likes left to start");?>
                              </label>
                          </fieldset>
                          
                    	</div>
                    	<!-- Timedate settings -->
                    
                    	<!-- Homepage Title, Description and some other settings -->
                    	<div class="well">
                        	<legend><?php echo _("Homepage");?></legend>	 
                        	
                            <fieldset>
                            	                               
                                
                        		<label><?php echo _("Title");?></label>
                        		<input type="text" name="title" class="input-block-level" value="<?php echo $set->title;?>">
                                
                                <label><?php echo _("Subtitle");?></label>
                        		<input type="text" name="subtitle" class="input-block-level" value="<?php echo $set->subtitle;?>">
                        
                        		<label><?php echo _("Description - use HTML tags for styling");?></label>
                        		<textarea name="description" id="description" rows="10" class="input-block-level"><?php echo str_replace("<br />", "", $set->description);?></textarea> 
                        
                        		<hr>
                        		<div class="span12">
                            
                            		<label class="checkbox">
                                		<input type="checkbox" name="homepage_use_img" value="ON" <?php echo ($set->homepage_use_img == "ON") ? "checked" : "";?>>
                                		<?php echo _("Use separate image above description on homepage. Min width 600px. Do not check if you use image or video in description.");?>
                            		</label>                  
                        		</div>
                        
                        		<div class="span2">
                            		<div class="thumbnail">
                            		<img id="home_thumb" src="uploads/<?php echo $set->home_img;?>" alt="Homepage image">
                            		</div>
                            	
                                	<span id="home_img_input">
                            			<input type="hidden" name="home_img" value="<?php echo $set->home_img;?>">
                            		</span>
                            
                            		<div style="margin-top:8px; text-align:center">
                            	
                            			<button type="button" id="home_img" class="btn btn-success btn-small upload">
											<i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                		</button>
                                
                            		</div>
                        		</div>  
                                <div class="clearfix"></div>
                                <hr>
                                
                                <label><?php echo _("Page footer. Use HTML for links.");?></label>
                        		<input type="text" name="footer_info" class="input-block-level" value="<?php echo $set->footer_info;?>">    
                                <hr>       
                        </fieldset>
                        </div>
                    	<!-- Homepage Title and Description -->
                    
                    	<!-- Fangate settings -->
                    	<div class="well">
                        <legend><?php echo _("Fangate settings");?></legend>
                        	<fieldset>
                        
                        		<label class="checkbox">
                        			<input type="checkbox" name="fangate" id="toggle_fangate" value="ON" <?php echo (isset($set->fangate)) ? 'checked' : '';?>>
                        	    	<?php echo _("Use fangate. Users have to Like your fanpage first. Fill in fangate HTML or select picture.");?>
                        		</label>
                        		<hr>
                        		<div id="fan_gate_form" style="display:none">
                            		<label><?php echo _("Fangate page - use HTML tags for styling. All Bootstrap classes available.");?></label>
                            		<textarea name="fangate_description" rows="10" class="input-block-level"><?php echo $set->fangate_description;?></textarea> 
                            		<hr>
                            		<div class="span12">
                                    	<label class="checkbox">
                                    		<input type="checkbox" name="fangate_use_img" value="ON" <?php echo (isset($set->fangate_use_img)) ? 'checked' : '';?>>
                                    		<?php echo _("Use image for fangate. Min width 800px. Text from the box above will be hidden.");?>
                                			</label>                  
                                	</div>
                            		
                                    <div class="span2">
                                		<div class="thumbnail">
                                        	<img id="fangate_thumb" src="uploads/<?php echo $set->fangate_img;?>" alt="Fangate image">
                                        </div>
                                
                                		<span id="fangate_img_input">
                                    		<input type="hidden" name="fangate_img" value="<?php echo $set->fangate_img;?>">
                                		</span>
                                
                                        <div style="margin-top:8px; text-align:center">
                       						<button type="button" id="fangate_img" class="btn btn-success btn-small upload">
                                            	<i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                        	</button>
                                        </div>
                                
                            		</div>
                        		</div>
                                             
                        </fieldset>
                    	</div>
                    	<!-- Fangate settings -->
                    
                    	<!-- Security form -->
                    	<div class="well">
                    		<legend><?php echo _("Verify form");?></legend>
                      		
                            <fieldset>
                        
                        		<label class="checkbox">
                        			<input type="checkbox" name="sec_form" id="toggle_secform" value="ON" <?php echo (isset($set->sec_form)) ? 'checked' : '';?>>
                            		<?php echo _("Use a form for extra verification.");?>
                        		</label>
                        		<hr>
                        
                        		<div id="sec_form_field" style="display:none">
                                
                            		<label><?php echo _("Build a form with the simple text fields you need.");?></label>
                            		<hr>
                            	
                                	<div class="sec_form_fields span12">
                                    	
                                        <label><?php echo _("Security form title");?></label>
                                        <input type="text" name="sec_form_title" id="sec_form_title" class="input-xxlarge" value="<?php echo $set->sec_form_title;?>">
                                            
                                        <label><?php echo _("Security form description");?></label>
                                        <input type="text" name="sec_form_description" id="sec_form_descripton" class="input-xxlarge" value="<?php echo $set->sec_form_description;?>">
                                        
                                        <label><?php echo _("Button text");?></label>
                                        <input type="text" name="sec_form_btn" id="sec_form_btn" class="input-mediume" value="<?php echo $set->sec_form_btn;?>">
                                                                           	
                                   		<div>
                                        	<hr>
                                                                                       
                                            <div id="sec_wrap" class="span7">
                                            	<label><?php echo _("Name the field(s) and tick the checkbox to set it mandatory. You can see form example on right.");?></label>
                                                <?php
												// Array made at the beginning of the scipt
												// Now looping over the elements in array
												foreach($sec_fields as $key=>$field) {
													$parts = explode(";:;",$field);
													$fieldname = $parts[0];
													$checkbox = $parts[1];
													$numbr = $key+1;
													
													echo '<div id="sec_form_input_'.$numbr.'" class="form-inline sec_inp_div" style="margin-top:8px;">';
														echo '<input type="text" name="txt_'.$numbr.'" id="inp_'.$numbr.'" class="input-large" placeholder="'. _("Field name").'" value="'.$fieldname.'">&nbsp;&nbsp;';
														echo '<label class="checkbox">';
															echo '<input type="checkbox" name="txt'.$numbr.'_mand" value="mandatory" '. (($checkbox=='mandatory') ? "checked" : "") .'>'. _("Mandatory");
														echo '</label>';
														
														if($numbr > 1) {
															echo "&nbsp;&nbsp;<button type='button' id='remove_".$numbr."' class='btn btn-danger btn-mini remove' ";
															if($numbr < $numofelements) {
																echo "style='display:none;'";
															}
															echo ">". _('Remove')."</button>";
														}
														
													echo '</div>';
													
												}
												?>
                                                                                            
                                            </div>
                                            
                                            <div class="span4">
                                            	
                                                <h3 class="text-center"><?php echo _("Form Title");?></h3>
                                                <p style="text-align:justify"><?php echo _("Here will be your form description, to provide little explanation for your users. * means mandatory field.");?></p>
                                                
                                                <label><?php echo _("* Email address");?></label>
                                                <input type="text" class="input-large uneditable-input" placeholder="your@email.com">
                                               
                                                <label><?php echo _("* Phone number");?></label>
                                                <input type="text" class="input-large uneditable-input" placeholder="1234567890">
                                                <button type="button" class="btn"><?php echo _("Button Text");?></button>
                                                
                                            </div>
                                            
                                            <div class="clearfix"></div>
                                           
                                            <div class="span12" id="addfieldbtn">
                                                <hr>
                                                <label><?php echo _("Click on button to add one more field.");?></label>
                                                <button type="button" id="add_sec_field" class="btn btn-primary btn-small">
                                                    <i class="icon icon-plus-sign icon-white"></i>
                                                    <?php echo _("Add field");?>
                                                </button>
                                            </div>
                                            
                                        </div>
                                    	
                            		</div>
                            		<!-- sec_form_fields end -->
                            
                        		</div>
                                             
                        	</fieldset>
                        </div>
                        <!-- Security form -->
                    
                	</div>
                	<!-- Set1_1 end -->
                	
                    <!-- Prizes setup -->
                	<div id="set2_2" class="set_cont">
                    	<hr>
                		<legend><?php echo _("Prizes");?></legend>
                   		
                        <!-- Prize Page Title -->
                        <div class="well">
                        	<legend><?php echo _("Title for prizes page");?></legend>
                        	<fieldset>
                            	<input type="text" name="prize_page_title" id="prize_page_title" class="input-block-level" value="<?php echo $set->prize_page_title;?>">
                            </fieldset>
                        </div>
                        <!-- Prize Page Title end -->
                        
                        <!-- First Prize -->
                        <div class="well">
                        	
                            <p><?php echo _("Set up prizes for your fans. You can set up 3 different awards. Options are Amount, Title, Description and Image. Use HTML tags for syling in description. For amount give positive numeric value. 0(zero) will hide the prize from users.");?></p>
                                       
                        	<legend><?php echo _("Prize 1");?></legend>
                        	<fieldset>  
                        		<div class="form-inline">
                                    <label class="control-label" for="prize1_amount"><?php echo _("Amount");?></label>
                                    <input type="text" name="prize1_amount" id="prize1_amount" class="span1" value="<?php echo $set->prize1_amount;?>">
                                    
                                    <label class="control-label" for="prize1_title"> <?php echo _("Title");?></label>
                                    <input type="text" name="prize1_title" id="prize1_title" class="span10" value="<?php echo $set->prize1_title;?>">
                                    
                                </div>
                                <hr>
                        		<label><?php echo _("Description - use HTML tags for styling");?></label>
                        		<textarea name="prize1_description" id="prize1_description" rows="10" class="input-block-level"><?php echo str_replace("<br />", "", $set->prize1_description);?></textarea> 
                        
                        		<hr>
                        		<label><?php echo _("Choose picture");?></label>
                        		<div class="span2">
                                	
                            		<div class="thumbnail">
                            		<img id="prize1_thumb" src="uploads/<?php echo $set->prize1_img;?>" alt="">
                            		</div>
                            	
                                	<span id="prize1_img_input">
                            			<input type="hidden" name="prize1_img" value="<?php echo $set->prize1_img;?>">
                            		</span>
                            
                            		<div style="margin-top:8px; text-align:center">
                            	
                            			<button type="button" id="prize1_img" class="btn btn-success btn-small upload">
											<i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                		</button>
                                
                            		</div>
                        		</div>                      
                        	</fieldset>
                         </div>
                         <!-- First Prize ends -->
                         
                         <!-- Second Prize -->
                         <div class="well">
                        	           
                        	<legend><?php echo _("Prize 2");?></legend>
                        	<fieldset>  
                        
                        		<div class="form-inline">
                                    <label class="control-label" for="prize1_amount"><?php echo _("Amount");?></label>
                                    <input type="text" name="prize2_amount" id="prize2_amount" class="span1" value="<?php echo $set->prize2_amount;?>">
                                    
                                    <label class="control-label" for="prize1_title"> <?php echo _("Title");?></label>
                                    <input type="text" name="prize2_title" id="prize2_title" class="span10" value="<?php echo $set->prize2_title;?>">
                                    
                                </div>
                                
                        		<label><?php echo _("Description - use HTML tags for styling");?></label>
                        		<textarea name="prize2_description" id="prize2_description" rows="10" class="input-block-level"><?php echo str_replace("<br />", "", $set->prize2_description);?></textarea> 
                        
                        		<hr>
                        		<label><?php echo _("Choose picture");?></label>
                        		<div class="span2">
									<div class="thumbnail">
                                    <img id="prize2_thumb" src="uploads/<?php echo $set->prize2_img;?>" alt="">
                            		</div>
                            	
                                	<span id="prize2_img_input">
                            			<input type="hidden" name="prize2_img" value="<?php echo $set->prize2_img;?>">
                            		</span>
                            
                            		<div style="margin-top:8px; text-align:center">
                            	
                            			<button type="button" id="prize2_img" class="btn btn-success btn-small upload">
											<i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                		</button>
                                
                            		</div>
                        		</div>                      
                        	</fieldset>
                         </div>
                         <!-- Second Prize ends -->
                         
                         <!-- Third Prize -->
                         <div class="well">
                        	           
                        	<legend><?php echo _("Prize 3");?></legend>
                        	<fieldset>  
                        		
                                <div class="form-inline">
                                    <label class="control-label" for="prize3_amount"><?php echo _("Amount");?></label>
                                    <input type="text" name="prize3_amount" id="prize3_amount" class="span1" value="<?php echo $set->prize3_amount;?>">
                                    
                                    <label class="control-label" for="prize1_title"> <?php echo _("Title");?></label>
                                    <input type="text" name="prize3_title" id="prize3_title" class="span10" value="<?php echo $set->prize3_title;?>">
                                    
                                </div>
                        		<label><?php echo _("Description - use HTML tags for styling");?></label>
                        		<textarea name="prize3_description" id="prize3_description" rows="10" class="input-block-level"><?php echo str_replace("<br />", "", $set->prize3_description);?></textarea> 
                        
                        		<hr>
                        		<label><?php echo _("Choose picture");?></label>
                            		
                        		<div class="span2">
                                	<div class="thumbnail">
                            		<img id="prize3_thumb" src="uploads/<?php echo $set->prize3_img;?>" alt="">
                            		</div>
                            	
                                	<span id="prize3_img_input">
                            			<input type="hidden" name="prize3_img" value="<?php echo $set->prize3_img;?>">
                            		</span>
                            
                            		<div style="margin-top:8px; text-align:center">
                            	
                            			<button type="button" id="prize3_img" class="btn btn-success btn-small upload">
											<i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                		</button>
                                
                            		</div>
                        		</div>                      
                        	</fieldset>
                         </div>
                         <!-- Third Prize ends -->
                	                         
                	</div>
             		<!-- Set2_2 end -->
                
                	<div id="set3_3" class="set_cont">
                	    <hr>
                		<legend><?php echo _("Timeline posts, emails and info messages");?></legend>
                   		
                        <!-- Post to users timelines -->
                        <div class="well">
                        	<fieldset>
                            <legend><?php echo _("Post to users timelines");?></legend>
                            
                            	<label class="checkbox">
                        			<input type="checkbox" name="post_timeline_check" id="toggle_post_timeline" value="ON" <?php echo (isset($set->post_timeline_check)) ? 'checked' : '';?>>
                            		<?php echo _("Post message to users timelines");?>
                        		</label>
                            	
                                <div id="timeline_post_fields" style="display:none">
                                    <label><?php echo _("Make direct post to all users or set the amount of random users to post. It's possible when long term tokens are saved. But be patient if you have many users, it will take some time. Attention! Message shows up as users personal message to their friends. Keep that in mind while composing it!");?></label>
                                    <hr>
                                    <div class="alert alert-info" id="timeline_info_msg" style="display:none"></div>
                                    
                                    <div class="span9">
                                        <label><?php echo _("Title");?></label>
                                        <input type="text" class="input-xxlarge" id="timeline_title">
                                        
                                        <label><?php echo _("Message");?></label>
                                        <textarea class="input-xxlarge" rows="3" id="timeline_message"></textarea>
                                        <label>
                                            <input type="text" id="timeline_amount" class="input-mini" value="0">
                                            <?php echo _(" Insert amount of random users, who will get that post. 0 = all users.");?>
                                        </label>
                                        <button type="button" id="timeline_send" class="btn"><?php echo _("Send");?></button>
                                        <button type="button" id="timeline_send_fake" class="btn" style="display:none"><?php echo _("Posting...");?></button>
                                    </div>
                                    
                                    <div class="span2">
                                        <label><?php echo _("Picture");?></label>
                                        <div class="span2">
                                                        
                                            <div class="thumbnail">
                                                <img id="timeline_thumb" src="img/timeline_placeholder.png" alt="">
                                            </div>
                                                        
                                            <span id="timeline_img_input">
                                                <input type="hidden" name="timeline_img" id="timeline_img" value="img/timeline_placeholder.png">
                                            </span>
                                                    
                                            <div style="margin-top:8px; text-align:center">
                                                        
                                                <button type="button" id="timeline_img" class="btn btn-success btn-small upload">
                                                    <i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                                </button>
                                                        
                                            </div>
                                                            
                                        </div> 
                                    </div>
                                    <div class="clearfix"></div>
                                
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Post to users timelines -->
                        
                        <!-- Newsletter -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Bulk, instant email to all joined users");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="send_bulk_email" id="toggle_bulk_email" value="ON" <?php echo (isset($set->send_bulk_email)) ? 'checked' : '';?>>
                            		<?php echo _("Send email to all users right now. ");?>
                        		</label>
                                
                                <div id="bulk_email_fields" style="display:none"> 
                                	<p><?php echo _("Emails to all users with BCC(blind carbon copy) method.");?></p>
                                    <p><?php echo _("Note: Some servers might need SMTP to send emails with BCC.");?></p>
                                    
                                    <hr>
                                    <div class="alert alert-info" id="bulk_email_info_msg" style="display:none; width:500px"></div>
                                    <div class="clearfix"></div>
                                    <label><?php echo _("Subject.");?></label>
                                    <input type="text" class="input-xxlarge" id="bulk_email_subject" placeholder="Write your subject line">
                                    
                                    <label><?php echo _("Email message. [APPLINK] shortcode available. Use HTML as you like.");?></label>
                                    <textarea class="input-xxlarge" rows="4" id="bulk_email_body" placeholder="Write your message"></textarea>
                                    <br>
                                    <button type="button" class="btn" id="bulk_email_send"><?php echo _("SEND");?></button>
                                </div>
                                
                            </fieldset>
                        </div>

                        <!-- Newsletter  -->
                        
                        
                        <!-- Email to user when someone comes with link or request -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Referred user notification");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="send_ref_email" id="toggle_ref_email" value="ON" <?php echo (isset($set->send_ref_email)) ? 'checked' : '';?>>
                            		<?php echo _("Send email, when someone joins via user request or via shared link");?>
                        		</label>
                                
                                <div id="ref_email_fields" style="display:none">
                                    <label><?php echo _("Subject. [NAME] shortcode available");?></label>
                                    <input type="text" class="input-xxlarge" name="ref_email_subject" value="<?php echo $set->ref_email_subject;?>">
                                    
                                    <label><?php echo _("Email message. [NAME], [REFNAME] and [APPLINK] shortcodes available");?></label>
                                    <textarea class="input-xxlarge" rows="4" name="ref_email_body"><?php echo $set->ref_email_body;?></textarea>
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Email to user when someone comes with link or request -->
                        
                        <!-- Email to winners -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Emails for winners");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="send_win_email" id="toggle_win_email" value="ON" <?php echo (isset($set->send_win_email)) ? 'checked' : '';?>>
                            		<?php echo _("Send emails to winners after end");?>
                        		</label>
                                
                                <div id="win_email_fields" style="display:none">
                                	<label><?php echo _("Subject. [NAME] shortcode available");?></label>
                                    <input type="text" class="input-xxlarge" name="win_email_subject" value="<?php echo $set->win_email_subject;?>">
                                    
                                    <label><?php echo _("Email message. [NAME], [PRIZE] and [APPLINK] shortcodes available");?></label>
                                    <textarea class="input-xxlarge" rows="4" name="win_email_body"><?php echo $set->win_email_body;?></textarea>
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Email to winners -->
                        
                        <!-- Email to admin after end -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Send notification to admin after end");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="send_end_email" id="toggle_end_email" value="ON" <?php echo (isset($set->send_end_email)) ? 'checked' : '';?>>
                            		<?php echo _("Send me email when raffle has ended");?>
                        		</label>
                                
                                <div id="end_email_fields" style="display:none">
                                	<label><?php echo _("Subject");?></label>
                                    <input type="text" class="input-xxlarge" name="end_email_subject" value="<?php echo $set->end_email_subject;?>">
                                    
                                    <label><?php echo _("Message");?></label>
                                    <textarea class="input-xxlarge" rows="4" name="end_email_body"><?php echo $set->end_email_body;?></textarea>
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Email to admin after end -->
                        
                        <!-- Email to all when new event starts -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("New raffle notification email");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="send_new_email" id="toggle_new_email" value="ON" <?php echo (isset($set->send_new_email)) ? 'checked' : '';?>>
                            		<?php echo _("Send email to all users when new event starts. ");?>
                        		</label>
                                
                                <div id="new_email_fields" style="display:none"> 
                                	<p><?php echo _("Emails will be sent right after you click RESET button. All users added as receivers of BCC(blind carbon copy).");?></p>
                                    <p><?php echo _("Attention! Some servers might require SMTP method to send BCC.");?></p>
                                    <hr>
                                    <label><?php echo _("Subject.");?></label>
                                    <input type="text" class="input-xxlarge" name="new_email_subject" value="<?php echo $set->new_email_subject;?>">
                                    
                                    <label><?php echo _("Email message. [PRIZES] and [APPLINK] shortcodes available");?></label>
                                    <textarea class="input-xxlarge" rows="4" name="new_email_body"><?php echo $set->new_email_body;?></textarea>
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Email to all when new event starts  -->
                        
                        <!-- Help&Rulez -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Explain Rules and other info");?></legend>
                                                                
                                <label><?php echo _("Describe all clearly. Style with HTML.");?></label>
                                <textarea class="input-block-level" rows="10" name="rules_and_help_page"><?php echo $set->rules_and_help_page;?></textarea>
                                
                            </fieldset>
                        </div>
                        <!-- Help&Rulez  -->
                        
                        <!-- Terms & Conditions -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Terms & Conditions");?></legend>
                                                                
                                <label><?php echo _("Create Terms and Conditions page. Link will be placed to the footer. Style with HTML.");?></label>
                                <textarea class="input-block-level" rows="10" name="terms_page"><?php echo (isset($set->terms_page)) ? $set->terms_page : '';?></textarea>
                                
                            </fieldset>
                        </div>
                        <!-- Terms & Conditions  -->
                        
                        <!-- Disclaimer -->
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Disclaimer");?></legend>
                                                                
                                <label><?php echo _("Create Disclaimer page. Link will be placed to the footer. Style with HTML.");?></label>
                                <textarea class="input-block-level" rows="10" name="disclaimer_page"><?php echo (isset($set->disclaimer_page)) ? $set->disclaimer_page : '';?></textarea>
                                
                            </fieldset>
                        </div>
                        <!-- Disclaimer  -->
                        
                	</div>
                	<!-- Set3_3 end -->
                	
                	<div id="set4_4" class="set_cont">
                    	<hr>
                		<legend><?php echo _("Tickets Setup");?></legend>
                   		<p><?php echo _("Yo can use three options to give tickets to users. Share, App requests and Slot Machine. You have to use at least one from these options.");?></p>
                        
                        <!-- Options -->
                        <div class="well">
                        	<fieldset>
                            	<label><?php echo _("Description for info-bubble(opens on hover over 'i' icon) above the 'Get more tickets' buttons. Describe all limits and intervals what user can face.");?></label>
                                <textarea name="btns_info_bubble" class="input-xxlarge" rows="4"><?php echo $set->btns_info_bubble;?></textarea>
                            </fieldset>
                        </div>
                        <!-- Options -->
                        
                        <!-- Tickets to admin -->
                        <div class="well">
            				<fieldset>
                            	<legend><?php echo _("Test tickets");?></legend>
                                <p><?php echo _("Choose for testing only. After uncheck, all admin tickets will be deleted if there is any.");?></p>                              
                                <label class="checkbox">
                        			<input type="checkbox" name="give_admin_tickets" value="ON" <?php echo (isset($set->give_admin_tickets)) ? 'checked' : '';?>>
                            		<?php echo _("Give tickets to admin.");?>
                        		</label>
                            </fieldset>
                        </div>
                        
                        <!-- Tickets setup -->
                        <div class="well">
            				<fieldset>
                            	<legend><?php echo _("Tickets for sharing");?></legend>
                                                                
                                <label class="checkbox">
                        			<input type="checkbox" name="use_share_tickets" id="toggle_share_tickets" value="ON" <?php echo (isset($set->use_share_tickets)) ? 'checked' : '';?>>
                            		<?php echo _("Use Sharethis widget for tickets.");?>
                        		</label>
           
                                <!-- sharing options -->
                                <div id="share_tickets_field" style="display:none">
                                	
                                    <label><?php echo _("Sharethis publisher KEY. You can get it here:");?> <a href="https://sharethis.com/publishers/get-sharing-tools" target="_blank"><?php echo _("Sharethis");?></a></label>
                            		<input type="text" name="sharethis_pubkey" class="input-xlarge" value="<?php echo $set->sharethis_pubkey;?>">
                                    
                                    <label><?php echo _("Share button text");?></label>
                                    <input type="text" name="share_btn_txt" class="input-xlarge" value="<?php echo $set->share_btn_txt;?>">
                                    
                                    <label><?php echo _("Button color. Bootstrap color casses.");?></label>
                                    <select name="share_btn_color" id="share_btn_color" class="input-medium">
                                        <option value="" <?php echo ($set->share_btn_color == "") ? "selected" : "";?>><?php echo _("Default(grey)");?></option>
                                        <option value="btn-primary" <?php echo ($set->share_btn_color == "btn-primary") ? "selected" : "";?>><?php echo _("Primary(blue)");?></option>
                                        <option value="btn-info" <?php echo ($set->share_btn_color == "btn-info") ? "selected" : "";?>><?php echo _("Info(lighter blue)");?></option>
                                        <option value="btn-success" <?php echo ($set->share_btn_color == "btn-success") ? "selected" : "";?>><?php echo _("Success(green)");?></option>
                                        <option value="btn-warning" <?php echo ($set->share_btn_color == "btn-warning") ? "selected" : "";?>><?php echo _("Warning(orange)");?></option>
                                        <option value="btn-danger" <?php echo ($set->share_btn_color == "btn-danger") ? "selected" : "";?>><?php echo _("Danger(red)");?></option>
                                        <option value="btn-inverse" <?php echo ($set->share_btn_color == "btn-inverse") ? "selected" : "";?>><?php echo _("Inverse(black)");?></option>
                                    </select>
                                    &nbsp;&nbsp;
                                    <button type="button" id='share_btn_sample' class='btn btn-large <?php echo $set->share_btn_color;?>' title='<?php echo $set->share_btn_color;?>'
                                    style='font-size:18px; min-width:180px; font-weight:bold; cursor:pointer; padding:12px'>
                                    <?php echo _("Button Text");?>
                                    </button>
                                    <hr>
                                    <label><?php echo _("Short description, message inside share widget.");?></label>
                                    <textarea name="share_content" class="input-xlarge"><?php echo $set->share_content;?></textarea>
                                    
                                    <label><?php echo _("Set image to share");?></label>
                                        
                                    <div class="span2">
                                        <div class="thumbnail">
                                        	<img id="share_thumb" src="uploads/<?php echo $set->share_img;?>" alt="">
                                        </div>
                                    
                                        <span id="share_img_input">
                                            <input type="hidden" name="share_img" value="<?php echo $set->share_img;?>">
                                        </span>
                                
                                        <div style="margin-top:8px; text-align:center">
                                    
                                            <button type="button" id="share_img" class="btn btn-success btn-small upload">
                                                <i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                            </button>
                                    
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <hr>
                                    
                                    <label><?php echo _("Amount of tickets per one joined user.");?></label>
                                    <input type="text" name="share_ticket_amount" class="input-mini" value="<?php echo $set->share_ticket_amount;?>">
                                    
                                    <label class="help-block"><?php echo _("Set interval for sharing. 0 = always available. If interval is bigger than 0, users have to wait until button is available again. There will be counter instead of button text.");?></label>
                                    <label>
                                    <input type="text" name="share_ticket_int" class="input-mini" value="<?php echo $set->share_ticket_int;?>"> <?php echo _("hours");?>
                                    </label>
                            	</div>
                                <!-- sharing options end -->
                                
                            </fieldset>
                        </div>
                        <!-- Tickets setup end -->
                        
                        <!-- Requests setup -->
                        <div class="well">
            				<fieldset>
                            	<legend><?php echo _("Tickets for app requests");?></legend>
                                <p><?php echo _("This option uses Facebooks app requests. Approved requests will bring tickets to user who made requests.");?></p>
                                
                                <label class="checkbox">
                        			<input type="checkbox" name="use_app_requests" id="use_app_requests" value="ON" <?php echo ($set->use_app_requests == 'ON') ? 'checked' : '';?>>
                            		<?php echo _("Use app requests for tickets.");?>
                        		</label>
                                
                                <!-- Requests options -->  
                                <div id="request_options_field" style="display:none">
                                	<hr>
                                	
                                    <label><?php echo _("Set limit for requests. 0 = no limits. This limit will be as total amount of requests on current event/raffle");?></label>
                                	<input type="text" name="request_limit" class="input-mini" value="<?php echo $set->request_limit;?>">
                                                                        
                                    <label><?php echo _("Amount of tickets for one approved request.");?></label>
                                	<input type="text" name="request_ticket_amount" class="input-mini" value="<?php echo $set->request_ticket_amount;?>">
                                    
                                    <label><?php echo _("Delete unanswered requests after X days. 1 is default. Function will run when admin loads app page.");?></label>
                                	<input type="text" name="request_delete_day" class="input-mini" value="<?php echo $set->request_delete_day;?>">
                                    
                                    <label><?php echo _("Request button text");?></label>
                                    <input type="text" name="req_btn_txt" class="input-xlarge" value="<?php echo $set->req_btn_txt;?>">
                                    
                                    <label><?php echo _("Button color. Bootstrap color casses.");?></label>
                                    <select name="req_btn_color" id="req_btn_color" class="input-medium">
                                        <option value="" <?php echo ($set->req_btn_color == "") ? "selected" : "";?>><?php echo _("Default(grey)");?></option>
                                        <option value="btn-primary" <?php echo ($set->req_btn_color == "btn-primary") ? "selected" : "";?>><?php echo _("Primary(blue)");?></option>
                                        <option value="btn-info" <?php echo ($set->req_btn_color == "btn-info") ? "selected" : "";?>><?php echo _("Info(lighter blue)");?></option>
                                        <option value="btn-success" <?php echo ($set->req_btn_color == "btn-success") ? "selected" : "";?>><?php echo _("Success(green)");?></option>
                                        <option value="btn-warning" <?php echo ($set->req_btn_color == "btn-warning") ? "selected" : "";?>><?php echo _("Warning(orange)");?></option>
                                        <option value="btn-danger" <?php echo ($set->req_btn_color == "btn-danger") ? "selected" : "";?>><?php echo _("Danger(red)");?></option>
                                        <option value="btn-inverse" <?php echo ($set->req_btn_color == "btn-inverse") ? "selected" : "";?>><?php echo _("Inverse(black)");?></option>
                                    </select>
                                    &nbsp;&nbsp;
                                    <button type="button" id='req_btn_sample' class='btn btn-large <?php echo $set->req_btn_color;?>' title='<?php echo $set->req_btn_color;?>'
                                    style='font-size:18px; min-width:180px; font-weight:bold; cursor:pointer; padding:12px'>
                                    <?php echo _("Button Text");?>
                                    </button>
                                    <hr>
                                                                        
                                    <label class="help-block"><?php echo _("Set interval for requests. 0 = always available. If interval is bigger than 0, users have to wait until button is available again. There will be counter instead of button text.");?></label>
                                    <input type="text" name="request_ticket_int" class="input-mini" value="<?php echo $set->request_ticket_int;?>"> <?php echo _("hours");?>
                                    
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Requests setup end -->
                        
                        <!-- Slot Machine setup -->
                        <div class="well">
            				<fieldset>
                            	<legend><?php echo _("Slot Machine for winning tickets");?></legend>
                                <p><?php echo _("3-wheeler Slot Machine to spin for users. You can set up wins and other options.");?></p>
                                
                                <label class="checkbox">
                        			<input type="checkbox" name="use_slot" id="use_slot" value="ON" <?php echo ($set->use_slot == 'ON') ? 'checked' : '';?>>
                            		<?php echo _("Use Slot Machine for tickets.");?>
                        		</label>
                                
                                <!-- Slot machine options -->  
                                <div id="slot_options_field" style="display:none">
                                	
                                    <hr>
                                    
                                    <label><?php echo _("Slot Machine opener button text");?></label>
                                    <input type="text" name="slot_btn_txt" class="input-xlarge" value="<?php echo $set->slot_btn_txt;?>">
                                    
                                    <label><?php echo _("Button color. Bootstrap color casses.");?></label>
                                    <select name="slot_btn_color" id="slot_btn_color" class="input-medium">
                                        <option value="" <?php echo ($set->slot_btn_color == "") ? "selected" : "";?>><?php echo _("Default(grey)");?></option>
                                        <option value="btn-primary" <?php echo ($set->slot_btn_color == "btn-primary") ? "selected" : "";?>><?php echo _("Primary(blue)");?></option>
                                        <option value="btn-info" <?php echo ($set->slot_btn_color == "btn-info") ? "selected" : "";?>><?php echo _("Info(lighter blue)");?></option>
                                        <option value="btn-success" <?php echo ($set->slot_btn_color == "btn-success") ? "selected" : "";?>><?php echo _("Success(green)");?></option>
                                        <option value="btn-warning" <?php echo ($set->slot_btn_color == "btn-warning") ? "selected" : "";?>><?php echo _("Warning(orange)");?></option>
                                        <option value="btn-danger" <?php echo ($set->slot_btn_color == "btn-danger") ? "selected" : "";?>><?php echo _("Danger(red)");?></option>
                                        <option value="btn-inverse" <?php echo ($set->slot_btn_color == "btn-inverse") ? "selected" : "";?>><?php echo _("Inverse(black)");?></option>
                                    </select>
                                    &nbsp;&nbsp;
                                    <button type="button" id='slot_btn_sample' class='btn btn-large <?php echo $set->slot_btn_color;?>' title='<?php echo $set->slot_btn_color;?>'
                                    style='font-size:18px; min-width:180px; font-weight:bold; cursor:pointer; padding:12px'>
                                    <?php echo _("Button Text");?>
                                    </button>
                                    <hr>
                               
                                	<label><?php echo _("Slot Machine page title");?></label>
                                    <input type="text" name="slot_title" class="input-xxlarge" value="<?php echo $set->slot_title;?>">
                                    
                                    <label><?php echo _("Slot Machine page description");?></label>
                                    <textarea name="slot_description" rows="5" class="input-xxlarge"><?php echo $set->slot_description;?></textarea>
                                    
                                    <label><?php echo _("Amount of free spins.");?></label>
                                	<input type="text" name="slot_free_spins" class="input-mini" value="<?php echo $set->slot_free_spins;?>">
                                    
                                    <label class="help-block"><?php echo _("Set interval for Slot Machine. Can't be zero. 0 or empty field will be replaced by 24.");?></label>
                                    <input type="text" name="slot_ticket_int" class="input-mini" value="<?php echo $set->slot_ticket_int;?>"> <?php echo _("hours");?>
                                    
                                    <hr>
                                              
                                    <label><?php echo _("Slot Machine reels. Reel can contain clover, heart or star, separated by comma.");?></label>
                                    <label class="help-block"><?php echo _("Example: clover,heart,clover,heart,star,clover");?></label>
                                    
                                    <div class="input-prepend">
                                      <span class="add-on"><?php echo _("Reel 1");?></span>
                                      <input name="reel_1" class="input-xxlarge" id="reel_1" type="text" value="<?php echo $set->reel_1;?>">
                                    </div>
                                    <div class="input-prepend">
                                      <span class="add-on"><?php echo _("Reel 2");?></span>
                                      <input name="reel_2" class="input-xxlarge" id="reel_2" type="text" value="<?php echo $set->reel_2;?>">
                                    </div>
                                    <div class="input-prepend">
                                      <span class="add-on"><?php echo _("Reel 3");?></span>
                                      <input name="reel_3" class="input-xxlarge" id="reel_3" type="text" value="<?php echo $set->reel_3;?>">
                                    </div>
                                    
                                    <label><?php echo _("Wins for combinations. Wheels have 3 different pictures. Clover, heart and star. Set amount of tickets users will get for each combination. 0 is nothing.");?></label> 
                                    
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/clover-mini.png" class="img-polaroid">
                                        <img src="img/slot/clover-mini.png" class="img-polaroid">
                                        <img src="img/slot/x.png" class="img-polaroid">
                                        <input type="text" name="clover_2_win" class="input-mini" value="<?php echo $set->clover_2_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/clover-mini.png" class="img-polaroid">
                                        <img src="img/slot/clover-mini.png" class="img-polaroid">
                                        <img src="img/slot/clover-mini.png" class="img-polaroid">
                                        <input type="text"  name="clover_3_win" class="input-mini" value="<?php echo $set->clover_3_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/heart-mini.png" class="img-polaroid">
                                        <img src="img/slot/heart-mini.png" class="img-polaroid">
                                        <img src="img/slot/x.png" class="img-polaroid">
                                        <input type="text" name="heart_2_win" class="input-mini" value="<?php echo $set->heart_2_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/heart-mini.png" class="img-polaroid">
                                        <img src="img/slot/heart-mini.png" class="img-polaroid">
                                        <img src="img/slot/heart-mini.png" class="img-polaroid">
                                        <input type="text" name="heart_3_win" class="input-mini" value="<?php echo $set->heart_3_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/star-mini.png" class="img-polaroid">
                                        <img src="img/slot/star-mini.png" class="img-polaroid">
                                        <img src="img/slot/x.png" class="img-polaroid">
                                        <input type="text" name="star_2_win" class="input-mini" value="<?php echo $set->star_2_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <div style="margin-bottom:6px">
                                    	<img src="img/slot/star-mini.png" class="img-polaroid">
                                        <img src="img/slot/star-mini.png" class="img-polaroid">
                                        <img src="img/slot/star-mini.png" class="img-polaroid">
                                        <input type="text" name="star_3_win" class="input-mini" value="<?php echo $set->star_3_win;?>" style="margin-bottom:-2px;">
                                    </div>
                                    <hr>                                  
                                   	<div>
                                        <label class="checkbox">
                                            <input type="checkbox" name="slot_timeline_toggle" id="slot_timeline_toggle" value="ON" <?php echo (isset($set->slot_timeline_toggle)) ? 'checked' : '';?>>
                                            <?php echo _("Users must post result to their timeline to collect tickets");?>
                                        </label>
                                    </div>
                                    <div id="slot_timeline" style="display:none">
                                        <legend><?php echo _("Timeline message settings");?></legend>
                                            
                                        <div class="control-group">
                                            <label class="control-label" for="slot_msg_title"><?php echo _("Title. Shortcode [AMOUNT] available. WIll be replaced by winned amount of tickets");?></label>
                                            <div class="controls">
                                                <input type="text" class="input-xxlarge" name="slot_msg_title" id="slot_msg_title" value="<?php echo $set->slot_msg_title;?>">
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label" for="slot_msg_description"><?php echo _("Description.");?></label>
                                            <div class="controls">
                                                <textarea class="input-xxlarge" rows="4" name="slot_msg_description" id="slot_msg_description"><?php echo $set->slot_msg_description;?></textarea>
                                            </div>
                                        </div>
                                        
                                        <div class="control-group">
                                            <label class="control-label" for="slot_msg_caption"><?php echo _("Caption");?></label>
                                            <div class="controls">
                                                <input type="text" class="input-xxlarge" name="slot_msg_caption" id="slot_msg_caption" value="<?php echo $set->slot_msg_caption;?>">
                                            </div>
                                        </div>
                                            
                                        <div class="control-group">
                                                
                                        <label class="control-label" for="slotmsg_thumb"><?php echo _("Image");?></label>
                                                
                                            <div class="span2">
                                                
                                                <div class="thumbnail">
                                                    <img id="slotmsg_thumb" src="uploads/<?php echo $set->slotmsg_img;?>" alt="">
                                                </div>
                                                
                                                <span id="slotmsg_img_input">
                                                    <input type="hidden" name="slotmsg_img" value="<?php echo $set->slotmsg_img;?>">
                                                </span>
                                            
                                                <div style="margin-top:8px; text-align:center">
                                                
                                                    <button type="button" id="slotmsg_img" class="btn btn-success btn-small upload">
                                                        <i class="icon-upload icon-white"></i>&nbsp;<?php echo _("Change");?>
                                                    </button>
                                                
                                                </div>
                                                    
                                            </div> 
                                        
                                        </div>
                                    </div><!-- Slot timeline -->
                                    
                                </div>
                                <!-- Slot machine options end -->
                            </fieldset>
                        </div>
                        <!-- Slot Machine setup end -->
                        
                	</div>
                	<!-- Set4_4 end -->
            
                	<div id="set5_5" class="set_cont">
                	    <hr>
                        
                        <legend><?php echo _("Some more adjustments");?></legend>
                        
                        <!-- Admin settings -->
                        <div class="well">
                        
            				<fieldset>
                            	<legend><?php echo _("Email sending");?></legend>
                                
                                <label><?php echo _("Admin email address");?></label>
                                <input type="text" class="input-xlarge" name="admin_email" value="<?php echo $set->admin_email;?>">
                                <label><?php echo _("From/Admin name");?></label>
                                <input type="text" class="input-xlarge" name="admin_name" value="<?php echo $set->admin_name;?>">
                                
                                <label class="checkbox">
                                	<input type="checkbox" name="smtp_emails" id="smtp_emails_toggle" value="ON" <?php echo (isset($set->smtp_emails)) ? "checked" : "";?>>
                                	<?php echo _("Send emails using PHPMailers SMTP feature. Uncheck = simple sendmail() function.");?>
                            	</label>
                                
                                <div id="smtp_fields" style="display:none">
                                
                                    <label><?php echo _("Hostname of the mail server");?></label>
                                    <input type="text" class="input-xlarge" name="smtp_host" value="<?php echo $set->smtp_host;?>">
                                    
                                    <label><?php echo _("SMTP port number - likely to be 25, 465 or 587");?></label>
                                    <input type="text" class="input-mini" name="smtp_port" value="<?php echo $set->smtp_port;?>">
                                    
                                    <label><?php echo _("Username to use for SMTP authentication");?></label>
                                    <input type="text" class="input-xlarge" name="smtp_user" value="<?php echo $set->smtp_user;?>">
                                    
                                    <label><?php echo _("Password to use for SMTP authentication");?></label>
                                    <input type="text" class="input-xlarge" name="smtp_pass" value="<?php echo $set->smtp_pass;?>">
                                
                                </div>
                                
                            </fieldset>
                        </div>
                        <!-- Admin settings -->
                        
                        <!-- Other settings -->
                        <div class="well">
                        
            				<fieldset>
                            	
                                <legend><?php echo _("Language");?></legend>
                                
                                <select name="app_lang">
									<?php get_lang_list('locale', $set->app_lang);?>
								</select>
                            	
                            	<legend><?php echo _("Maintenance");?></legend>
                                
                                <label class="checkbox">
                                	<input type="checkbox" name="maintenance" value="ON" <?php echo (isset($set->maintenance)) ? "checked" : "";?>>
                                	<?php echo _("Under maintenance if checked. Still available for admin(s)");?>
                            	</label>
                                <label><?php echo _("Maintenance message to users.");?></label>
                                <textarea class="input-xxlarge" name="maint_msg" rows="4"><?php echo $set->maint_msg;?></textarea>
                                
                                <legend><?php echo _("Options for picking winners");?></legend>
                                  	
                                <label class="radio">
                                	<input type="radio" name="winner_pick" value="random" <?php echo ($set->winner_pick == 'random') ? 'checked' : '';?> >
                                	 <?php echo _("By Random Ticket");?>
                                </label>
                                <label class="radio">
                                	<input type="radio" name="winner_pick" value="ticket_amount" <?php echo ($set->winner_pick == 'ticket_amount') ? 'checked' : '';?>  >
                                    <?php echo _("By Leaderboard Ranking");?>
                                </label>
                                <div class="form-inline">
                                    <input type="text" class="input-mini" name="min_participants" value="<?php echo $set->min_participants;?>"> <?php echo _("Minimum amount of participants needed. Otherwise show next message:");?>
                                </div>
                                <label><?php echo _("Show that message instead of winners");?></label>
                                <textarea class="input-xxlarge" rows="4" name="min_part_msg"><?php echo (isset($set->min_part_msg)) ? $set->min_part_msg : '';?></textarea>
                                
                                    
                                <legend><?php echo _("Homepage");?></legend>     
                                <label class="form-inline">
                                	<input type="text" class="input-mini" name="homepage_show_users_thumbs" value="<?php echo $set->homepage_show_users_thumbs;?>">
                                	<?php echo _(" users thumbnails on homepage. 0 or empty equals none.");?>
                            	</label>                                  	
                                
                                <label class="checkbox">
                                	<input type="checkbox" name="homepage_show_comments" value="ON" <?php echo (isset($set->homepage_show_comments)) ? "checked" : "";?>>
                                	<?php echo _("Show Facebook comments on homepage");?>
                            	</label>
                                
                                <label class="checkbox">
                                	<input type="checkbox" name="homepage_show_stats" value="ON" <?php echo (isset($set->homepage_show_stats)) ? "checked" : "";?>>
                                	<?php echo _("Show amount of joined users and tickets above title");?>
                            	</label>
                                
                                <legend><?php echo _("Leaderboard");?></legend>  
                                <label class="checkbox">
                                	<input type="checkbox" name="lboard_link" value="ON" <?php echo (isset($set->lboard_link)) ? "checked" : "";?>>
                                	<?php echo _("Add links to Leaderboard names, goes to user Facebook profile on new tab/page");?>
                            	</label>                                  	
                                                                
                                <label class="form-inline">
                                <select name="leaders_amount" class="input-mini">
                                  <?php
								  $sel_lead = (isset($set->leaders_amount)) ? $set->leaders_amount : 10;
								  	for($i=5; $i <= 50; $i += 5) {
										$sel = ($sel_lead == $i) ? "selected" : "" ;
										echo '<option value="'.$i.'" '.$sel.'>'.$i.'</option>';
									}
								  ?>
                                </select>
                                <?php echo _("Users on leaderboard");?>
                                </label>
                                
                                <legend><?php echo _("Longterm User Tokens");?></legend>
                                <label class="checkbox">
                                	<input type="checkbox" name="long_token" value="ON" <?php echo (isset($set->long_token)) ? "checked" : "";?>>
                                	<?php echo _("Save long term tokens for users. Needed for autoposting.");?>
                            	</label> 
                                <hr>
                                <legend><?php echo _("Ads");?></legend>
                                <p><?php echo _("Ad fields below are actually for any kind of HTML content. Like text widgets on WordPress. Use these as you like.");?></p>
                                <label><?php echo _("Header max 800px. Insert banner code for header. Generate banner somewhere and paste code here. Will be at the top of the main page. Empty field = not visible");?></label>
                                <textarea name="head_ad" class="input-block-level" rows="4"><?php echo $set->head_ad;?></textarea>
                                <hr>
                            	<label><?php echo _("Sidebar max 300px. Insert banner code for sidebar. Generate banner somewhere and paste code here. Will be placed below of the user data. Empty field = not visible");?></label>
                                <textarea name="sidebar_ad" class="input-block-level" rows="4"><?php echo $set->sidebar_ad;?></textarea>
                               
                            </fieldset>
                        </div>
                        <!-- Other settings end -->
                        
                	</div>
                	<!-- Set5_5 end -->
                    
                    <!-- Set 6_6 -->
                    <div id="set6_6" class="set_cont">
                	    <hr>
                        <!-- Mobile page settings -->
                        <legend><?php echo _("Settings for mobile page");?></legend>
                        
                        <p><?php echo _("Mobile page is just simple static page, with no functions. You can set page text and amount of tickets for mobile users, when user wants to come back. When someone joins via mobile, they can send unique link to their mailbox to use with computer. Explain how to use that link and etc.");?></p>
                        
                        <div class="well">
                        	<fieldset>
                            	<legend><?php echo _("Mobile home page");?></legend>
                                <label><?php echo _("Page title");?></label>
                                <input type="text" name="mob_page_title" class="input-xxlarge" value="<?php echo (isset($set->mob_page_title)) ? $set->mob_page_title : '';?>">
                                
                                <label><?php echo _("Page description. Shortcodes [ENDTIME] and [TICKETAMOUNT] available.");?></label>
                                <textarea name="mob_page_description" rows="6" class="input-xxlarge"><?php echo (isset($set->mob_page_description)) ? $set->mob_page_description : '';?></textarea>
                                
                                <label><?php echo _("Amount of free tickets if user will be back with computer");?></label>
                                <input type="text" name="mob_page_tickets" class="input-mini" value="<?php echo (isset($set->mob_page_tickets)) ? $set->mob_page_tickets : '';?>">
                                
                            </fieldset>
                            <fieldset>
                            <legend><?php echo _("Email for link sending");?></legend>
                                
                                <label><?php echo _("Subject. [NAME] shortcode available");?></label>
                                <input type="text" name="mob_email_subject" class="input-xxlarge" value="<?php echo (isset($set->mob_email_subject)) ? $set->mob_email_subject : '';?>">
                                
                                <label><?php echo _("Message. Shortcodes [NAME] and [LINK] available. Link is MUST, otherwise it goes without link!");?></label>
                                <textarea name="mob_email_message" rows="6" class="input-xxlarge"><?php echo (isset($set->mob_email_message)) ? $set->mob_email_message : '';?></textarea>
                                
                                
                            </fieldset>
                        </div>
                        <!-- Mobile page settings -->
                        
                    </div>
                    <!-- Set 6_6 end -->
             
                </form>
                
            </div><!--LOTTERY CONTENT-->
          	
            <!--USERS CONTENT-->
            <div id="users-cont" style="display:none">
          		<?php echo _("Loading...");?>
          	</div><!--USERS CONTENT-->
          
            <!--WINNERS CONTENT-->
          	<div id="winners-cont" style="display:none">
            	<?php echo _("Loading...");?>
            </div><!--WINNERS CONTENT-->
    
         </div> 
         <?php }?>
         <!-- #tab4 -->
         
         
         <!-- #tab2 -->
         <div id="tab2" class="tab-pane">
		 <?php echo _("Loading leaderboard ...");?>
         </div>
         <!-- #tab2 -->
         
         <!-- #tab3 -->
         <div id="tab3" class="tab-pane">
             <?php echo $set->rules_and_help_page;?>
         </div>
         <!-- #tab3 -->
         
         <!-- #tab5 -->
         <div id="tab5" class="tab-pane">
         	<?php echo _("Loading prizes ...");?>
         </div>
         <!-- #tab5 -->
         
     </div> <!-- tab content -->
    
               
    </div><!-- Tabable end-->              
    
    
    
    <div class="footer">
    	<div class="pull-left">
    		<?php echo $set->footer_info;?>
        </div>
        <div class="pull-right">
        	<?php if(isset($set->disclaimer_page) && $set->disclaimer_page != '')
					echo '<a href="#" id="disclaimer">' . _("Disclaimer"). '</a> ';
					
					if(($set->disclaimer_page != '') && ($set->terms_page != ''))
					  echo ' | ';
					
				  if(isset($set->terms_page) && ($set->terms_page != ''))
					echo ' <a href="#" id="terms">' . _("Terms & Conditions"). '</a>';
			?>
        </div>
        
        <div class="clearfix"></div>
    </div>
    
<?php 
  } // Extra security form else end
}
// Fan content ends
?>   
            
</div><!--MAIN CONTAINER ENDS-->


</body>
</html>
<?php } // fasebook $user ends here

// Comment out next line if gzip is enabled and gzip line on the top of that page is commented out
//ob_end_flush();
?>