/** * Returnts the full person custom attribute record (person_attributes and person_info_variants_to_attributes) * * @author Andrei V. Zhuravlev * @param $variantId integer variant id * @param $attributeId integer attribute id */ function getPersonCustomAttributeData($attributeId) { global $application; $tables = $this->getTables(); $piva = $tables['person_info_variants_to_attributes']['columns']; $pa = $tables['person_attributes']['columns']; $query = new DB_Select(); foreach ($piva as $k => $v) { if ($k != 'name' && $k != 'descr') { $query->addSelectField($v); } } $query->setMultiLangAlias('_ml_name', 'person_info_variants_to_attributes', $piva['name'], $piva['id'], 'Checkout'); $query->addSelectField($query->getMultiLangAlias('_ml_name'), 'person_attribute_visible_name'); $query->setMultiLangAlias('_ml_descr', 'person_info_variants_to_attributes', $piva['descr'], $piva['id'], 'Checkout'); $query->addSelectField($query->getMultiLangAlias('_ml_descr'), 'person_attribute_description'); foreach ($pa as $v) { $query->addSelectField($v); } $query->WhereField($piva['attribute_id'], DB_EQ, $pa['id']); $query->WhereAnd(); $query->WhereValue($piva['attribute_id'], DB_EQ, $attributeId); $query->WhereAnd(); $query->WhereValue($pa['is_custom'], DB_EQ, "1"); $result = $application->db->getDB_Result($query); return $result; }
/** * Saves a list of fields for the Person Info attribute. If it saves fields * for the Country attribute and it is invisible, then the State attribute, * associated with it, should be invisible too. * * @author Oleg Vlasenko * @param integer $fields - the array of new values of the fields * @return void */ function setPersonInfoFieldList($fields) { global $application; $tables = $this->getTables(); $columns = $tables['person_info_variants_to_attributes']['columns']; $variant_id = $fields['variant_id']; $attribute_id = $fields['attribute_id']; $fields_original = $this->getPersonInfoFieldsList($variant_id, $attribute_id); $fields['unremovable'] = $fields_original['unremovable']; if ($fields_original['unremovable'] != 0) { $fields['visible'] = '1'; $fields['required'] = '1'; } if ($fields_original['variant_id'] == 4) { $fields['unremovable'] = '1'; $fields['required'] = '0'; } $query = new DB_Update('person_info_variants_to_attributes'); if ($fields['name'] != null) { $query->addMultiLangUpdateValue($columns['name'], $fields['name'], $columns['id'], '', 'Checkout'); } if ($fields['descr'] != null) { $query->addMultiLangUpdateValue($columns['descr'], $fields['descr'], $columns['id'], '', 'Checkout'); } $query->addUpdateValue($columns['unremovable'], $fields['unremovable']); $query->addUpdateValue($columns['visible'], $fields['visible']); $query->addUpdateValue($columns['required'], $fields['required']); $query->WhereValue($columns['variant_id'], DB_EQ, $variant_id); $query->WhereAnd(); $query->WhereValue($columns['attribute_id'], DB_EQ, $attribute_id); $application->db->getDB_Result($query); // Correct the State field visibility if the Country field vsibility is changed if ($attribute_id == 9) { $country_visible = $fields['visible']; $states_attribute_id = 7; // get the State attribute state $query = new DB_Select(); $query->addSelectField($columns['visible'], 'visible'); $query->WhereValue($columns['variant_id'], DB_EQ, $variant_id); $query->WhereAnd(); $query->WhereValue($columns['attribute_id'], DB_EQ, $states_attribute_id); // States $result = $application->db->getDB_Result($query); $state_visible = $result[0]['visible']; // If State is visible and Country is invisible, then hide State if (!$country_visible && $state_visible) { $query = new DB_Update('person_info_variants_to_attributes'); $query->addUpdateValue($columns['visible'], 0); $query->addUpdateValue($columns['required'], 0); $query->WhereValue($columns['variant_id'], DB_EQ, $variant_id); $query->WhereAnd(); $query->WhereValue($columns['attribute_id'], DB_EQ, $states_attribute_id); $application->db->getDB_Result($query); } } modApiFunc('EventsManager', 'throwEvent', 'CheckoutPersonInfoFieldUpdated', $fields); }
/** * Checks, whether an e-mail address exists in the database. * * @param string $email - email address * @param integer $uid - user id * @return true, if it exists, false otherwise */ function isEmailExists($email, $uid) { global $application; $tables = $this->getTables(); $table = 'admin'; $a = $tables[$table]['columns']; $query = new DB_Select(); $query->addSelectField($a['id'], 'id'); $query->WhereValue($a['email'], DB_EQ, $email); $query->WhereAnd(); $query->WhereValue($a['id'], DB_NEQ, $uid); $result = $application->db->getDB_Result($query); if (sizeof($result) == 0) { return false; } return true; }
/** * Reencrypts temporary data on the server. The step of replacing RSA keys. * It selects encrypted data by chunks from the database. It reencrypts it and * saves back to the temporary table. If all data are reencrypted, returns * b_finished =true in the returned array, false otherwise. * * @param string $rsa_private_key_cryptrsa_format old RSA private key, which * was used to encrypt data, stored in the DB * @param string $new_rsa_public_key_asc_format new RSA public key, which is * used to encrypt data, decrypted by the old RSA private key. */ function ReplaceRSAKeyPairStep2ReencryptTmpData($rsa_private_key_cryptrsa_format, $new_rsa_public_key_asc_format) { global $application; $new_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $new_rsa_public_key_asc_format); /** * Read out from the temporary table 500 records at a time (empirical * value). * * Reencrypt by chunks, that have the same Blowfish key, it is about * 10 database records. The decryption of one blowfish key (RSA), if no * mathematical libraries exist, can take 10 sec. * Check the timeout after each chunk - 2 sec. * If no records are left and the timeout is over, exit. * * Write what has been reencrypted to the database. */ $tmp_table_name = "order_person_data" . $this->getTmpTableSuffix(); // TableInfo only, but not data. Refer to the table using AVACTIS. $opd_tmp_info = clone_db_table_info("Checkout", "order_person_data", $tmp_table_name); $opd_tmp = $opd_tmp_info['columns']; # get Person Info data. Total record number. $query = new DB_Select(); $query->addSelectField($query->fCount('*'), 'count'); $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1"); $result = $application->db->getDB_Result($query); $n_total = $result[0]['count']; # get Person Info data. $query = new DB_Select(); $query->addSelectField($opd_tmp['id'], 'id'); $query->addSelectField($opd_tmp['value'], 'value'); $query->addSelectField($opd_tmp['encrypted_secret_key'], 'encrypted_secret_key'); $query->addSelectField($opd_tmp['rsa_public_key_asc_format'], 'rsa_public_key_asc_format'); $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1"); $query->WhereAnd(); $query->Where($opd_tmp['id'], DB_GTE, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId); $query->SelectOrder($opd_tmp['id']); $query->SelectLimit(0, 500); $_person_data = $application->db->getDB_Result($query); if (sizeof($_person_data) == 0) { //No unreencrypted data is left. The reencryption is completed. return array("error_msg" => "", "b_finished" => true, "progress_position" => 1.0); } else { $i = 0; // a number of record from order_person_data $start_time = time(); while (time() - $start_time < 2) { //Process one block with the same blowfish key. $rsa_encrypted_blowfish_key = $_person_data[$i]['encrypted_secret_key']; /* If the loaded Private key doesn't match the Public key storing in the database - output an error message. Don't rewrite anything in the database. */ $old_rsa_public_key_asc_format = $_person_data[$i]['rsa_public_key_asc_format']; $old_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $old_rsa_public_key_asc_format); if (modApiFunc("Crypto", "rsa_do_public_key_match_private_key", $old_rsa_public_key_cryptrsa_format, $rsa_private_key_cryptrsa_format) === true) { //BEGIN decrypt blowfish key. $rsa_obj = new Crypt_RSA(); $blowfish_key = $rsa_obj->decrypt($rsa_encrypted_blowfish_key, $rsa_private_key_cryptrsa_format); $new_blowfish_key = modApiFunc("Crypto", "blowfish_gen_blowfish_key"); $new_encrypted_blowfish_key = $rsa_obj->encrypt($new_blowfish_key, $new_rsa_public_key_cryptrsa_format); //END decrypt blowfish key. //Bulk INSERT will increase the rate greatly! for (; $i < sizeof($_person_data) && $_person_data[$i]['encrypted_secret_key'] == $rsa_encrypted_blowfish_key; $i++) { $decrypted_value = modApiFunc("Crypto", "blowfish_decrypt", base64_decode($_person_data[$i]['value']), $blowfish_key); //Store decrypted data: $query = new DB_Update($tmp_table_name); $query->addUpdateValue($opd_tmp['value'], base64_encode(modApiFunc("Crypto", "blowfish_encrypt", $decrypted_value, $new_blowfish_key))); $query->addUpdateValue($opd_tmp['encrypted_secret_key'], $new_encrypted_blowfish_key); $query->addUpdateValue($opd_tmp['rsa_public_key_asc_format'], $new_rsa_public_key_asc_format); $query->WhereValue($opd_tmp['id'], DB_EQ, $_person_data[$i]['id']); $application->db->getDB_Result($query); $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId = $_person_data[$i]['id'] + 1; $this->saveState(); //Don't lose reencrypted data and save correct number //of the last processed record. Otherwise the timeout can occur during the //SQL query and data in the session will be incorrect. } if ($i >= sizeof($_person_data)) { break; } } else { //Report an error: keys don't match. $MessageResources =& $application->getInstance('MessageResources'); $msg = $MessageResources->getMessage('CRYPTO_RSA_PUBLIC_PRIVATE_KEYS_MISMATCH_DECRYPT_ERROR'); return array("error_msg" => $msg, "b_finished" => false, "progress_position" => 0.0); } } # get Person Info data. Total record count. $query = new DB_Select(); $query->addSelectField($query->fCount('*'), 'count'); $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1"); $query->WhereAnd(); $query->Where($opd_tmp['id'], DB_LT, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId); $result = $application->db->getDB_Result($query); $n_done = $result[0]['count']; return array("error_msg" => "", "b_finished" => false, "progress_position" => 1.0 * $n_done / $n_total); } }
/** * * * @param * @return */ function decrypt($name, $encrypted_string) { if (!$name && !$encrypted_string) { return $encrypted_string; } global $application; $session_id = session_id(); $tables = $this->getTables(); $table = 'crypto_keys'; $k = $tables[$table]['columns']; $query = new DB_Select(); $query->addSelectField($k["key"], "crypto_key"); $query->WhereValue($k["id"], DB_EQ, $session_id); $query->WhereAnd(); $query->WhereValue($k["name"], DB_EQ, $name); $result = $application->db->getDB_Result($query); if (isset($result[0]['crypto_key']) && $result[0]['crypto_key']) { $key = $result[0]['crypto_key']; $query = new DB_Delete($table); $query->WhereValue($k["id"], DB_EQ, $session_id); $query->WhereAnd(); $query->WhereValue($k["name"], DB_EQ, $name); $application->db->getDB_Result($query); $blowfish = new Crypt_Blowfish($key); $blowfish->setKey($key); $string = $blowfish->decrypt($encrypted_string); } else { return ""; } return $string; }
function getOrderCoupons($order_id = NULL, $coupon_id = NULL) { global $application; $tables = $this->getTables(); $tr = $tables['order_promo_codes']['columns']; $result_array = array(); $query = new DB_Select(); $query->addSelectField($tr["order_id"], "order_id"); $query->addSelectField($tr["coupon_id"], "coupon_id"); $query->addSelectField($tr["coupon_promo_code"], "coupon_promo_code"); $query->WhereValue('', '', '1'); if ($order_id !== NULL) { $query->WhereAnd(); $query->WhereValue($tr["order_id"], DB_EQ, $order_id); } if ($coupon_id !== NULL) { $query->WhereAND(); $query->WhereValue($tr["coupon_id"], DB_EQ, $coupon_id); } $result_rows = $application->db->getDB_Result($query); return $result_rows; }
/** * Gets a list of available info block tags by all actions. * *@param array $actionsList - a list of all actions * *@return array - a list of tags associated with actions */ function getAvailableTagsList($actionsList) { global $application; $tables = $this->getTables(); $i2a = $tables['infotags_to_action']['columns']; $ni = $tables['notification_infotags']['columns']; $b2a = $tables['blocktags_to_action']['columns']; $nb = $tables['notification_blocktags']['columns']; $i2b = $tables['infotags_to_blocktag']['columns']; $tagsList = array(); foreach ($actionsList as $actionInfo) { $tagsList[$actionInfo['Id']] = array(); $query = new DB_Select(); $query->addSelectField($ni['id'], 'Id'); $query->addSelectField($ni['name'], 'InfoTag'); $query->WhereField($ni['id'], DB_EQ, $i2a["ni_id"]); $query->WhereAnd(); $query->WhereValue($i2a['na_id'], DB_EQ, $actionInfo['Id']); $result = $application->db->getDB_Result($query); $InfoTags = array(); foreach ($result as $InfoTag) { $InfoTags[$InfoTag['Id']] = $InfoTag['InfoTag']; } $tagsList[$actionInfo['Id']]['InfoTags'] = $InfoTags; $query = new DB_Select(); $query->addSelectField($nb['id'], 'Id'); $query->addSelectField($nb['name'], 'BlockTag'); $query->WhereField($nb['id'], DB_EQ, $b2a["nb_id"]); $query->WhereAnd(); $query->WhereValue($b2a['na_id'], DB_EQ, $actionInfo['Id']); $result = $application->db->getDB_Result($query); $tagsList[$actionInfo['Id']]['BlockTags'] = array(); foreach ($result as $BlockTag) { $query = new DB_Select(); $query->addSelectField($ni['id'], 'Id'); $query->addSelectField($ni['name'], 'InfoTag'); $query->WhereField($ni['id'], DB_EQ, $i2b["ni_id"]); $query->WhereAnd(); $query->WhereValue($i2b['nb_id'], DB_EQ, $BlockTag['Id']); $_result = $application->db->getDB_Result($query); $InfoTags = array(); foreach ($_result as $InfoTag) { $InfoTags[$InfoTag['Id']] = $InfoTag['InfoTag']; } $tagsList[$actionInfo['Id']]['BlockTags'][$BlockTag['Id']] = array("BlockTag" => $BlockTag['BlockTag'], "BlockInfoTags" => $InfoTags); } } return $tagsList; }
/** * Returns a tax formulas/rates list for given country, state and * tax class. * Warning: the entries from * state_id = STATE_ID_ALL * and * tax_class_id = TAX_CLASS_ID_ANY * will be returned independently of $state_id and $tax_class_id. */ function getTaxRatesList($country_id = -1, $state_id = -1, $tax_class_id = -1, $tax_name_id = -1) { global $application; $tables = $this->getTables(); $tr = $tables['tax_rates']['columns']; $ptc = $tables['product_tax_classes']['columns']; $tn = $tables['tax_names']['columns']; $query = new DB_Select(); $query->addSelectField($tr['id'], 'Id'); $query->addSelectField($tr['c_id'], 'c_id'); $query->addSelectField($tr['s_id'], 's_id'); $query->addSelectField($ptc['name'], 'ProductTaxClass'); $query->addSelectField($ptc['id'], 'tax_class_id'); $query->addLeftJoin('product_tax_classes', $ptc['id'], DB_EQ, $tr['ptc_id']); $query->addLeftJoin('tax_names', $tn['id'], DB_EQ, $tr['tn_id']); $query->setMultiLangAlias('_name', 'tax_names', $tn['name'], $tn['id'], 'Taxes'); $query->addSelectField($query->getMultiLangAlias('_name'), 'TaxName'); $query->addSelectField($tn['id'], 'tax_name_id'); $query->addSelectField($tr['rate'], 'Rate'); $query->addSelectField($tr['formula'], 'Formula'); $query->addSelectField($tr['applicable'], 'Applicable'); $query->addSelectField($tr['rates_set'], 'rates_set'); $query->WhereValue('', '', '1'); if ($country_id != -1 && $country_id != TAXES_COUNTRY_NOT_NEEDED_ID) { $query->WhereAnd(); $query->addWhereOpenSection(); $query->WhereValue($tr['c_id'], DB_EQ, $country_id); $query->WhereOR(); $query->WhereValue($tr['c_id'], DB_EQ, TAXES_COUNTRY_NOT_NEEDED_ID); $query->addWhereCloseSection(); } if ($state_id != -1 && $state_id != TAXES_STATE_NOT_NEEDED_ID) { $query->WhereAnd(); $query->addWhereOpenSection(); $query->WhereValue($tr['s_id'], DB_EQ, $state_id); $query->WhereOR(); $query->WhereValue($tr['s_id'], DB_EQ, STATE_ID_ALL); $query->WhereOR(); $query->WhereValue($tr['s_id'], DB_EQ, TAXES_STATE_NOT_NEEDED_ID); $query->addWhereCloseSection(); } if ($tax_class_id != -1) { $query->WhereAnd(); $query->addWhereOpenSection(); $query->WhereValue($tr['ptc_id'], DB_EQ, $tax_class_id); $query->WhereOR(); $query->WhereValue($tr['ptc_id'], DB_EQ, TAX_CLASS_ID_ANY); $query->addWhereCloseSection(); } if ($tax_name_id != -1) { $query->WhereAnd(); $query->WhereValue($tr['tn_id'], DB_EQ, $tax_name_id); } return $application->db->getDB_Result($query); }
function __loadOrdersSummary() { if (!$this->search_completed or empty($this->orders_ids)) { return; } // : // , // main_store_currency . // main_store_currency, // . // main_store_currency. global $application; $co_tables = modApiStaticFunc('Checkout', 'getTables'); $orders_table = $co_tables['orders']['columns']; $order_prices_table = $co_tables['order_prices']['columns']; $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($order_prices_table['order_total'], 'order_total'); $query->addSelectField($orders_table['payment_status_id'], 'payment_status_id'); $query->addSelectField($order_prices_table['currency_code'], 'currency_code'); $query->WhereValue($order_prices_table['currency_type'], DB_EQ, CURRENCY_TYPE_MAIN_STORE_CURRENCY); $query->WhereAnd(); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $query->addLeftJoin('order_prices', $orders_table['id'], DB_EQ, $order_prices_table['order_id']); $rows = $application->db->getDB_Result($query); $amount = 0.0; $fully_paid_amount = 0.0; $main_store_currency = modApiFunc("Localization", "getCurrencyCodeById", modApiFunc("Localization", "getMainStoreCurrency")); foreach ($rows as $order_info) { $order_main_currency = $order_info['currency_code']; $order_total = $order_info['order_total']; if ($order_main_currency != $main_store_currency) { $order_total = modApiFunc('Currency_Converter', 'convert', $order_total, $order_main_currency, $main_store_currency); } $amount += $order_total; if ($order_info['payment_status_id'] == ORDER_PAYMENT_STATUS_FULLY_PAID) { $fully_paid_amount += $order_total; } } $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($query->fMax($orders_table['date']), 'max_date'); $query->addSelectField($query->fMin($orders_table['date']), 'min_date'); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $res = $application->db->getDB_Result($query); $this->orders_summary = array('amount' => $amount, 'max_date' => $res[0]['max_date'], 'min_date' => $res[0]['min_date'], 'fully_paid_amount' => $fully_paid_amount); }
/** * Gets a blocktag body. * *@param integer $b_id - id blocktag-a */ function getNotificationBlockBody($b_id) { $body = ""; global $application; $tables = Notifications::getTables(); $nbb = $tables['notification_blocktag_bodies']['columns']; $query = new DB_Select(); $query->setMultiLangAlias('_ml_ntfctn_body', 'notification_blocktag_bodies', $nbb['body'], $nbb['id'], 'Notifications'); $query->addSelectField($query->getMultiLangAlias('_ml_ntfctn_body'), 'Body'); $query->WhereValue($nbb['n_id'], DB_EQ, $this->notificationId); $query->WhereAnd(); $query->WhereValue($nbb['nb_id'], DB_EQ, $b_id); $result = $application->db->getDB_Result($query); if (sizeof($result) != 0) { $body = $result[0]['Body']; } return $body; }