~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/includes/ucp/ucp_zebra.php

Merge setup-stuff.

phpBB is gone, configuration, setup and jail building are completely redone.

Please read doc/setup/install_proc.txt, or you'll not get far.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
*
4
 
* @package ucp
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
8
 
*
9
 
*/
10
 
 
11
 
/**
12
 
* @ignore
13
 
*/
14
 
if (!defined('IN_PHPBB'))
15
 
{
16
 
        exit;
17
 
}
18
 
 
19
 
/**
20
 
* ucp_zebra
21
 
* @package ucp
22
 
*/
23
 
class ucp_zebra
24
 
{
25
 
        var $u_action;
26
 
 
27
 
        function main($id, $mode)
28
 
        {
29
 
                global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
30
 
 
31
 
                $submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false;
32
 
                $s_hidden_fields = '';
33
 
 
34
 
                $l_mode = strtoupper($mode);
35
 
 
36
 
                if ($submit)
37
 
                {
38
 
                        $data = $error = array();
39
 
                        $updated = false;
40
 
 
41
 
                        $var_ary = array(
42
 
                                'usernames'     => array(0),
43
 
                                'add'           => '',
44
 
                        );
45
 
 
46
 
                        foreach ($var_ary as $var => $default)
47
 
                        {
48
 
                                $data[$var] = request_var($var, $default, true);
49
 
                        }
50
 
 
51
 
                        if (!empty($data['add']) || sizeof($data['usernames']))
52
 
                        {
53
 
                                if (confirm_box(true))
54
 
                                {
55
 
                                        if ($data['add'])
56
 
                                        {
57
 
                                                $data['add'] = array_map('trim', array_map('utf8_clean_string', explode("\n", $data['add'])));
58
 
 
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);
68
 
 
69
 
                                                $friends = $foes = array();
70
 
                                                while ($row = $db->sql_fetchrow($result))
71
 
                                                {
72
 
                                                        if ($row['friend'])
73
 
                                                        {
74
 
                                                                $friends[] = utf8_clean_string($row['username']);
75
 
                                                        }
76
 
                                                        else
77
 
                                                        {
78
 
                                                                $foes[] = utf8_clean_string($row['username']);
79
 
                                                        }
80
 
                                                }
81
 
                                                $db->sql_freeresult($result);
82
 
 
83
 
                                                // remove friends from the username array
84
 
                                                $n = sizeof($data['add']);
85
 
                                                $data['add'] = array_diff($data['add'], $friends);
86
 
 
87
 
                                                if (sizeof($data['add']) < $n && $mode == 'foes')
88
 
                                                {
89
 
                                                        $error[] = $user->lang['NOT_ADDED_FOES_FRIENDS'];
90
 
                                                }
91
 
 
92
 
                                                // remove foes from the username array
93
 
                                                $n = sizeof($data['add']);
94
 
                                                $data['add'] = array_diff($data['add'], $foes);
95
 
 
96
 
                                                if (sizeof($data['add']) < $n && $mode == 'friends')
97
 
                                                {
98
 
                                                        $error[] = $user->lang['NOT_ADDED_FRIENDS_FOES'];
99
 
                                                }
100
 
 
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'])));
104
 
 
105
 
                                                if (sizeof($data['add']) < $n)
106
 
                                                {
107
 
                                                        $error[] = $user->lang['NOT_ADDED_' . $l_mode . '_SELF'];
108
 
                                                }
109
 
 
110
 
                                                unset($friends, $foes, $n);
111
 
 
112
 
                                                if (sizeof($data['add']))
113
 
                                                {
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);
119
 
 
120
 
                                                        $user_id_ary = array();
121
 
                                                        while ($row = $db->sql_fetchrow($result))
122
 
                                                        {
123
 
                                                                if ($row['user_id'] != ANONYMOUS && $row['user_type'] != USER_IGNORE)
124
 
                                                                {
125
 
                                                                        $user_id_ary[] = $row['user_id'];
126
 
                                                                }
127
 
                                                                else
128
 
                                                                {
129
 
                                                                        $error[] = $user->lang['NOT_ADDED_' . $l_mode . '_ANONYMOUS'];
130
 
                                                                }
131
 
                                                        }
132
 
                                                        $db->sql_freeresult($result);
133
 
 
134
 
                                                        if (sizeof($user_id_ary))
135
 
                                                        {
136
 
                                                                // Remove users from foe list if they are admins or moderators
137
 
                                                                if ($mode == 'foes')
138
 
                                                                {
139
 
                                                                        $perms = array();
140
 
                                                                        foreach ($auth->acl_get_list($user_id_ary, array('a_', 'm_')) as $forum_id => $forum_ary)
141
 
                                                                        {
142
 
                                                                                foreach ($forum_ary as $auth_option => $user_ary)
143
 
                                                                                {
144
 
                                                                                        $perms = array_merge($perms, $user_ary);
145
 
                                                                                }
146
 
                                                                        }
147
 
 
148
 
                                                                        $perms = array_unique($perms);
149
 
 
150
 
                                                                        if (sizeof($perms))
151
 
                                                                        {
152
 
                                                                                $error[] = $user->lang['NOT_ADDED_FOES_MOD_ADMIN'];
153
 
                                                                        }
154
 
 
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);
157
 
                                                                        unset($perms);
158
 
                                                                }
159
 
 
160
 
                                                                if (sizeof($user_id_ary))
161
 
                                                                {
162
 
                                                                        $sql_mode = ($mode == 'friends') ? 'friend' : 'foe';
163
 
 
164
 
                                                                        $sql_ary = array();
165
 
                                                                        foreach ($user_id_ary as $zebra_id)
166
 
                                                                        {
167
 
                                                                                $sql_ary[] = array(
168
 
                                                                                        'user_id'               => (int) $user->data['user_id'],
169
 
                                                                                        'zebra_id'              => (int) $zebra_id,
170
 
                                                                                        $sql_mode               => 1
171
 
                                                                                );
172
 
                                                                        }
173
 
 
174
 
                                                                        $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary);
175
 
 
176
 
                                                                        $updated = true;
177
 
                                                                }
178
 
                                                                unset($user_id_ary);
179
 
                                                        }
180
 
                                                        else if (!sizeof($error))
181
 
                                                        {
182
 
                                                                $error[] = $user->lang['USER_NOT_FOUND_OR_INACTIVE'];
183
 
                                                        }
184
 
                                                }
185
 
                                        }
186
 
                                        else if (sizeof($data['usernames']))
187
 
                                        {
188
 
                                                // Force integer values
189
 
                                                $data['usernames'] = array_map('intval', $data['usernames']);
190
 
 
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);
195
 
 
196
 
                                                $updated = true;
197
 
                                        }
198
 
 
199
 
                                        if ($updated)
200
 
                                        {
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);
204
 
                                        }
205
 
                                        else
206
 
                                        {
207
 
                                                $template->assign_var('ERROR', implode('<br />', $error));
208
 
                                        }
209
 
                                }
210
 
                                else
211
 
                                {
212
 
                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
213
 
                                                'mode'          => $mode,
214
 
                                                'submit'        => true,
215
 
                                                'usernames'     => $data['usernames'],
216
 
                                                'add'           => $data['add']))
217
 
                                        );
218
 
                                }
219
 
                        }
220
 
                }
221
 
 
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'] . "
226
 
                                AND $sql_and
227
 
                                AND u.user_id = z.zebra_id
228
 
                        ORDER BY u.username_clean ASC";
229
 
                $result = $db->sql_query($sql);
230
 
 
231
 
                $s_username_options = '';
232
 
                while ($row = $db->sql_fetchrow($result))
233
 
                {
234
 
                        $s_username_options .= '<option value="' . $row['zebra_id'] . '">' . $row['username'] . '</option>';
235
 
                }
236
 
                $db->sql_freeresult($result);
237
 
 
238
 
                $template->assign_vars(array(
239
 
                        'L_TITLE'                       => $user->lang['UCP_ZEBRA_' . $l_mode],
240
 
 
241
 
                        'U_FIND_USERNAME'       => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=ucp&amp;field=add'),
242
 
 
243
 
                        'S_USERNAME_OPTIONS'    => $s_username_options,
244
 
                        'S_HIDDEN_FIELDS'               => $s_hidden_fields,
245
 
                        'S_UCP_ACTION'                  => $this->u_action)
246
 
                );
247
 
 
248
 
                $this->tpl_name = 'ucp_zebra_' . $mode;
249
 
                $this->page_title = 'UCP_ZEBRA_' . $l_mode;
250
 
        }
251
 
}
252
 
 
253
 
?>
 
 
b'\\ No newline at end of file'