</p>
</div>

<form id="category_list_form" method="post">    
    <p class="swpm-select-box-left">
        <label for="membership_level_id"><?php 
SwpmUtils::e('Membership Level:');
?>
</label>
        <select id="membership_level_id" name="membership_level_id">
            <option <?php 
echo $category_list->selected_level_id == 1 ? "selected" : "";
?>
 value="1">General Protection</option>
            <?php 
echo SwpmUtils::membership_level_dropdown($category_list->selected_level_id);
?>
        </select>                
    </p>
    <p class="swpm-select-box-left"><input type="submit" class="button-primary" name="update_category_list" value="<?php 
SwpmUtils::e('Update');
?>
"></p>
        <?php 
$category_list->prepare_items();
?>
   
        <?php 
$category_list->display();
?>
</form>
function swpm_edit_pp_subscription_button()
{
    //Retrieve the payment button data and present it for editing.
    $button_id = sanitize_text_field($_REQUEST['button_id']);
    $button_id = absint($button_id);
    $button_type = sanitize_text_field($_REQUEST['button_type']);
    $button = get_post($button_id);
    //Retrieve the CPT for this button
    $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
    //$payment_amount = get_post_meta($button_id, 'payment_amount', true);
    $payment_currency = get_post_meta($button_id, 'payment_currency', true);
    $return_url = get_post_meta($button_id, 'return_url', true);
    $paypal_email = get_post_meta($button_id, 'paypal_email', true);
    $button_image_url = get_post_meta($button_id, 'button_image_url', true);
    //Subscription billing details
    $billing_amount = get_post_meta($button_id, 'billing_amount', true);
    $billing_cycle = get_post_meta($button_id, 'billing_cycle', true);
    $billing_cycle_term = get_post_meta($button_id, 'billing_cycle_term', true);
    $billing_cycle_count = get_post_meta($button_id, 'billing_cycle_count', true);
    $billing_reattempt = get_post_meta($button_id, 'billing_reattempt', true);
    //Trial billing details
    $trial_billing_amount = get_post_meta($button_id, 'trial_billing_amount', true);
    $trial_billing_cycle = get_post_meta($button_id, 'trial_billing_cycle', true);
    $trial_billing_cycle_term = get_post_meta($button_id, 'trial_billing_cycle_term', true);
    ?>
    <form id="pp_button_config_form" method="post">

        <div class="postbox">
            <h3 class="hndle"><label for="title"><?php 
    echo SwpmUtils::_('PayPal Subscription Button Configuration');
    ?>
</label></h3>
            <div class="inside">

                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button ID');
    ?>
</th>
                        <td>
                            <input type="text" size="10" name="button_id" value="<?php 
    echo $button_id;
    ?>
" readonly required />
                            <p class="description">This is the ID of this payment button. It is automatically generated for you and it cannot be changed.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button Title');
    ?>
</th>
                        <td>
                            <input type="text" size="50" name="button_name" value="<?php 
    echo $button->post_title;
    ?>
" required />
                            <p class="description">Give this membership payment button a name. Example: Gold membership payment</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Membership Level');
    ?>
</th>
                        <td>
                            <select id="membership_level_id" name="membership_level_id">
                                <?php 
    echo SwpmUtils::membership_level_dropdown($membership_level_id);
    ?>
                            </select>
                            <p class="description">Select the membership level this payment button is for.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Payment Currency');
    ?>
</th>
                        <td>                            
                            <select id="payment_currency" name="payment_currency">
                                <option value="USD" <?php 
    echo $payment_currency == 'USD' ? 'selected="selected"' : '';
    ?>
>US Dollars ($)</option>
                                <option value="EUR" <?php 
    echo $payment_currency == 'EUR' ? 'selected="selected"' : '';
    ?>
>Euros (€)</option>
                                <option value="GBP" <?php 
    echo $payment_currency == 'GBP' ? 'selected="selected"' : '';
    ?>
>Pounds Sterling (£)</option>
                                <option value="AUD" <?php 
    echo $payment_currency == 'AUD' ? 'selected="selected"' : '';
    ?>
>Australian Dollars ($)</option>
                                <option value="BRL" <?php 
    echo $payment_currency == 'BRL' ? 'selected="selected"' : '';
    ?>
>Brazilian Real (R$)</option>
                                <option value="CAD" <?php 
    echo $payment_currency == 'CAD' ? 'selected="selected"' : '';
    ?>
>Canadian Dollars ($)</option>
                                <option value="CNY" <?php 
    echo $payment_currency == 'CNY' ? 'selected="selected"' : '';
    ?>
>Chinese Yuan</option>
                                <option value="CZK" <?php 
    echo $payment_currency == 'CZK' ? 'selected="selected"' : '';
    ?>
>Czech Koruna</option>
                                <option value="DKK" <?php 
    echo $payment_currency == 'DKK' ? 'selected="selected"' : '';
    ?>
>Danish Krone</option>
                                <option value="HKD" <?php 
    echo $payment_currency == 'HKD' ? 'selected="selected"' : '';
    ?>
>Hong Kong Dollar ($)</option>
                                <option value="HUF" <?php 
    echo $payment_currency == 'HUF' ? 'selected="selected"' : '';
    ?>
>Hungarian Forint</option>
                                <option value="INR" <?php 
    echo $payment_currency == 'INR' ? 'selected="selected"' : '';
    ?>
>Indian Rupee</option>
                                <option value="IDR" <?php 
    echo $payment_currency == 'IDR' ? 'selected="selected"' : '';
    ?>
>Indonesia Rupiah</option>
                                <option value="ILS" <?php 
    echo $payment_currency == 'ILS' ? 'selected="selected"' : '';
    ?>
>Israeli Shekel</option>
                                <option value="JPY" <?php 
    echo $payment_currency == 'JPY' ? 'selected="selected"' : '';
    ?>
>Japanese Yen (¥)</option>
                                <option value="MYR" <?php 
    echo $payment_currency == 'MYR' ? 'selected="selected"' : '';
    ?>
>Malaysian Ringgits</option>
                                <option value="MXN" <?php 
    echo $payment_currency == 'MXN' ? 'selected="selected"' : '';
    ?>
>Mexican Peso ($)</option>
                                <option value="NZD" <?php 
    echo $payment_currency == 'NZD' ? 'selected="selected"' : '';
    ?>
>New Zealand Dollar ($)</option>
                                <option value="NOK" <?php 
    echo $payment_currency == 'NOK' ? 'selected="selected"' : '';
    ?>
>Norwegian Krone</option>
                                <option value="PHP" <?php 
    echo $payment_currency == 'PHP' ? 'selected="selected"' : '';
    ?>
>Philippine Pesos</option>
                                <option value="PLN" <?php 
    echo $payment_currency == 'PLN' ? 'selected="selected"' : '';
    ?>
>Polish Zloty</option>
                                <option value="SGD" <?php 
    echo $payment_currency == 'SGD' ? 'selected="selected"' : '';
    ?>
>Singapore Dollar ($)</option>
                                <option value="ZAR" <?php 
    echo $payment_currency == 'ZAR' ? 'selected="selected"' : '';
    ?>
>South African Rand (R)</option>
                                <option value="KRW" <?php 
    echo $payment_currency == 'KRW' ? 'selected="selected"' : '';
    ?>
>South Korean Won</option>
                                <option value="SEK" <?php 
    echo $payment_currency == 'SEK' ? 'selected="selected"' : '';
    ?>
>Swedish Krona</option>
                                <option value="CHF" <?php 
    echo $payment_currency == 'CHF' ? 'selected="selected"' : '';
    ?>
>Swiss Franc</option>
                                <option value="TWD" <?php 
    echo $payment_currency == 'TWD' ? 'selected="selected"' : '';
    ?>
>Taiwan New Dollars</option>
                                <option value="THB" <?php 
    echo $payment_currency == 'THB' ? 'selected="selected"' : '';
    ?>
>Thai Baht</option>
                                <option value="TRY" <?php 
    echo $payment_currency == 'TRY' ? 'selected="selected"' : '';
    ?>
>Turkish Lira</option>
                                <option value="VND" <?php 
    echo $payment_currency == 'VND' ? 'selected="selected"' : '';
    ?>
>Vietnamese Dong</option>
                            </select>
                            <p class="description">Select the currency for this payment button.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('PayPal Email');
    ?>
</th>
                        <td>
                            <input type="text" size="50" name="paypal_email" value="<?php 
    echo $paypal_email;
    ?>
" required />
                            <p class="description">Enter your PayPal email address. The payment will go to this PayPal account.</p>
                        </td>
                    </tr>                    

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Billing Amount Each Cycle');
    ?>
</th>
                        <td>
                            <input type="text" size="6" name="billing_amount" value="<?php 
    echo $billing_amount;
    ?>
" required />
                            <p class="description">Amount to be charged on every billing cycle. If used with a trial period then this amount will be charged after the trial period is over. Example values: 10.00 or 19.50 or 299.95 etc (do not put currency symbol).</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Billing Cycle');
    ?>
</th>
                        <td>
                            <input type="text" size="4" name="billing_cycle" value="<?php 
    echo $billing_cycle;
    ?>
" required />
                            <select id="billing_cycle_term" name="billing_cycle_term">
                                <option value="D" <?php 
    echo $billing_cycle_term == 'D' ? 'selected="selected"' : '';
    ?>
>Day(s)</option>
                                <option value="M" <?php 
    echo $billing_cycle_term == 'M' ? 'selected="selected"' : '';
    ?>
>Month(s)</option>
                                <option value="Y" <?php 
    echo $billing_cycle_term == 'Y' ? 'selected="selected"' : '';
    ?>
>Year(s)</option>
                            </select>
                            <p class="description">Set the interval of the recurring payment. Example value: 1 Month (if you want to charge every month)</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Billing Cycle Count');
    ?>
</th>
                        <td>
                            <input type="text" size="6" name="billing_cycle_count" value="<?php 
    echo $billing_cycle_count;
    ?>
" />
                            <p class="description">After how many cycles should billing stop. Leave this field empty (or enter 0) if you want the payment to continue until the subscription is canceled.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Re-attempt on Failure');
    ?>
</th>
                        <td>
                            <input type="checkbox" name="billing_reattempt" value="1" <?php 
    if ($billing_reattempt != '') {
        echo ' checked="checked"';
    }
    ?>
 />
                            <p class="description">When checked, the payment will be re-attempted two more times if the payment fails. After the third failure, the subscription will be canceled..</p>
                        </td>
                    </tr>

                </table>

            </div>
        </div><!-- end of main button configuration box -->

        <div class="postbox">
            <h3 class="hndle"><label for="title"><?php 
    echo SwpmUtils::_('Trial Billing Details (Leave empty if you are not offering a trial period)');
    ?>
</label></h3>
            <div class="inside">

                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Trial Billing Amount');
    ?>
</th>
                        <td>
                            <input type="text" size="6" name="trial_billing_amount" value="<?php 
    echo $trial_billing_amount;
    ?>
" />
                            <p class="description">Amount to be charged for the trial period. Enter 0 if you want to offer a free trial period.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Trial Billing Period');
    ?>
</th>
                        <td>
                            <input type="text" size="4" name="trial_billing_cycle" value="<?php 
    echo $trial_billing_cycle;
    ?>
" />
                            <select id="billing_cycle_term" name="trial_billing_cycle_term">
                                <option value="D" <?php 
    echo $trial_billing_cycle_term == 'D' ? 'selected="selected"' : '';
    ?>
>Day(s)</option>
                                <option value="M" <?php 
    echo $trial_billing_cycle_term == 'M' ? 'selected="selected"' : '';
    ?>
>Month(s)</option>
                                <option value="Y" <?php 
    echo $trial_billing_cycle_term == 'Y' ? 'selected="selected"' : '';
    ?>
>Year(s)</option>
                            </select>
                            <p class="description">Length of the trial period</p>
                        </td>
                    </tr>

                </table>
            </div>            
        </div><!-- end of trial billing details box -->   

        <div class="postbox">
            <h3 class="hndle"><label for="title"><?php 
    echo SwpmUtils::_('Optional Details');
    ?>
</label></h3>
            <div class="inside">

                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Return URL');
    ?>
</th>
                        <td>
                            <input type="text" size="100" name="return_url" value="<?php 
    echo $return_url;
    ?>
" />
                            <p class="description">This is the URL the user will be redirected to after a successful payment. Enter the URL of your Thank You page here.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button Image URL');
    ?>
</th>
                        <td>
                            <input type="text" size="100" name="button_image_url" value="<?php 
    echo $button_image_url;
    ?>
" />
                            <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
                        </td>
                    </tr> 

                </table>
            </div>            
        </div><!-- end of optional details box -->        

        <p class="submit">
            <input type="submit" name="swpm_pp_subscription_save_submit" class="button-primary" value="<?php 
    echo SwpmUtils::_('Save Payment Data');
    ?>
" >
        </p>

    </form>

    <?php 
}
function swpm_edit_pp_buy_now_button()
{
    //Retrieve the payment button data and present it for editing.
    $button_id = sanitize_text_field($_REQUEST['button_id']);
    $button_id = absint($button_id);
    $button_type = sanitize_text_field($_REQUEST['button_type']);
    $button = get_post($button_id);
    //Retrieve the CPT for this button
    $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
    $payment_amount = get_post_meta($button_id, 'payment_amount', true);
    $payment_currency = get_post_meta($button_id, 'payment_currency', true);
    $return_url = get_post_meta($button_id, 'return_url', true);
    $paypal_email = get_post_meta($button_id, 'paypal_email', true);
    $button_image_url = get_post_meta($button_id, 'button_image_url', true);
    ?>
    <div class="postbox">
        <h3 class="hndle"><label for="title"><?php 
    echo SwpmUtils::_('PayPal Buy Now Button Configuration');
    ?>
</label></h3>
        <div class="inside">

            <form id="pp_button_config_form" method="post">
                <input type="hidden" name="button_type" value="<?php 
    echo $button_type;
    ?>
">

                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button ID');
    ?>
</th>
                        <td>
                            <input type="text" size="10" name="button_id" value="<?php 
    echo $button_id;
    ?>
" readonly required />
                            <p class="description">This is the ID of this payment button. It is automatically generated for you and it cannot be changed.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button Title');
    ?>
</th>
                        <td>
                            <input type="text" size="50" name="button_name" value="<?php 
    echo $button->post_title;
    ?>
" required />
                            <p class="description">Give this membership payment button a name. Example: Gold membership payment</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Membership Level');
    ?>
</th>
                        <td>
                            <select id="membership_level_id" name="membership_level_id">
                                <?php 
    echo SwpmUtils::membership_level_dropdown($membership_level_id);
    ?>
                            </select>
                            <p class="description">Select the membership level this payment button is for.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Payment Amount');
    ?>
</th>
                        <td>
                            <input type="text" size="6" name="payment_amount" value="<?php 
    echo $payment_amount;
    ?>
" required />
                            <p class="description">Enter payment amount. Example values: 10.00 or 19.50 or 299.95 etc (do not put currency symbol).</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Payment Currency');
    ?>
</th>
                        <td>                            
                            <select id="payment_currency" name="payment_currency">
                                <option value="USD" <?php 
    echo $payment_currency == 'USD' ? 'selected="selected"' : '';
    ?>
>US Dollars ($)</option>
                                <option value="EUR" <?php 
    echo $payment_currency == 'EUR' ? 'selected="selected"' : '';
    ?>
>Euros (€)</option>
                                <option value="GBP" <?php 
    echo $payment_currency == 'GBP' ? 'selected="selected"' : '';
    ?>
>Pounds Sterling (£)</option>
                                <option value="AUD" <?php 
    echo $payment_currency == 'AUD' ? 'selected="selected"' : '';
    ?>
>Australian Dollars ($)</option>
                                <option value="BRL" <?php 
    echo $payment_currency == 'BRL' ? 'selected="selected"' : '';
    ?>
>Brazilian Real (R$)</option>
                                <option value="CAD" <?php 
    echo $payment_currency == 'CAD' ? 'selected="selected"' : '';
    ?>
>Canadian Dollars ($)</option>
                                <option value="CNY" <?php 
    echo $payment_currency == 'CNY' ? 'selected="selected"' : '';
    ?>
>Chinese Yuan</option>
                                <option value="CZK" <?php 
    echo $payment_currency == 'CZK' ? 'selected="selected"' : '';
    ?>
>Czech Koruna</option>
                                <option value="DKK" <?php 
    echo $payment_currency == 'DKK' ? 'selected="selected"' : '';
    ?>
>Danish Krone</option>
                                <option value="HKD" <?php 
    echo $payment_currency == 'HKD' ? 'selected="selected"' : '';
    ?>
>Hong Kong Dollar ($)</option>
                                <option value="HUF" <?php 
    echo $payment_currency == 'HUF' ? 'selected="selected"' : '';
    ?>
>Hungarian Forint</option>
                                <option value="INR" <?php 
    echo $payment_currency == 'INR' ? 'selected="selected"' : '';
    ?>
>Indian Rupee</option>
                                <option value="IDR" <?php 
    echo $payment_currency == 'IDR' ? 'selected="selected"' : '';
    ?>
>Indonesia Rupiah</option>
                                <option value="ILS" <?php 
    echo $payment_currency == 'ILS' ? 'selected="selected"' : '';
    ?>
>Israeli Shekel</option>
                                <option value="JPY" <?php 
    echo $payment_currency == 'JPY' ? 'selected="selected"' : '';
    ?>
>Japanese Yen (¥)</option>
                                <option value="MYR" <?php 
    echo $payment_currency == 'MYR' ? 'selected="selected"' : '';
    ?>
>Malaysian Ringgits</option>
                                <option value="MXN" <?php 
    echo $payment_currency == 'MXN' ? 'selected="selected"' : '';
    ?>
>Mexican Peso ($)</option>
                                <option value="NZD" <?php 
    echo $payment_currency == 'NZD' ? 'selected="selected"' : '';
    ?>
>New Zealand Dollar ($)</option>
                                <option value="NOK" <?php 
    echo $payment_currency == 'NOK' ? 'selected="selected"' : '';
    ?>
>Norwegian Krone</option>
                                <option value="PHP" <?php 
    echo $payment_currency == 'PHP' ? 'selected="selected"' : '';
    ?>
>Philippine Pesos</option>
                                <option value="PLN" <?php 
    echo $payment_currency == 'PLN' ? 'selected="selected"' : '';
    ?>
>Polish Zloty</option>
                                <option value="SGD" <?php 
    echo $payment_currency == 'SGD' ? 'selected="selected"' : '';
    ?>
>Singapore Dollar ($)</option>
                                <option value="ZAR" <?php 
    echo $payment_currency == 'ZAR' ? 'selected="selected"' : '';
    ?>
>South African Rand (R)</option>
                                <option value="KRW" <?php 
    echo $payment_currency == 'KRW' ? 'selected="selected"' : '';
    ?>
>South Korean Won</option>
                                <option value="SEK" <?php 
    echo $payment_currency == 'SEK' ? 'selected="selected"' : '';
    ?>
>Swedish Krona</option>
                                <option value="CHF" <?php 
    echo $payment_currency == 'CHF' ? 'selected="selected"' : '';
    ?>
>Swiss Franc</option>
                                <option value="TWD" <?php 
    echo $payment_currency == 'TWD' ? 'selected="selected"' : '';
    ?>
>Taiwan New Dollars</option>
                                <option value="THB" <?php 
    echo $payment_currency == 'THB' ? 'selected="selected"' : '';
    ?>
>Thai Baht</option>
                                <option value="TRY" <?php 
    echo $payment_currency == 'TRY' ? 'selected="selected"' : '';
    ?>
>Turkish Lira</option>
                                <option value="VND" <?php 
    echo $payment_currency == 'VND' ? 'selected="selected"' : '';
    ?>
>Vietnamese Dong</option>
                            </select>
                            <p class="description">Select the currency for this payment button.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Return URL');
    ?>
</th>
                        <td>
                            <input type="text" size="100" name="return_url" value="<?php 
    echo $return_url;
    ?>
" />
                            <p class="description">This is the URL the user will be redirected to after a successful payment. Enter the URL of your Thank You page here.</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('PayPal Email');
    ?>
</th>
                        <td>
                            <input type="text" size="50" name="paypal_email" value="<?php 
    echo $paypal_email;
    ?>
" required />
                            <p class="description">Enter your PayPal email address. The payment will go to this PayPal account.</p>
                        </td>
                    </tr>                    

                    <tr valign="top">
                        <th scope="row"><?php 
    echo SwpmUtils::_('Button Image URL');
    ?>
</th>
                        <td>
                            <input type="text" size="100" name="button_image_url" value="<?php 
    echo $button_image_url;
    ?>
" />
                            <p class="description">If you want to customize the look of the button using an image then enter the URL of the image.</p>
                        </td>
                    </tr> 

                </table>

                <p class="submit">
                    <input type="submit" name="swpm_pp_buy_now_edit_submit" class="button-primary" value="<?php 
    echo SwpmUtils::_('Save Payment Data');
    ?>
" >
                </p>

            </form>

        </div>
    </div>
    <?php 
}