Exemple #1
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_messagetable($id, $email)
{
    $qpp_setup = qpp_get_stored_setup();
    $qpp_ipn = qpp_get_stored_ipn();
    $options = qpp_get_stored_options($id);
    $message = get_option('qpp_messages' . $id);
    $messageoptions = qpp_get_stored_msg();
    $address = qpp_get_stored_address($id);
    $c = qpp_currency($id);
    $showthismany = '9999';
    $content = $padding = $count = $arr = '';
    if ($messageoptions['messageqty'] == 'fifty') {
        $showthismany = '50';
    }
    if ($messageoptions['messageqty'] == 'hundred') {
        $showthismany = '100';
    }
    ${$messageoptions}['messageqty'] = "checked";
    ${$messageoptions}['messageorder'] = "checked";
    if (!is_array($message)) {
        $message = array();
    }
    $title = $id;
    if ($id == '') {
        $title = 'Default';
    }
    if (!$email) {
        $dashboard = '<div class="wrap"><div id="qpp-widget">';
    } else {
        $padding = 'cellpadding="5"';
    }
    $dashboard .= '<table cellspacing="0" ' . $padding . '><tr>';
    if (!$email) {
        $dashboard .= '<th></th>';
    }
    $dashboard .= '<th style="text-align:left">Date Sent</th>';
    foreach (explode(',', $options['sort']) as $name) {
        $title = '';
        switch ($name) {
            case 'field1':
                $dashboard .= '<th style="text-align:left">' . $options['inputreference'] . '</th>';
                break;
            case 'field2':
                $dashboard .= '<th style="text-align:left">' . $options['quantitylabel'] . '</th>';
                break;
            case 'field3':
                $dashboard .= '<th style="text-align:left">' . $options['inputamount'] . '</th>';
                break;
            case 'field4':
                if ($options['use_stock']) {
                    $dashboard .= '<th style="text-align:left">' . $options['stocklabel'] . '</th>';
                }
                break;
            case 'field5':
                if ($options['use_options']) {
                    $dashboard .= '<th style="text-align:left">' . $options['optionlabel'] . '</th>';
                }
                break;
            case 'field6':
                if ($options['usecoupon']) {
                    $dashboard .= '<th style="text-align:left">' . $options['couponblurb'] . '</th>';
                }
                break;
            case 'field16':
                if ($options['useemail']) {
                    $dashboard .= '<th style="text-align:left">' . $options['emailblurb'] . '</th>';
                }
                break;
        }
    }
    if ($messageoptions['showaddress']) {
        $arr = array('email', 'firstname', 'lastname', 'address1', 'address2', 'city', 'state', 'zip', 'country', 'night_phone_b');
        foreach ($arr as $item) {
            $dashboard .= '<th style="text-align:left">' . $address[$item] . '</th>';
        }
    }
    if ($qpp_ipn['ipn']) {
        $dashboard .= '<th>' . $qpp_ipn['title'] . '</th>';
    }
    $dashboard .= '</tr>';
    if ($messageoptions['messageorder'] == 'newest') {
        $i = count($message) - 1;
        foreach (array_reverse($message) as $value) {
            if ($count < $showthismany) {
                if ($value['field0']) {
                    $report = 'messages';
                }
                $content .= qpp_messagecontent($id, $value, $options, $c, $messageoptions, $address, $arr, $i, $email);
                $count = $count + 1;
                $i--;
            }
        }
    } else {
        $i = 0;
        foreach ($message as $value) {
            if ($count < $showthismany) {
                if ($value['field0']) {
                    $report = 'messages';
                }
                $content .= qpp_messagecontent($id, $value, $options, $c, $messageoptions, $address, $arr, $i, $email);
                $count = $count + 1;
                $i++;
            }
        }
    }
    if ($report) {
        $dashboard .= $content . '</table>';
    } else {
        $dashboard .= '</table><p>No messages found</p>';
    }
    return $dashboard;
}