Exemple #1
0
    public function page_header($event)
    {
        if ($this->auth->acl_get('u_did_you_know')) {
            $sql_layer = $this->db->get_sql_layer();
            switch ($sql_layer) {
                case 'postgres':
                    $random = 'RANDOM()';
                    break;
                case 'mssql':
                case 'mssql_odbc':
                    $random = 'NEWID()';
                    break;
                default:
                    $random = 'RAND()';
                    break;
            }
            $sql = 'SELECT word, bbcode_uid, bbcode_bitfield, bbcode_options
				FROM ' . $this->did_you_know . "\n\t\t\t\tWHERE lang_iso = '{$this->user->data['user_lang']}'\n\t\t\t\t\tOR lang_iso = 'default'\n\t\t\t\tORDER BY {$random}";
            $result = $this->db->sql_query_limit($sql, 1);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            $word = generate_text_for_display($row['word'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
            $this->template->assign_vars(array('DID_YOU_KNOW' => str_replace(""", '"', $word), 'S_DIDYOUKNOW' => !empty($this->user->data['user_didyouknow']) ? true : false, 'U_DYK_HIDE' => $this->helper->route('dmzx_didyouknow_controller', array('mode' => 'hide'))));
        }
    }
Exemple #2
0
 /**
  * @dataProvider data_attachment_delete
  */
 public function test_attachment_delete($mode, $ids, $resync, $expected)
 {
     // We need to reset the attachment ID sequence to properly test this
     if ($this->db->get_sql_layer() === 'postgres') {
         $sql = 'ALTER SEQUENCE phpbb_attachments_seq RESTART WITH 1';
         $this->db->sql_query($sql);
     }
     $this->assertSame($expected, $this->attachment_delete->delete($mode, $ids, $resync));
 }
Exemple #3
0
    /**
     * Obtain active bots
     */
    function obtain_bots()
    {
        if (($bots = $this->driver->get('_bots')) === false) {
            switch ($this->db->get_sql_layer()) {
                case 'mssql_odbc':
                case 'mssqlnative':
                    $sql = 'SELECT user_id, bot_agent, bot_ip
						FROM ' . BOTS_TABLE . '
						WHERE bot_active = 1
					ORDER BY LEN(bot_agent) DESC';
                    break;
                    // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
                // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
                default:
                    $sql = 'SELECT user_id, bot_agent, bot_ip
						FROM ' . BOTS_TABLE . '
						WHERE bot_active = 1
					ORDER BY LENGTH(bot_agent) DESC';
                    break;
            }
            $result = $this->db->sql_query($sql);
            $bots = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $bots[] = $row;
            }
            $this->db->sql_freeresult($result);
            $this->driver->put('_bots', $bots);
        }
        return $bots;
    }
Exemple #4
0
    /**
     * Render the final page of the convertor
     */
    public function finish()
    {
        $this->setup_navigation('finish');
        $this->template->assign_vars(array('TITLE' => $this->language->lang('CONVERT_COMPLETE'), 'BODY' => $this->language->lang('CONVERT_COMPLETE_EXPLAIN')));
        // If we reached this step (conversion completed) we want to purge the cache and log the user out.
        // This is for making sure the session get not screwed due to the 3.0.x users table being completely new.
        $this->cache->purge();
        $this->installer_cache->purge();
        require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
        require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
        $sql = 'SELECT config_value
			FROM ' . $this->config_table . '
			WHERE config_name = \'search_type\'';
        $result = $this->db->sql_query($sql);
        if ($this->db->sql_fetchfield('config_value') != 'fulltext_mysql') {
            $this->template->assign_vars(array('S_ERROR_BOX' => true, 'ERROR_TITLE' => $this->language->lang('SEARCH_INDEX_UNCONVERTED'), 'ERROR_MSG' => $this->language->lang('SEARCH_INDEX_UNCONVERTED_EXPLAIN')));
        }
        $this->db->sql_freeresult($result);
        switch ($this->db->get_sql_layer()) {
            case 'sqlite':
            case 'sqlite3':
                $this->db->sql_query('DELETE FROM ' . $this->session_keys_table);
                $this->db->sql_query('DELETE FROM ' . $this->session_table);
                break;
            default:
                $this->db->sql_query('TRUNCATE TABLE ' . $this->session_keys_table);
                $this->db->sql_query('TRUNCATE TABLE ' . $this->session_table);
                break;
        }
        return $this->controller_helper->render('installer_convert.html', 'CONVERT_COMPLETE');
    }
    /**
     * Computes the stats and store them in the $this->stats associative array
     */
    protected function get_stats()
    {
        if (strpos($this->db->get_sql_layer(), 'mysql') === false) {
            $this->stats = array();
            return;
        }
        $sql = 'SHOW INDEX
			FROM ' . POSTS_TABLE;
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            // deal with older MySQL versions which didn't use Index_type
            $index_type = isset($row['Index_type']) ? $row['Index_type'] : $row['Comment'];
            if ($index_type == 'FULLTEXT') {
                if ($row['Key_name'] == 'post_subject') {
                    $this->stats['post_subject'] = $row;
                } else {
                    if ($row['Key_name'] == 'post_content') {
                        $this->stats['post_content'] = $row;
                    }
                }
            }
        }
        $this->db->sql_freeresult($result);
        $this->stats['total_posts'] = empty($this->stats) ? 0 : $this->db->get_estimated_row_count(POSTS_TABLE);
    }
    /**
     * Display various options that can be configured for the backend from the acp
     *
     * @return associative array containing template and config variables
     */
    public function acp()
    {
        $tpl = '
		<dl>
			<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
			<dd>' . ($this->db->get_sql_layer() == 'postgres' ? $this->user->lang['YES'] : $this->user->lang['NO']) . '</dd>
		</dl>
		<dl>
			<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
			<dd><select name="config[fulltext_postgres_ts_name]">';
        if ($this->db->get_sql_layer() == 'postgres') {
            $sql = 'SELECT cfgname AS ts_name
				  FROM pg_ts_config';
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $tpl .= '<option value="' . $row['ts_name'] . '"' . ($row['ts_name'] === $this->config['fulltext_postgres_ts_name'] ? ' selected="selected"' : '') . '>' . $row['ts_name'] . '</option>';
            }
            $this->db->sql_freeresult($result);
        } else {
            $tpl .= '<option value="' . $this->config['fulltext_postgres_ts_name'] . '" selected="selected">' . $this->config['fulltext_postgres_ts_name'] . '</option>';
        }
        $tpl .= '</select></dd>
		</dl>
                <dl>
                        <dt><label for="fulltext_postgres_min_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
                        <dd><input id="fulltext_postgres_min_word_len" type="number" min="0" max="255" name="config[fulltext_postgres_min_word_len]" value="' . (int) $this->config['fulltext_postgres_min_word_len'] . '" /></dd>
                </dl>
                <dl>
                        <dt><label for="fulltext_postgres_max_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
                        <dd><input id="fulltext_postgres_max_word_len" type="number" min="0" max="255" name="config[fulltext_postgres_max_word_len]" value="' . (int) $this->config['fulltext_postgres_max_word_len'] . '" /></dd>
                </dl>
		';
        // These are fields required in the config table
        return array('tpl' => $tpl, 'config' => array('fulltext_postgres_ts_name' => 'string', 'fulltext_postgres_min_word_len' => 'integer:0:255', 'fulltext_postgres_max_word_len' => 'integer:0:255'));
    }
 /**
  * {@inheritdoc}
  */
 public function get_template_side($module_id)
 {
     // Generate birthday list if required ... / borrowed from index.php 3.0.6
     $birthday_list = $birthday_ahead_list = '';
     if ($this->config['load_birthdays'] && $this->config['allow_birthdays']) {
         $time = $this->user->create_datetime();
         $now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset());
         $cache_days = $this->config['board3_birthdays_ahead_' . $module_id];
         $sql_days = '';
         while ($cache_days > 0) {
             $day = phpbb_gmgetdate($time->getTimestamp() + 86400 * $cache_days + $time->getOffset());
             $like_expression = $this->db->sql_like_expression($this->db->get_any_char() . sprintf('%2d-%2d-', $day['mday'], $day['mon']) . $this->db->get_any_char());
             $sql_days .= " OR u.user_birthday " . $like_expression . "";
             $cache_days--;
         }
         switch ($this->db->get_sql_layer()) {
             case 'mssql':
             case 'mssql_odbc':
                 $order_by = 'u.user_birthday ASC';
                 break;
             default:
                 $order_by = 'SUBSTRING(u.user_birthday FROM 4 FOR 2) ASC, SUBSTRING(u.user_birthday FROM 1 FOR 2) ASC, u.username_clean ASC';
                 break;
         }
         $sql_array = array('SELECT' => 'u.user_id, u.username, u.user_colour, u.user_birthday', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array(BANLIST_TABLE => 'b'), 'ON' => 'u.user_id = b.ban_userid')), 'WHERE' => "(b.ban_id IS NULL\n\t\t\t\t\t\tOR b.ban_exclude = 1)\n\t\t\t\t\tAND (u.user_birthday " . $this->db->sql_like_expression($this->db->get_any_char() . sprintf('%2d-%2d-', $now['mday'], $now['mon']) . $this->db->get_any_char()) . " {$sql_days})\n\t\t\t\t\tAND " . $this->db->sql_in_set('u.user_type', array(USER_NORMAL, USER_FOUNDER)), 'ORDER BY' => $order_by);
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
         $result = $this->db->sql_query($sql, 3600);
         $today = sprintf('%2d-%2d-', $now['mday'], $now['mon']);
         while ($row = $this->db->sql_fetchrow($result)) {
             if (substr($row['user_birthday'], 0, 6) == $today) {
                 $birthday_list = true;
                 $this->template->assign_block_vars('board3_birthday_list', array('USER' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'AGE' => ($age = (int) substr($row['user_birthday'], -4)) ? ' (' . ($now['year'] - $age) . ')' : ''));
             } else {
                 if ($this->config['board3_birthdays_ahead_' . $module_id] > 0) {
                     $birthday_ahead_list = true;
                     $this->template->assign_block_vars('board3_birthday_ahead_list', array('USER' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'AGE' => ($age = (int) substr($row['user_birthday'], -4)) ? ' (' . ($now['year'] - $age) . ')' : '', 'DATE' => $this->format_birthday($this->user, $row['user_birthday'], 'd M')));
                 }
             }
         }
         $this->db->sql_freeresult($result);
     }
     // Assign index specific vars
     $this->template->assign_vars(array('BIRTHDAY_LIST' => $birthday_list, 'BIRTHDAYS_AHEAD_LIST' => $this->config['board3_birthdays_ahead_' . $module_id] ? $birthday_ahead_list : '', 'L_BIRTHDAYS_AHEAD' => sprintf($this->user->lang['BIRTHDAYS_AHEAD'], $this->config['board3_birthdays_ahead_' . $module_id]), 'S_DISPLAY_BIRTHDAY_LIST' => $this->config['load_birthdays'] ? true : false, 'S_DISPLAY_BIRTHDAY_AHEAD_LIST' => $this->config['board3_birthdays_ahead_' . $module_id] > 0 ? true : false));
     return 'birthdays_side.html';
 }
    /**
     * Execute action requested
     *
     * @param	string $action Requested action
     * @return	null
     */
    public function exec_action($action)
    {
        switch ($action) {
            case 'votes':
                switch ($this->db->get_sql_layer()) {
                    case 'sqlite':
                    case 'firebird':
                        $this->db->sql_query('DELETE FROM ' . DIR_VOTE_TABLE);
                        break;
                    default:
                        $this->db->sql_query('TRUNCATE TABLE ' . DIR_VOTE_TABLE);
                        break;
                }
                $sql = 'UPDATE ' . DIR_LINK_TABLE . '
					SET link_vote = 0, link_note = 0';
                $this->db->sql_query($sql);
                if ($this->request->is_ajax()) {
                    trigger_error('DIR_RESET_VOTES_SUCCESS');
                }
                break;
            case 'comments':
                switch ($this->db->get_sql_layer()) {
                    case 'sqlite':
                    case 'firebird':
                        $this->db->sql_query('DELETE FROM ' . DIR_COMMENT_TABLE);
                        break;
                    default:
                        $this->db->sql_query('TRUNCATE TABLE ' . DIR_COMMENT_TABLE);
                        break;
                }
                $sql = 'UPDATE ' . DIR_LINK_TABLE . '
					SET link_comment = 0';
                $this->db->sql_query($sql);
                if ($this->request->is_ajax()) {
                    trigger_error('DIR_RESET_COMMENTS_SUCCESS');
                }
                break;
            case 'clicks':
                $sql = 'UPDATE ' . DIR_LINK_TABLE . '
					SET link_view = 0';
                $this->db->sql_query($sql);
                if ($this->request->is_ajax()) {
                    trigger_error('DIR_RESET_CLICKS_SUCCESS');
                }
                break;
            case 'orphans':
                $this->_orphan_files(true);
                if ($this->request->is_ajax()) {
                    trigger_error('DIR_DELETE_ORPHANS_SUCCESS');
                }
                break;
        }
    }
Exemple #9
0
 /**
  * Deletes all words from the index
  */
 public function delete_index($acp_module, $u_action)
 {
     switch ($this->db->get_sql_layer()) {
         case 'sqlite':
         case 'sqlite3':
             $this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
             $this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
             $this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
             break;
         default:
             $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
             $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
             $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
             break;
     }
 }
 /**
  *	Get the random statement for this database layer
  */
 protected function sql_random()
 {
     switch ($this->db->get_sql_layer()) {
         case 'firebird':
         case 'oracle':
         case 'postgres':
         case 'sqlite':
             return 'RANDOM()';
             /* All other cases should use the default
             			case 'mssql':
             			case 'mssqlnative':
             			case 'mysql_40':
             			case 'mysql_41':
             			case 'mysqli':*/
         /* All other cases should use the default
         			case 'mssql':
         			case 'mssqlnative':
         			case 'mysql_40':
         			case 'mysql_41':
         			case 'mysqli':*/
         default:
             return 'RAND()';
     }
 }
Exemple #11
0
/**
* Removes moderators and administrators from foe lists.
*
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\auth\auth $auth Authentication object
* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore
* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore
* @return null
*/
function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false)
{
    // update foes for some user
    if (is_array($user_id) && sizeof($user_id)) {
        $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
			WHERE ' . $db->sql_in_set('zebra_id', $user_id) . '
				AND foe = 1';
        $db->sql_query($sql);
        return;
    }
    // update foes for some group
    if (is_array($group_id) && sizeof($group_id)) {
        // Grab group settings...
        $sql_ary = array('SELECT' => 'a.group_id', 'FROM' => array(ACL_OPTIONS_TABLE => 'ao', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
				AND ' . $db->sql_in_set('a.group_id', $group_id) . "\n\t\t\t\tAND ao.auth_option IN ('a_', 'm_')", 'GROUP_BY' => 'a.group_id');
        $sql = $db->sql_build_query('SELECT', $sql_ary);
        $result = $db->sql_query($sql);
        $groups = array();
        while ($row = $db->sql_fetchrow($result)) {
            $groups[] = (int) $row['group_id'];
        }
        $db->sql_freeresult($result);
        if (!sizeof($groups)) {
            return;
        }
        switch ($db->get_sql_layer()) {
            case 'mysqli':
            case 'mysql4':
                $sql = 'DELETE ' . ($db->get_sql_layer() === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=') ? 'z.*' : ZEBRA_TABLE) . '
					FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug
					WHERE z.zebra_id = ug.user_id
						AND z.foe = 1
						AND ' . $db->sql_in_set('ug.group_id', $groups);
                $db->sql_query($sql);
                break;
            default:
                $sql = 'SELECT user_id
					FROM ' . USER_GROUP_TABLE . '
					WHERE ' . $db->sql_in_set('group_id', $groups);
                $result = $db->sql_query($sql);
                $users = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $users[] = (int) $row['user_id'];
                }
                $db->sql_freeresult($result);
                if (sizeof($users)) {
                    $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
						WHERE ' . $db->sql_in_set('zebra_id', $users) . '
							AND foe = 1';
                    $db->sql_query($sql);
                }
                break;
        }
        return;
    }
    // update foes for everyone
    $perms = array();
    foreach ($auth->acl_get_list(false, array('a_', 'm_'), false) as $forum_id => $forum_ary) {
        foreach ($forum_ary as $auth_option => $user_ary) {
            $perms = array_merge($perms, $user_ary);
        }
    }
    if (sizeof($perms)) {
        $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
			WHERE ' . $db->sql_in_set('zebra_id', array_unique($perms)) . '
				AND foe = 1';
        $db->sql_query($sql);
    }
    unset($perms);
}
 public function main($id, $mode)
 {
     global $cache, $config, $db, $phpbb_log, $request, $template, $user;
     $this->cache = $cache;
     $this->config = $config;
     $this->db = $db;
     $this->log = $phpbb_log;
     $this->request = $request;
     $this->template = $template;
     $this->user = $user;
     $this->user->add_lang_ext('vse/dbtool', 'dbtool_acp');
     $this->tpl_name = 'acp_dbtool';
     $this->page_title = 'ACP_OPTIMIZE_REPAIR';
     // Check to make sure only MySQL users can proceed
     if ($this->db->get_sql_layer() != 'mysql4' && $this->db->get_sql_layer() != 'mysqli') {
         trigger_error($this->user->lang('WARNING_MYSQL'), E_USER_WARNING);
     }
     // Get vars from the form
     $type = $this->request->variable('type', '');
     $marked = $this->request->variable('mark', array(''));
     $disable_board = !$this->config['board_disable'] ? $this->request->variable('disable_board', 0) : 0;
     if ($this->request->is_set_post('submit')) {
         if (confirm_box(true)) {
             if (!sizeof($marked)) {
                 trigger_error($this->user->lang('TABLE_ERROR') . adm_back_link($this->u_action), E_USER_WARNING);
             }
             // Make sure Safe Mode is disabled during this script execution
             if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on') {
                 @ini_set('safe_mode', 'Off');
             }
             // Extend or disable script execution timeout (copied this from acp_database.php)
             @set_time_limit(1200);
             @set_time_limit(0);
             $tables = implode(', ', $marked);
             unset($marked);
             switch ($type) {
                 case 'optimize':
                     $optimize = $this->table_maintenance('OPTIMIZE TABLE', $tables, $disable_board);
                     $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'OPTIMIZE_LOG', time(), array($tables));
                     trigger_error($this->user->lang('OPTIMIZE_SUCCESS') . $optimize . adm_back_link($this->u_action));
                     break;
                 case 'repair':
                     $repair = $this->table_maintenance('REPAIR TABLE', $tables, $disable_board);
                     $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'REPAIR_LOG', time(), array($tables));
                     trigger_error($this->user->lang('REPAIR_SUCCESS') . $repair . adm_back_link($this->u_action));
                     break;
                 case 'check':
                     $check = $this->table_maintenance('CHECK TABLE', $tables, $disable_board);
                     trigger_error($this->user->lang('CHECK_SUCCESS') . $check . adm_back_link($this->u_action));
                     break;
             }
         } else {
             confirm_box(false, $this->user->lang('CONFIRM_OPERATION'), build_hidden_fields(array('submit' => 1, 'mode' => $mode, 'type' => $type, 'mark' => $marked, 'disable_board' => $disable_board)));
         }
     }
     // Generate Show Table Data
     $total_data_size = $total_data_free = 0;
     $tables = $this->db->sql_query('SHOW TABLE STATUS');
     while ($table = $this->db->sql_fetchrow($tables)) {
         /**
          * NOTE: Only MyISAM, InnoDB and Archive storage engines can be used
          * Check    supports MyISAM, InnoDB and Archive
          * Optimize supports MyISAM, InnoDB and (as of MySQL 5.0.16) Archive
          * Repair   supports MyISAM, Archive
          */
         $table['Engine'] = !empty($table['Type']) ? $table['Type'] : $table['Engine'];
         if (in_array(strtolower($table['Engine']), array('myisam', 'innodb', 'archive'))) {
             // Data_free should always be 0 for InnoDB tables
             if (strtolower($table['Engine']) == 'innodb') {
                 $table['Data_free'] = 0;
             }
             $data_size = $table['Data_length'] + $table['Index_length'];
             $total_data_size = $total_data_size + $data_size;
             $total_data_free = $total_data_free + $table['Data_free'];
             $this->template->assign_block_vars('tables', array('TABLE_NAME' => $table['Name'], 'TABLE_TYPE' => $table['Engine'], 'DATA_SIZE' => $this->file_size($data_size), 'DATA_FREE' => $this->file_size($table['Data_free']), 'S_OVERHEAD' => $table['Data_free'] ? true : false));
         }
     }
     $this->db->sql_freeresult($tables);
     $this->template->assign_vars(array('TOTAL_DATA_SIZE' => $this->file_size($total_data_size), 'TOTAL_DATA_FREE' => $this->file_size($total_data_free), 'U_ACTION' => $this->u_action));
 }
 public function display_lottery()
 {
     // Grab some vars
     $action = $this->request->variable('action', '');
     $id = $this->request->variable('id', 0);
     // Read out config data
     $sql_array = array('SELECT' => 'config_name, config_value', 'FROM' => array($this->points_config_table => 'c'));
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql);
     while ($row = $this->db->sql_fetchrow($result)) {
         $points_config[$row['config_name']] = $row['config_value'];
     }
     $this->db->sql_freeresult($result);
     $this->template->assign_vars(array_change_key_case($points_config, CASE_UPPER));
     // Read out values data
     $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v'));
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql);
     $points_values = $this->db->sql_fetchrow($result);
     $this->db->sql_freeresult($result);
     // Form key
     add_form_key('acp_points');
     $this->template->assign_vars(array('BASE' => $this->u_action));
     $submit = $this->request->variable('submit', '');
     $lottery_data = $errors = array();
     if ($submit) {
         if (!check_form_key('acp_points')) {
             trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
         }
         // Get current lottery_base_amount
         $current_lottery_jackpot = $points_values['lottery_jackpot'];
         $current_lottery_base_amount = $points_values['lottery_base_amount'];
         // Values for phpbb_points_config
         $lottery_enable = $this->request->variable('lottery_enable', 0);
         $lottery_multi_ticket_enable = $this->request->variable('lottery_multi_ticket_enable', 0);
         $display_lottery_stats = $this->request->variable('display_lottery_stats', 0);
         // Values for phpbb_points_values
         $lottery_base_amount = round($this->request->variable('lottery_base_amount', 0.0), 2);
         $lottery_draw_period = $this->request->variable('lottery_draw_period', 0) * 3600;
         $lottery_ticket_cost = round($this->request->variable('lottery_ticket_cost', 0.0), 2);
         $lottery_name = $this->request->variable('lottery_name', '', true);
         $lottery_chance = round($this->request->variable('lottery_chance', 0.0), 2);
         $lottery_max_tickets = round($this->request->variable('lottery_max_tickets', 0.0), 2);
         $lottery_pm_from = $this->request->variable('lottery_pm_from', 0);
         // Check entered lottery chance - has to be max 100
         if ($lottery_chance > 100) {
             trigger_error($this->user->lang['LOTTERY_CHANCE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
         }
         // If base amount increases, increase jackpot
         if ($lottery_base_amount > $current_lottery_base_amount) {
             $this->functions_points->set_points_values('lottery_jackpot', $current_lottery_jackpot . '+' . $lottery_base_amount . '-' . $current_lottery_base_amount);
             //set_points_values('lottery_base_amount', $lottery_base_amount);
         }
         // Update values in phpbb_points_config
         if ($lottery_enable != $points_config['lottery_enable']) {
             $this->functions_points->set_points_config('lottery_enable', $lottery_enable);
         }
         if ($lottery_multi_ticket_enable != $points_config['lottery_multi_ticket_enable']) {
             $this->functions_points->set_points_config('lottery_multi_ticket_enable', $lottery_multi_ticket_enable);
         }
         if ($display_lottery_stats != $points_config['display_lottery_stats']) {
             $this->functions_points->set_points_config('display_lottery_stats', $display_lottery_stats);
         }
         // Update values in phpbb_points_values
         $this->functions_points->set_points_values('lottery_base_amount', $lottery_base_amount);
         // Check if 0 is entered. Must be > 0
         if ($lottery_draw_period < 0) {
             trigger_error($this->user->lang['LOTTERY_DRAW_PERIOD_SHORT'] . adm_back_link($this->u_action), E_USER_WARNING);
         } else {
             $this->functions_points->set_points_values('lottery_draw_period', $lottery_draw_period);
         }
         $this->functions_points->set_points_values('lottery_ticket_cost', $lottery_ticket_cost);
         $this->functions_points->set_points_values('lottery_name', "'" . $this->db->sql_escape($lottery_name) . "'");
         $this->functions_points->set_points_values('lottery_chance', $lottery_chance);
         $this->functions_points->set_points_values('lottery_max_tickets', $lottery_max_tickets);
         // Check, if the entered user_id really exists
         $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $lottery_pm_from);
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
         $result = $this->db->sql_query($sql);
         $id_exist = $this->db->sql_fetchfield('user_id');
         $this->db->sql_freeresult($result);
         if ($lottery_pm_from == 0) {
             $this->functions_points->set_points_values('lottery_pm_from', $lottery_pm_from);
         } else {
             if (empty($id_exist)) {
                 trigger_error($this->user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
             } else {
                 $this->functions_points->set_points_values('lottery_pm_from', $lottery_pm_from);
             }
         }
         // Set last draw time to current time, if draw period activated
         if ($points_values['lottery_last_draw_time'] == 0 && $points_values['lottery_draw_period'] != 0) {
             $this->functions_points->set_points_values('lottery_last_draw_time', time());
         }
         // Set last draw time to 0, if draw period deactivated
         if ($points_values['lottery_draw_period'] == 0) {
             $this->functions_points->set_points_values('lottery_last_draw_time', 0);
         }
         // Add logs
         $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_MOD_POINTS_LOTTERY');
         trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
     }
     // Delete lottery history
     $reset_lottery_history = isset($_POST['action_lottery_history']) ? true : false;
     if ($reset_lottery_history) {
         if (confirm_box(true)) {
             if (!$this->auth->acl_get('a_points')) {
                 trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
             $sql_layer = $this->db->get_sql_layer();
             switch ($sql_layer) {
                 case 'sqlite':
                 case 'firebird':
                     $this->db->sql_query('DELETE FROM ' . $this->table_points_lottery_history);
                     break;
                 default:
                     $this->db->sql_query('TRUNCATE TABLE ' . $this->table_points_lottery_history);
                     break;
             }
             $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_LOTTERY_HISTORY');
             trigger_error($this->user->lang['LOG_RESYNC_LOTTERY_HISTORY'] . adm_back_link($this->u_action));
         } else {
             $s_hidden_fields = build_hidden_fields(array('action_lottery_history' => true));
             // Display mode
             confirm_box(false, $this->user->lang['RESYNC_LOTTERY_HISTORY_CONFIRM'], $s_hidden_fields);
         }
     }
     $this->template->assign_vars(array('LOTTERY_BASE_AMOUNT' => $points_values['lottery_base_amount'], 'LOTTERY_DRAW_PERIOD' => $points_values['lottery_draw_period'] == 0 ? $points_values['lottery_draw_period'] : $points_values['lottery_draw_period'] / 3600, 'LOTTERY_TICKET_COST' => $points_values['lottery_ticket_cost'], 'LOTTERY_CASH_NAME' => $this->config['points_name'], 'LOTTERY_NAME' => $points_values['lottery_name'], 'LOTTERY_CHANCE' => $points_values['lottery_chance'], 'LOTTERY_MAX_TICKETS' => $points_values['lottery_max_tickets'], 'LOTTERY_PM_FROM' => $points_values['lottery_pm_from'], 'S_LOTTERY_ENABLE' => $points_config['lottery_enable'] ? true : false, 'S_LOTTERY_MULTI_TICKET_ENABLE' => $points_config['lottery_multi_ticket_enable'] ? true : false, 'S_DISPLAY_LOTTERY_STATS' => $points_config['display_lottery_stats'] ? true : false, 'S_LOTTERY' => true, 'U_ACTION' => $this->u_action));
 }
Exemple #14
0
    /**
     * Generates content of sphinx.conf
     *
     * @return bool True if sphinx.conf content is correctly generated, false otherwise
     */
    protected function config_generate()
    {
        // Check if Database is supported by Sphinx
        if ($this->db->get_sql_layer() == 'mysql' || $this->db->get_sql_layer() == 'mysql4' || $this->db->get_sql_layer() == 'mysqli') {
            $this->dbtype = 'mysql';
        } else {
            if ($this->db->get_sql_layer() == 'postgres') {
                $this->dbtype = 'pgsql';
            } else {
                $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_WRONG_DATABASE');
                return false;
            }
        }
        // Check if directory paths have been filled
        if (!$this->config['fulltext_sphinx_data_path']) {
            $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA');
            return false;
        }
        include $this->phpbb_root_path . 'config.' . $this->php_ext;
        /* Now that we're sure everything was entered correctly,
        		generate a config for the index. We use a config value
        		fulltext_sphinx_id for this, as it should be unique. */
        $config_object = new \phpbb\search\sphinx\config($this->config_file_data);
        $config_data = array('source source_phpbb_' . $this->id . '_main' => array(array('type', $this->dbtype . ' # mysql or pgsql'), array('sql_host', $dbhost . ' # SQL server host sphinx connects to'), array('sql_user', '[dbuser]'), array('sql_pass', '[dbpassword]'), array('sql_db', $dbname), array('sql_port', $dbport . ' # optional, default is 3306 for mysql and 5432 for pgsql'), array('sql_query_pre', 'SET NAMES \'utf8\''), array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'), array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), array('sql_range_step', '5000'), array('sql_query', 'SELECT
						p.post_id AS id,
						p.forum_id,
						p.topic_id,
						p.poster_id,
						p.post_visibility,
						CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
						p.post_time,
						p.post_subject,
						p.post_subject as title,
						p.post_text as data,
						t.topic_last_post_time,
						0 as deleted
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
					WHERE
						p.topic_id = t.topic_id
						AND p.post_id >= $start AND p.post_id <= $end'), array('sql_query_post', ''), array('sql_query_post_index', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = $maxid WHERE counter_id = 1'), array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'), array('sql_attr_uint', 'forum_id'), array('sql_attr_uint', 'topic_id'), array('sql_attr_uint', 'poster_id'), array('sql_attr_uint', 'post_visibility'), array('sql_attr_bool', 'topic_first_post'), array('sql_attr_bool', 'deleted'), array('sql_attr_timestamp', 'post_time'), array('sql_attr_timestamp', 'topic_last_post_time'), array('sql_attr_string', 'post_subject')), 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array(array('sql_query_pre', ''), array('sql_query_range', ''), array('sql_range_step', ''), array('sql_query', 'SELECT
						p.post_id AS id,
						p.forum_id,
						p.topic_id,
						p.poster_id,
						p.post_visibility,
						CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
						p.post_time,
						p.post_subject,
						p.post_subject as title,
						p.post_text as data,
						t.topic_last_post_time,
						0 as deleted
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
					WHERE
						p.topic_id = t.topic_id
						AND p.post_id >=  ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )')), 'index index_phpbb_' . $this->id . '_main' => array(array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), array('source', 'source_phpbb_' . $this->id . '_main'), array('docinfo', 'extern'), array('morphology', 'none'), array('stopwords', ''), array('min_word_len', '2'), array('charset_type', 'utf-8'), array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), array('min_prefix_len', '0'), array('min_infix_len', '0')), 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array(array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), array('source', 'source_phpbb_' . $this->id . '_delta')), 'indexer' => array(array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M')), 'searchd' => array(array('compat_sphinxql_magics', '0'), array('listen', ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '9312')), array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), array('read_timeout', '5'), array('max_children', '30'), array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'), array('max_matches', (string) SPHINX_MAX_MATCHES), array('binlog_path', $this->config['fulltext_sphinx_data_path'])));
        $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true);
        $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true);
        foreach ($config_data as $section_name => $section_data) {
            $section = $config_object->get_section_by_name($section_name);
            if (!$section) {
                $section = $config_object->add_section($section_name);
            }
            foreach ($delete as $key => $void) {
                $section->delete_variables_by_name($key);
            }
            foreach ($non_unique as $key => $void) {
                $section->delete_variables_by_name($key);
            }
            foreach ($section_data as $entry) {
                $key = $entry[0];
                $value = $entry[1];
                if (!isset($non_unique[$key])) {
                    $variable = $section->get_variable_by_name($key);
                    if (!$variable) {
                        $variable = $section->create_variable($key, $value);
                    } else {
                        $variable->set_value($value);
                    }
                } else {
                    $variable = $section->create_variable($key, $value);
                }
            }
        }
        $this->config_file_data = $config_object->get_data();
        return true;
    }
Exemple #15
0
 /**
  * Check if the database layer is MySQL4 or later
  *
  * @return	bool	True is MySQL4 or later, false otherwise
  * @access	protected
  */
 protected function is_mysql()
 {
     return $this->db->get_sql_layer() == 'mysql4' || $this->db->get_sql_layer() == 'mysqli';
 }
    /**
     * Run Lottery
     */
    function run_lottery()
    {
        $current_time = time();
        /**
         * Read out config values
         */
        $sql = 'SELECT *
				FROM ' . $this->points_values_table;
        $result = $this->db->sql_query($sql);
        $points_values = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Count number of tickets
        $sql_array = array('SELECT' => 'COUNT(ticket_id) AS num_tickets', 'FROM' => array($this->points_lottery_tickets_table => 'l'));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $total_tickets = (int) $this->db->sql_fetchfield('num_tickets');
        $this->db->sql_freeresult($result);
        // Select a random user from tickets table
        $sql_layer = $this->db->get_sql_layer();
        switch ($sql_layer) {
            case 'postgres':
                $order_by = 'RANDOM()';
                break;
            case 'mssql':
            case 'mssql_odbc':
                $order_by = 'NEWID()';
                break;
            default:
                $order_by = 'RAND()';
                break;
        }
        $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_lottery_tickets_table => 'l'), 'ORDER_BY' => $order_by);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, 1);
        $random_user_by_tickets = (int) $this->db->sql_fetchfield('user_id');
        $this->db->sql_freeresult($result);
        if ($total_tickets > 0) {
            // Genarate a random number
            $rand_base = $points_values['lottery_chance'];
            $rand_value = rand(0, 100);
            // Decide, if the user really wins
            if ($rand_value <= $rand_base) {
                $winning_number = $random_user_by_tickets;
                // Select a winner from ticket table
                $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . $winning_number);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $winner = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                // Check if lottery is enabled and prepare winner informations
                $sql = 'SELECT lottery_enable
						FROM ' . $this->points_config_table;
                $result = $this->db->sql_query($result);
                $lottery_enabled = $this->db->sql_fetchfield('lottery_enable');
                $this->db->sql_freeresult($result);
                if ($lottery_enabled != 0) {
                    $winnings_update = $winner['user_points'] + $this->points_values('lottery_jackpot');
                    $this->set_points($winner['user_id'], $winnings_update);
                    $winner_notification = $this->number_format_points($points_values['lottery_jackpot']) . ' ' . $this->config['points_name'] . ' ';
                    $winner_deposit = $this->user->lang['LOTTERY_PM_CASH_ENABLED'];
                    $amount_won = $points_values['lottery_jackpot'];
                } else {
                    $winner_notification = '';
                    $winner_deposit = '';
                    $amount_won = '';
                }
                // Update previous winner information
                $this->set_points_values('lottery_prev_winner', "'" . $winner['username'] . "'");
                $this->set_points_values('lottery_prev_winner_id', $winner['user_id']);
                // Check, if user wants to be informed by PM
                if ($winner['user_allow_pm'] == 1) {
                    $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . $points_values['lottery_pm_from']);
                    $sql = $this->db->sql_build_query('SELECT', $sql_array);
                    $result = $this->db->sql_query($sql);
                    $pm_sender = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    // Notify the lucky winner by PM
                    $pm_subject = utf8_normalize_nfc($this->user->lang['LOTTERY_PM_SUBJECT']);
                    $pm_text = utf8_normalize_nfc(sprintf($this->user->lang['LOTTERY_PM_BODY'], $winner_notification, $winner_deposit));
                    $poll = $uid = $bitfield = $options = '';
                    generate_text_for_storage($pm_subject, $uid, $bitfield, $options, false, false, false);
                    generate_text_for_storage($pm_text, $uid, $bitfield, $options, true, true, true);
                    $pm_data = array('address_list' => array('u' => array($winner['user_id'] => 'to')), 'from_user_id' => $points_values['lottery_pm_from'] == 0 ? $winner['user_id'] : $pm_sender['user_id'], 'from_username' => $points_values['lottery_pm_from'] == 0 ? $this->user->lang['LOTTERY_PM_COMMISION'] : $pm_sender['username'], 'icon_id' => 0, 'from_user_ip' => '', 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $pm_text, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid);
                    submit_pm('post', $pm_subject, $pm_data, false);
                }
                // Add new winner to lottery history
                $sql = 'INSERT INTO ' . $this->points_lottery_history_table . ' ' . $this->db->sql_build_array('INSERT', array('user_id' => (int) $winner['user_id'], 'user_name' => $winner['username'], 'time' => $current_time, 'amount' => $points_values['lottery_jackpot']));
                $this->db->sql_query($sql);
                // Update winners total
                $this->set_points_values('lottery_winners_total', $points_values['lottery_winners_total'] + 1);
                // Add jackpot to winner
                $this->add_points((int) $winner['user_id'], $points_values['lottery_jackpot']);
                // Reset jackpot
                $this->set_points_values('lottery_jackpot', $points_values['lottery_base_amount']);
            } else {
                $this->set_points_values('lottery_jackpot', $points_values['lottery_jackpot'] + $points_values['lottery_base_amount']);
                $no_winner = 0;
                $sql = 'INSERT INTO ' . $this->points_lottery_history_table . ' ' . $this->db->sql_build_array('INSERT', array('user_id' => 0, 'user_name' => $no_winner, 'time' => $current_time, 'amount' => 0));
                $this->db->sql_query($sql);
                // Update previous winner information
                $this->set_points_values('lottery_prev_winner', "'" . $no_winner . "'");
                $this->set_points_values('lottery_prev_winner_id', 0);
            }
        }
        // Reset lottery
        // Delete all tickets
        $sql = 'DELETE FROM ' . $this->points_lottery_tickets_table;
        $this->db->sql_query($sql);
        // Reset last draw time
        $check_time = $points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period'];
        $current_time = time();
        if ($current_time > $check_time) {
            while ($check_time < $current_time) {
                $check_time = $check_time + $points_values['lottery_draw_period'];
                $check_time++;
            }
            if ($check_time > $current_time) {
                $check_time = $check_time - $points_values['lottery_draw_period'];
                $this->set_points_values('lottery_last_draw_time', $check_time);
            }
        } else {
            $this->set_points_values('lottery_last_draw_time', $points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period']);
        }
    }
 /**
  * Runs this cron task.
  *
  * @return null
  */
 public function run()
 {
     // Need to include this file for the get_usable_memory() function
     if (!function_exists('get_usable_memory')) {
         include_once $this->phpbb_root_path . 'includes/acp/acp_database.' . $this->php_ext;
     }
     @set_time_limit(1200);
     @set_time_limit(0);
     $this->db_tools = $this->container->get('dbal.tools');
     $tables = $this->db_tools->sql_list_tables();
     $time = time();
     $filename = 'backup_' . $time . '_' . unique_id();
     $file_type = $this->config['auto_db_backup_filetype'];
     $location = $this->phpbb_root_path . '/store/';
     $extractor = $this->container->get('dbal.extractor');
     $extension = $this->get_extension($file_type);
     $extractor->init_extractor($file_type, $filename, $time, false, true);
     $extractor->write_start($this->table_prefix);
     foreach ($tables as $table_name) {
         $extractor->write_table($table_name);
         if ($this->config['auto_db_backup_optimize']) {
             switch ($this->db->get_sql_layer()) {
                 case 'sqlite':
                 case 'sqlite3':
                     $extractor->flush('DELETE FROM ' . $table_name . ";\n");
                     break;
                 case 'mssql':
                 case 'mssql_odbc':
                 case 'mssqlnative':
                     $extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
                     break;
                 case 'oracle':
                     $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
                     break;
                 default:
                     $extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n");
                     break;
             }
         }
         $extractor->write_data($table_name);
     }
     $extractor->write_end();
     /**
      * Event to allow exporting of a backup file
      *
      * @event david63.autodbbackup.backup_file_export
      * @var	string	filename	The backup filename
      * @var	string	file_type	The backup file type (text, bzip2 or gzip)
      * @var	string	extension	The file extension for the file type
      * @var	string	location	The location of the backup files
      *
      * @since 2.1.0
      */
     $vars = array('filename', 'file_type', 'extension', 'location');
     extract($this->dispatcher->trigger_event('david63.autodbbackup.backup_file_export', compact($vars)));
     // Delete backup copies
     if ($this->config['auto_db_backup_copies'] > 0) {
         $dir = opendir($location);
         $files = array();
         while (($file = readdir($dir)) !== false) {
             if (is_file($location . $file) && (substr($file, -3) == '.gz' || substr($file, -4) == '.bz2' || substr($file, -4) == '.sql')) {
                 $files[$file] = fileatime($location . $file);
             }
         }
         closedir($dir);
         arsort($files);
         reset($files);
         if (sizeof($files) > $this->config['auto_db_backup_copies']) {
             $i = 0;
             while (list($key, $val) = each($files)) {
                 $i++;
                 if ($i > $this->config['auto_db_backup_copies']) {
                     @unlink($location . $key);
                 }
             }
         }
     }
     // Update the last backup time and write the log entry
     $this->config->set('auto_db_backup_last_gc', time(), true);
     $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_AUTO_DB_BACKUP');
 }