public CustomDataType[] getUsers() { List <CustomDataType> cache; if (HttpContext.Current.Cache["userddlcache"] != null) { cache = HttpContext.Current.Cache["userddlcache"] as List <CustomDataType>; } else { cache = new List <CustomDataType>(); foreach (UserInfo user in ADUtils.FindUsers(OUVisibility.BookingSystem)) { if (user.Notes == user.UserName) { cache.Add(new CustomDataType(string.Format("{0}", user.UserName), user.UserName.ToLower())); } else { cache.Add(new CustomDataType(string.Format("{0} - ({1})", user.UserName, user.Notes), user.UserName.ToLower())); } } HttpContext.Current.Cache.Insert("userddlcache", cache, new System.Web.Caching.CacheDependency(new string[] { }, new string[] { }), DateTime.Now.AddHours(1), TimeSpan.Zero); } return(cache.ToArray()); }
protected void Page_Load(object sender, EventArgs e) { rez = new List <Resource>(); if (RouteData.Values.Count == 0) { foreach (Resource r in config.BookingSystem.Resources.Values) { if (isVisible(r.ShowTo, r.HideFrom)) { rez.Add(r); } } } else if (RouteData.Values.ContainsKey("resource")) { foreach (string s in RouteData.GetRequiredString("resource").Split(new char[] { ',' })) { foreach (Resource r in config.BookingSystem.Resources.Values) { if (isVisible(r.ShowTo, r.HideFrom) && r.Name.ToLower() == s.Trim().ToLower()) { rez.Add(r); } } } } else if (RouteData.Values.ContainsKey("type")) { foreach (string s in RouteData.GetRequiredString("type").Split(new char[] { ',' })) { foreach (Resource r in config.BookingSystem.Resources.Values) { if (isVisible(r.ShowTo, r.HideFrom) && r.Type == (ResourceType)Enum.Parse(typeof(ResourceType), s.Trim())) { rez.Add(r); } } } } if (rez.Count == 0 && !isBSAdmin) { Response.Redirect("~/unauthorised.aspx"); } resources1.DataSource = resources2.DataSource = rez.ToArray(); resources1.DataBind(); resources2.DataBind(); lessons.DataSource = config.BookingSystem.Lessons; lessons.DataBind(); subjects.DataSource = config.BookingSystem.Subjects.ToArray(); subjects.DataBind(); adminlink.Visible = isBSAdmin || User.IsInRole("Domain Admins"); userlist.Items.Clear(); foreach (UserInfo user in ADUtils.FindUsers(OUVisibility.BookingSystem)) { if (user.DisplayName == user.UserName) { userlist.Items.Add(new ListItem(user.UserName, user.UserName.ToLower())); } else { userlist.Items.Add(new ListItem(string.Format("{0} - ({1})", user.UserName, user.Notes), user.UserName.ToLower())); } } userlist.SelectedValue = ADUser.UserName.ToLower(); try { DateTime d = CurrentDate; BodyCode = new string[] { "", "" }; } catch (ArgumentOutOfRangeException) { BodyCode = new string[] { " style=\"display: none;\"", "You are current outside of the set terms, please get an Admin to set the new year terms" }; } }
protected void importSIMS_Click(object sender, EventArgs args) { if (!File.Exists(Server.MapPath("~/app_data/sims-bookings.xml"))) { return; } XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("~/app_data/sims-bookings.xml")); XmlDocument sb = new XmlDocument(); sb.Load(Server.MapPath("~/app_data/StaticBookings.xml")); UserInfo[] users = ADUtils.FindUsers(OUVisibility.BookingSystem); foreach (XmlNode n in doc.SelectNodes("/SuperStarReport/Record")) { string res = ""; try { res = n.SelectSingleNode("Name").InnerText; } catch { continue; } string user = ""; if (n.SelectSingleNode("MainTeacher") == null) { continue; } if (users.Count(u => u.Notes.ToLower() == n.SelectSingleNode("MainTeacher").InnerText.ToLower()) > 0) { user = users.Single(u => u.Notes.ToLower() == n.SelectSingleNode("MainTeacher").InnerText.ToLower()).UserName; } else if (users.Count(u => u.DisplayName.ToLower().EndsWith(n.SelectSingleNode("MainTeacher").InnerText.ToLower().Split(new char[] { ' ' })[n.SelectSingleNode("MainTeacher").InnerText.ToLower().Split(new char[] { ' ' }).Length - 1])) == 1) { user = users.Single(u => u.DisplayName.ToLower().EndsWith(n.SelectSingleNode("MainTeacher").InnerText.ToLower().Split(new char[] { ' ' })[n.SelectSingleNode("MainTeacher").InnerText.ToLower().Split(new char[] { ' ' }).Length - 1])).UserName; } if (string.IsNullOrWhiteSpace(user)) { throw new ArgumentOutOfRangeException("MainTeacher", "User cannot be found from " + n.SelectSingleNode("MainTeacher").InnerText); } string name = n.SelectSingleNode("Description").InnerText; if (n.SelectSingleNode("YearGroup") != null) { name = n.SelectSingleNode("YearGroup").InnerText.Replace(" ", " ") + " " + name; } string d = n.SelectSingleNode("Name1").InnerText.Split(new char[] { ':' })[0]; int day; if (int.TryParse(d.Substring(d.Length - 2, 1), out day)) { day = int.Parse(d.Substring(d.Length - 2, 2)); } else if (!int.TryParse(d.Substring(d.Length - 1, 1), out day)) { day = ConvertDayToInt(d); } string lesson = n.SelectSingleNode("Name1").InnerText.Split(new char[] { ':' })[1]; lesson = config.BookingSystem.Lessons.Single(l => l.Name.EndsWith(" " + lesson)).Name; if (sb.SelectSingleNode("/Bookings").ChildNodes.Count == 0 || sb.SelectSingleNode("/Bookings/Booking[@day='" + day + "' and @lesson='" + lesson + "' and @room='" + res + "']") == null) { XmlElement e = sb.CreateElement("Booking"); e.SetAttribute("day", day.ToString()); e.SetAttribute("lesson", lesson); e.SetAttribute("room", res); e.SetAttribute("name", name); e.SetAttribute("username", user); sb.SelectSingleNode("/Bookings").AppendChild(e); } else { XmlNode e = sb.SelectSingleNode("/Bookings/Booking[@day='" + day + "' and @lesson='" + lesson + "' and @room='" + res + "']"); e.Attributes["name"].Value = name; e.Attributes["username"].Value = user; } } sb.Save(HttpContext.Current.Server.MapPath("~/App_Data/StaticBookings.xml")); Response.Redirect("./"); }
protected void Page_Load(object sender, EventArgs e) { List <string> users = new List <string>(); foreach (string s in config.HelpDesk.Admins.Split(new char[] { ',' })) { if (s.StartsWith("!")) { continue; } else if (!System.Web.Security.Roles.RoleExists(s.Trim())) { users.Add(s.Trim().ToLower()); } else { foreach (string s2 in System.Web.Security.Roles.GetUsersInRole(s.Trim())) { if (!users.Contains(s2.ToLower())) { users.Add(s2.ToLower()); } } } } foreach (string s in config.HelpDesk.Admins.Split(new char[] { ',' })) { if (s.StartsWith("!") && users.Contains(s.Trim().Substring(1).ToLower())) { users.Remove(s.Trim().Substring(1).ToLower()); } } if (config.HelpDesk.Provider == "xml") { foreach (FileInfo f in new DirectoryInfo(Server.MapPath("~/app_data/")).GetFiles("Tickets_*.xml", SearchOption.TopDirectoryOnly)) { archiveddates.Items.Add(new ListItem(f.Name.Remove(f.Name.LastIndexOf('.')).Remove(0, 8).Replace("_", " to "), f.Name.Remove(f.Name.LastIndexOf('.')).Remove(0, 7))); } } else { Data.SQL.sql2linqDataContext sql = new Data.SQL.sql2linqDataContext(WebConfigurationManager.ConnectionStrings[config.HelpDesk.Provider].ConnectionString); foreach (var tick in sql.Tickets.Where(t => t.Archive != "").GroupBy(t => t.Archive)) { archiveddates.Items.Add(new ListItem(tick.Key.Replace("_", " to "), tick.Key)); } } hasArch = archiveddates.Items.Count > 0; if (hasArch) { archiveddates.Items.Insert(0, new ListItem("--- Select ---", "")); } adminbookingpanel.Visible = archiveadmin.Visible = isHDAdmin; if (isHDAdmin) { userlist.Items.Clear(); userlist2.Items.Clear(); foreach (UserInfo user in ADUtils.FindUsers(OUVisibility.HelpDesk)) { if (user.DisplayName == user.UserName) { userlist.Items.Add(new ListItem(user.UserName, user.UserName.ToLower())); } else { userlist.Items.Add(new ListItem(string.Format("{0} - ({1})", user.UserName, user.DisplayName), user.UserName.ToLower())); } if (users.Contains(user.UserName.ToLower())) { if (user.DisplayName == user.UserName) { userlist2.Items.Add(new ListItem(user.UserName, user.UserName.ToLower())); } else { userlist2.Items.Add(new ListItem(string.Format("{0} - ({1})", user.UserName, user.DisplayName), user.UserName.ToLower())); } } } userlist.SelectedValue = userlist2.SelectedValue = ADUser.UserName.ToLower(); } if (!Request.Browser.Browser.Contains("Chrome")) { try { foreach (string ip in config.AD.InternalIP) { if (new IPSubnet(ip).Contains(Request.UserHostAddress) && Dns.GetHostEntry(Request.UserHostAddress).HostName.ToLower().EndsWith(config.AD.UPN.ToLower())) { newticket_pc.Value = Dns.GetHostEntry(Request.UserHostAddress).HostName.ToLower().Remove(Dns.GetHostEntry(Request.UserHostAddress).HostName.IndexOf('.')); } } } catch { } } migrate.Visible = isUpgrade; }