예제 #1
0
 function getSettings()
 {
     global $application;
     $tables = $this->getTables();
     $query = new DB_Select();
     $query->addSelectTable('frg_settings');
     $query->addSelectField('*');
     $res = $application->db->getDB_Result($query);
     $settings = array();
     foreach ($res as $k => $sval) {
         $settings[$sval['setting_key']] = $sval['setting_value'];
     }
     return $settings;
 }
예제 #2
0
 /**
  * This function calculates hash from checkout form fields array.
  * @author Andrei V. Zhuravlev
  *
  */
 function updateCheckoutFormHash()
 {
     global $application;
     $tables = $this->getTables();
     $pa = $tables['person_attributes']['columns'];
     $piva = $tables['person_info_variants_to_attributes']['columns'];
     $s = new DB_Select();
     $s->addSelectTable('person_attributes');
     $s->addSelectTable('person_info_variants_to_attributes');
     $s->WhereField($piva['attribute_id'], DB_EQ, $pa['id']);
     $checkout_data = $application->db->getDB_Result($s);
     //query fields
     $hash = md5(serialize($checkout_data));
     /*$tables = Configuration::getTables();
             $ss = $tables['store_settings']['columns'];
     
             $u = new DB_Update('store_settings');
             $u->addUpdateValue('variable_value',$hash);
             $u->WhereValue('variable_name', DB_EQ, SYSCONFIG_CHECKOUT_FORM_HASH);
             $application->db->getDB_Result($u);*/
     $cache = CCacheFactory::getCache('hash');
     $cache->write(SYSCONFIG_CHECKOUT_FORM_HASH, $hash);
     return $hash;
 }
 function getSubscribedTopics($email, $signed_id = null, $active_only = false)
 {
     global $application;
     $tables = $this->getTables();
     $ttable = 'subscription_topic';
     $tcolumns =& $tables[$ttable]['columns'];
     $etable = 'subscription_email';
     $ecolumns =& $tables[$etable]['columns'];
     $atable = 'email_address';
     $acolumns =& $tables[$atable]['columns'];
     $query = new DB_Select();
     $query->addSelectTable($ttable);
     $query->addSelectField($tcolumns['topic_id']);
     $query->SelectGroup($tcolumns['topic_id']);
     $query->addInnerJoin($etable, $ecolumns['topic_id'], DB_EQ, $tcolumns['topic_id']);
     if (is_numeric($email)) {
         $query->WhereValue($ecolumns['email_id'], DB_EQ, $email);
     } else {
         $query->addInnerJoin($atable, $acolumns['email_id'], DB_EQ, $ecolumns['email_id']);
         $query->WhereValue($acolumns['email'], DB_EQ, $email);
     }
     if (isset($signed_in)) {
         $query->WhereAND();
         $access = array(SUBSCRIPTION_TOPIC_FULL_ACCESS, $signed_id ? SUBSCRIPTION_TOPIC_REGISTERED_ONLY : SUBSCRIPTION_TOPIC_GUEST_ONLY);
         $query->Where($tcolumns['topic_access'], DB_IN, DBQuery::arrayToIn($access));
     }
     if ($active_only) {
         $query->WhereAND();
         $query->WhereValue($tcolumns['topic_status'], DB_EQ, SUBSCRIPTION_TOPIC_ACTIVE);
     }
     $res = $application->db->getDB_Result($query);
     $ids = array();
     foreach ($res as $r) {
         $ids[$r['topic_id']] = $r['topic_id'];
     }
     return $ids;
 }
 function __loadCOPITypesIDs()
 {
     global $application;
     loadClass('Checkout');
     $co_tables = Checkout::getTables();
     $pa_table = $co_tables['person_info_types']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('person_info_types');
     $query->addSelectField($pa_table['id'], 'type_id');
     $query->addSelectField($pa_table['tag'], 'type_tag');
     $res = $application->db->getDB_Result($query);
     foreach ($res as $k => $pa_info) {
         $this->_co_pi_types_ids[_ml_strtolower(str_replace('Info', '', $pa_info['type_tag']))] = $pa_info['type_id'];
     }
 }
 /**
  * Gets settings.
  *
  * @return array of the settings
  */
 function getSettings()
 {
     global $application;
     if (!isset($this->settings)) {
         $tables = $this->getTables();
         $columns = $tables['scc_settings']['columns'];
         $query = new DB_Select();
         $query->addSelectTable('scc_settings');
         $query->addSelectField($columns['key']);
         $query->addSelectField($columns['value']);
         $result = $application->db->getDB_Result($query);
         $settings = array();
         foreach ($result as $k => $v) {
             $settings[$v['scc_settings_key']] = $v['scc_settings_value'];
         }
         $this->settings = $settings;
     }
     return $this->settings;
 }
 function getPromoCodesNumber()
 {
     global $application;
     $query = new DB_Select();
     $query->addSelectField('COUNT(*)', 'coupons_number');
     $query->addSelectTable('promo_codes_coupons_table');
     $res = $application->db->getDB_Result($query);
     return $res[0]['coupons_number'];
 }
예제 #7
0
function getProductAttributeId($view_tag_name, $default_value = null)
{
    global $application;
    if (!is_object($application)) {
        return $default_value;
    }
    $attr_ids_cache = $application->getAttrIdsCache();
    $attr_id = $attr_ids_cache->read($view_tag_name);
    if ($attr_id == null) {
        if ($application->db->DB_isTableExists($application->getAppIni('DB_TABLE_PREFIX') . "attributes") != null) {
            $s = new DB_Select();
            $s->addSelectTable("attributes");
            $s->addSelectField('attribute_id', 'attribute_id');
            $s->WhereValue('attribute_view_tag', DB_EQ, $view_tag_name);
            $m = new DB_MySQL();
            $m->PrepareSQL($s);
            $result = $m->getDB_Result($s);
            $attr_id = !empty($result) ? $result[0]['attribute_id'] : $default_value;
        } else {
            $attr_id = $default_value;
        }
        $attr_ids_cache->write($view_tag_name, $attr_id);
    }
    return $attr_id;
}
 function __getNotificationNameById($n_id)
 {
     global $application;
     $tables = $this->getTables();
     $actions_table = $tables['notifications']['columns'];
     $query = new DB_Select();
     $query->addSelectField($actions_table['name'], 'notification_name');
     $query->addSelectTable('notifications');
     $query->WhereValue($actions_table['id'], DB_EQ, $n_id);
     $res = $application->db->getDB_Result($query);
     return $res[0]['notification_name'];
 }
 function __getMaxFPSortOrderForCategory($category_id)
 {
     global $application;
     $tables = $this->getTables();
     $fp_table = $tables['fp_links']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('fp_links');
     $query->addSelectField($query->fMax($fp_table['sort_order']), 'max_so');
     $query->WhereValue($fp_table['category_id'], DB_EQ, $category_id);
     $res = $application->db->getDB_Result($query);
     if (count($res) == 1) {
         return $res[0]['max_so'];
     } else {
         return 0;
     }
 }
 function getPaymentModulesListPrepared()
 {
     global $application;
     if (!empty($this->ModulesList)) {
         return $this->ModulesList;
     }
     $modules = $this->getInstalledModulesListData();
     $PaymentModulesGroupsInfo = modApiFunc("Checkout", "getPaymentModulesGroupsInfo");
     foreach ($modules as $module) {
         $name = _ml_strtolower($module->name);
         // include $table; $uid;
         include $application->getAppIni("PATH_ASC_ROOT") . $module->directory . "/includes/uid.php";
         if (isset($table)) {
             $query = new DB_Select();
             $query->addSelectTable($table);
             $fields = $application->db->getDB_Result($query);
             $module_label = '';
             foreach ($fields as $row) {
                 $i = 0;
                 $list = array();
                 foreach ($row as $field) {
                     $list[$i] = $field;
                     $i++;
                 }
                 if ($list[1] == "MODULE_NAME") {
                     $module_label = $list[2];
                 }
             }
             $unserialized_label = @unserialize($module_label);
             if ($unserialized_label === FALSE) {
                 $unserialized_label = $module_label;
             }
         }
         $payment_group = modApiFunc("Checkout", "getPaymentModuleGroup", $module);
         if ($payment_group != "") {
             $this->ModulesList[] = array('uid' => $uid, 'module_class_name' => $module->name, 'module_label_name' => $unserialized_label, 'payment_group' => $payment_group, 'group_short_name' => $PaymentModulesGroupsInfo[$payment_group]['short_name']);
         }
     }
     return $this->ModulesList;
 }
예제 #11
0
 /**
  *
  * @author Alexandr Girin
  */
 function getTablesAndRecordsCount($count_records = true)
 {
     global $application;
     $avactis_tables = array();
     $tables = $this->getTables();
     $module_tbl = 'module';
     $module_columns = $tables[$module_tbl]['columns'];
     $module_class_tbl = 'module_class';
     $module_class_columns = $tables[$module_class_tbl]['columns'];
     $db_select = new DB_Select();
     $db_select->addSelectField($module_columns['name']);
     $modules = $application->db->getDB_Result($db_select, QUERY_RESULT_NUM);
     $total_records = 0;
     foreach ($modules as $module) {
         if (method_exists($application->getInstance($module[0]), "getTables")) {
             $tables = modApiFunc($module[0], "getTables");
             if (sizeof($tables)) {
                 foreach ($tables as $tableName => $tableInfo) {
                     if (method_exists($application->getInstance($module[0]), "getIgnoredTablesForBackup")) {
                         $ignoredTables = modApiFunc($module[0], "getIgnoredTablesForBackup");
                         //print_r($ignoredTables);
                         if (in_array($tableName, $ignoredTables)) {
                             continue;
                         }
                     }
                     if ($count_records) {
                         $query = new DB_Select();
                         $query->addSelectTable($tableName);
                         $query->addSelectField($query->fCount('*'), 'count');
                         $result = $application->db->getDB_Result($query);
                         $avactis_tables[] = array('table_name' => $application->getAppIni('DB_TABLE_PREFIX') . $tableName, 'records_count' => $result[0]['count']);
                         $total_records += $result[0]['count'];
                     } else {
                         $avactis_tables[] = $application->getAppIni('DB_TABLE_PREFIX') . $tableName;
                     }
                 }
             }
         }
     }
     if ($count_records) {
         $avactis_tables['Total_Records'] = $total_records;
     }
     return $avactis_tables;
 }
 /**
  * Reelects the default value for the option of the type 'SS'
  *
  * @param int $option_id - option ID
  * @param int $value_id - ID of the value, dominating in the reelection
  * (if it is null, no dominating value exists)
  *
  * @return true it was successfully reelected, false otherwise
  */
 function __chooseAndSetDefaultValueForOption($option_id, $value_id = 0)
 {
     global $application;
     $tables = $this->getTables();
     $values = $tables['po_options_values']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('po_options_values');
     $query->addSelectField($values['value_id'], 'value_id');
     $query->addSelectField($values['is_default'], 'is_default');
     $query->WhereValue($values['option_id'], DB_EQ, $option_id);
     $query->SelectOrder($values['sort_order'], 'ASC');
     $res = $application->db->getDB_Result($query);
     if (!is_array($res)) {
         return false;
     }
     if (!empty($res)) {
         $default_ids = array();
         foreach ($res as $k => $v) {
             if ($v['is_default'] == 'Y') {
                 $default_ids[] = $v['value_id'];
             }
         }
         if (empty($default_ids)) {
             $new_default_id = $value_id > 0 ? $value_id : $res[0]['value_id'];
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'Y');
             $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
             $application->db->PrepareSQL($query);
             return $application->db->DB_Exec();
         } elseif (count($default_ids) == 1) {
             if ($value_id > 0) {
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'N');
                 $query->WhereValue($values['value_id'], DB_EQ, $default_ids[0]);
                 $application->db->PrepareSQL($query);
                 if ($application->db->DB_Exec()) {
                     $query = new DB_Update('po_options_values');
                     $query->addUpdateValue($values['is_default'], 'Y');
                     $query->WhereValue($values['value_id'], DB_EQ, $value_id);
                     $application->db->PrepareSQL($query);
                     return $application->db->DB_Exec();
                 } else {
                     return false;
                 }
             }
             return true;
         } else {
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'N');
             $query->WhereValue($values['option_id'], DB_EQ, $option_id);
             $application->db->PrepareSQL($query);
             if ($application->db->DB_Exec()) {
                 $new_default_id = $value_id > 0 ? $value_id : $default_ids[0];
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'Y');
                 $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
                 $application->db->PrepareSQL($query);
                 return $application->db->DB_Exec();
             } else {
                 return false;
             }
         }
     }
     return true;
 }
 function getHotlinkInfoByKey($hl_key)
 {
     global $application;
     $tables = $this->getTables();
     $hl_table = $tables['pf_hotlinks']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('pf_hotlinks');
     $query->addSelectField('*');
     $query->WhereValue($hl_table['hotlink_key'], DB_EQ, $hl_key);
     $res = $application->db->getDB_Result($query);
     if (empty($res)) {
         return null;
     } else {
         return array_shift($res);
     }
 }
 function validateOrder($orderID)
 {
     if (ltrim($_GET[WebToPay::PREFIX . 'orderid'], "0") != $orderID) {
         exit('Order ID mismatch!');
     }
     global $application;
     $msg =& $application->getInstance('MessageResources', "payment-module-wtp-messages", "AdminZone");
     $moduleData = $this->getSettings();
     $query = new DB_Select();
     $query->addSelectTable('order_prices');
     $query->addSelectField('*');
     $query->WhereValue('order_id', DB_EQ, $orderID);
     $Order = $application->db->getDB_Result($query);
     try {
         WebToPay::toggleSS2(true);
         $response = WebToPay::checkResponse($_GET, array('projectid' => $moduleData['MODULE_METHOD_ID'], 'sign_password' => $moduleData['MODULE_METHOD_PASS']));
     } catch (Exception $e) {
         exit(get_class($e) . ': ' . $e->getMessage());
     }
     if (intval(number_format($Order[0]['order_total'], 2, '', '')) > $_GET[WebToPay::PREFIX . 'amount']) {
         exit('Bad amount!');
     } else {
         if ($Order[0]['currency_code'] != $_GET[WebToPay::PREFIX . 'currency']) {
             exit('Bad currency!');
         } else {
             modApiFunc("Checkout", "UpdatePaymentStatusInDB", $orderID, 2, 'Payment accepted.');
             exit('OK');
         }
     }
 }
예제 #15
0
 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);
 }
예제 #16
0
 /**
  * @param int $category_id - ID
  * @param array $period = ('begin' => timestamp, 'end' => timestamp) -
  *
  * @param int $limit -                   (
  *                          ,    STAT_NO_LIMIT)
  * @param int $what_category = STAT_CATEGORY_THIS_ONLY ||
  * STAT_CATEGORY_RECURSIVE -
  *
  * @param int $what_products = STAT_PRODUCTS_ALL ||
  * STAT_PRODUCTS_EXISTS_ONLY -                                 ,
  *
  */
 function getProductsSellingStat($category_id, $period, $limit = STAT_NO_LIMIT, $what_category = STAT_CATEGORY_THIS_ONLY, $what_products = STAT_PRODUCTS_EXISTS_ONLY)
 {
     global $application;
     $tables = $this->getTables();
     $ps_table = $tables['stat_products_sold']['columns'];
     $categories_ids = array();
     if ($what_category == STAT_CATEGORY_RECURSIVE) {
         $categories = modApiFunc('Catalog', 'getSubcategoriesFullListWithParent', $category_id, false, false);
         foreach ($categories as $cat_info) {
             $categories_ids[] = $cat_info['id'];
         }
     } else {
         $categories_ids[] = $category_id;
     }
     $query = new DB_Select();
     $query->addSelectField($ps_table['product_id'], 'product_id');
     $query->addSelectField($query->fSum($ps_table['quantity']), 'sum_quantity');
     $query->addSelectTable('stat_products_sold');
     $query->WhereValue($ps_table['categories_ids'], DB_REGEXP, '[[.vertical-line.]]' . implode('|', $categories_ids) . '[[.vertical-line.]]');
     $query->WhereAND();
     $query->Where($ps_table['time'], DB_GTE, $period['begin']);
     $query->WhereAND();
     $query->Where($ps_table['time'], DB_LTE, $period['end']);
     if ($what_products == STAT_PRODUCTS_EXISTS_ONLY) {
         $catalog_tables = modApiStaticFunc('Catalog', 'getTables');
         $query->addSelectTable('products');
         $query->WhereAND();
         $query->WhereField($ps_table['product_id'], DB_EQ, $catalog_tables['products']['columns']['id']);
     }
     $query->SelectGroup('product_id');
     $query->SelectOrder('sum_quantity', 'DESC');
     if ($limit != STAT_NO_LIMIT) {
         $query->SelectLimit(0, $limit);
     }
     return $application->db->getDB_Result($query);
 }