407 lines
14 KiB
PHP
407 lines
14 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/site.php";
|
|
include_once "include/import.php";
|
|
|
|
$return_path = isset($_REQUEST['return']) ? $_REQUEST['return'] : "";
|
|
|
|
$database = site_prolog();
|
|
$owner_id = isset($_REQUEST['user']) ? $_REQUEST['user'] : 0;
|
|
|
|
$destination_folder = pg_escape_string($database, isset($_REQUEST['destination_folder']) ? $_REQUEST['destination_folder'] : "");
|
|
$destination_album = pg_escape_string($database, isset($_REQUEST['destination_album'])? $_REQUEST['destination_album'] : "");
|
|
$source_folder = pg_escape_string($database, isset($_REQUEST['source_folder']) ? $_REQUEST['source_folder'] : "");
|
|
$source_album = pg_escape_string($database, isset($_REQUEST['source_album']) ? $_REQUEST['source_album'] : "");
|
|
|
|
$goto_f_request = isset($_REQUEST['go_to_f']);
|
|
$goto_a_request = isset($_REQUEST['go_to_a']);
|
|
$move_f_request = isset($_REQUEST['move_to_f']);
|
|
$link_a_request = isset($_REQUEST['link_to_a']);
|
|
$move_a_request = isset($_REQUEST['move_to_a']);
|
|
|
|
$print_request = isset($_REQUEST['print_req']);
|
|
$printer_request = isset($_REQUEST['printer_req']);
|
|
$spool_request = isset($_REQUEST['spool_req']);
|
|
$export_request = isset($_REQUEST['export_req']);
|
|
$bulk_update_request = isset($_REQUEST['bulk_update_req']);
|
|
$delete_request = isset($_REQUEST['delete_req']);
|
|
$add_photo_request = isset($_REQUEST['add_photos']);
|
|
$empty_trash_request = isset($_REQUEST['empty_trash_req']);
|
|
|
|
$transform_request = isset($_REQUEST['rotate_req']);
|
|
$transform = isset($_REQUEST['transform']) ? pg_escape_string($database, $_REQUEST['transform']) : "";
|
|
|
|
if (isset($_REQUEST['selection']) && is_array($_REQUEST['selection'])) {
|
|
foreach ($_REQUEST['selection'] as $photo) {
|
|
$parts = explode(":", $photo);
|
|
$photo_data[] = $parts[0];
|
|
$version_data[] = $parts[1];
|
|
}
|
|
$photos = implode(",", $photo_data);
|
|
$versions = implode(",", $version_data);
|
|
} else {
|
|
$photos = "";
|
|
$versions = "";
|
|
}
|
|
|
|
/* Doesn't take arguments */
|
|
if ($export_request) {
|
|
site_epilog($database);
|
|
header("Location: export.php?export_type=$_REQUEST[export_type]");
|
|
exit();
|
|
}
|
|
|
|
/* Doesn't take arguments */
|
|
if ($print_request) {
|
|
site_epilog($database);
|
|
header("Location: print.php?print_type=$_REQUEST[print_type]");
|
|
exit();
|
|
}
|
|
|
|
/* Doesn't take arguments */
|
|
if ($printer_request) {
|
|
site_epilog($database);
|
|
header("Location: printer.php?printer=$_REQUEST[printer]");
|
|
exit();
|
|
}
|
|
|
|
if ($add_photo_request) {
|
|
header("Location: photo.add.php?folder=$source_folder");
|
|
exit();
|
|
}
|
|
|
|
if ($empty_trash_request) {
|
|
header("Location: trash.empty.php?user=$owner_id");
|
|
exit();
|
|
}
|
|
|
|
/* Redirect a trash request appropriately */
|
|
if ($delete_request != "") {
|
|
if ($source_album != "") {
|
|
$move_a_request = TRUE;
|
|
$destination_album = "trash";
|
|
} else {
|
|
$move_f_request = TRUE;
|
|
if ($po_user['type'] == PO_USER_TYPE_ADMIN) {
|
|
$destination_folder = "(select identifier from folder where users = $owner_id and caption = 'Trash')";
|
|
} else {
|
|
$destination_folder = $po_user['trash_folder'];
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Redirect a spool request appropriately. */
|
|
if ($spool_request) {
|
|
$link_a_request = TRUE;
|
|
$destination_album = $po_user['spool_album'];
|
|
}
|
|
|
|
/* Doesn't take arguments */
|
|
if ($goto_f_request && ($destination_folder != "")) {
|
|
site_epilog($database);
|
|
header("Location: ".generate_link('folder', $destination_folder, array(), TRUE));
|
|
exit();
|
|
}
|
|
|
|
/* Doesn't take arguments */
|
|
if ($goto_a_request && ($destination_album != "")) {
|
|
site_epilog($database);
|
|
header("Location: ".generate_link('album', $destination_album, array(), TRUE));
|
|
exit();
|
|
}
|
|
|
|
/* Make sure spool request is sane */
|
|
if ($spool_request && ($versions == "")) {
|
|
site_epilog($database);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
|
|
/* Make sure move request is sane */
|
|
if ($move_f_request && (($destination_folder == "") ||
|
|
($photos == ""))) {
|
|
site_epilog($database);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
|
|
/* Make sure link request is sane */
|
|
if ($link_a_request && (($destination_album == "") ||
|
|
($versions == ""))) {
|
|
site_epilog($database);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
|
|
/* Bulk update? */
|
|
if ($bulk_update_request) {
|
|
if ($photos != "") {
|
|
header("Location: my.tools.php?selector=1&type=list&selection=$photos");
|
|
} else if ($source_album != "") {
|
|
header("Location: my.tools.php?selector=1&type=album&selection=$source_album");
|
|
} else if ($source_folder != "") {
|
|
header("Location: my.tools.php?selector=1&type=folder&selection=$source_folder");
|
|
} else {
|
|
header("Location: my.tools.php?selector=1");
|
|
}
|
|
exit();
|
|
}
|
|
|
|
if ($transform_request && ($transform != "")) {
|
|
site_header($strings['generic_bulk_update']);
|
|
|
|
$user_display_string = disp_user_string($database, $po_user['id']);
|
|
site_navigator(5);
|
|
|
|
site_navigator_status("$user_display_string :". $strings['generic_bulk_update'], emit_a($return_path, $strings['generic_return']));
|
|
|
|
print "<div align=\"left\"><ul>";
|
|
|
|
/* Make sure the user owns it */
|
|
foreach ($version_data as $version_id) {
|
|
$owns = FALSE;
|
|
if ($po_user['type'] == PO_USER_TYPE_ADMIN) {
|
|
$owns = TRUE;
|
|
} else {
|
|
$result = pg_query($database, "select users, photo_version.photo from photo, photo_version where photo.identifier=photo_version.photo and photo_version.identifier = '$version_id'");
|
|
$data = pg_fetch_row($result);
|
|
if ($data[0] == $po_user['id']) {
|
|
$owns = TRUE;
|
|
}
|
|
}
|
|
if ($owns == FALSE) continue;
|
|
|
|
$output = "";
|
|
|
|
if (($current_volume = get_current_volume($database, FALSE)) == FALSE) {
|
|
print err_str($strings['errors_failed_volume']);
|
|
break;
|
|
}
|
|
|
|
print "<li>".$strings['tools_regenerating_images']. emit_a(generate_link('photo', $data[1], array('ver'=>$version_id)), "# $data[1]:$version_id");
|
|
|
|
print "<ul>";
|
|
|
|
$cleanup_files = array();
|
|
|
|
pg_query($database, "begin");
|
|
|
|
$next_index = pg_fetch_row(pg_query($database, "select nextval('photo_id_sequence')"));
|
|
|
|
$photo_data = pg_fetch_assoc(pg_query($database, "
|
|
select get_image_path(photo_version.identifier, 0) as original_path,
|
|
colorspace, orientation, photo_version.identifier as version, camera
|
|
from photo, photo_version, photo_tech
|
|
where photo.identifier = photo_version.photo
|
|
and photo.identifier = photo_tech.photo
|
|
and photo_version.identifier = '$version_id'"));
|
|
|
|
if ($photo_data['camera']) {
|
|
$camera_profile = pg_fetch_row(pg_query($database, "
|
|
select raw_icc_profile
|
|
from camera, camera_type
|
|
where camera.identifier = $photo_data[camera]
|
|
and camera.type = camera_type.identifier"));
|
|
} else {
|
|
$camera_profile[0] = FALSE;
|
|
}
|
|
|
|
$old_files = array();
|
|
$res = pg_query($database, "select identifier, path from files where version = $version_id and size != 0");
|
|
for ($i = 0 ; $i < pg_num_rows($res) ; $i++) {
|
|
$row = pg_fetch_row($res);
|
|
$old_files[$row[0]] = $row[1];
|
|
}
|
|
|
|
$original = $original_name = $image_repository_path ."/". $photo_data['original_path'];
|
|
$original_file_type = strtolower(substr($original_name, strrpos($original_name, ".") + 1));
|
|
|
|
$orientation = $photo_data['orientation'];
|
|
$version_id = $photo_data['version'];
|
|
|
|
$orientation = map_transform($orientation, $transform);
|
|
|
|
$retval = pg_query($database, "update photo_version set orientation = $orientation where identifier = '$version_id'");
|
|
|
|
$orientation = orientation_to_xform($database, $orientation);
|
|
|
|
$multi_page_parameter = $mime_type[$original_file_type]['page'];
|
|
$decoder = $mime_type[$original_file_type]['decoder'];
|
|
|
|
$image_data = array();
|
|
$index = 0;
|
|
$image_data['po_options'] = $po_options;
|
|
$image_data['po_user'] = $po_user;
|
|
$image_data['jpgfromraw'] = FALSE;
|
|
$image_data['file'][$index]['orientation_xform'] = $orientation;
|
|
$image_data['file'][$index]['colorspace'] = $photo_data['colorspace'];
|
|
|
|
// XXX preserve comments on new files!
|
|
|
|
/* RAW Decode */
|
|
if ($retval) {
|
|
$temporary_ppm_file = import_decode($original_name, $decoder, $camera_profile[0], $image_data, $index, $output);
|
|
if ($temporary_ppm_file) {
|
|
$original_name = $temporary_ppm_file;
|
|
}
|
|
}
|
|
|
|
/* Generate scaled images */
|
|
if ($retval) {
|
|
$retval = import_generate_all_scaled($original_name, $multi_page_parameter, $orientation, $photo_data['colorspace'], $original, $database, $version_id, '', '', $current_volume, $next_index[0], $cleanup_files, $original, $image_data, $index, $output);
|
|
}
|
|
|
|
if ($temporary_ppm_file) {
|
|
unlink($temporary_ppm_file);
|
|
}
|
|
|
|
/* Delete the old files! */
|
|
if ($retval) {
|
|
foreach ($old_files as $file => $path) {
|
|
$retval = pg_query($database, "delete from files where identifier = $file");
|
|
}
|
|
}
|
|
if ($retval) {
|
|
$err = error_reporting(0);
|
|
foreach ($old_files as $file => $path) {
|
|
unlink("$image_repository_path/$path");
|
|
}
|
|
error_reporting($err);
|
|
}
|
|
|
|
if ($retval) {
|
|
pg_query($database, "commit");
|
|
} else {
|
|
$output .= err_str($strings['errors_db_insert_failed']);
|
|
pg_query($database, "rollback");
|
|
$err = error_reporting(0);
|
|
foreach ($cleanup_files as $file) {
|
|
unlink($file);
|
|
}
|
|
error_reporting($err);
|
|
}
|
|
|
|
print $output;
|
|
print "</ul></li>";
|
|
}
|
|
|
|
print "</ul></div>";
|
|
|
|
print $thm_elem['button.back'];
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
exit();
|
|
|
|
} elseif ($move_f_request && ($destination_folder != "")) {
|
|
/* Check ownership on destination folder */
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN) {
|
|
$result = pg_query($database, "select identifier from folder where identifier='$destination_folder' and users = $po_user[id]");
|
|
if (pg_num_rows($result) <= 0) {
|
|
site_epilog($database);
|
|
site_push_error($strings['errors_not_owner']);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
/* And perform the move */
|
|
pg_query($database, "begin");
|
|
$clause = "";
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN) {
|
|
$clause = " AND users = $po_user[id] ";
|
|
}
|
|
$result = pg_query($database, "update photo set folder=$destination_folder where identifier in ( $photos ) $clause ");
|
|
|
|
if (!$result) {
|
|
pg_query($database, "rollback");
|
|
site_push_error($strings['errors_db_insert_failed']);
|
|
} else {
|
|
pg_query($database, "commit");
|
|
}
|
|
|
|
} elseif (($link_a_request || $move_a_request) && ($destination_album != "")) {
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN) {
|
|
/* ...to an album that isn't theirs! */
|
|
if ($destination_album != "trash") {
|
|
$result = pg_query($database, "select identifier from album where identifier='$destination_album' and users = $po_user[id]");
|
|
if (pg_num_rows($result) <= 0) {
|
|
site_epilog($database);
|
|
site_push_error($strings['errors_not_owner']);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
}
|
|
/* From a source album they don't own either ... */
|
|
if ($move_a_request) {
|
|
$result = pg_query($database, "select identifier from album where identifier='$source_album' and users = $po_user[id]");
|
|
if (pg_num_rows($result) <= 0) {
|
|
site_epilog($database);
|
|
site_push_error($strings['errors_not_owner']);
|
|
header("Location: $return_path");
|
|
exit();
|
|
}
|
|
}
|
|
}
|
|
pg_query($database, "begin");
|
|
|
|
/* If we're moving the photos to a different album,
|
|
delete them from the original album first */
|
|
if ($source_album != "" && $move_a_request) {
|
|
$result = pg_query($database, "delete from album_content where album=$source_album and version in ( $versions ) ");
|
|
}
|
|
|
|
/* Loop through the photos and add them to the destination */
|
|
foreach ($_REQUEST['selection'] as $photo) {
|
|
$parts = explode(":", $photo);
|
|
$photo_identifier = $parts[0];
|
|
$photo_version = $parts[1];
|
|
// print "$photo_identifier $photo_version -- $owner_id $destination_album\n";
|
|
if ($destination_album != "trash") {
|
|
/* Check for duplicates */
|
|
$result = pg_fetch_row(pg_query($database, "select count(*) from album_content where photo = $photo_identifier and version = $photo_version and album = $destination_album"));
|
|
if ($result[0] != 0) {
|
|
continue;
|
|
}
|
|
|
|
/* Check that we can read the photo.. */
|
|
$result = pg_fetch_row(pg_query($database, "select can_access_photo($photo_identifier, $po_user[id], '{".$passwords."}');"));
|
|
|
|
if ($result[0] == 't')
|
|
/* Add to album */
|
|
$result = pg_query($database, "insert into album_content (photo, version, album)
|
|
values ($photo_identifier, $photo_version, $destination_album)");
|
|
// (select v.identifier from photo_version v where v.photo = $photo_identifier and v.master = 't')
|
|
|
|
if (!$result) {
|
|
site_push_error($strings['errors_db_insert_failed']);
|
|
pg_query($database, "rollback");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
pg_query($database, "commit");
|
|
}
|
|
|
|
site_epilog($database);
|
|
header("Location: $return_path");
|
|
|
|
?>
|