示例#1
0
    private static function edit_page()
    {
        ?>
        <style>
            #paypalpro_submit_container{clear:both;}
            .paypalpro_col_heading{padding-bottom:2px; border-bottom: 1px solid #ccc; font-weight:bold; width:120px;}
            .paypalpro_field_cell {padding: 6px 17px 0 0; margin-right:15px;}

            .paypalpro_validation_error{ background-color:#FFDFDF; margin-top:4px; margin-bottom:6px; padding-top:6px; padding-bottom:6px; border:1px dotted #C89797;}
            .paypalpro_validation_error span {color: red;}
            .left_header{float:left; width:200px;}
            .margin_vertical_10{margin: 10px 0; padding-left:5px;}
            .margin_vertical_30{margin: 30px 0; padding-left:5px;}
            .width-1{width:300px;}
            .gf_paypalpro_invalid_form{margin-top:30px; background-color:#FFEBE8;border:1px solid #CC0000; padding:10px; width:600px;}
            .size-1{width:400px;}
        </style>
        <script type="text/javascript">
            var form = Array();
            function ToggleSetupFee(){
                if(jQuery('#gf_paypalpro_setup_fee').is(':checked')){
                    jQuery('#paypalpro_setup_fee_container').show('slow');
                    jQuery('#paypalpro_enable_trial_container, #paypalpro_trial_period_container').slideUp();
                }
                else{
                    jQuery('#paypalpro_setup_fee_container').hide('slow');
                    jQuery('#paypalpro_enable_trial_container').slideDown();
                    ToggleTrial();
                }
            }

            function ToggleTrial(){
                if(jQuery('#gf_paypalpro_trial_period').is(':checked'))
                    jQuery('#paypalpro_trial_period_container').show('slow');
                else
                    jQuery('#paypalpro_trial_period_container').hide('slow');
            }
        </script>
        <div class="wrap">
            <img alt="<?php 
        _e("PayPal Pro", "gravityformspaypalpro");
        ?>
" style="margin: 15px 7px 0pt 0pt; float: left;" src="<?php 
        echo self::get_base_url();
        ?>
/images/paypal_wordpress_icon_32.png"/>
            <h2><?php 
        _e("PayPal Pro Transaction Settings", "gravityformspaypalpro");
        ?>
</h2>

        <?php 
        //getting setting id (0 when creating a new one)
        $id = !empty($_POST["paypalpro_setting_id"]) ? $_POST["paypalpro_setting_id"] : absint($_GET["id"]);
        $config = empty($id) ? array("meta" => array(), "is_active" => true) : GFPayPalProData::get_feed($id);
        $is_validation_error = false;
        //updating meta information
        if (rgpost("gf_paypalpro_submit")) {
            $config["form_id"] = absint(rgpost("gf_paypalpro_form"));
            $config["meta"]["type"] = rgpost("gf_paypalpro_type");
            $config["meta"]["disable_note"] = rgpost("gf_paypalpro_disable_note");
            $config["meta"]["disable_shipping"] = rgpost('gf_paypalpro_disable_shipping');
            //$config["meta"]["delay_autoresponder"] = rgpost('gf_paypalpro_delay_autoresponder');
            //$config["meta"]["delay_notification"] = rgpost('gf_paypalpro_delay_notification');
            //$config["meta"]["delay_post"] = rgpost('gf_paypalpro_delay_post');
            $config["meta"]["update_post_action"] = rgpost('gf_paypalpro_update_action');
            // paypalpro conditional
            $config["meta"]["paypalpro_conditional_enabled"] = rgpost('gf_paypalpro_conditional_enabled');
            $config["meta"]["paypalpro_conditional_field_id"] = rgpost('gf_paypalpro_conditional_field_id');
            $config["meta"]["paypalpro_conditional_operator"] = rgpost('gf_paypalpro_conditional_operator');
            $config["meta"]["paypalpro_conditional_value"] = rgpost('gf_paypalpro_conditional_value');
            //recurring fields
            $config["meta"]["recurring_amount_field"] = rgpost("gf_paypalpro_recurring_amount");
            $config["meta"]["billing_cycle_number"] = rgpost("gf_paypalpro_billing_cycle_number");
            $config["meta"]["billing_cycle_type"] = rgpost("gf_paypalpro_billing_cycle_type");
            $config["meta"]["recurring_times"] = rgpost("gf_paypalpro_recurring_times");
            $config["meta"]["setup_fee_enabled"] = rgpost('gf_paypalpro_setup_fee');
            $config["meta"]["setup_fee_amount_field"] = rgpost('gf_paypalpro_setup_fee_amount');
            $has_setup_fee = $config["meta"]["setup_fee_enabled"];
            $config["meta"]["trial_period_enabled"] = $has_setup_fee ? false : rgpost('gf_paypalpro_trial_period');
            $config["meta"]["trial_type"] = $has_setup_fee ? "" : rgpost('gf_paypalpro_trial_type');
            $config["meta"]["trial_amount_field"] = $has_setup_fee ? "" : rgpost('gf_paypalpro_trial_amount');
            $config["meta"]["trial_period_number"] = $has_setup_fee ? "" : rgpost('gf_paypalpro_trial_period_number');
            $config["meta"]["trial_period_type"] = $has_setup_fee ? "" : rgpost('gf_paypalpro_trial_period_type');
            $config["meta"]["trial_recurring_times"] = $has_setup_fee ? "" : 1;
            //rgpost("gf_paypalpro_trial_recurring_times");
            //api settings fields
            $config["meta"]["api_settings_enabled"] = rgpost('gf_paypalpro_api_settings');
            $config["meta"]["api_mode"] = rgpost('gf_paypalpro_api_mode');
            $config["meta"]["api_username"] = rgpost('gf_paypalpro_api_username');
            $config["meta"]["api_password"] = rgpost('gf_paypalpro_api_password');
            $config["meta"]["api_signature"] = rgpost('gf_paypalpro_api_signature');
            if (!empty($config["meta"]["api_settings_enabled"])) {
                $local_api_settings = self::get_local_api_settings($config);
                self::log_debug("Validating credentials.");
                $is_valid = self::is_valid_key($local_api_settings);
                if ($is_valid) {
                    $config["meta"]["api_valid"] = true;
                    $config["meta"]["api_message"] = "Valid PayPal Pro credentials.";
                    self::log_debug($config["meta"]["api_message"]);
                } else {
                    $config["meta"]["api_valid"] = false;
                    $config["meta"]["api_message"] = "Invalid PayPal Pro credentials.";
                    self::log_error($config["meta"]["api_message"]);
                }
            }
            $customer_fields = self::get_customer_fields();
            $config["meta"]["customer_fields"] = array();
            foreach ($customer_fields as $field) {
                $config["meta"]["customer_fields"][$field["name"]] = $_POST["paypalpro_customer_field_{$field["name"]}"];
            }
            $config = apply_filters('gform_paypalpro_save_config', $config);
            $is_validation_error = apply_filters("gform_paypalpro_config_validation", false, $config);
            if (!$is_validation_error) {
                $id = GFPayPalProData::update_feed($id, $config["form_id"], $config["is_active"], $config["meta"]);
                ?>
                <div class="updated fade" style="padding:6px"><?php 
                echo sprintf(__("Feed Updated. %sback to list%s", "gravityformspaypalpro"), "<a href='?page=gf_paypalpro'>", "</a>");
                ?>
</div>
                <?php 
            } else {
                $is_validation_error = true;
            }
        }
        $form = isset($config["form_id"]) && $config["form_id"] ? $form = RGFormsModel::get_form_meta($config["form_id"]) : array();
        $settings = get_option("gf_paypalpro_settings");
        ?>
        <form method="post" action="">
            <input type="hidden" name="paypalpro_setting_id" value="<?php 
        echo $id;
        ?>
" />

            <div class="margin_vertical_10 <?php 
        echo $is_validation_error ? "paypalpro_validation_error" : "";
        ?>
">
                <?php 
        if ($is_validation_error) {
            ?>
                    <span><?php 
            _e('There was an issue saving your feed. Please address the errors below and try again.');
            ?>
</span>
                    <?php 
        }
        ?>
            </div> <!-- / validation message -->

            <?php 
        if ($settings["ipn_configured"] == "on") {
            ?>
            <div class="margin_vertical_10">
                <label class="left_header" for="gf_paypalpro_type"><?php 
            _e("Transaction Type", "gravityformspaypalpro");
            ?>
 <?php 
            gform_tooltip("paypalpro_transaction_type");
            ?>
</label>

                <select id="gf_paypalpro_type" name="gf_paypalpro_type" onchange="SelectType(jQuery(this).val());">
                    <option value=""><?php 
            _e("Select a transaction type", "gravityformspaypalpro");
            ?>
</option>
                    <option value="product" <?php 
            echo rgar($config['meta'], 'type') == "product" ? "selected='selected'" : "";
            ?>
><?php 
            _e("Products and Services", "gravityformspaypalpro");
            ?>
</option>
                    <option value="subscription" <?php 
            echo rgar($config['meta'], 'type') == "subscription" ? "selected='selected'" : "";
            ?>
><?php 
            _e("Subscriptions", "gravityformspaypalpro");
            ?>
</option>
                </select>
            </div>
            <?php 
        } else {
            $config["meta"]["type"] = "product";
            ?>

                  <input id="gf_paypalpro_type" type="hidden" name="gf_paypalpro_type" value="product">


            <?php 
        }
        ?>
            <div id="paypalpro_form_container" valign="top" class="margin_vertical_10" <?php 
        echo empty($config["meta"]["type"]) ? "style='display:none;'" : "";
        ?>
>
                <label for="gf_paypalpro_form" class="left_header"><?php 
        _e("Gravity Form", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_gravity_form");
        ?>
</label>

                <select id="gf_paypalpro_form" name="gf_paypalpro_form" onchange="SelectForm(jQuery('#gf_paypalpro_type').val(), jQuery(this).val(), '<?php 
        echo rgar($config, 'id');
        ?>
');">
                    <option value=""><?php 
        _e("Select a form", "gravityformspaypalpro");
        ?>
 </option>
                    <?php 
        $active_form = rgar($config, 'form_id');
        $available_forms = GFPayPalProData::get_available_forms($active_form);
        foreach ($available_forms as $current_form) {
            $selected = absint($current_form->id) == rgar($config, 'form_id') ? 'selected="selected"' : '';
            ?>

                            <option value="<?php 
            echo absint($current_form->id);
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo esc_html($current_form->title);
            ?>
</option>

                        <?php 
        }
        ?>
                </select>
                &nbsp;&nbsp;
                <img src="<?php 
        echo GFPayPalPro::get_base_url();
        ?>
/images/loading.gif" id="paypalpro_wait" style="display: none;"/>

                <div id="gf_paypalpro_invalid_product_form" class="gf_paypalpro_invalid_form"  style="display:none;">
                    <?php 
        _e("The form selected does not have any Product fields. Please add a Product field to the form and try again.", "gravityformspaypalpro");
        ?>
                </div>
                <div id="gf_paypalpro_invalid_donation_form" class="gf_paypalpro_invalid_form" style="display:none;">
                    <?php 
        _e("The form selected does not have any Donation fields. Please add a Donation field to the form and try again.", "gravityformspaypalpro");
        ?>
                </div>
            </div>
            <div id="paypalpro_field_group" valign="top" <?php 
        echo empty($config["meta"]["type"]) || empty($config["form_id"]) ? "style='display:none;'" : "";
        ?>
>

                <div id="paypalpro_field_container_subscription" class="paypalpro_field_container" valign="top" <?php 
        echo rgars($config, "meta/type") != "subscription" ? "style='display:none;'" : "";
        ?>
>
                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_recurring_amount"><?php 
        _e("Recurring Amount", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_recurring_amount");
        ?>
</label>
                        <select id="gf_paypalpro_recurring_amount" name="gf_paypalpro_recurring_amount">
                            <?php 
        echo self::get_product_options($form, rgar($config["meta"], "recurring_amount_field"), true);
        ?>
                        </select>
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_billing_cycle_number"><?php 
        _e("Billing Cycle", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_billing_cycle");
        ?>
</label>
                        <select id="gf_paypalpro_billing_cycle_number" name="gf_paypalpro_billing_cycle_number">
                            <?php 
        for ($i = 1; $i <= 100; $i++) {
            ?>
                                <option value="<?php 
            echo $i;
            ?>
" <?php 
            echo rgar($config["meta"], "billing_cycle_number") == $i ? "selected='selected'" : "";
            ?>
><?php 
            echo $i;
            ?>
</option>
                            <?php 
        }
        ?>
                        </select>&nbsp;
                        <select id="gf_paypalpro_billing_cycle_type" name="gf_paypalpro_billing_cycle_type" onchange="SetPeriodNumber('#gf_paypalpro_billing_cycle_number', jQuery(this).val());">
                            <option value="D" <?php 
        echo rgars($config, "meta/billing_cycle_type") == "D" ? "selected='selected'" : "";
        ?>
><?php 
        _e("day(s)", "gravityformspaypalpro");
        ?>
</option>
                            <option value="W" <?php 
        echo rgars($config, "meta/billing_cycle_type") == "W" ? "selected='selected'" : "";
        ?>
><?php 
        _e("week(s)", "gravityformspaypalpro");
        ?>
</option>
                            <option value="M" <?php 
        echo rgars($config, "meta/billing_cycle_type") == "M" || strlen(rgars($config, "meta/billing_cycle_type")) == 0 ? "selected='selected'" : "";
        ?>
><?php 
        _e("month(s)", "gravityformspaypalpro");
        ?>
</option>
                            <option value="Y" <?php 
        echo rgars($config, "meta/billing_cycle_type") == "Y" ? "selected='selected'" : "";
        ?>
><?php 
        _e("year", "gravityformspaypalpro");
        ?>
</option>
                        </select>
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_recurring_times"><?php 
        _e("Recurring Times", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_recurring_times");
        ?>
</label>
                        <select id="gf_paypalpro_recurring_times" name="gf_paypalpro_recurring_times">
                            <option value=""><?php 
        _e("Infinite", "gravityformspaypalpro");
        ?>
</option>
                            <?php 
        for ($i = 2; $i <= 30; $i++) {
            $selected = $i == rgar($config["meta"], "recurring_times") ? 'selected="selected"' : '';
            ?>
                                <option value="<?php 
            echo $i;
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo $i;
            ?>
</option>
                                <?php 
        }
        ?>
                        </select>
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_setup_fee"><?php 
        _e("Setup Fee", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_setup_fee_enable");
        ?>
</label>
                        <input type="checkbox" onchange="if(this.checked) {jQuery('#gf_paypalpro_setup_fee_amount').val('Select a field');}" name="gf_paypalpro_setup_fee" id="gf_paypalpro_setup_fee" value="1" onclick="ToggleSetupFee();" <?php 
        echo rgars($config, "meta/setup_fee_enabled") ? "checked='checked'" : "";
        ?>
 />
                        <label class="inline" for="gf_paypalpro_setup_fee"><?php 
        _e("Enable", "gravityformspaypalpro");
        ?>
</label>
                        &nbsp;&nbsp;&nbsp;
                        <span id="paypalpro_setup_fee_container" <?php 
        echo rgars($config, "meta/setup_fee_enabled") ? "" : "style='display:none;'";
        ?>
>
                            <select id="gf_paypalpro_setup_fee_amount" name="gf_paypalpro_setup_fee_amount">
                                <?php 
        echo self::get_product_options($form, rgar($config["meta"], "setup_fee_amount_field"), false);
        ?>
                            </select>
                        </span>
                    </div>

                    <div id='paypalpro_enable_trial_container' class="margin_vertical_10" <?php 
        echo rgars($config, "meta/setup_fee_enabled") ? "style='display:none;'" : "";
        ?>
>
                        <label class="left_header" for="gf_paypalpro_trial_period"><?php 
        _e("Trial Period", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_trial_period_enable");
        ?>
</label>
                        <input type="checkbox" name="gf_paypalpro_trial_period" id="gf_paypalpro_trial_period" value="1" onclick="ToggleTrial();" <?php 
        echo rgars($config, "meta/trial_period_enabled") ? "checked='checked'" : "";
        ?>
 />
                        <label class="inline" for="gf_paypalpro_trial_period"><?php 
        _e("Enable", "gravityformspaypalpro");
        ?>
</label>
                    </div>

                    <div id="paypalpro_trial_period_container" <?php 
        echo rgars($config, "meta/trial_period_enabled") && !rgars($config, "meta/setup_fee_enabled") ? "" : "style='display:none;'";
        ?>
>

                        <div class="margin_vertical_10">
                            <label class="left_header" for="gf_paypalpro_trial_type"><?php 
        _e("Trial Amount", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_trial_amount");
        ?>
</label>
                            <input type="radio" name="gf_paypalpro_trial_type" value="free" onclick="if(jQuery(this).is(':checked')) jQuery('#gf_paypalpro_trial_amount').val('Select a field');" <?php 
        echo rgar($config["meta"], "trial_type") != "paid" ? "checked='checked'" : "";
        ?>
/>
                            <label class="inline" for="gf_paypalpro_trial_type_free"><?php 
        _e("Free", "gravityformspaypalpro");
        ?>
</label>
                            &nbsp;&nbsp;&nbsp;
                            <input type="radio" name="gf_paypalpro_trial_type" value="paid" <?php 
        echo rgar($config["meta"], "trial_type") == "paid" ? "checked='checked'" : "";
        ?>
/>
                            <span id="paypalpro_trial_amount_values">
                                <select id="gf_paypalpro_trial_amount" name="gf_paypalpro_trial_amount" onchange="jQuery('[name=gf_paypalpro_trial_type]').filter('[value=paid]').prop('checked',true);">
                                    <?php 
        echo self::get_product_options($form, rgar($config["meta"], "trial_amount_field"), false);
        ?>
                                </select>
                            </span>
                        </div>
                        <div class="margin_vertical_10">
                            <label class="left_header" for="gf_paypalpro_trial_period_number"><?php 
        _e("Trial Billing Cycle", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_trial_period");
        ?>
</label>
                            <select id="gf_paypalpro_trial_period_number" name="gf_paypalpro_trial_period_number">
                                <?php 
        for ($i = 1; $i <= 100; $i++) {
            ?>
                                    <option value="<?php 
            echo $i;
            ?>
" <?php 
            echo rgars($config, "meta/trial_period_number") == $i ? "selected='selected'" : "";
            ?>
><?php 
            echo $i;
            ?>
</option>
                                <?php 
        }
        ?>
                            </select>&nbsp;
                            <select id="gf_paypalpro_trial_period_type" name="gf_paypalpro_trial_period_type" onchange="SetPeriodNumber('#gf_paypalpro_trial_period_number', jQuery(this).val());">
                                <option value="D" <?php 
        echo rgars($config, "meta/trial_period_type") == "D" ? "selected='selected'" : "";
        ?>
><?php 
        _e("day(s)", "gravityformspaypalpro");
        ?>
</option>
                                <option value="W" <?php 
        echo rgars($config, "meta/trial_period_type") == "W" ? "selected='selected'" : "";
        ?>
><?php 
        _e("week(s)", "gravityformspaypalpro");
        ?>
</option>
                                <option value="M" <?php 
        echo rgars($config, "meta/trial_period_type") == "M" || empty($config["meta"]["trial_period_type"]) ? "selected='selected'" : "";
        ?>
><?php 
        _e("month(s)", "gravityformspaypalpro");
        ?>
</option>
                                <option value="Y" <?php 
        echo rgars($config, "meta/trial_period_type") == "Y" ? "selected='selected'" : "";
        ?>
><?php 
        _e("year(s)", "gravityformspaypalpro");
        ?>
</option>
                            </select>
                        </div>
                        <!--<div class="margin_vertical_10">
                            <label class="left_header" for="gf_paypalpro_trial_recurring_times"><?php 
        _e("Trial Recurring Times", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_trial_recurring_times");
        ?>
</label>
                            <select id="gf_paypalpro_trial_recurring_times" name="gf_paypalpro_trial_recurring_times">
                                <?php 
        for ($i = 1; $i <= 30; $i++) {
            $selected = $i == rgar($config["meta"], "trial_recurring_times") ? 'selected="selected"' : '';
            ?>
                                    <option value="<?php 
            echo $i;
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo $i;
            ?>
</option>
                                    <?php 
        }
        ?>
                            </select>
                        </div>-->
                    </div>
                </div>

                <div class="margin_vertical_10">
                    <label class="left_header"><?php 
        _e("Customer", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_customer");
        ?>
</label>

                    <div id="paypalpro_customer_fields">
                        <?php 
        if (!empty($form)) {
            echo self::get_customer_information($form, $config);
        }
        ?>
                    </div>
                </div>

                <?php 
        $display_post_fields = !empty($form) ? GFCommon::has_post_field($form["fields"]) : false;
        ?>

                <div class="margin_vertical_10"  >
                    <ul style="overflow:hidden;">
                        <li id="paypalpro_post_update_action" <?php 
        echo $display_post_fields && $config["meta"]["type"] == "subscription" ? "" : "style='display:none;'";
        ?>
>
                            <label class="left_header"><?php 
        _e("Options", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_options");
        ?>
</label>
                            <input type="checkbox" name="gf_paypalpro_update_post" id="gf_paypalpro_update_post" value="1" <?php 
        echo rgar($config["meta"], "update_post_action") ? "checked='checked'" : "";
        ?>
 onclick="var action = this.checked ? 'draft' : ''; jQuery('#gf_paypalpro_update_action').val(action);" />
                            <label class="inline" for="gf_paypalpro_update_post"><?php 
        _e("Update Post when subscription is cancelled.", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_update_post");
        ?>
</label>
                            <select id="gf_paypalpro_update_action" name="gf_paypalpro_update_action" onchange="var checked = jQuery(this).val() ? 'checked' : false; jQuery('#gf_paypalpro_update_post').attr('checked', checked);">
                                <option value=""></option>
                                <option value="draft" <?php 
        echo rgar($config["meta"], "update_post_action") == "draft" ? "selected='selected'" : "";
        ?>
><?php 
        _e("Mark Post as Draft", "gravityformspaypalpro");
        ?>
</option>
                                <option value="delete" <?php 
        echo rgar($config["meta"], "update_post_action") == "delete" ? "selected='selected'" : "";
        ?>
><?php 
        _e("Delete Post", "gravityformspaypalpro");
        ?>
</option>
                            </select>
                        </li>

                        <?php 
        do_action("gform_paypalpro_action_fields", $config, $form);
        ?>
                    </ul>
                </div>

                <?php 
        do_action("gform_paypalpro_add_option_group", $config, $form);
        ?>

                <div id="gf_paypalpro_conditional_section" valign="top" class="margin_vertical_10">
                    <label for="gf_paypalpro_conditional_optin" class="left_header"><?php 
        _e("PayPal Pro Condition", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_conditional");
        ?>
</label>

                    <div id="gf_paypalpro_conditional_option">
                        <table cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    <input type="checkbox" id="gf_paypalpro_conditional_enabled" name="gf_paypalpro_conditional_enabled" value="1" onclick="if(this.checked){jQuery('#gf_paypalpro_conditional_container').fadeIn('fast');} else{ jQuery('#gf_paypalpro_conditional_container').fadeOut('fast'); }" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_enabled') ? "checked='checked'" : "";
        ?>
/>
                                    <label for="gf_paypalpro_conditional_enable"><?php 
        _e("Enable", "gravityformspaypalpro");
        ?>
</label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="gf_paypalpro_conditional_container" <?php 
        echo !rgar($config['meta'], 'paypalpro_conditional_enabled') ? "style='display:none'" : "";
        ?>
>

                                        <div id="gf_paypalpro_conditional_fields" style="display:none">
                                            <?php 
        _e("Send to PayPal Pro if ", "gravityformspaypalpro");
        ?>

                                            <select id="gf_paypalpro_conditional_field_id" name="gf_paypalpro_conditional_field_id" class="optin_select" onchange='jQuery("#gf_paypalpro_conditional_value_container").html(GetFieldValues(jQuery(this).val(), "", 20));'></select>
                                            <select id="gf_paypalpro_conditional_operator" name="gf_paypalpro_conditional_operator">
                                                <option value="is" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "is" ? "selected='selected'" : "";
        ?>
><?php 
        _e("is", "gravityformspaypalpro");
        ?>
</option>
                                                <option value="isnot" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "isnot" ? "selected='selected'" : "";
        ?>
><?php 
        _e("is not", "gravityformspaypalpro");
        ?>
</option>
                                                <option value=">" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == ">" ? "selected='selected'" : "";
        ?>
><?php 
        _e("greater than", "gravityformspaypalpro");
        ?>
</option>
                                                <option value="<" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "<" ? "selected='selected'" : "";
        ?>
><?php 
        _e("less than", "gravityformspaypalpro");
        ?>
</option>
                                                <option value="contains" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "contains" ? "selected='selected'" : "";
        ?>
><?php 
        _e("contains", "gravityformspaypalpro");
        ?>
</option>
                                                <option value="starts_with" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "starts_with" ? "selected='selected'" : "";
        ?>
><?php 
        _e("starts with", "gravityformspaypalpro");
        ?>
</option>
                                                <option value="ends_with" <?php 
        echo rgar($config['meta'], 'paypalpro_conditional_operator') == "ends_with" ? "selected='selected'" : "";
        ?>
><?php 
        _e("ends with", "gravityformspaypalpro");
        ?>
</option>
                                            </select>
                                            <div id="gf_paypalpro_conditional_value_container" name="gf_paypalpro_conditional_value_container" style="display:inline;"></div>
                                        </div>
                                        <div id="gf_paypalpro_conditional_message" style="display:none">
                                            <?php 
        _e("To create a registration condition, your form must have a field supported by conditional logic.", "gravityform");
        ?>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>

                </div> <!-- / paypalpro conditional -->

                <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_api_settings"><?php 
        _e("API Settings", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_api_settings_enable");
        ?>
</label>
                        <input type="checkbox" name="gf_paypalpro_api_settings" id="gf_paypalpro_api_settings" value="1" onclick="if(jQuery(this).is(':checked')) jQuery('#paypalpro_api_settings_container').show('slow'); else jQuery('#paypalpro_api_settings_container').hide('slow');" <?php 
        echo rgars($config, "meta/api_settings_enabled") ? "checked='checked'" : "";
        ?>
 />
                        <label class="inline" for="gf_paypalpro_api_settings"><?php 
        _e("Override Default Settings", "gravityformspaypalpro");
        ?>
</label>
                </div>

                <div id="paypalpro_api_settings_container" <?php 
        echo rgars($config, "meta/api_settings_enabled") ? "" : "style='display:none;'";
        ?>
>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_api_mode"><?php 
        _e("API", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_api_mode");
        ?>
</label>
                        <input type="radio" name="gf_paypalpro_api_mode" value="production" <?php 
        echo rgar($config["meta"], "api_mode") != "test" ? "checked='checked'" : "";
        ?>
/>
                        <label class="inline" for="gf_paypalpro_api_mode_production"><?php 
        _e("Production", "gravityformspaypalpro");
        ?>
</label>
                        &nbsp;&nbsp;&nbsp;
                        <input type="radio" name="gf_paypalpro_api_mode" value="test" <?php 
        echo rgar($config["meta"], "api_mode") == "test" ? "checked='checked'" : "";
        ?>
/>
                        <label class="inline" for="gf_paypalpro_api_mode_test"><?php 
        _e("Sandbox", "gravityformspaypalpro");
        ?>
</label>
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_api_username"><?php 
        _e("API Username", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_api_username");
        ?>
</label>
                        <input class="size-1" id="gf_paypalpro_api_username" name="gf_paypalpro_api_username" value="<?php 
        echo rgar($config["meta"], "api_username");
        ?>
" />
                        <img src="<?php 
        echo self::get_base_url();
        ?>
/images/<?php 
        echo rgars($config, "meta/api_valid") ? "tick.png" : "stop.png";
        ?>
" border="0" alt="<?php 
        echo $config["meta"]["api_message"];
        ?>
" title="<?php 
        echo $config["meta"]["api_message"];
        ?>
" style="display:<?php 
        echo empty($config["meta"]["api_message"]) ? 'none;' : 'inline;';
        ?>
" />
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_api_password"><?php 
        _e("API Password", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_api_password");
        ?>
</label>
                        <input class="size-1" id="gf_paypalpro_api_password" name="gf_paypalpro_api_password" value="<?php 
        echo rgar($config["meta"], "api_password");
        ?>
" />
                        <img src="<?php 
        echo self::get_base_url();
        ?>
/images/<?php 
        echo rgars($config, "meta/api_valid") ? "tick.png" : "stop.png";
        ?>
" border="0" alt="<?php 
        echo $config["meta"]["api_message"];
        ?>
" title="<?php 
        echo $config["meta"]["api_message"];
        ?>
" style="display:<?php 
        echo empty($config["meta"]["api_message"]) ? 'none;' : 'inline;';
        ?>
" />
                    </div>

                    <div class="margin_vertical_10">
                        <label class="left_header" for="gf_paypalpro_api_signature"><?php 
        _e("API Signature", "gravityformspaypalpro");
        ?>
 <?php 
        gform_tooltip("paypalpro_api_signature");
        ?>
</label>
                        <input class="size-1" id="gf_paypalpro_api_signature" name="gf_paypalpro_api_signature" value="<?php 
        echo rgar($config["meta"], "api_signature");
        ?>
" />
                        <img src="<?php 
        echo self::get_base_url();
        ?>
/images/<?php 
        echo rgars($config, "meta/api_valid") ? "tick.png" : "stop.png";
        ?>
" border="0" alt="<?php 
        echo $config["meta"]["api_message"];
        ?>
" title="<?php 
        echo $config["meta"]["api_message"];
        ?>
" style="display:<?php 
        echo empty($config["meta"]["api_message"]) ? 'none;' : 'inline;';
        ?>
" />
                    </div>

                </div>

                <div id="paypalpro_submit_container" class="margin_vertical_30">
                    <input type="submit" name="gf_paypalpro_submit" value="<?php 
        echo empty($id) ? __("  Save  ", "gravityformspaypalpro") : __("Update", "gravityformspaypalpro");
        ?>
" class="button-primary"/>
                    <input type="button" value="<?php 
        _e("Cancel", "gravityformspaypalpro");
        ?>
" class="button" onclick="javascript:document.location='admin.php?page=gf_paypalpro'" />
                </div>
            </div>
        </form>
        </div>

        <script type="text/javascript">
            jQuery(document).ready(function(){
                SetPeriodNumber('#gf_paypalpro_billing_cycle_number', jQuery("#gf_paypalpro_billing_cycle_type").val());
                SetPeriodNumber('#gf_paypalpro_trial_period_number', jQuery("#gf_paypalpro_trial_period_type").val());
            });

            function SelectType(type){
                jQuery("#paypalpro_field_group").slideUp();

                jQuery("#paypalpro_field_group input[type=\"text\"], #paypalpro_field_group select").val("");
                jQuery("#gf_paypalpro_trial_period_type, #gf_paypalpro_billing_cycle_type").val("M");

                jQuery("#paypalpro_field_group input:checked").attr("checked", false);

                if(type){
                    jQuery("#paypalpro_form_container").slideDown();
                    jQuery("#gf_paypalpro_form").val("");
                }
                else{
                    jQuery("#paypalpro_form_container").slideUp();
                }
            }

            function SelectForm(type, formId, settingId){
                if(!formId){
                    jQuery("#paypalpro_field_group").slideUp();
                    return;
                }

                jQuery("#paypalpro_wait").show();
                jQuery("#paypalpro_field_group").slideUp();

                var mysack = new sack(ajaxurl);
                mysack.execute = 1;
                mysack.method = 'POST';
                mysack.setVar( "action", "gf_select_paypalpro_form" );
                mysack.setVar( "gf_select_paypalpro_form", "<?php 
        echo wp_create_nonce("gf_select_paypalpro_form");
        ?>
" );
                mysack.setVar( "type", type);
                mysack.setVar( "form_id", formId);
                mysack.setVar( "setting_id", settingId);
                mysack.encVar( "cookie", document.cookie, false );
                mysack.onError = function() {jQuery("#paypalpro_wait").hide(); alert('<?php 
        _e("Ajax error while selecting a form", "gravityformspaypalpro");
        ?>
' )};
                mysack.runAJAX();

                return true;
            }

            function EndSelectForm(form_meta, customer_fields, recurring_amount_options, product_field_options){
                //setting global form object
                form = form_meta;

                var type = jQuery("#gf_paypalpro_type").val();

                jQuery(".gf_paypalpro_invalid_form").hide();
                if( (type == "product" || type =="subscription") && GetFieldsByType(["product"]).length == 0){
                    jQuery("#gf_paypalpro_invalid_product_form").show();
                    jQuery("#paypalpro_wait").hide();
                    return;
                }
                else if(type == "donation" && GetFieldsByType(["product", "donation"]).length == 0){
                    jQuery("#gf_paypalpro_invalid_donation_form").show();
                    jQuery("#paypalpro_wait").hide();
                    return;
                }

                jQuery(".paypalpro_field_container").hide();
                jQuery("#paypalpro_customer_fields").html(customer_fields);
                jQuery("#gf_paypalpro_recurring_amount").html(recurring_amount_options);
                jQuery("#gf_paypalpro_trial_amount").html(product_field_options);
                jQuery("#gf_paypalpro_setup_fee_amount").html(product_field_options);

                //displaying delayed post creation setting if current form has a post field
                var post_fields = GetFieldsByType(["post_title", "post_content", "post_excerpt", "post_category", "post_custom_field", "post_image", "post_tag"]);
                if(post_fields.length > 0){
                    jQuery("#paypalpro_post_action").show();
                }
                else{
                    //jQuery("#gf_paypalpro_delay_post").attr("checked", false);
                    jQuery("#paypalpro_post_action").hide();
                }

                if(type == "subscription" && post_fields.length > 0){
                    jQuery("#paypalpro_post_update_action").show();
                }
                else{
                    jQuery("#gf_paypalpro_update_post").attr("checked", false);
                    jQuery("#paypalpro_post_update_action").hide();
                }

                SetPeriodNumber('#gf_paypalpro_billing_cycle_number', jQuery("#gf_paypalpro_billing_cycle_type").val());
                SetPeriodNumber('#gf_paypalpro_trial_period_number', jQuery("#gf_paypalpro_trial_period_type").val());

                //Calling callback functions
                jQuery(document).trigger('paypalproFormSelected', [form]);

                jQuery("#gf_paypalpro_conditional_enabled").attr('checked', false);
                SetPayPalProCondition("","");

                jQuery("#paypalpro_field_container_" + type).show();
                jQuery("#paypalpro_field_group").slideDown();
                jQuery("#paypalpro_wait").hide();
            }

            function SetPeriodNumber(element, type){
                var prev = jQuery(element).val();

                var min = 1;
                var max = 0;
                switch(type){
                    case "D" :
                        max = 100;
                    break;
                    case "W" :
                        max = 52;
                    break;
                    case "M" :
                        max = 12;
                    break;
                    case "Y" :
                        max = 1;
                    break;
                }
                var str="";
                for(var i=min; i<=max; i++){
                    var selected = prev == i ? "selected='selected'" : "";
                    str += "<option value='" + i + "' " + selected + ">" + i + "</option>";
                }
                jQuery(element).html(str);
            }

            function GetFieldsByType(types){
                var fields = new Array();
                for(var i=0; i<form["fields"].length; i++){
                    if(IndexOf(types, form["fields"][i]["type"]) >= 0)
                        fields.push(form["fields"][i]);
                }
                return fields;
            }

            function IndexOf(ary, item){
                for(var i=0; i<ary.length; i++)
                    if(ary[i] == item)
                        return i;

                return -1;
            }

        </script>

        <script type="text/javascript">

            // Paypal Conditional Functions

            <?php 
        if (!empty($config["form_id"])) {
            ?>

                // initilize form object
                form = <?php 
            echo GFCommon::json_encode($form);
            ?>
 ;

                // initializing registration condition drop downs
                jQuery(document).ready(function(){
                    var selectedField = "<?php 
            echo str_replace('"', '\\"', $config["meta"]["paypalpro_conditional_field_id"]);
            ?>
";
                    var selectedValue = "<?php 
            echo str_replace('"', '\\"', $config["meta"]["paypalpro_conditional_value"]);
            ?>
";
                    SetPayPalProCondition(selectedField, selectedValue);
                });

                <?php 
        }
        ?>

            function SetPayPalProCondition(selectedField, selectedValue){

                // load form fields
                jQuery("#gf_paypalpro_conditional_field_id").html(GetSelectableFields(selectedField, 20));
                var optinConditionField = jQuery("#gf_paypalpro_conditional_field_id").val();
                var checked = jQuery("#gf_paypalpro_conditional_enabled").attr('checked');

                if(optinConditionField){
                    jQuery("#gf_paypalpro_conditional_message").hide();
                    jQuery("#gf_paypalpro_conditional_fields").show();
                    jQuery("#gf_paypalpro_conditional_value_container").html(GetFieldValues(optinConditionField, selectedValue, 20));
                    jQuery("#gf_paypalpro_conditional_value").val(selectedValue);
                }
                else{
                    jQuery("#gf_paypalpro_conditional_message").show();
                    jQuery("#gf_paypalpro_conditional_fields").hide();
                }

                if(!checked) jQuery("#gf_paypalpro_conditional_container").hide();

            }

            function GetFieldValues(fieldId, selectedValue, labelMaxCharacters){
                if(!fieldId)
                    return "";

                var str = "";
                var field = GetFieldById(fieldId);
                if(!field)
                    return "";

                var isAnySelected = false;

                if(field["type"] == "post_category" && field["displayAllCategories"]){
                    str += '<?php 
        $dd = wp_dropdown_categories(array("class" => "optin_select", "orderby" => "name", "id" => "gf_paypalpro_conditional_value", "name" => "gf_paypalpro_conditional_value", "hierarchical" => true, "hide_empty" => 0, "echo" => false));
        echo str_replace("\n", "", str_replace("'", "\\'", $dd));
        ?>
';
                }
                else if(field.choices){
                    str += '<select id="gf_paypalpro_conditional_value" name="gf_paypalpro_conditional_value" class="optin_select">'

                    for(var i=0; i<field.choices.length; i++){
                        var fieldValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text;
                        var isSelected = fieldValue == selectedValue;
                        var selected = isSelected ? "selected='selected'" : "";
                        if(isSelected)
                            isAnySelected = true;

                        str += "<option value='" + fieldValue.replace(/'/g, "&#039;") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>";
                    }

                    if(!isAnySelected && selectedValue){
                        str += "<option value='" + selectedValue.replace(/'/g, "&#039;") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>";
                    }
                    str += "</select>";
                }
                else
                {
                    selectedValue = selectedValue ? selectedValue.replace(/'/g, "&#039;") : "";
                    //create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...)
                    str += "<input type='text' placeholder='<?php 
        _e("Enter value", "gravityforms");
        ?>
' id='gf_paypalpro_conditional_value' name='gf_paypalpro_conditional_value' value='" + selectedValue.replace(/'/g, "&#039;") + "'>";
                }

                return str;
            }

            function GetFieldById(fieldId){
                for(var i=0; i<form.fields.length; i++){
                    if(form.fields[i].id == fieldId)
                        return form.fields[i];
                }
                return null;
            }

            function TruncateMiddle(text, maxCharacters){
                if(!text)
                    return "";

                if(text.length <= maxCharacters)
                    return text;
                var middle = parseInt(maxCharacters / 2);
                return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle);
            }

            function GetSelectableFields(selectedFieldId, labelMaxCharacters){
                var str = "";
                var inputType;
                for(var i=0; i<form.fields.length; i++){
                    fieldLabel = form.fields[i].adminLabel ? form.fields[i].adminLabel : form.fields[i].label;
                    inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
                    if (IsConditionalLogicField(form.fields[i])) {
                        var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : "";
                        str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(fieldLabel, labelMaxCharacters) + "</option>";
                    }
                }
                return str;
            }

            function IsConditionalLogicField(field){
                inputType = field.inputType ? field.inputType : field.type;
                var supported_fields = ["checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title",
                                        "post_tags", "post_custom_field", "post_content", "post_excerpt"];

                var index = jQuery.inArray(inputType, supported_fields);

                return index >= 0;
            }

        </script>

        <?php 
    }
<link rel="stylesheet" href="<?php 
echo GFPayPalPro::get_base_url() . "/css/confirmation.css";
?>
" />

<?php 
if (empty($products["products"])) {
    ?>
    <div class="error"><?php 
    printf(__("Your cart is empty. Order could not be processed. %sReturn to site%s", "gravityformspaypalpro"), "<a href='" . home_url() . "'>", "</a>");
    ?>
</div>
    <?php 
} else {
    ?>
    <!-- begin product checkout table markup -->
    <form method='post'>
        <div class="gf_checkout_review_table_wrapper">

            <h2 class="gf_checkout_heading"><?php 
    _e("Checkout", "gravityformspaypalpro");
    ?>
</h2>

            <table cellspacing="0" class="gf_checkout_review_table">
                <thead>
                    <tr>
                        <td colspan="4" class="gf_checkout_review_table_title"><?php 
    _e("Order Review", "gravityformspaypalpro");
    ?>
</td>