114 lines
4.9 KiB
PHP
114 lines
4.9 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/profile.php";
|
|
include_once "include/site.php";
|
|
include_once "include/calendar.php";
|
|
|
|
function update_camera($database, $user_id, $camera_id, $camera_type_id, $camera_manufacturer_id, $camera_model, $camera_variation,
|
|
$camera_serial_number, $camera_purchase_timestamp, $camera_purchased_new, $camera_access_rights, $camera_icc_profile, $camera_ignore_comment) {
|
|
global $po_user;
|
|
global $strings;
|
|
|
|
$camera_date_of_purchase = check_date_validity($camera_purchase_timestamp);
|
|
|
|
$camera_model = pg_escape_string($database, $camera_model);
|
|
$camera_variation = pg_escape_string($database, $camera_variation);
|
|
$camera_serial_number = pg_escape_string($database, $camera_serial_number);
|
|
$camera_ignore_comment = pg_escape_string($database, $camera_ignore_comment);
|
|
|
|
$result = TRUE;
|
|
|
|
/* Ensure the user owns it !*/
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN) {
|
|
$result = pg_fetch_row(pg_query($database, "select count(identifier) from camera where identifier=$camera_id and users=$po_user[id]"));
|
|
if ($result[0] == 0) {
|
|
site_push_error($strings['errors_not_owner']);
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
pg_query($database, "begin");
|
|
$camera_type_to_remove = FALSE;
|
|
|
|
if ($camera_type_id=='custom') {
|
|
/* camera type has changed */
|
|
$number_of_cameraes_of_same_type = pg_fetch_row(pg_query($database, "select count(identifier) from camera where type=(select type from camera where identifier='$camera_id')"));
|
|
if ($number_of_cameraes_of_same_type[0] == 1) {
|
|
/* there was only one camera of this kind, so we have to remove it */
|
|
$camera_type_to_remove = pg_fetch_row(pg_query($database, "select type from camera where identifier='$camera_id'"));
|
|
}
|
|
/* create new type */
|
|
$new_camera_type_id = pg_fetch_row(pg_query($database, "select nextval('camera_type_id_sequence')"));
|
|
$camera_type_id = $new_camera_type_id[0];
|
|
$result = pg_query($database, "insert into camera_type (identifier, manufacturer, model, variation, last_modified_date, last_modifying_users, raw_icc_profile)
|
|
values ($camera_type_id, $camera_manufacturer_id, '$camera_model', '$camera_variation', now(), $user_id, $camera_icc_profile)");
|
|
}
|
|
|
|
/* add camera */
|
|
if ($result) {
|
|
$result = pg_query($database, "
|
|
update camera
|
|
set type=$camera_type_id,
|
|
serial_number='$camera_serial_number',
|
|
date_of_purchase=$camera_date_of_purchase,
|
|
purchased_new='$camera_purchased_new',
|
|
access_rights='$camera_access_rights',
|
|
ignore_comment='$camera_ignore_comment'
|
|
where identifier='$camera_id'");
|
|
}
|
|
|
|
/* remove old type */
|
|
if ($result && $camera_type_to_remove) {
|
|
$result = pg_query($database, "delete from camera_type where identifier='$camera_type_to_remove[0]'");
|
|
}
|
|
|
|
if ($result) {
|
|
pg_query($database, "commit");
|
|
return TRUE;
|
|
} else {
|
|
pg_query($database, "rollback");
|
|
site_push_error($strings['errors_db_insert_failed']);
|
|
return FALSE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
$database = site_prolog(PO_USER_TYPE_USER);
|
|
|
|
update_camera($database, $po_user['id'],
|
|
pg_escape_string($database, $_REQUEST['item_id']),
|
|
pg_escape_string($database, $_REQUEST['camera_type_id']),
|
|
pg_escape_string($database, $_REQUEST['manufacturer_id']),
|
|
pg_escape_string($database, $_REQUEST['camera_model']),
|
|
pg_escape_string($database, $_REQUEST['camera_variation']),
|
|
pg_escape_string($database, $_REQUEST['camera_serial_number']),
|
|
pg_escape_string($database, $_REQUEST['camera_purchase_timestamp']),
|
|
pg_escape_string($database, $_REQUEST['camera_purchased_new']),
|
|
pg_escape_string($database, $_REQUEST['camera_access_rights']),
|
|
pg_escape_string($database, $_REQUEST['camera_icc_profile']),
|
|
pg_escape_string($database, $_REQUEST['camera_ignore_comment']));
|
|
|
|
|
|
site_epilog($database);
|
|
header("Location: my.profile.php?selector=".$profile_data['camera']['idx']);
|
|
?>
|