Location: PHPKode > projects > Openelibrary > e-library/tipo_testoadd.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 ("tipo_testoinfo.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("tipo_testo") : GetAnonymousPriv("tipo_testo");
	if (($ewCurSec & ewAllowAdd) <> ewAllowAdd) {
		ob_end_clean();
		header("Location: tipo_testolist.php");
		exit();
	}
?>
<?php

// Initialize common variables
$x_id_tipologia_testo = NULL;
$ox_id_tipologia_testo = NULL;
$z_id_tipologia_testo = NULL;
$ar_x_id_tipologia_testo = NULL;
$ari_x_id_tipologia_testo = NULL;
$x_id_tipologia_testoList = NULL;
$x_id_tipologia_testoChk = NULL;
$cbo_x_id_tipologia_testo_js = NULL;
$x_tipologia_testo = NULL;
$ox_tipologia_testo = NULL;
$z_tipologia_testo = NULL;
$ar_x_tipologia_testo = NULL;
$ari_x_tipologia_testo = NULL;
$x_tipologia_testoList = NULL;
$x_tipologia_testoChk = NULL;
$cbo_x_tipologia_testo_js = NULL;
?>
<?php

// Load key from QueryString
$bCopy = true;
$x_id_tipologia_testo = @$HTTP_GET_VARS["id_tipologia_testo"];
if (($x_id_tipologia_testo == "") || ($x_id_tipologia_testo == NULL)) $bCopy = false;

// Get action
$sAction = @$HTTP_POST_VARS["a_add"];
if (($sAction == "") || (($sAction == NULL))) {
	if ($bCopy) {
		$sAction = "C"; // Copy record
	} else {
		$sAction = "I"; // Display blank record
	}
} else {

	// Get fields from form
	$x_id_tipologia_testo = @$HTTP_POST_VARS["x_id_tipologia_testo"];
	$x_tipologia_testo = @$HTTP_POST_VARS["x_tipologia_testo"];
}
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction) {
	case "C": // Copy record
		if (!LoadData($conn)) { // Load record
			$HTTP_SESSION_VARS[ewSessionMessage] = "No records found";
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: tipo_testolist.php");
			exit();
		}
		break;
	case "A": // Add
		if (AddData($conn)) { // Add new record
			$HTTP_SESSION_VARS[ewSessionMessage] = "Add New Record Successful";
			phpmkr_db_close($conn);
			ob_end_clean();
			header("Location: tipo_testolist.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">Add to TABLE: Type of material<br><br><a href="tipo_testolist.php">Back to List</a></span></p>
<form name="ftipo_testoadd" id="ftipo_testoadd" action="tipo_testoadd.php" method="post" onSubmit="return EW_checkMyForm(this);">
<p>
<input type="hidden" name="a_add" value="A">
<?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_tipologia_testo">
		<td class="ewTableHeader"><span>tipologia testo</span></td>
		<td class="ewTableAltRow"><span id="cb_x_tipologia_testo">
<input type="text" name="x_tipologia_testo" id="x_tipologia_testo" size="30" maxlength="50" value="<?php echo htmlspecialchars(@$x_tipologia_testo) ?>">
</span></td>
	</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</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_tipologia_testo;
	$sFilter = ewSqlKeyWhere;
	if (!is_numeric($x_id_tipologia_testo)) return false;
	$x_id_tipologia_testo =  (get_magic_quotes_gpc()) ? stripslashes($x_id_tipologia_testo) : $x_id_tipologia_testo;
	$sFilter = str_replace("@id_tipologia_testo", AdjustSql($x_id_tipologia_testo), $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_tipologia_testo"] = $row["id_tipologia_testo"];
		$GLOBALS["x_tipologia_testo"] = $row["tipologia_testo"];
	}
	phpmkr_free_result($rs);
	return $bLoadData;
}
?>
<?php

//-------------------------------------------------------------------------------
// Function AddData
// - Add Data
// - Variables used: field variables

function AddData($conn)
{
	global $HTTP_SESSION_VARS;
	global $HTTP_POST_VARS;
	global $HTTP_POST_FILES;
	global $HTTP_ENV_VARS;
	global $x_id_tipologia_testo;
	global $x_tipologia_testo;
	$sFilter = ewSqlKeyWhere;

	// Check for duplicate key
	$bCheckKey = true;
	if ((@$x_id_tipologia_testo == "") || (@$x_id_tipologia_testo == NULL)) {
		$bCheckKey = false;
	} else {
		$sFilter = str_replace("@id_tipologia_testo", AdjustSql($x_id_tipologia_testo), $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) {
			$HTTP_SESSION_VARS[ewSessionMessage] = "Duplicate value for primary key";
			phpmkr_free_result($rsChk);
			return false;
		}
		phpmkr_free_result($rsChk);
	}
	if (@$x_tipologia_testo == "" || (@$x_tipologia_testo == NULL)) { // Check field with unique index

		// Ignore
	} else {
		$sFilter = "(`tipologia_testo` = '" . AdjustSql($x_tipologia_testo) . "')";
		$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) {
			$HTTP_SESSION_VARS[ewSessionMessage] = "Duplicate value for index or primary key -- `tipologia_testo`, value = " . $x_tipologia_testo;
			phpmkr_free_result($rsChk);			
			return false;
		}
		phpmkr_free_result($rsChk);
	}

	// Field tipologia_testo
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_tipologia_testo"]) : $GLOBALS["x_tipologia_testo"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`tipologia_testo`"] = $theValue;

	// Insert
	$sSql = "INSERT INTO `tipo_testo` (";
	$sSql .= implode(",", array_keys($fieldList));
	$sSql .= ") VALUES (";
	$sSql .= implode(",", array_values($fieldList));
	$sSql .= ")";

	// Inserting event
	if (Recordset_Inserting($fieldList)) {
		phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
		$fieldList["`id_tipologia_testo`"] = phpmkr_insert_id($conn);
		$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)
{
	global $HTTP_SESSION_VARS;
	global $HTTP_POST_VARS;
	global $HTTP_POST_FILES;
	global $HTTP_ENV_VARS;
	$table = "tipo_testo";
}
?>
Return current item: Openelibrary