<?php
if(!isLoggedIn()) redirect(1,'login');
echo '<div class="page-title"><span>'.lang('vip_title',true).'</span></div>';
try {
    $VIP=new \Plugin\VIP\VIP();
    $VIP->setUsername($_SESSION['username']);
    $vipButton=$VIP->isAccountVip()?lang('vip_txt_3'):lang('vip_txt_2');
    if(isset($_GET['success'])) message('success',lang('vip_success_1'));
    if($VIP->isAccountVip()) {
        $data=$VIP->getAccountVipData();
        $days=sec_to_dhms(strtotime($data[_CLMN_VIP_DATE_])-time());
        message('info',langf('vip_txt_4',array(lang('vip_title_type_'.$data[_CLMN_VIP_TYPE_]),$days[0])));
    }
    $token=\Plugin\VIP\VIP::issuePurchaseToken();
    foreach($VIP->getVipTypeData() as $type=>$data) {
        if(!$data['enabled']) continue;
        echo '<div class="panel panel-default"><div class="panel-heading"><strong>'.htmlspecialchars($data['title'],ENT_QUOTES,'UTF-8').'</strong></div><div class="panel-body"><table class="table">';
        foreach($data['packages'] as $i=>$days) {
            echo '<tr><td>'.(int)$days.' dias</td><td>'.number_format($VIP->getVipCost($days,$type)).' creditos</td><td><form method="post" action="'.__VIP_HOME__.'order/"><input type="hidden" name="type" value="'.(int)$type.'"><input type="hidden" name="package" value="'.(int)$days.'"><input type="hidden" name="purchase_token" value="'.htmlspecialchars($token,ENT_QUOTES,'UTF-8').'"><button class="btn btn-primary" type="submit">'.htmlspecialchars($vipButton,ENT_QUOTES,'UTF-8').'</button></form></td></tr>';
        }
        echo '</table></div></div>';
    }
} catch(Exception $ex) { message('error',$ex->getMessage()); }
