/**
 * This function creates a new gallery based on the one being copied.
 *
 * @param ADONewConnection $db
 * @param int $old_community_id
 * @param int $old_gallery_page_id
 * @param int $new_community_id
 * @param int $new_parent_id
 * @param int $proxy_id
 * @return array(int, int) on success and 0 on failure.
 */
function create_gallery($db, $old_community_id, $old_gallery_page_id, $new_community_id, $new_parent_id, $proxy_id)
{
    $query = "\tSELECT *\n\t\t\tFROM " . DATABASE_NAME . ".`community_galleries`\n\t\t\tWHERE `community_id` = " . $old_community_id . "\n\t\t\tAND `cpage_id` = " . $old_gallery_page_id;
    $community_gallery_arr = $db->GetRow($query);
    //echo "\nQUERY: " . $query;
    if ($community_gallery_arr) {
        $time = time();
        $gallery = array();
        $gallery["community_id"] = $new_community_id;
        $gallery["cpage_id"] = $new_parent_id;
        $gallery["gallery_title"] = "Image Gallery";
        $gallery["gallery_description"] = "Image Gallery";
        $gallery["gallery_cgphoto_id"] = 0;
        $gallery["gallery_order"] = $community_gallery_arr["gallery_order"];
        $gallery["gallery_active"] = $community_gallery_arr["gallery_active"];
        $gallery["admin_notifications"] = $community_gallery_arr["admin_notifications"];
        $gallery["allow_public_read"] = $community_gallery_arr["allow_public_read"];
        $gallery["allow_public_upload"] = $community_gallery_arr["allow_public_upload"];
        $gallery["allow_public_comment"] = $community_gallery_arr["allow_public_comment"];
        $gallery["allow_troll_read"] = $community_gallery_arr["allow_troll_read"];
        $gallery["allow_troll_upload"] = $community_gallery_arr["allow_troll_upload"];
        $gallery["allow_troll_comment"] = $community_gallery_arr["allow_troll_comment"];
        $gallery["allow_member_read"] = $community_gallery_arr["allow_member_read"];
        $gallery["allow_member_upload"] = $community_gallery_arr["allow_member_upload"];
        $gallery["allow_member_comment"] = $community_gallery_arr["allow_member_comment"];
        $gallery["release_date"] = $time;
        $gallery["release_until"] = 0;
        $gallery["updated_date"] = $time;
        $gallery["updated_by"] = $proxy_id;
        $db->AutoExecute("" . DATABASE_NAME . ".community_galleries", $gallery, "INSERT");
        $new_gallery_id = $db->Insert_Id();
        output_success("Created new gallery with id: " . $new_gallery_id);
        return array("new_gallery_id" => $new_gallery_id, "old_gallery_id" => $community_gallery_arr["cgallery_id"]);
    } else {
        output_error("Community Gallery not found.");
        return 0;
    }
}