Menu.csp

To download the CSP files from this tutorial, click TutorialSamples.zip. For more information, see Code examples.

<%@ Language=JavaScript%>

<HTML>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

<BODY>

<link REL=STYLESHEET TYPE='text/css' HREF='tut.css'>

<!-- #include file=helper_js.csp -->

<!-- #Include file=RetrieveIStore.csp -->

<%

function RetrieveFullPath(FolderID, IStore)

{

//This function returns an HTML string that provides links

//to all of the parent folders for the current folder.

//The root folder is called 'Home'.


//Precondition:

//FolderID - The ID of the folder currently being viewed.

//IStore - The InfoStore object required to interface with server.

//Success - True if no error, False otherwise.



//Postcondition:

//Returns an empty string on error.


//Notes:

//The function returns an HTML string

    var Query;

    var Result;

    var Path;

        

    Path = "";


    if (FolderID == 0) {

        //This is the root folder. It has no name, so we will call it 'Home'.

        return("<a href='Home.csp?FolderID=0' target='_top'>Home</a>");

    }

            

    //A query that selects the parent folder's ID.

    Query = "Select SI_PATH, SI_NAME From CI_INFOOBJECTS Where " +

    "SI_ID =" + FolderID;

            

        

    //Query the server.

    try {

        Result = IStore.Query(Query);

    }

    catch(e){

       //There was an error querying the server.

       return("");

    }

            

    var FullPath;

        

    //Just in case something went wrong, check to see that you have a folder.

    if (Result.Count > 0)

    {

        

        //The number of parent folders.

        var NumFolders;

        NumFolders = Result.Item(1).Properties.Item("SI_PATH").Properties.Item("SI_NUM_FOLDERS");

            

        //The HomeLink variable is used to prefix the complete path with a link to the root folder.

        HomeLink = "<A HRef='Home.csp?FolderID=0' Target='_top'>Home</A>";

            

        //The full path must at least include the folder you are in.

        var CurrentName;

        CurrentName = Server.HTMLEncode(Result.Item(1).Title);

            

        //This variable represents the current folder.

        var CurrentFolder;

        CurrentFolder = "<A HRef='Home.csp?FolderID="+FolderID+ "' Target='_top'>" + CurrentName + "</A>";

        FullPath = HomeLink + " / " + CurrentFolder;


        if (NumFolders > 0)

        {

            var k, ParentID, ParentName;


            //This loop retrieves all the current folders' parent folders and concatenates them into

            //a complete path of hyperlinks to each of the folders.

            FullPath = "";

                        

            for (k = 1;k <= NumFolders;k++)

            {

                //Retrieve the parent's ID.

                ParentId = Result.Item(1).Properties.Item("SI_PATH").Properties.Item("SI_FOLDER_ID" + k);

                                

                //Retrieve the parent's name.

                ParentName = Result.Item(1).Properties.Item("SI_PATH").Properties.Item("SI_FOLDER_NAME" + k);

                ParentName = Server.HTMLEncode(ParentName);

                FullPath = "<A HRef='Home.csp?FolderID=" + ParentId + "' Target='_top'>" +

                ParentName +   "</A>" + " / " + FullPath;

                            

            }

                        

            //Now that you have a complete path of the parent folders to the current folder,

            //create the full path prefixed with the home link and suffixed with the current folder link.

                        

            FullPath = HomeLink + " / " + FullPath + CurrentFolder;

            return(FullPath);

        }    

    } else return("");

        

    return( FullPath );

}

function RedirectWithFrames(URL)

{

    Response.Write ("<script language=javascript>open (\""+URL+"\",\"_top\");</script>");

}

var IStore;

var CurrentFolderID;

var Success;


//Retrieve the CurrentFolderID from the file's parameter list.

CurrentFolderID = Request.QueryString.Item("FolderID");


Response.Write ("<TABLE Width='100%'><TR>");

IStore=RetrieveIStore();

//Try to retrieve the InfoStore object.

if (IStore==null)

    //If it failed, redirect the user to the logon page.

    RedirectWithFrames("LogonForm.csp");

else

{

    var FolderPath;

    FolderPath= RetrieveFullPath(CurrentFolderID, IStore,Success);

    if (Success != "")

        Response.Write ("<TD>" + FolderPath + "</TD>");

    else

        Response.Write ("There was an error trying to retrieve the full path of the folder.");

}

    

    //Write the link to the search page.

    Response.Write ("<TD Align='right'><A HRef='SearchForm.csp' Target='Main'>Search</A></TD></TR>");

    Response.Write ("<TR><TD></TD><TD Align='right'><A href='Logoff.csp' Target='_top'>Logoff</A></TD></TR></TABLE>");

    


%>

</BODY>

</HTML>



Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com