Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

csp files accessable via remote Web Browser Crystal XI

Status
Not open for further replies.

kamal7777ahmed

Programmer
Jul 12, 2005
6
US
I have 2 csp files (see below) which are accessable via a remote Web Browser (e.g. IE, Firefox) in Crystal 9. How can we make the same work in Crystal XI . The URL we used to access reports are: and The IP addresses and machine names are the names of the Crystal Server Hosts. Thanks, -Kamal.

GetReports.csp

<%@ language=JavaScript %>

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

<%

/**
*
*
* Description: Establish a session with Crystal server, and get the
* reporting structure.
*
*
*/


/**
* URL parameters
*
* *
* APS=devwin003
*
* user=Guest or Administrator
* password=
*
* tab
* &tab=Advisor - Generates only Advisor reports.
* &tab=Analysis - Generates only Analysis reports.
* <no argument> - Generates only Analysis reports.
*
*/

/**
* Global variables
*/
var xxx = 0;
var g_debugMode = false;
var g_reportingroot = "";
var g_tab = "";

var g_apstokens = "A1B2";
var g_apsuser = "Guest";
var g_apspassword = "";
var g_apsauthtype = "secEnterprise";
var g_cmd = "get_pg";
var g_viewer = "html_frame";
var g_incomplete_page_count = "1";
var g_page = "1";
var b_brch = "";
var g_urlbase = "
/**
* Emit an XML string.
* If not in debug mode, output the XML string specified.
*
* @param str : string to be output.
*
* @return no return -- side effect : output results in HTML format
*/
function emitXML(str)
{
if (!g_debugMode)
{
Response.write(str);
}
}

/**
* Emit an XML parameter string.
*
* @param name : name
* @param value : value
*
* @return no return -- side effect : output results in HTML format
*/
function emitXMLParameter(name,value)
{
emitXML("<parameter ");
emitXML(" name = ");
emitXML("\"");
emitXML(name);
emitXML("\"");
emitXML(" value = ");
emitXML("\"");
emitXML(value);
emitXML("\"");
emitXML("/>");
}

/**
* Emit an HTML string.
* If in debug mode, output the HTML string specified.
*
* @param str : string to be output.
*
* @return no return -- side effect : output results in HTML format
*/
function emitHTML(str)
{
if (g_debugMode)
{
var spaces = xxx*4;
for (var k = 1; k <= spaces; k++)
{
Response.write("&nbsp");
}
Response.write (str);
}
}


/**
* The purpose of this function is to ask crystal reports
* for all of its folders and reports.
*
* @param session : a valid logged-in crystal enterprise session
* @param parent : numeric identifier for the folder (0 for root)
*
* @return no return -- side effect : output results in HTML format
*/
function GetContents(session, parent)
{
//Get the category name, like "Advisor".
var CategoryName = parent.ID;
emitHTML("<br>CategoryName = "+","+parent + ")");

var IStore;
var LogonTokenMgr;

// Create the InfoStore object
if (typeof(session) != "object") return;
IStore = session.Service ("", "InfoStore");

// Store the INfoStore objec tin the session using the helper functions.
SetSession("IStore", IStore);

// Retrieve the LogonTokenManager.
LogonTokenMgr = session.LogonTokenMgr;

// Retrieve a Logon Token and store it in the user's cookie file for later use.
SetCookie("LogonToken", LogonTokenMgr.CreateLogonToken("", 1, 1000));

emitHTML("<br>GetContents(session, "+","+parent + ")");
emitHTML("<br>parent = " + parent);
emitHTML("<br>");

//Retrieve the IStore object
RetrieveIStore();

//Check if it is the Home folder with an ID of 0
if (parent == 0)
{
parentFolderName = 'Home';
Query = "Select SI_NAME From CI_INFOOBJECTS Where SI_PROGID = '" + g_reportingroot + ".Folder'";
}
else
{
Query = 'Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_PARENTID = ' + parent;
}

var children = IStore.Query(Query);
emitHTML("Query = " + Query);
emitHTML("<br>");
emitHTML("Found " + children.count + " children.<br>")

//Check if there are any children.
if (children.count > 0)
{
var childName = "";
var childID = "";
var subQuery = "";
for (var k = 1; k <= children.count; k++)
{
childName = String(children.Item(k).Properties.Item('SI_NAME'));

//If we're looking for Advisor reports, and the childName is "Advisor",
//do the report, otherwise bail out.
emitHTML("childName " + childName + " <br>")

var bDoReport = false;

if ((String(g_tab) == "Advisor") && (childName.substring(0,7)=="Advisor"))
{
bDoReport = true;

if ( childName=="Advisor" )
{
// do recursive call
GetContents(session,children.Item(k).ID);

// but don't display this "parent" node
bDoReport = false;
}


}

if ((String(g_tab) != "Advisor") && (childName.substring(0,7)!="Advisor"))
{
bDoReport = true;
if ( childName=="Root Folder" )
{
bDoReport = false;
}

if ( childName=="Report Samples" )
{
bDoReport = false;
}
if ( childName=="eSecurity" )
{
bDoReport = false;
}
}

//Skip these categories. Syntax error found within.
if (childName.substring(0,6)=="Securi")
{
//bDoReport = false;
}

if (bDoReport)
{
childID = children.Item(k).ID;
var tagName = "report";
subQuery = 'Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_PARENTID = ' + childID;

var subChildren = IStore.Query(subQuery);
if (subChildren.count > 0)
{
tagName = "category";
}

emitHTML("subQuery = " + subQuery);
emitHTML("<br>");
emitHTML("Found " + subChildren.count + " subChildren.<br>")

emitXML("<" + tagName + " name = " + "\"" + childName + "\"");
emitXML(" urlbase=" + "\"" + g_urlbase + "\"" +" urlfile=" + "\"" +"viewrpt.cwr" + "\"" + ">");

///////////////////////////////////////////////////////////////////////
//Put report parameters here.
emitXML("<parameters>");
emitXMLParameter("id",childID);
emitXMLParameter("apstokens",g_apstokens);
emitXMLParameter("apsuser",g_apsuser);
emitXMLParameter("apsauthtype",g_apsauthtype);
emitXMLParameter("cmd",g_cmd);
emitXMLParameter("init",g_viewer);
emitXMLParameter("incomplete_page_count",g_incomplete_page_count);
emitXMLParameter("page",g_page);
emitXMLParameter("brch",b_brch);
emitXML("</parameters>");
///////////////////////////////////////////////////////////////////////

//emitHTML("<br>k = " + k);

var folderName = String(children.Item(k).Properties.Item('SI_NAME'));
var folderID = children.Item(k).ID;

//the name of the folder is a link to its subfolders
emitHTML("<br><b>Folder </b>" + folderName + "<br>" );
emitHTML("children.Item(k).ID = " + folderID + "<br>");
emitHTML("Properties.Item('SI_NAME') = " + children.Item(k).Properties.Item('SI_NAME') + "<br>");
emitHTML("HEADER: " + tagName + " name = " + "\"" + childName + "\"<BR>");
emitHTML(" urlbase=" + "\"" + g_urlbase + "\"" +" urlfile=" + "\"" +"viewrpt.cwr" + "\"" + "<BR>");
emitHTML("<parameters><br>");
emitHTML("id = "+childID + "<br>");
emitHTML("apstokens = "+g_apstokens + "<br>");
emitHTML("apsuser = "+g_apsuser + "<br>");
emitHTML("apsauthtype = "+g_apsauthtype + "<br>");
emitHTML("cmd = "+g_cmd + "<br>");
emitHTML("init = "+g_viewer + "<br>");
emitHTML("incomplete_page_count = "+g_incomplete_page_count + "<br>");
emitHTML("page = "+g_page + "<br>");
emitHTML("brch = "+b_brch + "<br>");
emitHTML("</parameters><br>");

var substring = folderName.substr(0,7);

if (substring == "Advisor")
{
emitHTML("<br>YES");
}
else
{
emitHTML("<br>NO");
}
//Recursive call.
//emitHTML("<br>k = " + k);
emitHTML("<br>Attempting recursive call to GetContents("+folderName+","+folderID+ ")");

emitHTML("<br>xxx = " + ++xxx);

x = GetContents(session,children.Item(k).ID);
emitHTML("<br>Completed recursive call to GetContents() with return value "+x);
emitHTML("<br>xxx = " + xxx--);

emitXML("</" + tagName + ">");
}
}
emitHTML("<br>");
}

else
{
emitHTML("<br>No folders found");
}

return 1;
}

function emitHistoricalEvents()
{
emitXML("<category name = \"Historical Events\">")
emitXML("<report name=\"Quick Query\" urlbase= \"class://com.eSecurity.GuiWlements.EventHistoricalQueryTable\"/>");
emitXML("</category>");
}

/**
* Establish a session with Crystal server, and get the reporting structure.
*
*
* @return no return -- side effect : output results in HTML format
*/
function Main(reportingRoot)
{
g_reportingroot = reportingRoot;

if (g_debugMode)
{
Response.ContentType="text/HTML";
}

emitXML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
emitXML("<reports>");

//emitHistoricalEvents();

//Create session and session manager objects.
var g_session_manager;
var g_session;

Response.Expires = 0;

try
{
emitHTML("Making SessionManager<br>");
g_session_manager = Server.CreateObject(g_reportingroot+".SessionMgr");
emitHTML("Done Making SessionManager<br>");

/*
* Log the user onto Crystal Enterprise
*/
var UserID, Password, APS;

/*
* Get the parameters from the URL, which typically looks like
* */
APS = Request.QueryString.Item('aps');
emitHTML("APS parameter received " + APS + "<br>");
UserID = Request.QueryString.Item('user');

g_tab = String(Request.QueryString.Item('tab'));
emitHTML("tab parameter received " + g_tab + "<br>");

//Set the global user ID to the one passed in.
g_apsuser = UserID;

emitHTML("APS parameter received " + UserID + "<br>");
Password = Request.QueryString.Item('password');
emitHTML("APS parameter received " + Password + "<br>");

//Append APS to urlbase which is " + "devwin003" + "/"
g_urlbase = g_urlbase + APS + "/";
emitHTML("urlbase = " + g_urlbase + "<br>");

emitHTML("Performing logon with <br>");
emitHTML("UserID : " + UserID + "<br>");
emitHTML("Password : " + Password + "<br>");
emitHTML("APS : " + APS + "<br>");

g_session = g_session_manager.Logon(UserID, Password, APS, g_apsauthtype);
emitHTML("Completed logon<br>");
}
catch(e)
{
emitHTML(e.description);
/*
* Not able to grab a valid logged in session...
*/
emitHTML ("<SCRIPT language=\"javascript\"> " + " alert (\"Sorry = you could not be logged on to this server. Ensure that your user name and password, as well as the APS name are correct. " + "\");window.close();</script>");
// Redirect the user back to the logon page.
//emitHTML ("<META HTTP-EQUIV='refresh' CONTENT='0;URL=index.html'");
return;
}

//emitXML("<category name = " + "\"" + g_reportingroot + "\"" + ">");
//x = GetContents(g_session, 166, g_reportingroot);
x = GetContents(g_session, 0, g_reportingroot);
//emitXML("</category>");

//Test with the User Folder.
//x = GetContents("User children",18);

emitHTML("<br>Completed base call to GetContents() with return value "+x);

emitXML("</reports>");
emitHTML("<hr>All done");
}

Main("CrystalEnterprise");

%>
---------------------------------------
File = GetInfoStore.csp
------------------------------------------

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

<%

/**
*
*
* File: GetInfoStore.csp
*
* Description: Returns the InfoStore object that allows us to query the server
*
************************************************************
*
*/


function RetrieveIStore()
{ /*
Precondition:
None
Postcondition:
Returns the InfoStore object that allows us to query the server
The function returns null if it did not succeed. */

var LogonToken;
var SessionManager;
var Sess;
// Try and retrieve the cookie
LogonToken = GetCookie("LogonToken")

// Check to see if we really do have a logon token
if( LogonToken != "" )
{
// Check to see if the InfoStore already exists
if( typeof(Session.Value("IStore").Item) != "object" )
{
// Create a session manager
SessionManager = Server.CreateObject("CrystalEnterprise.SessionMgr");

// Logon using the token. This will fail if the token is no longer valid.
Sess = SessionManager.LogonWithToken(LogonToken);

// Create the InfoStore object.
IStore = Sess.Service("", "InfoStore");

// Save the InfoStore in the session
SetSession("IStore", IStore);
return (IStore);
}
else
{
// The InfoStore already exist so simply retrieve it from the session.
IStore = GetSession("IStore")
return(IStore);
}
}
else return(null);
}
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top