1
0
mirror of https://github.com/php/web-php.git synced 2026-03-23 23:02:13 +01:00

rewrote cal.php to get data from backend/events.csv. phpweb is once again

mysql-free. also got rid of events.php, since cal.php can now display info
about particular events. the calendar should look essentially the same, modulo
smaller default text, and some small css tweaks (mainly to put a divider
between events -- i could never tell them apart before).

one small thing to add would be a remove button to events a-la the
manual notes when the magic cookie is set.
This commit is contained in:
jim winstead
2002-03-05 02:54:19 +00:00
parent 5dac60f00a
commit 222ff1f075
7 changed files with 275 additions and 668 deletions

526
cal.php
View File

@@ -1,331 +1,225 @@
<?php
include_once 'prepend.inc';
require_once 'prepend.inc';
// The calendar is hosted at php2.chek.com only!
if (!is_primary_site()) {
/*
if (is_backup_primary()) {
commonHeader("Service Unavailable");?>
<p>Sorry, the event calendar is temporarily unavailable.</p>
<?php
commonFooter();
exit;
# this serves three different forms of the calendar data:
# * a monthly view ($cm, $cy)
# * a daily view ($cm, $cd, $cy)
# * an individual item view ($id)
# if we encounter an error display an event or a day, we display the current
# month (or the month of the requested day)
$begun = 0;
if ($id) {
if ($event = load_event($id)) {
commonHeader("Event: ".htmlentities($event['sdesc']));
display_event($event, 0);
$begun++;
}
else {
$errors[] = "There is no event for specified id ('".htmlentities($id)."')";
}
}
elseif ($cy && $cm && $cd) {
if (checkdate($cm,$cd,$cy)) {
$date = mktime(0,0,1,$cm,$cd,$cy);
if ($events = load_events($date)) {
commonHeader("Events: ".date("F j, Y", $date));
echo "<h2>", date("F j, Y", $date), "</h2>\n";
foreach ($events as $event) {
display_event($event, 0);
}
$begun++;
}
else {
$errors[] = "There are no events for the specified date (".date("F j, Y",$date).").";
}
*/
header("Location: http://php2.chek.com/cal.php");
exit;
}
if (!isset($format)) {
$format = 'html';
else {
$errors[] = "The specified date (".htmlentities("$cy/$cm/$cd").") was not valid.";
unset($cm); unset($cd); unset($cy);
}
if ($format == 'html') {
commonHeader("Event Calendar",1);
include_once 'cvs-auth.inc';
if (isset($save) && isset($pw)) { # non-developers don't have $user set
setcookie("MAGIC_COOKIE",base64_encode("$user:$pw"),time()+3600*24*20,'/');
}
if (isset($MAGIC_COOKIE) && !isset($user) && !isset($pw)) {
list($user,$pw) = explode(":", base64_decode($MAGIC_COOKIE));
}
}
@mysql_connect('localhost') or die('unable to connect to database');
@mysql_select_db('php3');
$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last');
/*
CREATE TABLE phpcal (
id int(8) NOT NULL,
sdato date,
edato date,
recur char(12),
sdesc char(16) NOT NULL,
url varchar(128),
ldesc text,
tipo int(1) NOT NULL,
approved int(1) NOT NULL DEFAULT 0,
app_by char(16),
PRIMARY KEY(id),
INDEX (sdato),
INDEX (edato)
)
*/
/*
* Find the first, second, third, last, second-last etc. weekday of a month
*
* args: day 1 = Monday
* which 1 = first
* 2 = second
* 3 = third
* -1 = last
* -2 = second-last
*/
function weekday($year, $month, $day, $which) {
$ts = mktime(12,0,0,$month+(($which>0)?0:1),($which>0)?1:0,$year);
$done = false;
$match = 0;
$inc = 3600*24;
while(!$done) {
if(strftime('%w',$ts)==$day-1) {
$match++;
}
if($match==abs($which)) $done=true;
else $ts += (($which>0)?1:-1)*$inc;
}
return $ts;
}
function load_unapproved_events() {
global $re;
$days = days();
$result = mysql_query("select phpcal.*, country.name as name from phpcal, country where phpcal.country=country.id and approved=0 order by sdato");
if(!$result) echo mysql_error();
else {
while($row = mysql_fetch_array($result)) {
switch($row['tipo']) {
case 1:
$events[] = array($row['id'],$row['sdato'],$row['sdesc'],$row['ldesc'],$row['url'], $row['name'], $row['category']);
break;
case 2:
$events[] = array($row['id'],$row['sdato'].' to '.$row['edato'],$row['sdesc'],$row['ldesc'],$row['url'], $row['name'], $row['category']);
break;
case 3:
list($which,$day) = explode(':',$row['recur']);
$events[] = array($row['id'],'Every '.$re[(int)$which].' '.$days[$day],$row['sdesc'],$row['ldesc'],$row['url'], $row['name'], $row['category']);
break;
}
}
}
return $events;
}
function load_month($year, $month) {
$result = mysql_query("select * from phpcal where (((MONTH(sdato)=$month or MONTH(edato)=$month) and (YEAR(sdato)=$year or YEAR(edato)=$year) and tipo<3) or tipo=3) and approved=1");
if(!$result) echo mysql_error();
else {
while($row = mysql_fetch_array($result)) {
switch($row['tipo']) {
case 1:
list(,,$dd) = explode('-',$row['sdato']);
$events[(int)$dd][] = $row;
break;
case 2:
list(,$mm,$dd) = explode('-',$row['sdato']);
list(,$m2,$d2) = explode('-',$row['edato']);
if((int)$mm==(int)$m2) {
for($i=(int)$dd; $i<=(int)$d2; $i++) {
$events[$i][] = $row;
}
} elseif((int)$mm==$month) {
for($i=(int)$dd; $i<32; $i++) {
$events[$i][] = $row;
}
} else {
for($i=1; $i<=(int)$d2; $i++) {
$events[$i][] = $row;
}
}
break;
case 3:
list($which,$dd) = explode(':',$row['recur']);
$ts = weekday($year,$month,$dd,$which);
$events[(int)strftime('%d',$ts)][] = $row;
break;
}
}
}
return($events);
}
function start_month($year, $month) {
$ts = mktime(12,0,0,$month,1,$year);
return strftime('%w',$ts);
}
function last_day($year,$month) {
$ts = mktime(12,0,0,$month+1,0,$year);
return strftime('%e',$ts);
}
function months() {
static $months=NULL;
if(!$months) for($i=1;$i<=12;$i++) {
$months[$i] = strftime('%B',mktime(12,0,0,$i,1));
}
return $months;
}
/* returns array of Days starting with 1 = Sunday */
function days() {
static $days=NULL;
if(!$days) for($i=1;$i<=7;$i++) {
$days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001));
}
return $days;
}
function draw_cal($y,$m) {
global $ev, $cm, $cy;
$months = months();
$m=(int)$m;
$month=$months[$m];
$events = load_month($y,$m);
$pm=$m-1;
$nm=$m+1;
$py = $ny = $y;
if($m==1) {
$pm = 12;
$py = $y-1;
} else {
$pm = $m-1;
}
if($m==12) {
$nm = 1;
$ny = $y+1;
}
?>
<table border=0 cellspacing=0 cellpadding=3 width=100%><tr bgcolor=#d0d0d0>
<th align=left>
<table width=100% border=0
<tr><td align=left><a href="cal.php?cm=<?php echo $pm?>&cy=<?php echo $py?>"><?php echo $months[$pm].', '.$py?></a></td>
<td align=center><b><?php echo $month,', '.$y?></b></td>
<td align=right><a href="cal.php?cm=<?php echo $nm?>&cy=<?php echo $ny?>"><?php echo $months[$nm].', '.$ny?></a></td></tr></table></th>
</tr>
<tr bgcolor=#d0d0d0><td>
<table border=1 cellspacing=0 cellpadding=3 width=100%>
<?php
$days = days();
$start = start_month($y,$m);
$last = last_day($y,$m);
if(($start==5 && $last>30) || ($start==6 && $last>29)) $rows=7; else $rows=6;
for($j=0;$j<$rows; $j++) {
echo '<tr>';
for($i=1; $i<=7; $i++) {
if($j==0) echo '<th width=14.2% bgcolor=#a0a0a0>'.$days[$i]."</th>\n";
else {
if($j==1 && ($i-1)==$start) $day = 1;
if($day && $day<=$last) {
$label=$day;
$col = '#f0f0f0';
$bcol=$col;
$data = '&nbsp;';
if(is_array($events[$day])) {
$data = '';
foreach($events[$day] as $row) {
if($data) $data .= "<br>\n";
$data .= "<a href=\"cal.php?cm=$cm&cy=$cy&ev=".$row['id']."\">".$row['sdesc'].'</a>';
}
}
}
else { $label=''; $data=''; $col='#d0d0d0'; $bcol=$col; }
echo "<td bgcolor=$bcol><table border=0 width=100% bgcolor=\"$col\" cellspacing=0><tr><td align=right>$label</td></tr>";
echo "<tr><td>$data</td></tr></table></td>\n";
}
if($day) $day++;
}
echo "</tr>\n";
}
?>
</table>
<?php if($ev) draw_event($ev) ?>
<?php
echo "</table>\n";
}
function draw_event($ev) {
global $re;
$stmt = "select phpcal.*,country.name as cname from phpcal,country where phpcal.country = country.id and phpcal.id=$ev";
$result = mysql_query($stmt);
if(!$result) echo mysql_error();
else $event = mysql_fetch_array($result);
$days=days();
$cat = $event['category'];
switch($cat) {
case 1:
$category = "regional";
break;
case 2:
$category = "national";
break;
case 3:
$category = "international";
break;
default:
$category = "unknown";
}
?>
<tr bgcolor=#d0d0d0><td>
<table border=0 cellspacing=0 cellpadding=3 width=100%>
<tr bgcolor=#a0a0a0><th><?php echo $event['sdesc']?></th>
<td bgcolor=#f0f0f0 rowspan=3 width=80%>
<?php
echo ini_get('magic_quotes_gpc') ? stripslashes($event['ldesc']) : $event['ldesc'] ;
echo ((!$event['country']) || ($event['country'] != 'XXX')) ? "<br><b>Country</b>: ". $event['cname'] : "" ;
echo ((!isset($category)) || ($category != "unknown")) ? "<br><b>Event Type</b>: ". $category : "" ;
if(strlen($event['url'])) {
echo "<br><b>URL</b>: <a href=\"".$event['url']."\">".$event['url']."</a>\n";
if ($cm && $cy && !checkdate($cm,1,$cy)) {
$errors[] = "The specified year and month (".htmlentities("$cy, $cm").") are not valid.";
unset($cm); unset($cy);
}
if (!$cm) $cm = date("m");
if (!$cy) $cy = date("Y");
$date = mktime(0,0,1,$cm,1,$cy);
if (!$begun) {
commonHeader("Events: ".date("F Y", $date));
?>
</td></tr>
<tr bgcolor=#a0a0a0><th>
<?php switch($event['tipo']) {
case 1:
echo $event['sdato'];
break;
case 2:
echo $event['sdato'].' to '.$event['edato'];
break;
case 3:
list($which,$day) = explode(':',$event['recur']);
echo 'Every '.$re[(int)$which].' '.$days[$day];
break;
}
?>
</th></tr>
<tr bgcolor=#a0a0a0><th>Approved by: <?php echo $event['app_by']?></th></tr>
</table>
</td></tr>
<div class="tip">
<p>If you would like to suggest an upcoming event to be listed on this
calendar, you can use <a href="submit-event.php">our event submission
form</a>.</p>
<p>You can click on each of the events for details, or on the number for a day
to get the details for all of the events taking place that day.</p>
</div>
<?php
}
if (!isset($cm)) $cm = (int)strftime('%m');
if (!isset($cy)) $cy = (int)strftime('%Y');
if (!isset($cd)) $cd = (int)strftime('%d');
if (!isset($nm)) $nm = 1;
switch($format) {
case 'html':
echo "<h1>Event Calendar</h1>";
draw_cal($cy,$cm);
echo "<br>";
commonFooter();
break;
$events = load_events($date,1);
case 'csv':
while($nm) {
$entries = load_month($cy,$cm);
$last = last_day($cy,$cm);
for($i=$cd; $i<=$last; $i++) {
if(is_array($entries[$i])) foreach($entries[$i] as $row) {
if($data) $data.="\n";
$data .= "$i,$cm,$cy,\"http://php.net/cal.php?cm=$cm&cy=$cy&ev=".$row['id']."\",\"".addslashes($row['sdesc']).'"';
}
}
$nm--;
$cd = 1;
if($nm) {
$cm++;
if($cm==13) { $cy++; $cm=1; }
}
}
echo $data;
break;
if ($errors) display_errors($errors);
# beginning and end of this month
$bom = mktime(0,0,1,$cm, 1,$cy);
$eom = mktime(0,0,1,$cm+1,0,$cy);
# last month and next month
$lm = mktime(0,0,1,$cm,0,$cy);
$nm = mktime(0,0,1,$cm+1,1,$cy);
echo '<br /><table bgcolor="#d0d0d0" width="100%" border="0" cellspacing="0" cellpadding="3">',
"\n<tr>", '<td align="left" width="33%"><a href="', $PHP_SELF,
strftime('?cm=%m&amp;cy=%Y">%B, %Y</a></td>', $lm),
'<td align="center" width="33%">', strftime('<b>%B, %Y</b></td>', $bom),
'<td align="right" width="33%"><a href="', $PHP_SELF,
strftime('?cm=%m&amp;cy=%Y">%B, %Y</a></td>', $nm),
"</tr>\n</table>\n";
# begin the calendar
echo '<table id="cal" bgcolor="#f0f0f0" width="100%" border="1" cellspacing="0" cellpadding="3">',
"\n",'<tr bgcolor="#a0a0a0">',"\n";
for ($i = 0; $i < 7; $i++) {
echo '<th width="14%">', date("l",mktime(0,0,1,4,$i+1,2001)), "</th>\n";
}
echo "</tr>\n<tr>";
# generate the requisite number of blank days to get things started
for ($days = $i = date("w",$bom); $i > 0; $i--) {
echo '<td bgcolor="#d0d0d0">&nbsp;</td>';
}
for ($i = 1; $i <= date("t",$bom); $i++) {
echo '<td valign="top"><a class="day" href="',
$PHP_SELF, "?cm=$cm&amp;cd=$i&amp;cy=$cy",
'">',$i,'</a>';
display_events_for_day(date("Y-m-",$bom).sprintf("%02d",$i),$events);
echo '</td>';
if (++$days % 7 == 0) echo "</tr>\n<tr>";
}
# generate the requisite number of blank days to wrap things up
for (; $days % 7; $days++) {
echo '<td bgcolor="#d0d0d0">&nbsp;</td>';
}
echo "</tr>\n</table>\n";
commonFooter();
# FUNCTIONS
/* generate the date on which a recurring event falls for a given month */
/* $bom and $eom are the first and last day of the month to look at */
function date_for_recur($recur,$day,$bom,$eom) {
/* $day == 1 == 'Sunday' == date("w",'some sunday')+1 */
if ($recur > 0) { /* ${recur}th $day of the month */
$bomd = date("w",$bom) + 1;
$days = (($day - $bomd + 7) % 7) + (($recur - 1) * 7);
return mktime(0,0,1, date("m",$bom), $days + 1, date("Y",$bom));
}
else { /* ${recur}th to last $day of the month */
$eomd = date("w",$eom) + 1;
$days = (($eomd - $day + 7) % 7) + ((abs($recur) - 1) * 7);
return mktime(0,0,1, date("m",$bom)+1, -$days, date("Y",$bom));
}
}
/* display a <div> for each of the events that fall on a given day */
function display_events_for_day($day,$events) {
global $PHP_SELF,$cm,$cy;
foreach ($events as $event) {
if (($event['type'] == 2 && $event['start'] <= $day && $event['end'] >= $day)
|| ($event['start'] == $day)) {
echo '<div class="event">',
'<a href="',$PHP_SELF,"?id=$event[id]&amp;cm=$cm&amp;cy=$cy",'">',
htmlentities($event['sdesc']),
'</a></div>';
}
}
}
/* load a single event from the event list, by id */
function load_event($id) {
$fp = @fopen("backend/events.csv",'r');
if (!$fp) return;
while (!feof($fp)) {
$event = read_event($fp);
if ($event['id'] == $id) {
fclose($fp);
return $event;
}
}
fclose($fp);
return;
}
/* load a list of events, either for a particular day or a whole month */
function load_events($from, $whole_month=0) {
/* we'll take advantage of the equality behavior of this date format */
$from_date = date("Y-m-d", $from);
$bom = mktime(0,0,1,date("m",$from),1,date("Y",$from));
$eom = mktime(0,0,1,date("m",$from)+1,0,date("Y",$from));
$to_date = date("Y-m-d", $whole_month ? $eom : $from);
$events = $seen = array();
$fp = @fopen("backend/events.csv",'r');
if (!$fp) return;
while (!feof($fp)) {
$event = read_event($fp);
if ($seen[$event['id']]++) continue; # only want each event once!
switch ($event['type']) {
case 3: /* recurring event */
$date = date_for_recur($event['recur'],$event['recur_day'],$bom,$eom);
$event['start'] = date("Y-m-d", $date);
/* falls through: now it is just like a single-day event */
case 1: /* single-day event */
if ($event['start'] >= $from_date && $event['start'] <= $to_date) {
$events[] = $event;
}
break;
case 2: /* multi-day event */
if (($event['start'] >= $from_date && $event['start'] <= $to_date)
|| ($event['end'] >= $from_date && $event['end'] <= $to_date)
|| ($event['start'] <= $from_date && $event['end'] >= $to_date)) {
$events[] = $event;
}
break;
}
}
fclose($fp);
return $events;
}
/* read an event from the event listing */
function read_event($fp) {
list(,,,,$sdesc,$id,$ldesc,$url,$recur,$tipo,$sdato,$edato)
= fgetcsv($fp,8192);
list($recur,$recur_day) = explode(":",$recur,2);
return array(
'id' => $id,
'type' => $tipo,
'start' => $sdato,
'end' => $edato,
'recur' => $recur,
'recur_day' => $recur_day,
'sdesc' => $sdesc,
'url' => $url,
'ldesc' => base64_decode($ldesc),
);
}
?>

256
cal.sql
View File

@@ -1,256 +0,0 @@
#drop table phpcal;
CREATE TABLE phpcal (
id int(8) NOT NULL AUTO_INCREMENT,
sdato date,
edato date,
recur char(12),
sdesc char(16) NOT NULL,
url varchar(128),
ldesc text,
tipo int(1) NOT NULL,
country char(3) NOT NULL,
category TINYINT NOT NULL,
approved int(1) NOT NULL DEFAULT 0,
app_by char(16),
PRIMARY KEY(id),
INDEX (sdato),
INDEX (edato),
INDEX (country),
INDEX (category)
);
CREATE TABLE country (
id char(3) NOT NULL,
name varchar(55),
PRIMARY KEY (id)
);
INSERT INTO country VALUES ('AFG','Afghanistan');
INSERT INTO country VALUES ('ALB','Albania');
INSERT INTO country VALUES ('DZA','Algeria');
INSERT INTO country VALUES ('ASM','American Samoa');
INSERT INTO country VALUES ('AND','Andorra');
INSERT INTO country VALUES ('AGO','Angola');
INSERT INTO country VALUES ('AIA','Anguilla');
INSERT INTO country VALUES ('ATG','Antigua and Barbuda');
INSERT INTO country VALUES ('ARG','Argentina');
INSERT INTO country VALUES ('ARM','Armenia');
INSERT INTO country VALUES ('ABW','Aruba');
INSERT INTO country VALUES ('AUS','Australia');
INSERT INTO country VALUES ('AUT','Austria');
INSERT INTO country VALUES ('AZE','Azerbaijan');
INSERT INTO country VALUES ('BHS','Bahamas');
INSERT INTO country VALUES ('BHR','Bahrain');
INSERT INTO country VALUES ('BGD','Bangladesh');
INSERT INTO country VALUES ('BRB','Barbados');
INSERT INTO country VALUES ('BLR','Belarus');
INSERT INTO country VALUES ('BEL','Belgium');
INSERT INTO country VALUES ('BLZ','Belize');
INSERT INTO country VALUES ('BEN','Benin');
INSERT INTO country VALUES ('BMU','Bermuda');
INSERT INTO country VALUES ('BTN','Bhutan');
INSERT INTO country VALUES ('BOL','Bolivia');
INSERT INTO country VALUES ('BIH','Bosnia and Herzegovina');
INSERT INTO country VALUES ('BWA','Botswana');
INSERT INTO country VALUES ('BRA','Brazil');
INSERT INTO country VALUES ('VGB','British Virgin Islands');
INSERT INTO country VALUES ('BRN','Brunei Darussalam');
INSERT INTO country VALUES ('BGR','Bulgaria');
INSERT INTO country VALUES ('BFA','Burkina Faso');
INSERT INTO country VALUES ('BDI','Burundi');
INSERT INTO country VALUES ('KHM','Cambodia');
INSERT INTO country VALUES ('CMR','Cameroon');
INSERT INTO country VALUES ('CAN','Canada');
INSERT INTO country VALUES ('CPV','Cape Verde');
INSERT INTO country VALUES ('CYM','Cayman Islands');
INSERT INTO country VALUES ('CAF','Central African Republic');
INSERT INTO country VALUES ('TCD','Chad');
INSERT INTO country VALUES ('CHL','Chile');
INSERT INTO country VALUES ('CHN','China');
INSERT INTO country VALUES ('HKG','Hong Kong Special Administrative');
INSERT INTO country VALUES ('MAC','Macao Special Administrative Region of China');
INSERT INTO country VALUES ('COL','Colombia');
INSERT INTO country VALUES ('COM','Comoros');
INSERT INTO country VALUES ('COG','Congo');
INSERT INTO country VALUES ('COK','Cook Islands');
INSERT INTO country VALUES ('CRI','Costa Rica');
INSERT INTO country VALUES ('CIV','Cote d\'Ivoire');
INSERT INTO country VALUES ('HRV','Croatia');
INSERT INTO country VALUES ('CUB','Cuba');
INSERT INTO country VALUES ('CYP','Cyprus');
INSERT INTO country VALUES ('CZE','Czech Republic');
INSERT INTO country VALUES ('PRK','Democratic People\'s Republic of Korea');
INSERT INTO country VALUES ('COD','Democratic Republic of the Congo');
INSERT INTO country VALUES ('DNK','Denmark');
INSERT INTO country VALUES ('DJI','Djibouti');
INSERT INTO country VALUES ('DMA','Dominica');
INSERT INTO country VALUES ('DOM','Dominican Republic');
INSERT INTO country VALUES ('TMP','East Timor');
INSERT INTO country VALUES ('ECU','Ecuador');
INSERT INTO country VALUES ('EGY','Egypt');
INSERT INTO country VALUES ('SLV','El Salvador');
INSERT INTO country VALUES ('GNQ','Equatorial Guinea');
INSERT INTO country VALUES ('ERI','Eritrea');
INSERT INTO country VALUES ('EST','Estonia');
INSERT INTO country VALUES ('ETH','Ethiopia');
INSERT INTO country VALUES ('FRO','Faeroe Islands');
INSERT INTO country VALUES ('FLK','Falkland Islands (Malvinas)');
INSERT INTO country VALUES ('FJI','Fiji');
INSERT INTO country VALUES ('FIN','Finland');
INSERT INTO country VALUES ('FRA','France');
INSERT INTO country VALUES ('GUF','French Guiana');
INSERT INTO country VALUES ('PYF','French Polynesia');
INSERT INTO country VALUES ('GAB','Gabon');
INSERT INTO country VALUES ('GMB','Gambia');
INSERT INTO country VALUES ('GEO','Georgia');
INSERT INTO country VALUES ('DEU','Germany');
INSERT INTO country VALUES ('GHA','Ghana');
INSERT INTO country VALUES ('GIB','Gibraltar');
INSERT INTO country VALUES ('GRC','Greece');
INSERT INTO country VALUES ('GRL','Greenland');
INSERT INTO country VALUES ('GRD','Grenada');
INSERT INTO country VALUES ('GLP','Guadeloupe');
INSERT INTO country VALUES ('GUM','Guam');
INSERT INTO country VALUES ('GTM','Guatemala');
INSERT INTO country VALUES ('GIN','Guinea');
INSERT INTO country VALUES ('GNB','Guinea-Bissau');
INSERT INTO country VALUES ('GUY','Guyana');
INSERT INTO country VALUES ('HTI','Haiti');
INSERT INTO country VALUES ('VAT','Holy See');
INSERT INTO country VALUES ('HND','Honduras');
INSERT INTO country VALUES ('HUN','Hungary');
INSERT INTO country VALUES ('ISL','Iceland');
INSERT INTO country VALUES ('IND','India');
INSERT INTO country VALUES ('IDN','Indonesia');
INSERT INTO country VALUES ('IRN','Iran (Islamic Republic of)');
INSERT INTO country VALUES ('IRQ','Iraq');
INSERT INTO country VALUES ('IRL','Ireland');
INSERT INTO country VALUES ('ISR','Israel');
INSERT INTO country VALUES ('ITA','Italy');
INSERT INTO country VALUES ('JAM','Jamaica');
INSERT INTO country VALUES ('JPN','Japan');
INSERT INTO country VALUES ('JOR','Jordan');
INSERT INTO country VALUES ('KAZ','Kazakhstan');
INSERT INTO country VALUES ('KEN','Kenya');
INSERT INTO country VALUES ('KIR','Kiribati');
INSERT INTO country VALUES ('KWT','Kuwait');
INSERT INTO country VALUES ('KGZ','Kyrgyzstan');
INSERT INTO country VALUES ('LAO','Lao People\'s Democratic Republic');
INSERT INTO country VALUES ('LVA','Latvia');
INSERT INTO country VALUES ('LBN','Lebanon');
INSERT INTO country VALUES ('LSO','Lesotho');
INSERT INTO country VALUES ('LBR','Liberia');
INSERT INTO country VALUES ('LBY','Libyan Arab Jamahiriya');
INSERT INTO country VALUES ('LIE','Liechtenstein');
INSERT INTO country VALUES ('LTU','Lithuania');
INSERT INTO country VALUES ('LUX','Luxembourg');
INSERT INTO country VALUES ('MDG','Madagascar');
INSERT INTO country VALUES ('MWI','Malawi');
INSERT INTO country VALUES ('MYS','Malaysia');
INSERT INTO country VALUES ('MDV','Maldives');
INSERT INTO country VALUES ('MLI','Mali');
INSERT INTO country VALUES ('MLT','Malta');
INSERT INTO country VALUES ('MHL','Marshall Islands');
INSERT INTO country VALUES ('MTQ','Martinique');
INSERT INTO country VALUES ('MRT','Mauritania');
INSERT INTO country VALUES ('MUS','Mauritius');
INSERT INTO country VALUES ('MEX','Mexico');
INSERT INTO country VALUES ('FSM','Micronesia Federated States of,');
INSERT INTO country VALUES ('MCO','Monaco');
INSERT INTO country VALUES ('MNG','Mongolia');
INSERT INTO country VALUES ('MSR','Montserrat');
INSERT INTO country VALUES ('MAR','Morocco');
INSERT INTO country VALUES ('MOZ','Mozambique');
INSERT INTO country VALUES ('MMR','Myanmar');
INSERT INTO country VALUES ('NAM','Namibia');
INSERT INTO country VALUES ('NRU','Nauru');
INSERT INTO country VALUES ('NPL','Nepal');
INSERT INTO country VALUES ('NLD','Netherlands');
INSERT INTO country VALUES ('ANT','Netherlands Antilles');
INSERT INTO country VALUES ('NCL','New Caledonia');
INSERT INTO country VALUES ('NZL','New Zealand');
INSERT INTO country VALUES ('NIC','Nicaragua');
INSERT INTO country VALUES ('NER','Niger');
INSERT INTO country VALUES ('NGA','Nigeria');
INSERT INTO country VALUES ('NIU','Niue');
INSERT INTO country VALUES ('NFK','Norfolk Island');
INSERT INTO country VALUES ('MNP','Northern Mariana Islands');
INSERT INTO country VALUES ('NOR','Norway');
INSERT INTO country VALUES ('PSE','Occupied Palestinian Territory');
INSERT INTO country VALUES ('OMN','Oman');
INSERT INTO country VALUES ('PAK','Pakistan');
INSERT INTO country VALUES ('PLW','Palau');
INSERT INTO country VALUES ('PAN','Panama');
INSERT INTO country VALUES ('PNG','Papua New Guinea');
INSERT INTO country VALUES ('PRY','Paraguay');
INSERT INTO country VALUES ('PER','Peru');
INSERT INTO country VALUES ('PHL','Philippines');
INSERT INTO country VALUES ('PCN','Pitcairn');
INSERT INTO country VALUES ('POL','Poland');
INSERT INTO country VALUES ('PRT','Portugal');
INSERT INTO country VALUES ('PRI','Puerto Rico');
INSERT INTO country VALUES ('QAT','Qatar');
INSERT INTO country VALUES ('KOR','Republic of Korea');
INSERT INTO country VALUES ('MDA','Republic of Moldova');
INSERT INTO country VALUES ('REU','Réunion');
INSERT INTO country VALUES ('ROM','Romania');
INSERT INTO country VALUES ('RUS','Russian Federation');
INSERT INTO country VALUES ('RWA','Rwanda');
INSERT INTO country VALUES ('SHN','Saint Helena');
INSERT INTO country VALUES ('KNA','Saint Kitts and Nevis');
INSERT INTO country VALUES ('LCA','Saint Lucia');
INSERT INTO country VALUES ('SPM','Saint Pierre and Miquelon');
INSERT INTO country VALUES ('VCT','Saint Vincent and the Grenadines');
INSERT INTO country VALUES ('WSM','Samoa');
INSERT INTO country VALUES ('SMR','San Marino');
INSERT INTO country VALUES ('STP','Sao Tome and Principe');
INSERT INTO country VALUES ('SAU','Saudi Arabia');
INSERT INTO country VALUES ('SEN','Senegal');
INSERT INTO country VALUES ('SYC','Seychelles');
INSERT INTO country VALUES ('SLE','Sierra Leone');
INSERT INTO country VALUES ('SGP','Singapore');
INSERT INTO country VALUES ('SVK','Slovakia');
INSERT INTO country VALUES ('SVN','Slovenia');
INSERT INTO country VALUES ('SLB','Solomon Islands');
INSERT INTO country VALUES ('SOM','Somalia');
INSERT INTO country VALUES ('ZAF','South Africa');
INSERT INTO country VALUES ('ESP','Spain');
INSERT INTO country VALUES ('LKA','Sri Lanka');
INSERT INTO country VALUES ('SDN','Sudan');
INSERT INTO country VALUES ('SUR','Suriname');
INSERT INTO country VALUES ('SJM','Svalbard and Jan Mayen Islands');
INSERT INTO country VALUES ('SWZ','Swaziland');
INSERT INTO country VALUES ('SWE','Sweden');
INSERT INTO country VALUES ('CHE','Switzerland');
INSERT INTO country VALUES ('SYR','Syrian Arab Republic');
INSERT INTO country VALUES ('TWN','Taiwan Province of China');
INSERT INTO country VALUES ('TJK','Tajikistan');
INSERT INTO country VALUES ('THA','Thailand');
INSERT INTO country VALUES ('MKD','The former Yugoslav Republic of Macedonia');
INSERT INTO country VALUES ('TGO','Togo');
INSERT INTO country VALUES ('TKL','Tokelau');
INSERT INTO country VALUES ('TON','Tonga');
INSERT INTO country VALUES ('TTO','Trinidad and Tobago');
INSERT INTO country VALUES ('TUN','Tunisia');
INSERT INTO country VALUES ('TUR','Turkey');
INSERT INTO country VALUES ('TKM','Turkmenistan');
INSERT INTO country VALUES ('TCA','Turks and Caicos Islands');
INSERT INTO country VALUES ('TUV','Tuvalu');
INSERT INTO country VALUES ('UGA','Uganda');
INSERT INTO country VALUES ('UKR','Ukraine');
INSERT INTO country VALUES ('ARE','United Arab Emirates');
INSERT INTO country VALUES ('GBR','United Kingdom');
INSERT INTO country VALUES ('TZA','United Republic of Tanzania');
INSERT INTO country VALUES ('USA','United States');
INSERT INTO country VALUES ('VIR','United States Virgin Islands');
INSERT INTO country VALUES ('URY','Uruguay');
INSERT INTO country VALUES ('UZB','Uzbekistan');
INSERT INTO country VALUES ('VUT','Vanuatu');
INSERT INTO country VALUES ('VEN','Venezuela');
INSERT INTO country VALUES ('VNM','Viet Nam');
INSERT INTO country VALUES ('WLF','Wallis and Futuna Islands');
INSERT INTO country VALUES ('ESH','Western Sahara');
INSERT INTO country VALUES ('YEM','Yemen');
INSERT INTO country VALUES ('YUG','Yugoslavia');
INSERT INTO country VALUES ('ZMB','Zambia');
INSERT INTO country VALUES ('ZWE','Zimbabwe');

View File

@@ -1,74 +0,0 @@
<?php
include_once 'prepend.inc';
commonHeader('Upcoming Events');
?>
<h1>Upcoming Events</h1>
<p>
If you would like to see the list of events in a calendar format,
visit the <a href="http://www.php.net/cal.php">complete event calendar</a>.
You can also add events yourself with our "<a href="submit-event.php">Add
an Event</a>" form.
</p>
<?php
$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last');
function load_events() {
global $re;
$days = days();
$fp = @fopen("backend/events.csv",'r');
while(!feof($fp)) {
list($d,$m,$y,,$sdesc,$id,$ldesc,$url,$recur,$tipo,$sdato,$edato) = fgetcsv($fp,8192);
if(!$seen[$m][$id]) {
switch($tipo) {
case 1:
$events[] = array($id,$sdato,$sdesc,$ldesc,$url,$d,$m,$y);
break;
case 2:
$events[] = array($id,$sdato.' to '.$edato,$sdesc,$ldesc,$url,$d,$m,$y);
break;
case 3:
list($which,$day) = explode(':',$recur);
$events[] = array($id,'Every '.$re[(int)$which].' '.$days[$day].' of the month',$sdesc,$ldesc,$url,$d,$m,$y);
break;
}
$seen[$m][$id] = true;
}
}
return $events;
}
/* returns array of Days starting with 1 = Sunday */
function days() {
static $days=NULL;
if(!$days) for($i=1;$i<=7;$i++) {
$days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001));
}
return $days;
}
?>
<?php
$events = load_events();
?>
<table cellpadding="5" cellspacing="1" border="0" width="70%">
<?php
$cm = 0;
foreach($events as $event) {
$m = $event[6];
if($cm!=$m) {
$cm = $m;
$month = strftime('%B',mktime(12,0,0,$event[6],$event[5],$event[7]));
echo "</table><h2>&nbsp;&nbsp;$month</h2><table cellpadding=\"5\" cellspacing=\"1\" border=\"0\">\n";
}
echo '<tr bgcolor=#cccccc><td align=left><b><a name="'.$event[5].'_'.$event[6].'">'.$month.'</a> '.$event[5].'</b> <a href="'.$event[4].'">'.$event[2].'</a> ('.$event[1].")</td></tr>\n";
echo '<tr><td bgcolor=#e0e0e0>&nbsp;'.base64_decode($event[3])."</td></tr>\n";
}
?>
</table>
<?php
commonFooter();
?>

View File

@@ -394,4 +394,41 @@ function display_errors($errors)
echo '</div>';
}
function display_event($event,$include_date=1)
{
for ($i = 0; $i < 7; $i++) {
$days[$i+1] = strftime('%A',mktime(12,0,0,4,$i,2001));
}
$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last');
$sday = $event['start'] ? strtotime($event['start'])
: mktime(0,0,1,$event['smonth'],$event['sday'],$event['syear']);
$eday = $event['end'] ? strtotime($event['end'])
: mktime(0,0,1,$event['emonth'],$event['eday'],$event['eyear']);
?>
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr bgcolor="#dddddd"><td>
<?php
if ($include_date && ($event['start'] || $event['smonth'])) echo "<b>", date("F j, Y", $sday), "</b>\n";
if ($event['url']) echo '<a href="', htmlentities($event['url']),'">';
echo "<b>", htmlentities($event['sdesc']), "</b>";
if ($event['url']) echo "</a>";
switch ($event['type']) {
case 2:
case 'multi':
echo " (", date("Y-m-d",$sday), " to ", date("Y-m-d",$eday), ")";
break;
case 3:
case 'recur':
echo " (Every ", $re[$event['recur']], " ", $days[$event['recur_day']], " of the month)";
break;
}
?>
</td></tr>
<tr bgcolor="#eeeeee"><td><?php echo $event['ldesc']?></td></tr>
</table>
<?php
}
?>

View File

@@ -57,7 +57,7 @@ $fp = @fopen("backend/events.csv",'r');
if($fp) {
$cm=0;
while(!feof($fp)) {
list($d,$m,$y,$url,$desc) = fgetcsv($fp,8192);
list($d,$m,$y,$url,$desc,$id) = fgetcsv($fp,8192);
if($cm!=(int)$m) {
if($cm) $RSIDEBAR_DATA.= "<br />\n";
else $RSIDEBAR_DATA.='<h3>Upcoming Events<br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="submit-event.php">[add event]</a></h3>';
@@ -66,7 +66,7 @@ if($fp) {
unset($seen);
}
if(!$seen[$desc]) {
$RSIDEBAR_DATA .= "$d. <a href=\"$url\">$desc</a><br>\n";
$RSIDEBAR_DATA .= "$d. <a href=\"cal.php?id=$id\">$desc</a><br>\n";
$seen[$desc] = true;
}
}

View File

@@ -129,3 +129,26 @@ div.tip {
background: #eef;
padding: 0px 8px;
}
table#cal {
font-size: smaller;
}
table#cal a {
text-decoration: none;
}
table#cal a:hover {
text-decoration: underline;
}
table#cal a.day {
float: right;
font-weight: bold;
color: #666;
}
table#cal div.event {
margin-bottom: 2px;
padding-bottom: 2px;
border-bottom: 1px dashed #000;
}

View File

@@ -111,27 +111,10 @@ for ($i = 0; $i < 12; $i++) {
$re = array(1=>'First',2=>'Second',3=>'Third',4=>'Fourth',-1=>'Last',-2=>'2nd Last',-3=>'3rd Last');
if (isset($in)) {?>
<p><b>Preview:</b></p>
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr bgcolor="#dddddd"><td>
<b><?php echo date("F j, Y", mktime(0,0,1,$in['smonth'],$in['sday'],$in['syear']))?></b>
<?php
if ($in['url']) echo '<a href="', htmlentities($in['url']),'">';
echo htmlentities($in['sdesc']);
if ($in['url']) echo "</a>";
switch ($in['type']) {
case 'multi':
echo " ($in[syear]-$in[smonth]-$in[sday] to $in[eyear]-$in[emonth]-$in[eday])";
break;
case 'recur':
echo " (Every ", $re[$in['recur']], " ", $days[$in['recur_day']], " of the month)";
break;
}
if (isset($in)) {
echo "<p><b>Preview:</b></p>\n";
display_event($in);
?>
</td></tr>
<tr bgcolor="#eeeeee"><td><?php echo $in['ldesc']?></td></tr>
</table>
<p><b>Change:</b></p>
<?php
}