<?php
if (! empty($_POST['subscription_id'])) {
    $sub = new subscription;
    $getS = $sub->get_subscription($_POST['subscription_id']);
    $uid = $getS['data']['member_id'];
}
else if (! empty($_POST['user_id'])) {
    $uid = $_POST['user_id'];
} else {
    $data = array();
}

if (! empty($uid)) {
    $user = new user;
    $data = $user->get_user($uid);
}

?>

<script type="text/javascript">

    $.ctrl('S', function () {
        return json_add('credit_card-add', 'x', '0', 'popupform');
    });

</script>


<form action="" method="post" id="popupform" onsubmit="return json_add('credit_card-add','x','0','popupform');">


    <div id="popupsave">

        <input type="submit" value="Save" class="save"/>

        <input type="hidden" name="subscription_id" value="<?php if (!empty($_POST['subscription_id'])) {
            echo $_POST['subscription_id'];
        } ?>"/>

        <input type="hidden" name="user_id" value="<?php if (!empty($_POST['user_id'])) {
            echo $_POST['user_id'];
        } ?>"/>

    </div>

    <h1>Credit Card Management</h1>


    <div class="pad24t popupbody">


        <fieldset>

            <legend>Payment Gateway</legend>

            <div class="pad24t">

                <div class="field">

                    <label>Gateway</label>

                    <div class="field_entry">

                        <select name="gateway" style="width:300px;">

                            <?php

                            $cart = new cart;

                            $gateways = $cart->get_gateways('0', '', '1');

                            foreach ($gateways as $item) {
                                if ($item['local_card_storage'] == '1') {
                                    $storage = 'Stored Locally';

                                } else {
                                    $storage = 'Tokenized';

                                }
                                echo "<option value=\"" . $item['code'] . "\">" . $item['name'] . " ($storage)</option>";

                            }

                            ?>

                        </select>

                    </div>

                </div>

            </div>

        </fieldset>



        <?php



        $field = new field('billing');

        $dataA = $field->generate_form('billing_form', array('billing' => $data['data']));

        $data = $field->generate_form('payment_form');

        echo $dataA;

        echo $data;

        ?>


    </div>


</form>