Exemple #1
0
 public static function run()
 {
     // get site name
     $result = \DB::select('config_name', 'config_value')->from('config')->where('config_name', 'site_name')->as_object()->execute();
     $row = $result->current();
     $site_name = $row->config_value;
     unset($result, $row);
     // get domain
     if (isset($_SERVER['HTTP_HOST'])) {
         $site_domain = $_SERVER['HTTP_HOST'];
     } elseif (isset($_SERVER['SERVER_NAME'])) {
         $site_domain = $_SERVER['SERVER_NAME'];
     } else {
         $site_domain = 'localhost';
     }
     $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('sites') . "` (\n            `site_id` int(11) NOT NULL AUTO_INCREMENT,\n            `site_name` varchar(255) DEFAULT NULL,\n            `site_domain` varchar(255) DEFAULT NULL COMMENT 'ex. domain.com, sub.domain.com with out http://',\n            `site_status` int(1) NOT NULL DEFAULT '0' COMMENT '0=disable, 1=enable',\n            `site_create` bigint(20) DEFAULT NULL,\n            `site_create_gmt` bigint(20) DEFAULT NULL,\n            `site_update` bigint(20) DEFAULT NULL,\n            `site_update_gmt` bigint(20) DEFAULT NULL,\n            PRIMARY KEY (`site_id`)\n        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;";
     \DB::query($sql)->execute();
     // check if table already created before insert.
     $result = \DB::count_records('sites');
     if ($result <= 0) {
         $sql = "INSERT INTO `" . \DB::table_prefix('sites') . "` (`site_id`, `site_name`, `site_domain`, `site_status`, `site_create`, `site_create_gmt`, `site_update`, `site_update_gmt`) VALUES\n            (1, '" . $site_name . "', '" . $site_domain . "', 1, " . time() . ", " . \Extension\Date::localToGmt() . ", " . time() . ", " . \Extension\Date::localToGmt() . ");";
         \DB::query($sql)->execute();
     }
     unset($sql);
     return true;
 }
Exemple #2
0
    /**
     * 获取指定分类ID的子类ID集
     * 
     * @param $cid 待查询的分类ID
     * @return Array 所有子类ID
     */
    public static function getChildIds($cid)
    {
        $t_category = DB::table_prefix('categories');
        $sql = <<<sql_statment
SELECT c.id FROM {$t_category} AS c,(SELECT tree, depth, lft, rgt FROM {$t_category} WHERE id = {$cid}) AS m
 WHERE c.tree = m.tree AND c.depth > m.depth AND c.lft > m.lft AND c.rgt < m.rgt
sql_statment;
        return DB::query($sql)->execute()->as_array();
    }
Exemple #3
0
 public function action_install()
 {
     $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('blog') . "` (\n\t\t\t`post_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`post_name` varchar(255) DEFAULT NULL,\n\t\t\t`post_body` longtext,\n\t\t\t`post_date` bigint(20) DEFAULT NULL,\n\t\t\tPRIMARY KEY (`post_id`)\n\t\t  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
     \DB::query($sql)->execute();
     $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('blog_comment') . "` (\n\t\t\t`comment_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`post_id` int(11) DEFAULT NULL,\n\t\t\t`comment_name` varchar(255) DEFAULT NULL,\n\t\t\t`comment_body` text,\n\t\t\t`comment_date` bigint(20) DEFAULT NULL,\n\t\t\tPRIMARY KEY (`comment_id`)\n\t\t  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
     \DB::query($sql)->execute();
     unset($sql);
     echo 'Install db tables for blog module completed.';
 }
Exemple #4
0
 public static function run()
 {
     // create permission table. (user's permission)
     $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('account_permission') . "` (\n            `permission_id` int(11) NOT NULL AUTO_INCREMENT,\n            `account_id` int(11) NOT NULL COMMENT 'refer to accounts.account_id',\n            `permission_core` int(1) NOT NULL DEFAULT '0' COMMENT '1=core permission, 0=modules permission',\n            `module_system_name` varchar(255) DEFAULT NULL COMMENT 'module system name',\n            `permission_page` varchar(255) NOT NULL,\n            `permission_action` varchar(255) DEFAULT NULL,\n            PRIMARY KEY (`permission_id`),\n            KEY `account_id` (`account_id`)\n        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='contain user''s permission for each admin page and action.' AUTO_INCREMENT=1 ;";
     \DB::query($sql)->execute();
     unset($sql);
     // loop sites to create permission table.
     $sites = \Model_Sites::find('all');
     if ($sites != null) {
         foreach ($sites as $row) {
             $table_name = 'account_permission';
             if ($row->site_id != '1') {
                 $table_name = $row->site_id . '_' . $table_name;
             }
             if (!\DBUtil::table_exists($table_name)) {
                 $sql = 'CREATE TABLE IF NOT EXISTS ' . \DB::table_prefix($table_name) . ' LIKE ' . \DB::table_prefix('account_permission');
                 \DB::query($sql)->execute();
                 unset($sql);
             }
         }
     }
     unset($row, $sites);
     return true;
 }
Exemple #5
0
 /**
  * Set a table prefix for the quick_ functions
  * If it's set to blank (default), then no prefix will be used
  *
  * @param unknown_type $prefix
  */
 public static function set_table_prefix($prefix)
 {
     self::$table_prefix = '';
 }
Exemple #6
0
 protected static function table_maintenance($operation, $table, $db = null)
 {
     $result = \DB::query($operation . ' ' . \DB::quote_identifier(\DB::table_prefix($table, $db ? $db : static::$connection), $db ? $db : static::$connection), \DB::SELECT)->execute($db ? $db : static::$connection);
     $type = $result->get('Msg_type');
     $message = $result->get('Msg_text');
     $table = $result->get('Table');
     if ($type === 'status' and in_array(strtolower($message), array('ok', 'table is already up to date'))) {
         return true;
     }
     if ($type === 'error') {
         logger(\Fuel::L_ERROR, 'Table: ' . $table . ', Operation: ' . $operation . ', Message: ' . $result->get('Msg_text'), 'DBUtil::table_maintenance');
     } else {
         logger(ucfirst($type), 'Table: ' . $table . ', Operation: ' . $operation . ', Message: ' . $result->get('Msg_text'), 'DBUtil::table_maintenance');
     }
     return false;
 }
 protected static function table_maintenance($operation, $table, $db = null)
 {
     $result = \DB::query($operation . ' ' . \DB::quote_identifier(\DB::table_prefix($table, $db ? $db : static::$connection), $db ? $db : static::$connection), \DB::SELECT)->execute($db ? $db : static::$connection);
     $type = $result->get('Msg_type');
     $message = $result->get('Msg_text');
     $table = $result->get('Table');
     if ($type === 'status' and in_array(strtolower($message), array('ok', 'table is already up to date'))) {
         return true;
     }
     // make sure we have a type logger can handle
     if (in_array($type, array('info', 'warning', 'error'))) {
         $type = strtoupper($type);
     } else {
         $type = \Fuel::L_INFO;
     }
     logger($type, 'Table: ' . $table . ', Operation: ' . $operation . ', Message: ' . $result->get('Msg_text'), 'DBUtil::table_maintenance');
     return false;
 }
Exemple #8
0
if (Debug::$debug_enabled == true) {
    ini_set('log_errors', 'On');
    ini_set('display_errors', 'Off');
    ini_set('error_log', LOGS_PATH . '/errors.txt');
}
/* Init caching engine */
CodonCache::init($cache_settings);
if (DBASE_NAME != '' && DBASE_SERVER != '' && DBASE_NAME != 'DBASE_NAME') {
    require CLASS_PATH . DS . 'ezdb/ezdb.class.php';
    DB::$show_errors = Config::Get('DEBUG_MODE');
    DB::$throw_exceptions = false;
    DB::init(DBASE_TYPE);
    DB::set_log_errors(Config::Get('DEBUG_MODE'));
    DB::set_error_handler(array('Debug', 'db_error'));
    DB::set_caching(false);
    DB::$table_prefix = TABLE_PREFIX;
    DB::set_cache_dir(CACHE_PATH);
    DB::$DB->debug_all = false;
    if (Config::Get('DEBUG_MODE') == true) {
        DB::show_errors();
    } else {
        DB::hide_errors();
    }
    if (!DB::connect(DBASE_USER, DBASE_PASS, DBASE_NAME, DBASE_SERVER)) {
        Debug::showCritical(Lang::gs('database.connection.failed') . ' (' . DB::$errno . ': ' . DB::$error . ')');
        die;
    }
    # Set the charset type to send to mysql
    if (Config::Get('DB_CHARSET_NAME') !== '') {
        DB::query('SET NAMES \'' . Config::Get('DB_CHARSET_NAME') . '\'');
    }
Exemple #9
0
 /**
  * Generate model for a database table.
  *
  * Usage (from command line):
  *
  * php oil refine fromdb:model <table_name,table_name...>
  */
 public static function model($tables = '')
 {
     // do we have any tables defined?
     if (empty($tables)) {
         // do we want to generate for all tables?
         if (!\Cli::option('all', false)) {
             \Cli::write('No table names specified to generate a model on.', 'red');
             exit;
         }
         // get the list of all available tables
         try {
             $list = \DB::list_tables(null, \Cli::option('db', null));
         } catch (\FuelException $e) {
             \Cli::write('The database driver configured does not support listing tables. Please specify them manually.', 'red');
             exit;
         }
         $prefix = \DB::table_prefix();
         $migration = \Config::get('migrations.table', 'migration');
         $tables = array();
         // create the table list
         foreach ($list as $table) {
             // strip any defined table prefix from the table name
             if (!empty($prefix) and strpos($table, $prefix) === 0) {
                 $table = substr($table, strlen($prefix));
             }
             // skip the migration table
             $table == $migration or $tables[] = $table;
         }
     }
     // make sure we have an array to work with
     is_array($tables) or $tables = explode(',', $tables);
     // generate for each table defined
     foreach ($tables as $table) {
         // start with an empty list
         \Oil\Generate::$create_files = array();
         // and generate
         call_user_func('Oil\\Generate::model', static::arguments($table));
     }
 }
Exemple #10
0
 public function profilable($new = false)
 {
     $delete = \Cli::option('R', false) || \Cli::option('remove', false);
     if ($delete) {
         \DBUtil::drop_table('profiles');
         \Cli::write(\Cli::color('Dropped profiles table successfully', 'green'));
     } else {
         \DBUtil::create_table('profiles', array('id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true, 'auto_increment' => true), 'user_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true)), array('id'), false, 'InnoDB', 'utf8_unicode_ci');
         \DB::query("ALTER TABLE " . \DB::table_prefix('profiles') . "\n                            ADD KEY index_profiles_on_user_id(user_id),\n                            ADD CONSTRAINT fk_index_profiles_on_user_id\n                                FOREIGN KEY (user_id)\n                                REFERENCES " . \DB::table_prefix('users') . " (id) ON DELETE CASCADE", \DB::UPDATE)->execute();
         \Cli::write(\Cli::color('Created profiles table successfully', 'green'));
     }
     if (!$new) {
         \Config::set('warden.profilable', $delete ? false : true);
         $this->_save_config();
     }
 }
 public function create_user()
 {
     // Get groups
     $groups = \Sentry::group()->all('front');
     if (\Input::post()) {
         // Get POST values
         $insert = \Input::post();
         $register_type = 'register';
         if (\Input::post('register')) {
             $register_type = $insert['register'];
         }
         $ship_to = 'billing';
         if ($insert['ship'] == 'other') {
             $ship_to = 'shipping';
         }
         $val = \User\Controller_Validate::forge($register_type == 'register' ? 'create' : 'guest', false, $ship_to == 'shipping' ? 'shipping' : false);
         if ($val->run()) {
             array_walk($insert, create_function('&$val', '$val = trim($val);'));
             try {
                 // Generate random username
                 $email = $insert['email'];
                 $user_group = 3;
                 if ($register_type == 'guest') {
                     $username = '******' . \Str::random('numeric', 16);
                     $insert['guest'] = 1;
                     $random_password = '******' . \Str::random(unique);
                     $password = $random_password;
                 } else {
                     $username = $email;
                     $insert['guest'] = 0;
                     $password = $insert['password'];
                 }
                 unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['update']);
                 $only_billing = array('email');
                 $billing_data = \Arr::filter_prefixed($insert, "billing_");
                 // Set shipping data to be same as billing by default
                 if ($ship_to_billing) {
                     foreach ($billing_data as $key => $value) {
                         if (!in_array($key, $only_billing)) {
                             $insert['shipping_' . $key] = $value;
                         }
                     }
                 }
                 $metadata = \Arr::remove_prefixed($insert, "billing_") + $billing_data;
                 $table = \DB::table_prefix('users_metadata');
                 $columns = \DB::list_columns($table);
                 $insert = array_intersect_key($metadata, $columns);
                 // create the user - no activation required
                 $vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert);
                 $user_id = \Sentry::user()->create($vars);
                 $user = \Sentry::user($user_id);
                 // Add user to 'customer' group (id = 3)
                 if ($user_id and $user->add_to_group($user_group)) {
                     if ($register_type == 'account') {
                         \Messages::success('User successfully created.');
                     }
                     if ($register_type == 'guest') {
                         \Messages::success('You register as a guest.');
                     }
                     $login_column = \Config::get('sentry.login_column', 'email');
                     if (\Sentry::login(${$login_column}, $password, true)) {
                         \Response::redirect(\Uri::create('order/checkout/cost'));
                     } else {
                         if ($register_type == 'account') {
                             \Messages::error('There was an error while trying to create account. Please try to create new account.');
                         }
                         if ($register_type == 'guest') {
                             \Messages::error('There was an error. Please try to login with your account details.');
                         }
                     }
                 } else {
                     // show validation errors
                     \Messages::error('There was an error while trying to create account.');
                 }
             } catch (\Sentry\SentryException $e) {
                 // show validation errors
                 \Messages::error('There was an error while trying to create user.');
                 $errors = $e->getMessage();
                 \Messages::error($errors);
             }
         } else {
             if ($val->error() != array()) {
                 // show validation errors
                 \Messages::error('There was an error while trying to create user.');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
 }
Exemple #12
0
 /**
  * copy new site tables and set default values for some table.
  *
  * @param integer $site_id
  * @return boolean
  */
 public function copyNewSiteTable($site_id = '')
 {
     if (!is_numeric($site_id)) {
         return false;
     }
     // get module's multisite tables.
     $this->hookGetMultisiteTables();
     // copy tables
     foreach ($this->multisite_tables as $table) {
         $table_withprefix = \DB::table_prefix($table);
         $table_site_withprefix = \DB::table_prefix($site_id . '_' . $table);
         if ($table == 'config') {
             $sql = 'CREATE TABLE IF NOT EXISTS ' . $table_site_withprefix . ' SELECT * FROM ' . $table_withprefix . ' WHERE config_core = 1';
         } else {
             $sql = 'CREATE TABLE IF NOT EXISTS ' . $table_site_withprefix . ' LIKE ' . $table_withprefix;
         }
         \DB::query($sql)->execute();
         // create default values
         if ($table == 'account_level_group') {
             $sql = "INSERT INTO `" . $table_site_withprefix . "` (`level_group_id`, `level_name`, `level_description`, `level_priority`) VALUES\n                    (1, 'Super administrator', 'For site owner or super administrator.', 1),\n                    (2, 'Administrator', NULL, 2),\n                    (3, 'Member', 'For registered user.', 999),\n                    (4, 'Guest', 'For non register user.', 1000);";
             \DB::query($sql)->execute();
         }
     }
     unset($sql, $table, $table_site_withprefix, $table_withprefix);
     // loop get account and add default levels
     $exist_account_id = array();
     $result = \DB::select('*')->from('account_level')->as_object()->execute();
     foreach ($result as $row) {
         // check and set level group id
         $lvg = \Model_AccountLevelGroup::getHighestPriorityAccountLevel($row->account_id);
         if ($lvg !== false && $lvg->level_group_id == '1') {
             $level_group_id = '1';
         } else {
             $level_group_id = '3';
             // 3 is just member. always set to 3 for non super-administrator for safety.
         }
         if (!in_array($row->account_id, $exist_account_id)) {
             \DB::insert($site_id . '_account_level')->set(array('level_group_id' => $level_group_id, 'account_id' => $row->account_id))->execute();
             $exist_account_id = array_merge($exist_account_id, array($row->account_id));
         }
     }
     // done
     return true;
 }
Exemple #13
0
	protected static function table_maintenance($operation, $table)
	{
		$result = \DB::query($operation.' '.\DB::quote_identifier(DB::table_prefix($table)), \DB::SELECT)->execute();
		$type = $result->get('Msg_type');
		$message = $result->get('Msg_text');
		$table = $result->get('Table');
		if($type === 'status' and in_array(strtolower($message), array('ok','table is already up to date')))
		{
			return true;
		}

		if($type === 'error')
		{
			\Log::error('Table: '.$table.', Operation: '.$operation.', Message: '.$result->get('Msg_text'), 'DBUtil::table_maintenance');
		}
		else
		{
			\Log::write(ucfirst($type), 'Table: '.$table.', Operation: '.$operation.', Message: '.$result->get('Msg_text'), 'DBUtil::table_maintenance');
		}
		return false;
	}
Exemple #14
0
 /**
  * 查看带参数二维码列表
  * @param $id 公众号ID
  */
 public function action_param_qrcode($id = 0)
 {
     $params = array('title' => '微信公众帐户带参二维码列表——微信公众号管理', 'menu' => 'wxaccount', 'action_name' => '微信公众帐户列表 》带参二维码列表');
     if (\Input::method() == 'POST') {
         $data = \Input::post();
         $account_id = \Session::get('WXAccount')->id;
         $table = \DB::table_prefix('wx_accounts_qrcodes');
         $time = time();
         $sql = "SELECT * FROM {$table} WHERE (`key` = '{$data['key']}' AND `type` = 'TEMP' AND `valid_date` > {$time} AND `account_id` = {$account_id}) OR (`key` = '{$data['key']}' AND `type` = 'LIMIT' AND `account_id` = {$account_id})";
         $rows = \DB::query($sql)->execute()->as_array();
         if ($rows) {
             $data = current($rows);
             die(json_encode(array('status' => 'err', 'msg' => '该参数的二维码已存在', 'errcode' => 10, 'data' => $data ? $data['qrcode'] : '')));
         }
         $result = \impls\wechat\Common::generate_qrcode_ticket($data['key'], strtolower($data['type']));
         $array = json_decode($result);
         $data['url'] = $array->url;
         $data['ticket'] = $array->ticket;
         if ($data['type'] == 'TEMP') {
             $data['valid_date'] = time() + $array->expire_seconds;
         } else {
             $data['valid_date'] = 0;
         }
         $data['qrcode'] = \tools\Tools::generate_qrcode($data['url'], '/uploads/qrcodes/');
         $qrcode = \Model_WXAccountQrcode::forge($data);
         if ($qrcode->save()) {
             if (\Input::is_ajax()) {
                 die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $data['qrcode'])));
             }
         } else {
             if (\Input::is_ajax()) {
                 die(json_encode(array('status' => 'err', 'msg' => '生成失败', 'errcode' => 20)));
             }
         }
     }
     $data = \Input::get();
     $items = \Model_WXAccountQrcode::query()->where('account_id', $id);
     $where_args = '';
     //是否需要筛选二维码的参数
     if (isset($data['key']) && $data['key']) {
         $items->where('key', $data['key']);
         $where_args .= "key={$data['key']}&";
     }
     //是否需要筛选二维码的状态
     if (isset($data['status']) && $data['status']) {
         $where_args .= "status={$data['status']}&";
         if ($data['status'] == 'valid') {
             $items->and_where_open()->where('valid_date', '>', time())->where('type', 'TEMP')->and_where_close();
             $items->or_where_open()->where('type', 'LIMIT')->or_where_close();
         } else {
             if (in_array(strtoupper($data['status']), array('TEMP', 'LIMIT'))) {
                 $items->where('type', $data['status']);
             }
         }
     }
     $where_args = $where_args ? "?{$where_args}" : '';
     $count = $items->count();
     $config = array('pagination_url' => "/admin/wxaccount/param_qrcode/{$id}{$where_args}", 'total_items' => $count, 'per_page' => \Input::get('count', 15), 'uri_segment' => "start", 'show_first' => true, 'show_last' => true, 'name' => 'bootstrap3_cn');
     $pagination = new \Pagination($config);
     $params['pagination'] = $pagination;
     $params['items'] = $items->rows_offset($pagination->offset)->rows_limit($pagination->per_page)->get();
     \View::set_global($params);
     $this->template->content = \View::forge("ace/wxaccount/qrcodes");
 }