function update($VAR) { global $C_translate, $C_debug; /* load database object */ $db = new CORE_database(); $this->construct(); $type = "update"; /* conditional fields for cc/eft */ $dbx =& DB(); $rs = $dbx->Execute(sqlSelect($dbx, "account_billing", "card_type,id,checkout_plugin_id", "id=::{$VAR['id']}::")); if (!$rs || !$rs->RecordCount()) { return false; } $billing_id = $rs->fields['id']; $checkout_plugin_id = $rs->fields['checkout_plugin_id']; if ($rs->fields['card_type'] == 'eft') { /* EFT */ $this->method["{$type}"] = $db->ignore_fields(array('card_exp_month', 'card_exp_year', 'card_num'), $this->method["{$type}"]); /* last four */ @($VAR['account_billing_card_num4'] = substr($VAR['account_billing_eft_check_acct'], strlen($VAR['account_billing_eft_check_acct']) - 4, 4)); } else { /* CC */ # Validate the exp date if (mktime(0, 0, 0, $VAR['account_billing_card_exp_month'], date('d'), $VAR['account_billing_card_exp_year']) <= time()) { $msg = $C_translate->translate('val_exp', 'account_billing', ''); $C_debug->alert($msg); return false; } # Validate the card against the card type include_once PATH_CORE . 'validate.inc.php'; $validate = new CORE_validate(); if (!$validate->validate_cc(@$VAR['account_billing_card_num'], 'card_num', @$VAR['account_billing_card_type'], false)) { $msg = $C_translate->translate('val_cc', 'account_billing', ''); $C_debug->alert($msg); return false; } $this->method["{$type}"] = $db->ignore_fields(array('eft_trn', 'eft_check_acct'), $this->method["{$type}"]); /* last four */ @($VAR['account_billing_card_num4'] = substr($VAR['account_billing_card_num'], strlen($VAR['account_billing_card_num']) - 4, 4)); } if ($db->update($VAR, $this, $type)) { # Update any invoices using this billing record $dba =& DB(); $sql = "UPDATE " . AGILE_DB_PREFIX . "invoice SET\n\t\t\t\t\t\tcheckout_plugin_id \t= " . $dba->qstr($checkout_plugin_id) . "\n\t\t\t\t\t\tWHERE site_id\t\t\t\t= " . $dba->qstr(DEFAULT_SITE) . "\n\t\t\t\t\t\tAND account_billing_id\t= " . $dba->qstr($billing_id); $result = $dba->Execute($sql); return true; } return false; }