<?php

/*
////////////////////////////////////////////////////////////////////////////////
// JohnCMS                Mobile Content Management System                    //
// Project site:          http://johncms.com                                  //
// Support site:          http://gazenwagen.com                               //
////////////////////////////////////////////////////////////////////////////////
// Lead Developer:        Oleg Kasyanov   (AlkatraZ)  alkatraz@gazenwagen.com //
// Development Team:      Eugene Ryabinin (john77)    john77@gazenwagen.com   //
//                        Dmitry Liseenko (FlySelf)   flyself@johncms.com     //
////////////////////////////////////////////////////////////////////////////////
*/

defined('_IN_JOHNCMS') or die('Error: restricted access');

require('../incfiles/head.php');

/*
-----------------------------------------------------------------
Перемещение картинки в другой альбом
-----------------------------------------------------------------
*/
if ($img && $user['id'] == $user_id || $rights >= 6) {
    $req = mysql_query("SELECT * FROM `cms_album_files` WHERE `id` = '$img' AND `user_id` = '" . $user['id'] . "'");
    if (mysql_num_rows($req)) {
        $image = mysql_fetch_assoc($req);
        echo '<div class="phdr"><a href="index.php?act=show&amp;al=' . $image['album_id'] . '&amp;user=' . $user['id'] . '"><b>Фотоальбом</b></a> | Переместить фото</div>';
        if (isset($_POST['submit'])) {
            $req_a = mysql_query("SELECT * FROM `cms_album_cat` WHERE `id` = '$al' AND `user_id` = '" . $user['id'] . "'");
            if (mysql_num_rows($req_a)) {
                $res_a = mysql_fetch_assoc($req_a);
                mysql_query("UPDATE `cms_album_files` SET
                    `album_id` = '$al',
                    `access` = '" . $res_a['access'] . "'
                    WHERE `id` = '$img'
                ");
                echo '<div class="gmenu"><p>Фото перемещено<br />' .
                    '<a href="index.php?act=show&amp;al=' . $al . '&amp;user=' . $user['id'] . '">Продолжить</a></p></div>';
            } else {
                echo display_error('Неверные данные');
            }
        } else {
            $req = mysql_query("SELECT * FROM `cms_album_cat` WHERE `user_id` = '" . $user['id'] . "' AND `id` != '" . $image['album_id'] . "' ORDER BY `sort` ASC");
            if (mysql_num_rows($req)) {
                echo '<form action="index.php?act=image_move&amp;img=' . $img . '&amp;user=' . $user['id'] . '" method="post">' .
                    '<div class="menu"><p><h3>Выбрать альбом</h3>' .
                    '<select name="al">';
                while ($res = mysql_fetch_assoc($req)) {
                    echo '<option value="' . $res['id'] . '">' . checkout($res['name']) . '</option>';
                }
                echo '</select></p>' .
                    '<p><input type="submit" name="submit" value="Переместить"/></p>' .
                    '</div></form>' .
                    '<div class="phdr"><a href="index.php?act=show&amp;al=' . $image['album_id'] . '&amp;user=' . $user['id'] . '">Отмена</a></div>';
            } else {
                echo display_error('Ошибка перемещения', '<a href="index.php?act=list&amp;user=' . $user['id'] . '">Продолжить</a>');
            }
        }
    } else {
        display_error('Неверные данные');
    }
}