RSP [examples]

Return the value of a parameter passed to a .rsp script or return an alternative value if the parameter was not passed
GETPARAMETER
// WebView URL Attribute
quickreport.rsp?database=southwind&table=example&fields=*&heading=Client List (all)&columns=2,4,3,5,6,7,8,9,10,11,12&subtotals=9,10,11&gridlines=true
 
//--
// quickreport.rsp?parameter=value&parameter=value...
//
// parameters 
//--
private database   = getParameter("database", "southwind") 
private table      = getParameter("table", "example") 
private fields     = getParameter("fields", "*") 
private groupby    = getParameter("groupby", "") 
private heading    = getParameter("heading", "Report for all clients by state") 
private headings   = getParameter("headings", "") 
private filter     = getParameter("filter", "") 
private hyperlink  = getParameter("hyperlink", "") 
private columns    = getParameter("columns", "") 
private subtotals  = getParameter("subtotals", "") 
private gridlines  = getParameter("gridlines", "")
// ...

https://www.lianja.com/doc/index.php/GETPARAMETER()


Execute an rsp script
EXECRSP
execRSP("test.rsp?customerid=alfki")

test.rsp

<%@ Language=VFP %>
<%
    local m_customerID = getParameter("customerID", "")
    local m_tempfile = tmpnam()
    if database() <> "southwind"
        open database southwind
    endif
    set strcompare on  // perform autotrim and case insensitive string comparisons in queries 
    select * from customers where customerid=m_customerid into cursor temp
    select temp
    copy to &m_tempfile type csv
    type &m_tempfile
    erase &m_tempfile
%>

https://www.lianja.com/doc/index.php/EXECRSP()


Return the value of a session variable in a .rsp script or return an alternative value if the variable does not exist
GETSESSIONVAR
ss=len(_SESSION)
if ss > 0
	? "Active session variables ("+alltrim(str(ss))+")"
	foreach _session as name=>value 
		? "<br>    &name="+etos(value)
		next
else
	? "There are no active session variables."
endif
 
?"<br>"
? "start_time = " + getsessionvar("start_time",time())
?"<br>"

https://www.lianja.com/doc/index.php/GETSESSIONVAR()


example_cookies.rsp

This Visual FoxPro Server Page (.rsp) demonstrates querying of the _SERVER[], _SESSION[] and _COOKIE global associative arrays.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - accessing cookies</title>
</head>
<body>
<%
  // Get the hostname for the remote machine requesting the page
  ? "_server[ ] elements"
  foreach _server as name=>value 
    ? "<br>   &name="+etos(value)
  next
  ? "<br><br>"
  ? date()
  ? time()
  ? "<br><br>"
 
  cc=len(_COOKIE)
  if cc > 0
	? "Active session Cookies ("+alltrim(str(cc))+")"
	foreach _cookie as name=>value 
		? "<br>   &name="+etos(value)
	endfor
  else
	? "There are no active session cookies."
  endif
  ? "<br><br>"
 
  ss=len(_SESSION)
  if ss > 0
	? "Active session variables ("+alltrim(str(ss))+")"
	foreach _session as name=>value 
		? "<br>   &name="+etos(value)
	next
  else
	? "There are no active session variables."
  endif
 
  ? "<br><br>Press the browser refresh key."
  _session["time"] = time()
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Cookies_rsp

https://www.lianja.com/doc/index.php/Example_cookies_rsp


example_authentication.rsp

This Visual FoxPro Server Page (.rsp) demonstrates how to use the response object authenticate() method for user authentication.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - authentication</title>
</head>
<body>
<%
  if len(_SERVER["AUTH_TYPE"]) = 0 .or. len(_SERVER["REMOTE_USER"]) = 0 .or. len(_SERVER["REMOTE_PASSWORD"]) = 0
	response.Authenticate()
  endif
  ? "Hi " + proper(_SERVER["REMOTE_USER"]) + ", You have authenticated successfully."
  ? '<br>'
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Authentication_rsp

https://www.lianja.com/doc/index.php/Example_authentication_rsp


example_imagequery.rsp

This Visual FoxPro Server Page (.rsp) demonstrates the use of the base64_encode_file() function to generate the base64 encoded contents of an object field image as an IMG tag and output it into the HTML5.

<%@ Language=VFP %>
<html>
<head>
</head>
<body>
<%
  ? "<table width='80%' align=center cellpadding=12>"
  ? "<tr>"
  ? "<td align=center colspan=2>"
  ? "<h1>Lianja example - image queries</h1>"
  ? '<p>Customize this to suit your own needs. This is a just an example.<p>'
  ? '<hr size="1px" color="lightgray"/>'
  ? "</td>"
  ? "</tr>"
  ? "<tr>"
  ? "<td colspan=2>"
  ? "<h3>Employees</h3>"
  ? "</td>"
  ? "</tr>"
 
  // scan through the employees table
  open database southwind
  use employees
  scan
	? "<tr>"
	? "<td>"
	m_tmpnam = tmpnam()
	objectwrite(m_tmpnam,photo)
	base64_encode_file(m_tmpnam, objectType(photo), "200px", "200px")
	erase &m_tmpnam
	? "</td>"
	? "<td>"
	? mtos(notes) + "<a href='../odata/southwind/orders("+etos(employeeid)+",employeeid)'> JSON download of orders for ";
          + trim(firstname) + " " + lastname + "</a>"
	? "</td>"
	? "<tr>"
	? '<td colspan="2">'
	? '<hr size="1px" color="lightgray"/>'
	? "</td>"
	? "</tr>"
	? "</tr>"
  endscan
  close data
 
  ? "<tr>"
  ? "<td align=center colspan=2>"
  ? "<p>Copyright © 2013 Lianja Inc. All rights reserved worldwide.</p>"
  ? "<h3><a href 'http://www.lianja.com'> www.lianja.com</a></h3>"
  ? "</td>"
  ? "</tr>"
  ? "</table>"
%>
</body>
</html>

 

https://www.lianja.com/doc/index.php/Example_imagequery_rsp https://www.lianja.com/doc/index.php/Imagequery_rsp


 

example_datanavigation.rsp Example Visual FoxPro Server Page (.rsp) demonstrating basic data navigation.

<%@ Language=VFP %>
<html>
<body>
<%
    // Open the database
    open database southwind
    ? "<br>"
 
    // Open the table
    use customers
 
%>
<table>
<tr>
<%
     // Display the table headings
    for i = 1 to fcount()
        ? "<td>" + field(i) + "</td>"
    next
%>
</tr>
<%
    // Display the data in a table
    scan
        ? "<tr valign='top'>"
        for i = 1 to fcount()
            ? "<td>"
            ? &(field(i))
            ? "</td>"	
        next
        ? "</tr>"
    endscan
    // close the table and the database
    use
    close database
%>
</table>
</body>
</html>

 

https://www.lianja.com/doc/index.php/Example_rsp https://www.lianja.com/doc/index.php/Example_datanavigation_rsp


example_redirection.rsp This Visual FoxPro Server Page (.rsp) demonstrates the use of the response object redirect() method for URL redirection.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - redirection</title>
</head>
<body>
<%
	response.redirect("/default.rsp")
%>
</body>

https://www.lianja.com/doc/index.php/Example_redirection_rsp


pfooter.rsp

This Visual FoxPro Server Page (.rsp) is a Page Footer gadget example. See Page Footers for more information.

<%@ Language=VFP %>
<html>
<head>
<style>
table, td, th {
    border: 1px solid black;
}
table {
    border-collapse: collapse;
    width: 100%;
}
td {
    text-align: center;
}
</style>
</head>
<body>
<%
	private m_count = 0
	private m_total = 0
	private m_min = 0
	private m_max = 0
	private m_ordertotal = 0
	private m_linetotal = 0
 
	save recordview
 
	if used("orders") and used("customers")
		select orders
		seek customers.customerid
		scan while customerid = customers.customerid
			++m_count
			select order_details
			seek orders.orderid
			m_ordertotal = 0
			m_linetotal = 0
			scan while orderid = orders.orderid
				m_linetotal = (order_details.unitprice*order_details.quantity) - order_details.discount
				m_ordertotal = m_ordertotal + m_linetotal
			endscan
			if m_min = 0 or m_min > m_ordertotal
				m_min = m_ordertotal
			endif
			if m_max = 0 or m_max < m_ordertotal
				m_max = m_ordertotal
			endif
			m_total = m_total + m_ordertotal
		endscan
	endif
 
	m_min = currency(m_min)
	m_max = currency(m_max)
	m_total = currency(m_total)
 
	restore recordview
 
	text raw 
	<table>
	<tr>
	<th>
    <font color=darkgray>Total Orders</font>
	</th>
	<th>
	<font color=darkgray>Min Order Value</font>
	</th>
	<th>
	<font color=darkgray>Max Order Value</font>
	</th>
	<th>
	<font color=darkgray>Total Order Value</font>
	</th>
	</tr>
	<tr>
	<td>
	<font color=gray>&m_count</font>
	</td>
	<td>
    <font color=gray>&m_min</font>
	</td>
	<td>
    <font color=gray>&m_max</font>
	</td>
	<td>
    <font color=gray>&m_total</font>
	</td>
	</tr>
	</table>
	</body>
	endtext
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Pfooter.rsp


Advertisements
Categories RSP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.