[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package ucp 5 * @version $Id: ucp_zebra.php,v 1.37 2006/10/22 13:30:45 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 * ucp_zebra 13 * @package ucp 14 */ 15 class ucp_zebra 16 { 17 var $u_action; 18 19 function main($id, $mode) 20 { 21 global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; 22 23 $submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false; 24 $s_hidden_fields = ''; 25 26 $l_mode = strtoupper($mode); 27 28 if ($submit) 29 { 30 $data = $error = array(); 31 $updated = false; 32 33 $var_ary = array( 34 'usernames' => array(0), 35 'add' => '', 36 ); 37 38 foreach ($var_ary as $var => $default) 39 { 40 $data[$var] = request_var($var, $default, true); 41 } 42 43 if ($data['add']) 44 { 45 $data['add'] = array_map('trim', array_map('utf8_clean_string', explode("\n", $data['add']))); 46 47 // Do these name/s exist on a list already? If so, ignore ... we could be 48 // 'nice' and automatically handle names added to one list present on 49 // the other (by removing the existing one) ... but I have a feeling this 50 // may lead to complaints 51 $sql = 'SELECT z.*, u.username 52 FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u 53 WHERE z.user_id = ' . $user->data['user_id'] . ' 54 AND u.user_id = z.zebra_id'; 55 $result = $db->sql_query($sql); 56 57 $friends = $foes = array(); 58 while ($row = $db->sql_fetchrow($result)) 59 { 60 if ($row['friend']) 61 { 62 $friends[] = utf8_clean_string($row['username']); 63 } 64 else 65 { 66 $foes[] = utf8_clean_string($row['username']); 67 } 68 } 69 $db->sql_freeresult($result); 70 71 // remove friends from the username array 72 $n = sizeof($data['add']); 73 $data['add'] = array_diff($data['add'], $friends); 74 75 if (sizeof($data['add']) < $n && $mode == 'foes') 76 { 77 $error[] = $user->lang['NOT_ADDED_FOES_FRIENDS']; 78 } 79 80 // remove foes from the username array 81 $n = sizeof($data['add']); 82 $data['add'] = array_diff($data['add'], $foes); 83 84 if (sizeof($data['add']) < $n && $mode == 'friends') 85 { 86 $error[] = $user->lang['NOT_ADDED_FRIENDS_FOES']; 87 } 88 89 // remove the user himself from the username array 90 $n = sizeof($data['add']); 91 $data['add'] = array_diff($data['add'], array(utf8_clean_string($user->data['username']))); 92 93 if (sizeof($data['add']) < $n) 94 { 95 $error[] = $user->lang['NOT_ADDED_' . $l_mode . '_SELF']; 96 } 97 98 unset($friends, $foes, $n); 99 100 if (sizeof($data['add'])) 101 { 102 $sql = 'SELECT user_id, user_type 103 FROM ' . USERS_TABLE . ' 104 WHERE ' . $db->sql_in_set('username_clean', $data['add']) . ' 105 AND user_type <> ' . USER_INACTIVE; 106 $result = $db->sql_query($sql); 107 108 $user_id_ary = array(); 109 while ($row = $db->sql_fetchrow($result)) 110 { 111 if ($row['user_id'] != ANONYMOUS && $row['user_type'] != USER_IGNORE) 112 { 113 $user_id_ary[] = $row['user_id']; 114 } 115 else 116 { 117 $error[] = $user->lang['NOT_ADDED_' . $l_mode . '_ANONYMOUS']; 118 } 119 } 120 $db->sql_freeresult($result); 121 122 if (sizeof($user_id_ary)) 123 { 124 // Remove users from foe list if they are admins or moderators 125 if ($mode == 'foes') 126 { 127 $perms = array(); 128 foreach ($auth->acl_get_list($user_id_ary, array('a_', 'm_')) as $forum_id => $forum_ary) 129 { 130 foreach ($forum_ary as $auth_option => $user_ary) 131 { 132 $perms = array_merge($perms, $user_ary); 133 } 134 } 135 136 $perms = array_unique($perms); 137 138 if (sizeof($perms)) 139 { 140 $error[] = $user->lang['NOT_ADDED_FOES_MOD_ADMIN']; 141 } 142 143 // This may not be right ... it may yield true when perms equate to deny 144 $user_id_ary = array_diff($user_id_ary, $perms); 145 unset($perms); 146 } 147 148 if (sizeof($user_id_ary)) 149 { 150 $sql_mode = ($mode == 'friends') ? 'friend' : 'foe'; 151 152 $sql_ary = array(); 153 foreach ($user_id_ary as $zebra_id) 154 { 155 $sql_ary[] = array( 156 'user_id' => $user->data['user_id'], 157 'zebra_id' => (int) $zebra_id, 158 $sql_mode => 1 159 ); 160 } 161 162 $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary); 163 164 $updated = true; 165 } 166 unset($user_id_ary); 167 } 168 else if (!sizeof($error)) 169 { 170 $error[] = $user->lang['USER_NOT_FOUND_OR_INACTIVE']; 171 } 172 } 173 } 174 else if (sizeof($data['usernames'])) 175 { 176 // Force integer values 177 $data['usernames'] = array_map('intval', $data['usernames']); 178 179 $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' 180 WHERE user_id = ' . $user->data['user_id'] . ' 181 AND ' . $db->sql_in_set('zebra_id', $data['usernames']); 182 $db->sql_query($sql); 183 184 $updated = true; 185 } 186 187 if ($updated) 188 { 189 meta_refresh(3, $this->u_action); 190 $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>'); 191 trigger_error($message); 192 } 193 else 194 { 195 $template->assign_var('ERROR', implode('<br />', $error)); 196 } 197 } 198 199 $sql_and = ($mode == 'friends') ? 'z.friend = 1' : 'z.foe = 1'; 200 $sql = 'SELECT z.*, u.username 201 FROM ' . ZEBRA_TABLE . ' z, ' . USERS_TABLE . ' u 202 WHERE z.user_id = ' . $user->data['user_id'] . " 203 AND $sql_and 204 AND u.user_id = z.zebra_id 205 ORDER BY u.username ASC"; 206 $result = $db->sql_query($sql); 207 208 $s_username_options = ''; 209 while ($row = $db->sql_fetchrow($result)) 210 { 211 $s_username_options .= '<option value="' . $row['zebra_id'] . '">' . $row['username'] . '</option>'; 212 } 213 $db->sql_freeresult($result); 214 215 $template->assign_vars(array( 216 'L_TITLE' => $user->lang['UCP_ZEBRA_' . $l_mode], 217 218 'U_SEARCH_USER' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=ucp&field=add'), 219 220 'S_USERNAME_OPTIONS' => $s_username_options, 221 'S_HIDDEN_FIELDS' => $s_hidden_fields, 222 'S_UCP_ACTION' => $this->u_action) 223 ); 224 225 $this->tpl_name = 'ucp_zebra_' . $mode; 226 $this->page_title = 'UCP_ZEBRA_' . $l_mode; 227 } 228 } 229 230 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |