<?php

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

/*
-----------------------------------------------------------------
Перемещение картинки в другой альбом
-----------------------------------------------------------------
*/
if ($rights == 9) {
    $req = mysql_query("SELECT * FROM `album_files` WHERE `id` = '$img'");
    if (mysql_num_rows($req)) {
        $image = mysql_fetch_assoc($req);
        echo '<div class="phdr"><b>' . $lng_profile['image_move'] . '</b></div>';
        if (isset($_POST['submit'])) {
            $req_a = mysql_query("SELECT * FROM `album_cat` WHERE `id` = '$al'");
            if (mysql_num_rows($req_a)) {
                $res_a = mysql_fetch_assoc($req_a);
                mysql_query("UPDATE `album_files` SET
                    `album_id` = '$al',
                    WHERE `id` = '$img'
                ");
                echo '<div class="gmenu"><p>' . $lng_profile['image_moved'] . '<br />' .
                    '<a href="?act=show&amp;al=' . $al . '">' . $lng['continue'] . '</a></p></div>';
            } else {
                echo functions::display_error($lng['error_wrong_data']);
            }
        } else {
            $req = mysql_query("SELECT * FROM `album_cat` WHERE `id` != '" . $image['album_id'] . "' ORDER BY `sort` ASC");
            if (mysql_num_rows($req)) {
                echo '<form action="?act=image_move&amp;img=' . $img . '" method="post">' .
                    '<div class="menu"><p><h3>' . $lng_profile['album_select'] . '</h3>' .
                    '<select name="al">';
                while ($res = mysql_fetch_assoc($req)) {
                    echo '<option value="' . $res['id'] . '">' . functions::checkout($res['name']) . '</option>';
                }
                echo '</select></p>' .
                    '<p><input type="submit" name="submit" value="' . $lng['move'] . '"/></p>' .
                    '</div></form>' .
                    '<div class="phdr"><a href="?act=show&amp;al=' . $image['album_id'] . '">' . $lng['cancel'] . '</a></div>';
            } else {
                echo functions::display_error($lng_profile['image_move_error'], '<a href="?">' . $lng['continue'] . '</a>');
            }
        }
    } else {
        echo functions::display_error($lng['error_wrong_data']);
    }
}
?>