|
|
Due to the volume of spam happening on our forums, posting is now restricted to verified members only. If you're not verified, drop us a note with your username.
|
|
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: 177 |
|
|
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:
|
ONLINE TRAINING CLASSES FOR FLEXCMS IN MAY: FlexCMS Basics (101), Sat., May, 15, 2010 & FlexCMS Blocks (Mon., May 10, 2010). |
|
|
|
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: 625 |
|
|
| 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
FlexCMS v3.2 Has Been Released! |
|
|
|
|
|
|
| |
|
|
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: 625 |
|
|
| 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
FlexCMS v3.2 Has Been Released! |
|
|
|
|
|
|
| |
|
|
| November 25, 2010 @ 1:16pm | This is awsome... One more request. I have included all this code so my events are now sorted and showing 5-days out. How do we now display the "day" tag as a seperator from day to day in the block so all the events don't just run together but are also sorted by date and then time with "day tags?? I'm starting to like this cms.
why sleep when I can work... |
|
|
|
|
|
|
| |
DCSun Administrator
Posts: 625 |
|
|
| November 25, 2010 @ 5:37pm | Add this:
Code
if ($LastDay != $row55['DateCode']) { if ($LastDay != '') { print '<img src="'.$ImagesURL.'/spacer.gif" width="1" height="15" alt="" border="0"><br>'; }
print '<b>'.date('l, F j', $row55['DateCode']).'</b><br><img src="'.$ImagesURL.'/spacer.gif" width="1" height="5" alt="" border="0"><br>'; $LastDay = $row55['DateCode']; } |
|
before this line:
Code
print '<a href="'.$MainURL.'/calendar/details/'.$row5['RecordNumber'].'.html">'.$row5['Title'].'</a>'; |
|
Dave
FlexCMS v3.2 Has Been Released! |
|
|
|
|
|
|
| |
|
|
| November 26, 2010 @ 12:52am | Perfect! That did the trick. Formatted the type and added a <hr> and I am good to go! Thanks Dave.
why sleep when I can work... |
|
|
|
|
|
|
| |
DCSun Administrator
Posts: 625 |
|
|
|
|
|
|
|
|
|
|
|
| MEMBERS
|
|
|