From 4bc1e32a79c0928a079113c51f9cf9fcaf525a63 Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Tue, 29 Dec 2009 20:46:26 +0000 Subject: (OC) I cut down the calendar queries to just one which seems to work out a lot better. git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@409 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- blocks/mini_calendar/functions.php | 173 +++++++------------------------------ blocks/mini_calendar/index.php | 8 +- 2 files changed, 33 insertions(+), 148 deletions(-) (limited to 'blocks') diff --git a/blocks/mini_calendar/functions.php b/blocks/mini_calendar/functions.php index 968c7af..1133daa 100644 --- a/blocks/mini_calendar/functions.php +++ b/blocks/mini_calendar/functions.php @@ -20,110 +20,7 @@ /** * Note to anyone feeling the need to edit this file... * You MUST declare $db as global inside your functions in order access MySQL from here. - */ - - /** - * SelectDate($date) - * Function for outputing an html form for selecting a month day and year - * @param date - formatted date string yyyy-mm-dd (optional) - */ - function SelectDate($date = NULL){ - - //function for adding to the db in sql 'datetime' format - //$date = date("Y-m-d h:i:s", mktime(8, 30, 0, 10, 26, 2009)); - //$date = "2009-11-2"; - //echo $date."
"; - //function for parsing our date format into an array - //echo "
";
-	$date_arr = date_parse($date); //returns an associative array $array['year']
-	//print_r($date_arr);
-	//echo "
"; - //echo $date_arr['year']." ".$date_arr['month']." ".$date_arr['day']."
";; - - //List Months - echo '"; - - //List Days - echo '"; - - //List Years [CurYear, CurYear+5] - echo '"; - - } - - function ListEvents($date){ - - global $db; - -?> -
-

Events for:

-
- Add New Event -
-"; - - $result = $db->Query("SELECT * FROM bayonet_events WHERE `date` = '$date' ORDER BY `time`"); - while(($row = $db->Fetch($result))!=false) - { - $tmp = true; - - $datetime = date_create($date.' '.$row['time']); - $time = date_format($datetime, 'g:ia'); //gets time in hour:minutes am|pm -?> - - - -      - - Edit -  |  - Delete - - - -

- - - -
- -There are no events posted for this day."; - - echo ""; - - } - + */ /** * PrintCalendar() - prints the calendar with events @@ -132,42 +29,13 @@ $date = time(); date_default_timezone_set("America/New_York"); //EASTERN TIME ZONE - - //GET values for month and year - $month = ""; - $year = ""; - //$month = $_GET['month']; - //$year = $_GET['year']; - - $useCurDate = true; - - //check to makes sure month and year are in the desired ranges - if(!empty($month) && !empty($year) && $month > 0 && $month < 13 && $year > 1990){ - $useCurDate = false; - } - //check to see if the get variables are for todays month - if($month == date('n', $date) && $year == date('Y', $date)){ - $useCurDate = true; - } - - //use current date unless GET values are set - if($useCurDate) - { - $day = date('d', $date); - $today = date('j', $date); - $month = date('m', $date); - $monthNum = date('n', $date); - $year = date('Y', $date); - } - else - { - $monthNum = $month; - //if GET values are equal to curdate, set $today - if($year == date('Y', $date) && $monthNum == date('n', $date)) - $today = date('j', $date); - else - $today = 0; - } + + $day = date('d', $date); + $today = date('j', $date); + $month = date('m', $date); + $monthNum = date('n', $date); + $year = date('Y', $date); + /* Accounts for the last couple days from the previous months */ $first_day = mktime(0,0,0,$monthNum, 1, $year); @@ -236,6 +104,9 @@ echo ''.$days_before.''; //'.$days_before.''; $day_count++; } + +$sqlToday = $year.'-'.$monthNum.'-'.$today; +$events = GetEventsOnInterval("{$year}-{$monthNum}-01","{$year}-{$monthNum}-{$days_in_month}"); //loop printing each day of the CURRENT month ONLY while($day_num <= $days_in_month){ @@ -247,11 +118,20 @@ } $sqlDate = $year.'-'.$monthNum.'-'.$day_num; //old way NOT unix - + //checks to see if the current day has events $isEvent=false; + foreach($events as $event){ + if($event['date'] == $sqlDate){ + $isEvent = true; + if($event['date'] == $sqlToday){ + $todaysEvents[] = $event; + } + } + + } - global $db; + /* global $db; $result = $db->Query("SELECT title,color,date,time FROM `bayonet_events` WHERE `date` = '$sqlDate' ORDER BY `date` DESC"); while(($row = $db->Fetch($result))!=false) { @@ -259,7 +139,7 @@ if($day_num == $today){ $todaysEvents[] = $row; } - } + } */ if($day_num == $today && $isEvent==true){ echo '
'.$day_num.'
'; }else if($day_num == $today && $isEvent==false){ @@ -306,5 +186,12 @@ } } } + +function GetEventsOnInterval($start,$end){ + global $db; + $result = $db->Query("SELECT `event_id`, `title`, `color`, `date`, `time` FROM `bayonet_events` WHERE `date` BETWEEN '$start' AND '$end' ORDER BY `time` ASC"); + $events = $db->Fetch($result); + return $events; +} ?> \ No newline at end of file diff --git a/blocks/mini_calendar/index.php b/blocks/mini_calendar/index.php index c67df9a..c58469b 100644 --- a/blocks/mini_calendar/index.php +++ b/blocks/mini_calendar/index.php @@ -1,5 +1,3 @@ - - - - - \ No newline at end of file + + + -- cgit