|
|
|
in use at http://www.chatmusic.com (Chicago Harmony And Truth (CHAT)), a
musician's network.
This is calendar.php
<HTML>
<?php
$debug = 0;
$backText = "Use your back button to try again or <A
HREF=mailto:webmaster@yourserverhere.com>contact
webmaster@yourserverhere.com</A> if you think you received this message in
error.<BR>\n";
$internalError = "<B>Copy this message and <A
HREF=webmaster@yourserverhere.com>Contact webmaster@yourserverhere.com
immediately!!!</A></B><BR>\n";
$host = "";
$port = 5432;
$options = "";
$tty = "";
$dbname = "chat";
$user = 'www';
$password = 'www';
$months[1] = "January";
$months[2] = "February";
$months[3] = "March";
$months[4] = "April";
$months[5] = "May";
$months[6] = "June";
$months[7] = "July";
$months[8] = "August";
$months[9] = "September";
$months[10] = "October";
$months[11] = "November";
$months[12] = "December";
if (!isset($date)){
$now = time();
$date = date("m/d/Y", $now);
if ($debug){
echo("No date specified, using today: $date<BR>
\n");
}
}
$day = 1;
$month = (int) substr($date, 0, 2);
$year = (int) substr($date, 6);
if ($debug){
echo("Parsed date is: day $day, month $month, year
$year<BR>\n");
}
$now = mktime(0, 0, 0, $month, $day, $year);
$date = date("m/d/Y", $now);
if ($debug){
echo("Unix time: $now<BR>\n");
echo("date $date<BR>\n");
}
echo(" <HEAD><TITLE>Events for $months[$month]</TITLE></HEAD>
\n");
echo(" <BODY BGCOLOR=FFFFFF LINK=FF0000 VLINK=FF0000
ALINK=FFFF00><FONT FACE=\"Verdana,Helvetica,Arial\">\n");
$thisMonth = "0" . $month;
$thisMonth = substr($thisMonth, strlen($thisMonth) - 2, 2);
$nextYearYear = $year + 1;
$nextYear = "$thisMonth-01-$nextYearYear";
$lastYearYear = $year - 1;
$lastYear = "$thisMonth-01-$lastYearYear";
$nextMonthMonth = $month + 1;
$nextMonthYear = $year;
if ($nextMonthMonth == 13){
$nextMonthMonth = 1;
$nextMonthYear = $nextMonthYear + 1;
}
$nextMonthMonth = "0" . $nextMonthMonth;
$nextMonthMonth = substr($nextMonthMonth, strlen
($nextMonthMonth) - 2, 2);
$nextMonth = "$nextMonthMonth-01-$nextMonthYear";
$lastMonthMonth = $month - 1;
$lastMonthYear = $year;
if ($lastMonthMonth == 0){
$lastMonthMonth = 12;
$lastMonthYear = $lastMonthYear - 1;
}
$lastMonthMonth = "0" . $lastMonthMonth;
$lastMonthMonth = substr($lastMonthMonth, strlen
($lastMonthMonth) - 2, 2);
$lastMonth = "$lastMonthMonth-01-$lastMonthYear";
$connection = pg_Connect("port=$port user=$user password=
$password dbname=$dbname");
if (!$connection){
echo("Couldn't connect to database $dbname on port $port at host
$host<BR>\n");
if ($options != "" || $tty != ""){
echo(" (Options $options tty $tty)<BR>\n");
}
exit;
}
$query = "select whatDate, venueid, memberid, whatTime from
gigs where whatDate>='$date::date' and whatDate<'$nextMonth::date' order by
whatDate, venueid, whatTime";
if ($debug){
echo("$query<BR>\n");
}
$gigs = pg_Exec($connection, $query);
if ($gigs == 0){
echo("$internalError");
echo("$query<BR>\n");
exit;
}
$gigCount = pg_NumRows($gigs);
echo("<TABLE WIDTH=\"100%\"><TR>\n");
echo(" <TD ALIGN=LEFT><A HREF=calendar.php?date=$lastYear>
$lastYearYear</A><BR><FONT FACE=Verdana,Helvetica,Arial SIZE=5><A
HREF=calendar.php?date=$lastMonth>$lastMonthMonth-$lastMonthYear</A></FONT></TD>
\n");
echo(" <TD ALIGN=CENTER>$year<BR><FONT
FACE=Verdana,Helvetica,Arial SIZE=7>$months[$month]</FONT></CENTER></TD>\n");
echo(" <TD ALIGN=RIGHT><A HREF=calendar.php?date=$nextYear>
$nextYearYear</A><BR><FONT FACE=Verdana,Helvetica,Arial SIZE=5><A
HREF=calendar.php?date=$nextMonth>$nextMonthMonth-$nextMonthYear</A></FONT></TD>
\n");
echo("</TR></TABLE>\n");
$current = $date;
$dayOfWeek = date("w", $now);
if ($debug){
echo("Current: $current<BR>\n");
for ($start = 'A'; $start <= 'Z'; $start++){
$d = date($start, $now);
if ($d != $start){
echo("<BR>\n$start $d");
}
}
for ($start = 'a'; $start <= 'z'; $start++){
$d = date($start, $now);
if ($d != $start){
echo("<BR>\n$start $d");
}
}
echo("dayOfWeek is $dayOfWeek<BR>\n");
}
echo("<TABLE WIDTH=\"100%\" BORDER=1>\n");
echo(" <TR><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Sunday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Monday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Tuesday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Wednesday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Thursday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Friday</TH><TH ALIGN=CENTER WIDTH=\"14%\" BGCOLOR=
\"#FFCCCC\">Saturday</TH></TR>\n");
/* Start a new week. */
echo(" <TR>\n");
$dayW = 0;
/* spit out some blanks for days in last month */
while($dayW < $dayOfWeek){
echo(" <TD> </TD>\n");
$dayW = $dayW + 1;
}
$count = 0;
$index = 0;
$separator = "";
if ($debug){
echo("month is $month<BR>\n");
echo("current is $current<BR>\n");
$m = substr($current, 0, 2);
echo("substr is $m<BR>\n");
echo("gigs: $gigCount<BR>\n");
}
while ($month == substr($current, 0, 2) && $count < 32){
echo(" <TD BGCOLOR=\"#CCCCFF\" VALIGN=TOP><FONT
FACE=Verdana,Helvetica,Arial SIZE=1><A HREF=day.php?date=$current>\n");
echo(" $day<BR>\n");
while ($index < $gigCount && $day == substr(pg_Result
($gigs, $index, 0), 3, 2)){
$whatDate = pg_Result($gigs, $index, 0);
$venueID = pg_Result($gigs, $index, 1);
$memberID = pg_Result($gigs, $index, 2);
$whatTime = pg_Result($gigs, $index, 3);
$memberQuery = "select band, firstname,
lastname from membersweb where paulid = $memberID";
$memberTable = pg_Exec($connection,
$memberQuery);
if ($memberTable == 0){
echo("Couldn't find member with id
$memberID<BR>\n");
}
$memberName = pg_Result($memberTable, 0, 0);
if ($memberName == ''){
$fname = pg_Result($memberTable, 0, 1);
$lname = pg_Result($memberTable, 0, 2);
$memberName = $fname;
if ($fname != '' && $lname != ''){
$memberName .= ' ';
}
$memberName .= $lname;
}
echo("$memberName");
/* Figure out if the next gig is at the same
place and date... */
if (($index + 1) == $gigCount){
$nextVenueID = -1;
}
else{
$nextVenueID = pg_Result($gigs, $index
+ 1, 1);
$nextDate = pg_Result($gigs, $index +
1, 0);
}
/* ... If so, just keep churning out artists. */
if (($venueID == $nextVenueID) && ($whatDate ==
$nextDate)){
echo(", <BR>\n");
}
/* Otherwise dump out the venue name. */
else{
$venueQuery = "select name from venues
where venueid = $venueID";
$venueTable = pg_Exec($connection,
$venueQuery);
if ($venueTable == 0){
echo("Couldn't find venue with
id $venueID<BR>\n");
exit;
}
$venueName = pg_Result($venueTable, 0,
0);
echo(" @ $venueName<BR>\n");
}
$index = $index + 1;
}
echo(" </A></TD>\n");
$dayW = $dayW + 1;
if ($dayW == 7){
echo(" </TR>\n");
echo(" <TR>\n");
$dayW = 0;
}
$day = $day + 1;
/* Let Unix figure out when the month rolls over. */
$current = date("m/d/Y", mktime(0, 0, 0, $month, $day,
$year));
$count = $count + 1;
}
echo("</TR></TABLE>");
?>
<BR>
<CENTER><I>Click on any day to see details about that day's
gigs.</I></CENTER><BR><BR>
<HR>
<? include("toolbar.php"); ?>
</BODY>
</HTML>
// This is day.php
<HTML>
<?
if (!isset($date)){
$date = date("m/d/Y");
}
?>
<HEAD><TITLE>Events for <? echo("$date"); ?></TITLE></HEAD>
<BODY BGCOLOR=FFFFFF LINK=FF0000 VLINK=FF0000 ALINK=FFFF00><FONT FACE=
\"Verdana,Helvetica,Arial\">
<BASEFONT FACE="Verdana,Helvetica,Arial">
<?php
include("globals.php");
include("connect.php");
$debugLimit = 0;
if ($debugLimit){
echo("$date<BR>\n");
}
$mdy = split( '/', $date);
if ($debugLimit){
$c = count($mdy);
for ($i=0;$i<$c;$i++){
$x=$mdy[$i];
echo("$x ");
}
}
$month = (int) $mdy[0];
$day = (int) $mdy[1];
$year = (int) $mdy[2];
$now = mktime(0, 0, 0, $month, $day, $year);
$dayOfWeek = date("l", $now);
$yesterdayi = mktime(0, 0, 0, $month, $day - 1, $year);
$tomorrowi = mktime(0, 0, 0, $month, $day + 1, $year);
$yesterday = date("m/d/Y", $yesterdayi);
$tomorrow = date("m/d/Y", $tomorrowi);
echo(" <TABLE WIDTH=\"100%\"><TR>\n");
echo(" <TD ALIGN=LEFT><A
HREF=day.php?date=$yesterday>$yesterday</A></TD>\n");
echo(" <TD ALIGN=CENTER><FONT
FACE=Verdana,Helvetica,Arial SIZE=5><A HREF=calendar.php?date=$date>$month-$day-
$year<BR>$dayOfWeek</A></FONT></TD>\n");
echo(" <TD ALIGN=RIGHT><A
HREF=day.php?date=$tomorrow>$tomorrow</A></TD>\n");
echo(" </TABLE>\n");
$query = "select band, business, firstname, lastname,
name, whatTime, ages, cover, details, gigs.memberid, membersweb.web,
venues.web, membersweb.email, venues.email, venues.member, sponsored from gigs,
venues, membersweb ";
$query .= " where whatDate = '$date' and gigs.memberid
= membersweb.paulid and gigs.venueid=venues.venueid ";
$query .= " order by name, whatTime";
$gigs = pg_Exec($connection, $query);
if ($gigs == 0){
echo("Error getting gigs<BR>\n");
echo("$query<BR>\n");
echo("$internalError");
exit;
}
$gigcount = pg_NumRows($gigs);
echo(" <CENTER><TABLE WIDTH=$debugLimit WIDTH=
\"100%\">\n");
echo(" <TR HEIGHT=0><TD WIDTH=75
HEIGHT=0></TD><TD HEIGHT=0></TD><TD WIDTH=75 HEIGHT=0></TD></TR>\n");
echo(" <TR><TD COLSPAN=3><HR></TD></TR>
\n");
/* When several members are at the same venue, only put
out the venue once. */
/* Have to build up a string to be dumped at the
beginning of the next iteration. */
$lastvenue = '';
$venueString = '';
for($g = 0; $g < $gigcount; $g++){
$band = pg_Result($gigs, $g, 0);
$business = pg_Result($gigs, $g, 1);
$firstname = pg_Result($gigs, $g, 2);
$lastname = pg_Result($gigs, $g, 3);
$venue = pg_Result($gigs, $g, 4);
$whatTime = pg_Result($gigs, $g, 5);
$ages = pg_Result($gigs, $g, 6);
$cover = pg_Result($gigs, $g, 7);
$details = pg_Result($gigs, $g, 8);
$chatmeeting = pg_Result($gigs, $g, 9) == 0;
$bandweb = pg_Result($gigs, $g, 10);
$venueweb = pg_Result($gigs, $g, 11);
$bandemail = pg_Result($gigs, $g, 12);
$venueemail = pg_Result($gigs, $g, 13);
$membervenue = pg_Result($gigs, $g, 14);
$sponsored = (pg_Result($gigs, $g, 15) == 't')
? 1 : 0;
/* Wipe out data from the other venue's gigs
and start fresh. */
if ($lastvenue != $venue){
echo("$venueString");
$venueString = '';
$agesReal = '';
$coverReal = '';
$detailsReal = '';
$lastWhatTime = '';
$sponsoredReal = 0;
}
/* Build up stuff for the venue to be output in
the next iteration. */
$agesReal = ($ages == '') ? $agesReal : $ages;
$coverReal = max($cover, $coverReal);
$detailsReal = ($details == '') ? $detailsReal
: $details;
$sponsoredReal = $sponsoredReal + $sponsored;
$fullname = ($firstname == '' || $lastname ==
'') ? $firstname . $lastname : $firstname . ' ' . $lastname;
$artist = $band;
$artist .= ($artist == '') ? $business : '';
$artist .= ($artist == '') ? $fullname : '';
if ($debugLimit){
echo("\n <TR><TD
COLSPAN=3>What time: $whatTime</TD></TR>");
}
$hms = split(':', $whatTime);
$hours = $hms[0];
$minutes = $hms[1];
if ($debugLimit){
echo("\n <TR><TD
COLSPAN=3>What time: $whatTime</TD></TR>");
}
$whatTime = mktime($hours, $minutes, 0, $month,
$day, $year);
$whatTime = date("h:i a", $whatTime);
if ($whatTime[0] == '0'){
$whatTime = substr($whatTime, 1);
}
if ($debugLimit){
echo("\n <TR><TD
COLSPAN=3>What time: $whatTime</TD></TR>");
}
echo(" <TR>");
if ($chatmeeting){
echo(" <TD
ALIGN=CENTER VALIGN=TOP WIDTH=75><IMG SRC=visual/chatmeet.gif WIDTH=71
HEIGHT=36></TD>\n");
}
else{
echo("
<TD></TD>\n");
}
echo(" <TD
ALIGN=CENTER VALIGN=TOP>\n");
if ($bandweb != ''){
echo("<A HREF=http://$bandweb>");
}
elseif ($bandemail != ''){
echo("<A HREF=mailto:$bandemail>");
}
echo("<FONT FACE=\"Verdana,Helvetica,Arial\"
SIZE=7>$artist</FONT>");
if ($bandweb != '' || $bandemail != ''){
echo("</A>");
}
echo(" </TD>\n");
if ($whatTime != '' && $whatTime !=
$lastWhatTime){
echo("
<TD><FONT FACE=\"Verdana,Helvetica,Arial\" SIZE=2> $whatTime</FONT></TD>");
}
else{
echo("
<TD></TD>\n");
}
echo(" </TR>\n");
$lastWhatTime = $whatTime;
if ($lastvenue != $venue){
if ($chatmeeting){
$venueString .= "
<TR><TD></TD><TD ALIGN=CENTER VALIGN=TOP><I>at</I></TD></TR>\n";
}
else{
$venueString .= "
<TR><TD></TD><TD ALIGN=CENTER VALIGN=TOP><I>appearing at</I></TD></TR>
\n";
}
$venueString .= "
<TR>\n";
if ($sponsoredReal){
$venueString .= "
<TD ALIGN=CENTER VALIGN=TOP WIDTH=75><IMG
SRC=visual/chatevnt.gif WIDTH=72 HEIGHT=36></TD>\n";
}
else{
$venueString .= "
<TD></TD>\n";
}
$venueString .= "
<TD ALIGN=CENTER VALIGN=TOP>\n";
if ($venueweb != ''){
$venueString .= "
<A HREF=http://$venueweb>";
}
elseif($venueemail != ''){
$venueString .= "
<A HREF=mailto:$venueemail>";
}
$venueString .= "<FONT FACE=
\"Verdana,Helvetica,Arial\" SIZE=7>$venue</FONT>";
if ($venueweb != '' || $venueemail !=
''){
$venueString .= "</A>";
}
if ($agesReal != '' || $coverReal > 0){
$venueString .= "<BR>\n
$agesReal";
if ($coverReal != 0){
$venueString .= "
\$$coverReal";
}
}
if ($detailsReal != ''){
$venueString .= "<BR>\n
<DIV ALIGN=LEFT>$detailsReal</DIV><BR>\n
";
}
$venueString .= "\n
</TD>\n";
if ($membervenue){
$venueString .= "
<TD ALIGN=CENTER VALIGN=TOP><IMG SRC=visual/member.gif></TD>";
}
else{
$venueString .= "
<TD></TD>\n";
}
$venueString .= "
</TR>\n";
$venueString .= "
<TR><TD COLSPAN=3><HR></TD></TR>\n";
}
$lastvenue = $venue;
}
/* dump out that last venue */
echo("$venueString");
echo(" </TABLE></CENTER>\n");
include("toolbar.php");
?>
</FONT></BODY>
</HTML>
// This is global.php
<?php
$backText = "Use your back button to try again or <A
HREF=mailto:webmaster@yourserverhere.com>contact
webmaster@yourserverhere.com</A> if you think you received this message in
error.<BR>\n";
$internalError = "<B>Copy this message and <A
HREF=webmaster@yourserverhere.com>Contact webmaster@yourserverhere.com
immediately!!!</A></B><BR>\n";
$months[1] = "January";
$months[2] = "February";
$months[3] = "March";
$months[4] = "April";
$months[5] = "May";
$months[6] = "June";
$months[7] = "July";
$months[8] = "August";
$months[9] = "September";
$months[10] = "October";
$months[11] = "November";
$months[12] = "December";
?>
// This is connect.php
<?php
$host = "";
$port = 5432;
$options = "";
$tty = "";
$dbname = "chat";
$user = 'www';
$password = 'www';
/* $connection = pg_Connect($host, $port, $options, $tty, $dbname); */
$connection = pg_Connect("port=$port user=$user password=$password
dbname=$dbname");
if (!$connection){
echo("Couldn't connect to database $dbname on port $port at
host $host<BR>\n");
if ($options != "" || $tty != ""){
echo(" (Options $options tty $tty)<BR>\n");
}
exit;
}
?>
|
|
| Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays. Categories : Calendar, Date Time, PHP, Databases, MySQL | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, |
| |