<?php
if(!isLoggedIn()) redirect(1,'login');

echo '<div class="page-title"><span>'.htmlspecialchars(lang('redeemcode_title',true),ENT_QUOTES,'UTF-8').'</span></div>';
try {
    if(isset($_POST['redeem_submit'])) {
        try {
            $RedeemCode=new \Plugin\RedeemCode\RedeemCode();
            $RedeemCode->setCode($_POST['redeem_code']??'');
            $RedeemCode->redeemCode();
            message('success',lang('redeemcode_success_1',true));
        } catch(Exception $ex) { message('error',$ex->getMessage()); }
    }
    echo '<div class="col-xs-10 col-xs-offset-1 col-md-8 col-md-offset-2" style="margin-top:25px;">';
    echo '<p class="text-center"><strong>'.(class_exists('NexoraRealm')?htmlspecialchars(NexoraRealm::label(),ENT_QUOTES,'UTF-8'):'').'</strong></p>';
    echo '<p class="text-center text-muted">El código se canjeará únicamente en el reino activo.</p>';
    echo '<form class="form-horizontal" method="post" autocomplete="off">';
    echo '<div class="form-group"><div class="col-sm-12"><input type="text" class="form-control input-lg text-center" name="redeem_code" maxlength="50" placeholder="NEXORA-XXXX" required></div></div>';
    echo '<div class="form-group"><div class="col-sm-12 text-center"><button type="submit" name="redeem_submit" value="1" class="btn btn-primary">'.htmlspecialchars(lang('redeemcode_txt_1',true),ENT_QUOTES,'UTF-8').'</button></div></div>';
    echo '</form></div>';
} catch(Exception $ex) { message('error',$ex->getMessage()); }
