Example #1
0
function web_invoice_process_invoice_update($invoice_id, $unprivileged = false)
{
    global $wpdb;
    if ($unprivileged) {
        $profileuser = get_currentuserinfo();
    } else {
        $profileuser = get_userdata($_POST['user_id']);
    }
    $description = $_REQUEST['description'];
    $subject = $_REQUEST['subject'];
    $amount = $_REQUEST['amount'];
    $user_id = $_REQUEST['user_id'];
    $web_invoice_tax = serialize($_REQUEST['web_invoice_tax']);
    $itemized_list = $_REQUEST['itemized_list'];
    $web_invoice_custom_invoice_id = $_REQUEST['web_invoice_custom_invoice_id'];
    $web_invoice_date = "{$_REQUEST['web_invoice_date_year']}-{$_REQUEST['web_invoice_date_month']}-{$_REQUEST['web_invoice_date_day']}";
    $web_invoice_due_date_month = $_REQUEST['web_invoice_due_date_month'];
    $web_invoice_due_date_day = $_REQUEST['web_invoice_due_date_day'];
    $web_invoice_due_date_year = $_REQUEST['web_invoice_due_date_year'];
    $web_invoice_first_name = $_REQUEST['web_invoice_first_name'];
    $web_invoice_last_name = $_REQUEST['web_invoice_last_name'];
    $web_invoice_tax_id = $_REQUEST['web_invoice_tax_id'];
    $web_invoice_company_name = $_REQUEST['web_invoice_company_name'];
    $web_invoice_streetaddress = $_REQUEST['web_invoice_streetaddress'];
    $web_invoice_city = $_REQUEST['web_invoice_city'];
    $web_invoice_state = $_REQUEST['web_invoice_state'];
    $web_invoice_zip = $_REQUEST['web_invoice_zip'];
    $web_invoice_country = $_REQUEST['web_invoice_country'];
    $web_invoice_currency_code = $_REQUEST['web_invoice_currency_code'];
    $web_invoice_subscription_name = $_REQUEST['web_invoice_subscription_name'];
    $web_invoice_subscription_unit = $_REQUEST['web_invoice_subscription_unit'];
    $web_invoice_subscription_length = $_REQUEST['web_invoice_subscription_length'];
    $web_invoice_subscription_start_month = $_REQUEST['web_invoice_subscription_start_month'];
    $web_invoice_subscription_start_day = $_REQUEST['web_invoice_subscription_start_day'];
    $web_invoice_subscription_start_year = $_REQUEST['web_invoice_subscription_start_year'];
    $web_invoice_subscription_total_occurances = $_REQUEST['web_invoice_subscription_total_occurances'];
    $web_invoice_payment_methods = join(',', $_REQUEST['web_invoice_payment_methods']);
    $web_invoice_tax_names = unserialize(get_option('web_invoice_tax_name'));
    if (!is_array($web_invoice_tax_names)) {
        $web_invoice_tax_names = array();
    }
    for ($_txc = 0; $_txc < get_option('web_invoice_tax_count'); $_txc++) {
        if (!isset($_REQUEST['web_invoice_tax_name_' . $_txc])) {
            continue;
        }
        $web_invoice_tax_names[$_txc] = $_REQUEST['web_invoice_tax_name_' . $_txc];
    }
    //remove items from itemized list that are missing a title, they are most likely deleted
    if (is_array($itemized_list)) {
        $counter = 1;
        foreach ($itemized_list as $itemized_item) {
            if (empty($itemized_item[name])) {
                unset($itemized_list[$counter]);
            }
            $counter++;
        }
        array_values($itemized_list);
    }
    $itemized = urlencode(serialize($itemized_list));
    // Check if this is new invoice creation, or an update
    if (web_invoice_does_invoice_exist($invoice_id)) {
        // Updating Old Invoice
        if (web_invoice_get_invoice_attrib($invoice_id, 'subject') != $subject) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET subject = '{$subject}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Subject Updated ');
            $message .= "Subject updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'description') != $description) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET description = '{$description}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Description Updated ');
            $message .= "Description updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'amount') != $amount) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET amount = '{$amount}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Amount Updated ');
            $message .= "Amount updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'invoice_date') != $web_invoice_date) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET invoice_date = '{$web_invoice_date}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Invoice Date Updated ');
            $message .= "Invoice date updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'itemized') != $itemized) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET itemized = '{$itemized}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Itemized List Updated ');
            $message .= "Itemized List updated. ";
            web_invoice_clear_cache();
        }
    } else {
        // Create New Invoice
        if ($wpdb->query("INSERT INTO " . Web_Invoice::tablename('main') . " (amount,invoice_date,description,invoice_num,user_id,subject,itemized,status)\tVALUES ('{$amount}','{$web_invoice_date}','{$description}','{$invoice_id}','{$user_id}','{$subject}','{$itemized}','0')")) {
            $message = "New Invoice saved.";
            web_invoice_update_log($invoice_id, 'created', ' Created ');
        } else {
            $error = true;
            $message = "There was a problem saving invoice. Try deactivating and reactivating plugin. REF: " . mysql_errno();
        }
    }
    // See if invoice is recurring
    if (!empty($web_invoice_subscription_name) && !empty($web_invoice_subscription_unit) && !empty($web_invoice_subscription_total_occurances)) {
        $web_invoice_recurring_status = true;
        web_invoice_update_invoice_meta($invoice_id, "web_invoice_recurring_billing", true);
        $message .= " Recurring invoice saved.  This invoice may be viewed under \"Recurring Billing\". ";
    }
    // See if invoice is recurring
    if (empty($web_invoice_subscription_name) && empty($web_invoice_subscription_unit) && empty($web_invoice_subscription_total_occurances)) {
        $web_invoice_recurring_status = false;
        web_invoice_update_invoice_meta($invoice_id, "web_invoice_recurring_billing", false);
    }
    // Update Invoice Meta
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_custom_invoice_id", $web_invoice_custom_invoice_id);
    web_invoice_update_invoice_meta($invoice_id, "tax_value", $web_invoice_tax);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_currency_code", $web_invoice_currency_code);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_day", $web_invoice_due_date_day);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_month", $web_invoice_due_date_month);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_year", $web_invoice_due_date_year);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_payment_methods", $web_invoice_payment_methods);
    // Update Invoice Recurring Meta
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_name", $web_invoice_subscription_name);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_unit", $web_invoice_subscription_unit);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_length", $web_invoice_subscription_length);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_month", $web_invoice_subscription_start_month);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_day", $web_invoice_subscription_start_day);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_year", $web_invoice_subscription_start_year);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_total_occurances", $web_invoice_subscription_total_occurances);
    //Update User Information
    if (!empty($web_invoice_first_name)) {
        update_usermeta($user_id, 'first_name', $web_invoice_first_name);
    }
    if (!empty($web_invoice_last_name)) {
        update_usermeta($user_id, 'last_name', $web_invoice_last_name);
    }
    if (!empty($web_invoice_company_name)) {
        update_usermeta($user_id, 'company_name', $web_invoice_company_name);
    }
    if (!empty($web_invoice_tax_id)) {
        update_usermeta($user_id, 'tax_id', $web_invoice_tax_id);
    }
    if (!empty($web_invoice_streetaddress)) {
        update_usermeta($user_id, 'streetaddress', $web_invoice_streetaddress);
    }
    if (!empty($web_invoice_city)) {
        update_usermeta($user_id, 'city', $web_invoice_city);
    }
    if (!empty($web_invoice_state)) {
        update_usermeta($user_id, 'state', $web_invoice_state);
    }
    if (!empty($web_invoice_zip)) {
        update_usermeta($user_id, 'zip', $web_invoice_zip);
    }
    if (!empty($web_invoice_country)) {
        update_usermeta($user_id, 'country', $web_invoice_country);
    }
    if (is_array($web_invoice_tax_names)) {
        update_option('web_invoice_tax_name', serialize($web_invoice_tax_names));
    }
    //If there is a message, append it with the web invoice link
    if ($message && $invoice_id) {
        $invoice_info = new Web_Invoice_GetInfo($invoice_id);
        $message .= " <a href='" . $invoice_info->display('link') . "'>View Web Invoice</a>.";
    }
    if (!$error) {
        return $message;
    }
    if ($error) {
        return "An error occured: {$message}.";
    }
}
Example #2
0
 function init()
 {
     global $wpdb, $wp_version;
     if (version_compare($wp_version, '2.6', '<')) {
         // Using old WordPress
         load_plugin_textdomain(WEB_INVOICE_TRANS_DOMAIN, PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/languages');
     } else {
         load_plugin_textdomain(WEB_INVOICE_TRANS_DOMAIN, PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/languages', dirname(plugin_basename(__FILE__)) . '/languages');
     }
     if (is_admin()) {
         if (is_multisite() && !get_option('web_invoice_installed', false)) {
             $this->install();
         }
         if (get_option('web_invoice_installed', false) != WEB_INVOICE_VERSION_NUM) {
             $version = get_option('web_invoice_installed', false);
             if ($version == true) {
                 $version = '2.1.0';
             }
             $this->upgrade($version);
         }
         wp_enqueue_script('jquery');
         wp_enqueue_script('jquery-ui-core');
         wp_enqueue_script('jquery-ui-tabs');
         wp_enqueue_script('jquery-maskedinput', $this->uri . "/js/jquery.maskedinput.js", array('jquery'));
         wp_enqueue_script('jquery-cookie', $this->uri . "/js/jquery.cookie.js", array('jquery'));
         wp_enqueue_script('jquery-form', $this->uri . "/js/jquery.form.js", array('jquery'));
         wp_enqueue_script('jquery-impromptu', $this->uri . "/js/jquery-impromptu.1.7.js", array('jquery'), '1.8.0');
         wp_enqueue_script('jquery-field', $this->uri . "/js/jquery.field.min.js", array('jquery'), '1.8.0');
         wp_enqueue_script('jquery-delegate', $this->uri . "/js/jquery.delegate.js", array('jquery'), '1.8.0');
         wp_enqueue_script('jquery-calculation', $this->uri . "/js/jquery.calculation.min.js", array('jquery'), '1.8.0');
         wp_enqueue_script('jquery-tablesorter', $this->uri . "/js/jquery.tablesorter.min.js", array('jquery'), '1.8.0');
         wp_enqueue_script('jquery-autogrow-textarea', $this->uri . "/js/jquery.autogrow-textarea.js", array('jquery'), '1.8.0');
         wp_enqueue_script('web-invoice', $this->uri . "/js/web-invoice.js", array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'), WEB_INVOICE_VERSION_NUM, true);
     } else {
         if (isset($_POST['web_invoice_id_hash'])) {
             $md5_invoice_id = $_POST['web_invoice_id_hash'];
             $invoice_id = web_invoice_md5_to_invoice($md5_invoice_id);
             //Check to see if this is a credit card transaction, if so process
             if (web_invoice_does_invoice_exist($invoice_id)) {
                 web_invoice_process_cc_transaction($_POST);
                 exit(0);
             }
         }
         if (isset($_GET['invoice_id'])) {
             $md5_invoice_id = $_GET['invoice_id'];
             // Convert MD5 hash into Actual Invoice ID
             $invoice_id = web_invoice_md5_to_invoice($md5_invoice_id);
             //Check if invoice exists, SSL enforcement is setup, and we are not currently browing HTTPS,  then reload page into HTTPS
             if (!function_exists('wp_https_redirect')) {
                 if (web_invoice_does_invoice_exist($invoice_id) && get_option('web_invoice_force_https') == 'true' && $_SERVER['HTTPS'] != "on" && preg_match('/^https/', get_option('siteurl')) == 0) {
                     $host_x = preg_split('/\\//', get_option('siteurl'));
                     $host = $host_x[2];
                     header("Location: https://" . $host . $_SERVER['REQUEST_URI']);
                     exit(0);
                 }
             }
         }
     }
     if (empty($_GET['invoice_id'])) {
         unset($_GET['invoice_id']);
     }
 }