<?php
$sumfingIncl=true;
if(isset ($_POST['ticket_id']) && isset($_POST['uid'])) {      
	include '../config.thing.php';
	// Get options
	$set = get_adm_opts();
	include 'translate.php';
	
	// Get user data
	$user = is_user_fakeid($_POST['uid']);
	
	// Mark ticket as claimed win
	$ticket = explode("_",$_POST['ticket_id']);
	if($updt_ticket = update_user_ticket($user->fb_id,$ticket[1])) {
		
		// Get ticket code and other data
		$ticket_data = get_user_tickets($user->fb_id);
		foreach($ticket_data as $td) {
			$t = explode("|",$td);
			if($t[0] == $ticket[1]) {
				$ticketrow = '#' . $t[0]. ' &bull; ' . $t[1] . ' &bull; ' . $t[2];
			}
		}
		
		// Send email to admin
		
		// Make page/app url
		$app_namespace = '?sk=app_'.FB_APPID;
		$app_url = MY_FB_PAGE_URL . $app_namespace;
		
		// Subject and message
		$subject = _("Prize request from") . ' ' . $user->name;
		$message = _("User have requested prize for winning.") . '<br><br>';
		$message .= _("User name:"). ' ' . $user->name . '<br>';
		$message .= _("Email:"). ' ' . $user->email . '<br>';
		$message .= _("Ticket:"). ' ' . $ticketrow . '<br><br>';
		$message .= _("Go to app page and check it up from admin panel:<br>");
		$message .= '<a href="'.$app_url.'">' . $app_url . '</a>';
		
		if(claim_win_email($user->email,$set->admin_email,$subject,$message)) {
			echo $_POST['ticket_id'];
		} else {
			error_log(_("Email to admin failed. file: claimwin.php"));	
		}
	
	} else {
		error_log(_("Can not update user ticket for winner claim. file: claimwin.php"));	
	}
	
}
?>