<?php
require_once(dirname(__FILE__).'/../../config.php');
require_once(DIR_SYSTEM.'/admin/class.session.php');

$t	=	$prepare->sanitize( $_GET['t'], 'input');


if ( $t == 'approve' ) {
	$id	=	$prepare->sanitize( $_POST['id'], 'input');

	//*** GET ACTUAL STATUS ***//
	$checkStatus	=	$db->Query("SELECT `pub_withdrawal_status` FROM publishers_withdrawals where pub_withdrawal_id=?","i",$id);

	if ( $checkStatus['0']['pub_withdrawal_status'] == '0' OR $checkStatus['0']['pub_withdrawal_status'] == '4' ) {
		
		$update = $db->NoQuery("UPDATE publishers_withdrawals SET pub_withdrawal_status=? WHERE pub_withdrawal_id=?","ii",1,$id);
		
		if ( $update ) {
			echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_MARKED_APPROVED"].'</div>';
		} else {
			echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_ERROR"].'</div>';
		}
		
	} else {
		echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_ERROR_CANT_APPROVE"].'</div>';
	}

}



if ( $t == 'reject' ) {
	$id	=	$prepare->sanitize( $_POST['id'], 'input');

	//*** GET ACTUAL STATUS ***//
	$checkStatus	=	$db->Query("SELECT `pub_withdrawal_status`, `pub_withdrawal_user_id`, `pub_withdrawal_amount` FROM publishers_withdrawals where pub_withdrawal_id=?","i",$id);

	if ( $checkStatus['0']['pub_withdrawal_status'] == '0' OR $checkStatus['0']['pub_withdrawal_status'] == '4' ) {
		
		$update = $db->NoQuery("UPDATE publishers_withdrawals SET pub_withdrawal_status=? WHERE pub_withdrawal_id=?","ii",2,$id);
		
		if ( $update ) {


	$db->NoQuery("UPDATE publishers_profiles SET pub_profile_money=pub_profile_money+".$checkStatus['0']['pub_withdrawal_amount']." WHERE pub_profile_user_id=?","i",$checkStatus['0']['pub_withdrawal_user_id']);


			echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_REJECTED"].'</div>';
		} else {
			echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_ERROR"].'</div>';
		}
		
	} else {
		echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_ADMIN_REQUESTS_DETAILS_ERROR_CANT_REJECT"].'</div>';
	}

}

?>