using framework_business; using framework_library; using System; using System.Collections; using System.Configuration; using System.Data; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; public partial class Core : System.Web.UI.MasterPage { #region methods /// /// Shoulder Practice - Get checklist from surface app "Month End Checklist". If all items checked don't show /// private bool BindMonthEndCheckboxListAndShow() { bool hide = true; try { //UserControl lblTest = (UserControl)this.FindControl("navigation1"); //if (lblTest == null) // throw new Exception("lblTest not found."); //else // throw new Exception("FOUND"); UpdatePanel upCheck = (UpdatePanel)this.FindControl("upChecklist"); if (upCheck == null) throw new Exception("upChecklist not found."); CheckBoxList chkMonthEndChecklist = (CheckBoxList)upCheck.FindControl("chkMonthEndChecklist"); if (chkMonthEndChecklist == null) throw new Exception("chkMonthEndChecklist not found."); Label lblMonthEndChecklistHead = (Label)upCheck.FindControl("lblMonthEndChecklistHead"); chkMonthEndChecklist.Items.Clear(); string periodCol = ""; string currentPeriod = System.DateTime.Now.ToString("yyyyMM"); if (lblMonthEndChecklistHead != null) lblMonthEndChecklistHead.Text = "Month End Checklist - " + System.DateTime.Now.ToString("MMM yyyy"); foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", "MonthEndChecklist")) { ArrayList fieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surf.recId.ToString(), "sequence"); if (fieldList == null || fieldList.Count <= 0) throw new Exception("No fields found for surface Month End Checklist."); foreach (oSurfaceField field in fieldList) { if (field.surfaceFieldDisplay == "Period") { periodCol = field.surfaceFieldName; break; } } if (periodCol == "") throw new Exception("No Period field found for surface Month End Checklist."); //get data for current month DataTable surfaceData = xData.GetSurfaceData(surf.recId); //loop through fields, add all checkbox types to checkboxlist and determine if checked or not from data foreach (oSurfaceField field in fieldList) { if (field.surfaceFieldTypeId != pNums.FieldType.Checkbox.GetHashCode()) continue; ListItem chk = new ListItem(field.surfaceFieldDisplay.Replace("_", ","), field.surfaceFieldName); chk.Attributes.Add("class", "checkbox"); chk.Selected = false; foreach (DataRow row in surfaceData.Rows) { if (row[periodCol].ToString() != currentPeriod) continue; foreach (DataColumn col in surfaceData.Columns) { if (col.ColumnName == field.surfaceFieldName) { if (row[col].ToString() == "1") chk.Selected = true; break; } } } chkMonthEndChecklist.Items.Add(chk); if (!chk.Selected) hide = false; } } } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return !hide; } /// /// Setup Page Optimisation /// private void SetupPageOptimisation() { string title = String.Empty; string keywords = String.Empty; string description = String.Empty; try { switch (Page.AppRelativeVirtualPath.ToLower()) { case "~/default.aspx"://home page break; case "~/canvas.aspx"://canvas page string canvasTitle = handler.GetRoutedData("canvas-title"); //fetch canvas based on routed data ArrayList canvasList = xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "name", canvasTitle); //enumerate canvas list foreach (oCanvas canv in canvasList) { title = canv.seoTitle; keywords = canv.seoKeywords; description = canv.seoDescription; break; } break; case "~/media.aspx"://canvas page title = "Media"; keywords = "Media"; description = "Media"; break; } //chck if title provided if (title != String.Empty) AddPageOptimisation(title, keywords, description); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Page Optimisation /// /// /// /// private void AddPageOptimisation(string PageTitle, string keywords, string description) { Page.Title = PageTitle; metKeywords.Attributes.Add("content", keywords); metDescription.Attributes.Add("content", description); } /// /// Populate Terms /// private void PopulateTerms() { try { ArrayList Content = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "isActive", "1", "sequence"); foreach (oContent page in Content) { if (page.title.ToLower().Contains("terms")) { lblTerms.Text = page.contentHTML; } if (page.title.ToLower().Contains("privacy")) { lblPrivacy.Text = page.contentHTML; } } } catch (Exception ex) { exception.HandleException("Palette Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Populate User values /// /// private void PopulateUserValues(oUser _usr) { try { lblRegProfileHeading.Text = "Update My Details"; txbRegName.Text = _usr.name; txbRegLastName.Text = _usr.surname; //txbRegStreetAddress.Text = _usr.addressPhysical; //txbRegPostalAddress.Text = _usr.addressPostal; txbRegTelephone.Text = _usr.tel; txbRegEmail.Text = _usr.email; //txbRegCompany.Text = _usr.company; //txbRegCompanyAddress.Text = _usr.addressCompany; if (_usr.cookieId != String.Empty) chkRegRememberMe.Checked = true; chkRegTerms.Checked = _usr.isTermsAccepted; if (chkRegTerms.Checked) { btnRegister.Enabled = true; btnRegister.CssClass = "btn btn-success"; } else { btnRegister.Enabled = false; btnRegister.CssClass = "btn"; } //check if subscribed for email foreach (oSubscriber sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriber), "email", _usr.email)) { chkSubscribe.Checked = sub.isActive; break; } //check if subscribed for sms foreach (oSubscriberSMS sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriberSMS), "mobile", _usr.tel)) { chkSubscribeSMS.Checked = sub.isActive; break; } btnRegister.Text = "Update"; } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { oUser user = new oUser(); oSetup _setup = new oSetup(); try { if (!Page.IsPostBack) { _setup = handler.ReturnSetup(); divGoogleSignIn.Visible = _setup.isGoogleSignIn; //handle auth process if (Request.QueryString["auth"] != null && Request.QueryString["auth"] != String.Empty) { //3 step verification encryption encrypt = new encryption("p@l3tt3"); string encryptedCode = encrypt.DecodeUrlString(Request.QueryString["auth"]); string authData = encrypt.decryptData(encryptedCode); string[] authArr = authData.Split(char.Parse("|")); bool verified = true; if (authArr.Length >= 3) { //step 1 compare customer code if (authArr[0] != _setup.code) verified = false; //step 2 verify we have an id int id = 0; int.TryParse(authArr[1], out id); if (id == 0) verified = false; if (authArr.Length == 4)//registration first time { string val = authArr[3]; if (val == "reg") { foreach (oUser usr in xData.GetTypedByCriteriaSpecific("recId", typeof(oUser), "recId", authArr[1], "", "pal_",true)) { if (!usr.isActive) { usr.isActive = true; xData.UpdateTyped("recId", usr.recId.ToString(), typeof(oUser), usr, "pal_", true); hfReg.Value = "1"; //jas todo //lblLoginReset.Visible = true; //txbLoginEmail.Text = usr.email; //lblLoginReset.Text = "You have been sucessfully verified, login to continue"; upLogin.Update(); } else { hfReg.Value = "0"; } break; } } else verified = false; } else { //step 4 verify we have done this on the same day DateTime authDate = new DateTime(); DateTime.TryParse(authArr[2], out authDate); if (authDate.Date != DateTime.Now.Date) verified = false; if (verified) { foreach (oUser usr in xData.GetTypedByCriteriaSpecific("recId", typeof(oUser), "recId", authArr[1], "", "pal_",true)) { if (usr.isActive) { Session["user"] = usr; } break; } } } } else verified = false; } else { hfReg.Value = "0"; } //Setup Page Optimisation SetupPageOptimisation(); PopulateTerms(); SetTheme(); lblYear.Text = DateTime.Now.Year.ToString(); oSetup cc = handler.ReturnSetup(); /* CVH 2016-09-13 Add trading as name to company name */ string companyName = cc.customer; if (cc.tradingAs != String.Empty && !companyName.Contains(" t/a ")) companyName += " t/a " + cc.tradingAs; lblCustomerName.Text = companyName.Replace(" Website", ""); switch (Page.AppRelativeVirtualPath.ToLower()) { case "~/default.aspx": Page.Title = companyName; break; case "~/error.aspx": Page.Title = companyName; break; } if (utils.verifySession("user")) { user = (oUser)Session["user"]; PopulateUserValues(user); } } } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void SetTheme() { try { oSetup setup = handler.ReturnSetup(); if (setup.theme != null && setup.theme != string.Empty) { HtmlLink link = Page.Master.FindControl("theme") as HtmlLink; if (link != null) link.Href = "/css/Themes/" + setup.theme + ".css"; } } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Register User /// /// /// protected void btnRegister_Click(object sender, EventArgs e) { try { oSetup _setup = handler.ReturnSetup(); encryption encrypt = new encryption("p@l3tt3"); oUser regUser = new oUser(); Session["logout"] = null; if (utils.verifySession("user")) regUser = (oUser)Session["user"]; regUser.customerCode = _setup.code; regUser.isActive = true; regUser.name = txbRegName.Text; regUser.surname = txbRegLastName.Text; //regUser.addressPhysical = txbRegStreetAddress.Text; //regUser.addressPostal = txbRegPostalAddress.Text; regUser.email = txbRegEmail.Text; regUser.tel = txbRegTelephone.Text; regUser.password = encrypt.encryptValue(txbRegPassword.Text); //regUser.company = txbRegCompany.Text; //regUser.addressCompany = txbRegCompanyAddress.Text; if (Request.AnonymousID != null && chkRegRememberMe.Checked) { regUser.cookieId = Request.AnonymousID; } else { regUser.cookieId = String.Empty; } regUser.isTermsAccepted = chkRegTerms.Checked; //handle email subscriptions oSubscriber subEmail = new oSubscriber(); foreach (oSubscriber sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriber), "email", regUser.email)) { subEmail = sub; break; } subEmail.name = regUser.name; subEmail.email = regUser.email; subEmail.isActive = chkSubscribe.Checked; if (subEmail.recId > 0) xData.UpdateTyped("recId", subEmail.recId.ToString(), typeof(oSubscriber), subEmail); else { if (subEmail.isActive) subEmail.recId = xData.SaveTyped("recId", typeof(oSubscriber), subEmail); } //handle sms subscriptions oSubscriberSMS subSMS = new oSubscriberSMS(); foreach (oSubscriberSMS sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriberSMS), "mobile", regUser.tel)) { subSMS = sub; break; } subSMS.name = regUser.name; subSMS.mobile = regUser.tel; subSMS.isActive = chkSubscribeSMS.Checked; if (subSMS.recId > 0) xData.UpdateTyped("recId", subSMS.recId.ToString(), typeof(oSubscriberSMS), subSMS); else { if (subSMS.isActive) subSMS.recId = xData.SaveTyped("recId", typeof(oSubscriberSMS), subSMS); } if (regUser.recId > 0)//update { regUser.dateUpdated = DateTime.Now; if (xData.UpdateTyped("recId", regUser.recId.ToString(), typeof(oUser), regUser, "pal_", true)) { Session["user"] = regUser; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } else //save new { if (!xData.VerifyExists("recId", typeof(oUser), "email,isActive,customerCode", regUser.email + ",1," + _setup.code, "", "pal_", true)) { regUser.dateCreated = DateTime.Now; regUser.userType = pNums.UserType.WebsiteUser.GetHashCode(); if (_setup.securePath != String.Empty) { regUser.isActive = false; } regUser.recId = xData.SaveTyped("recId", typeof(oUser), regUser, "pal_", true); if (regUser.recId > 0) { if (_setup.securePath != String.Empty) { if (SendSecureRegistrationEmail(regUser)) { lblRegResult.Visible = true; lblRegResult.Text = "Thank you for your registering, we have emailed you the steps to login."; upRegister.Update(); } else { xData.DeleteTyped("recId", regUser.recId.ToString(), typeof(oUser), "pal_", true); lblRegResult.Visible = true; lblRegResult.Text = "Registration failed, please ensure email details are valid and try again."; upRegister.Update(); } } else { Session["user"] = regUser; //send registration email here SendRegistrationEmail(regUser); string redirectpath = String.Empty; //find secure landing page foreach (oCanvas page in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "isActive,isSecureLandingPage", "1,1", "sequence")) { redirectpath = page.name.ToLower(); break; } if (redirectpath != String.Empty) { Response.Redirect(_setup.securePath + "/pages/" + redirectpath, false); } else if (_setup.code == "SHOU-1") { Response.Redirect("/pages/patient~info", false); } else { Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } }; } } else { lblRegResult.Visible = true; lblRegResult.Text = "A user already exists with this email address"; upRegister.Update(); } } } catch (Exception ex) { exception.HandleException("Register:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Accept Pay Terms and register /// /// /// protected void btnAcceptPayTerms_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modPay", "$('#modPay').modal();", true); } /// /// Send Registration Email /// /// private void SendRegistrationEmail(oUser regUser) { //use template to get body string outboundBody = string.Empty, subjectOutbound = string.Empty; oEmail email = new oEmail(); bool outboundSent = false; foreach (oTemplate registrationTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString())) { if (registrationTemplate.templateName.ToLower().Contains("registration")) { outboundBody = registrationTemplate.templateContent; subjectOutbound = registrationTemplate.templateName; break; } } utils.MergeHTMData(ref outboundBody, utils.BuildFieldCodeList(regUser)); /* CVH 2016-09-13 Use communication email in Company Setup as from email address */ oSetup setup = handler.ReturnSetup(); email.fromAddress = setup.communicationEmail; email.toAddress = regUser.email; email.Subject = subjectOutbound; email.Body = outboundBody; /* CVH 2016-09-13 Set email from address display name from Company Setup */ outboundSent = communication.SendAnEmail(email, setup.sendingEmailName); } /// /// Send Registration Email /// /// private bool SendSecureRegistrationEmail(oUser regUser) { //use template to get body string outboundBody = string.Empty, subjectOutbound = string.Empty; oEmail email = new oEmail(); oSetup _setup = handler.ReturnSetup(); bool outboundSent = false; bool securefound = false; foreach (oTemplate registrationTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString())) { if (registrationTemplate.templateName.ToLower().Contains("secure registration")) { outboundBody = registrationTemplate.templateContent; subjectOutbound = registrationTemplate.templateName; securefound = true; break; } } utils.MergeHTMData(ref outboundBody, utils.BuildFieldCodeList(regUser)); //setup secure auth link string authCode = String.Empty; encryption encrypt = new encryption("p@l3tt3"); authCode = HttpUtility.UrlEncode(encrypt.encryptValue(_setup.code + "|" + regUser.recId + "|" + DateTime.Now.ToString("yyyy-MM-dd") + "|reg")); outboundBody = outboundBody.Replace("{secureAuth}", _setup.securePath + "/home?auth=" + authCode); /* CVH 2016-09-13 Use communication email in Company Setup as from email address */ email.fromAddress = _setup.communicationEmail; email.toAddress = regUser.email; email.Subject = subjectOutbound; email.Body = outboundBody; if (securefound) { /* CVH 2016-09-13 Set email from address display name from Company Setup */ outboundSent = communication.SendAnEmail(email, _setup.sendingEmailName); } return outboundSent; } /// /// Checked Changed event for terms /// /// /// protected void chkRegTerms_CheckedChanged(object sender, EventArgs e) { try { if (chkRegTerms.Checked) { btnRegister.Enabled = true; btnRegister.CssClass = "btn btn-success"; } else { btnRegister.Enabled = false; btnRegister.CssClass = "btn"; } } catch (Exception ex) { exception.HandleException("Register:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Login click /// /// /// protected void btnLogin_Click(object sender, EventArgs e) { try { oSetup _setup = handler.ReturnSetup(); Session["logout"] = null; encryption encrypt = new encryption("p@l3tt3"); bool userValid = false; int userType = 0; string password = encrypt.encryptValue(txtPassword.Value); string email = txtEmail.Value; string authCode = String.Empty; foreach (oUser usr in xData.GetTypedByCriteriaSpecific("recId", typeof(oUser), "email,password", email + "," + password, "", "pal_",true)) { if (usr.customerCode == _setup.code) { userValid = true; } else if (usr.customerCode == "EVOL-1" && usr.userType > pNums.UserType.PowerUser.GetHashCode() && usr.userType != (int)pNums.UserType.CustomUser) { userValid = true; } if (userValid) { userType = usr.userType; //jas todo //if (chkRememberMe.Checked) //{ // if (Request.AnonymousID != null) // { usr.cookieId = Request.AnonymousID; } //} //else //{ usr.cookieId = String.Empty; } usr.dateLoggedOn = DateTime.Now; xData.UpdateTyped("recId", usr.recId.ToString(), typeof(oUser), usr, "pal_", true); if (_setup.securePath != String.Empty) { Session["user"] = usr; //setup auth code authCode = HttpUtility.UrlEncode(encrypt.encryptValue(_setup.code + "|" + usr.recId + "|" + DateTime.Now.ToString("yyyy-MM-dd"))); } else { Session["user"] = usr; } break; } } if (userValid) { //CVH - 2016-07-27 - Shoulder Practice - Show checklist modal if specific user on successful login if (_setup.code == "SHOU-1" && ConfigurationManager.AppSettings["MonthEndUser"] != null && ConfigurationManager.AppSettings["MonthEndUser"].ToString().ToUpper() == email.ToUpper()) { dynamic navigation = this.FindControl("navigation1"); navigation.ReloadControl(); if (BindMonthEndCheckboxListAndShow()) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modChecklist", "ShowChecklistModal();", true); else ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "closeLogin", "$('#modLogin').modal('hide');", true); } //GR -- added custom redirect to patient info page if website user else if (userType == pNums.UserType.WebsiteUser.GetHashCode() && _setup.code == "SHOU-1")//to do we need to handle better Response.Redirect(_setup.securePath + "/pages/patient~info?auth=" + authCode, false); else { string redirectpath = String.Empty; //find secure landing page if (userType == pNums.UserType.WebsiteUser.GetHashCode()) { foreach (oCanvas page in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "isActive,isSecureLandingPage", "1,1", "sequence")) { redirectpath = page.name.ToLower(); break; } } if (redirectpath != String.Empty) { Response.Redirect(_setup.securePath + "/pages/" + redirectpath + "?auth=" + authCode, false); } else { switch (Page.AppRelativeVirtualPath.ToLower()) { case "~/default.aspx": Response.Redirect(_setup.securePath + "/home?auth=" + authCode, false); break; case "~/canvas.aspx": string page = handler.GetRoutedData("canvas-title"); Response.Redirect(_setup.securePath + "/pages/" + page + "?auth=" + authCode, false); break; case "~/error.aspx": Response.Redirect(_setup.securePath + "/home?auth=" + authCode, false); break; default: Response.Redirect(_setup.securePath + "/home?auth=" + authCode, false); break; } } } //jas todo //lblResult.Visible = false; //lblResult.Text = ""; } else { //jas todo //lblResult.Visible = true; //lblResult.Text = "Email or password is incorrect..."; } } catch (Exception ex) { exception.HandleException("Login:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Click event for the subscribe button /// /// /// protected void btnSubscribe_Click(object sender, EventArgs e) { try { oSubscriber subscriber = new oSubscriber(); foreach (oSubscriber sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriber), "email", txbEmailSubscribe.Text)) { subscriber = sub; break; } subscriber.email = txbEmailSubscribe.Text; subscriber.name = txtNameSubscribe.Text; subscriber.isActive = true; if (subscriber.recId > 0) { if (xData.UpdateTyped("recId", subscriber.recId.ToString(), typeof(oSubscriber), subscriber)) { lblResultSubscribe.Visible = true; lblResultSubscribe.Text = "Thank you for subscribing."; } } else { subscriber.recId = xData.SaveTyped("recId", typeof(oSubscriber), subscriber); if (subscriber.recId > 0) { lblResultSubscribe.Visible = true; lblResultSubscribe.Text = "Thank you for subscribing."; } } if (txbMobileSubscribe.Text != String.Empty) { oSubscriberSMS subscriberSMS = new oSubscriberSMS(); foreach (oSubscriberSMS sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriberSMS), "mobile", txbMobileSubscribe.Text)) { subscriberSMS = sub; break; } subscriberSMS.mobile = txbMobileSubscribe.Text; subscriberSMS.name = txtNameSubscribe.Text; subscriberSMS.isActive = true; if (subscriberSMS.recId > 0) { if (xData.UpdateTyped("recId", subscriberSMS.recId.ToString(), typeof(oSubscriberSMS), subscriberSMS)) { lblResultSubscribe.Visible = true; lblResultSubscribe.Text = "Thank you for subscribing."; } } else { subscriberSMS.recId = xData.SaveTyped("recId", typeof(oSubscriberSMS), subscriberSMS); if (subscriberSMS.recId > 0) { lblResultSubscribe.Visible = true; lblResultSubscribe.Text = "Thank you for subscribing."; } } } } catch (Exception ex) { exception.HandleException("Subscribe:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close after Cart message /// /// /// protected void btnClose_Click(object sender, EventArgs e) { try { Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Forgot Password Click /// /// /// protected void lnkForgot_Click(object sender, EventArgs e) { try { pnlLogin.Visible = false; pnlForgot.Visible = true; //btnLogin.Visible = false; //btnReset.Visible = true; //lblLoginReset.Text = "Reset Password"; } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Click event to go back to login /// /// /// protected void lnkBackToLogin_Click(object sender, EventArgs e) { try { pnlLogin.Visible = true; pnlForgot.Visible = false; //btnLogin.Visible = true; //btnReset.Visible = false; //lblLoginReset.Text = "Login"; ScriptManager.RegisterStartupScript(this, GetType(), "renderButton", "renderButton();", true); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Reset Password /// /// /// /// /// REVISION 001: UrlEncode the encrypted reset code string before adding it to the Query String /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 15 January 2016 /// protected void btnReset_Click(object sender, EventArgs e) { string encCode = String.Empty; bool resetValid = false; try { oSetup _setup = handler.ReturnSetup(); foreach (oUser usrReset in xData.GetTypedByCriteriaSpecific("recId", typeof(oUser), "isActive,email,customerCode", "1," + txtResetEmail.Value + "," + _setup.code, "", "pal_",true)) { resetValid = true; encryption encReset = new encryption("r3s3t"); usrReset.isReset = true; usrReset.resetCode = utils.RandomString(6, true); usrReset.dateUpdated = DateTime.Now; //update user with reset code and reset status also date updated set as this is used to determine if reset has expirecd if (xData.UpdateTyped("recId", usrReset.recId.ToString(), typeof(oUser), usrReset, "pal_", true)) { //encrypt code for resetting encCode = HttpUtility.UrlEncode(encReset.encryptValue(usrReset.resetCode)); oEmail email = new oEmail(); string resetbody = String.Empty; string Subject = String.Empty; foreach (oTemplate resetTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString())) { if (resetTemplate.templateName.ToLower().Contains("reset")) { resetbody = resetTemplate.templateContent; Subject = resetTemplate.templateName; break; } } //merge internal body with values resetbody = resetbody.Replace("src=\"/images", "src=\"" + ConfigurationManager.AppSettings["WebAddy"] + "/images"); resetbody = resetbody.Replace("{WebAddress}", ConfigurationManager.AppSettings["WebAddy"]); resetbody = resetbody.Replace("{encCode}", encCode); /* CVH 2016-09-13 Use communication email in Company Setup as from email address */ oSetup setup = handler.ReturnSetup(); email.fromAddress = setup.communicationEmail; email.toAddress = usrReset.email; email.Body = resetbody; /* CVH 2016-09-13 Subject shouldn't read "Palette", get from config */ //email.Subject = "Palette - " + Subject; email.Subject = ConfigurationManager.AppSettings["WebAddy"].Replace("{content}", Subject); /* CVH 2016-09-13 Set from address display name from Company Setup */ if (communication.SendAnEmail(email, setup.sendingEmailName)) { lblResultReset.Visible = true; lblResultReset.Text = "Success, we have sent you further instructions."; } } } if (!resetValid) { lblResultReset.Visible = true; lblResultReset.Text = "email address not found."; } } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnSendContact_Click(object sender, EventArgs e) { try { CheckBox chkSubscribeContact = this.FindControl("chkSubscribeContact") as CheckBox; oSetup _setup = handler.ReturnSetup(); oEmail email = new oEmail(); string body = String.Empty; string Subject = String.Empty; foreach (oTemplate contactTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString())) { if (contactTemplate.templateName.ToLower().Contains("contact") || contactTemplate.templateName.ToLower().Contains("website enquiry")) { body = contactTemplate.templateContent; Subject = contactTemplate.templateName; break; } } //merge internal body with values body = body.Replace("src=\"/images", "src=\"" + ConfigurationManager.AppSettings["WebAddy"] + "/images"); body = body.Replace("{ContactFromEmail}", txtContactFromEmail.Text); body = body.Replace("{ContactName}", txtContactName.Text); body = body.Replace("{ContactMessageBody}", txtContactMessage.Text); if (chkSubscribeContact != null && chkSubscribeContact.Checked) { body = body.Replace("{sub}", "Yes"); } else { body = body.Replace("{sub}", "No"); } email.fromAddress = ConfigurationManager.AppSettings["from"]; email.toAddress = ConfigurationManager.AppSettings["admin"]; email.bccAddress = ConfigurationManager.AppSettings["support"]; email.Subject = Subject; email.Body = body; if (_setup.code == "SHOU-1") { /* CVH 2016-09-05 Remove hard coded "The Shoulder Practice", get from config */ /* Get hidden value, change subject */ HtmlInputHidden lblContactHidden = (HtmlInputHidden)this.Page.FindControl("lblContactHidden"); if (lblContactHidden != null && lblContactHidden.Value == "Ask Dr Christelle") email.Subject = ConfigurationManager.AppSettings["support"].Replace("{content}", "Enquiry for Dr Christelle"); else email.Subject = ConfigurationManager.AppSettings["support"].Replace("{content}", Subject); if (communication.SendAnEmail(email)) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Thank you for your enquiry, it has been sent.');", true); } else { lblContactResult.Text = "There was an error trying to send your enquiry."; lblContactResult.Visible = true; } } else { if (communication.SendAnEmail(email)) { if (chkSubscribeContact != null && chkSubscribeContact.Checked) { oSubscriber subscriber = new oSubscriber(); subscriber.email = txtContactFromEmail.Text; subscriber.name = txtContactName.Text; subscriber.isActive = true; foreach (oSubscriber sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriber), "email", subscriber.email)) { subscriber.recId = sub.recId; break; } if (subscriber.recId > 0) { xData.UpdateTyped("recId", subscriber.recId.ToString(), typeof(oSubscriber), subscriber); } else { subscriber.recId = xData.SaveTyped("recId", typeof(oSubscriber), subscriber); } } lblContactResult.Text = "Thank you for your enquiry, it has been sent. "; lblContactResult.Visible = true; } else { lblContactResult.Text = "There was an error trying to send your enquiry."; lblContactResult.Visible = true; } } } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Shoulder Practice - instance specific modal event handler /// /// /// protected void chkMonthEndChecklist_SelectedIndexChanged(object sender, EventArgs e) { //checklist saved as surface data. when checked changed, delete current month data and resave current selections try { CheckBoxList chkList = (CheckBoxList)sender; if (chkList != null) { string currentPeriod = System.DateTime.Now.ToString("yyyyMM"); ArrayList surfList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", "MonthEndChecklist"); if (surfList == null || surfList.Count <= 0) throw new Exception("Month End Checklist surface could not be found."); oSurface surf = (oSurface)surfList[0]; ArrayList fieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surf.recId.ToString()); if (fieldList == null || fieldList.Count <= 0) throw new Exception("No fields found for Month End Checklist surface."); ArrayList dataList = new ArrayList(); foreach (oSurfaceField field in fieldList) { //delete all data linked to this month and resave from scratch if (field.surfaceFieldDisplay == "Period") { foreach (oSurfaceFieldData itemDel in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceFieldValueChar", surf.recId + "," + field.recId + "," + currentPeriod)) { if (xData.DeleteTyped("surfaceItemId", itemDel.surfaceItemId.ToString(), typeof(oSurfaceFieldData))) { if (xData.DeleteTyped("recId", itemDel.surfaceItemId.ToString(), typeof(oSurfaceItem))) { } } } oSurfaceFieldData data = new oSurfaceFieldData(); data.surfaceFieldID = field.recId; data.surfaceId = surf.recId; data.surfaceFieldValueChar = currentPeriod; dataList.Add(data); } //build new data if (field.surfaceFieldTypeId == (int)pNums.FieldType.Checkbox) { oSurfaceFieldData data = new oSurfaceFieldData(); data.surfaceFieldID = field.recId; data.surfaceId = surf.recId; data.surfaceFieldValueBool = false; foreach (ListItem chk in chkList.Items) { if (chk.Value == field.surfaceFieldName) { if (chk.Selected) data.surfaceFieldValueBool = true; break; } } dataList.Add(data); } } //create new item int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; oSurfaceItem item = new oSurfaceItem(); item.createdBy = userId; item.dateCreated = System.DateTime.Now; item.isActive = true; item.isDeleted = false; item.surfaceId = surf.recId; item.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), item); foreach (oSurfaceFieldData newData in dataList) { newData.surfaceItemId = item.recId; } xData.SaveTypedCollection("recId", typeof(oSurfaceFieldData), dataList); BindMonthEndCheckboxListAndShow(); } else throw new Exception("Checkboxlist is null."); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Submit /// /// /// protected void btnSubmitTips_Click(object sender, EventArgs e) { try { oDownloadSubmission submission = new oDownloadSubmission(); TextBox txbEmail = this.FindControl("txbEmail") as TextBox; TextBox txbName = this.FindControl("txbName") as TextBox; TextBox txbTelephone = this.FindControl("txbTelephone") as TextBox; Button btnDownloadTips = this.FindControl("btnDownloadTips") as Button; UpdatePanel upDownload = this.FindControl("upDownload") as UpdatePanel; CheckBox chkSubscribeTips = this.FindControl("chkSubscribeTips") as CheckBox; submission.dateSubmitted = DateTime.Now; submission.email = txbEmail.Text; submission.name = txbName.Text; submission.tel = txbTelephone.Text; foreach (oDownloadSubmission dnSub in xData.GetTypedByCriteriaSpecific("recId", typeof(oDownloadSubmission), "email", txbEmail.Text)) { submission.recId = dnSub.recId; break; } //save submission if (submission.recId > 0)//update { xData.UpdateTyped("recId", submission.recId.ToString(), typeof(oDownloadSubmission), submission); } else//add { submission.recId = xData.SaveTyped("recId", typeof(oDownloadSubmission), submission); } if (submission.recId > 0)//send internal mail notification { //handle opt in for newsletter if (chkSubscribeTips.Checked) { oSubscriber subscriber = new oSubscriber(); subscriber.email = txbEmail.Text; subscriber.name = txbName.Text; subscriber.isActive = true; foreach (oSubscriber sub in xData.GetTypedByCriteriaSpecific("recId", typeof(oSubscriber), "email", subscriber.email)) { subscriber.recId = sub.recId; break; } if (subscriber.recId > 0) { xData.UpdateTyped("recId", subscriber.recId.ToString(), typeof(oSubscriber), subscriber); } else { subscriber.recId = xData.SaveTyped("recId", typeof(oSubscriber), subscriber); } } oEmail submissionMail = new oEmail(); submissionMail.Subject = "Evolution Software Website - Download Submission"; submissionMail.fromAddress = ConfigurationManager.AppSettings["from"]; submissionMail.toAddress = ConfigurationManager.AppSettings["admin"]; submissionMail.bccAddress = ConfigurationManager.AppSettings["bcc"]; string Body = utils.ConvertHTMLFiletoString(Server.MapPath("~/templates/internal/DownloadSubmission.htm")); utils.MergeHTMData(ref Body, utils.BuildFieldCodeList(submission)); Body = Body.Replace("{WebAddress}", ConfigurationManager.AppSettings["WebAddy"]); if (chkSubscribeTips.Checked) { Body = Body.Replace("{sub}", "yes"); } else { Body = Body.Replace("{sub}", "no"); } submissionMail.Body += Body; communication.SendAnEmail(submissionMail); //set visible for download btnDownloadTips.Visible = true; upDownload.Update(); } } catch (Exception ex) { exception.HandleException("Tips:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); } } /// /// Download the 15 Tips /// /// /// protected void btnDownloadTips_Click(object sender, EventArgs e) { try { Response.Clear(); //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=Evolution_Software_15Tips.pdf"); Response.TransmitFile(Server.MapPath("~/upload/file/Evolution_Software_15Tips.pdf")); Response.Flush(); Response.SuppressContent = true; ApplicationInstance.CompleteRequest(); } catch (Exception ex) { exception.HandleException("Tips:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); } } #endregion }