Click here to Skip to main content
15,891,316 members
Articles / Programming Languages / C#

Events Manager: A Vista Gadget

Rate me:
Please Sign up or sign in to vote.
4.35/5 (28 votes)
2 Feb 20076 min read 91.8K   2.6K   55  
An events manager gadget for Windows Vista
// JScript File
// Called by Init (Document.js)
// Start a timer to check for upcoming events
function NotificationTimer()
{
    var searchText = document.getElementById("SearchTextBox").value;
    if(searchText == "" || searchText == null) LoadEvents();
    else Search(searchText);
    setTimeout(NotificationTimer, RefreshInterval * 60 * 1000);
}
// Called by AddLineToEventsList (EventManager.js)
function CheckEvent(eventId)
{
    var result = true;
    var radical = "Event" + eventId;
    var now = new Date();
    var eventDate = System.Gadget.Settings.read(radical + "EventDate");
    var notifyBefore = System.Gadget.Settings.read(radical + "NotifyBefore");
    
    var eventDateInMs = getDateFromFormat(eventDate, "M/d/yyyy H:m");
    var difference = eventDateInMs - now.getTime();
    
    // the event is too old, and should be deleted
    if(DeleteOldEvents==true && difference < -(OldEventDeletionDelay * 24 * 60 * 60 * 1000))
    {
        RemoveEvent(eventId);
        result = false;
    }
    // the event is old
    else if(difference <= 0)
    {
        System.Gadget.Settings.write(radical + "State", "Old");
    }
    // the event is coming soon (notify user/send email)
    else if(difference < (notifyBefore * 60 * 60 * 1000))
    {
        if(System.Gadget.Settings.read(radical + "SendEmail") == true &&
            System.Gadget.Settings.read(radical + "EmailSent") == false)
        {
            if(SendMail(eventId))
            {
                System.Gadget.Settings.write(radical + "EmailSent", true);
            }
        }
        System.Gadget.Settings.write(radical + "State", "Hot");
    }
    else
    {
        System.Gadget.Settings.write(radical + "State", "Cold");
    }
    return result;
}
function SendMail(eventId)
{
    var radical = "Event" + eventId;
    var result = true;
    // create an XmlHttpRequest obj
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    // ServerSideScript : script used to send mail
    // method : POST
    // async : false
    xmlHttp.Open("POST",System.Gadget.Settings.read("ServerSideScript"),false);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    // Email data
    var email = System.Gadget.Settings.read("YourEmail");
    var name = System.Gadget.Settings.read(radical + "Name");
    var description = System.Gadget.Settings.read(radical + "Description");
    var date = System.Gadget.Settings.read(radical + "EventDate");
    var message = "You have an upcoming event : " + name + ".\nDate : " + date + "\nDescription :\n" + description + "\n\nSent by Event Manager Gadget.";
    // if user specified an email adress
    if(email != "")
    {
        // send the request
        xmlHttp.send("address="+email+"&subject=notification : "+name+"&message="+message);
        if(xmlHttp.status != 200)
        {
            // if request failed
            result = false;
        }
    }
    else
    {
        result = false;
    }
    return result;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions