<%@ Page language="c#" Debug="true"%>
<%
//! Support file only, run Schools.html instead !
// This file is used as Page_Url
// Loads and returrns reviews for given record

// --- Database initialization ---
string Path = System.IO.Path.GetDirectoryName(Context.Request.PhysicalPath);
System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=\"" + Path + "\\Database.mdb\";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=\"Microsoft.Jet.OLEDB.4.0\";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
Conn.Open();
System.Data.OleDb.OleDbCommand Cmd = Conn.CreateCommand();
System.Data.OleDb.OleDbDataReader R;

// --- Response initialization ---
Response.ContentType = "text/xml";
Response.Charset = "utf-8";
Response.AppendHeader("Cache-Control","max-age=1, must-revalidate");
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

// --- Returns ratings for the row as server child page --- 
string XML = Request["TGData"];
if (XML == null) XML = "<Grid><Body><B id='jan$Main$1'/></Body></Grid>";  // Just for examples if called directly
System.Xml.XmlDocument X = new System.Xml.XmlDocument();
X.LoadXml(HttpUtility.HtmlDecode(XML));
System.Xml.XmlNodeList Ch = X.GetElementsByTagName("B");
Response.Write ("<Grid><Body>");   

foreach (System.Xml.XmlElement I in Ch)
{
   string[] id = I.GetAttribute("id").Split("$".ToCharArray());  // User$Def$Ident
   Response.Write ("<B id='"+I.GetAttribute("id")+"'>");
   Cmd.CommandText = "SELECT * FROM Schools_Ratings WHERE Owner='" + id[0].Replace("'","''") + "' AND Id=" + id[2];
   R = Cmd.ExecuteReader();
   while(R.Read())
   {
      Response.Write ("<I Def='Review' CName='" + R["ADate"].ToString() 
         + "' CCountry='" + R["Review"].ToString().Replace("&", "&amp;").Replace("'", "&apos;").Replace("<", "&lt;")
         + "' CRating='" +R["Stars"].ToString() + "'/>");
   }
   Response.Write("</B>");
}
Response.Write ("</Body></Grid>");
// --------------------------------------------------------------------------
%>