po/src/my.datebook.php

282 lines
11 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/datebook.php";
include_once "include/common.php";
include_once "include/contacts.php";
$showcounts = TRUE;
$database = site_prolog(PO_USER_TYPE_CLIENT);
$auth_handle = new $po_auth();
$calendar_view = isset($_REQUEST['view']) ? $_REQUEST['view'] : 1;
$calendar_year = (int) isset($_REQUEST['year']) ? $_REQUEST['year'] : FALSE;
$calendar_month = (int) isset($_REQUEST['month']) ? $_REQUEST['month'] : FALSE;
$calendar_day = (int) isset($_REQUEST['day']) ? $_REQUEST['day'] : FALSE;
site_header($strings['generic_my_datebook']);
site_navigator(8);
site_navigator_status(emit_a(generate_link('user', ''), $strings['generic_users'])." : ".$strings['generic_my_datebook'], "");
print "<br/>";
print "<div class=\"navigatorf\">";
print "<ul>";
$day_in_month = getDaysInMonth($calendar_year, $calendar_month);
if ($calendar_day === FALSE || $calendar_day < 1 || $calendar_day > $day_in_month) {
$today = getdate(time());
$calendar_day = $today["mday"];
}
if ($calendar_month === FALSE || $calendar_month < 1 || $calendar_month > 12) {
$today = getdate(time());
$calendar_month = $today["mon"];
}
if ($calendar_year === FALSE) {
$today = getdate(time());
$calendar_year = $today["year"];
}
$calendar_week = getWeekNumber($calendar_year, $calendar_month, $calendar_day, $po_options['start_day']);
if ($calendar_week=="") {
$today = getdate(time());
$calendar_week = getWeekNumber($calendar_year, $today["mon"], $today["mday"], $po_options['start_day']);
}
if ($calendar_view == "" || $calendar_view == 1) {
$here = "class=\"menu_here\" ";
} else {
$here = "";
}
print "<li $here><a $here href=\"my.datebook.php?view=1&amp;year=$calendar_year&amp;month=$calendar_month&amp;day=$calendar_day\">".$strings['datebook_day']."</a></li>";
$week = getWeekNumber($calendar_year, $calendar_month, $calendar_day, $po_options['start_day']);
if ($calendar_view == 2) {
$here = "class=\"menu_here\" ";
} else {
$here = "";
}
print "<li $here><a $here href=\"my.datebook.php?view=2&amp;year=$calendar_year&amp;month=$calendar_month&amp;day=$calendar_day\">".$strings['datebook_week']."</a></li>";
if ($calendar_view == 3) {
$here = "class=\"menu_here\" ";
} else {
$here = "";
}
print "<li $here><a $here href=\"my.datebook.php?view=3&amp;year=$calendar_year&amp;month=$calendar_month&amp;day=$calendar_day\">".$strings['datebook_month']."</a></li>";
if ($calendar_view == 4) {
$here = "class=\"menu_here\" ";
} else {
$here = "";
}
print "<li $here><a $here href=\"my.datebook.php?view=4&amp;year=$calendar_year&amp;month=$calendar_month&amp;day=$calendar_day\">".$strings['datebook_goto']."</a></li>";
// get correct YMD.
{
$today = getdate(time());
$day = $today["mday"];
$month = $today["mon"];
$year = $today["year"];
print "<li><a href=\"my.datebook.php?view=1&amp;year=$year&amp;month=$month&amp;day=$day\">".$strings['datebook_today']."</a></li>";
print "<li><a href=\"my.datebook.php?view=2&amp;year=$year&amp;month=$month&amp;day=$day\">".$strings['datebook_this_week']."</a></li>";
print "<li><a href=\"my.datebook.php?view=3&amp;year=$year&amp;month=$month&amp;day=$day\">".$strings['datebook_this_month']."</a></li>";
}
print "</ul>";
print "</div>";
switch ($calendar_view) {
default:
case 1:
displayDayHTML($database, $po_user['id'], $calendar_year, $calendar_month, $calendar_day, $po_options['start_hour'], $po_options['end_hour'], $showcounts);
$timestamp = mktime(12, 0, 0, $calendar_month, $calendar_day, $calendar_year);
$date = getdate($timestamp);
$dayNameIndex = $date["wday"];
print "<div class=\"photo_nav\">";
$yesterday = adjustDay($calendar_year, $calendar_month, $calendar_day - 1);
print sprintf($thm_elem['button.previous'], "my.datebook.php?view=1&amp;year=$yesterday[0]&amp;month=$yesterday[1]&amp;day=$yesterday[2]", $strings['generic_day'], "");
print "<b>&nbsp;&nbsp; $dayNames[$dayNameIndex] ".date($strings['formats_date'], $timestamp)."&nbsp;&nbsp;</b>";
$tomorrow = adjustDay($calendar_year, $calendar_month, $calendar_day + 1);
print sprintf($thm_elem['button.next'], "my.datebook.php?view=1&amp;year=$tomorrow[0]&amp;month=$tomorrow[1]&amp;day=$tomorrow[2]", $strings['generic_day'], "");
print "</div>";
break;
case 2:
displayWeekHTML($database, $po_user['id'], $calendar_year, $calendar_week, $dayNames, $po_options['start_day'], $showcounts);
$firstDayOfWeek = getFirstDayOfWeek($calendar_year, $calendar_week, $po_options['start_day']);
$lastDayOfWeek = adjustDay($firstDayOfWeek[0], $firstDayOfWeek[1], $firstDayOfWeek[2]+7);
$month1 = $firstDayOfWeek[1];
$month2 = $lastDayOfWeek[1];
print "<div class=\"photo_nav\">";
$prev_week = adjustDay($calendar_year, $calendar_month, $calendar_day - 7);
print sprintf($thm_elem['button.previous'], "my.datebook.php?view=2&amp;year=$prev_week[0]&amp;month=$prev_week[1]&amp;day=$prev_week[2]", $strings['generic_week'], "");
if ($firstDayOfWeek[0] != $lastDayOfWeek[0])
print "<b>&nbsp;&nbsp;".$strings['datebook_week2']." $calendar_week, $monthNames[$month1] $firstDayOfWeek[0] - $monthNames[$month2] $lastDayOfWeek[0]&nbsp;&nbsp;</b>";
else {
if ($firstDayOfWeek[1] != $lastDayOfWeek[1])
print "<b>&nbsp;&nbsp;".$strings['datebook_week2']." $calendar_week, $monthNames[$month1] - $monthNames[$month2] $lastDayOfWeek[0]&nbsp;&nbsp;</b>";
else
print "<b>&nbsp;&nbsp;".$strings['datebook_week2']." $calendar_week, $monthNames[$month2] $lastDayOfWeek[0]&nbsp;&nbsp;</b>";
}
$next_week = adjustDay($calendar_year, $calendar_month, $calendar_day + 7);
print sprintf($thm_elem['button.next'], "my.datebook.php?view=2&amp;year=$next_week[0]&amp;month=$next_week[1]&amp;day=$next_week[2]", $strings['generic_week'], "");
print "</div>";
break;
case 3:
if ($calendar_month=="" || $calendar_year=="") {
$today = getdate(time());
$calendar_year = $today["year"];
$calendar_month = $today["mon"];
}
displayMonthHTML($database, $po_user['id'], $calendar_year, $calendar_month, $dayNames, $po_options['start_day'], $showcounts);
print "<div class=\"photo_nav\">";
$next_month = adjustMonth($calendar_year, $calendar_month - 1);
print sprintf($thm_elem['button.previous'], "my.datebook.php?view=3&amp;year=$next_month[0]&amp;month=$next_month[1]", $strings['generic_month'], "");
print "<b>&nbsp;&nbsp;$monthNames[$calendar_month] $calendar_year&nbsp;&nbsp;</b>";
$previous_month = adjustMonth($calendar_year, $calendar_month + 1);
print sprintf($thm_elem['button.next'], "my.datebook.php?view=3&amp;year=$previous_month[0]&amp;month=$previous_month[1]", $strings['generic_month'], "");
print "</div>";
break;
case 4:
print "<div>";
print "<table class=\"datebook\">\n";
print "<tr>\n";
for ($month_index=1; $month_index < 13; $month_index++) {
if ($month_index == $calendar_month)
$bgcolor = "class=\"selected\"";
else
$bgcolor = "";
print "<td $bgcolor >\n";
print "&nbsp;&nbsp;<a href=\"my.datebook.php?view=4&amp;year=$calendar_year&amp;month=$month_index\">$monthNames[$month_index]</a>&nbsp;&nbsp;";
print "</td>\n";
}
print "</tr>\n";
print "</table>\n";
print "<center>";
print "<div class=\"photo_nav\">";
$next_year = $calendar_year - 1;
print sprintf($thm_elem['button.previous'], "my.datebook.php?view=4&amp;year=$next_year&amp;month=$calendar_month", $strings['generic_year'], "");
print "<b>&nbsp;&nbsp;&nbsp;$calendar_year&nbsp;&nbsp;&nbsp;</b>";
$previous_year = $calendar_year + 1;
print sprintf($thm_elem['button.next'], "my.datebook.php?view=4&amp;year=$previous_year&amp;month=$calendar_month", $strings['generic_year'], "");
print "</div>";
print "<table class=\"gotodate\">\n";
print "<tr>\n";
print emit_th($strings['datebook_week2']);
for ($dayIncrement = 0; $dayIncrement < 7; $dayIncrement++)
print "<th width=\"80\"><b>" . $dayNames[($po_options['start_day'] + $dayIncrement) % 7] . "</b></th>\n";
print "</tr>\n";
// get timestamp of first day of month at noon
$timestamp = mktime(12, 0, 0, $calendar_month, 1, $calendar_year);
// get first day index 0 Sunday
$date = getdate($timestamp);
$day = $po_options['start_day'] + 1 - $date["wday"];
if ($day > 1)
$day -= 7;
$today = getdate(time());
$daysInMonth = getDaysInMonth($calendar_year, $calendar_month);
while ($day <= $daysInMonth) {
print "<tr>\n";
$curDate = adjustDay($calendar_year, $calendar_month, $day);
$weekNumber=getWeekNumber($curDate[0], $curDate[1], $curDate[2], $po_options['start_day']);
print "<th>";
print "<a href=\"my.datebook.php?view=2&amp;year=$calendar_year&amp;month=$curDate[1]&amp;day=$curDate[2]\"><strong>$weekNumber</strong></a></th>\n";
for ($i = 0; $i < 7; $i++) {
$curDate = adjustDay($calendar_year, $calendar_month, $day);
$num_photos = 0;
if ($showcounts) {
$num_photos = photos_between_dates($database, $po_user['id'],
mktime(0,0,0,$curDate[1],$curDate[2],$curDate[0]),
mktime(0,0,0,$curDate[1],$curDate[2]+1,$curDate[0]));
}
$bgcolor = "";
if ($curDate[2]!=$day)
$bgcolor = "class=\"inactive\"";
if (($calendar_year == $today["year"]) &&
($calendar_month == $today["mon"]) &&
($day == $today["mday"])) {
$bgcolor = "class=\"selected\"";
}
print "<td $bgcolor ><a href=\"my.datebook.php?view=1&amp;year=$curDate[0]&amp;month=$curDate[1]&amp;day=$curDate[2]\">$curDate[2]</a>";
if ($showcounts && $num_photos > 0) {
$start = urlencode(sprintf("%04d-%02d-%02d 00:00:00", $curDate[0],$curDate[1],$curDate[2]));
$end = urlencode(sprintf("%04d-%02d-%02d 23:59:59", $curDate[0],$curDate[1],$curDate[2]));
if ($po_options['search_masters_only'] != 'f') {
$master = "&amp;only_masters=true";
} else {
$master = "";
}
$num_photos = emit_a("search.text.advanced.php?start_date=$start&amp;end_date=$end&amp;date_type=photo.date_of_exposure&amp;date_operator=or&amp;user=$po_user[id]$master", $num_photos);
print "&nbsp;[$num_photos]";
}
print "</td>\n";
$day++;
}
print "</tr>\n";
}
print "</table>\n";
print "</center>\n";
print "</div>";
print "<br/>";
break;
}
print "&nbsp;<br/>";
if ($po_user['type'] > PO_USER_TYPE_CLIENT) {
display_clients($database, $po_user['id'], $auth_handle);
}
display_protected_photographers($database, $po_user['id']);
site_footer($database);
site_epilog($database);
?>