<?php $sub_page = (!empty($_GET['plan'])) ? $_GET['plan'] : '';
$title = '';
if ($sub_page == 'new') {
    $title = 'پلن اشتراک جدید';
    $btn_text = 'افزودن پلن';
} elseif (is_numeric($sub_page)) {
    $title = 'ویرایش پلن اشتراک';
    $btn_text = 'ویرایش پلن';
}
$message_status = array();
if (!empty($_GET['status'])) $message_status['status'] = $_GET['status'];
if (!empty($_GET['msg'])) $message_status['text'] = $_GET['msg'];
$plan_info = array();
if (is_numeric($sub_page)) $plan_info = yascode_vip::get_plan_info($sub_page); ?>
<div class="wrap editplan-page">
    <h2><?php echo $title; ?></h2>
    <a href="<?php echo add_query_arg(array('page' => 'subscriptions'), admin_url('admin.php')); ?>" class="page-title-action">پلن ها</a>
    <div id="poststuff">
        <div class="msg-body">
            <?php if (!empty($message_status) && is_array($message_status) && !empty($message_status['text'])) {
                $status = (!empty($message_status['status'])) ? $message_status['status'] : $message_status[0];
                $sts = ($status != 'nok') ? 'success' : 'error';
                $text = (!empty($message_status['text'])) ? $message_status['text'] : ''; ?>
                <div class="custom-notice notice-<?php echo $sts; ?>">
                    <p class="content"><?php echo $text; ?></p><button type="button" class="notice-dismiss"></button>
                </div>
            <?php } ?>
        </div>

        <form action="<?php echo add_query_arg(array('page' => 'subscriptions', 'plan' => $sub_page), admin_url('admin.php')); ?>" method="POST">
            <input type="hidden" name="plan_id" value="<?php echo (!empty($plan_info->ID)) ? $plan_info->ID : ''; ?>" />
            <div class="input">
                <label for="plan_name">نام پلن</label>
                <input type="text" name="plan_name" id="plan_name" value="<?php echo (!empty($plan_info->name)) ? $plan_info->name : ''; ?>" />
            </div>
            <div class="input">
                <label for="plan_time">تعداد روز (عدد)</label>
                <input type="text" name="plan_time" id="plan_time" value="<?php echo (!empty($plan_info->time)) ? $plan_info->time : ''; ?>" />
            </div>
            <div class="input">
                <label for="plan_price">قیمت (تومان)</label>
                <input type="text" name="plan_price" id="plan_price" value="<?php echo (!empty($plan_info->price)) ? $plan_info->price : ''; ?>" />
            </div>
            <div class="input">
                <label for="plan_discount_price">قیمت تخفیف خورده (تومان)</label>
                <input type="text" name="plan_discount_price" id="plan_discount_price" value="<?php echo (!empty($plan_info->discount_price)) ? $plan_info->discount_price : ''; ?>" />
            </div>
            <div class="input btn">
                <button type="submit" name="submit_edit_plan" class="button-primary"><?php echo $btn_text; ?></button>
            </div>
        </form>
    </div>
</div>