MaxObject for action with user confirmation


This example shows a MaxObject that ask confirmation before to take an action: in this case is voiding a table (zap).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!--
This example shows how to zap (void) a table.
It expects two parameters:
VAR_SETDB - the DB set to use
VAR_TABLE - the table to zap
In real use you should also care about indexes associated with the table
//-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-STORE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">
<link rel="stylesheet" type="text/css" href="/screen.css">
<link rel="shortcut icon" href="/favicon.ico">
<script type="text/javascript" src="/js/dbfree50.js"></script>
<title>Zap with confirmation Example</title>
</head>

<%
**************************************** DBFree 2-22-MINI-HEADER
zcRoot := strTran(getenv("DOCUMENT_ROOT"),"/","\")
if "IIS" $ getenv("SERVER_SOFTWARE")
   p1 := strTran(getenv("PATH_TRANSLATED"),"/","\")
   p2 := strTran(getenv("SCRIPT_NAME"),"/","\")
   zcRoot := strTran(p1,p2,"")
endif
zcLib := strTran(zcRoot,"/","\")+"\lib\free2.max"
set maxlib to &zcLib
freeslot()
CR_LF := chr(13)+chr(10)
**************************************** DBFree 2-22-MINI-HEADER
set decimals to 0
set century on
set hour to 24
cSelf := pageName()

*--- (the name of the table to zap)
cSetDb := MSPFieldValue("VAR_SETDB")
if empty(cSetDb)
   cDbPath := setDb("demo")
else
   cDbPath := setDb(cSetDb)
endif
cTable := MSPFieldValue("VAR_TABLE")
if empty(cTable)
   ? "Warning: this page needs at least the parameter VAR_TABLE="
   return
endif
cDb  := cDbPath + cTable
xParm:= "VAR_SETDB=" + cSetDb +"&VAR_TABLE=" + cTable

*--- confirmation form incoming parameter (the confirmation)
cConfirm := MSPFieldValue("PB_SUBMIT")
%>
<body>
<p><font size="1"><font color="#0000FF"> </font><a href="/index.msp"><font color="#0000FF">Home</font></a><font color="#0000FF">
-> </font><a href="/examples/index.htm"><font color="#0000FF">Examples</font></a><font color="#0000FF">
-> </font></font><a href="/examples/basics/index.htm"><font size="1" color="#0000FF">
Basics</font></a><br>
<font size="4"><b>Confirm</b></font> before to proceed<hr>
Incoming parameter is: [<%=cConfirm%>]<hr>
<%
do case
*-------------------------------
case empty(cConfirm)
*-------------------------------
%>

<form name="form1" action="<%=cSelf%>" method="post" style="form1">
<font color="#FF0000">You are about to erase all records contained into table </font><b>
<%=upper(cTable)%></b> <br>
Do you confirm this action?
<input type="submit" name="PB_SUBMIT" value="YES">
<input type="submit" name="PB_SUBMIT" value="No">
<hr>
These values would normally be hidden<br>
<input type="text" name="VAR_SETDB" value="
<%=cSetDb%>">
<input type="text" name="VAR_TABLE" value="
<%=cTable%>">
</form>

<%
*-------------------------------
case cConfirm="YES"
*-------------------------------
use (cDb) excl
if used()
   zap
endif
close data
%>
<p><b>All records from sample table <font color="#FF0000">[<%=cTable%>]</font> have been erased!</b>
<p><a target="_self" href="do_append.msp?
<%=xParm%>">Add a new record now</a> </p>
<%
*-------------------------------
case cConfirm="N"
*-------------------------------
%>
<h3>Ok!</h3>
Nothing done.
<a href="
<%=cSelf%>">Try again</a>
<%
*-------------------------------
endcase
*-------------------------------
%>
</body>
</html>