//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI;
using CommunityServer.Components;

namespace CommunityServer.Controls {

    public class UserOnlineStatus : UserInfo {
        

        protected override void Render(HtmlTextWriter writer) {
            Image image = new Image();
            DateTime date;
			string dateFormat;
			User user = this.User;

			if (user.IsAnonymous || IsCloakedUser) {
				return;
			}
        	CSContext cntx = CSContext.Current;
        	date = user.LastActivity;
			if (user.UserID > 0) 
			{
				dateFormat = user.Profile.DateFormat;

			} 
			else 
			{
				// date is already set
				dateFormat = cntx.SiteSettings.DateFormat;
			}
            
            if (user.LastActivity > DateTime.Now.AddMinutes(-15)) {
                image.ImageUrl = Globals.GetSkinPath() + "/images/user_IsOnline.gif";
				image.AlternateText = user.DisplayName + CommunityServer.Components.ResourceManager.GetString("User_UserOnlineStatus_isOnline") + date.ToString(dateFormat) + ", " + date.ToString(cntx.SiteSettings.TimeFormat);
            } else {
                image.ImageUrl = Globals.GetSkinPath() + "/images/user_IsOffline.gif";
				image.AlternateText = user.DisplayName + CommunityServer.Components.ResourceManager.GetString("User_UserOnlineStatus_isNotOnline") + date.ToString(dateFormat) + ", " + date.ToString(cntx.SiteSettings.TimeFormat); ;
            }

            // Render the image
            //
            image.RenderControl(writer);


        }

    }

}
