267 lines
10 KiB
PHP
267 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";
|
|
include_once "include/calendar.php";
|
|
|
|
$database = site_prolog(PO_USER_TYPE_CLIENT);
|
|
|
|
$event = isset($_REQUEST['event']) ? pg_escape_string($database, $_REQUEST['event']) : FALSE;
|
|
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
|
|
$go = isset($_REQUEST['go']);
|
|
|
|
if ($event) {
|
|
$event_data = pg_fetch_row(pg_query($database, "select start_date, end_date, remark, users, client, location from calendar where identifier='$event'"));
|
|
$start_date = $event_data[0];
|
|
$end_date = $event_data[1];
|
|
$client = $event_data[4];
|
|
$location = $event_data[5];
|
|
$owner = $event_data[3];
|
|
$remark = $event_data[2];
|
|
$year = (int)substr($event_data[0], 0, 4);
|
|
$month = (int)substr($event_data[0], 5, 2);
|
|
$day = (int)substr($event_data[0], 8, 2);
|
|
}
|
|
|
|
if ($action == 'edit') {
|
|
if ($po_user['id'] != $owner) {
|
|
site_push_error($strings['errors_not_owner']);
|
|
location("event.php?event=$event");
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
if ($go) {
|
|
$result = pg_query($database, "begin");
|
|
|
|
switch ($action) {
|
|
case 'delete':
|
|
if ($result) {
|
|
$result = pg_query($database, "update folder set event = null where event = $event");
|
|
}
|
|
if ($result) {
|
|
$result = pg_query($database, "update album set event = null where event = $event");
|
|
}
|
|
if ($result) {
|
|
$result = pg_query($database, "delete from calendar where identifier=$event");
|
|
}
|
|
break;
|
|
case 'edit':
|
|
case 'add':
|
|
$client = pg_escape_string($database, $_REQUEST['client']);
|
|
if ($client != "null") $client = "'$client'";
|
|
|
|
$start_date = pg_escape_string($database, $_REQUEST['start_date']);
|
|
$end_date = pg_escape_string($database, $_REQUEST['end_date']);
|
|
$remark = pg_escape_string($database, $_REQUEST['remark']);
|
|
$location = pg_escape_string($database, $_REQUEST['location']);
|
|
|
|
$year = (int)substr($start_date, 0, 4);
|
|
$month = (int)substr($start_date, 5, 2);
|
|
$day = (int)substr($start_date, 8, 2);
|
|
|
|
if ($action == 'add') {
|
|
$result = pg_query($database, "insert into calendar (identifier, users, start_date, end_date, remark, client, location)
|
|
values (nextval('calendar_id_sequence'), '$po_user[id]', '$start_date', '$end_date', '$remark', $client, $location)");
|
|
} else {
|
|
$result = pg_query($database, "update calendar set start_date='$start_date', end_date='$end_date', remark='$remark', client = $client, location = $location where identifier=$event");
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
if (!$result) {
|
|
site_push_error($strings['errors_db_insert_failed']);
|
|
pg_query($database, "rollback");
|
|
} else {
|
|
pg_query($database, "commit");
|
|
}
|
|
|
|
header("Location: my.datebook.php?year=$year&month=$month&day=$day");
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
|
|
/* Display the forms */
|
|
|
|
site_header(sprintf($strings["profile_$action"], $strings['datebook_event']));
|
|
site_navigator(8);
|
|
site_navigator_status(emit_a(generate_link('user', ''), $strings['generic_users'])." : ".emit_a("my.datebook.php", $strings['generic_my_datebook'])." : ".sprintf($strings["profile_$action"], $strings['datebook_event']) , "");
|
|
print "<br/>";
|
|
|
|
switch ($action) {
|
|
case 'view':
|
|
|
|
$num_photos = photos_between_dates_sql($database, $owner,
|
|
$start_date, $end_date);
|
|
|
|
print "<table class=\"listing\">\n";
|
|
print "<tr><td>".$strings['datebook_start']."</td><td><a href=my.datebook.php?year=$year&month=$month&day=$day>".emit_date_html($start_date, "full_date")."</a></td></tr>\n";
|
|
print "<tr><td>".$strings['datebook_end']."</td><td><a href=my.datebook.php?year=$year&month=$month&day=$day>".emit_date_html($end_date, "full_date")."</a></td></tr>\n";
|
|
// print "<tr><td>".$strings['datebook_client']."</td><td>$client</td></tr>";
|
|
print "<tr><td>".$strings['generic_remark']."</td> <td>$remark</td></tr>\n";
|
|
|
|
if ($num_photos > 0) {
|
|
$start = urlencode($start_date);
|
|
$end = urlencode($end_date);
|
|
if ($po_options['search_masters_only'] != 'f') {
|
|
$master = "&only_masters=true";
|
|
} else {
|
|
$master = "";
|
|
}
|
|
$num_photos = emit_a("search.text.advanced.php?start_date=$start&end_date=$end&date_type=photo.date_of_exposure&date_operator=or$master", $num_photos);
|
|
print "<tr><td>".$strings['generic_photos']."</td> <td>$num_photos</td></tr>\n";
|
|
}
|
|
|
|
print "</table>\n";
|
|
|
|
display_folders($database, "", 0, $event);
|
|
|
|
display_albums($database, "", 0, $event);
|
|
|
|
print "<br/>";
|
|
print "<center>";
|
|
print $thm_elem['button.back'];
|
|
if ($po_user['id'] == $owner) {
|
|
print sprintf($thm_elem['button.edit'], "event.php?action=edit&event=$event");
|
|
print sprintf($thm_elem['button.delete'], "event.php?action=delete&event=$event");
|
|
}
|
|
print "</center>";
|
|
|
|
break;
|
|
case 'delete':
|
|
print "<form method=\"post\" action=\"event.php\" accept-charset=\"".$strings['formats_encoding']."\">\n";
|
|
print "<input type=\"hidden\" name=\"go\" value=\"go\" />\n";
|
|
print "<input type=\"hidden\" name=\"action\" value=\"delete\" />\n";
|
|
print "<input type=\"hidden\" name=\"event\" value=\"$event\" />\n";
|
|
print "<table class=\"listing\">\n";
|
|
print "<tr><td>".$strings['datebook_start']."</td><td><a href=my.datebook.php?year=$year&month=$month&day=$day>".emit_date_html($start_date, "full_date")."</a></td></tr>\n";
|
|
print "<tr><td>".$strings['datebook_end']."</td><td><a href=my.datebook.php?year=$year&month=$month&day=$day>".emit_date_html($end_date, "full_date")."</a></td></tr>\n";
|
|
print "<tr><td>".$strings['generic_remark']."</td><td>$remark</td></tr>\n";
|
|
print "</table>\n";
|
|
|
|
print "<br/>\n";
|
|
print "<center>\n";
|
|
print $thm_elem['button.confirm.delete'];
|
|
print $thm_elem['button.cancel'];
|
|
print "</center>\n";
|
|
print "</form>\n";
|
|
|
|
break;
|
|
case 'edit':
|
|
|
|
$timestamp = mktime(12, 0, 0, $month, $day, $year);
|
|
$date = date($strings['formats_date'], $timestamp);
|
|
$dayNameIndex = $date["wday"];
|
|
|
|
/* Retrieve location info */
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN)
|
|
$location_mod = " where private is false or users=$po_user[id] ";
|
|
else
|
|
$location_mod = "";
|
|
|
|
$users_location = pg_query($database, "select identifier, country, state, city, place from view_location $location_mod order by country, state, city, place");
|
|
$values = array('location' => $location);
|
|
|
|
print "<form method=\"post\" action=\"event.php\" accept-charset=\"".$strings['formats_encoding']."\">\n";
|
|
print "<input type=\"hidden\" name=\"go\" value=\"go\" />\n";
|
|
print "<input type=\"hidden\" name=\"action\" value=\"edit\" />\n";
|
|
print "<input type=\"hidden\" name=\"event\" value=\"$event\" />\n";
|
|
print "<table class=\"listing\">\n";
|
|
|
|
print "<tr><td>".$strings['datebook_start']."</td><td>";
|
|
print emit_date_input_form("start_date", $start_date, 'full_date', FALSE);
|
|
print "</td></tr>";
|
|
print "<tr><td>".$strings['datebook_end']."</td><td>";
|
|
print emit_date_input_form("end_date", $end_date, 'full_date', FALSE);
|
|
print "</td></tr>";
|
|
print emit_form_combo_helper('location', $values, FALSE, $users_location, ',', TRUE);
|
|
print "<tr><td>".$strings['datebook_client']."</td><td>" . generate_html_clients_combo("client", $database, $po_user['id'], $client) . "</td></tr>";
|
|
print "<tr><td>".$strings['generic_remark']."</td><td><textarea id=\"template_editor\" name=\"remark\" rows=\"7\" cols=\"60\">$remark</textarea></td></tr>\n";
|
|
print "</table>\n";
|
|
|
|
print "<br/>";
|
|
print "<center>";
|
|
print $thm_elem['button.save.changes'];
|
|
print $thm_elem['button.clear'];
|
|
print $thm_elem['button.cancel'];
|
|
print "</center>\n";
|
|
print "</form>\n";
|
|
|
|
break;
|
|
case 'add':
|
|
$year = (int)$_REQUEST['year'];
|
|
$month = (int)$_REQUEST['month'];
|
|
if ($month < 1 || $month > 12) {
|
|
$month = 1;
|
|
}
|
|
$day = (int)$_REQUEST['day'];
|
|
$days_in_month = getDaysInMonth($year, $month);
|
|
if ($day < 1 || $day > $days_in_month) {
|
|
$day = 1;
|
|
}
|
|
$start_date = sprintf("%04d-%02d-%02d 00:00:00", $year, $month, $day);
|
|
$end_date = sprintf("%04d-%02d-%02d 01:00:00", $year, $month, $day);
|
|
|
|
$location = 0;
|
|
|
|
/* Retrieve location info */
|
|
if ($po_user['type'] != PO_USER_TYPE_ADMIN)
|
|
$location_mod = " where private is false or users=$po_user[id] ";
|
|
else
|
|
$location_mod = "";
|
|
|
|
$users_location = pg_query($database, "select identifier, country, state, city, place from view_location $location_mod order by country, state, city, place");
|
|
$values = array('location' => $location);
|
|
|
|
print "<form method=\"post\" action=\"event.php\" accept-charset=\"".$strings['formats_encoding']."\">\n";
|
|
print "<input type=\"hidden\" name=\"go\" value=\"go\" />\n";
|
|
print "<input type=\"hidden\" name=\"action\" value=\"add\" />\n";
|
|
print "<table class=\"listing\">\n";
|
|
print "<tr><td>".$strings['datebook_start']."</td><td>";
|
|
print emit_date_input_form("start_date", $start_date, 'full_date', FALSE);
|
|
print "</td></tr>";
|
|
print "<tr><td>".$strings['datebook_end']."</td><td>";
|
|
print emit_date_input_form("end_date", $end_date, 'full_date', FALSE);
|
|
print "</td></tr>";
|
|
print emit_form_combo_helper('location', $values, FALSE, $users_location, ',', TRUE);
|
|
print "<tr><td>".$strings['datebook_client']."</td><td>" . generate_html_clients_combo("client", $database, $po_user['id'], "") . "</td></tr>";
|
|
print "<tr><td>".$strings['generic_remark']."</td><td><textarea id=\"template_editor\" name=\"remark\" rows=\"7\" cols=\"60\"></textarea></td></tr>\n";
|
|
print "</table>\n";
|
|
|
|
print "<br/>\n";
|
|
print "<center>\n";
|
|
print $thm_elem['button.add'];
|
|
print $thm_elem['button.clear'];
|
|
print $thm_elem['button.cancel'];
|
|
print "</center>\n";
|
|
print "</form>\n";
|
|
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
?>
|