<?php
include_once "class_pagelogic.php";
//====== LOGIC CONTROLLER ========================
// in-line data, so read itself with state 0
// onlu data embeded between PARSERSTART and PARSEREND pair is read
// to read external data file, $page=PAGELOGIC(filename)
$page = new PAGELOGIC(__FILE__, 0);
// preset some variables
// this is used to replace the {} fields in the HTML template
$HTML_HOME=$HTTP_SERVER_VARS['PHP_SELF']."?".strftime("%H%M%S");
$page->SetItem("DATA.local", "HTML_HOME", $HTML_HOME);
$page->SetItem("DATA.local", "STYLE", "style='background: lightblue; width: 100%'");
// Extract the action value, typicall for form use HTTP_POST_VARS
// For index.html?action='abc', use $action=$HTTP_POST_VARS['action']
$action = $HTTP_POST_VARS['action'];
echo "<h6>ACTION: [$action]</h6>";
// ##### CALL OUT FORM LOGIC
// Dependence on the category FORM.action in sample_main.dat,
// the $action value determine which function to call and also
// which web page to include.
DisplayBanner();
$page->FormLogic('HTML.logic', $action);
DisplayFooter();
// debug
foreach ( $HTTP_POST_VARS as $key => $value )
echo "<H6>$key: [$value]</H6>";
return;
/* THIS IS THE MODULE LOGIC, ALL FUNCTIONS IS WITHIN THIS FILE
PARSERSTART
[HTML.logic]
; if the DisplayMain() routine is in another file, use this:
; DEFAULT=DisplayMain, <file1> [, file2, file 3 ...]
; the file will be include_once before the function is executed.
; DEFAULT function will be called if there is no match
DEFAULT=DisplayMain
EDIT=EditPage
PROC=ProcPage
PARSEREND
*/
//====== SUPPORTING FUNCTION ========================
function DisplayMain()
{ global $page;
global $HTTP_SERVER_VARS;
// Display Header
DisplayHeader("HOME PAGE");
// Prepare a form for submision to itself
$page->CreateForm('FORM_MAIN', $HTML_HOME, 'POST');
$page->AddFormItem('FORM_MAIN',"action", "");
$page->AddFormItem('FORM_MAIN',"rec_no", "");
// add a javascript which set up to variable action and rec_no
// to use it: javascript:DEMO2('EDIT', 3) will set action to EDIT
// and rec_no to 3
$page->CreateJSScript('FORM_MAIN',"DEMO2", array('action', 'rec_no'));
// generate the js routines and the form statement
// if you want to add more fields to your form
// issue it with GenHiddenForm(form_name, PLOGIC_OPENFORM);
echo $page->GenHiddenForm('FORM_MAIN');
// Display Content
$page->UpdateCat("HTML.home", "FORM_MAIN");
echo $page->GetCatStr("HTML.home");
}
/* HTML home template
PARSERSTART
[HTML.home, FREE]
;This is the HTML template, note that the category is HTML.home and
;it is of FREE format, ie not <index>=<value> but line by line type.
<TABLE BORDER=1 WIDTH=80% ALIGN=CENTER>
<TR><TD><A HREF="javascript:DEMO2('EDIT', 1);">Edit Record 1</A>
<TR><TD><A HREF="javascript:DEMO2('EDIT', 2);">Edit Record 2</A>
<TR><TD><A HREF="javascript:DEMO2('EDIT', 3);">Edit Record 3</A>
</TABLE>
PARSEREND
*/
function EditPage()
{ global $page;
global $HTTP_SERVER_VARS;
global $HTTP_POST_VARS;
//----- DATA PREPARATION
// create hidden form
$page->CreateForm('FORM_MAIN', "", 'POST');
$page->AddFormItem('FORM_MAIN',"action", "");
$page->AddFormItem('FORM_MAIN',"rec_no", "");
$page->AddFormItem('FORM_MAIN',"rec_data", "");
$page->CreateJSScript('FORM_MAIN',"SUBMIT", array('action'));
echo $page->GenHiddenForm('FORM_MAIN', PLOGIC_OPEN);
// Get record data
$rec_no = $HTTP_POST_VARS['rec_no'];
$page->SetItem("DATA.local", "REC_NO", $rec_no);
$rec_data = "[$rec_no] GENERATE YOUR DATA HERE";
$page->SetItem("DATA.local", "REC_DATA", $rec_data);
// replace the keyword in the HTML template
$page->UpdateCat("HTML.edit", "DATA.local");
//----- HTML GENERATION
// Display Header
DisplayHeader("EDIT");
// Display Content
echo $page->GetCatStr("HTML.edit");
}
/* HTML EDIT PAGE TEMPLATE
PARSERSTART
[HTML.edit, FREE]
<INPUT TYPE=HIDDEN NAME=rec_no VALUE='{REC_NO}'>
<TABLE BORDER=1 WIDTH=80% ALIGN=CENTER>
<TR><TD COLSPAN=2 BGCOLOR=LIGHTGREEN><B>Edit Record No: {REC_NO}</B>
<TR><TD>DATA<TD><INPUT NAME=REC_DATA VALUE='{REC_DATA}'>
<TR><TD COLSPAN=2>
<INPUT TYPE=SUBMIT VALUE="SUBMIT" ONCLICK='SUBMIT("PROC");'>
<INPUT TYPE=RESET VALUE="RESET">
<INPUT TYPE=SUBMIT VALUE="CANCEL" ONCLICK='SUBMIT("");'>
</TABLE>
</FORM>
PARSEREND
*/
function ProcPage()
{ global $page;
global $HTTP_POST_VARS;
DisplayHeader("Process Record");
//==== validation
$rec_no = $HTTP_POST_VARS['rec_no'];
echo "<B>You have enter data for record: [$rec_no]</B><BR>\n";
$rec_data = $HTTP_POST_VARS['REC_DATA'];
echo "<B>the data is: [ $rec_data ]</B><BR><HR>\n";
//==== Generate hidden form to jump back
$method = 1;
echo "<script>alert('Press any key to continue');
location='".$page->item["DATA.local"]["HTML_HOME"]."';";
echo "</script>";
}
function DisplayHeader($title)
{
global $page;
$page->SetItem("DATA.local", "TITLE", $title);
$page->SetItem("DATA.local", "TIME", strftime("%d %b %y %H:%M"));
$page->UpdateCat("HTML.header", "DATA.local");
echo $page->GetCatStr("HTML.header");
}
/* HTML Header Template
PARSERSTART
[HTML.header, FREE]
; Note that {TITLE} and {TIME} value is to be replaced by
; actual values from another category using UpdateCat()
<H2>{TITLE}</H2></DIV>
<H6>{TIME}</H6>
<BR>
PARSEREND
*/
function DisplayBanner()
{
global $page;
$page->UpdateCat("HTML.banner", "DATA.local");
echo $page->GetCatStr("HTML.banner");
}
/* HTML Banner Template
PARSERSTART
[HTML.banner, FREE]
<DIV {STYLE}><H1><CENTER>PAGELOGIC DEMO</center></H1></DIV>
PARSEREND
*/
function DisplayFooter()
{
global $page;
$page->UpdateCat("HTML.footer", "DATA.local");
echo $page->GetCatStr("HTML.footer");
}
/* HTML Footer Template
PARSERSTART
[HTML.footer, FREE]
<BR>
<DIV {STYLE} ALIGN=CENTER PADDING=0><H6>Page Logic Demo Footer</H6></DIV>
<BR>
PARSEREND
*/
?>
|