package main_package;

import java.io.IOException;
import java.io.Serializable;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;

@ManagedBean(name="welcome")
@ViewScoped

public class WelcomeBean implements Serializable
{
	boolean showAdmin, showDeposit,showEmployee, showTdsModule, showMsgModule, showUserApp, showAdminApp,showPersonalLoan, showPropertyLoan, showVehicleLoan, showGroupLoan, showOdLoan;
	boolean showMemberOdReport,sessionFlag, showHighMarkReport;
	String type, userId;
	DataBaseMethods db=new DataBaseMethods();
	
	public WelcomeBean() throws ParseException, IOException 
	{
		//System.out.println("Time 6 :"+new Timestamp(new Date().getTime()));
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		
		showAdmin=(boolean) ss.getAttribute("showWelcomeAdmin");
		showEmployee=(boolean) ss.getAttribute("showWelcomeEmployee");
		showHighMarkReport=(boolean) ss.getAttribute("showWelcomeHighMarkReport");
		showDeposit=(boolean) ss.getAttribute("showWelcomeDeposit");
//		showTdsModule=(boolean) ss.getAttribute("showWelcomeTdsModule");
//		showMsgModule=(boolean) ss.getAttribute("showWelcomeMsgModule");
//		showUserApp=(boolean) ss.getAttribute("showWelcomeUserApp");
//		showAdminApp=(boolean) ss.getAttribute("showWelcomeAdminApp");
//		showPersonalLoan=(boolean) ss.getAttribute("showWelcomePersonalLoan");
//		showPropertyLoan=(boolean) ss.getAttribute("showWelcomePropertyLoan");
//		showVehicleLoan=(boolean) ss.getAttribute("showWelcomeVehicleLoan");
//		showGroupLoan=(boolean) ss.getAttribute("showWelcomeGroupLoan");
//		showOdLoan=(boolean) ss.getAttribute("showWelcomeOdLoan");
//		showMemberOdReport=(boolean) ss.getAttribute("showMemberOdReport");
		userId=(String) ss.getAttribute("username");
		
		// Session use because db method call only one time at login bean and access value always from session.
		
		Date dt=new Date();
		Date expDt=db.checkSoftwareValidity();
		int days = (int) ((expDt.getTime() - dt.getTime()) / (1000 * 60 * 60 * 24));
		if(days<=20 && days>0)
		{
			RequestContext.getCurrentInstance().showMessageInDialog(new FacesMessage(FacesMessage.SEVERITY_INFO, "Server Renewal Required : Dear User, "+days+" Days Remaining to Renewal Your Server. You have to do it at least 7 to 10 days before expiration of the Server.", 
					" आपके सर्वर की वैधता समाप्त होने में "+days+" दिन शेष है, सेवाओं को जारी रखने के लिए कृपया तुरंत रिचार्ज कराये, गर्ग वेब इंफोटेक की बैंक डिटेल के लिए हेल्प मेनू में बैंक डिटेल पर क्लिक करे | धन्यवाद् !!! "));
			
		}
		/*else if(days<=0 && days<=-2)
		{
			RequestContext.getCurrentInstance().showMessageInDialog(new FacesMessage(FacesMessage.SEVERITY_INFO, "Software Required Update", 
					"Dear User, Your Software is Out Of Date. Please Update Your Software otherwise it will not work Properly."));
		}*/
		else if(days<=0)
		{
			RequestContext.getCurrentInstance().showMessageInDialog(new FacesMessage(FacesMessage.SEVERITY_INFO, "Server Renewal Required", 
					"Dear User, Your Software is Out Of Date. Please Update Your Software otherwise it will not work Properly."));
			FacesContext.getCurrentInstance().getExternalContext().redirect("loginPage.xhtml");
		}
	}
	
	
	public boolean isShowAdmin() {
		return showAdmin;
	}
	public void setShowAdmin(boolean showAdmin) {
		this.showAdmin = showAdmin;
	}
	public boolean isShowEmployee() {
		return showEmployee;
	}
	public void setShowEmployee(boolean showEmployee) {
		this.showEmployee = showEmployee;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}


	public boolean isShowTdsModule() {
		return showTdsModule;
	}


	public void setShowTdsModule(boolean showTdsModule) {
		this.showTdsModule = showTdsModule;
	}


	public boolean isShowPersonalLoan() {
		return showPersonalLoan;
	}


	public void setShowPersonalLoan(boolean showPersonalLoan) {
		this.showPersonalLoan = showPersonalLoan;
	}


	public boolean isShowPropertyLoan() {
		return showPropertyLoan;
	}


	public void setShowPropertyLoan(boolean showPropertyLoan) {
		this.showPropertyLoan = showPropertyLoan;
	}


	public boolean isShowVehicleLoan() {
		return showVehicleLoan;
	}


	public void setShowVehicleLoan(boolean showVehicleLoan) {
		this.showVehicleLoan = showVehicleLoan;
	}


	public boolean isShowGroupLoan() {
		return showGroupLoan;
	}


	public void setShowGroupLoan(boolean showGroupLoan) {
		this.showGroupLoan = showGroupLoan;
	}


	public String getUserId() {
		return userId;
	}


	public void setUserId(String userId) {
		this.userId = userId;
	}


	public boolean isShowMsgModule() {
		return showMsgModule;
	}


	public void setShowMsgModule(boolean showMsgModule) {
		this.showMsgModule = showMsgModule;
	}


	public boolean isShowOdLoan() {
		return showOdLoan;
	}


	public void setShowOdLoan(boolean showOdLoan) {
		this.showOdLoan = showOdLoan;
	}


	public boolean isShowUserApp() {
		return showUserApp;
	}


	public void setShowUserApp(boolean showUserApp) {
		this.showUserApp = showUserApp;
	}


	public boolean isShowAdminApp() {
		return showAdminApp;
	}


	public void setShowAdminApp(boolean showAdminApp) {
		this.showAdminApp = showAdminApp;
	}


	public boolean isShowMemberOdReport() {
		return showMemberOdReport;
	}


	public void setShowMemberOdReport(boolean showMemberOdReport) {
		this.showMemberOdReport = showMemberOdReport;
	}


	

	public boolean isSessionFlag() {
		return sessionFlag;
	}


	public void setSessionFlag(boolean sessionFlag) {
		this.sessionFlag = sessionFlag;
	}


	public boolean isShowHighMarkReport() {
		return showHighMarkReport;
	}


	public void setShowHighMarkReport(boolean showHighMarkReport) {
		this.showHighMarkReport = showHighMarkReport;
	}


	public boolean isShowDeposit() {
		return showDeposit;
	}


	public void setShowDeposit(boolean showDeposit) {
		this.showDeposit = showDeposit;
	}
	
	 
}
