function qpp_get_default_email()
{
    $qpp_setup = qpp_get_stored_setup();
    $qpp_email = array();
    $qpp_email[''] = $qpp_setup['email'];
    return $qpp_email;
}
Example #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_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;
}
    public function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('amount' => '', 'id' => '', 'form' => ''));
        $id = $instance['id'];
        $amount = $instance['amount'];
        $form = $instance['form'];
        $qpp_setup = qpp_get_stored_setup();
        ?>
        <h3>Select Form:</h3>
        <select class="widefat" name="<?php 
        echo $this->get_field_name('form');
        ?>
">
        <?php 
        $arr = explode(",", $qpp_setup['alternative']);
        foreach ($arr as $item) {
            if ($item == '') {
                $showname = 'default';
                $item = '';
            } else {
                $showname = $item;
            }
            if ($showname == $form || $form == '') {
                $selected = 'selected';
            } else {
                $selected = '';
            }
            ?>
<option value="<?php 
            echo $item;
            ?>
" id="<?php 
            echo $this->get_field_id('form');
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo $showname;
            ?>
</option><?php 
        }
        ?>
        </select>
        <h3>Presets:</h3>
        <p><label for="<?php 
        echo $this->get_field_id('id');
        ?>
">Payment Reference: <input class="widefat" id="<?php 
        echo $this->get_field_id('id');
        ?>
" name="<?php 
        echo $this->get_field_name('id');
        ?>
" type="text" value="<?php 
        echo attribute_escape($id);
        ?>
" /></label></p>
        <p><label for="<?php 
        echo $this->get_field_id('amount');
        ?>
">Amount: <input class="widefat" id="<?php 
        echo $this->get_field_id('amount');
        ?>
" name="<?php 
        echo $this->get_field_name('amount');
        ?>
" type="text" value="<?php 
        echo attribute_escape($amount);
        ?>
" /></label></p>
        <p>Leave blank to use the default settings.</p>
        <p>To configure the payment form use the <a href="'.get_admin_url().'options-general.php?page=quick-paypal-payments/quick-paypal-payments.php">Settings</a> page</p>
        <?php 
    }