Пример #1
0
 public function RunSQL($data)
 {
     $db = new ADB($data['db_driver'], $data['db_host'], $data['db_user'], $data['db_password'], $data['db_name']);
     $file = DIR_APP_SECTION . 'abantecart_database.sql';
     if ($sql = file($file)) {
         $query = '';
         foreach ($sql as $line) {
             $tsl = trim($line);
             if ($sql != '' && substr($tsl, 0, 2) != "--" && substr($tsl, 0, 1) != '#') {
                 $query .= $line;
                 if (preg_match('/;\\s*$/', $line)) {
                     $query = str_replace("DROP TABLE IF EXISTS `ac_", "DROP TABLE IF EXISTS `" . $data['db_prefix'], $query);
                     $query = str_replace("CREATE TABLE `ac_", "CREATE TABLE `" . $data['db_prefix'], $query);
                     $query = str_replace("INSERT INTO `ac_", "INSERT INTO `" . $data['db_prefix'], $query);
                     $query = str_replace("ON `ac_", "ON `" . $data['db_prefix'], $query);
                     $db->query($query);
                     //no silence mode! if error - will throw to exception
                     $query = '';
                 }
             }
         }
         $db->query("SET CHARACTER SET utf8;");
         $db->query("SET @@session.sql_mode = 'MYSQL40';");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "users`\n\t\t\t\tSET user_id = '1',\n\t\t\t\t\tuser_group_id = '1',\n\t\t\t\t\temail = '" . $db->escape($data['email']) . "',\n\t\t\t\t    username = '******'username']) . "',\n\t\t\t\t    password = '******'password'])) . "',\n\t\t\t\t    status = '1',\n\t\t\t\t    date_added = NOW();");
         $db->query("UPDATE `" . $data['db_prefix'] . "settings` SET value = '" . $db->escape($data['email']) . "' WHERE `key` = 'store_main_email'; ");
         $db->query("UPDATE `" . $data['db_prefix'] . "settings` SET value = '" . $db->escape(HTTP_ABANTECART) . "' WHERE `key` = 'config_url'; ");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "settings` SET `group` = 'config', `key` = 'install_date', value = NOW(); ");
         $db->query("UPDATE `" . $data['db_prefix'] . "products` SET `viewed` = '0';");
         //process triggers
         //$this->create_triggers($db, $data['db_name']);
         //run descructor and close db-connection
         unset($db);
     }
     //clear cache dir in case of reinstall
     $cache = new ACache();
     $cache->remove('*');
 }
Пример #2
0
 /**
  * Get available tax classes for country ID and zone ID
  * Storefront use only!!!
  * @param $country_id
  * @param $zone_id
  * @return mixed|null
  */
 public function getTaxes($country_id, $zone_id)
 {
     $country_id = (int) $country_id;
     $zone_id = (int) $zone_id;
     $language = $this->registry->get('language');
     $language_id = $language->getLanguageID();
     $cache_name = 'tax_class.' . $country_id . '.' . $zone_id;
     $results = $this->cache->get($cache_name, $language_id);
     if (is_null($results)) {
         //Note: Default language text is picked up if no selected language available
         $sql = "SELECT tr.tax_class_id,\n\t\t\t\t\t\t\ttr.rate AS rate, tr.rate_prefix AS rate_prefix, \n\t\t\t\t\t\t\ttr.threshold_condition AS threshold_condition, tr.threshold AS threshold,\n\t\t\t\t\t\t\tCOALESCE( td1.title,td2.title) as title,\n\t\t\t\t\t\t\tCOALESCE( NULLIF(trd1.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(td1.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(trd2.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(td2.description, ''),\n\t\t\t\t\t\t\t\t\t  COALESCE( td1.title,td2.title)\n\t\t\t\t\t\t\t) as description,\n\t\t\t\t\t\t\ttr.priority\t\n\t\t\t\t\tFROM " . $this->db->table("tax_rates") . " tr\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_rate_descriptions") . " trd1 ON \n\t\t\t\t\t\t(tr.tax_rate_id = trd1.tax_rate_id AND trd1.language_id = '" . (int) $language_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_rate_descriptions") . " trd2 ON \n\t\t\t\t\t\t(tr.tax_rate_id = trd2.tax_rate_id AND trd2.language_id = '" . (int) $default_lang_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_classes") . " tc ON tc.tax_class_id = tr.tax_class_id\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_class_descriptions") . " td1 ON \n\t\t\t\t\t\t(tc.tax_class_id = td1.tax_class_id AND td1.language_id = '" . (int) $language_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_class_descriptions") . " td2 ON \n\t\t\t\t\t\t(tc.tax_class_id = td2.tax_class_id AND td2.language_id = '" . (int) $default_lang_id . "')\n\t\t\t\t\tWHERE (tr.zone_id = '0' OR tr.zone_id = '" . $zone_id . "')\n\t\t\t\t\t\tAND tr.location_id in (SELECT z2l.location_id\n\t\t\t\t\t\t\t\t\t\t\t   FROM " . $this->db->table("zones_to_locations") . " z2l, " . $this->db->table("locations") . " l\n\t\t\t\t\t\t\t\t\t\t\t   WHERE z2l.location_id = l.location_id and z2l.zone_id = '" . $zone_id . "')\n\t\t\t\t\tORDER BY tr.priority ASC";
         $tax_rate_query = $this->db->query($sql);
         $results = $tax_rate_query->rows;
         $this->cache->set($cache_name, $results, $language_id);
     }
     return $results;
 }
Пример #3
0
 /**
  * @param array $data
  */
 protected function _write_missing_definition($data)
 {
     $update_data = array();
     if ($this->is_admin) {
         $this->loader->model('localisation/language_definitions');
         $model = $this->registry->get('model_localisation_language_definitions');
         $model->addLanguageDefinition($data);
     } else {
         foreach ($data as $key => $val) {
             $update_data[$this->db->escape($key)] = $this->db->escape($val);
         }
         if (!$this->_is_definition_in_db($update_data)) {
             $sql = "INSERT INTO " . DB_PREFIX . "language_definitions\n                                (`" . implode("`, `", array_keys($update_data)) . "`)\n                                VALUES ('" . implode("', '", $update_data) . "') ";
             $this->db->query($sql);
             $this->cache->remove('localization');
             $this->cache->remove('storefront_menu');
         }
     }
     if ($this->registry->get('config')->get('warn_lang_text_missing')) {
         $this->registry->get('messages')->saveNotice('Missing language definition "' . $data['language_key'] . '" was loaded for "' . $this->available_languages[$this->code]['name'] . '" language', 'Missing language definition with key "' . $data['language_key'] . '" for block "' . $data['block'] . '" was automatically added. Please check this at #admin#rt=localisation/language_definitions to see or change value.');
     }
 }
 /**
  * @param string $type
  * @param array $tr_details - amount, order_id, transaction_type, description, comments, creator
  * @return bool
  */
 private function _record_transaction($type, $tr_details)
 {
     if (!$this->isLogged()) {
         return false;
     }
     if (!has_value($tr_details['transaction_type']) || !has_value($tr_details['created_by'])) {
         return false;
     }
     if ($type == 'debit') {
         $amount = 'debit = ' . (double) $tr_details['amount'];
     } else {
         if ($type == 'credit') {
             $amount = 'credit = ' . (double) $tr_details['amount'];
         } else {
             return false;
         }
     }
     $this->db->query("INSERT INTO " . $this->db->table("customer_transactions") . "\n      \t                SET customer_id \t\t= '" . (int) $this->getId() . "',\n      \t                \torder_id \t\t\t= '" . (int) $tr_details['order_id'] . "',\n      \t                    transaction_type \t= '" . $this->db->escape($tr_details['transaction_type']) . "',\n      \t                    description \t\t= '" . $this->db->escape($tr_details['description']) . "',\n      \t                    comment \t\t\t= '" . $this->db->escape($tr_details['comment']) . "',\n\t\t\t\t\t\t\t" . $amount . ",\n\t\t\t\t\t\t\tsection\t\t\t\t= '" . ((int) $tr_details['section'] ? (int) $tr_details['section'] : 0) . "',\n      \t                    created_by \t\t\t= '" . (int) $tr_details['created_by'] . "',\n      \t                    date_added = NOW()");
     $this->cache->delete('balance.' . (int) $this->getId());
     if ($this->db->getLastId()) {
         return true;
     }
     return false;
 }
Пример #5
0
 public function _load_demo_data()
 {
     $reg = $this->_prepare_registry();
     $db = $reg->get('db');
     $db->query("SET NAMES 'utf8'");
     $db->query("SET CHARACTER SET utf8");
     $file = DIR_APP_SECTION . 'abantecart_sample_data.sql';
     if ($sql = file($file)) {
         $query = '';
         foreach ($sql as $line) {
             $tsl = trim($line);
             if ($sql != '' && substr($tsl, 0, 2) != "--" && substr($tsl, 0, 1) != '#') {
                 $query .= $line;
                 if (preg_match('/;\\s*$/', $line)) {
                     $query = str_replace("DROP TABLE IF EXISTS `ac_", "DROP TABLE IF EXISTS `" . DB_PREFIX, $query);
                     $query = str_replace("CREATE TABLE `ac_", "CREATE TABLE `" . DB_PREFIX, $query);
                     $query = str_replace("INSERT INTO `ac_", "INSERT INTO `" . DB_PREFIX, $query);
                     $result = $db->query($query);
                     if (!$result || $db->error) {
                         die($db->error . '<br>' . $query);
                     }
                     $query = '';
                 }
             }
         }
         $db->query("SET CHARACTER SET utf8");
         $db->query("SET @@session.sql_mode = 'MYSQL40'");
     }
     //clear earlier created cache by AConfig and ALanguage classes in previous step
     $cache = new ACache();
     $cache->delete('*');
     return null;
 }