コード例 #1
0
ファイル: Calendar.cs プロジェクト: smithydll/boxsocial
        public static void Show(Core core, TPage page, Primitive owner, int year, int month, int day)
        {
            core.Template.SetTemplate("Calendar", "viewcalendarday");

            // 15 year window
            if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5)
            {
                core.Functions.Generate404();
            }

            if (month < 1 || month > 12)
            {
                core.Functions.Generate404();
            }

            if (day < 1 || day > DateTime.DaysInMonth(year, month))
            {
                core.Functions.Generate404();
            }

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", day.ToString() + " " + core.Functions.IntToMonth(month) + " " + year.ToString());

            core.Template.Parse("CURRENT_DAY", day.ToString());
            core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month));
            core.Template.Parse("CURRENT_YEAR", year.ToString());

            long startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, day, 0, 0, 0));
            long endTime = startTime + 60 * 60 * 24;

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, owner);
            }

            if (cal.Access.Can("CREATE_EVENTS"))
            {
                core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true,
                    string.Format("year={0}", year),
                    string.Format("month={0}", month),
                    string.Format("day={0}", day)));
            }

            List<Event> events = cal.GetEvents(core, owner, startTime, endTime);

            bool hasAllDaysEvents = false;

            foreach (Event calendarEvent in events)
            {
                if (calendarEvent.AllDay)
                {
                    hasAllDaysEvents = true;
                    VariableCollection eventVariableCollection = core.Template.CreateChild("event");

                    eventVariableCollection.Parse("TITLE", calendarEvent.Subject);
                    eventVariableCollection.Parse("URI", calendarEvent.Uri);
                }
            }

            if (hasAllDaysEvents)
            {
                core.Template.Parse("ALL_DAY_EVENTS", "TRUE");
            }

            VariableCollection[] hours = new VariableCollection[24];

            for (int hour = 0; hour < 24; hour++)
            {
                VariableCollection timeslotVariableCollection = core.Template.CreateChild("timeslot");

                DateTime hourTime = new DateTime(year, month, day, hour, 0, 0);

                timeslotVariableCollection.Parse("TIME", hourTime.ToString("h tt").ToLower());
                hours[hour] = timeslotVariableCollection;
            }

            showHourEvents(core, owner, year, month, day, hours, events);

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { year.ToString(), year.ToString() });
            calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) });
            calendarPath.Add(new string[] { day.ToString(), day.ToString() });
            owner.ParseBreadCrumbs(calendarPath);
        }
コード例 #2
0
ファイル: Event.cs プロジェクト: smithydll/boxsocial
        public static void ShowAll(object sender, ShowPPageEventArgs e)
        {
            e.Template.SetTemplate("Calendar", "viewcalendarevents");

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

            e.Template.Parse("PAGE_TITLE", e.Core.Prose.GetString("EVENTS"));

            long startTime = e.Core.Tz.GetUnixTimeStamp(new DateTime(e.Core.Tz.Now.Year, e.Core.Tz.Now.Month, e.Core.Tz.Now.Day, 0, 0, 0));
            long endTime = startTime + 60 * 60 * 24 * 30; // skip ahead one month into the future

            Calendar cal = null;
            try
            {
                cal = new Calendar(e.Core, e.Page.Owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(e.Core, e.Page.Owner);
            }

            List<Event> events = cal.GetEvents(e.Core, e.Page.Owner, startTime, endTime);

            VariableCollection appointmentDaysVariableCollection = null;
            DateTime lastDay = e.Core.Tz.Now;

            e.Template.Parse("U_NEW_EVENT", e.Core.Hyperlink.AppendSid(string.Format("{0}calendar/new-event",
                e.Page.Owner.AccountUriStub)));

            if (events.Count > 0)
            {
                e.Template.Parse("HAS_EVENTS", "TRUE");
            }

            foreach (Event calendarEvent in events)
            {
                DateTime eventDay = calendarEvent.GetStartTime(e.Core.Tz);
                DateTime eventEnd = calendarEvent.GetEndTime(e.Core.Tz);

                if (appointmentDaysVariableCollection == null || lastDay.Day != eventDay.Day)
                {
                    lastDay = eventDay;
                    appointmentDaysVariableCollection = e.Template.CreateChild("appointment_days_list");

                    appointmentDaysVariableCollection.Parse("DAY", e.Core.Tz.DateTimeToDateString(eventDay, true));
                }

                VariableCollection appointmentVariableCollection = appointmentDaysVariableCollection.CreateChild("appointments_list");

                appointmentVariableCollection.Parse("TIME", eventDay.ToShortTimeString() + " - " + eventEnd.ToShortTimeString());
                appointmentVariableCollection.Parse("SUBJECT", calendarEvent.Subject);
                appointmentVariableCollection.Parse("LOCATION", calendarEvent.Location);
                appointmentVariableCollection.Parse("URI", Event.BuildEventUri(e.Core, calendarEvent));
            }
        }
コード例 #3
0
ファイル: Calendar.cs プロジェクト: smithydll/boxsocial
        public static void Show(Core core, TPage page, Primitive owner, int year, int month)
        {
            core.Template.SetTemplate("Calendar", "viewcalendarmonth");

            if (month < 1 || month > 12)
            {
                core.Functions.Generate404();
            }

            // 15 year window
            if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5)
            {
                core.Functions.Generate404();
            }

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", core.Functions.IntToMonth(month) + " " + year.ToString());

            core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month));
            core.Template.Parse("CURRENT_YEAR", year.ToString());

            core.Template.Parse("U_PREVIOUS_MONTH", Calendar.BuildMonthUri(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month)));
            core.Template.Parse("U_NEXT_MONTH", Calendar.BuildMonthUri(core, owner, YearOfNextMonth(year, month), NextMonth(month)));

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, owner);
            }

            if (cal.Access.Can("CREATE_EVENTS"))
            {
                core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true,
                    string.Format("year={0}", year),
                    string.Format("month={0}", month),
                    string.Format("day={0}", ((month == core.Tz.Now.Month) ? core.Tz.Now.Day : 1))));
            }

            int days = DateTime.DaysInMonth(year, month);
            DayOfWeek firstDay = new DateTime(year, month, 1).DayOfWeek;
            int offset = Calendar.GetFirstDayOfMonthOffset(firstDay);
            int weeks = (int)Math.Ceiling((days + offset) / 7.0);
            int daysPrev = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month));

            long startTime = 0;
            if (offset > 0)
            {
                // the whole month including entry days
                startTime = core.Tz.GetUnixTimeStamp(new DateTime(YearOfPreviousMonth(year, month), PreviousMonth(month), daysPrev - offset + 1, 0, 0, 0));
            }
            else
            {
                // the whole month
                startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, 1, 0, 0, 0));
            }

            // the whole month including exit days
            long endTime = startTime + 60 * 60 * 24 * weeks * 7;

            List<Event> events = cal.GetEvents(core, owner, startTime, endTime);

            /*if (startTime == -8885289600 || startTime == 11404281600 || endTime == -8885289600 || endTime == 11404281600)
            {
                Functions.Generate404();
                return;
            }*/

            for (int week = 0; week < weeks; week++)
            {
                VariableCollection weekVariableCollection = core.Template.CreateChild("week");

                weekVariableCollection.Parse("WEEK", (week + 1).ToString());

                /* lead in week */
                if (week + 1 == 1)
                {
                    int daysPrev2 = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month));
                    /* days in month prior */
                    for (int i = offset - 1; i >= 0; i--)
                    {
                        int day = daysPrev2 - i;

                        Calendar.showDayEvents(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month), day, weekVariableCollection, events);
                    }
                    /* first days in month */
                    for (int i = offset; i < 7; i++)
                    {
                        int day = i - offset + 1;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                }
                /* lead out week */
                else if (week + 1 == weeks)
                {
                    /* last days in month */
                    for (int i = week * 7 - offset; i < days; i++)
                    {
                        int day = i + 1;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                    /* days in month upcoming */
                    for (int i = 0; i < weeks * 7 - days - offset; i++)
                    {
                        int day = i + 1;

                        Calendar.showDayEvents(core, owner, YearOfNextMonth(year, month), NextMonth(month), day, weekVariableCollection, events);
                    }
                }
                else
                {
                    for (int i = 0; i < 7; i++)
                    {
                        int day = week * 7 + i + 1 - offset;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                }
            }

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { year.ToString(), year.ToString() });
            calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) });
            owner.ParseBreadCrumbs(calendarPath);
        }
コード例 #4
0
ファイル: AppInfo.cs プロジェクト: smithydll/boxsocial
        void ShowToday(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "todayupcommingevents");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            long startTime = e.core.Tz.GetUnixTimeStamp(new DateTime(e.core.Tz.Now.Year, e.core.Tz.Now.Month, e.core.Tz.Now.Day, 0, 0, 0));
            long endTime = startTime + 60 * 60 * 24 * 7; // skip ahead one week into the future

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, core.Session.LoggedInMember);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, core.Session.LoggedInMember);
            }

            List<Event> events = cal.GetEvents(core, e.core.Session.LoggedInMember, startTime, endTime);

            template.Parse("U_NEW_EVENT", core.Hyperlink.AppendSid(string.Format("{0}calendar/new-event",
                e.core.Session.LoggedInMember.AccountUriStub)));

            template.Parse("U_CALENDAR", core.Hyperlink.AppendSid(string.Format("{0}calendar",
                e.core.Session.LoggedInMember.UriStub)));

            VariableCollection appointmentDaysVariableCollection = null;
            DateTime lastDay = e.core.Tz.Now;

            if (events.Count > 0)
            {
                template.Parse("HAS_EVENTS", "TRUE");
            }

            foreach(Event calendarEvent in events)
            {
                DateTime eventDay = calendarEvent.GetStartTime(e.core.Tz);
                DateTime eventEnd = calendarEvent.GetEndTime(e.core.Tz);

                if (appointmentDaysVariableCollection == null || lastDay.Day != eventDay.Day)
                {
                    lastDay = eventDay;
                    appointmentDaysVariableCollection = template.CreateChild("appointment_days_list");

                    appointmentDaysVariableCollection.Parse("DAY", core.Tz.DateTimeToDateString(eventDay));
                }

                VariableCollection appointmentVariableCollection = appointmentDaysVariableCollection.CreateChild("appointments_list");

                appointmentVariableCollection.Parse("TIME", eventDay.ToShortTimeString() + " - " + eventEnd.ToShortTimeString());
                appointmentVariableCollection.Parse("SUBJECT", calendarEvent.Subject);
                appointmentVariableCollection.Parse("LOCATION", calendarEvent.Location);
                appointmentVariableCollection.Parse("URI", Event.BuildEventUri(core, calendarEvent));
            }

            e.core.AddMainPanel(template);

            //
            // Tasks panel
            //

            template = new Template(Assembly.GetExecutingAssembly(), "todaytaskspanel");
            template.SetProse(core.Prose);
            List<Task> tasks = cal.GetTasks(core, e.core.Session.LoggedInMember, startTime, endTime, true);

            VariableCollection taskDaysVariableCollection = null;
            lastDay = e.core.Tz.Now;

            if (tasks.Count > 0)
            {
                template.Parse("HAS_TASKS", "TRUE");
            }

            template.Parse("U_TASKS", Task.BuildTasksUri(e.core, e.core.Session.LoggedInMember));

            foreach (Task calendarTask in tasks)
            {
                DateTime taskDue = calendarTask.GetDueTime(e.core.Tz);

                if (taskDaysVariableCollection == null || lastDay.Day != taskDue.Day)
                {
                    lastDay = taskDue;
                    taskDaysVariableCollection = template.CreateChild("task_days");

                    taskDaysVariableCollection.Parse("DAY", taskDue.DayOfWeek.ToString());
                }

                VariableCollection taskVariableCollection = taskDaysVariableCollection.CreateChild("task_list");

                taskVariableCollection.Parse("DATE", taskDue.ToShortDateString() + " (" + taskDue.ToShortTimeString() + ")");
                taskVariableCollection.Parse("TOPIC", calendarTask.Topic);
                taskVariableCollection.Parse("ID", calendarTask.Id.ToString());
                taskVariableCollection.Parse("URI", Task.BuildTaskUri(core, calendarTask));
                taskVariableCollection.Parse("U_MARK_COMPLETE", Task.BuildTaskMarkCompleteUri(core, calendarTask));

                if (calendarTask.Status == TaskStatus.Overdue)
                {
                    taskVariableCollection.Parse("OVERDUE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "overdue-task");
                }
                else if (calendarTask.Status == TaskStatus.Completed)
                {
                    taskVariableCollection.Parse("COMPLETE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "complete-task");
                }
                else
                {
                    taskVariableCollection.Parse("CLASS", "task");
                }

                if (calendarTask.Priority == TaskPriority.High)
                {
                    taskDaysVariableCollection.Parse("HIGH_PRIORITY", "TRUE");
                }
                else if (calendarTask.Priority == TaskPriority.Low)
                {
                    taskDaysVariableCollection.Parse("LOW_PRIORITY", "TRUE");
                }
            }

            e.core.AddSidePanel(template);
        }