Exemplo n.º 1
0
    function delete_album()
    {
        global $cache, $db, $template, $user;
        $s_hidden_fields = build_hidden_fields(array('album_id' => request_var('album_id', 0)));
        if (confirm_box(true)) {
            $album_id = request_var('album_id', 0);
            $left_id = $right_id = 0;
            $deleted_images_na = '';
            $deleted_albums = array();
            // Check for owner
            $sql = 'SELECT album_id, left_id, right_id, parent_id
				FROM ' . GALLERY_ALBUMS_TABLE . '
				WHERE album_user_id = ' . $user->data['user_id'] . '
				ORDER BY left_id ASC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $album[] = $row;
                if ($row['album_id'] == $album_id) {
                    $left_id = $row['left_id'];
                    $right_id = $row['right_id'];
                    $parent_id = $row['parent_id'];
                }
            }
            $db->sql_freeresult($result);
            for ($i = 0, $end = count($album); $i < $end; $i++) {
                if ($left_id <= $album[$i]['left_id'] && $album[$i]['left_id'] <= $right_id) {
                    $deleted_albums[] = $album[$i]['album_id'];
                }
            }
            // $deleted_albums is the array of albums we are going to delete.
            // Now get the images in $deleted_images
            $sql = 'SELECT image_id, image_filename
				FROM ' . GALLERY_IMAGES_TABLE . '
				WHERE ' . $db->sql_in_set('image_album_id', $deleted_albums) . '
				ORDER BY image_id ASC';
            $result = $db->sql_query($sql);
            $deleted_images = $filenames = array();
            while ($row = $db->sql_fetchrow($result)) {
                $deleted_images[] = $row['image_id'];
                $filenames[(int) $row['image_id']] = $row['image_filename'];
            }
            // We have all image_ids in $deleted_images which are deleted.
            // Aswell as the album_ids in $deleted_albums.
            // So now drop the comments, ratings, images and albums.
            if (!empty($deleted_images)) {
                $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . '
					WHERE ' . $db->sql_in_set('comment_image_id', $deleted_images);
                $db->sql_query($sql);
                $sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . '
					WHERE ' . $db->sql_in_set('report_image_id', $deleted_images);
                $db->sql_query($sql);
                $sql = 'DELETE FROM ' . GALLERY_FAVORITES_TABLE . '
					WHERE ' . $db->sql_in_set('image_id', $deleted_images);
                $db->sql_query($sql);
                $sql = 'DELETE FROM ' . GALLERY_WATCH_TABLE . '
					WHERE ' . $db->sql_in_set('image_id', $deleted_images);
                $db->sql_query($sql);
                phpbb_gallery_image_base::delete_images($deleted_images, $filenames);
            }
            $sql = 'DELETE FROM ' . GALLERY_ALBUMS_TABLE . '
				WHERE ' . $db->sql_in_set('album_id', $deleted_albums);
            $db->sql_query($sql);
            // Make sure the overall image & comment count is correct...
            $sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments
				FROM ' . GALLERY_IMAGES_TABLE . '
				WHERE image_status <> ' . phpbb_gallery_image::STATUS_UNAPPROVED;
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            phpbb_gallery_config::set('num_images', $row['num_images']);
            phpbb_gallery_config::set('num_comments', $row['num_comments']);
            $num_images = sizeof($deleted_images);
            if ($num_images) {
                phpbb_gallery_hookup::add_image($user->data['user_id'], 0 - $num_images);
                phpbb_gallery::$user->update_images(0 - $num_images);
            }
            // Maybe we deleted all, so we have to empty phpbb_gallery::$user->get_data('personal_album_id')
            if (in_array(phpbb_gallery::$user->get_data('personal_album_id'), $deleted_albums)) {
                phpbb_gallery::$user->update_data(array('personal_album_id' => 0));
                phpbb_gallery_config::dec('num_pegas', 1);
                if (phpbb_gallery_config::get('newest_pega_album_id') == phpbb_gallery::$user->get_data('personal_album_id')) {
                    // Update the config for the statistic on the index
                    if (phpbb_gallery_config::get('num_pegas') > 0) {
                        $sql_array = array('SELECT' => 'a.album_id, u.user_id, u.username, u.user_colour', 'FROM' => array(GALLERY_ALBUMS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.album_user_id')), 'WHERE' => 'a.album_user_id <> ' . phpbb_gallery_album::PUBLIC_ALBUM . ' AND a.parent_id = 0', 'ORDER_BY' => 'a.album_id DESC');
                        $sql = $db->sql_build_query('SELECT', $sql_array);
                        $result = $db->sql_query_limit($sql, 1);
                        $newest_pgallery = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        phpbb_gallery_config::set('newest_pega_user_id', $newest_pgallery['user_id']);
                        phpbb_gallery_config::set('newest_pega_username', $newest_pgallery['username']);
                        phpbb_gallery_config::set('newest_pega_user_colour', $newest_pgallery['user_colour']);
                        phpbb_gallery_config::set('newest_pega_album_id', $newest_pgallery['album_id']);
                    } else {
                        phpbb_gallery_config::set('newest_pega_user_id', 0);
                        phpbb_gallery_config::set('newest_pega_username', '');
                        phpbb_gallery_config::set('newest_pega_user_colour', '');
                        phpbb_gallery_config::set('newest_pega_album_id', 0);
                    }
                }
            } else {
                // Solve the left_id right_id problem
                $delete_id = $right_id - ($left_id - 1);
                $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\tSET left_id = left_id - {$delete_id}\n\t\t\t\t\tWHERE left_id > {$left_id}\n\t\t\t\t\t\tAND album_user_id = " . $user->data['user_id'];
                $db->sql_query($sql);
                $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . "\n\t\t\t\t\tSET right_id = right_id - {$delete_id}\n\t\t\t\t\tWHERE right_id > {$right_id}\n\t\t\t\t\t\tAND album_user_id = " . $user->data['user_id'];
                $db->sql_query($sql);
            }
            $cache->destroy('sql', GALLERY_ALBUMS_TABLE);
            $cache->destroy('sql', GALLERY_COMMENTS_TABLE);
            $cache->destroy('sql', GALLERY_FAVORITES_TABLE);
            $cache->destroy('sql', GALLERY_IMAGES_TABLE);
            $cache->destroy('sql', GALLERY_RATES_TABLE);
            $cache->destroy('sql', GALLERY_REPORTS_TABLE);
            $cache->destroy('sql', GALLERY_WATCH_TABLE);
            $cache->destroy('_albums');
            phpbb_gallery_auth::set_user_permissions('all', '');
            trigger_error($user->lang['DELETED_ALBUMS'] . '<br /><br />
				<a href="' . ($parent_id ? phpbb_gallery_url::append_sid('phpbb', 'ucp', 'i=gallery&amp;mode=manage_albums&amp;action=manage&amp;parent_id=' . $parent_id) : append_sid('phpbb', 'ucp', 'i=gallery&amp;mode=manage_albums')) . '">' . $user->lang['BACK_TO_PREV'] . '</a>');
        } else {
            $album_id = request_var('album_id', 0);
            phpbb_gallery_album::check_user($album_id);
            confirm_box(false, 'DELETE_ALBUM', $s_hidden_fields);
        }
    }
Exemplo n.º 2
0
    /**
     * Handle user- & total image_counter
     *
     * @param	array	$image_id_ary	array with the image_ids which changed their status
     * @param	bool	$add			are we adding or removing the images
     * @param	bool	$readd			is it possible that there are images which aren't really changed
     */
    public static function handle_counter($image_id_ary, $add, $readd = false)
    {
        global $db;
        $num_images = $num_comments = 0;
        $sql = 'SELECT SUM(image_comments) comments
			FROM ' . GALLERY_IMAGES_TABLE . '
			WHERE image_status ' . ($readd ? '=' : '<>') . ' ' . self::STATUS_UNAPPROVED . '
				AND ' . $db->sql_in_set('image_id', $image_id_ary) . '
			GROUP BY image_user_id';
        $result = $db->sql_query($sql);
        $num_comments = $db->sql_fetchfield('comments');
        $db->sql_freeresult($result);
        $sql = 'SELECT COUNT(image_id) images, image_user_id
			FROM ' . GALLERY_IMAGES_TABLE . '
			WHERE image_status ' . ($readd ? '=' : '<>') . ' ' . self::STATUS_UNAPPROVED . '
				AND ' . $db->sql_in_set('image_id', $image_id_ary) . '
			GROUP BY image_user_id';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $sql_ary = array('user_id' => $row['image_user_id'], 'user_images' => $row['images']);
            phpbb_gallery_hookup::add_image($row['image_user_id'], $add ? $row['images'] : 0 - $row['images']);
            $num_images = $num_images + $row['images'];
            $sql = 'UPDATE ' . GALLERY_USERS_TABLE . '
				SET user_images = user_images ' . ($add ? '+ ' : '- ') . $row['images'] . '
				WHERE ' . $db->sql_in_set('user_id', $row['image_user_id']);
            $db->sql_query($sql);
            if ($db->sql_affectedrows() != 1) {
                $sql = 'INSERT INTO ' . GALLERY_USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
                $db->sql_query($sql);
            }
        }
        $db->sql_freeresult($result);
        if ($add) {
            phpbb_gallery_config::inc('num_images', $num_images);
            phpbb_gallery_config::inc('num_comments', $num_comments);
        } else {
            phpbb_gallery_config::dec('num_images', $num_images);
            phpbb_gallery_config::dec('num_comments', $num_comments);
        }
    }
Exemplo n.º 3
0
                        }
                    } else {
                        $comment_ary = generate_text_for_edit($comment_data['comment'], $comment_data['comment_uid'], $comment_data['comment_bitfield'], 7);
                        $comment = $comment_ary['text'];
                        $comment_username = $comment_data['comment_username'];
                    }
                    $s_album_action = phpbb_gallery_url::append_sid('posting', "mode=comment&amp;submode=edit&amp;album_id={$album_id}&amp;image_id={$image_id}&amp;comment_id={$comment_id}");
                    $page_title = $user->lang['EDIT_COMMENT'];
                    break;
                case 'delete':
                    $s_hidden_fields = build_hidden_fields(array('album_id' => $album_id, 'image_id' => $image_id, 'comment_id' => $comment_id, 'mode' => 'comment', 'submode' => 'delete'));
                    $comment = $comment_username = $comment_username_req = '';
                    if (confirm_box(true)) {
                        $sql = 'DELETE FROM ' . GALLERY_COMMENTS_TABLE . " WHERE comment_id = {$comment_id};";
                        $db->sql_query($sql);
                        phpbb_gallery_config::dec('num_comments', 1);
                        $sql = 'SELECT MAX(comment_id) last_comment
						FROM ' . GALLERY_COMMENTS_TABLE . "\n\t\t\t\t\t\tWHERE comment_image_id = {$image_id}\n\t\t\t\t\t\tORDER BY comment_id";
                        $result = $db->sql_query_limit($sql, 1);
                        $last_comment_id = (int) $db->sql_fetchfield('last_comment');
                        $db->sql_freeresult($result);
                        $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . "\n\t\t\t\t\t\tSET image_comments = image_comments - 1,\n\t\t\t\t\t\t\timage_last_comment = {$last_comment_id}\n\t\t\t\t\t\tWHERE " . $db->sql_in_set('image_id', $image_id);
                        $db->sql_query($sql);
                        if ($user->data['user_id'] != $comment_data['comment_user_id']) {
                            add_log('gallery', $image_data['image_album_id'], $image_data['image_id'], 'LOG_GALLERY_COMMENT_DELETED', $image_data['image_name']);
                        }
                        $submit = true;
                        $message = $user->lang['DELETED_COMMENT'] . '<br />';
                    } else {
                        if (isset($_POST['cancel'])) {
                            $message = $user->lang['DELETED_COMMENT_NOT'] . '<br />';