Example #1
0
function qpp_coupon_codes($id)
{
    qpp_change_form_update();
    if (isset($_POST['Submit']) && check_admin_referer("save_qpp")) {
        $arr = array('couponnumber', 'couponget', 'duplicate', 'couponerror');
        foreach ($arr as $item) {
            $coupon[$item] = stripslashes($_POST[$item]);
            $coupon[$item] = filter_var($coupon[$item], FILTER_SANITIZE_STRING);
        }
        $options = array('code', 'coupontype', 'couponpercent', 'couponfixed');
        if ($coupon['couponnumber'] < 1) {
            $coupon['couponnumber'] = 1;
        }
        for ($i = 1; $i <= $coupon['couponnumber']; $i++) {
            foreach ($options as $item) {
                $coupon[$item . $i] = stripslashes($_POST[$item . $i]);
            }
            if (!$coupon['coupontype' . $i]) {
                $coupon['coupontype' . $i] = 'percent' . $i;
            }
            if (!$coupon['couponpercent' . $i]) {
                $coupon['couponpercent' . $i] = '10';
            }
            if (!$coupon['couponfixed' . $i]) {
                $coupon['couponfixed' . $i] = '5';
            }
        }
        update_option('qpp_coupon' . $id, $coupon);
        if ($coupon['duplicate']) {
            $qpp_setup = qpp_get_stored_setup();
            $arr = explode(",", $qpp_setup['alternative']);
            foreach ($arr as $item) {
                update_option('qpp_coupon' . $item, $coupon);
            }
        }
        qpp_admin_notice("The coupon settings have been updated.");
    }
    if (isset($_POST['Reset']) && check_admin_referer("save_qpp")) {
        delete_option('qpp_coupon' . $id);
        qpp_admin_notice("The coupon settings have been reset.");
    }
    $qpp_setup = qpp_get_stored_setup();
    $id = $qpp_setup['current'];
    $currency = qpp_get_stored_curr();
    $before = array('USD' => '&#x24;', 'CDN' => '&#x24;', 'EUR' => '&euro;', 'GBP' => '&pound;', 'JPY' => '&yen;', 'AUD' => '&#x24;', 'BRL' => 'R&#x24;', 'HKD' => '&#x24;', 'ILS' => '&#x20aa;', 'MXN' => '&#x24;', 'NZD' => '&#x24;', 'PHP' => '&#8369;', 'SGD' => '&#x24;', 'TWD' => 'NT&#x24;', 'TRY' => '&pound;');
    $after = array('CZK' => 'K&#269;', 'DKK' => 'Kr', 'HUF' => 'Ft', 'MYR' => 'RM', 'NOK' => 'kr', 'PLN' => 'z&#322', 'RUB' => '&#1056;&#1091;&#1073;', 'SEK' => 'kr', 'CHF' => 'CHF', 'THB' => '&#3647;');
    foreach ($before as $item => $key) {
        if ($item == $currency[$id]) {
            $b = $key;
        }
    }
    foreach ($after as $item => $key) {
        if ($item == $currency[$id]) {
            $a = $key;
        }
    }
    $coupon = qpp_get_stored_coupon($id);
    $content = '<div class="qpp-settings"><div class="qpp-options">';
    if ($id) {
        $content .= '<h2>Coupons codes for ' . $id . '</h2>';
    } else {
        $content .= '<h2>Default form coupons codes</h2>';
    }
    $content .= qpp_change_form($qpp_setup);
    $content .= '<form method="post" action="">
    <p<span<b>Note:</b> Leave fields blank if you don\'t want to use them</span></p>
    <p>Number of Coupons: <input type="text" name="couponnumber" value="' . $coupon['couponnumber'] . '" style="width:4em"></p>
    <table>
    <tr><td>Coupon Code</td><td>Percentage</td><td>Fixed Amount</td></tr>';
    for ($i = 1; $i <= $coupon['couponnumber']; $i++) {
        $percent = $coupon['coupontype' . $i] == 'percent' . $i ? 'checked' : '';
        $fixed = $coupon['coupontype' . $i] == 'fixed' . $i ? 'checked' : '';
        $content .= '<tr><td><input type="text" name="code' . $i . '" value="' . $coupon['code' . $i] . '" /></td>
        <td><input style="margin:0; padding:0; border:none;" type="radio" name="coupontype' . $i . '" value="percent' . $i . '" ' . $percent . ' /> <input type="text" style="width:4em;padding:2px" label="couponpercent' . $i . '" name="couponpercent' . $i . '" value="' . $coupon['couponpercent' . $i] . '" /> %</td>
        <td><input style="margin:0; padding:0; border:none;" type="radio" name="coupontype' . $i . '" value="fixed' . $i . '" ' . $fixed . ' />&nbsp;' . $b . '&nbsp;<input type="text" style="width:4em;padding:2px" label="couponfixed' . $i . '" name="couponfixed' . $i . '" value="' . $coupon['couponfixed' . $i] . '" /> ' . $a . '</td></tr>';
    }
    $content .= '</table>
    <h2>Invalid Coupon Code Message</h2>
    <input id="couponerror" type="text" name="couponerror" value="' . $coupon['couponerror'] . '" /></p>
    <h2>Coupon Code Autofill</h2>
    <p>You can add coupon codes to URLs which will autofill the field. The URL format is: mysite.com/mypaymentpage/?coupon=code. The code you set will appear on the form with the following caption:<br>
    <input id="couponget" type="text" name="couponget" value="' . $coupon['couponget'] . '" /></p>
    <h2>Clone Coupon Settings</h2>
    <p><input type="checkbox" style="margin:0; padding: 0; border: none" name="duplicate" ' . $coupon['duplicate'] . ' value="checked" /> Duplicate coupon codes across all forms</p>
    <p><input type="submit" name="Submit" class="button-primary" style="color: #FFF;" value="Save Changes" /> <input type="submit" name="Reset" class="button-primary" style="color: #FFF;" value="Reset" onclick="return window.confirm( \'Are you sure you want to reset the coupon codes?\' );"/></p>';
    $content .= wp_nonce_field("save_qpp");
    $content .= '</form>
    </div>
    <div class="qpp-options" style="float:right;">
    <h2>Coupon Check</h2>
    <p>Test your coupon codes.</p>';
    if ($id) {
        $form = ' form="' . $id . '"';
    }
    $args = array('form' => $id, 'id' => '', 'amount' => '');
    $content .= qpp_loop($args);
    $content .= '<p>There are some more examples of payment forms <a href="http://quick-plugins.com/quick-paypal-payments/paypal-examples/" target="_blank">on this page</a>.</p>
    <p>And there are loads of shortcode options <a href="http://quick-plugins.com/quick-paypal-payments/paypal-payments-shortcodes/" target="_blank">on this page</a>.</p>
    </div></div>';
    echo $content;
}
function qpp_show_messages($id)
{
    if ($id == 'default') {
        $id = '';
    }
    $qpp_setup = qpp_get_stored_setup();
    $qpp = qpp_get_stored_options($id);
    qpp_generate_csv();
    if (isset($_POST['qpp_emaillist'])) {
        $message = get_option('qpp_messages' . $id);
        $messageoptions = qpp_get_stored_msg();
        $content = qpp_messagetable($id, 'checked');
        $title = $id;
        if ($id == '') {
            $title = 'Default';
        }
        $title = 'Payment List for ' . $title . ' as at ' . date('j M Y');
        global $current_user;
        get_currentuserinfo();
        $qpp_email = $current_user->user_email;
        $headers = "From: {<{$qpp_email}>\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"utf-8\"\r\n";
        wp_mail($qpp_email, $title, $content, $headers);
        qpp_admin_notice('Message list has been sent to ' . $qpp_email . '.');
    }
    if (isset($_POST['qpp_reset_message' . $id])) {
        delete_option('qpp_messages' . $id);
    }
    if (isset($_POST['Submit'])) {
        $options = array('messageqty', 'messageorder', 'showaddress');
        foreach ($options as $item) {
            $messageoptions[$item] = stripslashes($_POST[$item]);
        }
        update_option('qpp_messageoptions', $messageoptions);
        qpp_admin_notice("The message options have been updated.");
    }
    if (isset($_POST['qpp_delete_selected'])) {
        $id = $_POST['formname'];
        $message = get_option('qpp_messages' . $id);
        $count = count($message);
        for ($i = 0; $i <= $count; $i++) {
            if ($_POST[$i] == 'checked') {
                unset($message[$i]);
            }
        }
        $message = array_values($message);
        update_option('qpp_messages' . $id, $message);
        qpp_admin_notice('Selected payments have been deleted.');
    }
    $messageoptions = qpp_get_stored_msg();
    $fifty = $hundred = $all = $oldest = $newest = '';
    $showthismany = '9999';
    if ($messageoptions['messageqty'] == 'fifty') {
        $showthismany = '50';
    }
    if ($messageoptions['messageqty'] == 'hundred') {
        $showthismany = '100';
    }
    ${$messageoptions}['messageqty'] = "checked";
    ${$messageoptions}['messageorder'] = "checked";
    $dashboard = '<form method="post" action="">
    <p><b>Show</b> <input style="margin:0; padding:0; border:none;" type="radio" name="messageqty" value="fifty" ' . $fifty . ' /> 50 
    <input style="margin:0; padding:0; border:none;" type="radio" name="messageqty" value="hundred" ' . $hundred . ' /> 100 
    <input style="margin:0; padding:0; border:none;" type="radio" name="messageqty" value="all" ' . $all . ' /> all messages.&nbsp;&nbsp;
    <b>List</b> <input style="margin:0; padding:0; border:none;" type="radio" name="messageorder" value="oldest" ' . $oldest . ' /> oldest first 
    <input style="margin:0; padding:0; border:none;" type="radio" name="messageorder" value="newest" ' . $newest . ' /> newest first
    &nbsp;&nbsp;
    <input style="margin:0; padding:0; border:none;" type="checkbox" name="showaddress" value="checked" ' . $messageoptions['showaddress'] . ' /> Show Addresses
    &nbsp;&nbsp;
    <input type="submit" name="Submit" class="button-secondary" value="Update options" />
    </form></p>';
    $dashboard .= '<form method="post" id="download_form" action="">';
    $dashboard .= qpp_messagetable($id, '');
    $dashboard .= '<input type="hidden" name="formname" value = "' . $id . '" />
    <input type="submit" name="download_qpp_csv" class="button-primary" value="Export to CSV" />
    <input type="submit" name="qpp_emaillist" class="button-primary" value="Email List" />
    <input type="submit" name="qpp_reset_message" class="button-secondary" value="Delete All" onclick="return window.confirm( \'Are you sure you want to delete all the payment details?\' );"/>
    <input type="submit" name="qpp_delete_selected" class="button-secondary" value="Delete Selected" onclick="return window.confirm( \'Are you sure you want to delete the selected payment details?\' );"/>
    </form></div></div>';
    echo $dashboard;
}