exit('');
}
$image = null;
if (isset($_POST['id'])) {
    $image = $db->selectObject('imagegallery_image', 'id=' . $_POST['id']);
} else {
    $image->gallery_id = $_POST['parent'];
}
if (isset($_POST['gid'])) {
    $image->gallery_id = $_POST['gid'];
}
$gallery = $db->selectObject('imagegallery_gallery', 'id=' . $image->gallery_id);
$loc = unserialize($gallery->location_data);
$loc->int = $gallery->id;
if (pathos_permissions_check('manage', $loc)) {
    $image = imagegallery_image::update($_POST, $image);
    // Re-order for ranking
    if (isset($image->id)) {
        // changed rank for an existing image
        if ($_POST['rank'] < $image->rank) {
            // New rank is before the current rank. Item moved up
            $db->increment('imagegallery_image', 'rank', 1, 'gallery_id=' . $image->gallery_id . ' AND rank >= ' . $_POST['rank'] . ' AND rank < ' . $image->rank);
        } else {
            if ($_POST['rank'] > $image->rank) {
                // New rank is after the current rank. Item moved down
                $db->decrement('imagegallery_image', 'rank', 1, 'gallery_id=' . $image->gallery_id . ' AND rank < ' . $_POST['rank'] . ' AND rank >= ' . $image->rank);
                $_POST['rank']--;
            }
        }
        // Rank didn't change
        $image->rank = $_POST['rank'];
#
# $Id: edit_image.php,v 1.4 2005/02/24 20:14:14 filetreefrog Exp $
##################################################
if (!defined("PATHOS")) {
    exit("");
}
$image = null;
if (isset($_GET['id'])) {
    $image = $db->selectObject("imagegallery_image", "id=" . $_GET['id']);
}
if (!$image) {
    $image->gallery_id = $_GET['gid'];
}
$gallery = $db->selectObject("imagegallery_gallery", "id=" . $image->gallery_id);
if ($gallery) {
    $loc = unserialize($gallery->location_data);
    $loc->int = $gallery->id;
    if (pathos_permissions_check("manage", $loc)) {
        $form = imagegallery_image::form($image);
        $form->location($loc);
        $form->meta("action", "save_image");
        $template = new template("imagegallerymodule", "_form_editimage", $loc);
        $template->assign("is_edit", isset($image->id) ? 1 : 0);
        $template->assign("form_html", $form->toHTML());
        $template->output();
    } else {
        echo SITE_403_HTML;
    }
} else {
    echo SITE_404_HTML;
}