diff -u -r -N karmapools.orig/docs/Changelog karmapools/docs/Changelog
--- karmapools.orig/docs/Changelog 2004-09-11 19:52:34.000000000 -0500
+++ karmapools/docs/Changelog 2004-09-12 14:18:39.085417304 -0500
@@ -50,4 +50,22 @@
Patch: patch-0.0.3-01
Author: Mike Green
-Moved source/ out of the source!
\ No newline at end of file
+Moved source/ out of the source!
+
+Date: 2004-09-12 14:12
+Patch: patch-0.0.3-02
+Author: Mike Green
+
+includes/app.functions.php: added stats information array to
+queryPoolInfo().
+
+includes/globals.php: added define for db include file so that database
+types can be abstracted. Moved requires() to bottom of file to account
+for DBINCLUDE.
+
+includes/html.functions.php: Moved month and day header routines to
+their own functions - drawMonthHeader() and drawDayHeader(). Changed loop
+to key off of total days from start_date instead of end_date due to daylight
+savings time causing weirdness.
+
+Added user pick count total to output if user is logged in.
\ No newline at end of file
diff -u -r -N karmapools.orig/includes/app.functions.php karmapools/includes/app.functions.php
--- karmapools.orig/includes/app.functions.php 2004-09-11 16:51:46.000000000 -0500
+++ karmapools/includes/app.functions.php 2004-09-12 10:55:04.807269824 -0500
@@ -556,6 +556,15 @@
$info_ar = db_fetch_array($qid);
db_free_result($qid);
+// don't abort on this one
+$stats_ar = array();
+$fl = "pool_id,days_total,days_taken";
+$sql = "select $fl from " . DBN . ".pool_stats ";
+$sql .= "where pool_id=$pool_id limit 1";
+if ($qid = db_query($sql) and db_num_rows($qid) == 1) {
+ $stats_ar = db_fetch_array($qid);
+ }
+
$sql = "select a.user_id,a.date_guess,a.user_comment,b.user_name ";
$sql .= "from " . DBN . ".pool_data as a, " . DBN . ".pool_users as b ";
$sql .= "where a.pool_id=$pool_id and a.user_id=b.user_id ";
@@ -574,7 +583,8 @@
}
db_free_result($qid);
-return array('info'=>$info_ar,'entries'=>$entries_ar,'dates'=>$dates_ar);
+return array('info'=>$info_ar,'stats'=>$stats_ar,
+ 'entries'=>$entries_ar,'dates'=>$dates_ar);
}
diff -u -r -N karmapools.orig/includes/globals.php karmapools/includes/globals.php
--- karmapools.orig/includes/globals.php 2004-09-11 16:24:57.000000000 -0500
+++ karmapools/includes/globals.php 2004-09-12 09:51:18.712924576 -0500
@@ -5,15 +5,15 @@
* Created 2004-09-09 Mike Green *
*****************************************************************************/
if (basename($PHP_SELF) == basename(__FILE__)) { die("Access Denied"); }
-require_once('includes/mysql.functions.php');
-require_once('includes/html.functions.php');
-require_once('includes/app.functions.php');
// database settings
define(DBH,"localhost");
define(DBN,"date_pools");
define(DBU,"webuser");
define(DBP,"webuser");
+// Database abstraction library in the includes directory. In case
+// someone wants to port to another database engine.
+define(DBINCLUDE,"mysql.functions.php");
// defaults - comment out banner and url if you don't want it.
define(DEFAULT_SITE_TITLE,"Badpenguins Karma Pools");
@@ -57,6 +57,11 @@
define(USERID_MAX_LEN,100);
define(UA_MAX_LEN,255);
+// includes
+require_once('includes/' . DBINCLUDE);
+require_once('includes/html.functions.php');
+require_once('includes/app.functions.php');
+
// start the session
session_start();
session_register("POOLSESS");
diff -u -r -N karmapools.orig/includes/html.functions.php karmapools/includes/html.functions.php
--- karmapools.orig/includes/html.functions.php 2004-09-11 19:01:28.000000000 -0500
+++ karmapools/includes/html.functions.php 2004-09-12 14:07:07.500554184 -0500
@@ -3,11 +3,17 @@
* Copyright (c)2004 badpenguins.com *
* Distributed under the terms of the GNU General Public License v2 *
* Created 2004-09-09 Mike Green *
- *****************************************************************************/
+ *****************************************************************************/
if (basename($PHP_SELF) == basename(__FILE__)) { die("Access Denied"); }
/*****************************************************************************
- *
+ * This is messy. It would be much faster to use database queries to *
+ * calculate date differences and such, but different database engines have *
+ * different capabilities, so we handle all date calculations in php for *
+ * optimum portability. We don't use php calendar routines for the same *
+ * reason, can't count on everyone using --enable-calendar when compiling *
+ * php! Daylight savings time causes havoc, so we overload mktime() with *
+ * days_forward to run the loop. *
*****************************************************************************/
function displayPoolCalendar($echo=true,$pool_ar='',$cols='7') {
@@ -16,106 +22,100 @@
$info_ar = $pool_ar['info'];
$entries_ar = $pool_ar['entries'];
$dates_ar = $pool_ar['dates'];
-
if (!is_array($info_ar) or !is_array($entries_ar) or !is_array($dates_ar)) {
return false;
}
-
-$start_date = $info_ar['pool_start'] . " 01:00:00";
-$end_date = $info_ar['pool_end'] . " 01:00:00";
-$start_ts = strtotime($start_date);
-$end_ts = strtotime($end_date);
-$cur_date = date('Y-m-d 01:00:00');
-$cur_ts = strtotime($cur_date);
$pool_id = $info_ar['pool_id'];
$pool_desc = stripslashes($info_ar['pool_desc']);
-
-$first_day = date('l',$start_ts);
-$first_mon = date('F',$start_ts);
-$first_year = date('Y',$start_ts);
-$last_year = $first_year;
-$last_month = $first_mon;
$day_header = array("Monday","Tuesday","Wednesday","Thursday","Friday",
"Saturday","Sunday");
-// fix the calendar so that Monday is the first day
+// get all of the date information together
+$start_date = $info_ar['pool_start'];
+$cut_date = $info_ar['cutoff_date'];
+$end_date = $info_ar['pool_end'];
+$cur_date = date('Y-m-d');
+$start_ts = strtotime($start_date . " 00:00:00");
+$cut_ts = strtotime($cut_date . " 00:00:00");
+$end_ts = strtotime($end_date . " 00:00:00");
+$cur_ts = strtotime($cur_date . " 00:00:00");
+$first_day = date('j',$start_ts);
+$first_month = date('n',$start_ts);
+$first_year = date('Y',$start_ts);
+$last_year = $first_year;
+$last_month = $first_month;
+// calculate total days
+$e_month = date('n',$end_ts);
+$e_day = date('j',$end_ts);
+$e_year = date('Y',$end_ts);
+$total_days = getDaysDiff($first_year,$first_month,$first_day,
+ $e_year,$e_month,$e_day);
+// turn off links if cutoff or end date has expired
+if (($cur_ts > $cut_ts) or ($cur_ts > $end_ts)) {
+ $showlinks = false;
+ } else {
+ $showlinks = true;
+ }
+// pad so that Monday is the first day
$pad_cells = 0;
+$first_day_str = date('l',$start_ts);
for($j=0; $j < count($day_header); $j++) {
- if ("$day_header[$j]" == "$first_day") {
+ if ("$day_header[$j]" == "$first_day_str") {
$pad_cells = $j;
break;
}
}
// manually create the first month/year header and
// align the days_header up with monday.
-$col_ctr = 0;
-$mon_ctr = 0;
-$next_mon = $mon_ctr + 1;
-$next_qs = "#month_" . $next_mon;
-$next_url = ">";
-$html .= "";
-$html .= "| ";
-$html .= "";
-$html .= "$first_mon $first_year $next_url |
\n";
-$html .= "\n";
-foreach($day_header as $day) {
- $html .= " | $day | \n";
- }
-$html .= "
\n";
+$html .= drawMonthHeader(false,$start_ts,false);
+$html .= drawDayHeader(false,"Monday");
+
if ($pad_cells > 0) {
- $td = " N/A | \n";
+ $td = " N/A | \n";
$html .= "\n";
$html .= str_repeat($td,$pad_cells);
$col_ctr = $pad_cells;
+ } else {
+ $col_ctr = 0;
}
-for($j=$start_ts; $j <= $end_ts; $j += (60*60*24)) {
+$limit = $first_day + $total_days;
+for($j=$first_day; $j < $limit; $j++) {
$col_ctr++;
- $cur_year = date('Y',$j);
- $cur_month = date('F',$j);
- $day_str = date('jS',$j);
-
- if ($cur_ts > $j) { $expired = true; } else { $expired = false; }
-
+ $ts = mktime(0,0,0,$first_month,$j,$first_year);
+ $cur_year = date('Y',$ts);
+ $cur_month = date('n',$ts);
+ $day_str = date('jS',$ts);
+ $cur_month_txt = date('F',$ts);
+ $cur_day_txt = date('jS',$ts);
+ if ($cur_ts > $ts) { $expired = true; } else { $expired = false; }
if ("$cur_month" !== "$last_month" and $col_ctr == 1) {
$last_month = $cur_month;
- $mon_ctr++;
- $prev_mon = $mon_ctr - 1;
- $prev_qs = "#month_" . $prev_mon;
- $prev_url = "<";
- $next_mon = $mon_ctr + 1;
- $next_qs = "#month_" . $next_mon;
- $next_url = ">";
- $html .= "
";
- $html .= "| ";
- $html .= "";
- $html .= "$prev_url $cur_month $cur_year";
- $html .= " $next_url |
\n";
- $html .= "\n";
- foreach($day_header as $day) {
- $html .= " | ";
- $html .= "$day | \n";
- }
- $html .= "
\n";
+ $n_ts = mktime(0,0,0,$cur_month+1,1,$cur_year);
+ if ($n_ts >= $end_ts) { $drawnext=false; } else { $drawnext=true; }
+ $html .= drawMonthHeader(false,$ts,true,$drawnext);
+ $html .= drawDayHeader(false,"Monday");
}
if ("$cur_month" !== "$last_month") {
- $day_str = substr($cur_month,0,3) . " $day_str";
+ $day_str = date('M',$ts) . " $day_str";
}
if ( $col_ctr == 1 ) {
$html .= "\n";
}
- $comp_date = date('Y-m-d',$j);
+ $comp_date = date('Y-m-d',$ts);
$username = false;
+ $date_text = $day_str;
if (in_array($comp_date,$dates_ar)) {
- $select_url = $day_str;
- $username = $entries_ar["$comp_date"]['user_name'];
- $picked = true;
+ $username = $entries_ar["$comp_date"]['user_name'];
+ $picked = true;
} else {
- $select_url = "$day_str";
- $picked = false;
+ $picked = false;
+ }
+ if ($showlinks and !$picked) {
+ $date_text = "$day_str";
}
if ($expired) {
- $select_url = $day_str;
+ $date_text = $day_str;
if ($picked) {
$td_class = "exptak";
} else {
@@ -124,11 +124,13 @@
}
if ($picked and !$expired) { $td_class = "taken"; }
if (!$picked and !$expired) { $td_class = "avail"; }
-
+ if (date('Y-m-d',$ts) == $cut_date) {
+ $td_class = "cutoff";
+ }
$html .= " ";
- $html .= "$select_url";
+ $html .= "$date_text";
if ($username) { $html .= " $username"; }
$html .= " | \n";
if ( $col_ctr == 7) {
@@ -142,7 +144,6 @@
$html .= str_repeat($td,(7 - $col_ctr));
$html .= "
\n";
}
-
if ($echo) { echo $html; } else { return $html; }
}
@@ -260,13 +261,107 @@
$picks[] = $entry['date_guess'];
}
}
+
+$per_count = $pool_ar['info']['allowed_entries'];
+$cur_count = count($picks);
+$rem_count = $per_count - $cur_count;
+
+$html = "You have selected $cur_count date(s) and have $rem_count pick(s)";
+$html .= " remaining. ";
+
if (count($picks) > 0) {
- $html = "
Your picks: ";
+ $html .= "Your picks:
";
foreach($picks as $pick) {
$html .= "$pick ";
}
- $html .= "
";
}
+$html .= "
";
+
+if ($echo) { echo $html; } else { return $html; }
+
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+function drawDayHeader($echo=false,$start_day='Monday') {
+
+$start_day = strtolower($start_day);
+
+switch($start_day) {
+ case 1|"tuesday":
+ $d = array("Tuesday","Wednesday","Thursday","Friday","Saturday",
+ "Sunday","Monday");
+ break;
+ case 2|"wednesday":
+ $d = array("Wednesday","Thursday","Friday","Saturday","Sunday",
+ "Monday","Tuesday");
+ break;
+ case 3|"thursday":
+ $d = array("Thursday","Friday","Saturday","Sunday","Monday",
+ "Tuesday","Wednesday");
+ break;
+ case 4|"friday":
+ $d = array("Friday","Saturday","Sunday","Monday","Tuesday",
+ "Wednesday","Thursday");
+ break;
+ case 5|"saturday":
+ $d = array("Saturday","Sunday","Monday","Tuesday","Wednesday",
+ "Thursday","Friday");
+ break;
+ case 6|"sunday":
+ $d = array("Sunday","Monday","Tuesday","Wednesday","Thursday",
+ "Friday","Saturday");
+ break;
+ default:
+ $d = array("Monday","Tuesday","Wednesday","Thursday","Friday",
+ "Saturday","Sunday");
+ break;
+ }
+
+$html = "\n";
+foreach($d as $day) {
+ $html .= " | ";
+ $html .= "$day | \n";
+ }
+$html .= "
\n";
+
+if ($echo) { echo $html; } else { return $html; }
+
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+function drawMonthHeader($echo=true,$timestamp='',
+ $link_prev=true,$link_next=true,$cols=7) {
+
+if ($timestamp == '') { return false; }
+$year = date('Y',$timestamp);
+$month = date('n',$timestamp);
+$day = date('j',$timestamp);
+if (!checkdate($month,$day,$year)) { return false; }
+
+if ($link_prev) {
+ $ts = mktime(0,0,0,$month - 1,1,$year);
+ $pm = "month_" . date('n-Y',$ts);
+ $lp = "< ";
+ } else {
+ $lp = " ";
+ }
+if ($link_next) {
+ $ts = mktime(0,0,0,$month + 1,1,$year);
+ $nm = "month_" . date('n-Y',$ts);
+ $ln = " >";
+ } else {
+ $ln = " ";
+ }
+$aname = "";
+$text = date('F',$timestamp) . " $year";
+$home = "$text";
+$html .= "| ";
+$html .= $aname . $lp . $home . $ln . " |
\n";
+
if ($echo) { echo $html; } else { return $html; }
}