<?php
/**
 * Grand Reset Plugin
 * https://webenginecms.org/
 * 
 * @version 1.0.0
 * @author Lautaro Angelico <http://lautaroangelico.com/>
 * @copyright (c) 2013-2019 Lautaro Angelico, All Rights Reserved
 */

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

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

try {
	
	$GrandReset = new Plugin\GrandReset\GrandReset();
	$GrandReset->setUsername($_SESSION['username']);
	$AccountCharacters = $GrandReset->getAccountPlayerList();
	
	if(check_value($_POST['submit'])) {
		try {
			$GrandReset->setPlayer($_POST['character']);
			$GrandReset->grandResetPlayer();
		} catch(Exception $ex) {
			message('error', $ex->getMessage());
		}
	}
	
	echo '<table class="table general-table-ui">';
		echo '<tr>';
			echo '<td></td>';
			echo '<td>'.lang('resetcharacter_txt_1').'</td>';
			echo '<td>'.lang('resetcharacter_txt_2').'</td>';
			echo '<td>'.lang('resetcharacter_txt_3').'</td>';
			echo '<td>'.lang('resetcharacter_txt_4').'</td>';
			echo '<td>'.lang('grandreset_txt_1').'</td>';
			echo '<td></td>';
		echo '</tr>';
		
		foreach($AccountCharacters as $player) {
			$characterIMG = getPlayerClassAvatar($player[_CLMN_CHR_CLASS_], true, true);
			
			echo '<form action="'.__GRANDRESET_HOME__.'" method="post">';
				echo '<input type="hidden" name="character" value="'.$player[_CLMN_CHR_NAME_].'"/>';
				echo '<tr>';
					echo '<td>'.$characterIMG.'</td>';
					echo '<td>'.$player[_CLMN_CHR_NAME_].'</td>';
					echo '<td>'.$player[_CLMN_CHR_LVL_].'</td>';
					echo '<td>'.number_format($player[_CLMN_CHR_ZEN_]).'</td>';
					echo '<td>'.number_format($player[_CLMN_CHR_RSTS_]).'</td>';
					echo '<td>'.number_format($player[_CLMN_CHR_GRSTS_]).'</td>';
					echo '<td><button name="submit" value="submit" class="btn btn-primary">'.lang('grandreset_txt_2').'</button></td>';
				echo '</tr>';
			echo '</form>';
		}
	echo '</table>';
	
	echo '<div class="module-requirements text-center">';
		if($GrandReset->getRequiredZen() > 0) echo '<p>'.langf('grandreset_txt_3', array($GrandReset->getRequiredZen())).'</p>';
		if($GrandReset->getRequiredResets() > 0) echo '<p>'.langf('grandreset_txt_4', array($GrandReset->getRequiredResets())).'</p>';
		if($GrandReset->getRequiredLevel() > 0) echo '<p>'.langf('grandreset_txt_5', array($GrandReset->getRequiredLevel())).'</p>';
	echo '</div>';
	
} catch(Exception $ex) {
	message('error', $ex->getMessage());
}