5
* @version $Id: ucp_zebra.php,v 1.44 2007/10/05 14:36:34 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
27
function main($id, $mode)
29
global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
31
$submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false;
32
$s_hidden_fields = '';
34
$l_mode = strtoupper($mode);
38
$data = $error = array();
42
'usernames' => array(0),
46
foreach ($var_ary as $var => $default)
48
$data[$var] = request_var($var, $default, true);
51
if (!empty($data['add']) || sizeof($data['usernames']))
53
if (confirm_box(true))
57
$data['add'] = array_map('trim', array_map('utf8_clean_string', explode("\n", $data['add'])));
59
// Do these name/s exist on a list already? If so, ignore ... we could be
60
// 'nice' and automatically handle names added to one list present on
61
// the other (by removing the existing one) ... but I have a feeling this
62
// may lead to complaints
63
$sql = 'SELECT z.*, u.username, u.username_clean
64
FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
65
WHERE z.user_id = ' . $user->data['user_id'] . '
66
AND u.user_id = z.zebra_id';
67
$result = $db->sql_query($sql);
69
$friends = $foes = array();
70
while ($row = $db->sql_fetchrow($result))
74
$friends[] = utf8_clean_string($row['username']);
78
$foes[] = utf8_clean_string($row['username']);
81
$db->sql_freeresult($result);
83
// remove friends from the username array
84
$n = sizeof($data['add']);
85
$data['add'] = array_diff($data['add'], $friends);
87
if (sizeof($data['add']) < $n && $mode == 'foes')
89
$error[] = $user->lang['NOT_ADDED_FOES_FRIENDS'];
92
// remove foes from the username array
93
$n = sizeof($data['add']);
94
$data['add'] = array_diff($data['add'], $foes);
96
if (sizeof($data['add']) < $n && $mode == 'friends')
98
$error[] = $user->lang['NOT_ADDED_FRIENDS_FOES'];
101
// remove the user himself from the username array
102
$n = sizeof($data['add']);
103
$data['add'] = array_diff($data['add'], array(utf8_clean_string($user->data['username'])));
105
if (sizeof($data['add']) < $n)
107
$error[] = $user->lang['NOT_ADDED_' . $l_mode . '_SELF'];
110
unset($friends, $foes, $n);
112
if (sizeof($data['add']))
114
$sql = 'SELECT user_id, user_type
115
FROM ' . USERS_TABLE . '
116
WHERE ' . $db->sql_in_set('username_clean', $data['add']) . '
117
AND user_type <> ' . USER_INACTIVE;
118
$result = $db->sql_query($sql);
120
$user_id_ary = array();
121
while ($row = $db->sql_fetchrow($result))
123
if ($row['user_id'] != ANONYMOUS && $row['user_type'] != USER_IGNORE)
125
$user_id_ary[] = $row['user_id'];
129
$error[] = $user->lang['NOT_ADDED_' . $l_mode . '_ANONYMOUS'];
132
$db->sql_freeresult($result);
134
if (sizeof($user_id_ary))
136
// Remove users from foe list if they are admins or moderators
140
foreach ($auth->acl_get_list($user_id_ary, array('a_', 'm_')) as $forum_id => $forum_ary)
142
foreach ($forum_ary as $auth_option => $user_ary)
144
$perms = array_merge($perms, $user_ary);
148
$perms = array_unique($perms);
152
$error[] = $user->lang['NOT_ADDED_FOES_MOD_ADMIN'];
155
// This may not be right ... it may yield true when perms equate to deny
156
$user_id_ary = array_diff($user_id_ary, $perms);
160
if (sizeof($user_id_ary))
162
$sql_mode = ($mode == 'friends') ? 'friend' : 'foe';
165
foreach ($user_id_ary as $zebra_id)
168
'user_id' => (int) $user->data['user_id'],
169
'zebra_id' => (int) $zebra_id,
174
$db->sql_multi_insert(ZEBRA_TABLE, $sql_ary);
180
else if (!sizeof($error))
182
$error[] = $user->lang['USER_NOT_FOUND_OR_INACTIVE'];
186
else if (sizeof($data['usernames']))
188
// Force integer values
189
$data['usernames'] = array_map('intval', $data['usernames']);
191
$sql = 'DELETE FROM ' . ZEBRA_TABLE . '
192
WHERE user_id = ' . $user->data['user_id'] . '
193
AND ' . $db->sql_in_set('zebra_id', $data['usernames']);
194
$db->sql_query($sql);
201
meta_refresh(3, $this->u_action);
202
$message = $user->lang[$l_mode . '_UPDATED'] . '<br />' . implode('<br />', $error) . ((sizeof($error)) ? '<br />' : '') . '<br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
203
trigger_error($message);
207
$template->assign_var('ERROR', implode('<br />', $error));
212
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
215
'usernames' => $data['usernames'],
216
'add' => $data['add']))
222
$sql_and = ($mode == 'friends') ? 'z.friend = 1' : 'z.foe = 1';
223
$sql = 'SELECT z.*, u.username, u.username_clean
224
FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u
225
WHERE z.user_id = ' . $user->data['user_id'] . "
227
AND u.user_id = z.zebra_id
228
ORDER BY u.username_clean ASC";
229
$result = $db->sql_query($sql);
231
$s_username_options = '';
232
while ($row = $db->sql_fetchrow($result))
234
$s_username_options .= '<option value="' . $row['zebra_id'] . '">' . $row['username'] . '</option>';
236
$db->sql_freeresult($result);
238
$template->assign_vars(array(
239
'L_TITLE' => $user->lang['UCP_ZEBRA_' . $l_mode],
241
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=ucp&field=add'),
243
'S_USERNAME_OPTIONS' => $s_username_options,
244
'S_HIDDEN_FIELDS' => $s_hidden_fields,
245
'S_UCP_ACTION' => $this->u_action)
248
$this->tpl_name = 'ucp_zebra_' . $mode;
249
$this->page_title = 'UCP_ZEBRA_' . $l_mode;
b'\\ No newline at end of file'