using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for ReadWriteManager /// public class ReadWriteManager { public ReadWriteManager() { // // TODO: Add constructor logic here // } // overloaded method accept's user's role as input and returns Board/Portfolio name public static string GetUserBoardPortfolio(string role) { string boardPortfolio = "None"; switch (role) { case "MemberAC": boardPortfolio = "Arts & Culture"; break; case "MemberAKEB": boardPortfolio = "Education Board"; break; case "MemberAKF": boardPortfolio = "Aga Khan Foundation"; break; case "MemberAKHB": boardPortfolio = "Health Board"; break; case "MemberAKSWB": boardPortfolio = "Social Welfare Board"; break; case "MemberAKU": boardPortfolio = "Aga Khan University"; break; case "MemberAKYSB": boardPortfolio = "Youth & Sports Board"; break; case "MemberCP": boardPortfolio = "Communications & Publications"; break; case "MemberCR": boardPortfolio = "Community Relations"; break; case "MemberEPB": boardPortfolio = "Economic Planning Board"; break; case "MemberHRDIVC": boardPortfolio = "HRD/IVC"; break; case "MemberITREB": boardPortfolio = "ITREB"; break; case "MemberJKServices": boardPortfolio = "Jamatkhana Services"; break; case "MemberSettlement": boardPortfolio = "Settlement"; break; case "MemberWDP": boardPortfolio = "Women's Development"; break; case "MemberQLEI": boardPortfolio = "Quality Life Elderly Improvement"; break; case "AdminFinance": boardPortfolio = "Finance"; break; case "ReadOnlyFull": boardPortfolio = "Read Only"; break; case "AdminPlanning": boardPortfolio = "Planning & Evaluations"; break; default: boardPortfolio = role; break; } return boardPortfolio; } public static string GetUserBoardPortfolio() { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; string boardPortfolio = "None"; int membershipCount = 0; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); MembershipUser user = Membership.GetUser(userName); if (user != null) { string[] roles = Roles.GetRolesForUser(user.ToString()); if (roles.Length >= 1) { boardPortfolio = String.Empty; foreach (string role in roles) { membershipCount++; if (membershipCount > 1) { boardPortfolio += "', '"; } if (role.IndexOf(@"Member") >= 0) { switch (role) { case "MemberAC": boardPortfolio += "Arts & Culture"; break; case "MemberAKEB": boardPortfolio += "Education Board"; break; case "MemberAKF": boardPortfolio += "Aga Khan Foundation"; break; case "MemberAKHB": boardPortfolio += "Health Board"; break; case "MemberAKSWB": boardPortfolio += "Social Welfare Board"; break; case "MemberAKU": boardPortfolio += "Aga Khan University"; break; case "MemberAKYSB": boardPortfolio += "Youth & Sports Board"; break; case "MemberCP": boardPortfolio += "Communications & Publications"; break; case "MemberCR": boardPortfolio += "Community Relations"; break; case "MemberEPB": boardPortfolio += "Economic Planning Board"; break; case "MemberHRDIVC": boardPortfolio += "HRD/IVC"; break; case "MemberITREB": boardPortfolio += "ITREB"; break; case "MemberJKServices": boardPortfolio += "Jamatkhana Services"; break; case "MemberSettlement": boardPortfolio += "Settlement"; break; case "MemberWDP": boardPortfolio += "Women''s Development"; break; case "MemberQLEI": boardPortfolio += "Quality Life Elderly Improvement"; break; default: boardPortfolio = role; break; } } else { boardPortfolio = role; } } } } return boardPortfolio; } public static void SetProjectDetailsPermissions(int ppStatusID, string ppStatus, Control pageForm, SqlDataSource ds) { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; bool enableStatusChange = false; bool enableForm = false; bool enableDateChange = false; bool displayEveryStatus = false; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); if (Roles.IsUserInRole(userName, "ChairBoardPortfolio")) { switch (ppStatus) { case "Pre-event Details": case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableStatusChange = true; enableForm = true; break; } } else if (Roles.IsUserInRole(userName, "AdminFinance")) { enableForm = true; switch (ppStatus) { case "New": case "Post-event Finance Review": enableStatusChange = true; break; case "Complete": case "Cancelled": enableForm = false; break; } } else if (Roles.IsUserInRole(userName, "AdminPlanning")) { enableStatusChange = true; enableForm = true; enableDateChange = true; displayEveryStatus = true; } else if (Roles.IsUserInRole(userName, "ReadOnlyFull")) { enableStatusChange = false; enableForm = false; } else { switch (ppStatus) { case "Pre-event Details": case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableStatusChange = false; enableForm = true; break; } } // Populate Status dropdown DropDownList proposalStatusDropDown = (DropDownList)pageForm.FindControl("proposalStatusDropDown"); if (displayEveryStatus == true) { Utilities.populateCombo(ds, proposalStatusDropDown, "mspPPStatusGetAll", "PPStatusID", "PPStatus"); } else { Utilities.populateCombo(ds, proposalStatusDropDown, "mspPPStatusGetByCurrentStatus", "PPStatusID", "PPStatus", "CurrentStatusID", ppStatusID); } if (enableForm == false) { Utilities.DisableControls(pageForm); } else if (enableStatusChange == true) { // Find the controls to enable DropDownList dropdown = (DropDownList)pageForm.FindControl("proposalStatusDropDown"); Button button = (Button)pageForm.FindControl("updateStatusButton"); // Enable controls dropdown.Enabled = true; button.Enabled = true; } // enable ability to change date if role is AdminPlanning if (enableDateChange == true) { OboutInc.Calendar2.Calendar eventDateCalendar = (OboutInc.Calendar2.Calendar)pageForm.FindControl("eventDateCalendar"); TextBox proposedDateTextBox = (TextBox)pageForm.FindControl("proposedDateTextBox"); Button updateEventDateButton = (Button)pageForm.FindControl("updateEventDateButton"); eventDateCalendar.AllowDeselect = true; eventDateCalendar.OnClientDateChanged = "onDateChange"; eventDateCalendar.TextBoxId = proposedDateTextBox.ID; //Changed date can only be picked up if textbox is enabled and NOT read-only proposedDateTextBox.Enabled = true; //proposedDateTextBox.ReadOnly = true; updateEventDateButton.Visible = true; } // Hyperlinks for services spreadsheets are always enabled HyperLink link = (HyperLink)pageForm.FindControl("servicesSpreadsheetHyperLink"); link.Enabled = true; link = (HyperLink)pageForm.FindControl("ppServicesSpreadsheetHyperLink"); link.Enabled = true; } public static void SetBudgetDetailsPermissions(string ppStatus, Control pageForm) { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; bool enableForm = false; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); if (Roles.IsUserInRole(userName, "ChairBoardPortfolio")) { switch (ppStatus) { case "Pre-event Details": case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableForm = true; break; } } else if (Roles.IsUserInRole(userName, "AdminFinance")) { enableForm = true; } else if (Roles.IsUserInRole(userName, "AdminPlanning")) { enableForm = true; } else if (Roles.IsUserInRole(userName, "ReadOnlyFull")) { enableForm = false; } else { switch (ppStatus) { case "Pre-event Details": case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableForm = true; break; } } if (enableForm == false) { Utilities.DisableControls(pageForm); } // Hyperlinks for budget forms are always enabled //HyperLink link = (HyperLink)pageForm.FindControl("servicesSpreadsheetHyperLink"); //link.Enabled = true; //link = (HyperLink)pageForm.FindControl("ppServicesSpreadsheetHyperLink"); //link.Enabled = true; } public static void SetEvalDetailsPermissions(string ppStatus, Control pageForm) { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; bool enableForm = false; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); if (Roles.IsUserInRole(userName, "ChairBoardPortfolio")) { switch (ppStatus) { case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableForm = true; break; } } else if (Roles.IsUserInRole(userName, "AdminFinance")) { enableForm = true; } else if (Roles.IsUserInRole(userName, "AdminPlanning")) { enableForm = true; } else if (Roles.IsUserInRole(userName, "ReadOnlyFull")) { enableForm = false; } else { switch (ppStatus) { case "Event Implementation": case "Post-event Fix (PEIT)": case "Post-event Fix (Finance)": enableForm = true; break; } } if (enableForm == false) { Utilities.DisableControls(pageForm); } } public static void SetGLCodeControlPermissions(string ppStatus, Control pageForm) { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; bool enableGLCodeChange = false; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); if (Roles.IsUserInRole(userName, "AdminFinance")) { enableGLCodeChange = true; } if (enableGLCodeChange == true) { // Find the controls to enable TextBox textbox = (TextBox)pageForm.FindControl("glCodeTextBox"); Button button = (Button)pageForm.FindControl("updateGLCodeButton"); Label label = (Label)pageForm.FindControl("glCodeValueLabel"); // Enable controls textbox.Visible = true; button.Visible = true; label.Visible = false; } //Hyperlinks for downloadable forms are always enabled HyperLink link = (HyperLink)pageForm.FindControl("ChequeReqHyperLink"); link.Enabled = true; link = (HyperLink)pageForm.FindControl("DepositHyperLink"); link.Enabled = true; } public static bool GetOSBudgetEditPermissions() { System.Security.Principal.IPrincipal User; User = System.Web.HttpContext.Current.User; bool osBudgetEditable = false; string userName = Utilities.GetLoggedInUserID(User.Identity.Name); if (Roles.IsUserInRole(userName, "AdminFinance")) { osBudgetEditable = true; } return osBudgetEditable; } }