po/src/folder.php

264 lines
8.8 KiB
PHP

<?php
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
include_once "include/config.php";
include_once "include/common.php";
include_once "include/site.php";
include_once "include/orderby.php";
$folder_id = pg_escape_string($database, $_REQUEST['folder']);
$offset = pg_escape_string($database, isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0);
if ($offset && !is_numeric($offset)) {
$offset = 0;
}
$database = site_prolog();
$folder = FALSE;
if ($folder_id && is_numeric($folder_id)) {
$folder = pg_fetch_row(pg_query($database, "select caption, access_rights, users, description, password, can_access_folder(folder.identifier, $po_user[id], '{".$passwords."}'), orderby from folder where identifier='$folder_id'"));
}
if (!$folder) {
header("HTTP/1.1 404 Not found");
site_header($strings['generic_display_folder']);
site_navigator(1);
site_navigator_status(disp_user_string($database, 0). " : ". $strings['errors_no_such_folder'], "");
site_footer($database);
site_epilog($database);
exit();
}
if ($folder[5] == 'f') {
if ($folder[1] == $access['private']) {
header("HTTP/1.1 403 Forbidden");
site_header($strings['generic_display_folder']);
site_navigator(1);
site_navigator_status(disp_user_string($database, 0). " : ". $strings['errors_private'], "");
site_footer($database);
site_epilog($database);
} else {
site_push_error($strings['errors_protected']);
header("Location: $site_url/login.php?reason=protected&orig=".urlencode(generate_link('folder', $folder_id)));
}
exit();
}
/* get the last value from the database */
$folder_name = $folder[0];
$owner_id = $folder[2];
/* Set up folder order/view */
$order_by = $folder[6];
if (isset($po_options["folder_".$folder_id."_order"])) {
$order_by = $po_options["folder_".$folder_id."_order"];
}
if ($order_by === FALSE || !isset($order_by_string[$order_by])) {
$order_by = $po_options['order_by'];
}
$photo_view = FALSE;
if (isset($po_options["folder_".$folder_id."_view"])) {
$photo_view = $po_options["folder_".$folder_id."_view"];
}
if ($photo_view === FALSE) {
$photo_view = $po_options['photo_view'];
}
$rss = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$site_title : $folder_name - RSS\" href=\"$site_url/feed.php?type=photos&amp;subtype=folder&amp;id=$folder_id\" />\n";
$rss .= "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$site_title : $folder_name - RSS Folders\" href=\"$site_url/feed.php?type=folder&amp;subtype=&amp;id=$folder_id\" />";
site_header($folder_name, "", $rss);
$user_display_string = disp_user_string($database, $owner_id);
$master = "and photo_version.master = 't'";
$froms = array('folder');
$filter = "photo.folder = '$folder_id'
and folder.identifier = photo.folder
$master";
$num_of_photos = get_photo_count($database, $froms, $filter);
if ($photo_view == "slide") {
$limit = $po_options['photos_per_page'];
} else {
$limit = $po_options['rows_list_view'];
}
/* Sanity checks */
if ($limit > $num_of_photos) {
$limit = $num_of_photos;
}
while ($num_of_photos && $offset >= $num_of_photos) {
$offset -= $limit;
}
if ($offset < 0) {
$offset = 0;
}
if (($offset + $limit) > $num_of_photos) {
$items = $num_of_photos - $offset;
} else {
$items = $limit;
}
$path_to_folder = get_path_to_folder($database, $folder_id);
if (($po_user['id'] == $owner_id) &&
($folder_id != $po_user['trash_folder']))
$edit_folder = "[<a href=\"folder.edit.php?folder=$folder_id\">".$strings['generic_edit']."</a>]";
else
$edit_folder = "";
site_navigator(5);
if ($num_of_photos == 0) {
site_navigator_status("$user_display_string $path_to_folder $edit_folder", $strings['generic_is_empty']);
if ($folder[3] != "") {
print emit_folder_comment($folder[3]);
}
if (($folder_id != $po_user['trash_folder']) &&
($folder_name != 'Trash')) {
display_folders($database, $folder_id, $owner_id);
}
if (($po_user['id'] == $owner_id) &&
($folder_id != $po_user['trash_folder'])) {
print "<div align=\"center\">";
print "<form name=\"photoList\" method=\"post\" action=\"folder.content.php\" accept-charset=\"".$strings['formats_encoding']."\">";
print "<input type=\"hidden\" name=\"source_folder\" value=\"$folder_id\"/>\n";
print $thm_elem['button.add.photos'];
print "</div>";
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
print emit_print_actions($database, $po_user['id']);
print "</form>";
site_display_random_photos($database, 'folder', $folder_id, 10, FALSE);
}
site_footer($database);
site_epilog($database);
exit();
}
$folder_photo = get_photo_query($database, array(), $froms, $filter, $offset, $limit, $order_by);
site_navigator_status("$user_display_string $path_to_folder $edit_folder", $strings['generic_displaying'] . " " . display_photo_index_status($offset, $limit, $num_of_photos));
if ($folder[3] != "") {
print emit_folder_comment($folder[3]);
}
if ($folder_name != 'Trash' || $folder_id != $po_user['trash_folder']) {
display_folders($database, "$folder_id", $owner_id);
}
print "<form name=\"photoList\" method=\"post\" action=\"folder.content.php\" accept-charset=\"".$strings['formats_encoding']."\">";
print "<input type=\"hidden\" name=\"user\" value=\"$owner_id\"/>";
print "<input type=\"hidden\" name=\"photo_view\" value=\"$photo_view\"/>";
print "<input type=\"hidden\" name=\"return\" value=\"".generate_link('folder', $folder_id, array('offset'=>$offset))."\"/>";
print "<input type=\"hidden\" name=\"source_folder\" value=\"$folder_id\"/>\n";
display_photo_navigator(generate_link('folder', $folder_id), $offset, $limit, $num_of_photos);
if ($photo_view == "slide") {
$checkboxes = display_photo_slides("folder", $folder_id, $folder_photo, 0, $items, true, true);
} else {
$checkboxes = display_photo_list("folder", $folder_id, $folder_photo, 0, $items);
}
display_photo_navigator(generate_link('folder', $folder_id), $offset, $limit, $num_of_photos);
site_navigator_status("$user_display_string $path_to_folder $edit_folder", $strings['generic_displaying'] . " " . display_photo_index_status($offset, $limit, $num_of_photos));
print "<div class=\"actions\">";
if ($checkboxes !== FALSE) {
display_order_by_combo_with_button($order_by);
if ($photo_view == 'slide') {
print emit_photos_per_page_combo('photos_per_page', $po_options['photos_per_page']);
} else {
print emit_photos_per_page_combo('rows_list_view', $po_options['rows_list_view']);
}
print emit_transform_actions();
}
print "<span>\n";
if ($checkboxes !== FALSE) {
display_list_slide_option($photo_view, generate_link('folder', $folder_id, array('offset'=>$offset)));
}
if ($checkboxes && ($po_user['type'] >= PO_USER_TYPE_CLIENT)) {
theme_display_selectButton();
print $thm_elem['button.add.to.spool'];
}
if (($po_user['id'] == $owner_id) ||
($po_user['type'] == PO_USER_TYPE_ADMIN)) {
if ($folder_name == 'Trash' || $folder_id == $po_user['trash_folder']) {
if ($checkboxes)
print $thm_elem['button.empty.trash'];
} else {
if ($po_user['id'] == $owner_id) {
print $thm_elem['button.add.photos'];
}
if ($checkboxes) {
print $thm_elem['button.delete_s'];
print $thm_elem['button.bulk.update'];
}
}
}
print "</span>";
if ($checkboxes) {
if (($po_user['id'] == $owner_id) ||
($po_user['type'] == PO_USER_TYPE_ADMIN)) {
$folder_all = get_users_folder($database);
print emit_folder_actions($folder_all, $folder_id);
}
$album_all = get_users_album($database);
if (count($album_all)) {
print emit_album_actions($album_all, '');
}
}
if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
print emit_print_actions($database, $po_user['id']);
}
print "</div>";
print "</form>\n";
if ($po_user['id'] == $owner_id) {
site_display_random_photos($database, 'folder', $folder_id, 10, FALSE);
}
site_footer($database);
site_epilog($database);
?>