<?php
/**
 * WebEngine CMS
 * https://webenginecms.org/
 * 
 * @version 1.2.0
 * @author Lautaro Angelico <http://lautaroangelico.com/>
 * @copyright (c) 2013-2019 Lautaro Angelico, All Rights Reserved
 * 
 * Licensed under the MIT license
 * http://opensource.org/licenses/MIT
 */
?>
<h2>Configurar Ranking de Ligas</h2>
<?php
function saveChanges() {
	global $_POST;
	
	$xmlPath = __PATH_MODULE_CONFIGS__.'rankings.xml';
	$xml = simplexml_load_file($xmlPath);
	
	$xml->rankings_liga_show_jugadas 			= $_POST['setting_1'];
	$xml->rankings_liga_show_ganadas 			= $_POST['setting_2'];
	$xml->rankings_liga_show_perdidas 			= $_POST['setting_3'];
	$xml->rankings_liga_show_winrate 			= $_POST['setting_4'];
	$xml->rankings_liga_show_liga 				= $_POST['setting_5'];

	$xml->rankings_liga_ganadas 				= $_POST['setting_6'];
	$xml->rankings_liga_perdidas 				= $_POST['setting_7'];
	
	$xml->rankings_liga_elo_hierro1 			= $_POST['setting_8'];
	$xml->rankings_liga_elo_hierro2 			= $_POST['setting_9'];
	$xml->rankings_liga_elo_hierro3 			= $_POST['setting_10'];
	$xml->rankings_liga_elo_bronce1 			= $_POST['setting_11'];
	$xml->rankings_liga_elo_bronce2 			= $_POST['setting_12'];
	$xml->rankings_liga_elo_bronce3 			= $_POST['setting_13'];
	$xml->rankings_liga_elo_plata1 				= $_POST['setting_14'];
	$xml->rankings_liga_elo_plata2 				= $_POST['setting_15'];
	$xml->rankings_liga_elo_plata3 				= $_POST['setting_16'];
	$xml->rankings_liga_elo_oro1 				= $_POST['setting_17'];
	$xml->rankings_liga_elo_oro2 				= $_POST['setting_18'];
	$xml->rankings_liga_elo_oro3 				= $_POST['setting_19'];
	$xml->rankings_liga_elo_platino1 			= $_POST['setting_20'];
	$xml->rankings_liga_elo_platino2 			= $_POST['setting_21'];
	$xml->rankings_liga_elo_platino3 			= $_POST['setting_22'];
	$xml->rankings_liga_elo_diamante1 			= $_POST['setting_23'];
	$xml->rankings_liga_elo_diamante2 			= $_POST['setting_24'];
	$xml->rankings_liga_elo_diamante3 			= $_POST['setting_25'];
	$xml->rankings_liga_elo_leyenda1 			= $_POST['setting_26'];
	$xml->rankings_liga_elo_leyenda2 			= $_POST['setting_27'];
	$xml->rankings_liga_elo_leyenda3 			= $_POST['setting_28'];
	$xml->rankings_liga_elo_challenger 			= $_POST['setting_29'];

	$xml->rankings_liga_img_hierro1 			= $_POST['setting_30'];
	$xml->rankings_liga_img_hierro2 			= $_POST['setting_31'];
	$xml->rankings_liga_img_hierro3 			= $_POST['setting_32'];
	$xml->rankings_liga_img_bronce1 			= $_POST['setting_33'];
	$xml->rankings_liga_img_bronce2 			= $_POST['setting_34'];
	$xml->rankings_liga_img_bronce3 			= $_POST['setting_35'];
	$xml->rankings_liga_img_plata1 				= $_POST['setting_36'];
	$xml->rankings_liga_img_plata2 				= $_POST['setting_37'];
	$xml->rankings_liga_img_plata3 				= $_POST['setting_38'];
	$xml->rankings_liga_img_oro1 				= $_POST['setting_39'];
	$xml->rankings_liga_img_oro2 				= $_POST['setting_40'];
	$xml->rankings_liga_img_oro3 				= $_POST['setting_41'];
	$xml->rankings_liga_img_platino1 			= $_POST['setting_42'];
	$xml->rankings_liga_img_platino2 			= $_POST['setting_43'];
	$xml->rankings_liga_img_platino3 			= $_POST['setting_44'];
	$xml->rankings_liga_img_diamante1 			= $_POST['setting_45'];
	$xml->rankings_liga_img_diamante2 			= $_POST['setting_46'];
	$xml->rankings_liga_img_diamante3 			= $_POST['setting_47'];
	$xml->rankings_liga_img_leyenda1 			= $_POST['setting_48'];
	$xml->rankings_liga_img_leyenda2 			= $_POST['setting_49'];
	$xml->rankings_liga_img_leyenda3 			= $_POST['setting_50'];
	$xml->rankings_liga_img_challenger 			= $_POST['setting_51'];

	$save = $xml->asXML($xmlPath);
	if($save) {
		message('success','Cambios guardados correctamente.');
	} else {
		message('error','No se ha podido guardar los cambios.');
	}
}

if(check_value($_POST['submit_changes'])) {
	saveChanges();
}

$xmlPath = __PATH_MODULE_CONFIGS__.'rankings.xml';
$moduleConfig = simplexml_load_file($xmlPath);
?>
<form action="" method="post">
	<h3>Columnas a mostrar</h3>
	<table class="table table-striped table-bordered table-hover module_config_tables">
		<tr>
			<th>Duelos Jugados<br /><span>Mostrar u Ocultar Duelos Jugados.</span></th>
			<td>
				<?php enabledisableCheckboxes('setting_1',$moduleConfig->rankings_liga_show_jugadas,'Mostrar','Ocultar'); ?>
			</td>
		</tr>
		<tr>
			<th>Duelos Ganados<br /><span>Mostrar u Ocultar Duelos Ganados.</span></th>
			<td>
				<?php enabledisableCheckboxes('setting_2',$moduleConfig->rankings_liga_show_ganadas,'Mostrar','Ocultar'); ?>
			</td>
		</tr>
		<tr>
			<th>Duelos Perdidos<br /><span>Mostrar u Ocultar Duelos Perdidos.</span></th>
			<td>
				<?php enabledisableCheckboxes('setting_3',$moduleConfig->rankings_liga_show_perdidas,'Mostrar','Ocultar'); ?>
			</td>
		</tr>
		<tr>
			<th>Win Rate<br /><span>Mostrar u Ocultar Win Rate.</span></th>
			<td>
				<?php enabledisableCheckboxes('setting_4',$moduleConfig->rankings_liga_show_winrate,'Mostrar','Ocultar'); ?>
			</td>
		</tr>
		<tr>
			<th>Liga<br /><span>Mostrar u Ocultar Liga.</span></th>
			<td>
				<?php enabledisableCheckboxes('setting_5',$moduleConfig->rankings_liga_show_liga,'Mostrar','Ocultar'); ?>
			</td>
		</tr>
	</table>

	<h3>Configuracion de Puntaje</h3>
	<table class="table table-striped table-bordered table-hover module_config_tables">
		<tr>
			<th>Ganadas<br /><span>Puntos a dar al ganar un Duelo.</span></th>
			<td>
				<input class="input-mini" type="text" name="setting_6" value="<?php echo $moduleConfig->rankings_liga_ganadas; ?>"/>
			</td>
		</tr>
		<tr>
			<th>Perdidas<br /><span>Puntos a quitar al perder un Duelo.</span></th>
			<td>
				<input class="input-mini" type="text" name="setting_7" value="<?php echo $moduleConfig->rankings_liga_perdidas; ?>"/>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<b>Formula para obtener Elo:</b> <b>(</b> Duelos ganados <b>*</b> Puntos por Ganadas <b>) - (</b> Duelos Perdidos <b>*</b> Puntos por Perdidas <b>)</b><br />
				<b>Ejemplo:</b> <b>(</b> 12 <b>*</b> <?php echo $moduleConfig->rankings_liga_ganadas; ?> <b>) - (</b> 7 <b>*</b> <?php echo $moduleConfig->rankings_liga_perdidas; ?> <b>)</b><br />
				<b>Resultado:</b> <?php echo 12*$moduleConfig->rankings_liga_ganadas; ?> <b>-</b> <?php echo 7*$moduleConfig->rankings_liga_perdidas; ?> <br />
				<b>Elo de Personaje:</b> <?php echo (12*$moduleConfig->rankings_liga_ganadas)-(7*$moduleConfig->rankings_liga_perdidas); ?> <br />
				Suponiendo que <b>Hierro 3</b> te pide minimo <b>10 de Elo</b> para entrar a esa liga, este personaje entraria minimo en esta misma liga.
			</td>
		</tr>
	</table>

	<h3>Configuracion de Elo de Liga</h3>
	<table class="table table-striped table-bordered table-hover module_config_tables">
		<tr>
			<td><b>Nombre de Liga<b></td>
			<td><b>Elo Division 1</b></td>
			<td><b>Elo Division 2</b></td>
			<td><b>Elo Division 3</b></td>
			<td><b>Imagen Division 1</b></td>
			<td><b>Imagen Division 2</b></td>
			<td><b>Imagen Division 3</b></td>
		</tr>
		<tr>
			<th>Hierro<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_8" value="<?php echo $moduleConfig->rankings_liga_elo_hierro1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_9" value="<?php echo $moduleConfig->rankings_liga_elo_hierro2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_10" value="<?php echo $moduleConfig->rankings_liga_elo_hierro3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_30" value="<?php echo $moduleConfig->rankings_liga_img_hierro1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_31" value="<?php echo $moduleConfig->rankings_liga_img_hierro2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_32" value="<?php echo $moduleConfig->rankings_liga_img_hierro3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Bronce<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_11" value="<?php echo $moduleConfig->rankings_liga_elo_bronce1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_12" value="<?php echo $moduleConfig->rankings_liga_elo_bronce2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_13" value="<?php echo $moduleConfig->rankings_liga_elo_bronce3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_33" value="<?php echo $moduleConfig->rankings_liga_img_bronce1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_34" value="<?php echo $moduleConfig->rankings_liga_img_bronce2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_35" value="<?php echo $moduleConfig->rankings_liga_img_bronce3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Plata<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_14" value="<?php echo $moduleConfig->rankings_liga_elo_plata1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_15" value="<?php echo $moduleConfig->rankings_liga_elo_plata2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_16" value="<?php echo $moduleConfig->rankings_liga_elo_plata3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_36" value="<?php echo $moduleConfig->rankings_liga_img_plata1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_37" value="<?php echo $moduleConfig->rankings_liga_img_plata2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_38" value="<?php echo $moduleConfig->rankings_liga_img_plata3; ?>"/>
			</td>
		</tr>
		
		<tr>
			<th>Oro<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_17" value="<?php echo $moduleConfig->rankings_liga_elo_oro1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_18" value="<?php echo $moduleConfig->rankings_liga_elo_oro2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_19" value="<?php echo $moduleConfig->rankings_liga_elo_oro3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_39" value="<?php echo $moduleConfig->rankings_liga_img_oro1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_40" value="<?php echo $moduleConfig->rankings_liga_img_oro2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_41" value="<?php echo $moduleConfig->rankings_liga_img_oro3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Platino<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_20" value="<?php echo $moduleConfig->rankings_liga_elo_platino1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_21" value="<?php echo $moduleConfig->rankings_liga_elo_platino2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_22" value="<?php echo $moduleConfig->rankings_liga_elo_platino3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_42" value="<?php echo $moduleConfig->rankings_liga_img_platino1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_43" value="<?php echo $moduleConfig->rankings_liga_img_platino2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_44" value="<?php echo $moduleConfig->rankings_liga_img_platino3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Diamante<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_23" value="<?php echo $moduleConfig->rankings_liga_elo_diamante1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_24" value="<?php echo $moduleConfig->rankings_liga_elo_diamante2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_25" value="<?php echo $moduleConfig->rankings_liga_elo_diamante3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_45" value="<?php echo $moduleConfig->rankings_liga_img_diamante1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_46" value="<?php echo $moduleConfig->rankings_liga_img_diamante2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_47" value="<?php echo $moduleConfig->rankings_liga_img_diamante3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Leyenda<br /><span>Elo necesario para ser de esta liga.<br />* Cada <b>liga</b> se divide en <b>3</b> divisiones, <b>1, 2 y 3</b>. Siendo la <b>3, la mejor</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_26" value="<?php echo $moduleConfig->rankings_liga_elo_leyenda1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_27" value="<?php echo $moduleConfig->rankings_liga_elo_leyenda2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_28" value="<?php echo $moduleConfig->rankings_liga_elo_leyenda3; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_48" value="<?php echo $moduleConfig->rankings_liga_img_leyenda1; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_49" value="<?php echo $moduleConfig->rankings_liga_img_leyenda2; ?>"/>
			</td>
			<td>
				<input class="input-mini" type="text" name="setting_50" value="<?php echo $moduleConfig->rankings_liga_img_leyenda3; ?>"/>
			</td>
		</tr>

		<tr>
			<th>Challenger<br /><span>Elo necesario para ser de esta liga.<br />* Esta liga es de unica division<b>(1)</b></span></th>
			<td>
				<input class="input-mini" type="text" name="setting_29" value="<?php echo $moduleConfig->rankings_liga_elo_challenger; ?>"/>
			</td>
			<td></td>
			<td></td>
			<td>
				<input class="input-mini" type="text" name="setting_51" value="<?php echo $moduleConfig->rankings_liga_img_challenger; ?>"/>
			</td>
			<td></td>
			<td></td>
		</tr>

		<tr>
			<td colspan="7"><input type="submit" name="submit_changes" value="Guardar Cambios" class="btn btn-success"/></td>
		</tr>
	</table>

	

</form>