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;
}
Exemple #2
0
function qpp_generate_csv()
{
    $qpp_setup = qpp_get_stored_setup();
    if (isset($_POST['download_qpp_csv'])) {
        $id = $_POST['formname'];
        $filename = urlencode($id . '.csv');
        if ($id == '') {
            $filename = urlencode('default.csv');
        }
        header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header('Content-Type: text/csv');
        $outstream = fopen("php://output", 'w');
        $message = get_option('qpp_messages' . $id);
        $messageoptions = qpp_get_stored_msg();
        if (!is_array($message)) {
            $message = array();
        }
        $qpp = qpp_get_stored_options($id);
        $address = qpp_get_stored_address($id);
        $headerrow = array();
        array_push($headerrow, 'Date Sent');
        array_push($headerrow, $qpp['inputreference']);
        array_push($headerrow, $qpp['quantitylabel']);
        array_push($headerrow, $qpp['inputamount']);
        array_push($headerrow, $qpp['stock']);
        array_push($headerrow, $qpp['optionlabel']);
        array_push($headerrow, $qpp['couponblurb']);
        if ($messageoptions['showaddress']) {
            array_push($headerrow, $address['email']);
            array_push($headerrow, $address['firstname']);
            array_push($headerrow, $address['lastname']);
            array_push($headerrow, $address['address1']);
            array_push($headerrow, $address['address2']);
            array_push($headerrow, $address['city']);
            array_push($headerrow, $address['state']);
            array_push($headerrow, $address['zip']);
            array_push($headerrow, $address['country']);
            array_push($headerrow, $address['night_phone_b']);
        }
        if ($qpp_setup['ipn']) {
            array_push($headerrow, 'Paid');
        }
        fputcsv($outstream, $headerrow, ',', '"');
        foreach (array_reverse($message) as $value) {
            $cells = array();
            array_push($cells, $value['field0']);
            array_push($cells, $value['field1']);
            array_push($cells, $value['field2']);
            array_push($cells, $value['field3']);
            $value['field4'] = $value['field4'] != $value['stocklabel'] ? $value['field4'] : '';
            array_push($cells, $value['field4']);
            $value['field5'] = $value['field5'] != $value['optionlabel'] ? $value['field5'] : '';
            array_push($cells, $value['field5']);
            $value['field6'] = $value['field6'] != $value['couponblurb'] ? $value['field6'] : '';
            array_push($cells, $value['field6']);
            if ($messageoptions['showaddress']) {
                $value['field8'] = $value['field8'] != $address['email'] ? $value['field8'] : '';
                array_push($cells, $value['field8']);
                $value['field9'] = $value['field9'] != $address['firstname'] ? $value['field9'] : '';
                array_push($cells, $value['field9']);
                $value['field10'] = $value['field10'] != $address['lastname'] ? $value['field10'] : '';
                array_push($cells, $value['field10']);
                $value['field11'] = $value['field11'] != $address['address1'] ? $value['field11'] : '';
                array_push($cells, $value['field11']);
                $value['field12'] = $value['field12'] != $address['address2'] ? $value['field12'] : '';
                array_push($cells, $value['field12']);
                $value['field13'] = $value['field13'] != $address['city'] ? $value['field13'] : '';
                array_push($cells, $value['field13']);
                $value['field14'] = $value['field14'] != $address['state'] ? $value['field14'] : '';
                array_push($cells, $value['field14']);
                $value['field15'] = $value['field15'] != $address['zip'] ? $value['field15'] : '';
                array_push($cells, $value['field15']);
                $value['field16'] = $value['field16'] != $address['country'] ? $value['field16'] : '';
                array_push($cells, $value['field16']);
                $value['field17'] = $value['field17'] != $address['night_phone_b'] ? $value['field17'] : '';
                array_push($cells, $value['field17']);
            }
            if ($qpp_setup['ipn']) {
                $paid = $value['field18'] == 'Paid' ? 'Paid' : '';
                array_push($cells, $paid);
            }
            fputcsv($outstream, $cells, ',', '"');
        }
        fclose($outstream);
        exit;
    }
}
function qpp_send_confirmation($values, $id, $amounttopay)
{
    $qpp_setup = qpp_get_stored_setup();
    $qpp = qpp_get_stored_options($id);
    $send = qpp_get_stored_send($id);
    $auto = qpp_get_stored_autoresponder($id);
    $c = qpp_currency($id);
    if (empty($auto['fromemail'])) {
        $auto['fromemail'] = $qpp_setup['email'];
    }
    if (empty($auto['fromname'])) {
        $auto['fromname'] = get_bloginfo('name');
    }
    $fullamount = $c['b'] . $amounttopay . $c['a'];
    $headers = "From: {$auto['fromname']} <{$auto['fromemail']}>\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"utf-8\"\r\n";
    $subject = $auto['subject'];
    $ref = $qpp['shortcodereference'] ? $qpp['shortcodereference'] : 'Reference';
    if ($qpp['fixedreference']) {
        $qpp['inputreference'] = $ref;
    }
    $amt = $qpp['shortcodeamount'] ? $qpp['shortcodeamount'] : 'Amount';
    if ($qpp['fixedamount']) {
        $qpp['inputamount'] = $amt;
    }
    $details = '<table>
    <tr><td>' . $qpp['inputreference'] . ': </td><td>' . $values['reference'] . '</td></tr><tr><td>' . $qpp['quantitylabel'] . ': </td><td>' . $values['quantity'] . '</td></tr>';
    if ($qpp['use_stock']) {
        $details .= '<tr><td>' . $qpp['stocklabel'] . ': </td><td>' . strip_tags($values['stock']) . '</td></tr>';
    }
    if ($qpp['use_options']) {
        $details .= '<tr><td>' . $qpp['optionlabel'] . ': </td><td>' . strip_tags($values['option1']) . '</td></tr>';
    }
    $details .= '<tr><td>' . $qpp['inputamount'] . ': </td><td>' . $amounttopay . '</td></tr></table>';
    $content = '<p>' . $auto['message'] . '</p>';
    $content = str_replace('<p><p>', '<p>', $content);
    $content = str_replace('</p></p>', '</p>', $content);
    $content = str_replace('[firstname]', $values['firstname'], $content);
    $content = str_replace('[name]', $values['firstname'] . ' ' . $values['lastname'], $content);
    $content = str_replace('[reference]', $values['reference'], $content);
    $content = str_replace('[fullamount]', $fullamount, $content);
    $content = str_replace('[amount]', $amounttopay, $content);
    $content = str_replace('[stock]', $values['stock'], $content);
    $content = str_replace('[option]', $values['option1'], $content);
    $content = str_replace('[details]', $details, $content);
    if ($auto['paymentdetails']) {
        $content .= $details;
    }
    wp_mail($values['email'], $subject, $content, $headers);
    if ($send['confirmmessage']) {
        $subject = 'Payment for ' . $values['reference'];
        if ($qpp['useaddress']) {
            $contentb .= '<tr><td>' . $address['email'] . '</td><td>' . $values['email'] . '</td></tr></tr>
            <tr><td>' . $address['firstname'] . '</td><td>' . $values['firstname'] . '</td></tr>
            <tr><td>' . $address['lastname'] . '</td><td>' . $values['lastname'] . '</td></tr>
            <tr><td>' . $address['address1'] . '</td><td>' . $values['address1'] . '</td></tr>
            <tr><td>' . $address['address2'] . '</td><td>' . $values['address2'] . '</td></tr>
            <tr><td>' . $address['city'] . '</td><td>' . $values['city'] . '</td></tr>
            <tr><td>' . $address['state'] . '</td><td>' . $values['state'] . '</td></tr>
            <tr><td>' . $address['zip'] . '</td><td>' . $values['zip'] . '</td></tr>
            <tr><td>' . $address['country'] . '</td><td>' . $values['country'] . '</td></tr>
            <tr><td>' . $address['night_phone_b'] . '</td><td>' . $values['night_phone_b'] . '</td></tr>';
        }
        $content = $cotenta . $contentb . $contentc;
        wp_mail($qpp_setup['email'], $subject, $content, $headers);
    }
}