Changeset 61 for trunk/admin/include
- Timestamp:
- Aug 30, 2003, 5:54:37 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r57 r61 95 95 // It also deletes (in the database) : 96 96 // - all the images of the images (thanks to delete_image, see further) 97 // - all the links between images and this category 97 98 // - all the restrictions linked to the category 98 99 // The function works recursively. … … 102 103 $query = 'SELECT id'; 103 104 $query.= ' FROM '.PREFIX_TABLE.'images'; 104 $query.= ' WHERE cat_id = '.$id;105 $query.= ' WHERE storage_category_id = '.$id; 105 106 $query.= ';'; 106 107 $result = mysql_query( $query ); … … 109 110 delete_image( $row['id'] ); 110 111 } 112 113 // destruction of the links between images and this category 114 $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; 115 $query.= ' WHERE category_id = '.$id; 116 $query.= ';'; 117 mysql_query( $query ); 111 118 112 119 // destruction of the access linked to the category … … 141 148 // It also deletes (in the database) : 142 149 // - all the comments related to the image 150 // - all the links between categories and this image 143 151 // - all the favorites associated to the image 144 152 function delete_image( $id ) … … 151 159 $query.= ';'; 152 160 mysql_query( $query ); 153 161 162 // destruction of the links between images and this category 163 $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; 164 $query.= ' WHERE image_id = '.$id; 165 $query.= ';'; 166 mysql_query( $query ); 167 154 168 // destruction of the favorites associated with the picture 155 169 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; … … 245 259 // retrieving all the favorites for this user and comparing their 246 260 // categories to the restricted categories 247 $query = 'SELECT image_id , cat_id';248 $query.= ' FROM '.PREFIX_TABLE.'favorites , '.PREFIX_TABLE.'images';261 $query = 'SELECT image_id'; 262 $query.= ' FROM '.PREFIX_TABLE.'favorites'; 249 263 $query.= ' WHERE user_id = '.$user_id; 250 $query.= ' AND id = image_id';251 264 $query.= ';'; 252 265 $result = mysql_query ( $query ); 253 266 while ( $row = mysql_fetch_array( $result ) ) 254 267 { 255 if ( in_array( $row['cat_id'], $restricted_cat ) ) 268 // for each picture, we have to check all the categories it belongs 269 // to. Indeed if a picture belongs to category_1 and category_2 and that 270 // category_2 is not restricted to the user, he can have the picture as 271 // favorite. 272 $query = 'SELECT DISTINCT(category_id) as category_id'; 273 $query.= ' FROM '.PREFIX_TABLE.'image_category'; 274 $query.= ' WHERE image_id = '.$row['image_id']; 275 $query.= ';'; 276 $picture_result = mysql_query( $query ); 277 $picture_cat = array(); 278 while ( $picture_row = mysql_fetch_array( $picture_result ) ) 279 { 280 array_push( $picture_cat, $picture_row['category_id'] ); 281 } 282 if ( count( array_diff( $picture_cat, $restricted_cat ) ) > 0 ) 256 283 { 257 284 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; … … 263 290 } 264 291 } 292 293 // update_category updates calculated informations about a category : 294 // date_last and nb_images 295 function update_category( $id = 'all' ) 296 { 297 if ( $id == 'all' ) 298 { 299 $query = 'SELECT id'; 300 $query.= ' FROM '.PREFIX_TABLE.'categories'; 301 $query.= ';'; 302 $result = mysql_query( $query ); 303 while ( $row = mysql_fetch_array( $result ) ) 304 { 305 // recursive call 306 update_category( $row['id'] ); 307 } 308 } 309 else if ( is_numeric( $id ) ) 310 { 311 // updating the number of pictures 312 $query = 'SELECT COUNT(*) as nb_images'; 313 $query.= ' FROM '.PREFIX_TABLE.'image_category'; 314 $query.= ' WHERE category_id = '.$id; 315 $query.= ';'; 316 $row = mysql_fetch_array( mysql_query( $query ) ); 317 $query = 'UPDATE '.PREFIX_TABLE.'categories'; 318 $query.= ' SET nb_images = '.$row['nb_images']; 319 $query.= ' WHERE id = '.$id; 320 $query.= ';'; 321 mysql_query( $query ); 322 // updating the date_last 323 $query = 'SELECT date_available'; 324 $query.= ' FROM '.PREFIX_TABLE.'images'; 325 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; 326 $query.= ' WHERE category_id = '.$id; 327 $query.= ' ORDER BY date_available DESC'; 328 $query.= ' LIMIT 0,1'; 329 $query.= ';'; 330 $row = mysql_fetch_array( mysql_query( $query ) ); 331 $query = 'UPDATE '.PREFIX_TABLE.'categories'; 332 $query.= " SET date_last = '".$row['date_available']."'"; 333 $query.= ' WHERE id = '.$id; 334 $query.= ';'; 335 mysql_query( $query ); 336 } 337 } 338 339 function check_date_format( $date ) 340 { 341 // date arrives at this format : DD/MM/YYYY 342 list($day,$month,$year) = explode( '/', $date ); 343 return checkdate ( $month, $day, $year ); 344 } 345 346 function date_convert( $date ) 347 { 348 // date arrives at this format : DD/MM/YYYY 349 // It must be transformed in YYYY-MM-DD 350 list($day,$month,$year) = explode( '/', $date ); 351 return $year.'-'.$month.'-'.$day; 352 } 353 354 function date_convert_back( $date ) 355 { 356 // date arrives at this format : YYYY-MM-DD 357 // It must be transformed in DD/MM/YYYY 358 if ( $date != '' ) 359 { 360 list($year,$month,$day) = explode( '-', $date ); 361 return $day.'/'.$month.'/'.$year; 362 } 363 else 364 { 365 return ''; 366 } 367 } 368 369 // get_keywords returns an array with relevant keywords found in the string 370 // given in argument. Keywords must be separated by comma in this string. 371 // keywords must : 372 // - be longer or equal to 3 characters 373 // - not contain ', " or blank characters 374 // - unique in the string ("test,test" -> "test") 375 function get_keywords( $keywords_string ) 376 { 377 $keywords = array(); 378 379 $candidates = explode( ',', $keywords_string ); 380 foreach ( $candidates as $candidate ) { 381 if ( strlen($candidate) >= 3 and !preg_match( '/(\'|"|\s)/', $candidate ) ) 382 array_push( $keywords, $candidate ); 383 } 384 385 return array_unique( $keywords ); 386 } 387 388 function display_categories( $categories, $indent ) 389 { 390 global $vtp,$sub; 391 392 foreach ( $categories as $category ) { 393 $vtp->addSession( $sub, 'associate_cat' ); 394 $vtp->setVar( $sub, 'associate_cat.value', $category['id'] ); 395 $content = $indent.'- '.$category['name']; 396 $vtp->setVar( $sub, 'associate_cat.content', $content ); 397 $vtp->closeSession( $sub, 'associate_cat' ); 398 display_categories( $category['subcats'], $indent.str_repeat(' ',3) ); 399 } 400 } 265 401 ?>
Note: See TracChangeset
for help on using the changeset viewer.