<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');
require('../incfiles/head.php');

/*
-----------------------------------------------------------------
Удалить альбом
-----------------------------------------------------------------
*/
if ($rights == 9) {
    $req_a = mysql_query("SELECT * FROM `album_cat` WHERE `id` = '$al' LIMIT 1");
    if (mysql_num_rows($req_a)) {
        $res_a = mysql_fetch_assoc($req_a);
        echo '<div class="phdr"><b>' . $lng['delete'] . '</b></div>';
        if (isset($_POST['submit'])) {
            $req = mysql_query("SELECT * FROM `album_files` WHERE `album_id` = '" . $res_a['id'] . "'");
            while ($res = mysql_fetch_assoc($req)) {
                // Удаляем файлы фотографий
                @unlink('../files/album/' . $user['id'] . '/' . $res['img_name']);
                @unlink('../files/album/' . $user['id'] . '/' . $res['tmb_name']);
                // Удаляем записи из таблицы голосований
                mysql_query("DELETE FROM `album_votes` WHERE `file_id` = '" . $res['id'] . "'");
            }
            // Удаляем записи из таблиц
            mysql_query("DELETE FROM `album_files` WHERE `album_id` = '" . $res_a['id'] . "'");
            mysql_query("DELETE FROM `album_cat` WHERE `id` = '" . $res_a['id'] . "'");
            mysql_query("OPTIMIZE TABLE `album_cat`");
            mysql_query("OPTIMIZE TABLE `album_files`");
            echo '<div class="menu"><p>' . $lng_profile['album_deleted'] . '<br />' .
                '<a href="?">' . $lng['continue'] . '</a></p></div>';
        } else {
            echo '<div class="rmenu"><form action="?act=delete&amp;al=' . $al . '" method="post">' .
                '<p>' . $lng_profile['album'] . ': <b>' . functions::checkout($res_a['name']) . '</b></p>' .
                '<p>' . $lng_profile['album_delete_warning'] . '</p>' .
                '<p><input type="submit" name="submit" value="' . $lng['delete'] . '"/></p>' .
                '</form></div>';
        }
    } else {
        echo functions::display_error($lng['error_wrong_data']);
    }
}
?>