function web_invoice_md5_to_invoice($md5) { global $wpdb, $_web_invoice_md5_to_invoice_cache; if (isset($_web_invoice_md5_to_invoice_cache[$md5]) && $_web_invoice_md5_to_invoice_cache[$md5]) { return $_web_invoice_md5_to_invoice_cache[$md5]; } $md5_escaped = mysql_escape_string($md5); $all_invoices = $wpdb->get_col("SELECT invoice_num FROM " . Web_Invoice::tablename('main') . " WHERE MD5(invoice_num) = '{$md5_escaped}'"); foreach ($all_invoices as $value) { if (md5($value) == $md5) { $_web_invoice_md5_to_invoice_cache[$md5] = $value; return $_web_invoice_md5_to_invoice_cache[$md5]; } } }
function display($what) { global $_web_invoice_clear_cache, $wpdb; if (!$this->_row_cache || $_web_invoice_clear_cache) { $this->_setRowCache($wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('main') . " WHERE invoice_num = '{$this->id}'")); $_web_invoice_clear_cache = false; } $invoice_info = $this->_row_cache; switch ($what) { case 'log_status': if ($status_update = $wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('log') . " WHERE invoice_id = " . $this->id . " ORDER BY `" . Web_Invoice::tablename('log') . "`.`time_stamp` DESC LIMIT 0 , 1")) { return $status_update->value . " - " . web_invoice_Date::convert($status_update->time_stamp, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN)); } break; case 'paid_date': $paid_date = $wpdb->get_var("SELECT time_stamp FROM " . Web_Invoice::tablename('log') . " WHERE action_type = 'paid' AND invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC LIMIT 0, 1"); if ($paid_date) { return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime(web_invoice_Date::convert($paid_date, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN)))); } break; case 'paid_date_raw': $paid_date = $wpdb->get_var("SELECT time_stamp FROM " . Web_Invoice::tablename('log') . " WHERE action_type = 'paid' AND invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC LIMIT 0, 1"); if ($paid_date) { return $paid_date; } break; case 'subscription_name': return web_invoice_meta($this->id, 'web_invoice_subscription_name'); break; case 'interval_length': return web_invoice_meta($this->id, 'web_invoice_subscription_length'); break; case 'interval_unit': return web_invoice_meta($this->id, 'web_invoice_subscription_unit'); break; case 'totalOccurrences': return web_invoice_meta($this->id, 'web_invoice_subscription_total_occurances'); break; case 'installment': return web_invoice_meta($this->id, 'installment', 0); break; case 'startDate': $web_invoice_subscription_start_day = web_invoice_meta($this->id, 'web_invoice_subscription_start_day'); $web_invoice_subscription_start_year = web_invoice_meta($this->id, 'web_invoice_subscription_start_year'); $web_invoice_subscription_start_month = web_invoice_meta($this->id, 'web_invoice_subscription_start_month'); if ($web_invoice_subscription_start_month && $web_invoice_subscription_start_year && $web_invoice_subscription_start_day && strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day) > time()) { return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day)); } else { return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), time() + 1800); } break; case 'endDate': return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * $this->display('totalOccurrences') . " " . $this->display('interval_unit'), strtotime($this->display('startDateM')))); break; case 'nextDate': if ($this->display('totalOccurrences') > $this->display('installment')) { if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) { $start_date = $this->display('due_dateM'); } else { $start_date = $this->display('startDateM'); } return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * $this->display('installment') . " " . $this->display('interval_unit'), strtotime($start_date))); } return $this->display('endDate'); break; case 'startDateM': $web_invoice_subscription_start_day = web_invoice_meta($this->id, 'web_invoice_subscription_start_day'); $web_invoice_subscription_start_year = web_invoice_meta($this->id, 'web_invoice_subscription_start_year'); $web_invoice_subscription_start_month = web_invoice_meta($this->id, 'web_invoice_subscription_start_month'); if ($web_invoice_subscription_start_month && $web_invoice_subscription_start_year && $web_invoice_subscription_start_day && strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day) > time()) { return date('Y-m-d', strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day)); } else { return date('Y-m-d', time() + 1800); } break; case 'endDateM': return date('Y-m-d', strtotime("+" . $this->display('interval_length') * $this->display('totalOccurrences') . " " . $this->display('interval_unit'), strtotime($this->display('startDateM')))); break; case 'nextDateM': if ($this->display('totalOccurrences') > $this->display('installment')) { if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) { $start_date = $this->display('due_dateM'); } else { $start_date = $this->display('startDateM'); } return date('Y-m-d', strtotime("+" . $this->display('interval_length') * $this->display('installment') . " " . $this->display('interval_unit'), strtotime($start_date))); } return $this->display('endDate'); break; case 'profileEndDate': return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * ($this->display('totalOccurrences') - 1) . " " . $this->display('interval_unit'), strtotime($this->display('startDate')) + 3600 * 24)); break; case 'archive_status': $result = $wpdb->get_col("SELECT action_type FROM " . Web_Invoice::tablename('log') . " WHERE invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC"); foreach ($result as $event) { if ($event == 'unarchive') { return ''; break; } if ($event == 'archive') { return 'archive'; break; } } break; case 'display_billing_rate': $length = web_invoice_meta($this->id, 'web_invoice_subscription_length'); $unit = web_invoice_meta($this->id, 'web_invoice_subscription_unit'); $occurances = web_invoice_meta($this->id, 'web_invoice_subscription_total_occurances'); // days if ($unit == "days") { if ($length == '1') { return "daily for {$occurances} days"; } if ($length > '1') { return "every {$length} days for a total of {$occurances} billing cycles"; } } //months if ($unit == "months") { if ($length == '1') { return "monthly for {$occurances} months"; } if ($length > '1') { return "every {$length} months {$occurances} times"; } } if ($unit == "years") { if ($length == '1') { return "annually for {$occurances} years"; } if ($length > '1') { return "every {$length} years {$occurances} times"; } } break; case 'link': $link_to_page = get_permalink(get_option('web_invoice_web_invoice_page')); $hashed = md5($this->id); if (get_option("permalink_structure")) { return $link_to_page . "?invoice_id=" . $hashed; } else { return $link_to_page . "&invoice_id=" . $hashed; } break; case 'invoice_hash': return md5($this->id); break; case 'print_link': return $this->display('link') . '&print=1'; break; case 'hash': return md5($this->id); break; case 'currency': if (web_invoice_meta($this->id, 'web_invoice_currency_code') != '') { $currency_code = web_invoice_meta($this->id, 'web_invoice_currency_code'); } else { if (get_option('web_invoice_default_currency_code') != '') { $currency_code = get_option('web_invoice_default_currency_code'); } else { $currency_code = "USD"; } } return $currency_code; break; case 'display_id': $web_invoice_custom_invoice_id = web_invoice_meta($this->id, 'web_invoice_custom_invoice_id'); if (empty($web_invoice_custom_invoice_id)) { return $this->id; } else { return $web_invoice_custom_invoice_id; } break; case 'due_date': $web_invoice_due_date_month = web_invoice_meta($this->id, 'web_invoice_due_date_month'); $web_invoice_due_date_year = web_invoice_meta($this->id, 'web_invoice_due_date_year'); $web_invoice_due_date_day = web_invoice_meta($this->id, 'web_invoice_due_date_day'); if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day)) { return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("{$web_invoice_due_date_year}-{$web_invoice_due_date_month}-{$web_invoice_due_date_day}")); } return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN))); break; case 'due_dateM': $web_invoice_due_date_month = web_invoice_meta($this->id, 'web_invoice_due_date_month'); $web_invoice_due_date_year = web_invoice_meta($this->id, 'web_invoice_due_date_year'); $web_invoice_due_date_day = web_invoice_meta($this->id, 'web_invoice_due_date_day'); if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day)) { return date('Y-m-d', strtotime("{$web_invoice_due_date_year}-{$web_invoice_due_date_month}-{$web_invoice_due_date_day}")); } return date('Y-m-d'); break; case 'invoice_date': if ($invoice_info && $invoice_info->invoice_date && !empty($invoice_info->invoice_date)) { date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime($invoice_info->invoice_date)); } return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN))); break; case 'amount': return $invoice_info->amount; break; case 'due_amount': $payments = web_invoice_sum_payments($this->id); return max(0, $invoice_info->amount - $payments); break; case 'tax_percent': $_tax_values = unserialize(web_invoice_meta($this->id, 'tax_value')); if (is_array($_tax_values)) { $_tax_value = 0; foreach ($_tax_values as $_tax_valuex) { $_tax_value += $_tax_valuex; } } else { $_tax_value = $_tax_values; } return $_tax_value; break; case 'tax_total': $_tax_values = unserialize(web_invoice_meta($this->id, 'tax_value')); if (is_array($_tax_values)) { $_tax_value = 0; foreach ($_tax_values as $_tax_valuex) { $_tax_value += $_tax_valuex; } } else { $_tax_value = $_tax_values; } return $_tax_value * $invoice_info->amount; break; case 'subject': return $invoice_info->subject; break; case 'display_amount': return web_invoice_display_payment($this->display('currency'), $invoice_info->amount); break; case 'description': return str_replace("\n", "<br />", $invoice_info->description); break; case 'itemized': return unserialize(urldecode($invoice_info->itemized)); break; case 'status': return $invoice_info->status; break; case 'trx_id': return web_invoice_payment_register($this->id, $this->display('amount')); break; } }
function web_invoice_draw_user_selection_form($user_id) { global $wpdb, $blog_id; $_SESSION['last_new_invoice'] = true; ?> <div class="postbox" id="wp_new_web_invoice_div"> <div class="inside"> <form action="admin.php?page=new_web_invoice" method='POST'> <table class="form-table" id="get_user_info"> <tr class=""> <th><?php if (isset($user_id)) { _e("Start New Invoice For: ", WEB_INVOICE_TRANS_DOMAIN); } else { _e("Create New Invoice For: ", WEB_INVOICE_TRANS_DOMAIN); } ?> </th> <td><select name='user_id' class='user_selection'> <option></option> <?php if (is_dir(WP_CONTENT_DIR . '/mu-plugins') || MULTISITE) { $prefix = $wpdb->base_prefix; if ($prefix == "") { $prefix = $wpdb->prefix; } $get_all_users = $wpdb->get_results("SELECT * FROM {$prefix}users LEFT JOIN {$prefix}usermeta on {$prefix}users.id={$prefix}usermeta.user_id WHERE ({$prefix}usermeta.meta_key='primary_blog' and {$prefix}usermeta.meta_value = {$blog_id}) OR ({$prefix}usermeta.meta_key='{$wpdb->prefix}capabilities') ORDER BY {$prefix}users.user_nicename"); } else { $prefix = $wpdb->prefix; $get_all_users = $wpdb->get_results("SELECT ID FROM {$prefix}users ORDER BY {$prefix}users.user_nicename"); } $_used_ids = array(); foreach ($get_all_users as $user) { if (isset($_used_ids[$user->ID])) { continue; } $profileuser = get_user_to_edit($user->ID); echo "<option "; if (isset($user_id) && $user_id == $user->ID) { echo " SELECTED "; } if (!empty($profileuser->last_name) && !empty($profileuser->first_name)) { echo " value=\"" . $user->ID . "\">" . $profileuser->last_name . ", " . $profileuser->first_name . " (" . $profileuser->user_email . ")</option>\n"; } else { echo " value=\"" . $user->ID . "\">" . $profileuser->user_login . " (" . $profileuser->user_email . ")</option>\n"; } $_used_ids[$user->ID] = true; } ?> </select> <input type='submit' class='button' id="web_invoice_create_new_web_invoice" value='<?php _e("Create New Invoice", WEB_INVOICE_TRANS_DOMAIN); ?> ' /> <?php if (web_invoice_number_of_invoices() > 0) { ?> <span id="web_invoice_copy_invoice" class="web_invoice_click_me"><?php _e("copy from another", WEB_INVOICE_TRANS_DOMAIN); ?> </span> <br /> <div class="web_invoice_copy_invoice"><?php $all_invoices = $wpdb->get_results("SELECT * FROM " . Web_Invoice::tablename('main')); ?> <select name="copy_from_template"> <option SELECTED value=""></option> <?php foreach ($all_invoices as $invoice) { $profileuser = get_user_to_edit($invoice->user_id); ?> <option value="<?php echo $invoice->invoice_num; ?> "><?php if (web_invoice_recurring($invoice->invoice_num)) { _e("(recurring)", WEB_INVOICE_TRANS_DOMAIN); } ?> <?php echo $invoice->subject . " - \$" . $invoice->amount; ?> </option> <?php } ?> </select><input type='submit' class='button' value='<?php _e("New Invoice from Template", WEB_INVOICE_TRANS_DOMAIN); ?> ' /> <span id="web_invoice_copy_invoice_cancel" class="web_invoice_click_me"><?php _e("cancel", WEB_INVOICE_TRANS_DOMAIN); ?> </span> </div> <?php } if (!isset($user_id)) { _e("User must have a profile to receive invoices.", WEB_INVOICE_TRANS_DOMAIN); if (current_user_can('create_users')) { if ($GLOBALS['wp_version'] < '2.7') { echo "<a href=\"users.php\">" . __("Create a new user account.", WEB_INVOICE_TRANS_DOMAIN) . "</a>"; } else { echo "<a href=\"user-new.php\">" . __("Create a new user account.", WEB_INVOICE_TRANS_DOMAIN) . "</a>"; } } } ?> </td> </tr> </table> </form> </div> </div> <?php }
function web_invoice_frontend_css() { if (get_option('web_invoice_web_invoice_page') != '' && is_page(get_option('web_invoice_web_invoice_page'))) { echo '<meta name="robots" content="noindex, nofollow" />'; if (get_option('web_invoice_use_css') == 'yes') { echo '<link type="text/css" media="print" rel="stylesheet" href="' . Web_Invoice::frontend_path() . '/css/web_invoice-print.css?2.0.8"></link>' . "\n"; echo '<link type="text/css" media="screen" rel="stylesheet" href="' . Web_Invoice::frontend_path() . '/css/web_invoice-screen.css?2.0.8"></link>' . "\n"; } } }