Solved

Javascript

Posted on 2010-09-13
6
1,081 Views
Last Modified: 2012-06-22
I have a piece of code which works beutifully.  On of the things about it is that it has photo buttons for each row with the button onloy being displayed on the mouse rollover.  This works great except in IE6 runing under a Citrix web app client.  As the only time the page will be viewed in IE6 will be when using the Citrix software I am wondering if there is a way to test for the browser and version and then if it comes back as IE6, simply display all the buttons.  (Im guessing my issue is with the rollover event which unless anyone has any bright ideas, is easier just to remove the snazziness for those using an old browser!)

Thanks in advance
var output="";

var username="";

var userid=0;

var srf = false;

var menus = "";



//------------------------------------------------------------------------

// checkButtonResetType

// set to 1 for the check button to reset 1 week after last check

// set to 2 for the check button to reset once a week

//------------------------------------------------------------------------

var checkButtonResetType = 1;



function main()

{

    var resolved;

    var usertype = Session("usertype");



    if(!Session("signedin") || Session("signedin") == false)

    {

        Session("signinmessage") = "It appears your session has expired.";

        Response.Redirect("login.asp");

    }



    userid = parseInt(Session("userid"));

    username = Session("username");



    menus = username + "<br/>";



    if( usertype != null )

        if( (usertype == 2) || (usertype == 0) )  {

        	

            resolved = "<a href='default.asp?srf=1'>Show resolved faults</a>";



            if(Request.QueryString.Key("srf") == "srf")

                if(getquerytestnumparam("srf")==1)  {

                    resolved = "<a href='default.asp'>Hide resolved faults</a>";

                    srf = true;

                }



            menus += resolved + "<br/>";

            

        	if( usertype == 2) {

        		menus += "<a href='manageusers.asp'>Manage Users</a><br/>";

        		menus += "<a href='managetheaters.asp'>Manage Theatres</a><br/>";

        		menus += "<a href='manageequipment.asp'>Manage Equipment</a><br/>";        		

                }

                





        }

        

    menus += "<a href='changepassword.asp'>Change my password</a><br/>";

    menus += "<a href='signout.asp'>Sign out</a>";



    function formatdate(date)

    {



        var sdate = "";



        if(date.getDate() < 10)

            sdate += "0";



        sdate += date.getDate() + "/";



        if((date.getMonth()+1) < 10)

            sdate += "0";



        sdate += (date.getMonth()+1) + "/" + date.getFullYear();



        return(sdate);



    }



    function getUserName(dbConn,userid)

    {

        var username = "";

        var dbRec = Server.CreateObject("ADODB.RecordSet");

        var SQL = "SELECT * FROM Users WHERE (Userid = " + userid + ")";



        try {

            dbRec.Open(SQL,dbConn,1,1);



            try {



                if(!dbRec.EOF)

                    username = String(dbRec("FullName"));



            } catch(e) {}



            dbRec.Close();



        } catch(e) {}



        delete dbRec;



        return(username);

    }



    function areThereFaults(dbConn,theatreID)

    {

        var dbRec,SQL;

        var therearefaults = false;



        dbRec = Server.CreateObject("ADODB.RecordSet");



        SQL = "SELECT Faults.ID FROM Faults JOIN Equipment ON (Equipment.EquipID = Faults.EquipID) WHERE (Equipment.TheatreID = " + theatreID + ")";

        

        // SDS - added this so that ! indicator doesn't show up when its not supposed to

        

        if(!srf)

            SQL += " AND (Faults.SignedOffBy = 0 )"; // get unresolved faults for this equipment

    

        dbRec.Open(SQL,dbConn,1,1);



        if(!dbRec.EOF)

            therearefaults = true;



        dbRec.Close();



        return(therearefaults);



    }



//---------- getFaults() ------------------------------------------------

// given the equipid will look up all associated faults and build

// a table to display them

//-----------------------------------------------------------------------



    function getFaults(dbConn,equipid)

    {

        var output = "";

        var dbRec,SQL;

        var tdate;

        var faultid;

        var description;



        dbRec = Server.CreateObject("ADODB.RecordSet");



        SQL = "SELECT Faults.ID, Faults.Resolution, Faults.description, Faults.ReportedOn, Faults.SignedOffOn, Faults.EquipID, Faults.SignedOffBy, Faults.ReportedBy, Users.UserID, Users.FullName FROM Faults JOIN Users ON (Faults.ReportedBy=Users.UserID) WHERE ((Faults.EquipID = " + equipid + ")";



        if(!srf)

            SQL += " AND (Faults.SignedOffBy = 0 )"; // get unresolved faults for this equipment



        SQL += ")";



        dbRec.Open(SQL,dbConn,1,1);



        while(!dbRec.EOF)

        {

            faultid = dbRec("ID");

            tdate = new Date(dbRec("ReportedOn"));



            output += "<tr onmousemove='highlightrow(this)' onmouseout='unhighlightrow(this)' id='faultrow" + faultid + "'><td style='padding-bottom: 5pt' id='faultdesc" + faultid + "' ";



            if(dbRec("SignedOffBy")>0)

                output += "class='faultfixed'";

            else

                output += "class='fault'";



            output += " colspan='3'>";

            output += formatdate(tdate) + "&nbsp;Reported By:" + dbRec("FullName");

            description = String(dbRec("Description"));

            description = description.replace(/\n/g,"<br/>");

            output += "<span style='padding-left: 10pt'><br/>" + description;



            if(dbRec("SignedOffBy") != 0 )

            {

                tdate = new Date(dbRec("SignedOffOn"));

                output += "<br/>" + formatdate(tdate) + "&nbsp;Resolved By: " + getUserName(dbConn,dbRec("SignedOffBy"));

                description = String(dbRec("Resolution"));

                description = description.replace(/\n/g,"<br/>");

                output += "<br/>" + description;

            }



            output += "</span>";

            output += "</td><td valign='top' id='resolve" + faultid + "'>";



            if(dbRec("SignedOffBy") != 0 )

                output += "&nbsp;";

            else

                output += "<button style='width: 60pt' onclick='resolvefault(" + faultid + ")'>Resolve</button>";



            output += "</td><td>&nbsp;</td>";

            output += "<td style='width: 60pt'><img src='images/spacer.gif' style='width: 55pt' /></td></tr>";

        	

            dbRec.MoveNext();

        }



        dbRec.Close();



        return(output);

    }



function loadTheatres()

{

    var dbConn,dbRec,SQL;

    var i,tdate,xdate;

    var currenttheatre = 0;

    var milliweek = 1000*60*60*24*6;

    var equipid;

    var firsttheatre = true;

    var showcheckbox;

    

    output = "";

    dbConn = OpenDatabase();



    try

    {

        dbRec = Server.CreateObject("ADODB.RecordSet");



        // join with Theatres tables field: "Name" joined with "TheatreID"

        // join with usersId -> TheatreID (only users assigned to the theatre)

     

        SQL = "SELECT Equipment.LastCheckDate,Equipment.SignedOffBy,Equipment.EquipID, Equipment.Signage,Equipment.Variant,Equipment.PhotoNumber,Equipment.DateAdded,Equipment.TheatreID,Theatres.Name FROM Theatres INNER JOIN Assignments ON Theatres.ID = Assignments.TheatreID INNER JOIN Equipment ON Equipment.TheatreID = Theatres.ID WHERE ( Assignments.UserID = " + userid + ")";

        SQL += " AND ((Equipment.Removed IS NULL) OR (Equipment.Removed = 0)) ORDER BY Theatres.Name";

     

        dbRec.Open(SQL,dbConn,1,1);



        while(!dbRec.EOF)

        {

            foutput = getFaults(dbConn,dbRec("EquipId"));



            if( (Session("usertype") == 0) || (Session("usertype") == 2) || ( (Session("usertype") == 1)&&(foutput.length>0)) )

            {

                if( dbRec("TheatreID") != currenttheatre)

                {

                    if(!firsttheatre)

                        output += "</table></div>";  // close the theatre



                    firsttheatre = false;



                    output += "<div style='width: 600pt; vertical-align: middle'><img style='padding-top: 10pt' onclick='collapseexpandtheatre(this," + dbRec("TheatreID") + ")' src='images/rightarrow.png' width=24><span class='theatrename'>" + dbRec("Name");



                    if( areThereFaults(dbConn,Number(dbRec("TheatreID")) ) )

                        output += "<span class='faultindicator'>&nbsp;!</span>";



                    output += "</span>\r\n";

                    output += "<table style='display: none; width: 100%' id='equiptable" + dbRec("TheatreID") + "' border='0' cellpadding='0' cellspacing='0'>";

                    output += "<tr></th><th style='width: 250pt'>Signage</th>";

                    output += "<th style='width: 100pt'>Variant</th>";

                    output += "<th style='width: 40pt; padding-left: 10pt; padding-right: 10pt; white-space: nowrap'>Photo #</th>";

                    output += "<th style='text-align: center; width: 80pt'>Faults</th>";



                    if(Session("usertype") != 1)

                        output += "<th style='text-align: center; width: 70pt'>Checked</th>";

                    else

                        output += "<th style='width: 70pt'>&nbsp;</th>";



                output += "<th style='width: 60pt'>&nbsp;</th></tr>\r\n"; // blank cell that would have photo in it



                    currenttheatre = parseInt(dbRec("TheatreID"));

                }



                equipid = dbRec("EquipID");



                output += "<tr id='equiprowid"+equipid+"' onmousemove='highlightrow(this)' onmouseout='unhighlightrow(this)'>";

                output += "<td style='padding-left: 4pt; height: 18pt'>" + dbRec("Signage") + "</td>";



                if(dbRec("Variant").ActualSize != 0)

                	output += "<td class='variant' style='padding-left: 4pt; padding-right: 4pt'>" + dbRec("Variant") + "</td>";

                else

                    output += "<td class='variant'>&nbsp;</td>";



                if(dbRec("PhotoNumber").ActualSize != 0 )

                    output += "<td style='text-align: center'>" + dbRec("PhotoNumber") + "</td>";

                else

                    output += "<td>&nbsp;</td>";



                if(Session("usertype") != 1)

                {

                	output += "<td><button id='faultbutton" + equipid + "' style='display: none; width: 60pt' onclick='addfault("+equipid+")'>Add fault</button></td>";



                    // if the last time this was checked was over a week ago then show the button - else show the date



                 try {

                        tdate = new Date(dbRec("LastCheckDate"));

                        tdate = new Date(tdate.getFullYear(),tdate.getMonth(),tdate.getDate(),0,0,0,0);

                        xdate = new Date();

                        xdate = new Date(xdate.getFullYear(),xdate.getMonth(),xdate.getDate(),0,0,0,0);

                            

                        if(checkButtonResetType == 1) // reset one week since last check

                        {

                            showcheckbox = ((xdate.getTime() - tdate.getTime()) > milliweek);

                        }

                        

                        if(checkButtonResetType == 2) // reset on Sunday 12:00 am

                        {

                            var weekday = xdate.getDay(); // Sunday == 0

                            xdate = new Date(xdate.getTime() - (weekday * (24*60*60*1000))); // this is previous sunday at midnight



                            showcheckbox = (xdate.getTime() > tdate.getTime());

                        }

                        

                        if(showcheckbox)

                            output += "<td style='text-align: center'><input type='checkbox' onclick='checkequipment(this,"+equipid+")' /><span id='checked"+equipid+"'></span></td>";

                        else

                            output += "<td style='text-align: center' id='checked"+equipid+"'>" + formatdate(tdate) + "</td>";



                    } catch(e)

                    {

                        output += "<td style='text-align: center'><input type='checkbox' onclick='checkequipment(this,"+equipid+")' /><span id='checked"+equipid+"'></span></td>";

                    }

                }

                else

                	output += "<td>&nbsp;</td><td>&nbsp;</td>";

            	

                output += "<td style='width: 60pt'><button id='photo" + equipid + "' style='display: none; width: 55pt' onclick='ShowPhoto("+ equipid + ")'>Photo</button></td>";

                output += "</tr>\r\n" + foutput;

                

            }

            

            dbRec.MoveNext();

         }



         // close the last theatre

         output += "</table></div>";



        dbRec.Close();



    } catch(e) { Response.write(e.description); }



    dbConn.Close();

}



loadTheatres();



}

main();

Open in new window

0
Comment
Question by:simonwait
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 500 total points
Comment Utility
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
0
 
LVL 10

Expert Comment

by:bugada
Comment Utility
the method of previous post is not safe: you can edit the user agent easily making void that test.

It's better to check what is not working and find a workaround, or use a compatibility javascript line thos og Dean Edwards. Read this link carefully:

http://code.google.com/p/ie7-js/

Then the safest way to check IE version:

<!--[if lt IE 6]>
do code specific for IE6
<![endif]-->

Those tags are ignored by other manufacturers, as long as the code included (considered commented out).
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
why would you change the user-agent first of all?

To give the entire control to google code, i'm not sure, if thats a fully controllable situation, than what Microsoft suggests (who developed IE).

my 2 cents.

thanks.
0
 
LVL 10

Expert Comment

by:bugada
Comment Utility
usually because some sites are designed for a specific browser and blocks different ones (ie. microsoft)

Then:

Opera 7 & 8 default to MSIE identification
IE 6/7 on particular distribution  default to Gecko identification
GChrome 1 default to Safari identification

That utility is designed to make  Microsoft Internet Explorer behave like a standards-compliant browser.
You can write only one version of your program instead of branching it depending on the browser.
Is written by Dean Edwards that is one of the best javascript coder in the world.

Obvioulsy all respect to your point of view.
0
 
LVL 1

Author Comment

by:simonwait
Comment Utility
This has actually turned out to not be the Citrix component but the Cisco ASA providing the VPN.  The issue stops all javascript from running so simply finding the browser wont actually help as the original plan of just displaying all hidden buttons but this means while the buttons show, clicking on them does nothing!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now