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