using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Data.OracleClient;

/// <summary>
/// Summary description for Helper
/// </summary>
public class SecurityAgent
{
    public SecurityAgent()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static string AuthenticateArchive()
    {
        // mode = "l" live
        // mode = "a" archive
        if (HttpContext.Current.Session["mode"] != null)
        {
            string mode = HttpContext.Current.Session["mode"].ToString();
            if (mode.Equals("a"))
                HttpContext.Current.Response.Redirect("../Business/default.aspx?err=1");
        }
        else
        {
            HttpContext.Current.Response.Redirect("../Business/Default.aspx");
        }
        return "";
    }

    public static DataSet authenticateUserPage(string userID, string pageURL, ref string response, ref string message)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_AUTHENTICATE.Authenticate_User_Page";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_url", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_page_url"].Value = pageURL;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = userID;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();

        response = oracom.Parameters["p_res_code"].Value.ToString();
        message = oracom.Parameters["p_res_msg"].Value.ToString();

        return ds;
    }

    //public static DataSet getPageFunctions(string pageID)
    //{
    //    string DBConnection = Helper.dbConnection();

    //    OracleConnection oracon = new OracleConnection(DBConnection);
    //    oracon.Open();

    //    OracleCommand oracom = new OracleCommand();
    //    oracom.Connection = oracon;

    //    oracom.CommandType = CommandType.StoredProcedure;
    //    oracom.CommandText = "sec_module_core.get_page_functions";

    //    oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_page_fns", OracleType.Cursor).Direction = ParameterDirection.Output;

    //    oracom.Parameters["p_pid"].Value = pageID;

    //    OracleDataAdapter da = new OracleDataAdapter(oracom);
    //    DataSet ds = new DataSet();
    //    da.Fill(ds);
    //    oracon.Close();

    //    return ds;
    //}

}
