Example #1
0
 function convert_encrypt($data, $field)
 {
     if ($data != "") {
         include_once PATH_CORE . 'crypt.inc.php';
         return CORE_encrypt($data);
     } else {
         return '';
     }
 }
 function accounts()
 {
     global $VAR, $C_debug;
     $p = AGILE_DB_PREFIX;
     $s = DEFAULT_SITE;
     ### Connect to the remote Db;
     $dbr =& NewADOConnection($this->type);
     $dbr->Connect($this->host, $this->user, $this->pass, $this->db);
     ### Determine the offset for the account
     if (empty($VAR['offset'])) {
         $VAR['offset'] = 0;
     }
     @($offset = $VAR['offset'] . "," . $this->select_limit);
     # select each account from aMember
     echo $sql = "SELECT *, UNIX_TIMESTAMP(added) as date_orig FROM {$this->prefix}members";
     $rs = $dbr->SelectLimit($sql, $offset);
     if ($rs === false) {
         $C_debug->alert("Query to the table '{$this->prefix}members' failed!");
         return false;
     }
     if ($rs->RecordCount() == 0) {
         $C_debug->alert("No more records to process!");
         echo "<script language=javascript>setTimeout('document.location=\\'?_page=import:import&plugin={$VAR['plugin']}\\'', 1500); </script>";
         return;
     }
     ### Include AB Encryption class:
     include_once PATH_CORE . 'crypt.inc.php';
     ### Get the default checkout plugin id:
     $db =& DB();
     $sql = "SELECT id FROM {$p}checkout WHERE\n\t\t\t\tsite_id = {$s} AND\n\t\t\t\tcheckout_plugin = '{$this->gateway}'";
     $ch = $db->Execute($sql);
     $checkout_plugin_id = $ch->fields['id'];
     $msg = "Processing " . $rs->RecordCount() . " Records...<BR>";
     # loop through each remote account
     while (!$rs->EOF) {
         $msg .= "<BR>Processing account: {$rs->fields['login']}...";
         # start a new transaction for the insert:
         $db =& DB();
         $db->StartTrans();
         # Get a local account id
         $id = $db->GenID($p . 'account_id');
         # Get orig date
         if (!empty($rs->fields['date_orig'])) {
             $date_orig = $rs->fields['date_orig'];
         } else {
             $date_orig = time();
         }
         # Insert the account
         $sql = "INSERT INTO {$p}account SET\n\t\t\t\t\tid \t\t\t= {$id},\n\t\t\t\t\tsite_id\t\t= {$s},\n\t\t\t\t\tdate_orig\t= {$date_orig},\n\t\t\t\t\tdate_last\t= " . time() . ",\n\t\t\t\t\tlanguage_id\t= " . $db->qstr(DEFAULT_LANGUAGE) . ",\n\t\t\t\t\tcurrency_id\t= " . DEFAULT_CURRENCY . ",\n\t\t\t\t\ttheme_id\t= " . $db->qstr(DEFAULT_THEME) . ",\n\t\t\t\t\tusername\t= " . $db->qstr($rs->fields['login']) . ",\n\t\t\t\t\tpassword\t= " . $db->qstr(md5($rs->fields['pass'])) . ",\n\t\t\t\t\tstatus\t\t= 1,\n\t\t\t\t\tcountry_id\t= " . $db->qstr($rs->fields['country']) . ",\n\t\t\t\t\tfirst_name\t= " . $db->qstr($rs->fields['name_f']) . ",\n\t\t\t\t\tlast_name\t= " . $db->qstr($rs->fields['name_l']) . ", \n\t\t\t\t\taddress1\t= " . $db->qstr($rs->fields['street']) . ",\n\t\t\t\t\tcity\t\t= " . $db->qstr($rs->fields['city']) . ",\n\t\t\t\t\tstate\t\t= " . $db->qstr($rs->fields['state']) . ",\n\t\t\t\t\tzip\t\t\t= " . $db->qstr($rs->fields['zip']) . ",\n\t\t\t\t\temail\t\t= " . $db->qstr($rs->fields['email']) . ",\n\t\t\t\t\temail_type\t= 0";
         $db->Execute($sql);
         # Insert the import record
         $this->import_transaction($this->plugin, $VAR['action'], 'account', $id, 'members', $rs->fields['member_id'], &$db);
         if (!empty($rs->fields['data'])) {
             $data = unserialize($rs->fields['data']);
             if (is_array($data)) {
                 if (!empty($data['cc']) && !empty($data['cc-expire'])) {
                     ### Insert a CC record for this user:
                     $idx = $db->GenID($p . 'account_billing_id');
                     $exp_month = substr($data['cc-expire'], 0, 2);
                     $exp_year = substr($data['cc-expire'], 2, 2);
                     $cc_num = $data['cc'];
                     $last_four = substr($cc_num, strlen($cc_num) - 4, 4);
                     $card_type = $this->cc_identify($cc_num);
                     $card_num = CORE_encrypt($cc_num);
                     # Insert local billing record
                     $sql = "INSERT INTO {$p}account_billing SET\n\t\t\t\t\t\t\t\tid \t\t\t\t\t= {$idx},\n\t\t\t\t\t\t\t\tsite_id\t\t\t\t= {$s},  \n\t\t\t\t\t\t\t\taccount_id\t\t\t= {$id},\n\t\t\t\t\t\t\t\tcheckout_plugin_id \t= {$checkout_plugin_id},\n\t\t\t\t\t\t\t\tcard_type\t\t\t= '{$card_type}',\n\t\t\t\t\t\t\t\tcard_num\t\t\t= " . $db->qstr($card_num) . ",\n\t\t\t\t\t\t\t\tcard_num4\t\t\t= '{$last_four}',\n\t\t\t\t\t\t\t\tcard_exp_month\t\t= '{$exp_month}',\n\t\t\t\t\t\t\t\tcard_exp_year\t\t= '{$exp_year}'";
                     $db->Execute($sql);
                     # Update the account
                     $sql = "UPDATE {$p}account SET    \n\t\t\t\t\t\t\t\taddress1\t= " . $db->qstr(@$data['cc_street']) . ",\n\t\t\t\t\t\t\t\tcity\t\t= " . $db->qstr(@$data['cc_city']) . ",\n\t\t\t\t\t\t\t\tstate\t\t= " . $db->qstr(@$data['cc_state']) . ",\n\t\t\t\t\t\t\t\tzip\t\t\t= " . $db->qstr(@$data['cc_zip']) . "\n\t\t\t\t\t\t\t\tWHERE   id  = {$id}";
                     $db->Execute($sql);
                     # Insert the import record
                     $this->import_transaction($VAR['plugin'], $VAR['action'], 'account_billing', $idx, 'billing', $rs->fields['member_id'], &$db);
                 }
             }
         }
         # Complete the transaction
         $db->CompleteTrans();
         $rs->MoveNext();
     }
     $C_debug->alert($msg);
     $offset = $VAR['offset'] + $this->select_limit;
     echo "<script language=javascript> \n\t\t\t  setTimeout('document.location=\\'?_page=core:blank&offset={$offset}&action={$VAR['action']}&plugin={$VAR['plugin']}&do[]=import:do_action\\'', 1200);\n\t\t\t </script>";
 }
Example #3
0
 function billing()
 {
     global $VAR, $C_debug;
     $p = AGILE_DB_PREFIX;
     $s = DEFAULT_SITE;
     # validate the salt file...
     if (!is_file($this->salt)) {
         $C_debug->alert('The path to the salt file set in the plugin script ' . __FILE__ . ' is incorrect');
         return;
     }
     ### Determine the offset for the account
     if (empty($VAR['offset'])) {
         $VAR['offset'] = 0;
     }
     @($offset = $VAR['offset'] . "," . $this->select_limit);
     ### Select from the imported accounts
     $db =& DB();
     $sql = "SELECT * FROM {$p}import WHERE\n\t\t\t\tplugin \t\t= '{$this->plugin}' AND\n\t\t\t\taction \t\t= 'accounts' AND\n\t\t\t\tab_table \t= 'account' AND\n\t\t\t\tsite_id\t\t= {$s}";
     $rs = $db->SelectLimit($sql, $offset);
     if ($rs === false) {
         $C_debug->alert("Query to the table 'import' failed!");
         return false;
     }
     if ($rs->RecordCount() == 0) {
         $C_debug->alert("No more records to process!");
         echo "<script language=javascript>setTimeout('document.location=\\'?_page=import:import&plugin={$VAR['plugin']}\\'', 1500); </script>";
         return;
     }
     ### Include AB Encryption class:
     include_once PATH_CORE . 'crypt.inc.php';
     ### Get the default checkout plugin id:
     $sql = "SELECT id FROM {$p}checkout WHERE site_id = {$s} AND checkout_plugin = '{$this->gateway}'";
     $ch = $db->Execute($sql);
     $checkout_plugin_id = $ch->fields['id'];
     $msg = "Processing " . $rs->RecordCount() . " Records...<BR>";
     # loop through each remote billing record
     while (!$rs->EOF) {
         $msg .= "<BR>Processing Account Id: {$rs->fields['ab_id']}...";
         # start a new transaction for the insert:
         $db->StartTrans();
         # Get the local account id
         $ab_account_id = $rs->fields['ab_id'];
         $remote_account_id = $rs->fields['remote_id'];
         # Connect to the remote DB and get all billing records for this
         # account, where the cc_num is not blank
         $dbr =& NewADOConnection($this->type);
         $dbr->Connect($this->host, $this->user, $this->pass, $this->db);
         $sql = "SELECT * FROM billing WHERE\n\t\t\t\t\tbilling_account_id = {$remote_account_id} AND\n\t\t\t\t\tbilling_cc_num != ''";
         $billing = $dbr->Execute($sql);
         if ($billing != false && $billing->RecordCount() > 0) {
             while (!$billing->EOF) {
                 # Get local billing id
                 $db =& DB();
                 $id = $db->GenID($p . 'account_billing_id');
                 # Decrypt the remote CC
                 $cc_num_plain = $this->RC4($billing->fields['billing_cc_num'], 'de');
                 # Encrypt to local algorythm
                 $card_num = CORE_encrypt($cc_num_plain);
                 # get the last 4 digits:
                 $last_four = eregi_replace('^............', '', $cc_num_plain);
                 # Identify the card type:
                 $card_type = $this->cc_identify($cc_num_plain);
                 # Get the month  & year
                 $exp = explode('20', trim($billing->fields['billing_cc_exp']));
                 $exp_month = @$exp[0];
                 $exp_year = @$exp[1];
                 if ($card_type != '') {
                     # Start transaction
                     $db->StartTrans();
                     # Insert local billing record
                     $sql = "INSERT INTO {$p}account_billing SET\n\t\t\t\t\t\t\t\tid \t\t\t\t\t= {$id},\n\t\t\t\t\t\t\t\tsite_id\t\t\t\t= {$s},  \n\t\t\t\t\t\t\t\taccount_id\t\t\t= {$ab_account_id},\n\t\t\t\t\t\t\t\tcheckout_plugin_id \t= {$checkout_plugin_id},\n\t\t\t\t\t\t\t\tcard_type\t\t\t= '{$card_type}',\n\t\t\t\t\t\t\t\tcard_num\t\t\t= " . $db->qstr($card_num) . ",\n\t\t\t\t\t\t\t\tcard_num4\t\t\t= '{$last_four}',\n\t\t\t\t\t\t\t\tcard_exp_month\t\t= '{$exp_month}',\n\t\t\t\t\t\t\t\tcard_exp_year\t\t= '{$exp_year}'";
                     $db->Execute($sql);
                     # Insert the import record
                     $this->import_transaction($VAR['plugin'], $VAR['action'], 'account_billing', $id, 'billing', $billing->fields['billing_id'], &$db);
                     # Complete the transaction
                     $db->CompleteTrans();
                 }
                 $billing->MoveNext();
             }
         }
         $rs->MoveNext();
     }
     $C_debug->alert($msg);
     $offset = $VAR['offset'] + $this->select_limit;
     echo "<script language=javascript> \n\t\t\t setTimeout('document.location=\\'?_page=core:blank&offset={$offset}&action={$VAR['action']}&plugin={$VAR['plugin']}&do[]=import:do_action\\'', 1500);\n\t\t\t </script>";
 }
 /**
  * Store the billing EFT details entered
  */
 function saveEFTDetails($VAR)
 {
     global $C_auth;
     if (!empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout', 'admin_checkoutnow')) {
         $account_id = $VAR['account_id'];
     } else {
         $account_id = SESS_ACCOUNT;
     }
     # Check if this card is already on file:
     $last_four = substr($this->billing['eft_check_acct'], strlen($this->billing['eft_check_acct']) - 4, 4);
     $db =& DB();
     $q = "SELECT id,card_exp_month,card_exp_year FROM " . AGILE_DB_PREFIX . "account_billing WHERE\n\t\t\tsite_id \t\t= " . $db->qstr(DEFAULT_SITE) . " AND \n\t\t\taccount_id \t\t= " . $db->qstr($account_id) . " AND\n\t\t\tcard_num4 \t\t= " . $db->qstr($last_four) . " AND\n\t\t\tcheckout_plugin_id = " . $db->qstr($this->checkout_id) . " AND\n\t\t\tcard_type\t \t= " . $db->qstr($this->billing['card_type']);
     $rs = $db->Execute($q);
     if ($rs && $rs->RecordCount()) {
         return $rs->fields['id'];
     }
     include_once PATH_CORE . 'crypt.inc.php';
     $ssn = false;
     $dob = false;
     $dl_no = false;
     if (!empty($this->billing['dob'])) {
         $dob = CORE_encrypt($this->billing['dob']);
     }
     if (!empty($this->billing['ssn'])) {
         $ssn = CORE_encrypt($this->billing['ssn']);
     }
     if (!empty($this->billing['dl_no'])) {
         $dl_no = CORE_encrypt($this->billing['dl_no']);
     }
     $check_acct = CORE_encrypt($this->billing['eft_check_acct']);
     $trn = CORE_encrypt($this->billing['eft_trn']);
     $id = $db->GenID(AGILE_DB_PREFIX . 'account_billing_id');
     $sql = "INSERT INTO " . AGILE_DB_PREFIX . "account_billing SET\n\t\t\tid \t\t\t\t\t= " . $db->qstr($id) . ",\n\t\t\tsite_id\t\t\t\t= " . $db->qstr(DEFAULT_SITE) . ",\n\t\t\taccount_id\t\t\t= " . $db->qstr($account_id) . ",\n\t\t\tcheckout_plugin_id\t= " . $db->qstr($this->checkout_id) . ", \n\t\t\tcard_num4\t\t\t= " . $db->qstr($last_four) . ", \n\t\t\tcard_type\t\t\t= " . $db->qstr(@$this->billing['card_type']) . ",\n\t\t\teft_check_checkno\t= " . $db->qstr($this->billing['eft_check_checkno']) . ",\n\t\t\teft_check_acct_type\t= " . $db->qstr($this->billing['eft_check_acct_type']) . ",\n\t\t\teft_trn\t\t\t\t= " . $db->qstr($trn) . ",\n\t\t\teft_check_acct\t\t= " . $db->qstr($check_acct) . ",\n\t\t\tdob\t\t\t\t\t= " . $db->qstr($dob) . ",\n\t\t\tdl_no\t\t\t\t= " . $db->qstr($dl_no) . ",  \n\t\t\tssn\t\t\t\t\t= " . $db->qstr($ssn) . ", \n\t\t\tfirst_name\t\t\t= " . $db->qstr(@$this->account['first_name']) . ",\n\t\t\tlast_name\t\t\t= " . $db->qstr(@$this->account['last_name']) . ",\n\t\t\taddress1\t\t\t= " . $db->qstr(@$this->account['address1']) . ",\n\t\t\taddress2\t\t\t= " . $db->qstr(@$this->account['address2']) . ",\n\t\t\tcity\t\t\t\t= " . $db->qstr(@$this->account['city']) . ",\n\t\t\tstate\t\t\t\t= " . $db->qstr(@$this->account['state']) . ",\n\t\t\tzip\t\t\t\t\t= " . $db->qstr(@$this->account['zip']) . ",\n\t\t\tcountry_id\t\t\t= " . $db->qstr(@$this->account['country_id']) . ",\n\t\t\tphone\t\t\t\t= " . $db->qstr(@$this->account['phone']) . ",\n\t\t\temail\t\t\t\t= " . $db->qstr(@$this->account['email']) . ",\n\t\t\tcompany\t\t\t\t= " . $db->qstr(@$this->account['company']);
     $result = $db->Execute($sql);
     if ($result) {
         return $id;
     }
     return false;
 }