protected void notifySubscribers(LiftContext ctx) { Organization org = Organization.Current; OrgEmail oe = new OrgEmail(); oe.organization_id.Value = org.id.Value; oe = oe.doSingleObjectQuery <OrgEmail>("select"); Request r = new Request(); r.id.Value = ctx.getInt("request_id"); List <Request> rlist = r.doQuery <Request>("get_most_recent_update"); StringBuilder body = new StringBuilder(); string title = string.Empty; foreach (Request u in rlist) { if (title.Length == 0) { title = u.title.Value; } body.Append("From: "); body.Append(u.from.Value); body.Append(" ("); body.Append(u.from_email.Value); body.Append(")"); // body.Append(u.getDateTime("post_date").ToString("G")); // times are in utc - needs to be converted to subscriber tz body.Append("\r\n\r\n"); body.Append(u.description.Value); body.Append("\r\n\r\n"); } Email e = new Email(); e.from = org.getFromEmail(); e.Body = body.ToString(); e.subject = "Update: " + title; Subscription s = new Subscription(); s.request_id.Value = ctx.getInt("request_id"); DataSet subsribers = s.doQuery("get_subscribers"); if (DatabasePersist.hasData(subsribers)) { foreach (DataRow subscriber in subsribers.Tables[0].Rows) { e.clearRecipients(); e.addTo(subscriber["email"].ToString()); e.send(); } } }
protected void Page_Load(object sender, EventArgs e) { EmailValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_MUST_BE_A_VALID_EMAIL_ADDRESS; PasswordValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_PASSWORDS_DO_NOT_MATCH; if (!Organization.setCurrent()) { Response.Redirect(LiftContext.Redirect); } PageAuthorized.check(Request, Response); int initialLanguageId = 1; //-- 1 = English string initialTimeZone = string.Empty; string saltValue = string.Empty; int sumTotalRequests = 0; TimeSpan sumPrayerSessionsDurationTimeSpan = new TimeSpan(); //------------------------------------------------------------------------- //-- do the language setting for the SUBMIT button here //-- (unable to place <%=LiftDomain.Language.Current.SHARED_SUBMIT %> in asp:Button Text field) //------------------------------------------------------------------------- this.submitBtn.Text = LiftDomain.Language.Current.SHARED_SUBMIT; this.submitBtnPassword.Text = LiftDomain.Language.Current.SHARED_CHANGE; this.submitBtnTimeZone.Text = LiftDomain.Language.Current.SHARED_CHANGE; LiftDomain.User thisUser = new LiftDomain.User(); if (IsPostBack) { //------------------------------------------------------------------------- //-- transfer screen values to the object //------------------------------------------------------------------------- thisUser.id.Value = int.Parse(id.Value); thisUser.login.Value = login.Text; thisUser.first_name.Value = first_name.Text; thisUser.last_name.Value = last_name.Text; thisUser.email.Value = email.Text; thisUser.address.Value = address.Text; thisUser.city.Value = city.Text; thisUser.state_province.Value = state_province.Text; thisUser.postal_code.Value = postal_code.Text; thisUser.phone.Value = phone.Text; thisUser.language_id.Value = Convert.ToInt32(language_list.SelectedItem.Value); //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT //(user_password.Text != user_password_confirmation.Text) if (!String.IsNullOrEmpty(user_password.Text.Trim())) { thisUser.password_hash_type.Value = "md5"; saltValue = LiftDomain.User.generateRandomSalt(); thisUser.password_salt.Value = saltValue; thisUser.crypted_password.Value = LiftDomain.User.hash(user_password.Text, saltValue); } thisUser.updated_at.Value = LiftTime.CurrentTime; thisUser.time_zone.Value = timezone_list.SelectedItem.Value; thisUser.previous_increment_id.Value = 0; //------------------------------------------------------------------------- //-- persist the User object data to the database //------------------------------------------------------------------------- thisUser.doCommand("save_current"); Response.Redirect("MyAccount.aspx"); } else { //------------------------------------------------------------------------- //-- query database for data for the current user //------------------------------------------------------------------------- id.Value = LiftDomain.User.Current.id.Value.ToString(); thisUser.id.Value = LiftDomain.User.Current.id.Value; thisUser = thisUser.doSingleObjectQuery <LiftDomain.User>("select"); } //------------------------------------------------------------------------- //-- populate the screen controls //------------------------------------------------------------------------- first_name_label.Text = thisUser.first_name; last_name_label.Text = thisUser.last_name; login.Text = thisUser.login; created_at.Text = thisUser.created_at.Value.ToString("dddd MMMM dd, yyyy"); first_name.Text = thisUser.first_name; last_name.Text = thisUser.last_name; email.Text = thisUser.email; address.Text = thisUser.address; city.Text = thisUser.city; state_province.Text = thisUser.state_province; postal_code.Text = thisUser.postal_code; phone.Text = thisUser.phone; initialLanguageId = thisUser.language_id; initLanguageList(initialLanguageId); initialTimeZone = thisUser.time_zone; initTimeZoneList(initialTimeZone); //------------------------------------------------------------------------- //-- MY PRAYER REQUESTS //------------------------------------------------------------------------- LiftDomain.Request prayerRequest = new LiftDomain.Request(); prayerRequest.user_id.Value = thisUser.id; prayerRequestSet = prayerRequest.doQuery("get_my_account_requests"); if (prayerRequestSet.Tables[0].Rows.Count > 0) { prayerRequestRenderer = new PartialRenderer(HttpContext.Current, prayerRequestSet, "_MyAccountRequest.htm", new PartialRenderer.RenderHelper(prayerRequest.my_account_request_helper)); prayerRequestRendererResult = prayerRequestRenderer; } else { prayerRequestRendererResult = "<p>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_REQUESTS.Value + ".</p>"; } //------------------------------------------------------------------------- //-- MY PRAYER REQUEST SUBSCRIPTIONS //------------------------------------------------------------------------- LiftDomain.Subscription prayerRequestSubscription = new LiftDomain.Subscription(); prayerRequestSubscription.user_id.Value = thisUser.id; prayerRequestSubscriptionSet = prayerRequestSubscription.doQuery("get_subscription_by_user"); if (prayerRequestSubscriptionSet.Tables[0].Rows.Count > 0) { prayerRequestSubscriptionRenderer = new PartialRenderer(HttpContext.Current, prayerRequestSubscriptionSet, "_MyAccountPrayerRequestSubscription.htm", new PartialRenderer.RenderHelper(prayerRequestSubscription.my_account_prayer_request_subscription_helper)); prayerRequestSubscriptionRendererResult = prayerRequestSubscriptionRenderer; } else { prayerRequestSubscriptionRendererResult = "<p>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_SUBSCRIPTIONS.Value + ".</p>"; } //------------------------------------------------------------------------- //-- MY PRAYER SESSIONS //------------------------------------------------------------------------- LiftDomain.Prayersession prayerSessionObject = new LiftDomain.Prayersession(); prayerSessionObject.user_id.Value = thisUser.id; prayerSessionSet = prayerSessionObject.doQuery("get_prayer_sessions_by_user_start_time_desc"); if (prayerSessionSet.Tables[0].Rows.Count > 0) { prayerSessionRenderer = new PartialRenderer(HttpContext.Current, prayerSessionSet, "_MyAccountPrayerSession.htm", new PartialRenderer.RenderHelper(prayerSessionObject.my_account_prayer_session_helper)); prayerSessionRendererResult = prayerSessionRenderer; foreach (DataRow thisDataRow in prayerSessionSet.Tables[0].Rows) { sumTotalRequests += Convert.ToInt32(thisDataRow["total_requests"]); sumPrayerSessionsDurationTimeSpan = sumPrayerSessionsDurationTimeSpan.Add(Convert.ToDateTime(thisDataRow["end_time"]) - Convert.ToDateTime(thisDataRow["start_time"])); } prayer_requests_sum_label = Convert.ToString(sumTotalRequests); prayer_sessions_duration_sum_label = Convert.ToString(sumPrayerSessionsDurationTimeSpan.Hours) + "." + (((float)((float)sumPrayerSessionsDurationTimeSpan.Minutes / (float)60)) * 10).ToString("0"); } else { prayerSessionRendererResult = "<tr id='request0'><td valign='top' colspan='4' align='center'>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_SESSIONS.Value + ".</td></tr>"; } }