<?php
$sumfingIncl=true;
if(isset ($_POST['func']) && isset($_POST['uid'])) {      
	include '../config.thing.php';
	
	$reset_all = false;
	// Get options
	$set = get_adm_opts();
	include 'translate.php';
	
	# 1 Delete tickets
	
	# 2 Delete slot leaderboard
	
	# 3 Delete requested security data
	
	# 4 Delete all pending requests and empty requests table
	
	# 5 Reset users table [ verified , share_int , req_int and slot_int ]
	
	# 6 Empty latest_winners
	
	# 7 Delete mobile links table
	
	// Get admin opts
	//$set = get_adm_opts();
	$user = is_user_fakeid($_POST['uid']);
	if($user->isadmin == 1) {
	
		$reset_all = reset_all($user->fake_id);
	
		if($reset_all === true) {
			
			// Send emails if set so
			if(isset($set->send_new_email)) {
				
				// Get users emails
				$to = get_users_emails($user->fake_id);
				
				// Get email subject and message and replace shortcodes
				$subject = $set->new_email_subject;
				$message = $set->new_email_body;
				// Replace [PRIZES] and [APPLINK]
				$url = urldecode($_POST['url']);
				$message = str_replace("[APPLINK]","<a href='".$url."'>".$url."</a>", $message);
				
				// Prizes
				$prizes = array(
							'prize_1' => array(
								'amt' => (isset($set->prize1_amount) ? $set->prize1_amount : ""),
								'ttl' => (isset($set->prize1_title) ? $set->prize1_title : ""),
								'dsc' => (isset($set->prize1_description) ? $set->prize1_description : ""),
								'img' => (isset($set->prize1_img) ? $set->prize1_img : "")
							),
							
							'prize_2' => array(
								'amt' => (isset($set->prize2_amount) ? $set->prize2_amount : ""),
								'ttl' => (isset($set->prize2_title) ? $set->prize2_title : ""),
								'dsc' => (isset($set->prize2_description) ? $set->prize2_description : ""),
								'img' => (isset($set->prize2_img) ? $set->prize2_img : "")
							),
							
							'prize_3' => array(
								'amt' => (isset($set->prize3_amount) ? $set->prize3_amount : ""),
								'ttl' => (isset($set->prize3_title) ? $set->prize3_title : ""),
								'dsc' => (isset($set->prize3_description) ? $set->prize3_description : ""),
								'img' => (isset($set->prize3_img) ? $set->prize3_img : "")
							)
				);
				
				// Get app path
				$serv = explode('/',$_SERVER['PHP_SELF']);
				$scriptname = end($serv);
				$scriptpath = str_replace($scriptname,'',$_SERVER['PHP_SELF']);
				$app_files_url = 'https://'.$_SERVER['SERVER_NAME'].$scriptpath;
				$app_files_url = str_replace("incl/","",$app_files_url);
				$emailprizes = '';
				foreach($prizes as $val) { 
					
					if(($val['ttl'] != "") && ($val['amt'] != "") && ($val['amt'] != 0)) {
						
						$amt = ($val['amt'] > 1) ? $val['amt'] . " &times; " : "";
						
						
							$emailprizes .= '<table cellpadding="0" cellspacing="0" border="0">';
						  		
								$emailprizes .= '<tr><td>';
								$emailprizes .= '<img src="' . $app_files_url . 'uploads/thumbs/' . $val['img'] . '" alt="" style="margin:8px">';
								$emailprizes .= '</td>';
						  	
							
								$emailprizes .= '<td>';
						  		$emailprizes .= '<h3>' . $amt . $val['ttl'] . '</h3>';
								
								if($val['dsc'] != "") {
									$emailprizes .= '<div>' . $val['dsc'] . '</div>';
								}
								
								$emailprizes .= '</td></tr>';
							
							$emailprizes .= '</table>';  
						  
					}
				}
				
				$message = str_replace("[PRIZES]",$emailprizes, $message);
				
				$message = nl2br($message);
				
				// Send out with BCC
				if(!send_new_note($to,$subject,$message)) {
					error_log(_("New raffle note sending failed."));
				} else {
					echo "OK";	
				}
			}
				
		} else {
			error_log(_("App reset failed."));	
		}
	}
	
die;
}
?>

