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->delete('*');
 }
 /**
  * @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;
 }
示例#3
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;
 }