<?php
/**
 * Transfer Credits
 * https://webenginecms.org/
 * 
 * @version 1.4.0
 * @author Lautaro Angelico <http://lautaroangelico.com/>
 * @copyright (c) 2013-2025 Lautaro Angelico, All Rights Reserved
 * @build w641ba01901cb0925ec50f543e59acbd
 */

if(!isLoggedIn()) redirect(1,'login');

echo '<div class="page-title"><span>'.lang('transfercredits_title',true).'</span></div>';

try {
	
	if(isset($_GET['success'])) {
		
		message('success', lang('transfercredits_success_1',true));
		
	} else {
	
		if(!isset($_GET['player'])) redirect(1,'transfercredits/transfer/');
		if(!isset($_GET['type'])) redirect(1,'transfercredits/transfer/');
		if(!isset($_GET['credits'])) redirect(1,'transfercredits/transfer/');
		
		$TransferCredits = new \Plugin\TransferCredits\TransferCredits();
		$TransferCredits->setUser($_SESSION['username']);
		$TransferCredits->setPlayer(base64url_decode($_GET['player']));
		$TransferCredits->setCreditsConfigId($_GET['type']);
		$TransferCredits->setTransferAmount($_GET['credits']);
		$TransferCredits->transfer();
	
	}
	
} catch(Exception $ex) {
	message('error', $ex->getMessage());
}