PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/web-invoice.php

http://web-invoice.googlecode.com/
PHP | 1336 lines | 1089 code | 182 blank | 65 comment | 216 complexity | 549454dca8e94c4b4a9ac61de3f18642 MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: Web Invoice
  4. Plugin URI: http://mohanjith.com/wordpress/web-invoice.html
  5. Description: Send itemized web invoices directly to your clients. Credit card payments may be accepted via Authorize.net, MerchantPlus NaviGate, Moneybookers, AlertPay, Google Checkout or PayPal account. Recurring billing is also available via Authorize.net's ARB, Moneybookers, Google Checkout and PayPal. Visit <a href="admin.php?page=web_invoice_settings">Web Invoice Settings Page</a> to setup.
  6. Author: S H Mohanjith (Zinglix)
  7. Version: 2.1.0
  8. Author URI: http://mohanjith.com/
  9. Text Domain: web-invoice
  10. Stable tag: 2.1.0
  11. License: GPL
  12. Copyright 2011 S H Mohanjith (email : moha@mohanjith.net)
  13. */
  14. /*
  15. Created by TwinCitiesTech.com
  16. (website: twincitiestech.com email : support@twincitiestech.com)
  17. Modified by S H Mohanjith
  18. (website: mohanjith.com email : support@mohanjith.com)
  19. This program is free software; you can redistribute it and/or modify
  20. it under the terms of the GNU General Public License as published by
  21. the Free Software Foundation; version 3 of the License, with the
  22. exception of the JQuery JavaScript framework which is released
  23. under it's own license. You may view the details of that license in
  24. the prototype.js file.
  25. This program is distributed in the hope that it will be useful,
  26. but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. GNU General Public License for more details.
  29. You should have received a copy of the GNU General Public License
  30. along with this program; if not, write to the Free Software
  31. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. */
  33. define("WEB_INVOICE_VERSION_NUM", "2.1.0");
  34. define("WEB_INVOICE_PHP_VERSION", "5.2");
  35. define("WEB_INVOICE_TRANS_DOMAIN", "web-invoice");
  36. require_once "Flow.php";
  37. require_once "Functions.php";
  38. require_once "Display.php";
  39. require_once "Frontend.php";
  40. global $web_invoice, $web_invoice_print, $web_invoice_memory_head_room;
  41. global $_web_invoice_getinfo, $_web_invoice_payment_cache, $_web_invoice_payment_meta_cache, $_web_invoice_clear_cache;
  42. $web_invoice_memory_head_room = web_invoice_return_bytes(ini_get('memory_limit'))-memory_get_usage();
  43. $web_invoice_print = false;
  44. $php_version_check = version_compare(WEB_INVOICE_PHP_VERSION, PHP_VERSION, '<');
  45. if ($_GET['action'] == 'error_scrape') {
  46. die(sprintf(__("Web Invoice requires PHP ".WEB_INVOICE_PHP_VERSION." or better. Please upgrade or switch to a host that supports PHP ".WEB_INVOICE_PHP_VERSION." like %s.", WEB_INVOICE_TRANS_DOMAIN), '<a href="http://bit.ly/atOh9t" target="_blank">Pacific Host</a>'));
  47. }
  48. if ( $php_version_check )
  49. {
  50. class Web_Invoice
  51. {
  52. var $Invoice;
  53. var $web_invoice_user_level = array('administrator');
  54. var $uri;
  55. var $the_path;
  56. var $message;
  57. static function tablename ($table)
  58. {
  59. global $table_prefix;
  60. return $table_prefix.'web_invoice_'.$table;
  61. }
  62. function the_path()
  63. {
  64. $path = WP_PLUGIN_URL."/".basename(dirname(__FILE__));
  65. return $path;
  66. }
  67. function frontend_path()
  68. {
  69. $path = WP_PLUGIN_URL."/".basename(dirname(__FILE__));
  70. if(get_option('web_invoice_force_https') == 'true')
  71. $path = str_replace('http://','https://',$path);
  72. return $path;
  73. }
  74. function Web_Invoice()
  75. {
  76. $version = get_option('web_invoice_version');
  77. $_file = "web-invoice/" . basename(__FILE__);
  78. $this->path = dirname(__FILE__);
  79. $this->file = basename(__FILE__);
  80. $this->directory = basename($this->path);
  81. $this->uri = WP_PLUGIN_URL."/".$this->directory;
  82. $this->the_path = $this->the_path();
  83. register_activation_hook($_file, array(&$this, 'install'));
  84. register_deactivation_hook($_file, array(&$this, 'uninstall'));
  85. add_action('init', array($this, 'init'), 0);
  86. add_action('profile_update','web_invoice_profile_update');
  87. add_action('edit_user_profile', 'web_invoice_user_profile_fields');
  88. add_action('show_user_profile', 'web_invoice_user_profile_fields');
  89. add_action('wp', array($this, 'api'));
  90. add_action('admin_head', array($this, 'admin_head'));
  91. add_action('contextual_help', 'web_invoice_contextual_help_list', 10, 3);
  92. add_action('wp_head', 'web_invoice_frontend_css');
  93. add_action('admin_menu', array($this, 'web_invoice_add_pages'));
  94. add_filter('favorite_actions', array(&$this, 'favorites'));
  95. if (strcasecmp(get_option('web_invoice_payment_method'), 'cc') || strcasecmp(get_option('web_invoice_payment_method'), 'pfp')) {
  96. add_action('wp_head', 'web_invoice_frontend_js');
  97. }
  98. add_filter('the_content', 'web_invoice_the_content');
  99. add_filter('web_invoice_email_variables', 'web_invoice_email_variables');
  100. add_filter('web_invoice_pdf_variables', 'web_invoice_pdf_variables');
  101. add_filter('web_invoice_html_variables', 'web_invoice_html_variables');
  102. add_filter('web_invoice_web_variables', 'web_invoice_web_variables');
  103. add_filter('wp_redirect', array($this, 'redirect'));
  104. $this->SetUserAccess(get_option('web_invoice_user_level'));
  105. }
  106. function SetUserAccess($level = 8)
  107. {
  108. if (is_array($level) && count($level) > 0) {
  109. $this->web_invoice_user_level = 'manage_web_invoice';
  110. } else {
  111. $this->web_invoice_user_level = $level;
  112. }
  113. }
  114. function redirect($location)
  115. {
  116. if (get_option('web_invoice_redirect_after_user_add') == 'yes' && preg_match('/^users\.php\?usersearch/', $location) > 0) {
  117. return 'admin.php?page=new_web_invoice';
  118. }
  119. return $location;
  120. }
  121. function admin_head()
  122. {
  123. echo "<link rel='stylesheet' href='".$this->uri."/css/wp_admin.css?v=".WEB_INVOICE_VERSION_NUM."' type='text/css'type='text/css' media='all' />";
  124. }
  125. function web_invoice_add_pages()
  126. {
  127. $file = "web-invoice/" . basename(__FILE__);
  128. add_menu_page(__('Web Invoice System', WEB_INVOICE_TRANS_DOMAIN), __('Web Invoice', WEB_INVOICE_TRANS_DOMAIN), $this->web_invoice_user_level, $file, array(&$this,'invoice_overview'),$this->uri."/images/web_invoice.png");
  129. add_submenu_page($file, __("Recurring Billing", WEB_INVOICE_TRANS_DOMAIN), __("Recurring Billing", WEB_INVOICE_TRANS_DOMAIN), $this->web_invoice_user_level, 'web_invoice_recurring_billing', array(&$this,'recurring'));
  130. add_submenu_page($file, __("Manage Invoice", WEB_INVOICE_TRANS_DOMAIN), __("New Invoice", WEB_INVOICE_TRANS_DOMAIN), $this->web_invoice_user_level, 'new_web_invoice', array(&$this,'new_web_invoice'));
  131. add_submenu_page($file, __("Templates", WEB_INVOICE_TRANS_DOMAIN), __("Templates", WEB_INVOICE_TRANS_DOMAIN), $this->web_invoice_user_level, 'web_invoice_templates', array(&$this,'template_page'));
  132. // add_submenu_page($file, __("Items/Inventory"), __("Items"), $this->web_invoice_user_level, 'web_invoice_inventory_items', array(&$this,'inventory_items_page'));
  133. add_submenu_page($file, __("Settings", WEB_INVOICE_TRANS_DOMAIN), __("Settings", WEB_INVOICE_TRANS_DOMAIN), $this->web_invoice_user_level, 'web_invoice_settings', array(&$this,'settings_page'));
  134. add_submenu_page('profile.php', __("Your invoices", WEB_INVOICE_TRANS_DOMAIN), __("Invoices", WEB_INVOICE_TRANS_DOMAIN), 'subscriber', 'user_invoice_overview', array(&$this,'user_invoice_overview'));
  135. }
  136. function security()
  137. {
  138. //More to come later
  139. if(($_REQUEST['eqdkp_data'])) {
  140. setcookie('eqdkp_data');
  141. };
  142. }
  143. function new_web_invoice()
  144. {
  145. $Web_Invoice_Decider = new Web_Invoice_Decider('doInvoice');
  146. if($this->message) {
  147. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  148. }
  149. echo $Web_Invoice_Decider->display();
  150. }
  151. function favorites($actions)
  152. {
  153. $key = 'admin.php?page=new_web_invoice';
  154. $actions[$key] = array(__('New Invoice', WEB_INVOICE_TRANS_DOMAIN),$this->web_invoice_user_level);
  155. return $actions;
  156. }
  157. function recurring()
  158. {
  159. $Web_Invoice_Decider = new Web_Invoice_Decider('web_invoice_recurring_billing');
  160. if($this->message) {
  161. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  162. }
  163. echo $Web_Invoice_Decider->display();
  164. }
  165. function api()
  166. {
  167. if(get_option('web_invoice_web_invoice_page') != '' && is_page(get_option('web_invoice_web_invoice_page')))
  168. {
  169. if((get_option('web_invoice_moneybookers_merchant') == 'True') && isset($_POST['mb_transaction_id']) && isset($_POST['status'])) {
  170. require_once("gateways/moneybookers.class.php");
  171. $moneybookers_obj = new Web_Invoice_Moneybookers($_POST['transaction_id']);
  172. $moneybookers_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
  173. } else if((get_option('web_invoice_alertpay_merchant') == 'True') && isset($_POST['ap_itemname']) && isset($_POST['ap_securitycode'])) {
  174. require_once("gateways/alertpay.class.php");
  175. $alertpay_obj = new Web_Invoice_AlertPay($_POST['ap_itemname']);
  176. $alertpay_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
  177. } else if((get_option('web_invoice_google_checkout_level2') == 'True') && isset($_POST['_type'])) {
  178. require_once("gateways/googlecheckout.class.php");
  179. $gc_obj = new Web_Invoice_GoogleCheckout($_POST['_type'], $_POST);
  180. $gc_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
  181. } else if((get_option('web_invoice_payflow_silent_post') == 'True') && isset($_POST['PNREF'])) {
  182. require_once("gateways/payflow.class.php");
  183. $pf_obj = new Web_Invoice_Payflow($_POST['CUSTID'], $_POST);
  184. $pf_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
  185. } else if (isset($_GET['crypt'])) {
  186. require_once("gateways/sagepay.class.php");
  187. $pf_obj = new Web_Invoice_SagePay($_GET['crypt']);
  188. $pf_obj->processRequest($_SERVER['REMOTE_ADDR']);
  189. } else if (isset($_GET['paypal_ipn'])) {
  190. require_once("gateways/paypal.class.php");
  191. $pf_obj = new Web_Invoice_Paypal($_POST['invoice']);
  192. $pf_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
  193. } else if (isset($_REQUEST['order_number'])) {
  194. require_once("gateways/2co.class.php");
  195. $tco_obj = new Web_Invoice_2CO($_GET['cart_order_id']);
  196. $tco_obj->processRequest($_SERVER['REMOTE_ADDR'], $_REQUEST);
  197. }
  198. wp_enqueue_script('jquery');
  199. wp_enqueue_script('web-invoice',$this->uri."/js/web-invoice-frontend.js", array('jquery'), WEB_INVOICE_VERSION_NUM);
  200. // Make sure proper MD5 is being passed (32 chars), and strip of everything but numbers and letters
  201. if(isset($_GET['invoice_id']) && strlen($_GET['invoice_id']) != 32)
  202. {
  203. unset($_GET['invoice_id']);
  204. }
  205. $_GET['invoice_id'] = preg_replace('/[^A-Za-z0-9-]/', '', $_GET['invoice_id']);
  206. // Make sure proper MD5 is being passed (32 chars), and strip of everything but numbers and letters
  207. if (isset($_GET['generate_from']) && strlen($_GET['generate_from']) != 32)
  208. {
  209. unset($_GET['generate_from']);
  210. }
  211. $_GET['generate_from'] = preg_replace('/[^A-Za-z0-9-]/', '', $_GET['generate_from']);
  212. if (isset($_GET['generate_from']) && !empty($_GET['generate_from']) && (get_option('web_invoice_self_generate_from_template') == "yes"))
  213. {
  214. global $current_user;
  215. get_currentuserinfo();
  216. if ($current_user->ID > 0)
  217. {
  218. // Convert MD5 hash into Actual Invoice ID
  219. $template_id = web_invoice_md5_to_invoice($_GET['generate_from']);
  220. $invoice_id = web_invoice_self_generate_from_template($template_id, $current_user->ID);
  221. $web_invoice_getinfo = new Web_Invoice_GetInfo($invoice_id);
  222. wp_redirect($web_invoice_getinfo->display('link'));
  223. exit(0);
  224. }
  225. }
  226. if (isset($_GET['print']))
  227. {
  228. web_invoice_print_pdf();
  229. }
  230. }
  231. }
  232. function invoice_overview()
  233. {
  234. $web_invoice_web_invoice_page = get_option("web_invoice_web_invoice_page");
  235. $Web_Invoice_Decider = new Web_Invoice_Decider('overview');
  236. if($this->message)
  237. {
  238. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  239. }
  240. if(!function_exists('curl_exec'))
  241. {
  242. echo "<div id=\"message\" class='error' ><p>".__('cURL is not turned on on your server, credit card processing will not work. If you have access to your php.ini file, activate <b>extension=php_curl.dll</b>.', WEB_INVOICE_TRANS_DOMAIN)."</p></div>";
  243. }
  244. echo $Web_Invoice_Decider->display();
  245. }
  246. function user_invoice_overview()
  247. {
  248. $web_invoice_web_invoice_page = get_option("web_invoice_web_invoice_page");
  249. $Web_Invoice_Decider = new Web_Invoice_Decider('user_overview');
  250. if($this->message)
  251. {
  252. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  253. }
  254. echo $Web_Invoice_Decider->display();
  255. }
  256. function settings_page()
  257. {
  258. $Web_Invoice_Decider = new Web_Invoice_Decider('web_invoice_settings');
  259. if($this->message)
  260. {
  261. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  262. }
  263. echo $Web_Invoice_Decider->display();
  264. }
  265. function template_page()
  266. {
  267. $Web_Invoice_Decider = new Web_Invoice_Decider('web_invoice_email_templates');
  268. if($this->message)
  269. {
  270. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  271. }
  272. echo $Web_Invoice_Decider->display();
  273. }
  274. function inventory_items_page()
  275. {
  276. $Web_Invoice_Decider = new Web_Invoice_Decider('web_invoice_inventory_items');
  277. if($this->message)
  278. {
  279. echo "<div id=\"message\" class='error' ><p>".$this->message."</p></div>";
  280. }
  281. echo $Web_Invoice_Decider->display();
  282. }
  283. function init()
  284. {
  285. global $wpdb, $wp_version;
  286. if (version_compare($wp_version, '2.6', '<'))
  287. {
  288. // Using old WordPress
  289. load_plugin_textdomain(WEB_INVOICE_TRANS_DOMAIN, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/languages');
  290. } else {
  291. load_plugin_textdomain(WEB_INVOICE_TRANS_DOMAIN, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/languages', dirname(plugin_basename(__FILE__)).'/languages');
  292. }
  293. if (is_admin())
  294. {
  295. if (is_multisite() && !get_option('web_invoice_installed', false)) {
  296. $this->install();
  297. }
  298. wp_enqueue_script('jquery');
  299. wp_enqueue_script('jquery-ui-core');
  300. wp_enqueue_script('jquery-ui-tabs');
  301. wp_enqueue_script('jquery-maskedinput',$this->uri."/js/jquery.maskedinput.js", array('jquery'));
  302. wp_enqueue_script('jquery-cookie',$this->uri."/js/jquery.cookie.js", array('jquery'));
  303. wp_enqueue_script('jquery-form',$this->uri."/js/jquery.form.js", array('jquery') );
  304. wp_enqueue_script('jquery-impromptu',$this->uri."/js/jquery-impromptu.1.7.js", array('jquery'), '1.8.0');
  305. wp_enqueue_script('jquery-field',$this->uri."/js/jquery.field.min.js", array('jquery'), '1.8.0');
  306. wp_enqueue_script('jquery-delegate',$this->uri."/js/jquery.delegate.js", array('jquery'), '1.8.0');
  307. wp_enqueue_script('jquery-calculation',$this->uri."/js/jquery.calculation.min.js", array('jquery'), '1.8.0');
  308. wp_enqueue_script('jquery-tablesorter',$this->uri."/js/jquery.tablesorter.min.js", array('jquery'), '1.8.0');
  309. wp_enqueue_script('jquery-autogrow-textarea',$this->uri."/js/jquery.autogrow-textarea.js", array('jquery'), '1.8.0');
  310. wp_enqueue_script('web-invoice',$this->uri."/js/web-invoice.js", array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'), WEB_INVOICE_VERSION_NUM, true);
  311. } else {
  312. if(isset($_POST['web_invoice_id_hash']))
  313. {
  314. $md5_invoice_id = $_POST['web_invoice_id_hash'];
  315. $invoice_id = web_invoice_md5_to_invoice($md5_invoice_id);
  316. //Check to see if this is a credit card transaction, if so process
  317. if(web_invoice_does_invoice_exist($invoice_id))
  318. {
  319. web_invoice_process_cc_transaction($_POST);
  320. exit(0);
  321. }
  322. }
  323. if (isset($_GET['invoice_id']))
  324. {
  325. $md5_invoice_id = $_GET['invoice_id'];
  326. // Convert MD5 hash into Actual Invoice ID
  327. $invoice_id = web_invoice_md5_to_invoice($md5_invoice_id);
  328. //Check if invoice exists, SSL enforcement is setup, and we are not currently browing HTTPS, then reload page into HTTPS
  329. if (!function_exists('wp_https_redirect'))
  330. {
  331. if (web_invoice_does_invoice_exist($invoice_id) &&
  332. get_option('web_invoice_force_https') == 'true' &&
  333. $_SERVER['HTTPS'] != "on" &&
  334. preg_match('/^https/', get_option('siteurl')) == 0)
  335. {
  336. $host_x = preg_split('/\//', get_option('siteurl'));
  337. $host = $host_x[2];
  338. header("Location: https://". $host . $_SERVER['REQUEST_URI']);
  339. exit(0);
  340. }
  341. }
  342. }
  343. }
  344. if (empty($_GET['invoice_id']))
  345. {
  346. unset($_GET['invoice_id']);
  347. }
  348. }
  349. function uninstall()
  350. {
  351. global $wpdb;
  352. // Nothing to do
  353. }
  354. function install()
  355. {
  356. global $wpdb;
  357. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  358. if (!empty($wpdb->charset))
  359. {
  360. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  361. }
  362. if (!empty($wpdb->collate))
  363. {
  364. $charset_collate .= " COLLATE $wpdb->collate";
  365. }
  366. //change old table name to new one
  367. if($wpdb->get_var("SHOW TABLES LIKE 'web_invoice'"))
  368. {
  369. global $table_prefix;
  370. $sql_update = "RENAME TABLE ".$table_prefix."invoice TO ". Web_Invoice::tablename('main')."";
  371. $wpdb->query($sql_update);
  372. }
  373. if($wpdb->get_var("SHOW TABLES LIKE '". Web_Invoice::tablename('main') ."'") != Web_Invoice::tablename('main'))
  374. {
  375. $sql_main = "CREATE TABLE IF NOT EXISTS ". Web_Invoice::tablename('main') ." (
  376. id int(11) NOT NULL auto_increment,
  377. invoice_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  378. amount double default '0',
  379. description text NOT NULL,
  380. invoice_num varchar(45) NOT NULL default '',
  381. user_id varchar(20) NOT NULL default '',
  382. subject text NOT NULL,
  383. itemized text NOT NULL,
  384. status int(11) NOT NULL,
  385. PRIMARY KEY (id),
  386. UNIQUE KEY invoice_num (invoice_num)
  387. ) {$charset_collate};";
  388. dbDelta($sql_main);
  389. } else {
  390. if ($wpdb->get_var("SHOW COLUMNS FROM ". Web_Invoice::tablename('main') ." LIKE 'invoice_date'") != 'invoice_date')
  391. {
  392. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('main') ." ADD invoice_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER id;");
  393. $all_invoices = $wpdb->get_results("SELECT DISTINCT invoice_id, time_stamp FROM ". Web_Invoice::tablename('log') ." WHERE action_type = 'created'");
  394. foreach ($all_invoices as $invoice_log) {
  395. $wpdb->query("UPDATE ". Web_Invoice::tablename('main') ." SET invoice_date = '{$invoice_log->time_stamp}' WHERE invoice_date = '0000-00-00 00:00:00' AND invoice_num = '{$invoice_log->invoice_id}'");
  396. }
  397. }
  398. }
  399. if(preg_match('/^4\.0.*/', $wpdb->get_var("SELECT version()")) > 0)
  400. {
  401. $sql_log = "CREATE TABLE IF NOT EXISTS " . Web_Invoice::tablename('log') . " (
  402. id bigint(20) NOT NULL auto_increment,
  403. invoice_id int(11) NOT NULL default '0',
  404. action_type varchar(255) NOT NULL,
  405. `value` longtext NOT NULL,
  406. time_stamp timestamp NOT NULL,
  407. PRIMARY KEY (id)
  408. ) {$charset_collate};";
  409. dbDelta($sql_log);
  410. } else {
  411. $sql_log = "CREATE TABLE IF NOT EXISTS " . Web_Invoice::tablename('log') . " (
  412. id bigint(20) NOT NULL auto_increment,
  413. invoice_id int(11) NOT NULL default '0',
  414. action_type varchar(255) NOT NULL,
  415. `value` longtext NOT NULL,
  416. time_stamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  417. PRIMARY KEY (id)
  418. ) {$charset_collate};";
  419. dbDelta($sql_log);
  420. }
  421. $sql_meta= "CREATE TABLE IF NOT EXISTS `" . Web_Invoice::tablename('meta') . "` (
  422. `meta_id` bigint(20) NOT NULL auto_increment,
  423. `invoice_id` bigint(20) NOT NULL default '0',
  424. `meta_key` varchar(255) default NULL,
  425. `meta_value` longtext,
  426. PRIMARY KEY (`meta_id`),
  427. KEY `invoice_id` (`invoice_id`),
  428. KEY `meta_key` (`meta_key`)
  429. ) {$charset_collate};";
  430. dbDelta($sql_meta);
  431. if($wpdb->get_var("SHOW TABLES LIKE '". Web_Invoice::tablename('payment') ."'") != Web_Invoice::tablename('payment'))
  432. {
  433. $sql_payment = "CREATE TABLE IF NOT EXISTS ". Web_Invoice::tablename('payment') ." (
  434. payment_id int(20) NOT NULL auto_increment,
  435. amount double default '0',
  436. invoice_id int(20) NOT NULL,
  437. user_id int(20) NOT NULL,
  438. status int(11) NOT NULL,
  439. PRIMARY KEY (payment_id)
  440. ) {$charset_collate};";
  441. dbDelta($sql_payment);
  442. } else {
  443. if ($wpdb->get_var("SHOW COLUMNS FROM ". Web_Invoice::tablename('payment') ." LIKE 'invoice_id'") != 'invoice_id')
  444. {
  445. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('payment') ." ADD `invoice_id` INT( 20 ) NOT NULL AFTER `amount`;");
  446. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('payment') ." CHANGE `user_id` `user_id` INT( 20 ) NOT NULL;");
  447. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('payment') ." CHANGE `payment_id` `payment_id` INT( 20 ) NOT NULL;");
  448. }
  449. if ($wpdb->get_var("SHOW COLUMNS FROM ". Web_Invoice::tablename('payment') ." LIKE 'trx_id'") != 'trx_id')
  450. {
  451. $wpdb->query("TRUNCATE TABLE ". Web_Invoice::tablename('payment') .";");
  452. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('payment') ." CHANGE `payment_id` `payment_id` INT( 20 ) NOT NULL AUTO_INCREMENT;");
  453. $wpdb->query("ALTER TABLE ". Web_Invoice::tablename('payment') ." ADD `trx_id` VARCHAR( 25 ) NOT NULL AFTER `invoice_id`, ADD UNIQUE ( `trx_id` );");
  454. }
  455. }
  456. $sql_payment_meta = "CREATE TABLE IF NOT EXISTS `" . Web_Invoice::tablename('payment_meta') . "` (
  457. `payment_meta_id` int(20) NOT NULL auto_increment,
  458. `payment_id` int(20) NOT NULL default '0',
  459. `meta_key` varchar(255) default NULL,
  460. `meta_value` longtext,
  461. PRIMARY KEY (`payment_meta_id`),
  462. KEY `payment_id` (`payment_id`),
  463. KEY `meta_key` (`meta_key`)
  464. ) {$charset_collate};";
  465. dbDelta($sql_payment_meta);
  466. // Fix Paid Statuses from Old Version where they were kept in main table
  467. $all_invoices = $wpdb->get_results("SELECT invoice_num FROM ".Web_Invoice::tablename('main')." WHERE status ='1'");
  468. if(!empty($all_invoices))
  469. {
  470. foreach ($all_invoices as $invoice)
  471. {
  472. web_invoice_update_invoice_meta($invoice->invoice_num,'paid_status','paid');
  473. }
  474. }
  475. // Fix old phone_number and street_address to be without the dash
  476. $all_users_with_meta = $wpdb->get_col("SELECT DISTINCT user_id FROM $wpdb->usermeta");
  477. if(!empty($all_users_with_meta))
  478. {
  479. foreach ($all_users_with_meta as $user)
  480. {
  481. if (get_usermeta($user, 'company_name'))
  482. {
  483. update_usermeta($user, 'company_name',get_usermeta($user, 'company_name'));
  484. }
  485. if (get_usermeta($user, 'tax_id'))
  486. {
  487. update_usermeta($user, 'tax_id',get_usermeta($user, 'tax_id'));
  488. }
  489. if (get_usermeta($user, 'street_address'))
  490. {
  491. update_usermeta($user, 'streetaddress',get_usermeta($user, 'street_address'));
  492. }
  493. if (get_usermeta($user, 'phone_number'))
  494. {
  495. update_usermeta($user, 'phonenumber',get_usermeta($user, 'phone_number'));
  496. }
  497. if (get_usermeta($user, 'country'))
  498. {
  499. update_usermeta($user, 'country',get_usermeta($user, 'country'));
  500. }
  501. }
  502. }
  503. add_option('web_invoice_version', WEB_INVOICE_SCHEDULER_VERSION_NUM);
  504. add_option('web_invoice_email_address', get_bloginfo('admin_email'));
  505. add_option('web_invoice_business_name', get_bloginfo('blogname'));
  506. add_option('web_invoice_business_address', '');
  507. add_option('web_invoice_show_billing_address', 'no');
  508. add_option('web_invoice_show_business_address', 'no');
  509. add_option('web_invoice_payment_method','');
  510. add_option('web_invoice_protocol','http');
  511. add_option('web_invoice_user_level', array('administrator'));
  512. $current_role = get_option('web_invoice_user_level');
  513. if (!is_array($current_role) || in_array('level_8', $current_role))
  514. {
  515. $current_role = array('administrator');
  516. update_option('web_invoice_user_level', $current_role);
  517. }
  518. $ro = new WP_Roles();
  519. foreach ($ro->role_objects as $role)
  520. {
  521. if (in_array($role->name, $current_role))
  522. {
  523. $role->add_cap('manage_web_invoice', true);
  524. }
  525. }
  526. add_option('web_invoice_web_invoice_page','');
  527. add_option('web_invoice_redirect_after_user_add', 'no');
  528. add_option('web_invoice_self_generate_from_template', 'no');
  529. add_option('web_invoice_partial_payments', 'no');
  530. add_option('web_invoice_default_currency_code','USD');
  531. add_option('web_invoice_show_quantities','Hide');
  532. add_option('web_invoice_show_invoice_date','Hide');
  533. add_option('web_invoice_use_css','yes');
  534. add_option('web_invoice_force_https','false');
  535. add_option('web_invoice_send_thank_you_email','no');
  536. add_option('web_invoice_cc_thank_you_email','no');
  537. add_option('web_invoice_tax_count','1');
  538. add_option('web_invoice_tax_name',serialize(array()));
  539. //Authorize.net Gateway Settings
  540. add_option('web_invoice_gateway_username','');
  541. add_option('web_invoice_gateway_tran_key','');
  542. add_option('web_invoice_gateway_delim_char',',');
  543. add_option('web_invoice_gateway_encap_char','');
  544. add_option('web_invoice_gateway_merchant_email',get_bloginfo('admin_email'));
  545. add_option('web_invoice_gateway_header_email_receipt','Thanks for your payment!');
  546. add_option('web_invoice_recurring_gateway_url','https://api.authorize.net/xml/v1/request.api');
  547. add_option('web_invoice_gateway_url','https://gateway.merchantplus.com/cgi-bin/PAWebClient.cgi');
  548. add_option('web_invoice_gateway_MD5Hash','');
  549. add_option('web_invoice_gateway_test_mode','FALSE');
  550. add_option('web_invoice_gateway_delim_data','TRUE');
  551. add_option('web_invoice_gateway_relay_response','FALSE');
  552. add_option('web_invoice_gateway_email_customer','FALSE');
  553. // PayPal
  554. add_option('web_invoice_paypal_button','');
  555. add_option('web_invoice_paypal_subscribe_button','');
  556. add_option('web_invoice_paypal_address','');
  557. add_option('web_invoice_paypal_only_button', 'False');
  558. // Payflow
  559. add_option('web_invoice_payflow_button','');
  560. add_option('web_invoice_payflow_login','');
  561. add_option('web_invoice_payflow_partner','');
  562. add_option('web_invoice_payflow_only_button', 'False');
  563. add_option('web_invoice_payflow_shipping_details', 'True');
  564. add_option('web_invoice_payflow_silent_post', 'False');
  565. // Payflow Pro
  566. add_option('web_invoice_pfp_partner','');
  567. add_option('web_invoice_pfp_env', 'live');
  568. add_option('web_invoice_pfp_authentication','');
  569. add_option('web_invoice_pfp_username', '');
  570. add_option('web_invoice_pfp_password', '');
  571. add_option('web_invoice_pfp_signature', '');
  572. add_option('web_invoice_pfp_wpppe_vendor', '');
  573. add_option('web_invoice_pfp_wpppe_username', '');
  574. add_option('web_invoice_pfp_wpppe_password', '');
  575. add_option('web_invoice_pfp_3rdparty_email', '');
  576. add_option('web_invoice_pfp_shipping_details', 'True');
  577. // Other
  578. add_option('web_invoice_other_details','');
  579. // Moneybookers
  580. add_option('web_invoice_moneybookers_button','');
  581. add_option('web_invoice_moneybookers_address','');
  582. add_option('web_invoice_moneybookers_recurring_address','');
  583. add_option('web_invoice_moneybookers_merchant','False');
  584. add_option('web_invoice_moneybookers_secret',uniqid());
  585. add_option('web_invoice_moneybookers_ip', '83.220.158.0-83.220.158.31,213.129.75.193-213.129.75.206,91.208.28.0-91.208.28.255,193.105.47.0-193.105.47.255');
  586. // AlertPay
  587. add_option('web_invoice_alertpay_button','');
  588. add_option('web_invoice_alertpay_address','');
  589. add_option('web_invoice_alertpay_merchant','False');
  590. add_option('web_invoice_alertpay_secret',uniqid());
  591. add_option('web_invoice_alertpay_test_mode','FALSE');
  592. add_option('web_invoice_alertpay_ip', '67.205.87.225-67.205.87.226,67.205.87.235');
  593. // 2CO
  594. add_option('web_invoice_2co_button','');
  595. add_option('web_invoice_2co_sid','');
  596. add_option('web_invoice_2co_secret_word',uniqid());
  597. add_option('web_invoice_2co_demo_mode','FALSE');
  598. // Google Checkout
  599. add_option('web_invoice_google_checkout_button','');
  600. add_option('web_invoice_google_checkout_env','live');
  601. add_option('web_invoice_google_checkout_merchant_id','');
  602. add_option('web_invoice_google_checkout_level2','False');
  603. add_option('web_invoice_google_checkout_merchant_key','');
  604. add_option('web_invoice_google_checkout_tax_state','NY');
  605. // Sage Pay
  606. add_option('web_invoice_sagepay_button','');
  607. add_option('web_invoice_sagepay_env','live');
  608. add_option('web_invoice_sagepay_vendor_name','');
  609. add_option('web_invoice_sagepay_vendor_key','');
  610. add_option('web_invoice_sagepay_shipping_details', 'True');
  611. // Send invoice
  612. add_option('web_invoice_email_send_invoice_subject','%subject');
  613. add_option('web_invoice_email_send_invoice_content',
  614. "Dear %call_sign,
  615. %business_name has sent you a %recurring
  616. web invoice in the amount of %amount.
  617. %description
  618. You may pay, view and print the invoice online by visiting the following link:
  619. %link
  620. Best regards,
  621. %business_name ( %business_email )");
  622. // Send reminder (past due date)
  623. add_option('web_invoice_email_send_reminder_subject','[Reminder] %subject');
  624. add_option('web_invoice_email_send_reminder_content',
  625. "Dear %call_sign,
  626. %business_name has sent you a reminder for the %recurring
  627. web invoice in the amount of %amount.
  628. %description
  629. You may pay, view and print the invoice online by visiting the following link:
  630. %link.
  631. Best regards,
  632. %business_name ( %business_email )");
  633. // Send reminder (Due in future)
  634. add_option('web_invoice_email_send_reminder_pre_due_subject','[Reminder] %subject due on %due_date');
  635. add_option('web_invoice_email_send_reminder_pre_due_content',
  636. "Dear %call_sign,
  637. %business_name has sent you a friendly reminder for the %recurring
  638. web invoice in the amount of %amount due on %due_date.
  639. %description
  640. You may pay, view and print the invoice online by visiting the following link:
  641. %link.
  642. Best regards,
  643. %business_name ( %business_email )");
  644. // Send receipt
  645. add_option('web_invoice_email_send_receipt_subject','Receipt for %subject');
  646. add_option('web_invoice_email_send_receipt_content',
  647. "Dear %call_sign,
  648. %business_name has received your payment for the %recurring
  649. web invoice in the amount of %amount.
  650. Thank you very much for your patronage.
  651. Best regards,
  652. %business_name ( %business_email )");
  653. add_option('web_invoice_pdf_content',
  654. "<html>
  655. <head>
  656. <title>Invoice</title>
  657. <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  658. </head>
  659. <body>
  660. <div id='invoice_page' class='clearfix'>
  661. <img style='float: right;' src='".$this->the_path."/images/logo_small_padding.gif' style='width:420px; height: 110px;' />
  662. <h1>Invoice</h1>
  663. %content
  664. </div>
  665. </body>
  666. </html>");
  667. add_option('web_invoice_html_content',
  668. '<div id="invoice_page" class="clearfix">
  669. <div class="noprint"><p>%print_message</p></div>
  670. %content
  671. </div>');
  672. add_option('web_invoice_installed', true);
  673. }
  674. }
  675. class Web_Invoice_GetInfo
  676. {
  677. var $id;
  678. var $_row_cache;
  679. function __construct($invoice_id)
  680. {
  681. global $_web_invoice_getinfo, $_web_invoice_clear_cache, $wpdb;
  682. $this->id = $invoice_id;
  683. if (isset($_web_invoice_getinfo[$this->id]) && $_web_invoice_getinfo[$this->id])
  684. {
  685. $this->_row_cache = $_web_invoice_getinfo[$this->id];
  686. }
  687. if (!$this->_row_cache || $_web_invoice_clear_cache)
  688. {
  689. $this->_setRowCache($wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '{$invoice_id}'"));
  690. $_web_invoice_clear_cache = false;
  691. }
  692. if (!$this->_row_cache)
  693. {
  694. $_custom_invoice = $wpdb->get_row("SELECT invoice_id FROM ".Web_Invoice::tablename('meta')." WHERE meta_key = 'web_invoice_custom_invoice_id' AND meta_value = '{$invoice_id}'");
  695. $this->id = $_custom_invoice->invoice_id;
  696. $this->_setRowCache($wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '{$this->id}'"));
  697. }
  698. }
  699. function _setRowCache($row)
  700. {
  701. global $_web_invoice_getinfo;
  702. if (!$row)
  703. {
  704. $this->id = null;
  705. return;
  706. }
  707. $this->_row_cache = $row;
  708. $_web_invoice_getinfo[$this->id] = $this->_row_cache;
  709. }
  710. function recipient($what)
  711. {
  712. global $_web_invoice_clear_cache, $wpdb;
  713. if (!$this->_row_cache || $_web_invoice_clear_cache)
  714. {
  715. $this->_setRowCache($wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '{$this->id}'"));
  716. $_web_invoice_clear_cache = false;
  717. }
  718. if ($this->_row_cache)
  719. {
  720. $uid = $this->_row_cache->user_id;
  721. $profileuser = get_userdata($uid);
  722. $user_email = $profileuser->user_email;
  723. } else {
  724. $uid = false;
  725. $user_email = false;
  726. }
  727. $invoice_info = $this->_row_cache;
  728. switch ($what)
  729. {
  730. case 'callsign':
  731. $first_name = strip_tags(get_usermeta($uid,'first_name'));
  732. $last_name = strip_tags(get_usermeta($uid,'last_name'));
  733. if (empty($first_name) || empty($last_name))
  734. {
  735. return $user_email;
  736. } else {
  737. return $first_name . " " . $last_name;
  738. }
  739. break;
  740. case 'user_id':
  741. return $uid;
  742. break;
  743. case 'email_address':
  744. return $user_email;
  745. break;
  746. case 'first_name':
  747. return strip_tags(get_usermeta($uid,'first_name'));
  748. break;
  749. case 'last_name':
  750. return strip_tags(get_usermeta($uid,'last_name'));
  751. break;
  752. case 'phonenumber':
  753. return web_invoice_format_phone(get_usermeta($uid,'phonenumber'));
  754. break;
  755. case 'paypal_phonenumber':
  756. return get_usermeta($uid,'phonenumber');
  757. break;
  758. case 'log_status':
  759. 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"))
  760. {
  761. return $status_update->value . " - " . web_invoice_Date::convert($status_update->time_stamp, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN));
  762. }
  763. break;
  764. case 'paid_date':
  765. $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");
  766. if ($paid_date)
  767. {
  768. return web_inv;
  769. }
  770. break;
  771. case 'streetaddress':
  772. return get_usermeta($uid,'streetaddress');
  773. break;
  774. case 'state':
  775. return strtoupper(get_usermeta($uid,'state'));
  776. break;
  777. case 'city':
  778. return get_usermeta($uid,'city');
  779. break;
  780. case 'zip':
  781. return get_usermeta($uid,'zip');
  782. break;
  783. case 'country':
  784. if (get_usermeta($uid,'country'))
  785. {
  786. return get_usermeta($uid,'country');
  787. } else {
  788. return "US";
  789. }
  790. break;
  791. case 'company_name':
  792. if (get_usermeta($uid,'company_name'))
  793. {
  794. return get_usermeta($uid,'company_name');
  795. } else {
  796. return "";
  797. }
  798. break;
  799. case 'tax_id':
  800. if (get_usermeta($uid,'tax_id'))
  801. {
  802. return get_usermeta($uid,'tax_id');
  803. } else {
  804. return "";
  805. }
  806. break;
  807. }
  808. }
  809. function shipping($what) {
  810. global $_web_invoice_clear_cache, $wpdb;
  811. if (!$this->_row_cache || $_web_invoice_clear_cache)
  812. {
  813. $this->_setRowCache($wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '{$this->id}'"));
  814. $_web_invoice_clear_cache = false;
  815. }
  816. if ($this->_row_cache)
  817. {
  818. $uid = $this->_row_cache->user_id;
  819. $user_email = $wpdb->get_var("SELECT user_email FROM ". $wpdb->prefix . "users WHERE id=".$uid);
  820. } else {
  821. $uid = false;
  822. $user_email = false;
  823. }
  824. $invoice_info = $this->_row_cache;
  825. switch ($what)
  826. {
  827. case 'first_name':
  828. return (get_usermeta($uid,'shipto_first_name')!="")?get_usermeta($uid,'shipto_first_name'):get_usermeta($uid,'first_name');
  829. break;
  830. case 'last_name':
  831. return (get_usermeta($uid,'shipto_last_name')!="")?get_usermeta($uid,'shipto_last_name'):get_usermeta($uid,'last_name');
  832. break;
  833. case 'email_address':
  834. return $user_email;
  835. break;
  836. case 'phonenumber':
  837. $phone_number = (get_usermeta($uid,'shipto_phonenumber')!="")?get_usermeta($uid,'shipto_phonenumber'):get_usermeta($uid,'phonenumber');
  838. return web_invoice_format_phone($phone_number);
  839. break;
  840. case 'paypal_phonenumber':
  841. return (get_usermeta($uid,'shipto_phonenumber')!="")?get_usermeta($uid,'shipto_phonenumber'):get_usermeta($uid,'phonenumber');
  842. break;
  843. case 'streetaddress':
  844. return (get_usermeta($uid,'shipto_streetaddress')!="")?get_usermeta($uid,'shipto_streetaddress'):get_usermeta($uid,'streetaddress');
  845. break;
  846. case 'state':
  847. $state = (get_usermeta($uid,'shipto_state')!="")?get_usermeta($uid,'shipto_state'):get_usermeta($uid,'state');
  848. return strtoupper($state);
  849. break;
  850. case 'city':
  851. return (get_usermeta($uid,'shipto_city')!="")?get_usermeta($uid,'shipto_city'):get_usermeta($uid,'city');
  852. break;
  853. case 'zip':
  854. return (get_usermeta($uid,'shipto_zip')!="")?get_usermeta($uid,'shipto_zip'):get_usermeta($uid,'zip');
  855. break;
  856. case 'country':
  857. if(get_usermeta($uid,'shipto_country'))
  858. {
  859. return get_usermeta($uid,'shipto_country');
  860. } else if(get_usermeta($uid,'country')) {
  861. return get_usermeta($uid,'country');
  862. } else {
  863. return "US";
  864. }
  865. break;
  866. case 'company_name':
  867. if (get_usermeta($uid,'shipto_company_name'))
  868. {
  869. return get_usermeta($uid,'shipto_company_name');
  870. } else if(get_usermeta($uid,'company_name')) {
  871. return get_usermeta($uid,'company_name');
  872. } else {
  873. return "";
  874. break;
  875. }
  876. }
  877. }
  878. function display($what)
  879. {
  880. global $_web_invoice_clear_cache, $wpdb;
  881. if (!$this->_row_cache || $_web_invoice_clear_cache)
  882. {
  883. $this->_setRowCache($wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '{$this->id}'"));
  884. $_web_invoice_clear_cache = false;
  885. }
  886. $invoice_info = $this->_row_cache;
  887. switch ($what)
  888. {
  889. case 'log_status':
  890. 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"))
  891. {
  892. return $status_update->value . " - " . web_invoice_Date::convert($status_update->time_stamp, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN));
  893. }
  894. break;
  895. case 'paid_date':
  896. $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");
  897. if ($paid_date)
  898. {
  899. 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))));
  900. }
  901. break;
  902. case 'paid_date_raw':
  903. $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");
  904. if ($paid_date) {
  905. return $paid_date;
  906. }
  907. break;
  908. case 'subscription_name':
  909. return web_invoice_meta($this->id,'web_invoice_subscription_name');
  910. break;
  911. case 'interval_length':
  912. return web_invoice_meta($this->id,'web_invoice_subscription_length');
  913. break;
  914. case 'interval_unit':
  915. return web_invoice_meta($this->id,'web_invoice_subscription_unit');
  916. break;
  917. case 'totalOccurrences':
  918. return web_invoice_meta($this->id,'web_invoice_subscription_total_occurances');
  919. break;
  920. case 'installment':
  921. return web_invoice_meta($this->id,'installment',0);
  922. break;
  923. case 'startDate':
  924. $web_invoice_subscription_start_day = web_invoice_meta($this->id,'web_invoice_subscription_start_day');
  925. $web_invoice_subscription_start_year = web_invoice_meta($this->id,'web_invoice_subscription_start_year');
  926. $web_invoice_subscription_start_month = web_invoice_meta($this->id,'web_invoice_subscription_start_month');
  927. 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())
  928. {
  929. 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));
  930. } else {
  931. return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), time()+1800);
  932. }
  933. break;
  934. case 'endDate':
  935. 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'))));
  936. break;
  937. case 'nextDate':
  938. if ($this->display('totalOccurrences') > $this->display('installment')) {
  939. if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) {
  940. $start_date = $this->display('due_dateM');
  941. } else {
  942. $start_date = $this->display('startDateM');
  943. }
  944. 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)));
  945. }
  946. return $this->display('endDate');
  947. break;
  948. case 'startDateM':
  949. $web_invoice_subscription_start_day = web_invoice_meta($this->id,'web_invoice_subscription_start_day');
  950. $web_invoice_subscription_start_year = web_invoice_meta($this->id,'web_invoice_subscription_start_year');
  951. $web_invoice_subscription_start_month = web_invoice_meta($this->id,'web_invoice_subscription_start_month');
  952. 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())
  953. {
  954. return date('Y-m-d', strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day));
  955. } else {
  956. return date('Y-m-d', time()+1800);
  957. }
  958. break;
  959. case 'endDateM':
  960. return date('Y-m-d', strtotime("+".($this->display('interval_length')*$this->display('totalOccurrences'))." ".$this->display('interval_unit'), strtotime($this->display('startDateM'))));
  961. break;
  962. case 'nextDateM':
  963. if ($this->display('totalOccurrences') > $this->display('installment')) {
  964. if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) {
  965. $start_date = $this->display('due_dateM');
  966. } else {
  967. $start_date = $this->display('startDateM');
  968. }
  969. return date('Y-m-d', strtotime("+".($this->display('interval_length')*$this->display('installment'))." ".$this->display('interval_unit'), strtotime($start_date)));
  970. }
  971. return $this->display('endDate');
  972. break;
  973. case 'profileEndDate':
  974. 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));
  975. break;
  976. case 'archive_status':
  977. $result = $wpdb->get_col("SELECT action_type FROM ".Web_Invoice::tablename('log')." WHERE invoice_id = '".$this->id."' ORDER BY time_stamp DESC");
  978. foreach ($result as $event)
  979. {
  980. if ($event == 'unarchive')
  981. {
  982. return ''; break;
  983. }
  984. if ($event == 'archive')
  985. {
  986. return 'archive';
  987. break;
  988. }
  989. }
  990. break;
  991. case 'display_billing_rate':
  992. $length = web_invoice_meta($this->id,'web_invoice_subscription_length');
  993. $unit = web_invoice_meta($this->id,'web_invoice_subscription_unit');
  994. $occurances = web_invoice_meta($this->id,'web_invoice_subscription_total_occurances');
  995. // days
  996. if($unit == "days") {
  997. if($length == '1')
  998. {
  999. return "daily for $occurances days";
  1000. }
  1001. if ($length > '1') {
  1002. return "every $length days for a total of $occurances billing cycles";
  1003. }
  1004. }
  1005. //months
  1006. if ($unit == "months")
  1007. {
  1008. if ($length == '1') {
  1009. return "monthly for $occurances months";
  1010. }
  1011. if ($length > '1') {
  1012. return "every $length months $occurances times";
  1013. }
  1014. }
  1015. if ($unit == "years")
  1016. {
  1017. if ($length == '1') {
  1018. return "annually for $occurances years";
  1019. }
  1020. if ($length > '1') {
  1021. return "every $length years $occurances times";
  1022. }
  1023. }
  1024. break;
  1025. case 'link':
  1026. $link_to_page = get_permalink(get_option('web_invoice_web_invoice_page'));
  1027. $hashed = md5($this->id);
  1028. if(get_option("permalink_structure")) {
  1029. return $link_to_page . "?invoice_id=" .$hashed;
  1030. } else {
  1031. return $link_to_page . "&invoice_id=" . $hashed;
  1032. }
  1033. break;
  1034. case 'invoice_hash':
  1035. return md5($this->id);
  1036. break;
  1037. case 'print_link':
  1038. return $this->display('link').'&print=1';
  1039. break;
  1040. case 'hash':
  1041. return md5($this->id);
  1042. break;
  1043. case 'currency':
  1044. if (web_invoice_meta($this->id,'web_invoice_currency_code') != '')
  1045. {
  1046. $currency_code = web_invoice_meta($this->id,'web_invoice_currency_code');
  1047. } else if (get_option('web_invoice_default_currency_code') != '') {
  1048. $currency_code = get_option('web_invoice_default_currency_code');
  1049. } else {
  1050. $currency_code = "USD";
  1051. }
  1052. return $currency_code;
  1053. break;
  1054. case 'display_id':
  1055. $web_invoice_custom_invoice_id = web_invoice_meta($this->id,'web_invoice_custom_invoice_id');
  1056. if (empty($web_invoice_custom_invoice_id))
  1057. {
  1058. return $this->id;
  1059. } else {
  1060. return $web_invoice_custom_invoice_id;
  1061. }
  1062. break;
  1063. case 'due_date':
  1064. $web_invoice_due_date_month = web_invoice_meta($this->id,'web_invoice_due_date_month');
  1065. $web_invoice_due_date_year = web_invoice_meta($this->id,'web_invoice_due_date_year');
  1066. $web_invoice_due_date_day = web_invoice_meta($this->id,'web_invoice_due_date_day');
  1067. if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day))
  1068. {
  1069. 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"));
  1070. }
  1071. return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)));
  1072. break;
  1073. case 'due_dateM':
  1074. $web_invoice_due_date_month = web_invoice_meta($this->id,'web_invoice_due_date_month');
  1075. $web_invoice_due_date_year = web_invoice_meta($this->id,'web_invoice_due_date_year');
  1076. $web_invoice_due_date_day = web_invoice_meta($this->id,'web_invoice_due_date_day');
  1077. if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day))
  1078. {
  1079. return date('Y-m-d', strtotime("$web_invoice_due_date_year-$web_invoice_due_date_month-$web_invoice_due_date_day"));
  1080. }
  1081. return date('Y-m-d');
  1082. break;
  1083. case 'invoice_date':
  1084. if ($invoice_info && $invoice_info->invoice_date && !empty($invoice_info->invoice_date)) {
  1085. date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime($invoice_info->invoice_date));
  1086. }
  1087. return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)));
  1088. break;
  1089. case 'amount':
  1090. return $invoice_info->amount;
  1091. break;
  1092. case 'due_amount':
  1093. $payments = web_invoice_sum_payments($this->id);
  1094. return max(0, $invoice_info->amount-$payments);
  1095. bre

Large files files are truncated, but you can click here to view the full file