protected void Page_Load(object sender, EventArgs e)
        {
            // Check user authorised!

            string UserEmail = "";
            string UserID = "";

            // Read System Cookie for User Email / ID

            HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
            myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

            // Read the cookie information and display it.
            if (myTestCookie != null)
            {
                // User details collected

                UserEmail = myTestCookie.Value;

            }
            else
            {
                // No user cookie redirect to login

                Response.Redirect("/");
            }

            // Continue normal programming

            string thisOp = Request.QueryString["Op"];

            // Get Messages

            // Check details against DB

            DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);
            DBCommand = DBConnection.CreateCommand();

            UK_Film_Location_Class.UserDetails objUser = new UK_Film_Location_Class.UserDetails();
            objUser.getUserFromEmail(UserEmail);

            UserID = objUser.UserID;

            // Get Tasks

            int myCount = 0;

            switch (thisOp)
            {
                case "AllTasks":
                    TableHeaderLiteral.Text = "<tr><th>User</th><th>Task</th><th width=\"150\">Date Created</th><th width=\"180\"></th></tr>";

                    DBConnection.Open();

                    DBCommand.CommandText = "select Tasks.*, userdetails.firstname from Tasks left join Userdetails on userdetails.UserID = Tasks.AssignedUserID where IsComplete = 0 order by DateAdded asc;";

                    DBResult = DBCommand.ExecuteReader();

                    Messages.Text = "";

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string isAction = "";

                        if (!string.IsNullOrEmpty(DBResult["TaskAction"].ToString()))
                        {
                            isAction = "<a href=\"/" + UK_Film_Location_Class.UKFilmLocation.getTaskFromAction(DBResult["TaskAction"].ToString(), DBResult["TaskAttributes"].ToString()) + "\" class=\"btn-default btn\">Do</a> ";
                        }

                        Messages.Text += "<tr><td scope=\"row\">" + DBResult["FirstName"].ToString() + "</td><td>" + DBResult["Task"].ToString() + "</td><td>" + DBResult["DateAdded"].ToString() + "</td><td align=\"right\">" + isAction + "<a href=\"javascript:if (confirm('Are you sure you want to sign off this task?')) {document.location.href='/completetask.aspx?TaskID=" + DBResult["RecordID"].ToString() + "';}\" class=\"btn-default btn\">Complete</a></td></tr>";

                        myCount++;
                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Outstanding Tasks : " + myCount + "<br>";
                    break;
                case "LocationTasks":
                DBConnection.Open();

                DBCommand.CommandText = "select * from Locations where Approved = 0 and Removed = 0 order by RecordID desc;";

                DBResult = DBCommand.ExecuteReader();

                Messages.Text = "";

                myCount = 0;

                while (DBResult.Read())
                {
                    string thisAction = "";

                    TableHeaderLiteral.Text = "<tr><th>Task</th><th width=\"50\"></th></tr>";

                    thisAction += "This property needs to be approved!<br>";

                    if (string.IsNullOrEmpty(DBResult["LocationID"].ToString()))
                    {
                        thisAction += "This property needs an ID!<br>";
                    }

                    string thisPath = "";

                    thisPath = Server.MapPath("~/Locations/") + "/" + DBResult["LocationID"].ToString() + "/" + DBResult["LocationID"].ToString() + "_1-64x64.jpg";

                    if (!File.Exists(thisPath))
                    {
                        thisAction += "This property needs an image!";
                    }

                    if (!string.IsNullOrEmpty(thisAction))
                    {
                        Messages.Text += "<tr><td scope=\"row\"><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\">Location : " + DBResult["LocationID"].ToString() + " - " + DBResult["Title"].ToString() + "<br>" + thisAction + "</a></td><td><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                    }

                    myCount++;

                }

                DBResult.Close();
                DBConnection.Close();

                StatsLiteral.Text += "Locations needing approval : " + myCount + "<br>";

                // Check Images

                DBConnection.Open();

                DBCommand.CommandText = "select Locations.RecordID, Locations.LocationID, Locations.Title, (select count(*) from LocationImages where locationimages.LocationID = locations.LocationID ) as NumRecs from Locations where Approved = 1  order by RecordID asc;";

                DBResult = DBCommand.ExecuteReader();

                myCount = 0;

                while (DBResult.Read())
                {
                    string thisAction = "";

                    if (DBResult["NumRecs"].ToString() == "0")
                    {
                        thisAction = "Location : " + DBResult["LocationID"].ToString() + " - " + DBResult["Title"].ToString() + "<br>This location needs an image!";

                    }
                    if (!string.IsNullOrEmpty(thisAction))
                    {

                        Messages.Text += "<tr><th scope=\"row\"><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\">" + thisAction + "</a></td><td><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                        myCount++;
                    }

                }

                DBResult.Close();
                DBConnection.Close();

                StatsLiteral.Text += "Locations needing images : " + myCount + "<br>";
                    break;
                case "KitchenTasks":

                    // Check Images

                    DBConnection.Open();

                    DBCommand.CommandText = "SELECT distinct(Locations.LocationID), locations.Title, locations.RecordID, (select COUNT(LocationImages.LocationID) from LocationImages where LocationImages.LocationID = Locations.LocationID and LocationImages.Target = 'Kitchen') AS ImageCount, Locations.Approved  FROM Locations LEFT JOIN LocationImages on Locations.LocationID = LocationImages.LocationID  where Locations.Approved = 1 and (not Locations.kitchentype = '' and not Locations.kitchentype is null) having ImageCount = 0;";

                    DBResult = DBCommand.ExecuteReader();

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string thisAction = "";

                        if (DBResult["ImageCount"].ToString() == "0")
                        {
                            thisAction = "Location : " + DBResult["LocationID"].ToString() + " - " + DBResult["Title"].ToString() + "<br>This location needs an image!";

                        }
                        if (!string.IsNullOrEmpty(thisAction))
                        {

                            Messages.Text += "<tr><th scope=\"row\"><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\">" + thisAction + "</a></td><td><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                            myCount++;
                        }

                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Kitchen locations needing images : " + myCount + "<br>";

                    break;
                case "WarehouseTasks":

                    // Check Images

                    DBConnection.Open();

                    DBCommand.CommandText = "SELECT distinct(Locations.LocationID), locations.Title, locations.RecordID, (select COUNT(LocationImages.LocationID) from LocationImages where LocationImages.LocationID = Locations.LocationID and LocationImages.Target = 'Warehouse') AS ImageCount, Locations.Approved  FROM Locations LEFT JOIN LocationImages on Locations.LocationID = LocationImages.LocationID  where Locations.Approved = 1 and Locations.TypeID like '%2162%' having ImageCount = 0;";

                    DBResult = DBCommand.ExecuteReader();

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string thisAction = "";

                        if (DBResult["ImageCount"].ToString() == "0")
                        {
                            thisAction = "Location : " + DBResult["LocationID"].ToString() + " - " + DBResult["Title"].ToString() + "<br>This location needs an image selected!";

                        }
                        if (!string.IsNullOrEmpty(thisAction))
                        {

                            Messages.Text += "<tr><th scope=\"row\"><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\">" + thisAction + "</a></td><td><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                            myCount++;
                        }

                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Warehouse locations needing images selecting : " + myCount + "<br>";

                    break;
                case "AddressTasks":

                    // Check Images

                    DBConnection.Open();

                    DBCommand.CommandText = "SELECT distinct(Locations.LocationID), locations.Title, locations.RecordID FROM Locations where Removed = 0 and (Locations.Address = '' or Locations.Address is null or Locations.Postcode = '' or Locations.Postcode is null);";

                    DBResult = DBCommand.ExecuteReader();

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string thisAction = "";

                        thisAction = "Location : " + DBResult["LocationID"].ToString() + " - " + DBResult["Title"].ToString() + "<br>This location needs address details checked!";

                        if (!string.IsNullOrEmpty(thisAction))
                        {

                            Messages.Text += "<tr><th scope=\"row\"><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\">" + thisAction + "</a></td><td><a href=\"/LocationDetails.aspx?RecordID=" + DBResult["RecordID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                            myCount++;
                        }

                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Locations needing address details : " + myCount + "<br>";

                    break;

                case "MissingEmail":

                    // Check Images

                    DBConnection.Open();

                    DBCommand.CommandText = "SELECT ContactID, Name, Email, Tel, Mobile, RecordID FROM Contacts where email is null or email = '';";

                    DBResult = DBCommand.ExecuteReader();

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string thisAction = "";

                        thisAction = DBResult["Name"].ToString() + "<br>Tel : " + DBResult["Tel"].ToString() + "<br>Mobile : " + DBResult["Mobile"].ToString() + "<br>This contact needs details checked!";

                        if (!string.IsNullOrEmpty(thisAction))
                        {

                            Messages.Text += "<tr><th scope=\"row\"><a href=\"/ContactDetails.aspx?ContactID=" + DBResult["ContactID"].ToString() + "\">" + thisAction + "</a></td><td><a href=\"/ContactDetails.aspx?ContactID=" + DBResult["ContactID"].ToString() + "\" class=\"btn-default btn\">Do</a></td></tr>";
                            myCount++;
                        }

                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Locations needing address details : " + myCount + "<br>";

                    break;

                default:
                    TableHeaderLiteral.Text = "<tr><th colspan=\"2\">Task</th><th width=\"150\">Date Created</th><th width=\"180\"></th></tr>";

                    DBConnection.Open();

                    if (objUser.isAgent) DBCommand.CommandText = "select * from Tasks where (AssignedUserID = '" + UserID + "') and IsComplete = 0 order by DateAdded asc;";
                    else DBCommand.CommandText = "select * from Tasks where (AssignedUserID = '" + UserID + "' or AssignedUserID = '0') and IsComplete = 0 order by DateAdded asc;";

                    DBResult = DBCommand.ExecuteReader();

                    Messages.Text = "";

                    myCount = 0;

                    while (DBResult.Read())
                    {
                        string isAction = "";

                        if (!string.IsNullOrEmpty(DBResult["TaskAction"].ToString()))
                        {
                            isAction = "<a href=\"/" + UK_Film_Location_Class.UKFilmLocation.getTaskFromAction(DBResult["TaskAction"].ToString(), DBResult["TaskAttributes"].ToString()) + "\" class=\"btn-default btn\">Do</a> ";
                        }

                        UK_Film_Location_Class.Tasks objTask = new UK_Film_Location_Class.Tasks();
                        objTask.getTask(Convert.ToInt32(DBResult["RecordID"].ToString()));

                        Messages.Text += "<tr><td scope=\"row\" width=\"36\">" + UK_Film_Location_Class.Tasks.getTaskPriorityIcon(Convert.ToInt32(DBResult["Priority"].ToString()), 32) + "</td><td>" + objTask.Text + "</td><td>" + DBResult["DateAdded"].ToString() + "</td><td>" + isAction + "<a href=\"javascript:if (confirm('Are you sure you want to sign off this task?')) {document.location.href='/completetask.aspx?TaskID=" + DBResult["RecordID"].ToString() + "';}\" class=\"btn-default btn\">Complete</a></td></tr>";
                        myCount++;
                    }

                    DBResult.Close();
                    DBConnection.Close();

                    StatsLiteral.Text += "Outstanding Tasks : " + myCount + "<br>";
                    break;
            }

            DBConnection.Dispose();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get UserID

            string UserID = "";
            string UserEmail = "";

            HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
            myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

            // Read the cookie information and display it.
            if (myTestCookie != null)
            {
                // User details collected

                UserEmail = myTestCookie.Value;

            }
            else
            {
                // No user cookie redirect to login

                Response.Redirect("/");
            }

            UserID = UK_Film_Location_Class.UKFilmLocation.getUserFromEmail(myTestCookie.Value);

            GlobalData.Text = "<script>UserID = '" + UserID + "';</script>";

            DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);

            DBCommand = DBConnection.CreateCommand();

            ImmediateTasksLiteral.Text = "";

            DBConnection.Open();

            DBCommand.CommandText = "SELECT RecordID from tasks where DateComplete is null and (TaskAction = 'CHECK NEW LOCATION' or TaskAction = 'RECCE REQUEST' or TaskAction = 'CHECK NEW IMAGES' or TaskAction = 'NEW LOCATION' or TaskAction = 'APPROVE IMAGES') order by recordid desc limit 0, 5;";

            DBResult = DBCommand.ExecuteReader();

            while (DBResult.Read())
            {
                UK_Film_Location_Class.Tasks objTask = new UK_Film_Location_Class.Tasks();
                objTask.getTask(Convert.ToInt32(DBResult["RecordID"].ToString()));

                ImmediateTasksLiteral.Text += "<a href=\"" + UK_Film_Location_Class.Tasks.getTaskActionLink(objTask.TaskAction, objTask.TaskAttributes) + "\">";

                ImmediateTasksLiteral.Text += "<div class=\"online-top\">";
                ImmediateTasksLiteral.Text += "<div class=\"top-at\" style=\"margin-top: 5px;\">";

                // Change icon if possible

                string thisIcon = "";

               // thisIcon = UK_Film_Location_Class.Tasks.getTaskAlternativeIcon(objTask.TaskAction, objTask.TaskAttributes, 64);

                if (string.IsNullOrEmpty(thisIcon)) ImmediateTasksLiteral.Text += UK_Film_Location_Class.Tasks.getTaskPriorityIcon(Convert.ToInt32(objTask.RecordID), 64);

                ImmediateTasksLiteral.Text += thisIcon + "</div>";
                ImmediateTasksLiteral.Text += "<div class=\"top-on\">";
                ImmediateTasksLiteral.Text += "<div class=\"top-on1\">";
                ImmediateTasksLiteral.Text += "<p>"+ objTask.Task +"</p>";
                ImmediateTasksLiteral.Text += "<span>" + UK_Film_Location_Class.Tasks.getTaskDetails(objTask.TaskAction, objTask.TaskAttributes) + "</span>";

                ImmediateTasksLiteral.Text += "</div>";
                ImmediateTasksLiteral.Text += "<span style=\"display: block; clear: both;\"><a href=\"javascript:if (confirm('Are you sure you want to sign off this task?')) {document.location.href='/completetask.aspx?Op=/Dashboard.aspx&TaskID=" + objTask.RecordID + "';}\" class=\"btn-default btn\">Done!</a></span>";
                ImmediateTasksLiteral.Text += "<label class=\"round\"></label>";
                ImmediateTasksLiteral.Text += "<div class=\"clearfix\"></div>";
                ImmediateTasksLiteral.Text += "</div>";
                ImmediateTasksLiteral.Text += "<div class=\"clearfix\"></div>";
                ImmediateTasksLiteral.Text += "</div>";
                ImmediateTasksLiteral.Text += "</a>";
            }

            DBResult.Close();

            DBConnection.Close();

            DBConnection.Dispose();
        }