Changeset 244
- Timestamp:
- Jan 3, 2004, 9:13:42 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/release-1_3/include/functions_category.inc.php
r133 r244 18 18 ***************************************************************************/ 19 19 20 function get_subcats_id( $cat_id )21 {22 $restricted_cats = array();23 24 $query = 'SELECT id';25 $query.= ' FROM '.PREFIX_TABLE.'categories';26 $query.= ' WHERE id_uppercat = '.$cat_id;27 $query.= ';';28 $result = mysql_query( $query );29 while ( $row = mysql_fetch_array( $result ) )30 {31 array_push( $restricted_cats, $row['id'] );32 $sub_restricted_cats = get_subcats_id( $row['id'] );33 foreach ( $sub_restricted_cats as $sub_restricted_cat ) {34 array_push( $restricted_cats, $sub_restricted_cat );35 }36 }37 return $restricted_cats;38 }39 40 20 function check_restrictions( $category_id ) 41 21 { 42 22 global $user,$lang; 43 23 44 if ( i s_user_allowed( $category_id, $user['restrictions'] ) > 0)24 if ( in_array( $category_id, $user['restrictions'] ) ) 45 25 { 46 26 echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; … … 50 30 } 51 31 } 52 32 53 33 // the check_cat_id function check whether the $cat is a right parameter : 54 34 // - $cat is numeric and corresponds to a category in the database … … 62 42 if ( isset( $cat ) ) 63 43 { 64 if ( isset( $page['plain_structure'] ) ) 65 { 66 if ( isset( $page['plain_structure'][$cat] ) ) 67 { 68 $page['cat'] = $cat; 69 } 44 if ( isset( $page['plain_structure'][$cat] ) ) 45 { 46 $page['cat'] = $cat; 70 47 } 71 48 else if ( is_numeric( $cat ) ) … … 74 51 $query.= ' FROM '.PREFIX_TABLE.'categories'; 75 52 $query.= ' WHERE id = '.$cat; 76 $query. ';';53 $query.= ';'; 77 54 $result = mysql_query( $query ); 78 55 if ( mysql_num_rows( $result ) != 0 ) … … 92 69 } 93 70 94 function get_plain_structure() 95 { 96 $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat', 97 'rank','site_id'); 71 function get_user_plain_structure() 72 { 73 global $page,$user; 74 75 $infos = array( 'name','id','uc.date_last','nb_images','dir','id_uppercat', 76 'rank','site_id','nb_sub_categories','uppercats'); 98 77 99 78 $query = 'SELECT '; … … 102 81 $query.= $info; 103 82 } 104 $query.= ' FROM '.PREFIX_TABLE.'categories'; 83 $query.= ' FROM '.PREFIX_TABLE.'categories AS c'; 84 // $query.= ' ,'.PREFIX_TABLE.'user_category AS uc'; 85 $query.= ' INNER JOIN '.PREFIX_TABLE.'user_category AS uc'; 86 $query.= ' ON c.id = uc.category_id'; 87 $query.= ' WHERE user_id = '.$user['id']; 88 if ( $page['expand'] != 'all' ) 89 { 90 $query.= ' AND (id_uppercat is NULL'; 91 if ( count( $page['tab_expand'] ) > 0 ) 92 { 93 $query.= ' OR id_uppercat IN ('.$page['expand'].')'; 94 } 95 $query.= ')'; 96 } 97 if ( $user['forbidden_categories'] != '' ) 98 { 99 $query.= ' AND id NOT IN '; 100 $query.= '('.$user['forbidden_categories'].')'; 101 } 102 // $query.= ' AND c.id = uc.category_id'; 105 103 $query.= ' ORDER BY id_uppercat ASC, rank ASC'; 106 104 $query.= ';'; … … 125 123 } 126 124 127 function create_ structure( $id_uppercat, $restrictions)125 function create_user_structure( $id_uppercat ) 128 126 { 129 127 global $page; 130 128 131 129 if ( !isset( $page['plain_structure'] ) ) 132 $page['plain_structure'] = get_ plain_structure();130 $page['plain_structure'] = get_user_plain_structure(); 133 131 134 132 $structure = array(); 135 $ids = get_ subcat_ids( $id_uppercat );133 $ids = get_user_subcat_ids( $id_uppercat ); 136 134 foreach ( $ids as $id ) { 137 if ( !in_array( $id, $restrictions ) ) 138 { 139 $category = $page['plain_structure'][$id]; 140 $category['subcats'] = create_structure( $id, $restrictions ); 141 array_push( $structure, $category ); 142 } 135 $category = $page['plain_structure'][$id]; 136 $category['subcats'] = create_user_structure( $id ); 137 array_push( $structure, $category ); 143 138 } 144 139 return $structure; 145 140 } 146 141 147 function get_ subcat_ids( $id_uppercat )142 function get_user_subcat_ids( $id_uppercat ) 148 143 { 149 144 global $page; … … 158 153 159 154 // update_structure updates or add informations about each node of the 160 // structure : the last date, should the category be expanded in the menu ?, 161 // the associated expand string "48,14,54" 155 // structure : 162 156 // 163 // 1. last date 164 // for each category of the structure, we have to find the most recent 165 // subcat so that the parent cat has the same last_date info. 166 // For example : we have : 167 // > pets (2003.02.15) 168 // > dogs (2003.06.14) 169 // > rex (2003.06.18) 170 // > toby (2003.06.13) 171 // > kitten (2003.07.05) 172 // We finally want to have : 173 // > pets (2003.07.05) <- changed to pets > kitten last date 174 // > dogs (2003.06.18) <- changed to pets > dogs > rex last date 175 // > rex (2003.06.18) 176 // > toby (2003.06.13) 177 // > kitten (2003.07.05) 178 // 179 // 2. should the category be expanded in the menu ? 157 // 1. should the category be expanded in the menu ? 180 158 // If the category has to be expanded (ie its id is in the 181 159 // $page['tab_expand'] or all the categories must be expanded by default), 182 160 // $category['expanded'] is set to true. 183 161 // 184 // 3. associated expand string162 // 2. associated expand string 185 163 // in the menu, there is a expand string (used in the URL) to tell which 186 164 // categories must be expanded in the menu if this category is chosen … … 192 170 193 171 foreach ( $categories as $category ) { 194 // update the last date of the category195 $last_date = search_last_date( $category );196 $category['date_last'] = $last_date;197 172 // update the "expanded" key 198 173 if ( $user['expand'] … … 206 181 $category['expanded'] = false; 207 182 } 208 // update the 183 // update the "expand_string" key 209 184 if ( $page['expand'] == 'all' ) 210 185 { … … 220 195 $tab_expand = array_diff( $page['tab_expand'],array($category['id']) ); 221 196 } 222 else if ( count( $category['subcats'] )> 0 )197 else if ( $category['nb_sub_categories'] > 0 ) 223 198 { 224 199 // we have this time to add the $category['id']... … … 234 209 235 210 return $updated_categories; 236 }237 238 // search_last_date searchs the last date for a given category. If we take239 // back the example given for update_last_dates, we should have :240 // search_last_date( pets ) --> 2003.07.05241 // search_last_date( pets > dogs ) --> 2003.06.18242 // and so on243 function search_last_date( $category )244 {245 $date_last = $category['date_last'];246 foreach ( $category['subcats'] as $subcat ) {247 $subcat_date_last = search_last_date( $subcat );248 if ( $subcat_date_last > $date_last )249 {250 $date_last = $subcat_date_last;251 }252 }253 return $date_last;254 211 } 255 212 … … 263 220 function count_images( $categories ) 264 221 { 222 return count_user_total_images(); 265 223 $total = 0; 266 224 foreach ( $categories as $category ) { … … 269 227 } 270 228 return $total; 229 } 230 231 function count_user_total_images() 232 { 233 global $user; 234 235 $query = 'SELECT SUM(nb_images) AS total'; 236 $query.= ' FROM '.PREFIX_TABLE.'categories'; 237 if ( count( $user['restrictions'] ) > 0 ) 238 $query.= ' WHERE id NOT IN ('.$user['forbidden_categories'].')'; 239 $query.= ';'; 240 241 $row = mysql_fetch_array( mysql_query( $query ) ); 242 243 return $row['total']; 271 244 } 272 245 … … 290 263 $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir'; 291 264 $query.= ',date_last,uploadable,status,visible,representative_picture_id'; 265 $query.= ',uppercats'; 292 266 $query.= ' FROM '.PREFIX_TABLE.'categories AS a'; 293 267 $query.= ', '.PREFIX_TABLE.'sites AS b'; … … 304 278 $cat['status'] = $row['status']; 305 279 $cat['visible'] = get_boolean( $row['visible'] ); 280 $cat['uppercats'] = $row['uppercats']; 306 281 $cat['representative_picture_id'] = $row['representative_picture_id']; 307 282 308 283 $cat['name'] = array(); 309 284 310 if ( !isset( $page['plain_structure'] ) ) 311 $page['plain_structure'] = get_plain_structure(); 312 313 array_push( $cat['name'], $page['plain_structure'][$id]['name'] ); 314 while ( $page['plain_structure'][$id]['id_uppercat'] != '' ) 315 { 316 $id = $page['plain_structure'][$id]['id_uppercat']; 317 array_push( $cat['name'], $page['plain_structure'][$id]['name'] ); 318 } 285 $query = 'SELECT name'; 286 $query.= ' FROM '.PREFIX_TABLE.'categories'; 287 $query.= ' WHERE id IN ('.$cat['uppercats'].')'; 288 $query.= ' ORDER BY id ASC'; 289 $query.= ';'; 290 $result = mysql_query( $query ); 291 while( $row = mysql_fetch_array( $result ) ) 292 { 293 array_push( $cat['name'], $row['name'] ); 294 } 295 319 296 return $cat; 320 297 } … … 338 315 global $page; 339 316 340 if ( !isset( $page['plain_structure'] ) ) 341 $page['plain_structure'] = get_plain_structure(); 342 343 // creating the local path : "root_cat/sub_cat/sub_sub_cat/" 344 $dir = $page['plain_structure'][$category_id]['dir'].'/'; 345 while ( $page['plain_structure'][$category_id]['id_uppercat'] != '' ) 346 { 347 $category_id = $page['plain_structure'][$category_id]['id_uppercat']; 348 $dir = $page['plain_structure'][$category_id]['dir'].'/'.$dir; 349 } 350 return $dir; 317 $uppercats = ''; 318 $local_dir = ''; 319 320 if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) ) 321 { 322 $uppercats = $page['plain_structure'][$category_id]['uppercats']; 323 } 324 else 325 { 326 $query = 'SELECT uppercats'; 327 $query.= ' FROM '.PREFIX_TABLE.'categories'; 328 $query.= ' WHERE id = '.$category_id; 329 $query.= ';'; 330 $row = mysql_fetch_array( mysql_query( $query ) ); 331 $uppercats = $row['uppercats']; 332 } 333 334 $query = 'SELECT dir'; 335 $query.= ' FROM '.PREFIX_TABLE.'categories'; 336 $query.= ' WHERE id IN ('.$uppercats.')'; 337 $query.= ' ORDER BY id ASC'; 338 $query.= ';'; 339 $result = mysql_query( $query ); 340 while( $row = mysql_fetch_array( $result ) ) 341 { 342 $local_dir.= $row['dir'].'/'; 343 } 344 345 return $local_dir; 351 346 } 352 347 … … 357 352 global $page; 358 353 359 if ( !isset( $page['plain_structure'] ) )360 $page['plain_structure'] = get_plain_structure();361 362 354 $query = 'SELECT galleries_url'; 363 $query.= ' FROM '.PREFIX_TABLE.'sites'; 364 $query.= ' WHERE id = '.$page['plain_structure'][$category_id]['site_id']; 355 $query.= ' FROM '.PREFIX_TABLE.'sites AS s,'.PREFIX_TABLE.'categories AS c'; 356 $query.= ' WHERE s.id = c.site_id'; 357 $query.= ' AND c.id = '.$category_id; 365 358 $query.= ';'; 366 359 $row = mysql_fetch_array( mysql_query( $query ) ); … … 375 368 // - $style : the style of the span tag for the lowest category, 376 369 // "font-style:italic;" for example 377 function get_cat_display_name( $array_cat_names, $separation, $style ) 378 { 379 $output = ""; 380 for ( $i = sizeof( $array_cat_names ) - 1; $i >= 0; $i-- ) 381 { 382 if ( $i != sizeof( $array_cat_names ) - 1 ) 383 { 384 $output.= $separation; 385 } 386 if ( $i != 0 ) 387 { 388 $output.= $array_cat_names[$i]; 389 } 370 function get_cat_display_name( $array_cat_names, $separation, 371 $style, $replace_space = true ) 372 { 373 $output = ''; 374 foreach ( $array_cat_names as $i => $name ) { 375 if ( $i > 0 ) $output.= $separation; 376 if ( $i < count( $array_cat_names ) - 1 or $style == '') 377 $output.= $name; 390 378 else 391 { 392 if ( $style != "" ) 393 { 394 $output.= '<span style="'.$style.'">'; 395 } 396 $output.= $array_cat_names[$i]; 397 if ( $style != "" ) 398 { 399 $output.= "</span>"; 400 } 401 } 402 } 403 return replace_space( $output ); 379 $output.= '<span style="'.$style.'">'.$name.'</span>'; 380 } 381 if ( $replace_space ) return replace_space( $output ); 382 else return $output; 404 383 } 405 384 … … 419 398 function initialize_category( $calling_page = 'category' ) 420 399 { 400 pwg_debug( 'start initialize_category' ); 421 401 global $page,$lang,$user,$conf; 422 402 … … 438 418 $page['cat_site_id'] = $result['site_id']; 439 419 $page['cat_uploadable'] = $result['uploadable']; 440 $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' ); 420 $page['uppercats'] = $result['uppercats']; 421 $page['title'] = get_cat_display_name( $page['cat_name'],' - ','',false); 441 422 $page['where'] = ' WHERE category_id = '.$page['cat']; 442 423 } … … 447 428 { 448 429 // we must not show pictures of a forbidden category 449 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 450 if ( count( $restricted_cats ) > 0 ) 430 if ( $user['forbidden_categories'] != '' ) 451 431 { 452 $where_append.= ' AND category_id NOT IN ('; 453 foreach ( $restricted_cats as $i => $restricted_cat ) { 454 if ( $i > 0 ) $where_append.= ','; 455 $where_append.= $restricted_cat; 456 } 457 $where_append.= ')'; 432 $query.= ' AND category_id NOT IN '; 433 $query.= '('.$user['forbidden_categories'].')'; 458 434 } 459 435 } … … 574 550 $page['title'] = $lang['diapo_default_page_title']; 575 551 } 552 pwg_debug( 'end initialize_category' ); 576 553 } 577 554 … … 605 582 else $query.= '= '.$id_uppercat; 606 583 // we must not show pictures of a forbidden category 607 foreach ( $user['restrictions'] as $restricted_cat ) { 608 $query.= ' AND id != '.$restricted_cat; 584 if ( $user['forbidden_categories'] != '' ) 585 { 586 $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; 609 587 } 610 588 $query.= ' ORDER BY rank'; … … 636 614 $query.= ' WHERE id_uppercat = '.$id_uppercat; 637 615 // we must not show pictures of a forbidden category 638 foreach ( $user['restrictions'] as $restricted_cat ) { 639 $query.= ' AND id != '.$restricted_cat; 616 if ( $user['forbidden_categories'] != '' ) 617 { 618 $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; 640 619 } 641 620 $query.= ' ORDER BY RAND()';
Note: See TracChangeset
for help on using the changeset viewer.