Beispiel #1
0
function notifymods_mail($mod, $users_id = 0, $var = NULL)
{
    // $mail_text[$lang] = cs_translate('notifymods');  // not implicitly necessary
    if (!is_array($var)) {
        $var = array($var);
    }
    $mails_send = 0;
    $from = "notifymods ntm INNER JOIN {pre}_users usr ON ntm.notifymods_user = usr.users_id";
    $where = "ntm.notifymods_user != '" . $users_id . "'  \n            AND usr.users_delete != 1\n            AND usr.users_active = 1\n            AND ntm.notifymods_" . $mod . " = 1";
    $ntm_users = cs_sql_select(__FILE__, $from, 'usr.users_lang, usr.users_email', $where, 0, 0, 0);
    $pattern1 = '/\'(?<mod>.*)_text\'\\](\\s*)=(\\s*)\'(?<value>.*)\';/';
    $pattern2 = '/\'(?<mod>.*)_subject\'\\](\\s*)=(\\s*)\'(?<value>.*)\';/';
    if (!empty($ntm_users)) {
        foreach ($ntm_users as $mail_user) {
            $lang = empty($mail_user['users_lang']) ? $cs_main['def_lang'] : $mail_user['users_lang'];
            if (empty($mail_text[$lang][$mod . '_text'])) {
                $mail_text[$lang] = cs_cache_load('lang_notifymods_' . $lang);
                if ($mail_text[$lang] === FALSE and file_exists('lang/' . $lang . '/notifymods.php')) {
                    // read lang-file and search for text- & subject-placeholder
                    $fp = fopen('lang/' . $lang . '/notifymods.php', 'r');
                    $file_content = '';
                    while (!feof($fp)) {
                        $file_content .= fgets($fp, 4096);
                    }
                    fclose($fp);
                    preg_match_all($pattern1, $file_content, $match);
                    $run = 0;
                    foreach ($match['mod'] as $lang_mod) {
                        $mail_text[$lang][$lang_mod . '_text'] = $match['value'][$run];
                        $run++;
                    }
                    preg_match_all($pattern2, $file_content, $match);
                    $run = 0;
                    foreach ($match['mod'] as $lang_mod) {
                        $mail_text[$lang][$lang_mod . '_subject'] = $match['value'][$run];
                        $run++;
                    }
                    cs_cache_save('lang_notifymods_' . $lang, $mail_text[$lang]);
                }
            }
            if (empty($text[$lang])) {
                $text[$lang] = empty($var) ? $mail_text[$lang][$mod . '_text'] : vsprintf($mail_text[$lang][$mod . '_text'], $var);
            }
            if (cs_mail($mail_user['users_email'], $mail_text[$lang][$mod . '_subject'], $text[$lang])) {
                $mails_send++;
            }
        }
        return $mails_send;
    }
}
Beispiel #2
0
<?php

// ClanSphere 2010 - www.clansphere.net
// $Id$
$thisday = cs_datereal('m-d');
$output = array();
$data = array();
$data = cs_cache_load('navbirth');
$cs_lang = cs_translate('users');
$options = cs_sql_option(__FILE__, 'users');
if ($data['day'] != $thisday) {
    $data['day'] = $thisday;
    $select = 'users_id, users_nick, users_age';
    $where = "users_age LIKE '%-" . $data['day'] . "' AND users_hidden NOT LIKE '%users_age%' AND users_active = 1";
    $order = 'users_nick ASC';
    $data['users'] = cs_sql_select(__FILE__, 'users', $select, $where, $order, 0, 0);
    cs_cache_save('navbirth', $data);
}
if (empty($data['users'])) {
    echo $cs_lang['no_data'];
} else {
    $count = empty($options['navbirth_max_users']) ? count($data['users']) : min(count($data['users']), $options['navbirth_max_users']);
    for ($run = 0; $run < $count; $run++) {
        $birth = explode('-', $data['users'][$run]['users_age']);
        $output['users'][$run]['age'] = cs_datereal('Y') - $birth[0];
        $output['users'][$run]['day'] = $birth[2];
        $output['users'][$run]['month'] = $birth[1];
        $output['users'][$run]['year'] = $birth[0];
        $output['users'][$run]['user'] = cs_user($data['users'][$run]['users_id'], $data['users'][$run]['users_nick']);
        $output['users'][$run]['messageurl'] = cs_url('messages', 'create', 'to_id=' . $data['users'][$run]['users_id']);
    }
Beispiel #3
0
<?php

// ClanSphere 2010 - www.clansphere.net
// $Id$
$cs_lang = cs_translate('servers');
$id = empty($_GET['id']) ? 0 : (int) $_GET['id'];
$cache_name = 'servers_list_' . (int) $id;
$cache_time = 60;
$data = cs_cache_load($cache_name, $cache_time);
// Test if fsockopen active
if (empty($data) and fsockopen("udp://127.0.0.1", 1)) {
    $results = array();
    $data = array('servers' => array());
    $data['if']['noquery'] = false;
    $data['if']['server'] = false;
    include_once 'mods/servers/servers.class.php';
    /* Get Server SQL-Data */
    $select = 'servers_name, servers_ip, servers_port, servers_info, servers_query, servers_class, servers_slots, servers_stats, servers_order, servers_id';
    $order = 'servers_order ASC';
    $where = empty($id) ? '' : 'servers_id = \'' . $id . '\'';
    $cs_servers = cs_sql_select(__FILE__, 'servers', $select, $where, $order, 0, 0);
    $servers_count = count($cs_servers);
    /* if no Server in SQL */
    if (empty($servers_count)) {
        unset($data['servers']);
    } else {
        $data['if']['server'] = true;
        /* Settings */
        $objServers = Servers::__getInstance();
        for ($run = 0; $run < $servers_count; $run++) {
            $server_query_ex = explode(";", $cs_servers[$run]['servers_class']);
Beispiel #4
0
function cs_init($predefined)
{
    @error_reporting(E_ALL | E_STRICT);
    @set_error_handler("php_error");
    @ini_set('short_open_tag', 'off');
    @ini_set('arg_separator.output', '&amp;');
    @ini_set('session.use_trans_sid', '0');
    @ini_set('session.use_cookies', '1');
    @ini_set('session.use_only_cookies', '1');
    @ini_set('display_errors', 'on');
    $phpversion = phpversion();
    if (version_compare($phpversion, '5.1', '>=')) {
        @date_default_timezone_set('Europe/Berlin');
    }
    global $account, $com_lang, $cs_db, $cs_logs, $cs_main, $cs_micro, $cs_template;
    $cs_micro = explode(' ', microtime());
    # starting parsetime
    $cs_logs = array('php_errors' => '', 'errors' => '', 'sql' => '', 'queries' => 0, 'warnings' => 1, 'dir' => 'uploads/logs');
    $cs_main['cellspacing'] = 1;
    $cs_main['def_lang'] = empty($cs_main['def_lang']) ? 'English' : $cs_main['def_lang'];
    $cs_main['def_theme'] = empty($cs_main['def_theme']) ? 'base' : $cs_main['def_theme'];
    $cs_main['xsrf_protection'] = true;
    $cs_main['zlib'] = true;
    require_once 'system/core/servervars.php';
    $cs_main['ajaxrequest'] = isset($_REQUEST['xhr']) ? true : false;
    require_once 'system/core/tools.php';
    require_once 'system/core/abcode.php';
    require_once 'system/core/templates.php';
    require_once 'system/core/gd.php';
    require_once 'system/core/cachegen.php';
    $cs_main['cache_mode'] = 'file';
    if (version_compare($phpversion, '5.0', '<')) {
        require_once 'mods/clansphere/fallback.php';
    }
    if ($cs_main['php_self']['basename'] == 'install.php') {
        $account = array('users_id' => 0, 'access_clansphere' => 0, 'access_errors' => 2, 'access_install' => 5);
    } else {
        file_exists('setup.php') ? require_once 'setup.php' : die(cs_error_internal('setup', '<a href="' . $cs_main['php_self']['dirname'] . 'install.php">Installation</a>'));
    }
    if (!in_array($cs_main['cache_mode'], array('file', 'none')) and !extension_loaded($cs_main['cache_mode'])) {
        $cs_main['cache_mode'] = 'file';
    }
    require_once 'system/cache/' . $cs_main['cache_mode'] . '.php';
    if (empty($cs_main['charset'])) {
        $cs_main['charset'] = 'UTF-8';
        die(cs_error_internal(0, 'No charset information found in setup.php'));
    }
    # backfall if json extension is not available
    if (!extension_loaded('json')) {
        require_once 'system/output/json.php';
    }
    require_once 'system/output/xhtml_10.php';
    # add old xhtml functions if needed
    if (!empty($cs_main['xhtml_old'])) {
        require_once 'system/output/xhtml_10_old.php';
    }
    if (!empty($predefined['init_sql'])) {
        require_once 'system/database/' . $cs_db['type'] . '.php';
        $cs_db['con'] = cs_sql_connect($cs_db);
        unset($cs_db['pwd'], $cs_db['user']);
        $cs_options = cs_sql_option(__FILE__, 'clansphere');
        $cs_options['unicode'] = extension_loaded('unicode') ? 1 : 0;
        if (!isset($cs_options['cache_unicode']) or $cs_options['cache_unicode'] != $cs_options['unicode']) {
            cs_cache_clear();
        }
    } else {
        $cs_options = array();
    }
    $cs_main = array_merge($cs_main, $cs_options, $predefined);
    if (empty($cs_main['def_path'])) {
        $cs_main['def_path'] = getcwd();
    }
    # process mod and action data
    $cs_main = cs_content_prepare($cs_main);
    if (!empty($predefined['init_sql'])) {
        require_once 'system/core/account.php';
        $cs_main['def_theme'] = empty($account['users_theme']) ? $cs_main['def_theme'] : $account['users_theme'];
    }
    # determine users language
    $account['users_lang'] = cs_content_lang();
    if (!empty($predefined['init_sql'])) {
        # check for deprecated runstartup behavior
        if (!empty($cs_main['runstartup'])) {
            cs_tasks('system/runstartup');
        }
        # fetch startup files
        $startup = cs_cache_load('startup');
        # fallback to create startup files overview
        if ($startup == false) {
            $startup = cs_cache_dirs('mods', $account['users_lang'], 1);
        }
        # execute startup files
        if (is_array($startup)) {
            foreach ($startup as $mod) {
                $file = $cs_main['def_path'] . '/mods/' . $mod . '/startup.php';
                file_exists($file) ? include_once $file : cs_error($file, 'cs_init - Startup file not found');
            }
        }
    }
    # search for possible mod and action errors
    $cs_main = cs_content_check($cs_main);
    $cs_main['template'] = empty($cs_main['def_tpl']) ? 'clansphere' : $cs_main['def_tpl'];
    $cs_template = cs_template_info($cs_main['template']);
    if (!empty($_GET['template']) and preg_match("=^[_a-z0-9-]+\$=i", $_GET['template'])) {
        $cs_main['template'] = $_GET['template'];
    }
    if (!empty($predefined['init_tpl'])) {
        if ($cs_main['ajaxrequest'] === true) {
            echo cs_ajaxwrap();
        } else {
            echo cs_template($cs_micro, $cs_main['tpl_file']);
        }
    }
}
Beispiel #5
0
function cs_cache_theme($mod, $action)
{
    global $cs_main;
    $tpl_temp = 'thm_' . $cs_main["def_theme"] . '_' . $mod . '_' . $action . '_' . $cs_main['php_self']['filename'];
    $tpl_data = cs_cache_load($tpl_temp);
    $tpl_real = cs_subtemplate_check($mod, $action);
    if ($tpl_real === false) {
        return false;
    } elseif ($tpl_data != false) {
        if ($cs_main['cache_mode'] != 'file' or filemtime($tpl_real) < filemtime('uploads/cache/' . $tpl_temp . '.tmp')) {
            return $tpl_data;
        }
    }
    $tpl_data = file_get_contents($tpl_real);
    # the default template is used since users may have different templates activated
    $tpl_data = str_replace('{page:template}', $cs_main['def_tpl'], $tpl_data);
    # page path does always end with a slash
    $tpl_data = str_replace('{page:path}', $cs_main['php_self']['dirname'], $tpl_data);
    $tpl_data = str_replace('{page:width}', $cs_main['def_width'], $tpl_data);
    $tpl_data = str_replace('{page:cellspacing}', $cs_main['cellspacing'], $tpl_data);
    $tpl_data = preg_replace_callback("={icon:([\\S]*?)}=i", 'cs_icon', $tpl_data);
    $tpl_data = preg_replace_callback('={url(?:_([\\w]*?))?:([\\w]*?)(?:_([\\w]*?)((?::(?:(?:[\\S]*?{[\\S]*?}[\\S]*?)*?|[\\S]*?))*?))?}=i', 'cs_templateurl', $tpl_data);
    return cs_cache_save($tpl_temp, $tpl_data);
}
Beispiel #6
0
function cs_sql_select($cs_file, $sql_table, $sql_select, $sql_where = 0, $sql_order = 0, $first = 0, $max = 1, $cache = 0)
{
    if (!empty($cache) && ($return = cs_cache_load($cache))) {
        return $return;
    }
    global $cs_db;
    $first = $first < 0 ? 0 : (int) $first;
    $max = $max < 0 ? 20 : (int) $max;
    $run = 0;
    $sql_query = 'SELECT ' . $sql_select . ' FROM ' . $cs_db['prefix'] . '_' . $sql_table;
    if (!empty($sql_where)) {
        $sql_query .= ' WHERE ' . $sql_where;
    }
    if (!empty($sql_order)) {
        $sql_query .= ' ORDER BY ' . str_replace('{random}', 'RANDOM()', $sql_order);
    }
    if (!empty($max)) {
        $sql_query .= ' LIMIT ' . $max . ' OFFSET ' . $first;
    }
    $sql_query = str_replace('{pre}', $cs_db['prefix'], $sql_query);
    $sql_data = pg_query($cs_db['con'], $sql_query) or cs_error_sql($cs_file, 'cs_sql_select', cs_sql_error(0, $sql_query));
    if ($max == 1) {
        $new_result = pg_fetch_assoc($sql_data);
    } else {
        while ($sql_result = pg_fetch_assoc($sql_data)) {
            $new_result[$run] = $sql_result;
            $run++;
        }
    }
    pg_free_result($sql_data);
    cs_log_sql($cs_file, $sql_query);
    if (!empty($new_result)) {
        if (!empty($cache)) {
            cs_cache_save($cache, $new_result);
        }
        return $new_result;
    }
    return NULL;
}
Beispiel #7
0
<?php

// ClanSphere 2010 - www.clansphere.net
// $Id$
$time_now = explode('-', date('Y-m-d'));
$output = array();
$data = cs_cache_load('nextbirth');
$cs_lang = cs_translate('users');
$options = cs_sql_option(__FILE__, 'users');
if (empty($data) or $data['day'] != $time_now['2'] . $time_now['1']) {
    $data = array();
    // We need to reset the data array here, else new birthdays will be added to existing cached entries!
    $nextday = cs_datereal('d', cs_time() + $options['nextbirth_time_interval']);
    $nextmonth = cs_datereal('m', cs_time() + $options['nextbirth_time_interval']);
    $data['day'] = $time_now['2'] . $time_now['1'];
    $check_n = $nextmonth == '01' ? (int) 13 . $nextday : (int) $nextmonth . $nextday;
    $check_t = (int) $time_now['1'] . $time_now['2'];
    $select = 'users_id, users_nick, users_age';
    $where = "users_hidden NOT LIKE '%users_age%' AND users_active = 1 ";
    $where .= $nextmonth == $time_now['1'] ? " AND users_age LIKE '%-" . $time_now['1'] . "-%'" : "AND (users_age LIKE '%-" . $time_now['1'] . "-%' OR users_age LIKE '%-" . $nextmonth . "-%')";
    $cs_users = cs_sql_select(__FILE__, 'users', $select, $where, 'users_age', 0, 0);
    if (!empty($cs_users)) {
        $run = 0;
        foreach ($cs_users as $birth_users) {
            $birth = explode('-', $birth_users['users_age']);
            $check_b = $birth[1] == '01' ? (int) 13 . $birth[2] : (int) $birth[1] . $birth[2];
            if ($check_b < $check_n and $check_b >= $check_t) {
                $data['users'][$run]['users_id'] = $birth_users['users_id'];
                $data['users'][$run]['users_nick'] = $birth_users['users_nick'];
                $data['users'][$run]['users_day'] = $birth[2];
                $data['users'][$run]['users_month'] = $birth[1];
Beispiel #8
0
function cs_sql_select($cs_file, $sql_table, $sql_select, $sql_where = 0, $sql_order = 0, $first = 0, $max = 1, $cache = 0)
{
    if (!empty($cache) && ($return = cs_cache_load($cache))) {
        return $return;
    }
    global $cs_db;
    $first = $first < 0 ? 0 : (int) $first;
    $max = $max < 0 ? 20 : (int) $max;
    $new_result = 0;
    $run = 0;
    if ($cs_db['type'] == 'pdo_sqlsrv' and (!empty($max) or $sql_order === '{random}')) {
        $sql_select = ' TOP ' . $max . ' ' . $sql_select;
        if (!empty($first)) {
            $cell = explode(' ', $sql_table);
            $same_qry = ' ' . $cell[0] . '_id FROM ' . $cs_db['prefix'] . '_' . $sql_table;
            $same_qry .= empty($sql_where) ? '' : ' WHERE ' . $sql_where;
            $same_qry .= empty($sql_order) ? '' : ' ORDER BY ' . $sql_order;
            $sql_notin = '(' . $cell[0] . '_id NOT IN (SELECT TOP ' . $first . ' ' . $same_qry . '))';
            $sql_where = empty($sql_where) ? $sql_notin : $sql_notin . ' AND ' . $sql_where;
        }
    }
    $sql_query = 'SELECT ' . $sql_select . ' FROM ' . $cs_db['prefix'] . '_' . $sql_table;
    if (!empty($sql_where)) {
        $sql_query .= ' WHERE ' . $sql_where;
    }
    if (!empty($sql_order)) {
        if ($cs_db['type'] == 'pdo_mysql') {
            $random = 'RAND()';
        } elseif ($cs_db['type'] == 'pdo_sqlsrv') {
            $random = 'NEWID()';
        } else {
            $random = 'RANDOM()';
        }
        $sql_query .= ' ORDER BY ' . str_replace('{random}', $random, $sql_order);
    }
    if ($cs_db['type'] != 'pdo_sqlsrv' and !empty($max)) {
        $limit = $cs_db['type'] == 'pdo_pgsql' ? $max . ' OFFSET ' . $first : $first . ',' . $max;
        $sql_query .= ' LIMIT ' . $limit;
    }
    $sql_query = str_replace('{pre}', $cs_db['prefix'], $sql_query);
    cs_log_sql($cs_file, $sql_query);
    try {
        $sql_data = $cs_db['con']->query($sql_query);
    } catch (PDOException $err) {
        cs_error_sql($cs_file, 'cs_sql_select', cs_sql_error($err, $sql_query));
    }
    if (empty($error)) {
        $new_result = $max == 1 ? $sql_data->fetch(PDO::FETCH_ASSOC) : $sql_data->fetchAll(PDO::FETCH_ASSOC);
        $sql_data = NULL;
    }
    if (!empty($new_result)) {
        if (!empty($cache)) {
            cs_cache_save($cache, $new_result);
        }
        return $new_result;
    }
    return NULL;
}
Beispiel #9
0
        $data['messages']['new'] = $messages_count_new;
    }
    if (empty($data['if']['panel']) and $account['access_contact'] >= 3) {
        $data['contact']['new'] = cs_cache_load('count_mail_unread');
        if ($data['contact']['new'] === false) {
            $data['contact']['new'] = cs_cache_save('count_mail_unread', (int) cs_sql_count(__FILE__, 'mail', 'mail_answered = 0'));
        }
    }
    if (empty($data['if']['panel']) and $account['access_joinus'] >= 3) {
        $data['joinus']['joinus_count'] = cs_cache_load('count_joinus');
        if ($data['joinus']['joinus_count'] === false) {
            $data['joinus']['joinus_count'] = cs_cache_save('count_joinus', (int) cs_sql_count(__FILE__, 'joinus'));
        }
    }
    if (empty($data['if']['panel']) and $account['access_fightus'] >= 3) {
        $data['fightus']['fightus_count'] = cs_cache_load('count_fightus');
        if ($data['fightus']['fightus_count'] === false) {
            $data['fightus']['fightus_count'] = cs_cache_save('count_fightus', (int) cs_sql_count(__FILE__, 'fightus'));
        }
    }
    if (empty($data['if']['panel']) and $account['access_board'] >= 4) {
        $data['boardreport']['boardreport_count'] = cs_cache_load('count_boardreport');
        if ($data['boardreport']['boardreport_count'] === false) {
            $data['boardreport']['boardreport_count'] = cs_cache_save('count_boardreport', (int) cs_sql_count(__FILE__, 'boardreport', 'boardreport_done = 0'));
        }
    }
    if (!empty($data['if']['panel']) and $account['access_clansphere'] >= 3) {
        $data['link']['panel'] = cs_url('clansphere', 'admin', '', 'admin');
    }
    echo cs_subtemplate(__FILE__, $data, 'users', 'navlogin_view' . $style);
}
Beispiel #10
0
 $from = "abonements abo LEFT JOIN {pre}_read red ON (abo.users_id = red.users_id AND abo.threads_id = red.threads_id)\n                               INNER JOIN {pre}_users usr ON abo.users_id = usr.users_id";
 $where = 'abo.threads_id = ' . $data['thread']['threads_id'] . '
         AND abo.users_id != ' . $account['users_id'] . '
         AND usr.users_delete != 1
         AND usr.users_abomail = 1';
 $abo_users = cs_sql_select(__FILE__, $from, 'abo.abonements_id, usr.users_lang, usr.users_email', $where, 0, 0, 0);
 $abo['count'] = empty($abo_users) ? 0 : count($abo_users);
 $abo_lang[$account['users_lang']]['text'] = $cs_lang['abo_mail_text'];
 $abo_lang[$account['users_lang']]['subject'] = $cs_lang['mod2'];
 $pattern1 = '/abo_mail_text\'\\](\\s*)=(\\s*)\'(?<value>.*)\';/';
 $pattern2 = '/mod2\'\\](\\s*)=(\\s*)\'(?<value>.*)\';/';
 $abo['new_time'] = array(cs_time());
 for ($run = 0; $run < $abo['count']; $run++) {
     $abo['lang'] = empty($abo_users[$run]['users_lang']) ? 'English' : $abo_users[$run]['users_lang'];
     if (empty($abo_lang[$abo['lang']]['text'])) {
         $abo_lang[$abo['lang']] = cs_cache_load('lang_abo_' . $abo['lang']);
         if ($abo_lang[$abo['lang']] === FALSE) {
             // read lang-file and search for text- & subject-placeholder
             $fp = fopen($cs_main['def_path'] . '/lang/' . $abo['lang'] . '/board.php', 'r');
             $file_content = '';
             while (!feof($fp)) {
                 $file_content .= fgets($fp, 4096);
             }
             preg_match($pattern1, $file_content, $match);
             $abo_lang[$abo['lang']]['text'] = $match['value'];
             preg_match($pattern2, $file_content, $match);
             $abo_lang[$abo['lang']]['subject'] = $match['value'];
             cs_cache_save('lang_abo_' . $abo['lang'], $abo_lang[$abo['lang']]);
         }
     }
     if (empty($abo_text[$abo['lang']]['text'])) {
Beispiel #11
0
<?php

// ClanSphere 2010 - www.clansphere.net
// $Id$
// Publish News when time has come
global $cs_main, $account;
if ($cs_main['mod'] == 'news' and !empty($account['access_news'])) {
    $next_publish = cs_cache_load('news_publish');
    if ($next_publish === false) {
        $where = 'news_public = 0 AND news_publishs_at != 0';
        $next_publish = cs_sql_select(__FILE__, 'news', 'news_publishs_at', $where, 'news_publishs_at ASC');
        $next_publish = empty($next_publish) ? '0' : $next_publish['news_publishs_at'];
        cs_cache_save('news_publish', $next_publish);
    }
    if ($next_publish != 0 and cs_time() > $next_publish) {
        $cond = 'news_publishs_at != 0 AND news_public = 0 AND news_publishs_at < ' . cs_time();
        $publish = cs_sql_select(__FILE__, 'news', 'news_id, news_publishs_at, news_public', $cond, 0, 0, 0);
        if (!empty($publish)) {
            $count_publish = count($publish);
            for ($run = 0; $run < $count_publish; $run++) {
                cs_sql_update(__FILE__, 'news', array('news_public', 'news_time'), array('1', $publish[$run]['news_publishs_at']), $publish[$run]['news_id']);
            }
        }
        cs_cache_delete('news_publish');
        if (!empty($publish)) {
            include_once 'mods/news/rss.php';
        }
    }
}
Beispiel #12
0
function cs_sql_select($cs_file, $sql_table, $sql_select, $sql_where = 0, $sql_order = 0, $first = 0, $max = 1, $cache = 0)
{
    if (!empty($cache) && ($return = cs_cache_load($cache))) {
        return $return;
    }
    global $cs_db;
    $first = $first < 0 ? 0 : (int) $first;
    $max = $max < 0 ? 20 : (int) $max;
    $run = 0;
    if (!empty($max) or $sql_order === '{random}') {
        $sql_select = ' TOP ' . $max . ' ' . $sql_select;
        if (!empty($first)) {
            $cell = explode(' ', $sql_table);
            $same_qry = ' ' . $cell[0] . '_id FROM ' . $cs_db['prefix'] . '_' . $sql_table;
            $same_qry .= empty($sql_where) ? '' : ' WHERE ' . $sql_where;
            $same_qry .= empty($sql_order) ? '' : ' ORDER BY ' . $sql_order;
            $sql_notin = '(' . $cell[0] . '_id NOT IN (SELECT TOP ' . $first . ' ' . $same_qry . '))';
            $sql_where = empty($sql_where) ? $sql_notin : $sql_notin . ' AND ' . $sql_where;
        }
    }
    $sql_query = 'SELECT ' . $sql_select . ' FROM ' . $cs_db['prefix'] . '_' . $sql_table;
    if (!empty($sql_where)) {
        $sql_query .= ' WHERE ' . $sql_where;
    }
    if (!empty($sql_order)) {
        $sql_query .= ' ORDER BY ' . str_replace('{random}', 'NEWID()', $sql_order);
    }
    $sql_query = str_replace('{pre}', $cs_db['prefix'], $sql_query);
    if (!($sql_data = sqlsrv_query($cs_db['con'], $sql_query))) {
        cs_error_sql($cs_file, 'cs_sql_select', cs_sql_error(0, $sql_query));
        return NULL;
    }
    if ($max == 1) {
        $new_result = sqlsrv_fetch_array($sql_data, SQLSRV_FETCH_ASSOC);
    } else {
        while ($sql_result = sqlsrv_fetch_array($sql_data, SQLSRV_FETCH_ASSOC)) {
            $new_result[$run] = $sql_result;
            $run++;
        }
    }
    sqlsrv_free_stmt($sql_data);
    cs_log_sql($cs_file, $sql_query);
    if (!empty($new_result)) {
        if (!empty($cache)) {
            cs_cache_save($cache, $new_result);
        }
        return $new_result;
    }
    return NULL;
}