wanaka
|
| Posted: 04/15/2003, 8:41 PM |
|
I finally get it work under the record form but there is one more problem here if I edit the current record...the selected item still won't change at all.
How could I overwrite the selected item when the form is in update mode
<?php
/*********************************************************************************
* Filename: form_device.php
* Generated with CodeCharge 2.0.5
* PHP 4.0 & Templates build 11/30/2001
*********************************************************************************/
//-------------------------------
// form_device CustomIncludes begin
include ("./common.php");
// form_device CustomIncludes end
//-------------------------------
session_start();
//===============================
// Save Page and File Name available into variables
//-------------------------------
$filename = "form_device.php";
$template_filename = "form_device.html";
//===============================
//===============================
// form_device PageSecurity begin
check_security(2);
// form_device PageSecurity end
//===============================
//===============================
// form_device Open Event begin
$fldmodel ="6";
$fldmanufacturer ="1";
$fldequipment_series="1";
// form_device Open Event end
//===============================
//===============================
// form_device OpenAnyPage Event start
// form_device OpenAnyPage Event end
//===============================
//===============================
//Save the name of the form and type of action into the variables
//-------------------------------
$sAction = get_param("FormAction");
$sForm = get_param("FormName");
//===============================
// form_device Show begin
//===============================
// Perform the form's action
//-------------------------------
// Initialize error variables
//-------------------------------
$sdeviceErr = "";
//-------------------------------
// Select the FormAction
//-------------------------------
switch ($sForm) {
case "device":
device_action($sAction);
break;
}
//===============================
//===============================
// Display page
//-------------------------------
// Load HTML template for this page
//-------------------------------
$tpl = new Template($app_path);
$tpl->load_file($template_filename, "main");
//-------------------------------
// Load HTML template of Header and Footer
//-------------------------------
//-------------------------------
$tpl->set_var("FileName", $filename);
//-------------------------------
// Step through each form
//-------------------------------
device_show();
//-------------------------------
// Process page templates
//-------------------------------
//-------------------------------
// Output the page to the browser
//-------------------------------
$tpl->pparse("main", false);
// form_device Show end
//===============================
// form_device Close Event begin
// form_device Close Event end
//===============================
//********************************************************************************
//===============================
// Action of the Record Form
//-------------------------------
function device_action($sAction)
{
//-------------------------------
// Initialize variables
//-------------------------------
global $db;
global $tpl;
global $sForm;
global $sdeviceErr;
$bExecSQL = true;
$sActionFileName = "";
$sWhere = "";
$bErr = false;
$pPKsid = "";
$fldpid = "";
$fldmanufacturer = "";
$fldequipment_series = "";
$fldmodel = "";
$fldhostname = "";
$fldserial_no = "";
$fldos_id = "";
$fldsl_id = "";
$fldlocation = "";
$fldrack_no = "";
$fldstate = "";
$flddevice_desc = "";
$fldlast_modify = "";
//-------------------------------
//-------------------------------
// device Action begin
//-------------------------------
$sActionFileName = "form_device.php";
//-------------------------------
// CANCEL action
//-------------------------------
if($sAction == "cancel")
{
//-------------------------------
// device BeforeCancel Event begin
// device BeforeCancel Event end
//-------------------------------
header("Location: " . $sActionFileName);
exit;
}
//-------------------------------
//-------------------------------
// Build WHERE statement
//-------------------------------
if($sAction == "update" || $sAction == "delete")
{
$pPKsid = get_param("PK_sid");
if( !strlen($pPKsid)) return;
$sWhere = "sid=" . tosql($pPKsid, "Number");
}
//-------------------------------
//-------------------------------
// Load all form fields into variables
//-------------------------------
$fldpid = get_param("pid");
$fldmanufacturer = get_param("manufacturer");
$fldequipment_series = get_param("equipment_series");
$fldmodel = get_param("model");
$fldhostname = get_param("hostname");
$fldserial_no = get_param("serial_no");
$fldos_id = get_param("os_id");
$fldsl_id = get_param("sl_id");
$fldlocation = get_param("location");
$fldrack_no = get_param("rack_no");
$fldstate = get_param("state");
$flddevice_desc = get_param("device_desc");
$fldlast_modify = get_param("last_modify");
//-------------------------------
// Validate fields
//-------------------------------
if($sAction == "insert" || $sAction == "update")
{
if(!is_number($fldpid))
$sdeviceErr .= "The value in field Project is incorrect.<br>";
if(!is_number($fldos_id))
$sdeviceErr .= "The value in field Operating System is incorrect.<br>";
if(!is_number($fldsl_id))
$sdeviceErr .= "The value in field Service Level is incorrect.<br>";
//-------------------------------
// device Check Event begin
// device Check Event end
//-------------------------------
if(strlen($sdeviceErr)) return;
}
//-------------------------------
//-------------------------------
// Create SQL statement
//-------------------------------
switch(strtolower($sAction))
{
case "insert":
//-------------------------------
// device Insert Event begin
// device Insert Event end
//-------------------------------
$sSQL = "insert into device (" .
"pid," .
"model_id," .
"hostname," .
"serial_no," .
"os_id," .
"sl_id," .
"location," .
"rack_no," .
"state," .
"device_desc," .
"last_modify)" .
" values (" .
tosql($fldpid, "Number") . "," .
tosql($fldmodel, "Number") . "," .
tosql($fldhostname, "Text") . "," .
tosql($fldserial_no, "Text") . "," .
tosql($fldos_id, "Number") . "," .
tosql($fldsl_id, "Number") . "," .
tosql($fldlocation, "Text") . "," .
tosql($fldrack_no, "Text") . "," .
tosql($fldstate, "Text") . "," .
tosql($flddevice_desc, "Text") . "," .
tosql(NOW, "Text") .
")";
break;
case "update":
//-------------------------------
// device Update Event begin
// device Update Event end
//-------------------------------
$sSQL = "update device set " .
"pid=" . tosql($fldpid, "Number") .
",model_id=" . tosql($fldmodel, "Number") .
",hostname=" . tosql($fldhostname, "Text") .
",serial_no=" . tosql($fldserial_no, "Text") .
",os_id=" . tosql($fldos_id, "Number") .
",sl_id=" . tosql($fldsl_id, "Number") .
",location=" . tosql($fldlocation, "Text") .
",rack_no=" . tosql($fldrack_no, "Text") .
",state=" . tosql($fldstate, "Text") .
",device_desc=" . tosql($flddevice_desc, "Text") .
",last_modify=NOW()";
$sSQL .= " where " . $sWhere;
break;
case "delete":
//-------------------------------
// device Delete Event begin
// device Delete Event end
//-------------------------------
$sSQL = "delete from view_device where " . $sWhere;
break;
}
//-------------------------------
//-------------------------------
// device BeforeExecute Event begin
// device BeforeExecute Event end
//-------------------------------
//-------------------------------
// Execute SQL statement
//-------------------------------
if(strlen($sdeviceErr)) return;
if($bExecSQL)
$db->query($sSQL);
header("Location: " . $sActionFileName);
exit;
//-------------------------------
// device Action end
//-------------------------------
}
//===============================
// Display Record Form
//-------------------------------
function device_show()
{
global $db;
global $tpl;
global $sAction;
global $sForm;
global $sdeviceErr;
$fldsid = "";
$fldpid = "";
$fldmanufacturer = "";
$fldequipment_series = "";
$fldmodel = "";
$fldhostname = "";
$fldserial_no = "";
$fldos_id = "";
$fldsl_id = "";
$fldlocation = "";
$fldrack_no = "";
$fldstate = "";
$flddevice_desc = "";
$fldlast_modify = "";
//-------------------------------
// device Show begin
//-------------------------------
$sFormTitle = "Add/Edit Device";
$sWhere = "";
$bPK = true;
//-------------------------------
// Load primary key and form parameters
//-------------------------------
if($sdeviceErr == "")
{
$psid = get_param("sid");
$tpl->set_var("deviceError", "");
}
else
{
$fldsid = strip(get_param("sid"));
$fldpid = strip(get_param("pid"));
$fldmanufacturer = strip(get_param("manufacturer"));
$fldequipment_series = strip(get_param("equipment_series"));
$fldmodel = strip(get_param("model_id"));
$fldhostname = strip(get_param("hostname"));
$fldserial_no = strip(get_param("serial_no"));
$fldos_id = strip(get_param("os_id"));
$fldsl_id = strip(get_param("sl_id"));
$fldlocation = strip(get_param("location"));
$fldrack_no = strip(get_param("rack_no"));
$fldstate = strip(get_param("state"));
$flddevice_desc = strip(get_param("device_desc"));
$fldlast_modify = strip(get_param("last_modify"));
$psid = get_param("PK_sid");
$tpl->set_var("sdeviceErr", $sdeviceErr);
$tpl->set_var("FormTitle", $sFormTitle);
$tpl->parse("deviceError", false);
}
//-------------------------------
//-------------------------------
// Load all form fields
//-------------------------------
//-------------------------------
// Build WHERE statement
//-------------------------------
if( !strlen($psid)) $bPK = false;
$sWhere .= "sid=" . tosql($psid, "Number");
$tpl->set_var("PK_sid", $psid);
//-------------------------------
//-------------------------------
// device Open Event begin
$db->query("select et_id,vendor_id,equipment_series from equipment_series");
while ($db->next_record()) {
$tpl->set_var("et_id",$db->f("et_id")."#".$db->f("vendor_id"));
$tpl->set_var("equipment_series",$db->f("equipment_series")."#".$db->f("et_id"));
$tpl->parse("cats",true);
}
$db->query("select model_id,et_id,model_no from model");
while ($db->next_record()) {
$tpl->set_var("model_id",$db->f("model_id")."#".$db->f("et_id"));
$tpl->set_var("model_no",$db->f("model_no")."#".$db->f("model_id"));
$tpl->parse("cats2",true);
}
// device Open Event end
//-------------------------------
$tpl->set_var("FormTitle", $sFormTitle);
//-------------------------------
// Build SQL statement and execute query
//-------------------------------
$sSQL = "select * from view_device where " . $sWhere;
// Execute SQL statement
$db->query($sSQL);
$bIsUpdateMode = ($bPK && !($sAction == "insert" && $sForm == "device") && $db->next_record());
//-------------------------------
//-------------------------------
// Load all fields into variables from recordset or input parameters
//-------------------------------
if($bIsUpdateMode)
{
$fldsid = $db->f("sid");
//-------------------------------
// Load data from recordset when form displayed first time
//-------------------------------
if($sdeviceErr == "")
{
$fldpid = $db->f("pid");
$fldmanufacturer = $db->f("vendor_id");
$fldequipment_series = $db->f("et_id");
$fldmodel = $db->f("model_id");
$fldhostname = $db->f("hostname");
$fldserial_no = $db->f("serial_no");
$fldos_id = $db->f("os_id");
$fldsl_id = $db->f("sl_id");
$fldlocation = $db->f("location");
$fldrack_no = $db->f("rack_no");
$fldstate = $db->f("state");
$flddevice_desc = $db->f("device_desc");
$fldlast_modify = $db->f("last_modify");
}
$tpl->set_var("deviceInsert", "");
$tpl->parse("deviceEdit", false);
//-------------------------------
// device ShowEdit Event begin
// device ShowEdit Event end
//-------------------------------
}
else
{
$tpl->set_var("deviceEdit", "");
$tpl->parse("deviceInsert", false);
//-------------------------------
// device ShowInsert Event begin
// device ShowInsert Event end
//-------------------------------
}
$tpl->parse("deviceCancel", false);
//-------------------------------
// device Show Event begin
// device Show Event end
//-------------------------------
//-------------------------------
// Show form field
//-------------------------------
$tpl->set_var("sid", tohtml($fldsid));
$tpl->set_var("deviceLBpid", "");
$lookup_pid = db_fill_array("select pid, project_name from project order by 2");
if(is_array($lookup_pid))
{
reset($lookup_pid);
while(list($key, $value) = each($lookup_pid))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldpid)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBpid", true);
}
}
$tpl->set_var("deviceLBmanufacturer", "");
$lookup_manufacturer = db_fill_array("select vendor_id, vendor_name from manufacturer order by 2");
if(is_array($lookup_manufacturer))
{
reset($lookup_manufacturer);
while(list($key, $value) = each($lookup_manufacturer))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldmanufacturer)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBmanufacturer", true);
}
}
$tpl->set_var("deviceLBequipment_series", "");
$lookup_equipment_series = db_fill_array("select equipment_series, equipment_series from equipment_series order by 2");
if(is_array($lookup_equipment_series))
{
reset($lookup_equipment_series);
while(list($key, $value) = each($lookup_equipment_series))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldequipment_series)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBequipment_series", true);
}
}
$tpl->set_var("deviceLBmodel", "");
$lookup_model = db_fill_array("select model_id, model_no from model order by 2");
if(is_array($lookup_model))
{
reset($lookup_model);
while(list($key, $value) = each($lookup_model))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldmodel)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBmodel", true);
}
}
$tpl->set_var("hostname", tohtml($fldhostname));
$tpl->set_var("serial_no", tohtml($fldserial_no));
$tpl->set_var("deviceLBos_id", "");
$lookup_os_id = db_fill_array("select os_id, os_version from os order by 2");
if(is_array($lookup_os_id))
{
reset($lookup_os_id);
while(list($key, $value) = each($lookup_os_id))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldos_id)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBos_id", true);
}
}
$tpl->set_var("deviceLBsl_id", "");
$lookup_sl_id = db_fill_array("select sl_id, service_level from service_level order by 2");
if(is_array($lookup_sl_id))
{
reset($lookup_sl_id);
while(list($key, $value) = each($lookup_sl_id))
{
$tpl->set_var("ID", $key);
$tpl->set_var("Value", $value);
if($key == $fldsl_id)
$tpl->set_var("Selected", "SELECTED" );
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBsl_id", true);
}
}
$tpl->set_var("deviceLBlocation", "");
$LOV = split(";", "E-ONTAP;E-ONTAP;EXPAN;EXPAN;KEPPEL;KEPPEL;");
if(sizeof($LOV)%2 != 0)
$array_length = sizeof($LOV) - 1;
else
$array_length = sizeof($LOV);
reset($LOV);
for($i = 0; $i < $array_length; $i = $i + 2)
{
$tpl->set_var("ID", $LOV[$i]);
$tpl->set_var("Value", $LOV[$i + 1]);
if($LOV[$i] == $fldlocation)
$tpl->set_var("Selected", "SELECTED");
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBlocation", true);
}
$tpl->set_var("rack_no", tohtml($fldrack_no));
$tpl->set_var("deviceLBstate", "");
$LOV = split(";", "P;Production;D;Development;O;Power-off;");
if(sizeof($LOV)%2 != 0)
$array_length = sizeof($LOV) - 1;
else
$array_length = sizeof($LOV);
reset($LOV);
for($i = 0; $i < $array_length; $i = $i + 2)
{
$tpl->set_var("ID", $LOV[$i]);
$tpl->set_var("Value", $LOV[$i + 1]);
if($LOV[$i] == $fldstate)
$tpl->set_var("Selected", "SELECTED");
else
$tpl->set_var("Selected", "");
$tpl->parse("deviceLBstate", true);
}
$tpl->set_var("device_desc", tohtml($flddevice_desc));
$tpl->set_var("last_modify", tohtml($fldlast_modify));
$tpl->parse("Formdevice", false);
//-------------------------------
// device Close Event begin
// device Close Event end
//-------------------------------
//-------------------------------
// device Show end
//-------------------------------
}
//===============================
?>
|
|
|
 |
wanaka
|
| Posted: 04/16/2003, 1:08 AM |
|
any help???I saw many clueless post for this particular problem in this forum. Seem to me that I don't expect to get any answer here.
|
|
|
 |
|