root / branches / phpBB-3_0_0 / phpBB / includes / acp / acp_bots.php
History | View | Annotate | Download (11.9 kB)
| 1 | 5303 | acydburn | <?php
|
|---|---|---|---|
| 2 | 8147 | acydburn | /**
|
| 3 | 5303 | acydburn | * |
| 4 | 5303 | acydburn | * @package acp |
| 5 | 5303 | acydburn | * @version $Id$ |
| 6 | 8147 | acydburn | * @copyright (c) 2005 phpBB Group |
| 7 | 8147 | acydburn | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | 5303 | acydburn | * |
| 9 | 5303 | acydburn | */ |
| 10 | 5303 | acydburn | |
| 11 | 5303 | acydburn | /**
|
| 12 | 8147 | acydburn | * @ignore |
| 13 | 8147 | acydburn | */ |
| 14 | 8147 | acydburn | if (!defined('IN_PHPBB')) |
| 15 | 8147 | acydburn | {
|
| 16 | 8147 | acydburn | exit;
|
| 17 | 8147 | acydburn | } |
| 18 | 8147 | acydburn | |
| 19 | 8147 | acydburn | /**
|
| 20 | 5303 | acydburn | * @package acp |
| 21 | 5303 | acydburn | */ |
| 22 | 5303 | acydburn | class acp_bots |
| 23 | 5303 | acydburn | {
|
| 24 | 5558 | acydburn | var $u_action; |
| 25 | 5558 | acydburn | |
| 26 | 5303 | acydburn | function main($id, $mode) |
| 27 | 5303 | acydburn | {
|
| 28 | 5303 | acydburn | global $config, $db, $user, $auth, $template, $cache; |
| 29 | 6015 | acydburn | global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; |
| 30 | 5303 | acydburn | |
| 31 | 5303 | acydburn | $action = request_var('action', ''); |
| 32 | 5303 | acydburn | $submit = (isset($_POST['submit'])) ? true : false; |
| 33 | 5303 | acydburn | $mark = request_var('mark', array(0)); |
| 34 | 5303 | acydburn | $bot_id = request_var('id', 0); |
| 35 | 5303 | acydburn | |
| 36 | 5303 | acydburn | if (isset($_POST['add'])) |
| 37 | 5303 | acydburn | {
|
| 38 | 5303 | acydburn | $action = 'add'; |
| 39 | 5303 | acydburn | } |
| 40 | 5303 | acydburn | |
| 41 | 5303 | acydburn | $error = array(); |
| 42 | 5303 | acydburn | |
| 43 | 5303 | acydburn | $user->add_lang('acp/bots'); |
| 44 | 5303 | acydburn | $this->tpl_name = 'acp_bots'; |
| 45 | 5310 | acydburn | $this->page_title = 'ACP_BOTS'; |
| 46 | 8120 | kellanved | $form_key = 'acp_bots'; |
| 47 | 8120 | kellanved | add_form_key($form_key);
|
| 48 | 5303 | acydburn | |
| 49 | 8120 | kellanved | if ($submit && !check_form_key($form_key)) |
| 50 | 8120 | kellanved | {
|
| 51 | 8120 | kellanved | $error[] = $user->lang['FORM_INVALID']; |
| 52 | 8120 | kellanved | } |
| 53 | 8120 | kellanved | |
| 54 | 5303 | acydburn | // User wants to do something, how inconsiderate of them!
|
| 55 | 5303 | acydburn | switch ($action) |
| 56 | 5303 | acydburn | {
|
| 57 | 5303 | acydburn | case 'activate': |
| 58 | 5303 | acydburn | if ($bot_id || sizeof($mark)) |
| 59 | 5303 | acydburn | {
|
| 60 | 5303 | acydburn | $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')'; |
| 61 | 5303 | acydburn | |
| 62 | 8147 | acydburn | $sql = 'UPDATE ' . BOTS_TABLE . " |
| 63 | 5303 | acydburn | SET bot_active = 1 |
| 64 | 5303 | acydburn | WHERE bot_id $sql_id"; |
| 65 | 5303 | acydburn | $db->sql_query($sql); |
| 66 | 5303 | acydburn | } |
| 67 | 5303 | acydburn | |
| 68 | 7386 | acydburn | $cache->destroy('_bots'); |
| 69 | 5303 | acydburn | break;
|
| 70 | 5303 | acydburn | |
| 71 | 5303 | acydburn | case 'deactivate': |
| 72 | 5303 | acydburn | if ($bot_id || sizeof($mark)) |
| 73 | 5303 | acydburn | {
|
| 74 | 5303 | acydburn | $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')'; |
| 75 | 5303 | acydburn | |
| 76 | 8147 | acydburn | $sql = 'UPDATE ' . BOTS_TABLE . " |
| 77 | 5303 | acydburn | SET bot_active = 0 |
| 78 | 5303 | acydburn | WHERE bot_id $sql_id"; |
| 79 | 5303 | acydburn | $db->sql_query($sql); |
| 80 | 5303 | acydburn | } |
| 81 | 5303 | acydburn | |
| 82 | 7386 | acydburn | $cache->destroy('_bots'); |
| 83 | 5303 | acydburn | break;
|
| 84 | 5303 | acydburn | |
| 85 | 5303 | acydburn | case 'delete': |
| 86 | 5303 | acydburn | if ($bot_id || sizeof($mark)) |
| 87 | 5303 | acydburn | {
|
| 88 | 6719 | acydburn | if (confirm_box(true)) |
| 89 | 6719 | acydburn | {
|
| 90 | 6719 | acydburn | // We need to delete the relevant user, usergroup and bot entries ...
|
| 91 | 6719 | acydburn | $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')'; |
| 92 | 5303 | acydburn | |
| 93 | 8147 | acydburn | $sql = 'SELECT bot_name, user_id |
| 94 | 8147 | acydburn | FROM ' . BOTS_TABLE . " |
| 95 | 6719 | acydburn | WHERE bot_id $sql_id"; |
| 96 | 6719 | acydburn | $result = $db->sql_query($sql); |
| 97 | 5303 | acydburn | |
| 98 | 6719 | acydburn | $user_id_ary = $bot_name_ary = array(); |
| 99 | 6719 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 100 | 6719 | acydburn | {
|
| 101 | 6719 | acydburn | $user_id_ary[] = (int) $row['user_id']; |
| 102 | 6719 | acydburn | $bot_name_ary[] = $row['bot_name']; |
| 103 | 6719 | acydburn | } |
| 104 | 6719 | acydburn | $db->sql_freeresult($result); |
| 105 | 5303 | acydburn | |
| 106 | 6719 | acydburn | $db->sql_transaction('begin'); |
| 107 | 5303 | acydburn | |
| 108 | 8147 | acydburn | $sql = 'DELETE FROM ' . BOTS_TABLE . " |
| 109 | 6719 | acydburn | WHERE bot_id $sql_id"; |
| 110 | 5303 | acydburn | $db->sql_query($sql); |
| 111 | 5303 | acydburn | |
| 112 | 6970 | acydburn | if (sizeof($user_id_ary)) |
| 113 | 6719 | acydburn | {
|
| 114 | 6970 | acydburn | $_tables = array(USERS_TABLE, USER_GROUP_TABLE); |
| 115 | 6970 | acydburn | foreach ($_tables as $table) |
| 116 | 6970 | acydburn | {
|
| 117 | 6970 | acydburn | $sql = "DELETE FROM $table |
| 118 | 6970 | acydburn | WHERE " . $db->sql_in_set('user_id', $user_id_ary); |
| 119 | 6970 | acydburn | $db->sql_query($sql); |
| 120 | 6970 | acydburn | } |
| 121 | 6719 | acydburn | } |
| 122 | 5303 | acydburn | |
| 123 | 6719 | acydburn | $db->sql_transaction('commit'); |
| 124 | 5303 | acydburn | |
| 125 | 7386 | acydburn | $cache->destroy('_bots'); |
| 126 | 6719 | acydburn | |
| 127 | 6719 | acydburn | add_log('admin', 'LOG_BOT_DELETE', implode(', ', $bot_name_ary)); |
| 128 | 6719 | acydburn | trigger_error($user->lang['BOT_DELETED'] . adm_back_link($this->u_action)); |
| 129 | 6719 | acydburn | } |
| 130 | 6719 | acydburn | else
|
| 131 | 6719 | acydburn | {
|
| 132 | 6719 | acydburn | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
| 133 | 6719 | acydburn | 'mark' => $mark, |
| 134 | 6719 | acydburn | 'id' => $bot_id, |
| 135 | 6719 | acydburn | 'mode' => $mode, |
| 136 | 6719 | acydburn | 'action' => $action)) |
| 137 | 6719 | acydburn | ); |
| 138 | 6719 | acydburn | } |
| 139 | 5303 | acydburn | } |
| 140 | 5303 | acydburn | break;
|
| 141 | 5303 | acydburn | |
| 142 | 5303 | acydburn | case 'edit': |
| 143 | 5303 | acydburn | case 'add': |
| 144 | 6073 | acydburn | include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 145 | 6073 | acydburn | |
| 146 | 5303 | acydburn | $bot_row = array( |
| 147 | 7920 | acydburn | 'bot_name' => utf8_normalize_nfc(request_var('bot_name', '', true)), |
| 148 | 5303 | acydburn | 'bot_agent' => request_var('bot_agent', ''), |
| 149 | 5303 | acydburn | 'bot_ip' => request_var('bot_ip', ''), |
| 150 | 5303 | acydburn | 'bot_active' => request_var('bot_active', true), |
| 151 | 5303 | acydburn | 'bot_lang' => request_var('bot_lang', $config['default_lang']), |
| 152 | 5303 | acydburn | 'bot_style' => request_var('bot_style' , $config['default_style']), |
| 153 | 5303 | acydburn | ); |
| 154 | 5303 | acydburn | |
| 155 | 5303 | acydburn | if ($submit) |
| 156 | 5303 | acydburn | {
|
| 157 | 5303 | acydburn | if (!$bot_row['bot_agent'] && !$bot_row['bot_ip']) |
| 158 | 5303 | acydburn | {
|
| 159 | 5303 | acydburn | $error[] = $user->lang['ERR_BOT_NO_MATCHES']; |
| 160 | 5303 | acydburn | } |
| 161 | 5303 | acydburn | |
| 162 | 5303 | acydburn | if ($bot_row['bot_ip'] && !preg_match('#^[\d\.,:]+$#', $bot_row['bot_ip'])) |
| 163 | 5303 | acydburn | {
|
| 164 | 5303 | acydburn | if (!$ip_list = gethostbynamel($bot_row['bot_ip'])) |
| 165 | 5303 | acydburn | {
|
| 166 | 5303 | acydburn | $error[] = $user->lang['ERR_BOT_NO_IP']; |
| 167 | 5303 | acydburn | } |
| 168 | 5303 | acydburn | else
|
| 169 | 5303 | acydburn | {
|
| 170 | 5303 | acydburn | $bot_row['bot_ip'] = implode(',', $ip_list); |
| 171 | 5303 | acydburn | } |
| 172 | 5303 | acydburn | } |
| 173 | 5303 | acydburn | $bot_row['bot_ip'] = str_replace(' ', '', $bot_row['bot_ip']); |
| 174 | 5303 | acydburn | |
| 175 | 6364 | acydburn | // Make sure the admin is not adding a bot with an user agent similar to his one
|
| 176 | 6428 | acydburn | if ($bot_row['bot_agent'] && substr($user->data['session_browser'], 0, 149) === substr($bot_row['bot_agent'], 0, 149)) |
| 177 | 6364 | acydburn | {
|
| 178 | 6364 | acydburn | $error[] = $user->lang['ERR_BOT_AGENT_MATCHES_UA']; |
| 179 | 6364 | acydburn | } |
| 180 | 7809 | kellanved | |
| 181 | 7809 | kellanved | $bot_name = false; |
| 182 | 7809 | kellanved | if ($bot_id) |
| 183 | 7809 | kellanved | {
|
| 184 | 7809 | kellanved | $sql = 'SELECT u.username_clean |
| 185 | 7809 | kellanved | FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . " u |
| 186 | 7809 | kellanved | WHERE b.bot_id = $bot_id |
| 187 | 7809 | kellanved | AND u.user_id = b.user_id";
|
| 188 | 7809 | kellanved | $result = $db->sql_query($sql); |
| 189 | 7809 | kellanved | $row = $db->sql_fetchrow($result); |
| 190 | 7809 | kellanved | $db->sql_freeresult($result); |
| 191 | 6364 | acydburn | |
| 192 | 7809 | kellanved | if (!$bot_row) |
| 193 | 7809 | kellanved | {
|
| 194 | 7809 | kellanved | $error[] = $user->lang['NO_BOT']; |
| 195 | 7809 | kellanved | } |
| 196 | 7809 | kellanved | else
|
| 197 | 7809 | kellanved | {
|
| 198 | 7809 | kellanved | $bot_name = $row['username_clean']; |
| 199 | 7809 | kellanved | } |
| 200 | 7809 | kellanved | } |
| 201 | 7809 | kellanved | if (!$this->validate_botname($bot_row['bot_name'], $bot_name)) |
| 202 | 7809 | kellanved | {
|
| 203 | 7809 | kellanved | $error[] = $user->lang['BOT_NAME_TAKEN']; |
| 204 | 7809 | kellanved | } |
| 205 | 7809 | kellanved | |
| 206 | 5303 | acydburn | if (!sizeof($error)) |
| 207 | 5303 | acydburn | {
|
| 208 | 5303 | acydburn | // New bot? Create a new user and group entry
|
| 209 | 5303 | acydburn | if ($action == 'add') |
| 210 | 5303 | acydburn | {
|
| 211 | 8147 | acydburn | $sql = 'SELECT group_id, group_colour |
| 212 | 8147 | acydburn | FROM ' . GROUPS_TABLE . " |
| 213 | 8147 | acydburn | WHERE group_name = 'BOTS' |
| 214 | 5303 | acydburn | AND group_type = " . GROUP_SPECIAL; |
| 215 | 5303 | acydburn | $result = $db->sql_query($sql); |
| 216 | 5303 | acydburn | $group_row = $db->sql_fetchrow($result); |
| 217 | 5303 | acydburn | $db->sql_freeresult($result); |
| 218 | 5303 | acydburn | |
| 219 | 5303 | acydburn | if (!$group_row) |
| 220 | 5303 | acydburn | {
|
| 221 | 6428 | acydburn | trigger_error($user->lang['NO_BOT_GROUP'] . adm_back_link($this->u_action . "&id=$bot_id&action=$action"), E_USER_WARNING); |
| 222 | 5303 | acydburn | } |
| 223 | 7809 | kellanved | |
| 224 | 5303 | acydburn | |
| 225 | 6073 | acydburn | $user_id = user_add(array( |
| 226 | 8147 | acydburn | 'user_type' => (int) USER_IGNORE, |
| 227 | 8147 | acydburn | 'group_id' => (int) $group_row['group_id'], |
| 228 | 8147 | acydburn | 'username' => (string) $bot_row['bot_name'], |
| 229 | 6803 | acydburn | 'user_regdate' => time(), |
| 230 | 6803 | acydburn | 'user_password' => '', |
| 231 | 6803 | acydburn | 'user_colour' => (string) $group_row['group_colour'], |
| 232 | 6803 | acydburn | 'user_email' => '', |
| 233 | 8147 | acydburn | 'user_lang' => (string) $bot_row['bot_lang'], |
| 234 | 6803 | acydburn | 'user_style' => (int) $bot_row['bot_style'], |
| 235 | 6803 | acydburn | 'user_allow_massemail' => 0, |
| 236 | 6803 | acydburn | )); |
| 237 | 7809 | kellanved | |
| 238 | 5303 | acydburn | $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 239 | 5303 | acydburn | 'user_id' => (int) $user_id, |
| 240 | 8147 | acydburn | 'bot_name' => (string) $bot_row['bot_name'], |
| 241 | 8147 | acydburn | 'bot_active' => (int) $bot_row['bot_active'], |
| 242 | 5303 | acydburn | 'bot_agent' => (string) $bot_row['bot_agent'], |
| 243 | 5303 | acydburn | 'bot_ip' => (string) $bot_row['bot_ip']) |
| 244 | 5303 | acydburn | ); |
| 245 | 5303 | acydburn | $db->sql_query($sql); |
| 246 | 7809 | kellanved | |
| 247 | 5303 | acydburn | $log = 'ADDED'; |
| 248 | 5303 | acydburn | } |
| 249 | 5303 | acydburn | else if ($bot_id) |
| 250 | 5303 | acydburn | {
|
| 251 | 8147 | acydburn | $sql = 'SELECT user_id, bot_name |
| 252 | 8147 | acydburn | FROM ' . BOTS_TABLE . " |
| 253 | 5303 | acydburn | WHERE bot_id = $bot_id"; |
| 254 | 5303 | acydburn | $result = $db->sql_query($sql); |
| 255 | 5303 | acydburn | $row = $db->sql_fetchrow($result); |
| 256 | 5303 | acydburn | $db->sql_freeresult($result); |
| 257 | 5303 | acydburn | |
| 258 | 5303 | acydburn | if (!$row) |
| 259 | 5303 | acydburn | {
|
| 260 | 6320 | acydburn | trigger_error($user->lang['NO_BOT'] . adm_back_link($this->u_action . "&id=$bot_id&action=$action"), E_USER_WARNING); |
| 261 | 5303 | acydburn | } |
| 262 | 5303 | acydburn | |
| 263 | 6770 | acydburn | $sql_ary = array( |
| 264 | 5303 | acydburn | 'user_style' => (int) $bot_row['bot_style'], |
| 265 | 6770 | acydburn | 'user_lang' => (string) $bot_row['bot_lang'], |
| 266 | 6770 | acydburn | ); |
| 267 | 6770 | acydburn | |
| 268 | 6770 | acydburn | if ($bot_row['bot_name'] !== $row['bot_name']) |
| 269 | 6770 | acydburn | {
|
| 270 | 6770 | acydburn | $sql_ary['username'] = (string) $bot_row['bot_name']; |
| 271 | 6770 | acydburn | $sql_ary['username_clean'] = (string) utf8_clean_string($bot_row['bot_name']); |
| 272 | 6770 | acydburn | } |
| 273 | 6770 | acydburn | |
| 274 | 6770 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE user_id = {$row['user_id']}"; |
| 275 | 5303 | acydburn | $db->sql_query($sql); |
| 276 | 5303 | acydburn | |
| 277 | 5303 | acydburn | $sql = 'UPDATE ' . BOTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( |
| 278 | 8147 | acydburn | 'bot_name' => (string) $bot_row['bot_name'], |
| 279 | 8147 | acydburn | 'bot_active' => (int) $bot_row['bot_active'], |
| 280 | 5303 | acydburn | 'bot_agent' => (string) $bot_row['bot_agent'], |
| 281 | 5303 | acydburn | 'bot_ip' => (string) $bot_row['bot_ip']) |
| 282 | 5303 | acydburn | ) . " WHERE bot_id = $bot_id";
|
| 283 | 5303 | acydburn | $db->sql_query($sql); |
| 284 | 5303 | acydburn | |
| 285 | 6770 | acydburn | // Updated username?
|
| 286 | 6770 | acydburn | if ($bot_row['bot_name'] !== $row['bot_name']) |
| 287 | 6770 | acydburn | {
|
| 288 | 6770 | acydburn | user_update_name($row['bot_name'], $bot_row['bot_name']); |
| 289 | 6770 | acydburn | } |
| 290 | 6770 | acydburn | |
| 291 | 5303 | acydburn | $log = 'UPDATED'; |
| 292 | 5303 | acydburn | } |
| 293 | 7810 | kellanved | |
| 294 | 7810 | kellanved | $cache->destroy('_bots'); |
| 295 | 7810 | kellanved | |
| 296 | 7810 | kellanved | add_log('admin', 'LOG_BOT_' . $log, $bot_row['bot_name']); |
| 297 | 8025 | acydburn | trigger_error($user->lang['BOT_' . $log] . adm_back_link($this->u_action)); |
| 298 | 7810 | kellanved | |
| 299 | 5303 | acydburn | } |
| 300 | 5303 | acydburn | } |
| 301 | 5303 | acydburn | else if ($bot_id) |
| 302 | 5303 | acydburn | {
|
| 303 | 8147 | acydburn | $sql = 'SELECT b.*, u.user_lang, u.user_style |
| 304 | 5303 | acydburn | FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . " u |
| 305 | 5303 | acydburn | WHERE b.bot_id = $bot_id |
| 306 | 5303 | acydburn | AND u.user_id = b.user_id";
|
| 307 | 5303 | acydburn | $result = $db->sql_query($sql); |
| 308 | 5303 | acydburn | $bot_row = $db->sql_fetchrow($result); |
| 309 | 5303 | acydburn | $db->sql_freeresult($result); |
| 310 | 5303 | acydburn | |
| 311 | 5303 | acydburn | if (!$bot_row) |
| 312 | 5303 | acydburn | {
|
| 313 | 6320 | acydburn | trigger_error($user->lang['NO_BOT'] . adm_back_link($this->u_action . "&id=$bot_id&action=$action"), E_USER_WARNING); |
| 314 | 5303 | acydburn | } |
| 315 | 5303 | acydburn | |
| 316 | 5303 | acydburn | $bot_row['bot_lang'] = $bot_row['user_lang']; |
| 317 | 5303 | acydburn | $bot_row['bot_style'] = $bot_row['user_style']; |
| 318 | 5303 | acydburn | unset($bot_row['user_lang'], $bot_row['user_style']); |
| 319 | 5303 | acydburn | } |
| 320 | 5303 | acydburn | |
| 321 | 5303 | acydburn | $s_active_options = ''; |
| 322 | 5315 | acydburn | $_options = array('0' => 'NO', '1' => 'YES'); |
| 323 | 5315 | acydburn | foreach ($_options as $value => $lang) |
| 324 | 5303 | acydburn | {
|
| 325 | 5303 | acydburn | $selected = ($bot_row['bot_active'] == $value) ? ' selected="selected"' : ''; |
| 326 | 5303 | acydburn | $s_active_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>'; |
| 327 | 5303 | acydburn | } |
| 328 | 5303 | acydburn | |
| 329 | 5303 | acydburn | $style_select = style_select($bot_row['bot_style'], true); |
| 330 | 5303 | acydburn | $lang_select = language_select($bot_row['bot_lang']); |
| 331 | 5303 | acydburn | |
| 332 | 5303 | acydburn | $l_title = ($action == 'edit') ? 'EDIT' : 'ADD'; |
| 333 | 5303 | acydburn | |
| 334 | 5303 | acydburn | $template->assign_vars(array( |
| 335 | 5303 | acydburn | 'L_TITLE' => $user->lang['BOT_' . $l_title], |
| 336 | 5558 | acydburn | 'U_ACTION' => $this->u_action . "&id=$bot_id&action=$action", |
| 337 | 5558 | acydburn | 'U_BACK' => $this->u_action, |
| 338 | 5303 | acydburn | 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '', |
| 339 | 5303 | acydburn | |
| 340 | 5303 | acydburn | 'BOT_NAME' => $bot_row['bot_name'], |
| 341 | 5303 | acydburn | 'BOT_IP' => $bot_row['bot_ip'], |
| 342 | 5303 | acydburn | 'BOT_AGENT' => $bot_row['bot_agent'], |
| 343 | 5303 | acydburn | |
| 344 | 5303 | acydburn | 'S_EDIT_BOT' => true, |
| 345 | 5303 | acydburn | 'S_ACTIVE_OPTIONS' => $s_active_options, |
| 346 | 5303 | acydburn | 'S_STYLE_OPTIONS' => $style_select, |
| 347 | 5303 | acydburn | 'S_LANG_OPTIONS' => $lang_select, |
| 348 | 5303 | acydburn | 'S_ERROR' => (sizeof($error)) ? true : false, |
| 349 | 5303 | acydburn | ) |
| 350 | 5303 | acydburn | ); |
| 351 | 5303 | acydburn | |
| 352 | 5303 | acydburn | return;
|
| 353 | 5303 | acydburn | |
| 354 | 5303 | acydburn | break;
|
| 355 | 5303 | acydburn | } |
| 356 | 5303 | acydburn | |
| 357 | 5303 | acydburn | $s_options = ''; |
| 358 | 5315 | acydburn | $_options = array('activate' => 'BOT_ACTIVATE', 'deactivate' => 'BOT_DEACTIVATE', 'delete' => 'DELETE'); |
| 359 | 5315 | acydburn | foreach ($_options as $value => $lang) |
| 360 | 5303 | acydburn | {
|
| 361 | 5303 | acydburn | $s_options .= '<option value="' . $value . '">' . $user->lang[$lang] . '</option>'; |
| 362 | 5303 | acydburn | } |
| 363 | 5303 | acydburn | |
| 364 | 5303 | acydburn | $template->assign_vars(array( |
| 365 | 5558 | acydburn | 'U_ACTION' => $this->u_action, |
| 366 | 5303 | acydburn | 'S_BOT_OPTIONS' => $s_options) |
| 367 | 5303 | acydburn | ); |
| 368 | 5303 | acydburn | |
| 369 | 8147 | acydburn | $sql = 'SELECT b.bot_id, b.bot_name, b.bot_active, u.user_lastvisit |
| 370 | 5303 | acydburn | FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . ' u |
| 371 | 5303 | acydburn | WHERE u.user_id = b.user_id |
| 372 | 6719 | acydburn | ORDER BY u.user_lastvisit DESC, b.bot_name ASC';
|
| 373 | 5303 | acydburn | $result = $db->sql_query($sql); |
| 374 | 5303 | acydburn | |
| 375 | 5303 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 376 | 5303 | acydburn | {
|
| 377 | 5303 | acydburn | $active_lang = (!$row['bot_active']) ? 'BOT_ACTIVATE' : 'BOT_DEACTIVATE'; |
| 378 | 5303 | acydburn | $active_value = (!$row['bot_active']) ? 'activate' : 'deactivate'; |
| 379 | 5303 | acydburn | |
| 380 | 5303 | acydburn | $template->assign_block_vars('bots', array( |
| 381 | 5303 | acydburn | 'BOT_NAME' => $row['bot_name'], |
| 382 | 5303 | acydburn | 'BOT_ID' => $row['bot_id'], |
| 383 | 5303 | acydburn | 'LAST_VISIT' => ($row['user_lastvisit']) ? $user->format_date($row['user_lastvisit']) : $user->lang['BOT_NEVER'], |
| 384 | 5303 | acydburn | |
| 385 | 5558 | acydburn | 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&id={$row['bot_id']}&action=$active_value", |
| 386 | 5303 | acydburn | 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang], |
| 387 | 5558 | acydburn | 'U_EDIT' => $this->u_action . "&id={$row['bot_id']}&action=edit", |
| 388 | 5558 | acydburn | 'U_DELETE' => $this->u_action . "&id={$row['bot_id']}&action=delete") |
| 389 | 5303 | acydburn | ); |
| 390 | 5303 | acydburn | } |
| 391 | 5303 | acydburn | $db->sql_freeresult($result); |
| 392 | 5303 | acydburn | } |
| 393 | 7809 | kellanved | |
| 394 | 8025 | acydburn | /**
|
| 395 | 8025 | acydburn | * Validate bot name against username table |
| 396 | 8025 | acydburn | */ |
| 397 | 7809 | kellanved | function validate_botname($newname, $oldname = false) |
| 398 | 7809 | kellanved | {
|
| 399 | 7809 | kellanved | global $db; |
| 400 | 8025 | acydburn | |
| 401 | 7809 | kellanved | if ($oldname && utf8_clean_string($newname) === $oldname) |
| 402 | 7809 | kellanved | {
|
| 403 | 7809 | kellanved | return true; |
| 404 | 7809 | kellanved | } |
| 405 | 8025 | acydburn | |
| 406 | 8025 | acydburn | // Admins might want to use names otherwise forbidden, thus we only check for duplicates.
|
| 407 | 7809 | kellanved | $sql = 'SELECT username |
| 408 | 7809 | kellanved | FROM ' . USERS_TABLE . " |
| 409 | 7809 | kellanved | WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($newname)) . "'"; |
| 410 | 7809 | kellanved | $result = $db->sql_query($sql); |
| 411 | 7809 | kellanved | $row = $db->sql_fetchrow($result); |
| 412 | 7809 | kellanved | $db->sql_freeresult($result); |
| 413 | 7809 | kellanved | |
| 414 | 8025 | acydburn | return ($row) ? false : true; |
| 415 | 7809 | kellanved | } |
| 416 | 5303 | acydburn | } |
| 417 | 5303 | acydburn | |
| 418 | 5303 | acydburn | ?> |

