function qem_process_payment_form($values)
{
    $payments = qem_get_stored_payment();
    global $post;
    $page_url = qem_current_page_url();
    $reference = $post->post_title;
    $paypalurl = 'https://www.paypal.com/cgi-bin/webscr';
    $cost = get_post_meta($post->ID, 'event_cost', true);
    $cost = preg_replace('/[^.0-9]/', '', $cost);
    $quantity = $values['yourplaces'] < 1 ? 1 : strip_tags($values['yourplaces']);
    $redirect = get_post_meta($post->ID, 'event_redirect', true);
    if (!$redirect && $register['redirectionurl']) {
        $redirect = $register['redirectionurl'];
    }
    $redirect = $redirect ? $redirect : $page_url;
    if ($payments['useprocess'] && $payments['processtype'] == 'processpercent') {
        $percent = preg_replace('/[^.,0-9]/', '', $payments['processpercent']) / 100;
        $handling = $cost * $quantity * $percent;
    }
    if ($payments['useprocess'] && $payments['processtype'] == 'processfixed') {
        $handling = preg_replace('/[^.,0-9]/', '', $payments['processfixed']);
    }
    if ($payments['usecoupon']) {
        $coupon = qem_get_stored_coupon();
        for ($i = 1; $i <= 10; $i++) {
            if ($values['couponcode'] == $coupon['code' . $i]) {
                if ($coupon['coupontype' . $i] == 'percent' . $i) {
                    $cost = $cost - $cost * $coupon['couponpercent' . $i] / 100;
                }
                if ($coupon['coupontype' . $i] == 'fixed' . $i) {
                    $cost = $cost - $coupon['couponfixed' . $i];
                }
            }
        }
    }
    $content = '<h2 id="qem_reload">' . $payments['waiting'] . '</h2>
    <form action="' . $paypalurl . '" method="post" name="qempay" id="qempay">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="item_name" value="' . $reference . '"/>
    <input type="hidden" name="business" value="' . $payments['paypalemail'] . '">
    <input type="hidden" name="return" value="' . $redirect . '">
    <input type="hidden" name="cancel_return" value="' . $page_url . '">
    <input type="hidden" name="currency_code" value="' . $payments['currency'] . '">
    <input type="hidden" name="item_number" value="' . strip_tags($values['yourname']) . '">
    <input type="hidden" name="quantity" value="' . $quantity . '">
    <input type="hidden" name="amount" value="' . $cost . '">
    <input type="hidden" name="custom" value="' . $values['ipn'] . '">';
    if ($payments['useprocess']) {
        $content .= '<input type="hidden" name="handling" value="' . $handling . '">';
    }
    $content .= '</form>
    <script language="JavaScript">document.getElementById("qempay").submit();</script>';
    return $content;
}
function qem_coupon_codes()
{
    if (isset($_POST['Submit']) && check_admin_referer("save_qem")) {
        $options = array('code', 'coupontype', 'couponpercent', 'couponfixed');
        for ($i = 1; $i <= 10; $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('qem_coupon', $coupon);
        qem_admin_notice("The coupon settings have been updated");
    }
    if (isset($_POST['Reset']) && check_admin_referer("save_qem")) {
        delete_option('qem_coupon');
        qem_admin_notice("The coupon settings have been reset");
    }
    $payment = qem_get_stored_payment();
    $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 == $payment['currency']) {
            $b = $key;
        }
    }
    foreach ($after as $item => $key) {
        if ($item == $payment['currency']) {
            $a = $key;
        }
    }
    $coupon = qem_get_stored_coupon();
    $content = '<div class="qem-settings"><div class="qem-options">';
    $content .= '<h2>' . __('Coupons Codes', 'quick-event-manager') . '</h2>';
    $content .= '<form method="post" action="">
    <p<span<b>Note:</b>&nbsp;' . __('Leave fields blank if you don\'t want to use them', 'quick-event-manager') . '</span></p>
    <table width="100%">
    <tr>
    <td>' . __('Coupon Code', 'quick-event-manager') . '</td>
    <td>' . __('Percentage', 'quick-event-manager') . '</td>
    <td>' . __('Fixed Amount', 'quick-event-manager') . '</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 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 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>
    <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_qem");
    $content .= '</form>
    </div>
    </div>';
    echo $content;
}