- Timestamp:
- Aug 21, 2004, 3:20:28 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r467 r491 26 26 // +-----------------------------------------------------------------------+ 27 27 28 include(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php'); 29 28 30 $tab_ext_create_TN = array ( 'jpg', 'png', 'JPG', 'PNG' ); 29 31 … … 203 205 array_push($element_ids, $row['id']); 204 206 } 205 delete_elements($element_ids); 207 if (count($element_ids) > 0) 208 { 209 delete_elements($element_ids); 210 } 206 211 207 212 // destruction of the links between images and this category … … 236 241 array_push($subcat_ids, $row['id']); 237 242 } 238 delete_categories($subcat_ids); 243 if (count($subcat_ids) > 0) 244 { 245 delete_categories($subcat_ids); 246 } 239 247 240 248 // destruction of the category … … 254 262 function delete_elements($ids) 255 263 { 264 global $count_deleted; 265 256 266 // destruction of the comments on the image 257 267 $query = ' 258 268 DELETE FROM '.COMMENTS_TABLE.' 259 WHERE image_id IN ( '.implode(',', $ids).')260 ;'; 261 echo '<pre>'.$query.'</pre>';269 WHERE image_id IN ( 270 '.wordwrap(implode(', ', $ids), 80, "\n").') 271 ;'; 262 272 mysql_query($query); 263 273 … … 265 275 $query = ' 266 276 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 267 WHERE image_id IN ('.implode(',', $ids).') 277 WHERE image_id IN ( 278 '.wordwrap(implode(', ', $ids), 80, "\n").') 268 279 ;'; 269 280 mysql_query($query); … … 272 283 $query = ' 273 284 DELETE FROM '.FAVORITES_TABLE.' 274 WHERE image_id IN ('.implode(',', $ids).') 285 WHERE image_id IN ( 286 '.wordwrap(implode(', ', $ids), 80, "\n").') 275 287 ;'; 276 288 mysql_query($query); … … 279 291 $query = ' 280 292 DELETE FROM '.IMAGES_TABLE.' 281 WHERE id IN ('.implode(',', $ids).') 293 WHERE id IN ( 294 '.wordwrap(implode(', ', $ids), 80, "\n").') 282 295 ;'; 283 296 mysql_query($query); 297 298 $count_deleted+= count($ids); 284 299 } 285 300 … … 402 417 } 403 418 404 // update_category updates calculated informations about a category : 405 // date_last and nb_images. It also verifies that the representative picture 406 // is really linked to the category. 407 function update_category( $id = 'all' ) 408 { 409 if ( $id == 'all' ) 410 { 411 $query = 'SELECT id FROM '.CATEGORIES_TABLE.';'; 419 /** 420 * updates calculated informations about a category : date_last and 421 * nb_images. It also verifies that the representative picture is really 422 * linked to the category. Recursive. 423 * 424 * @param mixed category id 425 * @returns void 426 */ 427 function update_category($id = 'all') 428 { 429 $cat_ids = array(); 430 431 $query = ' 432 SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last 433 FROM '.IMAGES_TABLE.' 434 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; 435 if (is_numeric($id)) 436 { 437 $query.= ' 438 WHERE uppercats REGEXP \'(^|,)'.$id.'(,|$)\''; 439 } 440 $query.= ' 441 GROUP BY category_id 442 ;'; 443 $result = mysql_query( $query ); 444 while ( $row = mysql_fetch_array( $result ) ) 445 { 446 array_push($cat_ids, $row['category_id']); 447 $query = ' 448 UPDATE '.CATEGORIES_TABLE.' 449 SET date_last = \''.$row['date_last'].'\' 450 , nb_images = '.$row['count'].' 451 WHERE id = '.$row['category_id'].' 452 ;'; 453 mysql_query($query); 454 } 455 456 if (count($cat_ids) > 0) 457 { 458 $query = ' 459 SELECT id, representative_picture_id 460 FROM '.CATEGORIES_TABLE.' 461 WHERE representative_picture_id IS NOT NULL 462 AND id IN ('.implode(',', $cat_ids).') 463 ;'; 412 464 $result = mysql_query( $query ); 413 465 while ( $row = mysql_fetch_array( $result ) ) 414 466 { 415 // recursive call 416 update_category( $row['id'] ); 417 } 418 } 419 else if ( is_numeric( $id ) ) 420 { 421 // updating the number of pictures 422 $query = 'SELECT COUNT(*) as nb_images'; 423 $query.= ' FROM '.PREFIX_TABLE.'image_category'; 424 $query.= ' WHERE category_id = '.$id; 425 $query.= ';'; 426 list( $nb_images ) = mysql_fetch_array( mysql_query( $query ) ); 427 // updating the date_last 428 $query = 'SELECT MAX(date_available) AS date_available'; 429 $query.= ' FROM '.PREFIX_TABLE.'images'; 430 $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; 431 $query.= ' WHERE category_id = '.$id; 432 $query.= ';'; 433 list( $date_available ) = mysql_fetch_array( mysql_query( $query ) ); 434 435 $query = 'UPDATE '.CATEGORIES_TABLE; 436 $query.= " SET date_last = '".$date_available."'"; 437 $query.= ', nb_images = '.$nb_images; 438 $query.= ' WHERE id = '.$id; 439 $query.= ';'; 440 mysql_query( $query ); 441 442 // updating the representative_picture_id : if the representative 443 // picture of the category is not any more linked to the category, we 444 // have to set representative_picture_id to NULL 445 $query = 'SELECT representative_picture_id'; 446 $query.= ' FROM '.CATEGORIES_TABLE; 447 $query.= ' WHERE id = '.$id; 448 $row = mysql_fetch_array( mysql_query( $query ) ); 449 // if the category has no representative picture (ie 450 // representative_picture_id == NULL) we don't update anything 451 if ( isset( $row['representative_picture_id'] ) ) 452 { 453 $query = 'SELECT image_id'; 454 $query.= ' FROM '.PREFIX_TABLE.'image_category'; 455 $query.= ' WHERE category_id = '.$id; 456 $query.= ' AND image_id = '.$row['representative_picture_id']; 457 $query.= ';'; 467 $query = ' 468 SELECT image_id 469 FROM '.IMAGE_CATEGORY_TABLE.' 470 WHERE category_id = '.$row['id'].' 471 AND image_id = '.$row['representative_picture_id'].' 472 ;'; 458 473 $result = mysql_query( $query ); 459 if ( mysql_num_rows( $result ) == 0)474 if (mysql_num_rows($result) == 0) 460 475 { 461 $query = 'UPDATE '.CATEGORIES_TABLE; 462 $query.= ' SET representative_picture_id = NULL'; 463 $query.= ' WHERE id = '.$id; 464 $query.= ';'; 476 $query = ' 477 UPDATE '.CATEGORIES_TABLE.' 478 SET representative_picture_id = NULL 479 WHERE id = '.$row['id'].' 480 ;'; 465 481 mysql_query( $query ); 466 482 } … … 882 898 return $sub_dirs; 883 899 } 900 901 // my_error returns (or send to standard output) the message concerning the 902 // error occured for the last mysql query. 903 function my_error($header, $echo = true) 904 { 905 $error = $header.'<span style="font-weight:bold;">N°= '.mysql_errno(); 906 $error.= ' -->> '.mysql_error()."</span><br /><br />\n"; 907 if ($echo) 908 { 909 echo $error; 910 } 911 else 912 { 913 return $error; 914 } 915 } 884 916 ?>
Note: See TracChangeset
for help on using the changeset viewer.