/// <summary> /// AJAX handler to reply a JSON containing the events for /// EventCalendarAggregator placeholder and SimpleCalendar control /// </summary> /// <param name="context"></param> public void ProcessInternalRequest(DateTime start, DateTime end, HttpContext context) { bool showFile = PageUtils.getFromForm("showFile", false); // Basic rule: event calendar shows files, simple calendar does not CmsLanguage lang = CmsLanguage.GetFromHaystack(PageUtils.getFromForm("lang", "en"), CmsConfig.Languages); List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchDetailsDataByRange(start, end, lang); List <EventCalendarDb.EventCalendarCategoryData> eventCategories = new EventCalendarDb().fetchCategoryList(); List <FullCalendarEvent> eventsToOutput = new List <FullCalendarEvent>(); foreach (EventCalendarDb.EventCalendarDetailsData c in list) { eventsToOutput.Add(new FullCalendarEvent(c, eventCategories)); if (!showFile) { continue; } CmsPage eventPage = CmsContext.getPageById(c.PageId); List <FileLibraryDetailsData> fileList = new FileLibraryDb().fetchDetailsData(lang, eventPage); foreach (FileLibraryDetailsData f in fileList) { if (userHasAuthority(f)) { eventsToOutput.Add(new FullCalendarEvent(c, f, eventCategories)); } } } string json = JsonWriter.Serialize(eventsToOutput.ToArray()); context.Response.Write(json); }
/// <summary> /// Generate HTML SELECT and OPTION tags for events selection /// (count limited by the config) /// </summary> /// <param name="lang"></param> /// <param name="controlId"></param> /// <param name="selectedId"></param> /// <param name="eventRequired"></param> /// <returns></returns> protected string getEventOption(CmsLanguage lang, string controlId, int selectedId, bool eventRequired) { EventCalendarDb eventDb = new EventCalendarDb(); int dropdownCount = CmsConfig.getConfigValue("FileLibrary.NumEventsInList", 10); List <EventCalendarDb.EventCalendarDetailsData> eventList = eventDb.fetchAllDetailsData(lang, selectedId, dropdownCount); List <CmsPage> pageList = new List <CmsPage>(eventList.Count); NameValueCollection eventPageCollection = new NameValueCollection(eventList.Count); for (int x = 0; x < eventList.Count; x++) { EventCalendarDb.EventCalendarDetailsData e = eventList[x]; CmsPage p = CmsContext.getPageById(e.PageId); pageList.Add(p); eventPageCollection.Add(e.PageId.ToString(), p.getTitle(lang)); } StringBuilder html = new StringBuilder(); string htmlName = controlId + "eventPageId"; string selectTag = "<select name=\"{0}\" id=\"{1}\" onchange=\"$('.{2}table').css('display','none'); $('#{3}table_' + this.value).fadeIn();\">" + EOL; html.Append(String.Format(selectTag, new string[] { htmlName, htmlName, controlId, controlId })); string optionTag = "<option value=\"{0}\" {1}>{2}</option>" + EOL; string optionSelected = (selectedId == -1) ? "selected=\"selected\"" : ""; if (eventRequired == false) // if event not required, provide an option to select n/a { html.Append(String.Format(optionTag, new string[] { "-1", optionSelected, "(n/a)" })); } for (int x = 0; x < eventList.Count; x++) { EventCalendarDb.EventCalendarDetailsData e = eventList[x]; optionSelected = (selectedId == e.PageId) ? "selected=\"selected\"" : ""; html.Append(String.Format(optionTag, new string[] { e.PageId.ToString(), optionSelected, pageList[x].getTitle(lang) })); } html.Append("</select>" + EOL); List <EventCalendarDb.EventCalendarCategoryData> eventCategoryList = eventDb.fetchCategoryList(lang); for (int x = 0; x < eventList.Count; x++) { html.Append(getEventHiddenLayer(lang, eventCategoryList, pageList[x], eventList[x], controlId, selectedId)); } return(html.ToString()); }
protected override void Render(HtmlTextWriter writer) { DateTime currDateTime = DateTime.Now; int count = CmsControlUtils.getControlParameterKeyValue(CmsContext.currentPage, this, "count", 3); CmsLanguage lang = CmsContext.currentLanguage; List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchUpcomingEventDetails(currDateTime, lang, count); StringBuilder html = new StringBuilder("<div class=\"UpcomingEvents\">"); html.Append(renderUpcomingEventsHeader(lang)); html.Append(renderUpcomingEventsContent(lang, list)); html.Append("</div>"); writer.Write(html.ToString()); }
/// <summary> /// Handle form submit, either updating an existing category, or adding /// a new category. /// </summary> /// <param name="langArray"></param> /// <param name="controlId"></param> /// <returns></returns> protected string handleFormSubmit(CmsLanguage[] langArray, string controlId) { int id = PageUtils.getFromForm(controlId + "id", -999); if (id == -999) { return(""); } int step = langArray.Length; EventCalendarDb.EventCalendarCategoryData[] data = null; lock (this) // lock this code segment because auto-id cannot be used during insert { if (id == -1) // add new record { data = createAddRecord(langArray, controlId); } else // update existing record { data = createUpdateRecord(langArray, controlId, id); } EventCalendarDb db = new EventCalendarDb(); foreach (EventCalendarDb.EventCalendarCategoryData d in data) { if (id == -1) { if (db.insertCategoryData(d) == false) { return("<p style=\"color: red;\">Error adding category.</p>"); } } else { if (db.updateCategoryData(d) == false) { return("<p style=\"color: red;\">Error updating category.</p>"); } } } } return("<p>Calendar Category saved.</p>"); }
/// <summary> /// Create the entity object by reading the new values from html form. /// </summary> /// <param name="langArray"></param> /// <param name="controlId"></param> /// <returns></returns> protected EventCalendarDb.EventCalendarCategoryData[] createAddRecord(CmsLanguage[] langArray, string controlId) { int step = langArray.Length; EventCalendarDb.EventCalendarCategoryData[] data = new EventCalendarDb.EventCalendarCategoryData[step]; EventCalendarDb db = new EventCalendarDb(); int newId = db.fetchNextCategoryId(); for (int x = 0; x < step; x++) { string l = langArray[x].shortCode; data[x] = new EventCalendarDb.EventCalendarCategoryData(); data[x].CategoryId = newId; data[x].ColorHex = PageUtils.getFromForm(controlId + "addColorHex", ""); data[x].Lang = langArray[x]; data[x].Title = PageUtils.getFromForm(controlId + "addTitle_" + l, ""); data[x].Description = PageUtils.getFromForm(controlId + "addDescription_" + l, ""); } return(data); }
/// <summary> /// Create table body to show the Event Calendar Category records. /// </summary> /// <param name="langArray"></param> /// <param name="colorArray"></param> /// <param name="controlId"></param> /// <returns></returns> protected string generateContent(CmsLanguage[] langArray, string[] colorArray, string controlId) { EventCalendarDb db = new EventCalendarDb(); List <EventCalendarDb.EventCalendarCategoryData> list = db.fetchCategoryList(); int step = langArray.Length; StringBuilder html = new StringBuilder(); for (int x = 0; x < list.Count; x = x + step) { html.Append("<tr>" + EOL); EventCalendarDb.EventCalendarCategoryData data1 = list[x]; html.Append("<td>" + EOL); html.Append("<input class=\"" + controlId + "chgButton\" type=\"button\" value=\"Edit\" title=\"" + data1.CategoryId + "\" />" + EOL); html.Append("<input class=\"" + controlId + "chgSaveButton\" type=\"button\" value=\"Save\" title=\"" + data1.CategoryId + "\" />" + EOL); html.Append("<input class=\"" + controlId + "chgCancelButton\" type=\"button\" value=\"Cancel\" title=\"" + data1.CategoryId + "\" />" + EOL); html.Append("</td>" + EOL); html.Append("<td>" + EOL); html.Append("<select title=\"" + data1.ColorHex + "\" class=\"" + controlId + "chg\" disabled=\"disabled\" id=\"" + controlId + "colorHex_" + data1.CategoryId + "\" name=\"" + controlId + "colorHex\" onchange=\"this.style.backgroundColor=this.value;\">" + EOL); html.Append(generateColorOption(colorArray, data1.ColorHex)); html.Append("</select>" + EOL); html.Append("</td>" + EOL); for (int y = 0; y < step; y++) { string l = langArray[y].shortCode; EventCalendarDb.EventCalendarCategoryData data2 = list[y + x]; string title = data2.Title; html.Append("<td><div id=\"" + controlId + "title_" + l + "_" + data1.CategoryId + "\">" + title + "</div></td>" + EOL); string description = StringUtils.nl2br(data2.Description); html.Append("<td><div id=\"" + controlId + "description_" + l + "_" + data1.CategoryId + "\">" + description + "</div></td>" + EOL); } html.Append("</tr>" + EOL); } return(html.ToString()); }
public UserController() { db = new EventCalendarDb(); }
public void ProcessRequest(HttpContext context) { DateTime start = DateTime.MinValue; DateTime end = DateTime.MinValue; try { int startAddSeconds = PageUtils.getFromForm("start", Int32.MinValue); int endAddSeconds = PageUtils.getFromForm("end", Int32.MinValue); if (startAddSeconds < 0) { start = new DateTime(DateTime.Now.Year, 1, 1); } else { start = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(startAddSeconds); } if (endAddSeconds < 0) { end = new DateTime(DateTime.Now.Year, 1, 1).AddYears(1); } else { end = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(endAddSeconds); } if (end < start) { end = start.AddYears(1); } } catch { return; } bool showFile = PageUtils.getFromForm("showFile", false); // Basic rule: event calendar shows files, simple calendar does not CmsLanguage lang = CmsLanguage.GetFromHaystack(PageUtils.getFromForm("lang", "en"), CmsConfig.Languages); List <EventCalendarDb.EventCalendarDetailsData> list = new EventCalendarDb().fetchDetailsDataByRange(start, end, lang); iCalendar iCal = new iCalendar(); foreach (EventCalendarDb.EventCalendarDetailsData srcEvent in list) { // Create the event, and add it to the iCalendar Event evt = iCal.Create <Event>(); // Set information about the event evt.Start = new iCalDateTime(srcEvent.StartDateTime); evt.End = new iCalDateTime(srcEvent.EndDateTime); // This also sets the duration evt.Description = srcEvent.Description; // evt.Location = "Event location"; CmsPage srcEventPage = CmsContext.getPageById(srcEvent.PageId); evt.Summary = srcEventPage.getTitle(lang); Uri url = new Uri(srcEventPage.getUrl(CmsUrlFormat.FullIncludingProtocolAndDomainName, lang), UriKind.Absolute); evt.Url = url; evt.UID = srcEvent.PageId + "_" + srcEvent.Lang.shortCode + "_" + srcEvent.Identifier; } // Serialize (save) the iCalendar System.Text.Encoding outputEncoding = iCalOutputEncoding.Instance; context.Response.Clear(); context.Response.ContentEncoding = outputEncoding; context.Response.ContentType = "text/calendar"; iCalendarSerializer serializer = new iCalendarSerializer(); serializer.Serialize(iCal, context.Response.OutputStream, outputEncoding); }
public AccountController() { db = new EventCalendarDb(); }