コード例 #1
0
        void AccountCalendarEventInvite_StatusChanged(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long eventId = core.Functions.RequestLong("id", 0);

            if (eventId > 0)
            {
                Event calendarEvent = new Event(core, eventId);
                EventInvite invite = new EventInvite(core, eventId, LoggedInMember);

                UpdateQuery uQuery = new UpdateQuery(typeof(EventInvite));

                UpdateQuery uEventQuery = new UpdateQuery(typeof(Event));
                uEventQuery.AddCondition("event_id", eventId);

                switch (e.Mode)
                {
                    case "accept":
                        uQuery.AddField("invite_accepted", true);
                        uQuery.AddField("invite_status", (byte)EventAttendance.Yes);

                        switch (invite.InviteStatus)
                        {
                            case EventAttendance.Yes:
                                break;
                            case EventAttendance.Maybe:
                                uEventQuery.AddField("event_maybes", new QueryOperation("event_maybes", QueryOperations.Subtraction, 1));
                                break;
                            default:
                                break;
                        }
                        if (invite.InviteStatus != EventAttendance.Yes)
                        {
                            uEventQuery.AddField("event_attendees", new QueryOperation("event_attendees", QueryOperations.Addition, 1));
                        }
                        break;
                    case "reject":
                        uQuery.AddField("invite_accepted", false);
                        uQuery.AddField("invite_status", (byte)EventAttendance.No);

                        switch (invite.InviteStatus)
                        {
                            case EventAttendance.Yes:
                                uEventQuery.AddField("event_attendees", new QueryOperation("event_attendees", QueryOperations.Subtraction, 1));
                                break;
                            case EventAttendance.Maybe:
                                uEventQuery.AddField("event_maybes", new QueryOperation("event_maybes", QueryOperations.Subtraction, 1));
                                break;
                            default:
                                break;
                        }
                        break;
                    case "maybe":
                        uQuery.AddField("invite_accepted", false);
                        uQuery.AddField("invite_status", (byte)EventAttendance.Maybe);

                        switch (invite.InviteStatus)
                        {
                            case EventAttendance.Yes:
                                uEventQuery.AddField("event_attendees", new QueryOperation("event_attendees", QueryOperations.Subtraction, 1));
                                break;
                            default:
                                break;
                        }
                        if (invite.InviteStatus != EventAttendance.Maybe)
                        {
                            uEventQuery.AddField("event_maybes", new QueryOperation("event_maybes", QueryOperations.Addition, 1));
                        }
                        break;
                    default:
                        DisplayGenericError();
                        return;
                }

                // TODO: look into this
                uQuery.AddCondition("event_id", eventId);
                uQuery.AddCondition("item_id", LoggedInMember.Id);
                uQuery.AddCondition("item_type_id", LoggedInMember.TypeId);

                db.BeginTransaction();
                db.Query(uQuery);
                db.Query(uEventQuery);

                SetRedirectUri(calendarEvent.Uri);
                switch (e.Mode)
                {
                    case "accept":
                        core.Display.ShowMessage("Invitation Accepted", "You have accepted the invitation to this event.");
                        break;
                    case "maybe":
                        core.Display.ShowMessage("Invitation Acknowledged", "You have indicated you may go to this event.");
                        break;
                    case "reject":
                        core.Display.ShowMessage("Invitation Rejected", "You have rejected the invitation to this event.");
                        break;
                }
                return;
            }
            else
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission.");
                return;
            }
        }
コード例 #2
0
ファイル: Event.cs プロジェクト: smithydll/boxsocial
        public static void NotifyEventComment(Core core, Job job)
        {
            Comment comment = new Comment(core, job.ItemId);
            Event ev = new Event(core, comment.CommentedItemKey.Id);

            if (ev.Owner is User && (!comment.OwnerKey.Equals(ev.OwnerKey)))
            {
                core.CallingApplication.SendNotification(core, comment.User, (User)ev.Owner, ev.OwnerKey, ev.ItemKey, "_COMMENTED_EVENT", comment.BuildUri(ev));
            }

            core.CallingApplication.SendNotification(core, comment.OwnerKey, comment.User, ev.OwnerKey, ev.ItemKey, "_COMMENTED_EVENT", comment.BuildUri(ev));
        }
コード例 #3
0
ファイル: Event.cs プロジェクト: smithydll/boxsocial
        public static void Show(object sender, ShowPPageEventArgs e)
        {
            e.Template.SetTemplate("Calendar", "viewcalendarevent");

            /* pages */
            e.Core.Display.ParsePageList(e.Page.Owner, true);

            Event calendarEvent = null;

            if (e.ItemId <= 0)
            {
                User pageUser = null;
                if (e.Page.Owner is User)
                {
                    pageUser = (User)e.Page.Owner;
                    e.Core.LoadUserProfile(~e.ItemId);
                    User birthdayUser = e.Core.PrimitiveCache[~e.ItemId];
                    calendarEvent = new BirthdayEvent(e.Core, pageUser, birthdayUser, e.Core.Tz.Now.Year);
                }
                else
                {
                    e.Core.Functions.Generate404();
                    return;
                }
            }
            else
            {
                try
                {
                    calendarEvent = new Event(e.Core, e.ItemId);
                }
                catch (InvalidEventException)
                {
                    e.Core.Functions.Generate404();
                    return;
                }
            }

            if (e.Core.LoggedInMemberId == e.Page.Owner.Id && e.Page.Owner.GetType() == typeof(User))
            {
                e.Template.Parse("U_NEW_EVENT", e.Core.Hyperlink.BuildAccountSubModuleUri("calendar", "new-event", true,
                    string.Format("year={0}", e.Core.Tz.Now.Year),
                    string.Format("month={0}", e.Core.Tz.Now.Month),
                    string.Format("day={0}", e.Core.Tz.Now.Day)));
                if (!(calendarEvent is BirthdayEvent))
                {
                    e.Template.Parse("U_EDIT_EVENT", e.Core.Hyperlink.BuildAccountSubModuleUri("calendar", "new-event", "edit", e.ItemId, true));
                    e.Template.Parse("U_DELETE_EVENT", e.Core.Hyperlink.BuildAccountSubModuleUri("calendar", "delete-event", e.ItemId, true));
                    e.Template.Parse("U_EDIT_PERMISSIONS", Access.BuildAclUri(e.Core, calendarEvent));
                }
            }

            if (calendarEvent is BirthdayEvent)
            {
            }
            else
            {
                if ((!calendarEvent.Access.Can("VIEW")) && ((!e.Core.Session.IsLoggedIn) || (!calendarEvent.IsInvitee(e.Core.Session.LoggedInMember.ItemKey))))
                {
                    e.Core.Functions.Generate403();
                    return;
                }
            }

            e.Template.Parse("PAGE_TITLE", calendarEvent.Subject);
            e.Template.Parse("SUBJECT", calendarEvent.Subject);
            e.Template.Parse("LOCATION", calendarEvent.Location);
            e.Template.Parse("DESCRIPTION", calendarEvent.Description);
            e.Template.Parse("START_TIME", calendarEvent.GetStartTime(e.Core.Tz).ToString());
            e.Template.Parse("END_TIME", calendarEvent.GetEndTime(e.Core.Tz).ToString());

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", e.Core.Prose.GetString("CALENDAR") });
            //calendarPath.Add(new string[] { "events", "Events" });
            calendarPath.Add(new string[] { "event/" + calendarEvent.EventId.ToString(), calendarEvent.Subject });
            e.Page.Owner.ParseBreadCrumbs(calendarPath);

            if (!(calendarEvent is BirthdayEvent))
            {
                if (calendarEvent.Access.Can("COMMENT") || (e.Core.Session.IsLoggedIn && calendarEvent.IsInvitee(e.Core.Session.LoggedInMember.ItemKey)))
                {
                    e.Template.Parse("CAN_COMMENT", "TRUE");
                }
                e.Core.Display.DisplayComments(e.Template, calendarEvent.owner, calendarEvent);

                List<EventInvite> invitees = calendarEvent.GetInvites();
                List<long> invitedIds = new List<long>(); /* Users to be displayed on the page */

                long attendingCount = 0;
                long invitedCount = 0;
                long notAttendingCount = 0;
                long mightAttendCount = 0;
                long notRespondedCount = 0;

                int i = 0, j = 0, k = 0, l = 0;
                foreach (EventInvite ei in invitees)
                {
                    if (ei.Invited.TypeId == ItemType.GetTypeId(e.Core, typeof(User)))
                    {
                        invitedCount++;

                        switch (ei.InviteStatus)
                        {
                            case EventAttendance.Yes:
                                if (i < 4)
                                {
                                    invitedIds.Add(ei.Invited.Id);
                                    i++;
                                }
                                attendingCount++;
                                break;
                            case EventAttendance.Maybe:
                                if (j < 4)
                                {
                                    invitedIds.Add(ei.Invited.Id);
                                    j++;
                                }
                                mightAttendCount++;
                                break;
                            case EventAttendance.No:
                                if (k < 4)
                                {
                                    invitedIds.Add(ei.Invited.Id);
                                    k++;
                                }
                                notAttendingCount++;
                                break;
                            case EventAttendance.Unknown:
                                if (l < 4)
                                {
                                    invitedIds.Add(ei.Invited.Id);
                                    l++;
                                }
                                notRespondedCount++;
                                break;
                        }
                    }
                }

                e.Core.LoadUserProfiles(invitedIds);

                e.Template.Parse("ATTENDEES", attendingCount.ToString());
                e.Template.Parse("INVITEES", invitedCount.ToString());
                e.Template.Parse("NOT_ATTENDING", notAttendingCount.ToString());
                e.Template.Parse("MAYBE_ATTENDING", mightAttendCount.ToString());
                e.Template.Parse("NOT_RESPONDED", notRespondedCount.ToString());

                if (attendingCount > 1)
                {
                    e.Template.Parse("L_IS_ARE", "is");
                    e.Template.Parse("L_ATTENDEES", "attendees");
                }
                else
                {
                    e.Template.Parse("L_IS_ARE", "are");
                    e.Template.Parse("L_ATTENDEES", "attendee");
                }

                i = j = k = l = 0;
                foreach (EventInvite ei in invitees)
                {
                    if (ei.Invited.TypeId == ItemType.GetTypeId(e.Core, typeof(User)))
                    {
                        VariableCollection listVariableCollection = null;

                        switch (ei.InviteStatus)
                        {
                            case EventAttendance.Yes:
                                i++;
                                if (i > 4)
                                {
                                    continue;
                                }
                                listVariableCollection = e.Template.CreateChild("attendee_list");
                                break;
                            case EventAttendance.No:
                                j++;
                                if (j > 4)
                                {
                                    continue;
                                }
                                listVariableCollection = e.Template.CreateChild("not_attending_list");
                                break;
                            case EventAttendance.Maybe:
                                k++;
                                if (k > 4)
                                {
                                    continue;
                                }
                                listVariableCollection = e.Template.CreateChild("maybe_attending_list");
                                break;
                            case EventAttendance.Unknown:
                                l++;
                                if (l > 4)
                                {
                                    continue;
                                }
                                listVariableCollection = e.Template.CreateChild("unresponded_list");
                                break;
                        }

                        User user = e.Core.PrimitiveCache[ei.Invited.Id];

                        listVariableCollection.Parse("U_PROFILE", user.Uri);
                        listVariableCollection.Parse("USER_DISPLAY_NAME", user.DisplayName);
                        listVariableCollection.Parse("ICON", user.Icon);
                        listVariableCollection.Parse("TILE", user.Tile);
                    }
                }
            }
        }
コード例 #4
0
ファイル: Event.cs プロジェクト: smithydll/boxsocial
 public static string BuildEventUri(Core core, Event calendarEvent)
 {
     return core.Hyperlink.AppendSid(string.Format("{0}calendar/event/{1}",
         calendarEvent.Owner.Uri, calendarEvent.EventId));
 }
コード例 #5
0
ファイル: Event.cs プロジェクト: smithydll/boxsocial
 public static string BuildEventRejectUri(Core core, Event calendarEvent)
 {
     return core.Hyperlink.BuildAccountSubModuleUri("calendar", "invite-event", "reject", calendarEvent.Id, true);
 }
コード例 #6
0
        void AccountCalendarEventNew_Show(object sender, EventArgs e)
        {
            SetTemplate("account_calendar_event_new");

            DateTimePicker startDateTimePicker = new DateTimePicker(core, "start-date");
            startDateTimePicker.ShowTime = true;
            startDateTimePicker.ShowSeconds = false;

            DateTimePicker endDateTimePicker = new DateTimePicker(core, "end-date");
            endDateTimePicker.ShowTime = true;
            endDateTimePicker.ShowSeconds = false;

            UserSelectBox inviteesUserSelectBox = new UserSelectBox(core, "invitees");

            /* */
            SelectBox timezoneSelectBox = UnixTime.BuildTimeZoneSelectBox("timezone");

            bool edit = false;

            if (core.Http.Query["mode"] == "edit")
            {
                edit = true;
            }

            int year = core.Functions.RequestInt("year", tz.Now.Year);
            int month = core.Functions.RequestInt("month", tz.Now.Month);
            int day = core.Functions.RequestInt("day", tz.Now.Day);

            string inviteeUsernameList = core.Http.Form["invitees[raw]"];
            List<long> inviteeIds = UserSelectBox.FormUsers(core, "invitees");

            if (!(string.IsNullOrEmpty(inviteeUsernameList)))
            {
                string[] inviteesUsernames = inviteeUsernameList.Split(new char[] { ' ', '\t', ';', ',' });
                List<string> uns = new List<string>(inviteesUsernames.Length);
                foreach (string inviteeUsername in inviteesUsernames)
                {
                    if (!string.IsNullOrEmpty(inviteeUsername))
                    {
                        try
                        {
                            uns.Add(inviteeUsername);
                        }
                        catch (InvalidUserException)
                        {
                        }
                    }
                }

                inviteeIds.AddRange(core.LoadUserProfiles(uns).Values);
            }

            DateTime startDate = new DateTime(year, month, day, 8, 0, 0);
            DateTime endDate = new DateTime(year, month, day, 9, 0, 0);
            timezoneSelectBox.SelectedKey = core.Tz.TimeZoneCode.ToString();

            string subject = string.Empty;
            string location = string.Empty;
            string description = string.Empty;

            if (edit)
            {
                int id = core.Functions.RequestInt("id", -1);

                if (id < 1)
                {
                    core.Display.ShowMessage("Invalid", "If you have stumbled onto this page by mistake, click back in your browser.");
                }

                try
                {
                    Event calendarEvent = new Event(core, id);
                    inviteeIds.AddRange(calendarEvent.GetInviteeIds());

                    template.Parse("EDIT", "TRUE");
                    template.Parse("ID", calendarEvent.EventId.ToString());

                    startDate = calendarEvent.GetStartTime(core.Tz);
                    endDate = calendarEvent.GetEndTime(core.Tz);
                    inviteesUserSelectBox.Invitees = calendarEvent.GetInviteeIds();

                    subject = calendarEvent.Subject;
                    location = calendarEvent.Location;
                    description = calendarEvent.Description;
                }
                catch (InvalidEventException)
                {
                    core.Display.ShowMessage("Invalid", "If you have stumbled onto this page by mistake, click back in your browser.");
                }
            }

            template.Parse("S_YEAR", year.ToString());
            template.Parse("S_MONTH", month.ToString());
            template.Parse("S_DAY", day.ToString());

            startDateTimePicker.Value = startDate;
            endDateTimePicker.Value = endDate;

            List<string> permissions = new List<string>();
            permissions.Add("Can Read");

            //core.Display.ParsePermissionsBox(template, "S_EVENT_PERMS", eventAccess, permissions);

            template.Parse("S_SUBJECT", subject);
            template.Parse("S_LOCATION", location);
            template.Parse("S_DESCRIPTION", description);

            StringBuilder outputInvitees = null;
            StringBuilder outputInviteesIds = null;

            core.LoadUserProfiles(inviteeIds);

            foreach (long inviteeId in inviteeIds)
            {
                if (outputInvitees == null)
                {
                    outputInvitees = new StringBuilder();
                    outputInviteesIds = new StringBuilder();
                }
                else
                {
                    outputInvitees.Append("; ");
                    outputInviteesIds.Append(",");
                }

                outputInvitees.Append(core.PrimitiveCache[inviteeId].DisplayName);
                outputInviteesIds.Append(inviteeId.ToString());
            }

            if (outputInviteesIds != null)
            {
                template.Parse("INVITEES_ID_LIST", outputInviteesIds.ToString());
            }

            template.Parse("S_START_DATE", startDateTimePicker);
            template.Parse("S_END_DATE", endDateTimePicker);
            template.Parse("S_TIMEZONE", timezoneSelectBox);
            template.Parse("S_INVITEES", inviteesUserSelectBox);

            Save(new EventHandler(AccountCalendarEventNew_Save));
        }
コード例 #7
0
        void AccountCalendarEventNew_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long eventId = 0;
            string subject = string.Empty;
            string location = string.Empty;
            string description = string.Empty;
            long startTime = tz.GetUnixTimeStamp(tz.Now);
            long endTime = tz.GetUnixTimeStamp(tz.Now);
            bool edit = false;
            ushort timezone = core.Functions.FormUShort("timezone", 1);

            if (core.Http.Form["mode"] == "edit")
            {
                edit = true;
            }

            string inviteeUsernameList = core.Http.Form["invitees[raw]"];
            List<long> inviteeIds = UserSelectBox.FormUsers(core, "invitees");
            List<string> inviteesEmailsList = new List<string>();

            if (!(string.IsNullOrEmpty(inviteeUsernameList)))
            {
                string[] inviteesUsernames = inviteeUsernameList.Split(new char[] { ' ', '\t', ';', ',' });
                List<string> inviteesUsernamesList = new List<string>();

                foreach (string inviteeUsername in inviteesUsernames)
                {
                    if (!string.IsNullOrEmpty(inviteeUsername))
                    {
                        if (core.Email.IsEmailAddress(inviteeUsername))
                        {
                            inviteesEmailsList.Add(inviteeUsername);
                        }
                        else
                        {
                            inviteesUsernamesList.Add(inviteeUsername);
                        }
                    }
                }

                inviteeIds.AddRange(core.LoadUserProfiles(inviteesUsernamesList).Values);
            }

            try
            {
                subject = core.Http.Form["subject"];
                location = core.Http.Form["location"];
                description = core.Http.Form["description"];

                startTime = DateTimePicker.FormDate(core, "start-date", timezone);
                endTime = DateTimePicker.FormDate(core, "end-date", timezone);

                if (edit)
                {
                    eventId = long.Parse(core.Http.Form["id"]);
                }
            }
            catch
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission.");
                return;
            }

            if (!edit)
            {
                Event calendarEvent = Event.Create(core, Owner, subject, location, description, startTime, endTime);

                foreach (long inviteeId in inviteeIds)
                {
                    try
                    {
                        calendarEvent.Invite(core, core.PrimitiveCache[inviteeId]);
                    }
                    catch (CouldNotInviteEventException)
                    {
                    }
                }

                SetRedirectUri(Event.BuildEventUri(core, calendarEvent));
                core.Display.ShowMessage("Event Created", "You have successfully created a new event.");
            }
            else
            {
                Event calendarEvent = new Event(core, eventId);
                calendarEvent.Location = location;
                calendarEvent.Subject = subject;
                calendarEvent.Description = description;
                calendarEvent.StartTimeRaw = startTime;
                calendarEvent.EndTimeRaw = endTime;

                calendarEvent.Update();

                List<long> alreadyInvited = calendarEvent.GetInviteeIds();

                List<long> idsToBeInvited = new List<long>();

                foreach (long inviteeId in inviteeIds)
                {
                    if (!alreadyInvited.Contains(inviteeId))
                    {
                        idsToBeInvited.Add(inviteeId);
                    }
                }

                core.LoadUserProfiles(idsToBeInvited);

                foreach (long inviteeId in idsToBeInvited)
                {
                    try
                    {
                        calendarEvent.Invite(core, core.PrimitiveCache[inviteeId]);
                    }
                    catch (CouldNotInviteEventException)
                    {
                    }
                }

                foreach (string email in inviteesEmailsList)
                {
                    try
                    {
                        string emailKey = User.GenerateActivationSecurityToken(); ;

                        InsertQuery iQuery = new InsertQuery("event_email_invites");
                        iQuery.AddField("event_id", calendarEvent.Id);
                        iQuery.AddField("invite_email", email);
                        iQuery.AddField("invite_key", emailKey);
                        iQuery.AddField("inviter_id", core.Session.LoggedInMember.Id);
                        iQuery.AddField("invite_date_ut", UnixTime.UnixTimeStamp());
                        iQuery.AddField("invite_accepted", false);
                        iQuery.AddField("invite_status", (byte)EventAttendance.Unknown);

                        core.Db.Query(iQuery);
                    }
                    catch (CouldNotInviteEventException)
                    {
                    }
                }

                SetRedirectUri(Event.BuildEventUri(core, calendarEvent));
                core.Display.ShowMessage("Event Saved", "You have successfully saved your changes to the event.");
            }
        }
コード例 #8
0
        void AccountCalendarEventDelete_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long eventId = core.Functions.FormLong("id", 0);

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                if (eventId > 0)
                {
                    Event calendarEvent = new Event(core, eventId);

                    try
                    {
                        calendarEvent.Delete(core);

                        SetRedirectUri(core.Hyperlink.BuildAccountModuleUri(ModuleKey));
                        core.Display.ShowMessage("Event Deleted", "You have deleted an event from your calendar.");
                    }
                    catch (NotLoggedInException)
                    {
                        core.Display.ShowMessage("Unauthorised", "You are unauthorised to delete this event.");
                    }
                }
                else
                {
                    DisplayGenericError();
                    return;
                }
            }
            else
            {
            }
        }