Back to vBulletin 4.x Add-ons

Countdown to Calendar Event
Mod Version: 1.01, by JohnKF

vB Version: 4.0.6 Rating: (5 votes - 4.20 average) Installs: 57
Released: 16 Oct 2010 Last Update: Never Downloads: 352
Not Supported Template Edits Additional Files Re-usable Code Translations  

This widget picks up the next 2 events from a calendar of your choice.

It displays a countdown to the first event then once the first event has arrived it begins a countdown to the second event. The only reason for picking up two events is that someone may visit the page close to the end of the first event then see the no event message. By picking up two events such a visitor will see the countdown to the second event start.

To install...

From the ZIP file, extract eventcountdown.js and copy it to your site.

Navigate to AdminCP -> Style & Templates -> Style Manager -> Edit Template
Double click the headinclude template to edit it and add the following just above the first <script tag you find...
HTML Code:
<script src="scripts/eventcountdown.js" type="text/javascript"></script>
...the above assumes you have copied eventcountdown.js file in to a folder called scripts. Adjust the src path to wherever you have placed the .js file.

Navigate to AdminCP -> CMS -> Widgets.
Create a PHP Type Widget and paste the below code.

PHP Code:
ob_start();
global 
$db,$vbulletin;
$event_calendarid="1";
$no_events_message="<div style='width: 100%; text-align: center; font-weight: bold'>There are no events.</div>";
$today_date mktime(000date(date("m")), date(date("d")),  date(date("y")));
$and=" and dateline_from > '".$today_date."'";

$getevents=$db->query_read("SELECT eventid, title, dateline_from from " TABLE_PREFIX "event WHERE calendarid='".$event_calendarid."' $and order by dateline_from ASC LIMIT 2");
$count=1;
if(!
$db->num_rows($getevents))
{
echo 
$no_events_message;

else
{
echo 
"<script type='text/javascript'>\n";
WHILE (
$events=$db->fetch_array($getevents))
{
$event_title=$events['title'];
$event_date vbdate('U',$events['dateline_from'], false,true,false,true)-vbdate('U');
if(
$count==1)
{
echo 
"var CountDownTimer=new CountDown('CountDownToChange',1,'".$event_title."<br />','".$event_date."','ywdhms',1)\n";
}
else
{
echo 
"CountDownTimer.AddNewEvent('".$event_title."<br />','".$event_date."','ywdhms',".$count.")\n";
}
$count++;
}
}
echo 
"CountDownTimer.DisplayTime(FormatResults)\n";
echo 
"</script>\n";
$db->free_result($getevents);
unset(
$events);
$output=ob_get_contents();
ob_end_clean(); 
To create a forum block...
  1. Navigate to AdminCP -> Forums & Moderators -> Forum Blocks Manager
  2. Click the Add Block button
  3. From the drop down list select Custom HTML/PHP
  4. Click the Continue button
  5. Give the block a title (e.g. Event Countdown) and a short description
  6. Set the cache time to 1 minute
  7. In Content Type select PHP
  8. In Content paste the PHP code above in to the text box
  9. Click the Save button

You can set the value for $event_calendarid to the calendar that you want countdown events to come from. Change $no_events_message to the HTML you want to have appear when there are no events left in the selected calendar.

This is the first widget I've written so if you spot any errors or improvements that can be made then please let me know.

If you have an all day event in the calendar the countdown is to the begining of that day. Add a ranged event to the calendar for an exact time. Also, allow for any changes that may occur if a change to or from DST occurs.

Added ob_start(); to beginning of script (17th Oct, 2010)

To have a picture make the Title of the event in the calendar the HTML to display the picture. For example...
HTML Code:
Your Event<br /><img src="images/picture.gif" width="140" height="130" alt="">
...which shows as the text above in the calendar title, but displays as text and a picture in the countdown.

Download

File Type: %1$s eventcountdown.zip (1.6 KB, 391 downloads)

Screenshots

Click image for larger version
Name:	eventcountdown.jpg
Views:	2513
Size:	8.2 KB
ID:	122828  

Similar Mods

[RELEASE vB 2.0.3] Countdown To Calendar Events vBulletin 2.x Full Releases

vblts.ru supports vBulletin®, 2022-2024