Changeset 11728
- Timestamp:
- Jul 13, 2011, 3:32:23 PM (13 years ago)
- Location:
- trunk/admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r11487 r11728 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( … … 2184 2189 } 2185 2190 2191 function add_permission_on_category($category_ids, $user_ids) 2192 { 2193 // array-ify categories and users 2194 if (!is_array($category_ids)) 2195 { 2196 $category_ids = array($category_ids); 2197 } 2198 2199 if (!is_array($user_ids)) 2200 { 2201 $user_ids = array($user_ids); 2202 } 2203 2204 // check for emptiness 2205 if (count($category_ids) == 0 or count($user_ids) == 0) 2206 { 2207 return; 2208 } 2209 2210 // make sure categories are private and select uppercats 2211 $query = ' 2212 SELECT 2213 id 2214 FROM '.CATEGORIES_TABLE.' 2215 WHERE id IN ('.implode(',', get_uppercat_ids($category_ids)).') 2216 AND status = \'private\' 2217 ;'; 2218 $private_uppercats = array_from_query($query, 'id'); 2219 2220 if (count($private_uppercats) == 0) 2221 { 2222 return; 2223 } 2224 2225 // We must not reinsert already existing lines in user_access table 2226 $granteds = array(); 2227 foreach ($private_uppercats as $cat_id) 2228 { 2229 $granteds[$cat_id] = array(); 2230 } 2231 2232 $query = ' 2233 SELECT 2234 user_id, 2235 cat_id 2236 FROM '.USER_ACCESS_TABLE.' 2237 WHERE cat_id IN ('.implode(',', $private_uppercats).') 2238 AND user_id IN ('.implode(',', $user_ids).') 2239 ;'; 2240 $result = pwg_query($query); 2241 while ($row = pwg_db_fetch_assoc($result)) 2242 { 2243 array_push($granteds[$row['cat_id']], $row['user_id']); 2244 } 2245 2246 $inserts = array(); 2247 2248 foreach ($private_uppercats as $cat_id) 2249 { 2250 $grant_to_users = array_diff($user_ids, $granteds[$cat_id]); 2251 2252 foreach ($grant_to_users as $user_id) 2253 { 2254 array_push( 2255 $inserts, 2256 array( 2257 'user_id' => $user_id, 2258 'cat_id' => $cat_id 2259 ) 2260 ); 2261 } 2262 } 2263 2264 if (count($inserts) > 0) 2265 { 2266 mass_inserts(USER_ACCESS_TABLE, array_keys($inserts[0]), $inserts); 2267 } 2268 } 2269 2270 2271 function get_admins($include_webmaster=true) 2272 { 2273 $status_list = array('admin'); 2274 2275 if ($include_webmaster) 2276 { 2277 $status_list[] = 'webmaster'; 2278 } 2279 2280 $query = ' 2281 SELECT 2282 user_id 2283 FROM '.USER_INFOS_TABLE.' 2284 WHERE status in (\''.implode("','", $status_list).'\') 2285 ;'; 2286 2287 return array_from_query($query, 'user_id'); 2288 } 2186 2289 ?> -
trunk/admin/site_update.php
r11041 r11728 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.