Location: PHPKode > projects > Openelibrary > e-library/versionedit.php
<?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
if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off')) { // PHP5 with register_long_arrays off
	$HTTP_POST_VARS = &$_POST;
	$HTTP_GET_VARS = &$_GET;
	$HTTP_SERVER_VARS = &$_SERVER;
	$HTTP_COOKIE_VARS = &$_COOKIE;
	$HTTP_ENV_VARS = &$_ENV;
	$HTTP_POST_FILES = &$_FILES;
	if (isset($_SESSION)) $HTTP_SESSION_VARS = &$_SESSION;
}
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("versioninfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php include ("ewupload.php") ?>
<?php
	if (!IsLoggedIn() && (@$HTTP_COOKIE_VARS[ewCookieAutoLogin] == "autologin" && @$HTTP_COOKIE_VARS[ewCookiePassword] <> "")) {
		ob_end_clean();
		header("Location: login.php");
		exit();
	}
	LoadUserLevel();
	$ewCurSec = (IsLoggedIn())? CurrentUserLevelPriv("version") : GetAnonymousPriv("version");
	if (($ewCurSec & ewAllowEdit) <> ewAllowEdit) {
		ob_end_clean();
		header("Location: versionlist.php");
		exit();
	}
?>
<?php

// Initialize common variables
$x_id_version_id = NULL;
$ox_id_version_id = NULL;
$z_id_version_id = NULL;
$ar_x_id_version_id = NULL;
$ari_x_id_version_id = NULL;
$x_id_version_idList = NULL;
$x_id_version_idChk = NULL;
$cbo_x_id_version_id_js = NULL;
$x_version = NULL;
$ox_version = NULL;
$z_version = NULL;
$ar_x_version = NULL;
$ari_x_version = NULL;
$x_versionList = NULL;
$x_versionChk = NULL;
$cbo_x_version_js = NULL;
?>
<?php

// Load key from QueryString
$x_id_version_id = @$HTTP_GET_VARS["id_version_id"];

// Get action
$sAction = @$HTTP_POST_VARS["a_edit"];
if ($sAction == "") {
	$sAction = "I";	// Display record	
} else {

	// Get fields from form
	$x_id_version_id = @$HTTP_POST_VARS["x_id_version_id"];
	$x_version = @$HTTP_POST_VARS["x_version"];
}
if (($x_id_version_id == "") || ($x_id_version_id == NULL)) {
	ob_end_clean();
	header("Location: versionlist.php");
	exit();
}
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction) {
	case "I": // Display record
		if (!LoadData($conn)) { // Load record
			$HTTP_SESSION_VARS[ewSessionMessage] = "No records found";
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: versionlist.php");
			exit();
		}
		break;
	case "U": // Update
		if (EditData($conn)) { // Update record
			$HTTP_SESSION_VARS[ewSessionMessage] = "Update Record Successful";
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: versionlist.php");
			exit();
		}
		break;
}
?>
<?php include ("header.php") ?>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name
EW_MultiPagePage = "Page"; // multi-page Page Text
EW_MultiPageOf = "of"; // multi-page Of Text

//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "/"; // set date separator	

//-->
</script>
<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
return true;
}

//-->
</script>
<script type="text/javascript">
<!--
	var EW_DHTMLEditors = [];

//-->
</script>
<p><span class="phpmaker">Edit TABLE: Version<br><br><a href="versionlist.php">Back to List</a></span></p>
<form name="fversionedit" id="fversionedit" action="versionedit.php" method="post" onSubmit="return EW_checkMyForm(this);">
<p>
	<input type="hidden" name="a_edit" value="U">
<?php
if (@$HTTP_SESSION_VARS[ewSessionMessage] <> "") {
?>
	<p><span class="ewmsg"><?php echo $HTTP_SESSION_VARS[ewSessionMessage]; ?></span></p>
<?php
	$HTTP_SESSION_VARS[ewSessionMessage] = ""; // Clear message
}
?>
	<table class="ewTable">
		<tr id="r_id_version_id">
			<td class="ewTableHeader"><span>id version id</span></td>
			<td class="ewTableAltRow"><span id="cb_x_id_version_id">
<?php echo $x_id_version_id; ?><input type="hidden" id="x_id_version_id" name="x_id_version_id" value="<?php echo @$x_id_version_id; ?>">
</span></td>
		</tr>
		<tr id="r_version">
			<td class="ewTableHeader"><span>version</span></td>
			<td class="ewTableAltRow"><span id="cb_x_version">
<input type="text" name="x_version" id="x_version" size="30" maxlength="10" value="<?php echo htmlspecialchars(@$x_version) ?>">
</span></td>
		</tr>
	</table>
	<p>
	<input type="submit" name="btnAction" id="btnAction" value="EDIT">
</form>
<?php include ("footer.php") ?>
<?php
phpmkr_db_close($conn);
?>
<?php

//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables

function LoadData($conn)
{
	global $HTTP_SESSION_VARS;
	global $x_id_version_id;
	$sFilter = ewSqlKeyWhere;
	if (!is_numeric($x_id_version_id)) return false;
	$x_id_version_id =  (get_magic_quotes_gpc()) ? stripslashes($x_id_version_id) : $x_id_version_id;
	$sFilter = str_replace("@id_version_id", AdjustSql($x_id_version_id), $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_version_id"] = $row["id_version_id"];
		$GLOBALS["x_version"] = $row["version"];
	}
	phpmkr_free_result($rs);
	return $bLoadData;
}
?>
<?php

//-------------------------------------------------------------------------------
// Function EditData
// - Variables used: field variables

function EditData($conn)
{
	global $HTTP_SESSION_VARS;
	global $HTTP_POST_VARS;
	global $HTTP_POST_FILES;
	global $HTTP_ENV_VARS;
	global $x_id_version_id;
	$sFilter = ewSqlKeyWhere;
	if (!is_numeric($x_id_version_id)) return false;
	$sTmp =  (get_magic_quotes_gpc()) ? stripslashes($x_id_version_id) : $x_id_version_id;
	$sFilter = str_replace("@id_version_id", AdjustSql($sTmp), $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);

	// Get old recordset
	$oldrs = phpmkr_fetch_array($rs);
	if (phpmkr_num_rows($rs) == 0) {
		return false; // Update Failed
	} else {
		$x_id_version_id = @$HTTP_POST_VARS["x_id_version_id"];
		$x_version = @$HTTP_POST_VARS["x_version"];
		$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_version"]) : $GLOBALS["x_version"]; 
		$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
		$fieldList["`version`"] = $theValue;

		// Update
		$sSql = "UPDATE `version` SET ";
		foreach ($fieldList as $key=>$temp) {
			$sSql .= "$key = $temp, ";
		}
		if (substr($sSql, -2) == ", ") {
			$sSql = substr($sSql, 0, strlen($sSql)-2);
		}
		$sSql .= " WHERE " . $sFilter;

		// Updating event
		if (Recordset_Updating($fieldList, $oldrs)) {
			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);

			// Updated event
			if ($result) Recordset_Updated($fieldList, $oldrs);
		} else {
			$result = false; // Update Failed
		}
	}
	return $result;
}

// Updating Event
function Recordset_Updating($newrs, $oldrs)
{

	// Enter your customized codes here
	return true;
}

// Updated event
function Recordset_Updated($newrs, $oldrs)
{
	global $HTTP_SESSION_VARS;
	global $HTTP_POST_VARS;
	global $HTTP_POST_FILES;
	global $HTTP_ENV_VARS;
	$table = "version";
}
?>
Return current item: Openelibrary