<?php



if(login_control()) {

	

	if($user["user_authority"] == 2) {



		if(!permission('access', 'payments')){

			$page_title = "Yetkisiz Erişim";

			require admin_view("unauthorized");

			exit();

		}



		if(route(2) == "online"){



			if(!permission('access', 'payments')){

				$page_title = "Yetkisiz Erişim";

				require admin_view("unauthorized");

				exit();

			}

			$totalRecord = $db->from('deposits')
			->select('count(deposit_id) as total')
			->total();

			$pageLimit = 25;
			$pageParam = 'page';
			$pagination = $db->pagination($totalRecord, $pageLimit, $pageParam);

			if(@$_GET['method']){

				$deposits = $db->from('deposits')
				->leftjoin('users', 'users.user_id = deposits.user_id')
				->where('deposits.deposit_method', $_GET['method'])
				->orderby('deposits.deposit_id', 'DESC')
				->limit($pagination['start'], $pagination['limit'])
				->all();

			}elseif(@$_GET['status']){

				$deposits = $db->from('deposits')
				->leftjoin('users', 'users.user_id = deposits.user_id')
				->where('deposits.deposit_status', $_GET['status'])
				->orderby('deposits.deposit_id', 'DESC')
				->limit($pagination['start'], $pagination['limit'])
				->all();

			}else{

				if(@$_GET['search']){

					if($_GET['search_type'] == "id"){

				    	$deposits = $db->from('deposits')
						->leftjoin('users', 'users.user_id = deposits.user_id')
						->where('deposits.deposit_id', $_GET['search'])
						->orderby('deposits.deposit_id', 'DESC')
						->limit($pagination['start'], $pagination['limit'])
						->all();

					}

				}else{

					$deposits = $db->from('deposits')
					->leftjoin('users', 'users.user_id = deposits.user_id')
					->orderby('deposits.deposit_id', 'DESC')
					->limit($pagination['start'], $pagination['limit'])
					->all();

				}

			}			

			$tempDeposits = [];

			foreach($deposits as $deposit) {

				if($deposit["deposit_status"] == 2) {

					$deposit["deposit_status"] = "{PAYMENT_WAIT}";

				} elseif($deposit["deposit_status"] == 1) {

					$deposit["deposit_status"] = "{PAYMENT_SUCCESS}";

				} else {

					$deposit["deposit_status"] = "{PAYMENT_FAILED}";

				}

				$tempDeposits[] = $deposit;

			}

			$deposits = $tempDeposits;

			$title = "Online Ödemeler";
			$page_title = "Online Ödemeler";

		}elseif(route(2) == "bank"){

			if(!permission('access', 'payments')){
				$page_title = "Yetkisiz Erişim";
				require admin_view("unauthorized");
				exit();
			}

			$totalRecord = $db->from('bank_deposits')
			->select('count(id) as total')
			->total();

			$pageLimit = 25;
			$pageParam = 'page';
			$pagination = $db->pagination($totalRecord, $pageLimit, $pageParam);

			if(@$_GET['search']){

				if($_GET['search_type'] == "id"){

					$deposits = $db->from('bank_deposits')
					->leftjoin('users', 'users.user_id = bank_deposits.user')
					->where('bank_deposits.id', $_GET['search'])
					->orderby('bank_deposits.id', 'DESC')
					->limit($pagination['start'], $pagination['limit'])
					->all();

				}

			}else{

				$deposits = $db->from('bank_deposits')
				->leftjoin('users', 'users.user_id = bank_deposits.user')
				->orderby('bank_deposits.id', 'DESC')
				->limit($pagination['start'], $pagination['limit'])
				->all();

			}

			$title = "Banka Ödemeleri";
			$page_title = "Banka Ödemeleri";

		}else{

			header('Location:'. admin_url('payments/online'));

		}

		require admin_view('payments');

	}else{

		require controller("404");

	}

}else{

	require controller("404");	

}