




FlexCMS eNews 
To subscribe to our enewsletter, please enter your email address in the box below and click the "Subscribe" button.
Note: You may easily remove yourself from the newsletter list at any time by following the instructions included with every mailing.  |
|
|  |

Home > FlexCMS Support Forum > User Help > Code Snippets > Today's Event Block

FlexCMS Support Forum


Today's Event Block Started April 25, 2005 @ 5:03pm by otter
 |
Post Message |
otter Administrator
Posts: 158 |
|
|
| Today's Event Block | April 25, 2005 @ 5:03pm | Ever want to list today's events in a block on your FlexCMS site? Here's how you do that:
1) Create a new block
2) Block Title: Today's Events
3) Cut and paste the following code into the Custom Block Contents area:

Code
$TZO = (($Settings['TimezoneOffset']+5)*3600);
$DateSplit = getdate(); $DayTimestamp = mktime(0,0,0,$DateSplit['mon'],$DateSplit['mday'],$DateSplit['year']);
$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+86400+$TZO)." order by DateCode asc"; $result55 = mysql_query($query55) or die (mysql_error()); if (mysql_num_rows($result55) > 0) { while ($row55 = mysql_fetch_array($result55)) { $query5 = "select * from `".$Settings['DBPrefix']."cl-Events` where RecordNumber='".$row55['EventID']."' and MinLevel<='".$UserLevel."' limit 1"; $result5 = mysql_query($query5) or die (mysql_error()); if (mysql_num_rows($result5) > 0) { $row5 = mysql_fetch_array($result5); print '<img src="'.$ImagesURL.'/spacer.gif" width="1" height="5" alt="" border="0"><br>'; print '<a href="'.$MainURL.'/calendar/details/'.$row5['RecordNumber'].'.html">'.$row5['Title'].'</a>'; if ($row5['StartTime'] >= 0) { $Hours = 0; $Minutes = 0; $Seconds = $row5['StartTime']; while ($Seconds >= 3600) { $Seconds = $Seconds - 3600; $Hours++; } while ($Seconds >= 60) { $Seconds = $Seconds - 60; $Minutes++; } $Suffix = 'am'; if ($Hours >= 12) { $Hours -= 12; $Suffix = 'pm'; } if ($Hours == 0) { $Hours = 12; } if ($Minutes < 10) { $Minutes = '0' . $Minutes; } $TimePrint = $Hours . ':' . $Minutes . $Suffix;
//if ($row55['EndTime'] >= 0 && $row55['EndTime'] > $row55['StartTime']) { if ($row5['EndTime'] >= 0) { $Hours = 0; $Minutes = 0; $Seconds = $row5['EndTime']; while ($Seconds >= 3600) { $Seconds = $Seconds - 3600; $Hours++; } while ($Seconds >= 60) { $Seconds = $Seconds - 60; $Minutes++; } $Suffix = 'am'; if ($Hours >= 12) { $Hours -= 12; $Suffix = 'pm'; } if ($Hours == 0) { $Hours = 12; } if ($Minutes < 10) { $Minutes = '0' . $Minutes; } $TimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix; } } else { $TimePrint = ''; } if ($TimePrint != '') { print ' <font size="1">('.$TimePrint.')<br></font>'; } else { print '<br>'; } print '<img src="'.$ImagesURL.'/spacer.gif" width="1" height="5" alt="" border="0"><br>'; $EventsPrinted++; } }
}
if ($EventsPrinted < 1) { print '<br>[No Events Today]<br>?';
} |
|
4) Check the box next to Process PHP Code?
5) Save your block.
And that's it! Your block should look something similiar to this:
 |
|
|
|
Last Edit: April 25, 2005 @ 5:04pm by otter | |
|
|
|
| |
|
|
| May 6, 2005 @ 9:18pm | Works great! Is there a simple way to modify this so that I can get a list of events for more than just today. Suppose I want all events from now to a variable "numberofdays" from now?
john |
|
|
|
|
|
|
| |
DCSun Administrator
Posts: 392 |
|
|
| May 6, 2005 @ 11:39pm | John,
Yes, you can modify the query to do whatever you want it to! This line near the top 
Code
$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+86400+$TZO)." order by DateCode asc"; |
| controls what the date range is. If you wanted it to be the next three days, you could do 
Code
$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+(86400*3)+$TZO)." order by DateCode asc"; |
| or 
Code
$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+(86400*7)+$TZO)." order by DateCode asc"; |
| would make it the next seven (notice the 86400*x).
If you need any more help simply reply here and we'll be happy to give you a hand.
David |
|
|
|
|
|
|
| |
|
|
| SORTING EVENTS BY STARTTIME WITHIN DATE | December 15, 2006 @ 9:39am | This code snippet does not sort the events by starttime within a date -- how would we do that?
Regards, Chris |
|
|
|
|
|
|
| |
DCSun Administrator
Posts: 392 |
|
|
| December 15, 2006 @ 11:59am | Hi Chris,
Yes, the start time is stored with the details of event, rather than with the dates (two separate tables).
To sort it by start times as well, the two need to be joined in the MySQL query.
Something like this should do the trick:

Code
$query55 = "select `".$Settings['DBPrefix']."cl-EventDates`.RecordNumber,`".$Settings['DBPrefix']."cl-EventDates`.DateCode,`".$Settings['DBPrefix']."cl-EventDates`.EventID from `".$Settings['DBPrefix']."cl-EventDates` left join `".$Settings['DBPrefix']."cl-Events` on `".$Settings['DBPrefix']."cl-EventDates`.EventID=`".$Settings['DBPrefix']."cl-Events`.RecordNumber where `".$Settings['DBPrefix']."cl-EventDates`.DateCode>=".($DayTimestamp+$TZO)." and `".$Settings['DBPrefix']."cl-EventDates`.DateCode<".($DayTimestamp+(86400*7)+$TZO)." order by `".$Settings['DBPrefix']."cl-EventDates`.DateCode asc, `".$Settings['DBPrefix']."cl-Events`.StartTime asc"; |
|
David |
|
|
|
|
|
|
|

|
|
|