Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("NoSession.aspx");
            }

            int id = int.Parse(Request.Form["id"]);

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("catalog_item_delete", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@id";
            param.SqlDbType     = SqlDbType.Int;
            param.Value         = id;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            param = new SqlParameter();
            param.ParameterName = "@email";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = (string)Session["email"];
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            command.ExecuteNonQuery();
            conn.Close();
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("NoSession.aspx");
            }

            if (Request.QueryString["id"] != null)
            {
                this.id = int.Parse(Request.QueryString["id"]);
            }
            if (this.id == 0)
            {
                string objLang = ""; if (Request.QueryString["objLang"] != null)
                {
                    objLang = Request.QueryString["objLang"];
                }
                this.dic.LoadXml("<dictionary prominence='5' loginRequired='0' tcRequired='0'><objLang code='" + objLang + "'/><dicType code=''/><metaLang code='" + objLang + "'/><title lang='" + objLang + "'/><homepage/></dictionary>");
            }
            else
            {
                SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());
                conn.Open();

                SqlCommand command; SqlParameter param;
                command             = new SqlCommand("catalog_item_get", conn);
                command.CommandType = CommandType.StoredProcedure;

                param = new SqlParameter();
                param.ParameterName = "@id";
                param.SqlDbType     = SqlDbType.Int;
                param.Value         = this.id;
                param.Direction     = ParameterDirection.Input;
                command.Parameters.Add(param);

                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    this.dic.LoadXml((string)reader["Xml"]);

                    //remove history:
                    XmlNodeList histNodes = this.dic.SelectNodes("//history");
                    foreach (XmlNode n in histNodes)
                    {
                        n.ParentNode.RemoveChild(n);
                    }
                }
                reader.Close();
                conn.Close();
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form.Count > 0)
            {
                if (Request.Form["email"] != "")
                {
                    this.email = Request.Form["email"];
                }
                if (Request.Form["password"] != "")
                {
                    this.password = Request.Form["password"];
                }

                SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());
                conn.Open();

                SqlCommand command; SqlParameter param;
                command             = new SqlCommand("user_login", conn);
                command.CommandType = CommandType.StoredProcedure;

                param = new SqlParameter();
                param.ParameterName = "@email";
                param.SqlDbType     = SqlDbType.NVarChar;
                param.Value         = this.email;
                param.Direction     = ParameterDirection.Input;
                command.Parameters.Add(param);

                param = new SqlParameter();
                param.ParameterName = "@password";
                param.SqlDbType     = SqlDbType.NVarChar;
                param.Value         = this.password;
                param.Direction     = ParameterDirection.Input;
                command.Parameters.Add(param);

                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    this.stage = "success";
                    Session.Add("email", (string)reader["Email"]);
                    Session.Add("isAdmin", (bool)reader["IsAdmin"]);
                }
                else
                {
                    this.stage = "error";
                }

                reader.Close();
                conn.Close();
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("NoSession.aspx");
            }

            XmlDocument dic      = new XmlDocument(); dic.LoadXml((string)Request.Form["xml"]);
            int         parentID = 0; int.TryParse(dic.DocumentElement.GetAttribute("parentID"), out parentID);

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("catalog_item_save", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@xml";
            param.SqlDbType     = SqlDbType.Xml;
            param.Value         = dic.DocumentElement.OuterXml;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            if (parentID > 0)
            {
                param = new SqlParameter();
                param.ParameterName = "@parentID";
                param.SqlDbType     = SqlDbType.Int;
                param.Value         = parentID;
                param.Direction     = ParameterDirection.Input;
                command.Parameters.Add(param);
            }

            param = new SqlParameter();
            param.ParameterName = "@email";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = (string)Session["email"];
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            command.ExecuteNonQuery();
            conn.Close();
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("NoSession.aspx");
            }
            if (!(bool)Session["IsAdmin"])
            {
                Response.Redirect("NoSession.aspx");
            }

            XmlDocument doc = new XmlDocument(); doc.LoadXml((string)Request.Form["xml"]);

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("admin_save", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@xml";
            param.SqlDbType     = SqlDbType.Xml;
            param.Value         = doc.DocumentElement.OuterXml;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            param = new SqlParameter();
            param.ParameterName = "@currentUser";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = (string)Session["email"];
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            command.ExecuteNonQuery();
            conn.Close();
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("NoSession.aspx");
            }
            if (!(bool)Session["IsAdmin"])
            {
                Response.Redirect("NoSession.aspx");
            }

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("admin_get", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@currentUser";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = (string)Session["email"];
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                this.doc.LoadXml((string)reader["Xml"]);
            }
            reader.Close();
            conn.Close();
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("catalog_all", conn);
            command.CommandType = CommandType.StoredProcedure;

            SqlDataReader reader = command.ExecuteReader();
            List <int>    ids    = new List <int>();

            while (reader.Read())              //Read catalog items:
            {
                XmlDocument doc = new XmlDocument(); doc.LoadXml((string)reader["Xml"]);
                doc.DocumentElement.SetAttribute("id", ((int)reader["ID"]).ToString());
                if (reader["ParentID"] != DBNull.Value)
                {
                    doc.DocumentElement.SetAttribute("parentID", ((int)reader["ParentID"]).ToString());
                }
                this.dictionaries.Add(doc);
                ids.Add((int)reader["ID"]);

                //remove history:
                XmlNodeList histNodes = doc.SelectNodes("//history");
                foreach (XmlNode n in histNodes)
                {
                    n.ParentNode.RemoveChild(n);
                }
            }
            reader.Close();
            conn.Close();

            //Remove dictionaries whose parent is also here:
            List <XmlDocument> temp = new List <XmlDocument>();

            foreach (XmlDocument xmlDic in this.dictionaries)
            {
                int parentID = int.Parse(this.getXmlValue(xmlDic, "/dictionary/@parentID", "0"));
                if (!ids.Contains(parentID))
                {
                    temp.Add(xmlDic);
                }
            }
            this.dictionaries = temp;

            Response.ContentType = "text/xml";
            //Response.AppendHeader("Content-Disposition", "attachment; filename=catalog.xml");
            Response.Write("<dictionaries>\r\n\r\n");
            Response.Write("<!--Exported from the European Dictionary Portal on " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n");
            Response.Write("Available under Open Database Licence, http://opendatacommons.org/licenses/odbl/summary/\r\n");
            Response.Write("If you use this, do not forget to attribute the European Dictionary Portal, http://www.dictionaryportal.eu/-->\r\n\r\n");
            foreach (XmlDocument xmlDic in this.dictionaries)
            {
                Response.Write(PrettyPrintXml(xmlDic.DocumentElement.OuterXml) + "\r\n\r\n");
            }
            Response.Write("</dictionaries>\r\n");
            Response.End();
        }
Exemplo n.º 8
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //Canonize the URL:
            string domain = Request.Url.Host;

            if (domain != "localhost" && domain != "www.dictionaryportal.eu")
            {
                Response.Redirect("http://www.dictionaryportal.eu" + HttpContext.Current.Request.Url.PathAndQuery, false);
                Response.StatusCode = 301;
                Response.End();
            }

            //The requested path:
            string reqPath = Request.Url.AbsolutePath;

            //catalog.xml:
            Match match = Regex.Match(reqPath, @"^/catalog\.xml$", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                HttpContext.Current.RewritePath("/AllXml.aspx");
                return;
            }

            //File with an extension (GIF, CSS etc)? Let it through immediately:
            match = Regex.Match(reqPath, @"\.[a-zA-Z0-9]+$");
            if (match.Success && !reqPath.ToLower().EndsWith(".aspx"))
            {
                return;
            }

            Metadata metadata = new Metadata("", Server);

            //UI Languagess:
            List <string> uilangs = new List <string>();

            foreach (Language l in metadata.languages)
            {
                if (l.isUI)
                {
                    uilangs.Add(l.code);
                }
            }
            string uilangStamp = "__"; foreach (string uilang in uilangs)

            {
                if (uilangStamp != "")
                {
                    uilangStamp += "|";
                }
                uilangStamp += uilang;
            }

            //Set uilang cookie:
            match = Regex.Match(reqPath, @"^/(" + uilangStamp + @")/", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang = match.Groups[1].ToString().ToLower();
                Response.Cookies["uilang"].Value   = Server.UrlEncode(uilang);
                Response.Cookies["uilang"].Expires = DateTime.Now.AddDays(30);
                if (Request.Url.Host != "localhost")
                {
                    Response.Cookies["uilang"].Domain = Request.Url.Host;
                }
            }

            //Make sure URL always ends in slash:
            if (!Regex.IsMatch(reqPath, @"/$", RegexOptions.IgnoreCase) && !reqPath.ToLower().EndsWith(".aspx"))
            {
                Response.Redirect(reqPath + "/");
                return;
            }

            //UILang + An about page:
            match = Regex.Match(reqPath, @"^/(" + uilangStamp + @")/(info|prop|prop-ok|prop-ko|crit|crtr|stmp|dnld)/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang   = match.Groups[1].ToString().ToLower();
                string pageMode = match.Groups[2].ToString();
                HttpContext.Current.Items.Add("pageMode", pageMode);
                HttpContext.Current.Items.Add("uilang", uilang);
                HttpContext.Current.RewritePath("/About.aspx");
                return;
            }

            //Go:
            match = Regex.Match(reqPath, @"^/go/$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                HttpContext.Current.RewritePath("/Go.aspx");
                return;
            }

            //UILang + Catalog:
            match = Regex.Match(reqPath, @"^/(" + uilangStamp + @")/ctlg/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang = match.Groups[1].ToString().ToLower();
                HttpContext.Current.Items.Add("pageMode", "catalog");
                HttpContext.Current.Items.Add("uilang", uilang);
                HttpContext.Current.RewritePath("/Default.aspx");
                return;
            }

            //UILang + DictID:
            match = Regex.Match(reqPath, @"^/(" + uilangStamp + @")/([0-9]+)/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang = match.Groups[1].ToString().ToLower();
                int    dictID = int.Parse(match.Groups[2].ToString());
                HttpContext.Current.Items.Add("pageMode", "permalink");
                HttpContext.Current.Items.Add("dictID", dictID);
                HttpContext.Current.Items.Add("uilang", uilang);
                HttpContext.Current.RewritePath("/Default.aspx");
                return;
            }

            //no UILang + DictID:
            match = Regex.Match(reqPath, @"^/([0-9]+)/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                int    dictID = int.Parse(match.Groups[1].ToString());
                string uilang = Connfigger.DetectUILang(HttpContext.Current.Request, metadata);
                Response.Redirect("/" + uilang + "/" + dictID + "/");
                return;
            }

            //Home page + language code:
            match = Regex.Match(reqPath, @"^/(" + uilangStamp + @")/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang = match.Groups[1].ToString().ToLower();
                HttpContext.Current.Items.Add("pageMode", "home");
                HttpContext.Current.Items.Add("uilang", uilang);
                HttpContext.Current.RewritePath("/Default.aspx");
                return;
            }

            //Home page + no language code:
            match = Regex.Match(reqPath, @"^/(default\.aspx)?/?$", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string uilang = Connfigger.DetectUILang(HttpContext.Current.Request, metadata);
                Response.Redirect("/" + uilang + "/");
                return;
            }

            //Redirect deprecated URLs:
            if (reqPath == "/en/catalog/" && Request.QueryString.Count > 0)
            {
                Response.Redirect("/en/ctlg/?" + Request.QueryString);
            }
            if (reqPath == "/en/catalog/")
            {
                Response.Redirect("/en/ctlg/");
            }
            if (reqPath == "/en/about/")
            {
                Response.Redirect("/en/info/");
            }
            if (reqPath == "/en/stamp/")
            {
                Response.Redirect("/en/stmp/");
            }
            if (reqPath == "/en/curators/")
            {
                Response.Redirect("/en/crtr/");
            }
            if (reqPath == "/en/download/")
            {
                Response.Redirect("/en/dnld/");
            }
            if (reqPath == "/en/suggest/")
            {
                Response.Redirect("/en/prop/");
            }

            //Last chance saloon:
            //Response.Redirect("/");
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.pageMode = (string)Context.Items["pageMode"];
            this.uilang   = (string)Context.Items["uilang"];
            this.metadata = new Metadata(this.uilang, Server);

            if (Request.QueryString["objLang"] != null)
            {
                this.objLang = Request.QueryString["objLang"];
            }
            if (Request.QueryString["dicType"] != null)
            {
                this.dicType = Request.QueryString["dicType"];
            }
            if (Request.QueryString["metaLang"] != null)
            {
                this.metaLang = Request.QueryString["metaLang"];
            }
            if (Request.QueryString["txt"] != null)
            {
                this.txt = Request.QueryString["txt"];
            }

            if (pageMode == "catalog")
            {
                if (this.objLang == "x" && this.metaLang == "x" && this.dicType == "x")
                {
                    this.pageMode = "catalogHome";
                }
                else
                {
                    this.pageMode = "catalogListing";
                }
            }

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("catalog_list", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@pageMode";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = this.pageMode;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            param = new SqlParameter();
            param.ParameterName = "@objLang";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = this.objLang;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            param = new SqlParameter();
            param.ParameterName = "@dicType";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = this.dicType;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            param = new SqlParameter();
            param.ParameterName = "@metaLang";
            param.SqlDbType     = SqlDbType.NVarChar;
            param.Value         = this.metaLang;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            if (this.pageMode == "permalink")
            {
                param = new SqlParameter();
                param.ParameterName = "@dictID";
                param.SqlDbType     = SqlDbType.Int;
                param.Value         = (int)Context.Items["dictID"];
                param.Direction     = ParameterDirection.Input;
                command.Parameters.Add(param);
            }

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())              //read objLangs:
            {
                Hierarchy h = new Hierarchy();
                h.objLang = (string)reader["ObjLang"];
                h.count   = (int)reader["DictCount"];
                this.hierarchies.Add(h);
                this.objLangs.Add(h.objLang);
            }
            reader.NextResult();
            while (reader.Read())              //read searchable objLangs:
            {
                string code = (string)reader["SearchableObjLang"];
                this.searchableObjLangs.Add(code);
            }
            reader.NextResult();
            while (reader.Read())              //read metaLangs:
            {
                string code = (string)reader["MetaLang"];
                this.metaLangs.Add(code);
            }
            reader.NextResult();
            while (reader.Read())              //read objLangs-dicType combos:
            {
                string objLang = (string)reader["ObjLang"];
                foreach (Hierarchy h in this.hierarchies)
                {
                    if (h.objLang == objLang)
                    {
                        h.dicTypes.Add((string)reader["DicType"], (int)reader["DictCount"]);
                        break;
                    }
                }
            }
            reader.NextResult();
            while (reader.Read())              //read objLangs-metaLang combos:
            {
                string objLang = (string)reader["ObjLang"];
                foreach (Hierarchy h in this.hierarchies)
                {
                    if (h.objLang == objLang)
                    {
                        h.metaLangs.Add((string)reader["MetaLang"], (int)reader["DictCount"]);
                        break;
                    }
                }
            }
            reader.NextResult();
            List <int> ids = new List <int>();

            while (reader.Read())              //Read catalog items:
            {
                XmlDocument doc = new XmlDocument(); doc.LoadXml((string)reader["Xml"]);
                doc.DocumentElement.SetAttribute("id", ((int)reader["ID"]).ToString());
                if (reader["ParentID"] != DBNull.Value)
                {
                    doc.DocumentElement.SetAttribute("parentID", ((int)reader["ParentID"]).ToString());
                }
                this.dictionaries.Add(doc);
                ids.Add((int)reader["ID"]);
            }
            reader.Close();
            conn.Close();

            this.dictionariesCount = this.dictionaries.Count;
            //if(this.pageMode == "catalogListing") {
            //	//Remove dictionaries whose parent is also here:
            //	this.dictionariesCount = this.dictionaries.Count;
            //	List<XmlDocument> temp = new List<XmlDocument>();
            //	foreach(XmlDocument xmlDic in this.dictionaries) {
            //		int parentID = int.Parse(this.getXmlValue(xmlDic, "/dictionary/@parentID", "0"));
            //		if(!ids.Contains(parentID)) temp.Add(xmlDic);
            //	}
            //	this.dictionaries = temp;
            //}

            if (this.pageMode == "permalink" && this.dictionaries.Count == 0)
            {
                Response.Redirect("/" + this.uilang + "/");
            }
            if (this.pageMode == "permalink" && this.dictionaries.Count > 0)
            {
                this.permalinkTitle = this.getInnerXml(this.dictionaries[0], "/dictionary/title", "");
                this.permalinkTitle = System.Text.RegularExpressions.Regex.Replace(this.permalinkTitle, @"\</[^\>]+\>", ")");
                this.permalinkTitle = System.Text.RegularExpressions.Regex.Replace(this.permalinkTitle, @"\<[^\>]+\>", "(");
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["uilang"] != null)
            {
                this.uilang = Request.QueryString["uilang"];
            }
            if (Request.QueryString["txt"] != null)
            {
                this.txt = Request.QueryString["txt"];
            }
            if (Request.QueryString["id"] != null)
            {
                this.id = int.Parse(Request.QueryString["id"]);
            }
            if (Request.QueryString["index"] != null)
            {
                this.index = int.Parse(Request.QueryString["index"]);
            }

            SqlConnection conn = new SqlConnection(Connfigger.GetConnectionString());

            conn.Open();

            SqlCommand command; SqlParameter param;

            command             = new SqlCommand("catalog_item_get", conn);
            command.CommandType = CommandType.StoredProcedure;

            param = new SqlParameter();
            param.ParameterName = "@id";
            param.SqlDbType     = SqlDbType.Int;
            param.Value         = this.id;
            param.Direction     = ParameterDirection.Input;
            command.Parameters.Add(param);

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                this.dic.LoadXml((string)reader["Xml"]);
            }
            reader.Close();
            conn.Close();

            this.url = getXmlValue(this.dic, "/dictionary/homepage/text()", "");
            if (this.dic.SelectSingleNode("/dictionary/search[" + index + "]") != null)
            {
                XmlElement url = (XmlElement)this.dic.SelectSingleNode("/dictionary/search[" + index + "]/searchUrl");
                XmlElement el  = (XmlElement)url.SelectSingleNode("word");
                if (el != null)
                {
                    XmlText nd = this.dic.CreateTextNode(Server.UrlEncode(this.txt));
                    el.ParentNode.ReplaceChild(nd, el);
                }
                this.url = url.InnerText;
                foreach (XmlElement pf in this.dic.SelectNodes("/dictionary/search[" + index + "]/postField"))
                {
                    string name  = pf.GetAttribute("name");
                    string value = pf.GetAttribute("value");
                    if (!this.postFields.ContainsKey(name))
                    {
                        this.postFields.Add(name, value);
                    }
                }
            }
            if (this.postFields.Count == 0)            //this will be a GET request
            {
                Response.Redirect(url);
            }
            else                 //this will be a POST request
            {
                this.metadata = new Metadata(this.uilang, Server);
            }
        }