Changeset 11727
- Timestamp:
- Jul 13, 2011, 3:30:06 PM (13 years ago)
- Location:
- branches/2.2/admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/admin/include/functions.php
r11056 r11727 1273 1273 function create_virtual_category($category_name, $parent_id=null) 1274 1274 { 1275 global $conf ;1275 global $conf, $user; 1276 1276 1277 1277 // is the given category name only containing blank spaces ? … … 1361 1361 ;'; 1362 1362 pwg_query($query); 1363 1364 if ('private' == $insert['status']) 1365 { 1366 add_permission_on_category($inserted_id, array_unique(array_merge(get_admins(), array($user['id'])))); 1367 } 1363 1368 1364 1369 return array( … … 2168 2173 } 2169 2174 2175 function add_permission_on_category($category_ids, $user_ids) 2176 { 2177 // array-ify categories and users 2178 if (!is_array($category_ids)) 2179 { 2180 $category_ids = array($category_ids); 2181 } 2182 2183 if (!is_array($user_ids)) 2184 { 2185 $user_ids = array($user_ids); 2186 } 2187 2188 // check for emptiness 2189 if (count($category_ids) == 0 or count($user_ids) == 0) 2190 { 2191 return; 2192 } 2193 2194 // make sure categories are private and select uppercats 2195 $query = ' 2196 SELECT 2197 id 2198 FROM '.CATEGORIES_TABLE.' 2199 WHERE id IN ('.implode(',', get_uppercat_ids($category_ids)).') 2200 AND status = \'private\' 2201 ;'; 2202 $private_uppercats = array_from_query($query, 'id'); 2203 2204 if (count($private_uppercats) == 0) 2205 { 2206 return; 2207 } 2208 2209 // We must not reinsert already existing lines in user_access table 2210 $granteds = array(); 2211 foreach ($private_uppercats as $cat_id) 2212 { 2213 $granteds[$cat_id] = array(); 2214 } 2215 2216 $query = ' 2217 SELECT 2218 user_id, 2219 cat_id 2220 FROM '.USER_ACCESS_TABLE.' 2221 WHERE cat_id IN ('.implode(',', $private_uppercats).') 2222 AND user_id IN ('.implode(',', $user_ids).') 2223 ;'; 2224 $result = pwg_query($query); 2225 while ($row = pwg_db_fetch_assoc($result)) 2226 { 2227 array_push($granteds[$row['cat_id']], $row['user_id']); 2228 } 2229 2230 $inserts = array(); 2231 2232 foreach ($private_uppercats as $cat_id) 2233 { 2234 $grant_to_users = array_diff($user_ids, $granteds[$cat_id]); 2235 2236 foreach ($grant_to_users as $user_id) 2237 { 2238 array_push( 2239 $inserts, 2240 array( 2241 'user_id' => $user_id, 2242 'cat_id' => $cat_id 2243 ) 2244 ); 2245 } 2246 } 2247 2248 if (count($inserts) > 0) 2249 { 2250 mass_inserts(USER_ACCESS_TABLE, array_keys($inserts[0]), $inserts); 2251 } 2252 } 2253 2254 2255 function get_admins($include_webmaster=true) 2256 { 2257 $status_list = array('admin'); 2258 2259 if ($include_webmaster) 2260 { 2261 $status_list[] = 'webmaster'; 2262 } 2263 2264 $query = ' 2265 SELECT 2266 user_id 2267 FROM '.USER_INFOS_TABLE.' 2268 WHERE status in (\''.implode("','", $status_list).'\') 2269 ;'; 2270 2271 return array_from_query($query, 'user_id'); 2272 } 2170 2273 ?> -
branches/2.2/admin/site_update.php
r11040 r11727 315 315 } 316 316 317 // add default permissions to categories 318 $category_ids = array(); 319 foreach ($inserts as $category) 320 { 321 $category_ids[] = $category['id']; 322 } 323 add_permission_on_category($category_ids, get_admins()); 324 317 325 $counts['new_categories'] = count($inserts); 318 326 }
Note: See TracChangeset
for help on using the changeset viewer.