po/src/photo.edit.2.php

228 lines
10 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/common.php";
$database = site_prolog(PO_USER_TYPE_USER);
$photo_id = pg_escape_string($database, $_REQUEST['photo']);
$author = pg_escape_string($database, $_REQUEST['author']);
$title = pg_escape_string($database, $_REQUEST['title']);
$remark = pg_escape_string($database, $_REQUEST['remark']);
$caption = pg_escape_string($database, $_REQUEST['caption']);
$caption_writer = pg_escape_string($database, $_REQUEST['caption_writer']);
$web_statement = pg_escape_string($database, $_REQUEST['web_statement']);
$copyright = pg_escape_string($database, $_REQUEST['copyright']);
$supplemental_category = pg_escape_string($database, $_REQUEST['supplemental_category']);
$category = pg_escape_string($database, substr($_REQUEST['category'], 0, 3));
$credit = pg_escape_string($database, $_REQUEST['credit']);
$source = pg_escape_string($database, $_REQUEST['source']);
$headline = pg_escape_string($database, $_REQUEST['headline']);
$instructions = pg_escape_string($database, $_REQUEST['instructions']);
$transmission_reference = pg_escape_string($database, $_REQUEST['transmission_reference']);
$full_date_of_exposure = check_date_validity($_REQUEST['full_date_of_exposure']);
$date_of_exposure = check_date_validity($_REQUEST['exposure_timestamp']);
$location = pg_escape_string($database, $_REQUEST['location']);
$access_rights = pg_escape_string($database, $_REQUEST['access_rights']);
$hide_original = pg_escape_string($database, $_REQUEST['hide_original']);
$store_url = pg_escape_string($database, $_REQUEST['store_url']);
$camera = pg_escape_string($database, $_REQUEST['camera']);
$film = pg_escape_string($database, $_REQUEST['film']);
$focal_length = pg_escape_string($database, $_REQUEST['focal_length']);
$aperture = pg_escape_string($database, $_REQUEST['aperture']);
$shutter = pg_escape_string($database, $_REQUEST['shutter']);
$exp_comp = pg_escape_string($database, $_REQUEST['exp_comp']);
$exp_diff = pg_escape_string($database, $_REQUEST['exp_diff']);
$camera_metering = pg_escape_string($database, $_REQUEST['camera_metering']);
$camera_program = pg_escape_string($database, $_REQUEST['camera_program']);
$flash_mode = pg_escape_string($database, $_REQUEST['flash_mode']);
$flash_comp = pg_escape_string($database, $_REQUEST['flash_comp']);
$scan_resolution = pg_escape_string($database, $_REQUEST['scan_resolution']);
$scan_bitdepth = pg_escape_string($database, $_REQUEST['scan_bitdepth']);
$scan_multiscan = pg_escape_string($database, $_REQUEST['scan_multiscan']);
$iso_override = pg_escape_string($database, $_REQUEST['iso_override']);
$latitude = pg_escape_string($database, parse_latitude($_REQUEST['latitude']));
$longitude = pg_escape_string($database, parse_latitude($_REQUEST['longitude']));
$altitude = pg_escape_string($database, $_REQUEST['altitude']);
$direction = pg_escape_string($database, $_REQUEST['direction']);
$equipment = isset($_REQUEST['equipment']) ? $_REQUEST['equipment'] : array();
$keywords = $_REQUEST['keywords'];
$album_id = isset($_REQUEST['album']) ? pg_escape_string($database, $_REQUEST['album']) : FALSE;
$detail_info = isset($_REQUEST['detail_info']) ? pg_escape_string($database, $_REQUEST['detail_info']) : 1;
$version = $_REQUEST['version'];
if ($latitude == "") $latitude = 'null';
if ($longitude == "") $longitude = 'null';
if ($altitude == "") $altitude = 'null';
if ($direction == "") $direction = 'null';
$result = pg_query($database, "begin");
if ($po_user['type'] != PO_USER_TYPE_ADMIN) {
/* Ensure mere users don't move/mangle a photo that isn't theirs! */
$result = pg_query($database, "select identifier from photo where identifier='$photo_id' and users = $po_user[id]");
if (pg_num_rows($result) <= 0) {
site_referer_error('not_owner');
site_epilog($database);
exit();
}
}
if (substr($full_date_of_exposure, 0, 16) == substr($date_of_exposure, 0, 16)) {
$date_of_exposure = $full_date_of_exposure;
}
$query = "update photo
set location = $location,
author = '$author',
title = '$title',
caption = '$caption',
caption_writer = '$caption_writer',
web_statement = '$web_statement',
category = '$category',
supplemental_category = '$supplemental_category',
copyright_statement = '$copyright',
credit = '$credit',
source = '$source',
headline = '$headline',
instructions = '$instructions',
transmission_reference = '$transmission_reference',
date_of_exposure = $date_of_exposure,
access_rights = $access_rights,
hide_original = '$hide_original',
store_url = '$store_url',
comments = '$remark'
where identifier = $photo_id";
$result = pg_query($database, $query);
if ($result) {
if (pg_num_rows(pg_query($database, "select identifier from photo_tech where photo=$photo_id")) > 0) {
$query = "
update photo_tech
set camera=$camera,
film=$film,
scan_resolution=$scan_resolution,
aperture=$aperture,
focal_length=$focal_length,
shutter=$shutter,
camera_metering=$camera_metering,
camera_program=$camera_program,
flash_mode=$flash_mode,
exposure_comp=$exp_comp,
flash_comp=$flash_comp,
ev_difference=$exp_diff,
iso_override=$iso_override,
scan_bitdepth=$scan_bitdepth,
scan_multiscan=$scan_multiscan,
latitude=$latitude,
longitude=$longitude,
altitude=$altitude,
img_direction=$direction
where photo=$photo_id";
$result = pg_query($database, $query);
if ($memcache) {
po_log("memcache: delete photo_tech.$photo_id", PEAR_LOG_DEBUG);
$memcache->delete("photo_tech.$photo_id");
}
} else if (($camera != "null" ||
$film != "null" ||
$scan_resolution != "null" ||
$scan_bitdepth != "null" || $scan_multiscan != "null" ||
$aperture != "null" || $focal_length != "null" ||
$shutter != "null" || $camera_metering != "null" ||
$camera_program != "null" || $latitude != "null" ||
$longitude != "null" || $direction != "null" ||
$altitude != "null" || $flash_mode != "null" ||
$exp_comp != "null" || $flash_comp != "null" ||
$exp_diff != "null" || $iso_override != "null")) {
$result = pg_query($database, "
insert into photo_tech
(identifier, photo, camera, film, scan_resolution, aperture, focal_length, shutter,
camera_metering, camera_program, flash_mode, exposure_comp,
flash_comp, ev_difference, iso_override, scan_bitdepth,
scan_multiscan, latitude, longitude, altitude, img_direction)
values (nextval('photo_tech_id_sequence'), $photo_id, $camera, $film,
$scan_resolution, $aperture, $focal_length, $shutter,
$camera_metering, $camera_program, $flash_mode, $exp_comp,
$flash_comp, $exp_diff, $iso_override, $scan_bitdepth,
$scan_multiscan, $latitude, $longitude, $altitude, $direction)");
}
}
/* keyword update */
if ($result) {
$result = pg_query($database, "delete from photo_keywords where photo=$photo_id");
if ($memcache) {
po_log("memcache: delete photo_keywords.$photo_id", PEAR_LOG_DEBUG);
$memcache->delete("photo_keywords.$photo_id");
}
}
if ($result && $keywords) {
foreach ($keywords as $keyword) {
$keyword = strtolower(trim($keyword));
$keyword = trim($keyword);
if ($keyword == "") continue;
$keyword = pg_escape_string($database, $keyword);
if ($result) {
$result = pg_query($database, "insert into photo_keywords (photo, keyword) values ($photo_id, '$keyword')");
}
}
}
/* Update equipment */
if ($result) {
$result = pg_query($database, "delete from photo_equipment where photo = $photo_id");
foreach ($equipment as $equip) {
$parts = explode(":", $equip);
$parts[0] = pg_escape_string($database, $parts[0]);
$parts[1] = pg_escape_string($database, $parts[1]);
if ($result) {
$query = "insert into photo_equipment (photo, equipment, type) VALUES ($photo_id, $parts[0], $parts[1])";
$result = pg_query($database, $query);
}
}
if ($memcache) {
po_log("memcache: delete photo_equipment.$photo_id", PEAR_LOG_DEBUG);
$memcache->delete("photo_equipment.$photo_id");
}
}
if ($result) {
pg_query($database, "commit");
} else {
site_push_error($strings['errors_db_insert_failed']);
site_push_error(pg_last_error($database));
pg_query($database, "rollback");
}
site_epilog($database);
header("Location: ".generate_link('photo', $photo_id, array('ver'=>$version, 'detail_info'=>$detail_info,'album'=>$album_id), TRUE));
?>