4images Forum & Community

4images Help / Hilfe => Bug Fixes & Patches => Topic started by: Chris on March 16, 2005, 04:26:57 AM

Title: [1.7 / 1.7.1] Deleting an image does not remove it from lightboxes
Post by: Chris on March 16, 2005, 04:26:57 AM
Quote
When I, as an admin, delete an image, its ID remains in lightbox table, so it still counts for the user who had it in his lightbox. I've tried a search but nothing, is there a way to solve this? I show in user_logininfo the total number of images the user has in his lightbox, but after deleting one of them it is still counted...

Here is the fix:

in admin/images.php find:

Code: [Select]
  $sql = "SELECT image_id, cat_id, user_id, image_name, image_media_file, image_thumb_file
          FROM ".IMAGES_TABLE."
          WHERE image_id IN ($image_ids)";
  $image_result = $site_db->query($sql);
  while ($image_row = $site_db->fetch_array($image_result)) {

replace it with:
Code: [Select]
  $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_media_file, i.image_thumb_file, l.lightbox_image_ids
          FROM ".IMAGES_TABLE." i
          LEFT JOIN ".LIGHTBOXES_TABLE." l ON (l.user_id = i.user_id)
          WHERE i.image_id IN ($image_ids)";
  $image_result = $site_db->query($sql);
  while ($image_row = $site_db->fetch_array($image_result)) {
    if ($image_row['user_id'] != GUEST)
    {
      $lightbox_array = explode(" ",$image_row['lightbox_image_ids']);
      foreach ($lightbox_array as $key => $val) {
        if ($val == $image_row['image_id']) {
          unset($lightbox_array[$key]);
        }
      }
      $lightbox_image_ids = trim(implode(" ", $lightbox_array));
      $sql = "UPDATE ".LIGHTBOXES_TABLE."
              SET lightbox_image_ids = '".$lightbox_image_ids."'
              WHERE user_id = ".$image_row['user_id'];
      $site_db->query($sql);
    }

This should work as with original admin/images.php as with the v2.x and v3.x from the MODs forum. But it will not work for GUESTs ("Lighbox for guests" MOD)