<?php
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("stepsinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php
if (!IsLoggedIn() && (@$_COOKIE[ewCookieAutoLogin] == "autologin" && @$_COOKIE[ewCookiePassword] <> "")) {
ob_end_clean();
header("Location: login.php");
exit();
}
LoadUserLevel();
$ewCurSec = (IsLoggedIn())? CurrentUserLevelPriv("steps") : GetAnonymousPriv("steps");
if (($ewCurSec & ewAllowAdd) <> ewAllowAdd) {
ob_end_clean();
header("Location: stepslist.php");
exit();
}
?>
<?php
// Initialize common variables
$x_id = NULL;
$ox_id = NULL;
$z_id = NULL;
$ar_x_id = NULL;
$ari_x_id = NULL;
$x_idList = NULL;
$x_idChk = NULL;
$cbo_x_id_js = NULL;
$x_class = NULL;
$ox_class = NULL;
$z_class = NULL;
$ar_x_class = NULL;
$ari_x_class = NULL;
$x_classList = NULL;
$x_classChk = NULL;
$cbo_x_class_js = NULL;
$x_step = NULL;
$ox_step = NULL;
$z_step = NULL;
$ar_x_step = NULL;
$ari_x_step = NULL;
$x_stepList = NULL;
$x_stepChk = NULL;
$cbo_x_step_js = NULL;
$x_descrip = NULL;
$ox_descrip = NULL;
$z_descrip = NULL;
$ar_x_descrip = NULL;
$ari_x_descrip = NULL;
$x_descripList = NULL;
$x_descripChk = NULL;
$cbo_x_descrip_js = NULL;
$x_num_grp = NULL;
$ox_num_grp = NULL;
$z_num_grp = NULL;
$ar_x_num_grp = NULL;
$ari_x_num_grp = NULL;
$x_num_grpList = NULL;
$x_num_grpChk = NULL;
$cbo_x_num_grp_js = NULL;
$x_zone = NULL;
$ox_zone = NULL;
$z_zone = NULL;
$ar_x_zone = NULL;
$ari_x_zone = NULL;
$x_zoneList = NULL;
$x_zoneChk = NULL;
$cbo_x_zone_js = NULL;
$x_chest = NULL;
$ox_chest = NULL;
$z_chest = NULL;
$ar_x_chest = NULL;
$ari_x_chest = NULL;
$x_chestList = NULL;
$x_chestChk = NULL;
$cbo_x_chest_js = NULL;
$x_mob_url = NULL;
$ox_mob_url = NULL;
$z_mob_url = NULL;
$ar_x_mob_url = NULL;
$ari_x_mob_url = NULL;
$x_mob_urlList = NULL;
$x_mob_urlChk = NULL;
$cbo_x_mob_url_js = NULL;
?>
<?php
// Load key from QueryString
$bCopy = true;
$x_step = @$_GET["step"];
if (($x_step == "") || (is_null($x_step))) $bCopy = false;
// Get action
$sAction = @$_POST["a_add"];
if (($sAction == "") || ((is_null($sAction)))) {
if ($bCopy) {
$sAction = "C"; // Copy record
} else {
$sAction = "I"; // Display blank record
}
} else {
// Get fields from form
$x_id = @$_POST["x_id"];
$x_class = @$_POST["x_class"];
$x_step = @$_POST["x_step"];
$x_descrip = @$_POST["x_descrip"];
$x_num_grp = @$_POST["x_num_grp"];
$x_zone = @$_POST["x_zone"];
$x_chest = @$_POST["x_chest"];
$x_mob_url = @$_POST["x_mob_url"];
}
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction) {
case "C": // Copy record
if (!LoadData($conn)) { // Load record
$_SESSION[ewSessionMessage] = "No Steps found";
phpmkr_db_close($conn);
ob_end_clean();
header("Location: stepslist.php");
exit();
}
break;
case "A": // Add
if (AddData($conn)) { // Add new record
$_SESSION[ewSessionMessage] = "New Step Added Successfully";
phpmkr_db_close($conn);
ob_end_clean();
header("Location: stepslist.php");
exit();
}
break;
}
?>
<?php include ("sources/header.php") ?>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name
//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "-"; // set date separator
EW_UploadAllowedFileExt = "gif,jpg,jpeg,bmp,png,doc,xls,pdf,zip"; // allowed upload file extension
//-->
</script>
<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
if (EW_this.x_class && !EW_hasValue(EW_this.x_class, "SELECT")) {
if (!EW_onError(EW_this, EW_this.x_class, "SELECT", "Please enter required field - Class"))
return false;
}
if (EW_this.x_step && !EW_hasValue(EW_this.x_step, "TEXT")) {
if (!EW_onError(EW_this, EW_this.x_step, "TEXT", "Please enter required field - Step"))
return false;
}
if (EW_this.x_descrip && !EW_hasValue(EW_this.x_descrip, "TEXTAREA")) {
if (!EW_onError(EW_this, EW_this.x_descrip, "TEXTAREA", "Please enter required field - Description"))
return false;
}
if (EW_this.x_chest && !EW_hasValue(EW_this.x_chest, "SELECT")) {
if (!EW_onError(EW_this, EW_this.x_chest, "SELECT", "Please enter required field - Chest"))
return false;
}
return true;
}
//-->
</script>
<script type="text/javascript">
<!--
var EW_DHTMLEditors = [];
//-->
</script>
<form name="fstepsadd" id="fstepsadd" action="stepsadd.php" method="post" onsubmit="return EW_checkMyForm(this);">
<p>
<input type="hidden" name="a_add" value="A" />
<?php
if (@$_SESSION[ewSessionMessage] <> "") {
?>
<p><div class="ewmsg"><?php echo $_SESSION[ewSessionMessage]; ?></div></p>
<?php
$_SESSION[ewSessionMessage] = ""; // Clear message
}
?>
<table align="center" class="table_other">
<tr>
<td>Class<span class='ewmsg'> *</span></td>
<td><span id="cb_x_class">
<?php
$x_classList = "<select id='x_class' name='x_class'>";
$x_classList .= "<option value=''>Please Select</option>";
$sSqlWrk = "SELECT `id`, `class` FROM `class`";
$sSqlWrk .= " ORDER BY `class` Asc";
$rswrk = phpmkr_query($sSqlWrk,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL:' . $sSqlWrk);
if ($rswrk) {
$rowcntwrk = 0;
while ($datawrk = phpmkr_fetch_array($rswrk)) {
$x_classList .= "<option value=\"" . htmlspecialchars($datawrk[0]) . "\"";
if ($datawrk["id"] == @$x_class) {
$x_classList .= " selected";
}
$x_classList .= ">" . $datawrk["class"] . "</option>";
$rowcntwrk++;
}
}
@phpmkr_free_result($rswrk);
$x_classList .= "</select>";
echo $x_classList;
?>
</span></td>
</tr>
<tr>
<td>Step<span class='ewmsg'> *</span></td>
<td><span id="cb_x_step">
<input type="text" name="x_step" id="x_step" size="30" maxlength="255" value="<?php echo htmlspecialchars(@$x_step) ?>" class="text" />
</span></td>
</tr>
<tr>
<td valign="top">Description<span class='ewmsg'> *</span></td>
<td><span id="cb_x_descrip">
<textarea cols="70" rows="15" id="x_descrip" name="x_descrip" class="text"><?php echo @$x_descrip; ?></textarea>
</span></td>
</tr>
<tr>
<td>Number of Groups</td>
<td><span id="cb_x_num_grp">
<input type="text" name="x_num_grp" id="x_num_grp" size="30" maxlength="255" value="<?php echo htmlspecialchars(@$x_num_grp) ?>" class="text" />
</span></td>
</tr>
<tr>
<td>Zone</td>
<td><span id="cb_x_zone">
<input type="text" name="x_zone" id="x_zone" size="30" maxlength="255" value="<?php echo htmlspecialchars(@$x_zone) ?>" class="text" />
</span></td>
</tr>
<tr>
<td>Chest<span class='ewmsg'> *</span></td>
<td><span id="cb_x_chest">
<?php
$x_chestList = "<select id='x_chest' name='x_chest'>";
$x_chestList .= "<option value=''>Please Select</option>";
$x_chestList .= "<option value=\"Yes\"";
if (@$x_chest == "Yes") {
$x_chestList .= " selected";
}
$x_chestList .= ">" . "Yes" . "</option>";
$x_chestList .= "<option value=\"No\"";
if (@$x_chest == "No") {
$x_chestList .= " selected";
}
$x_chestList .= ">" . "No" . "</option>";
$x_chestList .= "<option value=\"?\"";
if (@$x_chest == "?") {
$x_chestList .= " selected";
}
$x_chestList .= ">" . "?" . "</option>";
$x_chestList .= "</select>";
echo $x_chestList;
?>
</span></td>
</tr>
<tr>
<td>Additional Information</td>
<td><span id="cb_x_mob_url">
<input type="text" name="x_mob_url" id="x_mob_url" size="30" maxlength="255" value="<?php echo htmlspecialchars(@$x_mob_url) ?>" class="text" />
</span></td>
</tr>
</table>
<p align="center">
<input type="submit" name="btnAction" id="btnAction" value="Add Step" class="button" />
</form>
<?php include ("footer.php") ?>
<?php
phpmkr_db_close($conn);
?>
<?php
//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables
function LoadData($conn)
{
global $x_step;
$sFilter = ewSqlKeyWhere;
$x_step = (get_magic_quotes_gpc()) ? stripslashes($x_step) : $x_step;
$sFilter = str_replace("@step", AdjustSql($x_step), $sFilter); // Replace key value
$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
if (phpmkr_num_rows($rs) == 0) {
$bLoadData = false;
} else {
$bLoadData = true;
$row = phpmkr_fetch_array($rs);
// Get the field contents
$GLOBALS["x_id"] = $row["id"];
$GLOBALS["x_class"] = $row["class"];
$GLOBALS["x_step"] = $row["step"];
$GLOBALS["x_descrip"] = $row["descrip"];
$GLOBALS["x_num_grp"] = $row["num_grp"];
$GLOBALS["x_zone"] = $row["zone"];
$GLOBALS["x_chest"] = $row["chest"];
$GLOBALS["x_mob_url"] = $row["mob_url"];
}
phpmkr_free_result($rs);
return $bLoadData;
}
?>
<?php
//-------------------------------------------------------------------------------
// Function AddData
// - Add Data
// - Variables used: field variables
function AddData($conn)
{
global $x_step;
$sFilter = ewSqlKeyWhere;
// Check for duplicate key
$bCheckKey = true;
if ((@$x_step == "") || (is_null(@$x_step))) {
$bCheckKey = false;
} else {
$sFilter = str_replace("@step", AdjustSql($x_step), $sFilter); // Replace key value
}
if ($bCheckKey) {
$sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
$rsChk = phpmkr_query($sSqlChk, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSqlChk);
if (phpmkr_num_rows($rsChk) > 0) {
$_SESSION[ewSessionMessage] = "Duplicate Value For Primary Key";
phpmkr_free_result($rsChk);
return false;
}
phpmkr_free_result($rsChk);
}
if (@$x_step == "" || (is_null(@$x_step))) { // Check field with unique index
// Ignore
} else {
$sFilter = "(`step` = '" . AdjustSql($x_step) . "')";
$sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
$rsChk = phpmkr_query($sSqlChk, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSqlChk);
if (phpmkr_num_rows($rsChk) > 0) {
$_SESSION[ewSessionMessage] = "Duplicate Value For Step -- `step`, value = " . $x_step;
phpmkr_free_result($rsChk);
return false;
}
phpmkr_free_result($rsChk);
}
// Field class
$theValue = ($GLOBALS["x_class"] != "") ? intval($GLOBALS["x_class"]) : "NULL";
$fieldList["`class`"] = $theValue;
// Field step
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_step"]) : $GLOBALS["x_step"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$sTmp = $theValue;
$srchFld = $sTmp;
$strsql = "SELECT * FROM `steps` WHERE `step` = " . $srchFld;
$rschk = phpmkr_query($strsql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL:' . $strsql);
if (phpmkr_num_rows($rschk) > 0) {
echo "Duplicate value for index or primary key -- step, value = " . $sTmp . "<br>";
echo "Press [Previous Page] key to continue!";
die();
}
@phpmkr_free_result($rschk);
$fieldList["`step`"] = $theValue;
// Field descrip
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_descrip"]) : $GLOBALS["x_descrip"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`descrip`"] = $theValue;
// Field num_grp
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_num_grp"]) : $GLOBALS["x_num_grp"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`num_grp`"] = $theValue;
// Field zone
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_zone"]) : $GLOBALS["x_zone"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`zone`"] = $theValue;
// Field chest
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_chest"]) : $GLOBALS["x_chest"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`chest`"] = $theValue;
// Field mob_url
$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_mob_url"]) : $GLOBALS["x_mob_url"];
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldList["`mob_url`"] = $theValue;
// Inserting event
if (Recordset_Inserting($fieldList)) {
// Insert
$sSql = "INSERT INTO `steps` (";
$sSql .= implode(",", array_keys($fieldList));
$sSql .= ") VALUES (";
$sSql .= implode(",", array_values($fieldList));
$sSql .= ")";
phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
$result = (phpmkr_affected_rows($conn) > 0);
// Inserted event
if ($result) Recordset_Inserted($fieldList);
} else {
$result = false;
}
return $result;
}
// Inserting event
function Recordset_Inserting(&$newrs)
{
// Enter your customized codes here
return true;
}
// Inserted event
function Recordset_Inserted($newrs)
{
$table = "steps";
}
?>