po/src/photo.version.php

323 lines
12 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/import.php";
$database = site_prolog(PO_USER_TYPE_USER);
$album_id = isset($_REQUEST['album']) ? pg_escape_string($database, $_REQUEST['album']) : FALSE;
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'add';
$go = isset($_REQUEST['go']);
$size = isset($_REQUEST['size']) ? pg_escape_string($database, $_REQUEST['size']) : 2;
switch($action) {
case 'add':
$photo_id = pg_escape_string($database, $_REQUEST['photo']);
$sql_selector = "photo_version.master = 't' and photo.identifier = '$photo_id'";
break;
case 'edit':
case 'delete':
$photo_id = pg_escape_string($database, $_REQUEST['photo']);
$version_id = pg_escape_string($database, $_REQUEST['version']);
$sql_selector = "photo_version.identifier = '$version_id' and photo.identifier = '$photo_id'";
$photo_version = pg_fetch_row(pg_query($database, "select identifier, key, date_of_creation, comment, master, colorspace from photo_version where identifier='$version_id'"));
break;
}
$photo_data = pg_fetch_assoc(pg_query($database, "
select caption, '' as preview_path,
users, title, folder, photo_version.identifier, original_image_name
from photo, photo_version
where photo.identifier = photo_version.photo
and $sql_selector"));
$version_id = $photo_data['identifier'];
/* Enforce ownership */
if (($po_user['type'] != PO_USER_TYPE_ADMIN) &&
($po_user['id'] != $photo_data['users'])) {
site_referer_error('not_owner');
site_epilog($database);
exit();
}
if ($go) {
$result = TRUE;
switch ($action) {
case 'add':
// XXX this code is a candidate for being merged into photo.add.2.php
$master = pg_escape_string($database, $_REQUEST['master']);
$replace_existing = $_REQUEST['replace_existing'];
$comment = pg_escape_string($database, $_REQUEST['comment']);
$colorspace = pg_escape_string($database, $_REQUEST['colorspace']);
$file_name = $_FILES['file_name']['name'][0];
$file_size = $_FILES['file_name']['size'][0];
$file_name_tmp = $_FILES['file_name']['tmp_name'][0];
$original_file_type = strtolower(substr($file_name, strrpos($file_name, ".") + 1));
site_header(sprintf($strings['profile_add'], $strings['generic_version']));
$user_display_string = disp_user_string($database, $photo_data['users']);
site_navigator(5);
$path_to_folder = get_path_to_folder($database, $photo_data['folder']);
site_navigator_status("$user_display_string $path_to_folder : ".emit_a(generate_link('photo', $photo_id, array()), "")." : ".$strings['import_import_photos'], "");
$index = 0;
$image_data['num_of_files'] = 0;
$tempnam = tempnam($tmp_volume_path, "po.import.");
move_uploaded_file($file_name_tmp, $tempnam);
$image_data['file'][$index]['name'] = $file_name;
$image_data['file'][$index]['name_tmp'] = $tempnam;
$image_data['file'][$index]['type'] = $original_file_type;
$image_data['file'][$index]['remark'] = $comment;
$image_data['file'][$index]['master'] = $master;
$image_data['file'][$index]['colorspace'] = $colorspace;
$image_data['num_of_files']++;
$image_data['replace_existing'] = $replace_existing;
$image_data['po_user'] = $po_user;
$image_data['po_options'] = $po_options;
$image_data['photo_id'] = $photo_id;
photo_import_all($database, $image_data);
if (!$external_workers)
photo_import_worker($database, $po_user['id'], FALSE);
print "<br/>".$strings['import_complete']."<br/>";
site_footer($database);
site_epilog($database);
exit();
case 'edit':
$master = pg_escape_string($database, $_REQUEST['master']);
$comment = pg_escape_string($database, $_REQUEST['comment']);
$colorspace = pg_escape_string($database, $_REQUEST['colorspace']);
$replace_existing = $_REQUEST['replace_existing'];
if ($master == 't') {
if ($replace_existing == 't') {
$data = pg_fetch_row(pg_query("select version from photo_version where photo = $photo_id and master = 't'"));
$old_master = $data[0];
if ($old_master != $version_id) {
$result = pg_query($database, "update album_content set version = $version_id where photo = $photo_id and version = $old_master");
}
}
if ($result) {
$result = pg_query($database, "update photo_version set master='f' where photo=$photo_id");
}
}
if ($result) {
$result = pg_query($database, "update photo_version set master='$master', comment = '$comment' where identifier=$version_id");
}
if ($memcache) {
po_log("memcache: delete versions.$photo_id", PEAR_LOG_DEBUG);
$memcache->delete("versions.$photo_id");
}
if ($result) {
pg_query($database, "commit");
} else {
pg_query($database, "rollback");
site_push_error($strings['errors_db_insert_failed']);
}
break;
case 'delete':
if ($photo_version[1] == 't') {
site_epilog($database);
site_push_error($strings['errors_delete_master']);
break;
}
$result = photo_version_delete($database, $photo_id, $version_id);
if ($result) {
$version_id = ''; /* So we don't dispay the one we just nuked */
}
break;
}
header("Location: ".generate_link('photo', $photo_id, array('ver'=>$version_id, 'detail_info'=>5,'album'=>$album_id), TRUE));
exit();
}
site_header(sprintf($strings["profile_$action"], $strings['generic_version']));
$user_display_string = disp_user_string($database, $photo_data['users']);
site_navigator(5);
$path_to_folder = get_path_to_folder($database, $photo_data['folder']);
$title = get_photo_title($photo_data['caption'], $photo_data['title'], $photo_data['original_image_name']);
site_navigator_status("$user_display_string $path_to_folder : ".emit_a(generate_link('photo', $photo_id, array('ver'=>$version_id, 'detail_info'=>5,'album'=>$album_id)), $title)." : ". sprintf($strings["profile_$action"], $strings['generic_version']), "");
print "<div align=\"center\">";
theme_display_photo(generate_link('image', $photo_id, array('ver'=>$version_id, 'size'=>$size)), "");
print "</div>\n";
switch($action) {
case 'add':
if (!ini_get("file_uploads")) {
print err_str($strings['errors_file_upload_disabled']);
print $thm_elem['button.back'];
site_footer($database);
site_epilog($database);
}
print "<form method=\"post\" action=\"photo.version.php\" enctype=\"multipart/form-data\" accept-charset=\"".$strings['formats_encoding']."\">\n";
print "<input type=\"hidden\"name=\"photo\" value=\"$photo_id\" />\n";
print "<input type=\"hidden\" name=\"go\" value=\"go\"/>\n";
if ($album_id) {
print "<input type=\"hidden\" name=\"album\" value=\"$album_id\"/>\n";
}
print "<input type=\"hidden\" name=\"action\" value=\"add\"/>\n";
print "<table class=\"profile\">\n";
print "<tr>\n";
print emit_th($strings['generic_master'], "width=\"5%\"");
print emit_th($strings['import_replace_in_album'], "width=\"10%\"");
print emit_th($strings['generic_remark'], "width=\"45%\"");
print emit_th($strings['generic_colorspace'], "width=\"10%\"");
print emit_th($strings['import_image_to_add'], "width=\"20%\"");
print "</tr>\n";
print "<tr>\n";
print "<td>";
print emit_yes_no_combo("master", "f");
print "</td>";
print "<td>";
print emit_yes_no_combo("replace_existing", "f");
print "</td>";
print "<td>";
print "<input type=\"text\" name=\"comment\" value=\"\" />\n";
print "</td>";
print "<td>";
print emit_colorspace_combo("colorspace", "");
print "</td>";
print "<td>";
// print "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"".ini_get_size('upload_max_filesize')."\" />";
print "<input type=\"file\" name=\"file_name[]\" alt=\"....\"/>";
print "</td></tr>";
print "</table>\n";
print "<div align=\"center\">\n";
print $thm_elem['button.add'];
print $thm_elem['button.clear'];
print $thm_elem['button.cancel'];
print "</div>";
print "</form>\n";
break;
case 'edit':
print "<form method=\"post\" action=\"photo.version.php\" accept-charset=\"".$strings['formats_encoding']."\">\n";
print "<input type=\"hidden\" name=\"photo\" value=\"$photo_id\"/>\n";
print "<input type=\"hidden\" name=\"version\" value=\"$version_id\"/>\n";
print "<input type=\"hidden\" name=\"key\" value=\"$photo_version[1]\"/>\n";
print "<input type=\"hidden\" name=\"go\" value=\"go\"/>\n";
if ($album_id) {
print "<input type=\"hidden\" name=\"album\" value=\"$album_id\"/>\n";
}
print "<input type=\"hidden\" name=\"action\" value=\"edit\"/>\n";
print "<table class=\"profile\">\n";
print "<tr>\n";
print emit_th($strings['generic_version'], "width=\"10%\"");
print emit_th($strings['generic_imported'], "width=\"20%\"");
print emit_th($strings['generic_master'], "width=\"5%\"");
if ($photo_version[4]!='t') {
print emit_th($strings['import_replace_in_album'], "width=\"10%\"");
}
print emit_th($strings['generic_remark'], "width=\"35%\"");
print emit_th($strings['generic_colorspace'], "width=\"10%\"");
print "</tr>\n";
print "<tr>\n";
print "<td>$photo_id-V.$photo_version[1]</td>";
print "<td>".emit_date_html($photo_version[2], 'date')."</td>";
print "<td>";
if ($photo_version[4]=='t') {
print $strings['generic_yes'];
print "<input type=\"hidden\" name=\"master\" value=\"t\"/>\n";
} else {
print emit_yes_no_combo("master", $photo_version[4]);
print "</td>";
print "<td>";
print emit_yes_no_combo("replace_existing", "f");
}
print "<td>";
print "<input type=\"text\" name=\"comment\" value=\"$photo_version[3]\"/>\n";
print "</td>";
print "<td>";
print emit_colorspace_combo("colorspace", $photo_version[5]);
print "</td>";
print "</tr>\n";
print "</table>\n";
print "<center>";
print $thm_elem['button.save.changes'];
print $thm_elem['button.clear'];
print $thm_elem['button.cancel'];
print "</center>";
print "</form>\n";
break;
case 'delete':
print "<form method=\"post\" action=\"photo.version.php\" accept-charset=\"".$strings['formats_encoding']."\">\n";
print "<input type=\"hidden\" name=\"photo\" value=\"$photo_id\"/>\n";
print "<input type=\"hidden\" name=\"version\" value=\"$version_id\"/>\n";
print "<input type=\"hidden\" name=\"key\" value=\"$photo_version[1]\"/>\n";
print "<input type=\"hidden\" name=\"go\" value=\"go\"/>\n";
if ($album_id) {
print "<input type=\"hidden\" name=\"album\" value=\"$album_id\"/>\n";
}
print "<input type=\"hidden\" name=\"action\" value=\"delete\"/>\n";
print "<table class=\"profile\">\n";
print "<tr>\n";
print emit_th($strings['generic_version'], "width=\"10%\"");
print emit_th($strings['generic_imported'], "width=\"20%\"");
print emit_th($strings['generic_master'], "width=\"5%\"");
print emit_th($strings['generic_remark'], "width=\"60%\"");
print "</tr>\n";
print "<tr>\n";
print "<td>$photo_id-V.$photo_version[1]</td>";
print "<td>".emit_date_html($photo_version[2], 'date')."</td>";
print emit_td(emit_yes_no_text($photo_version[4]));
print "<td>$photo_version[3]</td>";
print "</tr>\n";
print "</table>\n";
print "<center>";
if ($photo_version[4] == 't') {
print $thm_elem['button.back'];
} else {
print $thm_elem['button.confirm.delete'];
print $thm_elem['button.cancel'];
}
print "</center>";
print "</form>\n";
break;
}
site_footer($database);
site_epilog($database);
?>