<?php require_once('../Connections/modeli.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$today = date("m-d-y");
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO poracki (model_id, razmer_id, broy, cena, data_por) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['model_id'], "int"),
GetSQLValueString($_POST['razmer_id'], "int"),
GetSQLValueString($_POST['broy'], "int"),
GetSQLValueString($_POST['cena'], "double"),
GetSQLValueString($today, "date"));
mysql_select_db($database_modeli, $modeli);
$Result1 = mysql_query($insertSQL, $modeli) or die(mysql_error());
$insertGoTo = "/bayram/admin/porachki.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_modeli, $modeli);
$query_rs_modeli = "SELECT * FROM modeli";
$rs_modeli = mysql_query($query_rs_modeli, $modeli) or die(mysql_error());
$row_rs_modeli = mysql_fetch_assoc($rs_modeli);
$totalRows_rs_modeli = mysql_num_rows($rs_modeli);
mysql_select_db($database_modeli, $modeli);
$query_rs_razmer = "SELECT * FROM razmeri";
$rs_razmer = mysql_query($query_rs_razmer, $modeli) or die(mysql_error());
$row_rs_razmer = mysql_fetch_assoc($rs_razmer);
$totalRows_rs_razmer = mysql_num_rows($rs_razmer);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script type="text/javascript" src="js/jQuery.XDomainRequest.js"></script>
<script type="text/javascript">
function get_razmer(){
$.ajax({
type: "POST",
url: "get_razmer.php",
data: "id=" + document.getElementById("model_id").value,
success: function(html){
$(".razmer_id").html(html);
document.getElementById("broy").disabled = true;
document.getElementById("ob6ta_cena").value="";
document.getElementById("broy").value="";
document.getElementById('cena').value = "";
//document.getElementById('ob6ta_cena').value="";
// $("#cena").html(html);
}
});
}
function get_cena(){
$.ajax({
type: "POST",
url: "get_cena.php",
data: "model=" + document.getElementById("model_id").value +
"&razmer=" + document.getElementById("razmer_id").value,
success: function(html){
$("#response").html(html);
document.getElementById("broy").disabled = false;
document.getElementById("ob6ta_cena").value="";
document.getElementById("broy").value="";
// $("#cena").html(html);
},
error: function doClear(){
$('#cena').text('');
}
});
}
function ob6ta_cena1(){
var suma=(parseFloat(document.getElementById('cena').value)) * (parseInt(document.getElementById('broy').value));
document.getElementById('ob6ta_cena').value=parseFloat(suma).toFixed(2) + " лв.";
}
</script>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td colspan="2" align="center" nowrap="nowrap"><strong>Подай поръчка</strong></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Модел:</td>
<td><select name="model_id" id="model_id" class="model_id" onchange="get_razmer(); ">
<option selected="selected">--Избери модел--</option>
<?php
do {
?>
<option value="<?php echo $row_rs_modeli['id']?>" ><?php echo $row_rs_modeli['model']?></option>
<?php
} while ($row_rs_modeli = mysql_fetch_assoc($rs_modeli));
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Размер:</td>
<td><select name="razmer_id" id="razmer_id" class="razmer_id" onchange="get_cena()">
<option value="" > </option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Брой:</td>
<td><input name="broy" type="text" disabled="disabled" id="broy" onkeyup="ob6ta_cena1()" value="" size="10"/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Единична цена:</td>
<td><div id="response">
<input type="text" name="cena" value="" size="10" class="cena" disabled="disabled" id="cena" onchange="ob6ta_cena1()" onfocus="ob6ta_cena1()"/>
</div></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Обща цена</td>
<td><label for="ob6ta_cena"></label>
<input name="ob6ta_cena" type="text" readonly="readonly" id="ob6ta_cena" size="15"/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Добави" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<div id="response">
</div>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs_modeli);
mysql_free_result($rs_razmer);
?>