<?php
session_start();
$con = mysql_connect("ashconnell.com","root","");
mysql_select_db("homeinnovations", $con);
$searchQuery = strtoupper($_POST['searchInputValue']);
$query = "SELECT * FROM entries WHERE id LIKE '%" . $searchQuery . "%' OR description LIKE '%" . $searchQuery . "%' OR location LIKE '%" . $searchQuery . "%' ORDER BY id";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$subTotal = 0;
$subCtns = 0;
while($row = mysql_fetch_array($result)) {
$subCtns = $subCtns + $row['ctns'];
$subTotal = $subTotal + $row['total'];
?>
<ul class="entry" id="<?php echo $row['primaryID']; ?>">
<li class="id"><?php echo $row['id']; ?></li>
<li class="name"><?php echo $row['description']; ?></li>
<li class="ctns"><?php echo $row['ctns']; ?></li>
<li class="ppc"><?php echo $row['ppc']; ?></li>
<li class="total"><?php echo $row['total']; ?></li>
<li class="notes"><?php echo $row['notes']; ?></li>
<li class="location"><?php echo $row['location']; ?></li>
<li class="edit">
<a href="javascript:void(0);" class="deleteBtn"></a>
<a href="javascript:void(0);" class="editBtn"></a>
</li>
</ul>
<?php
}
?>
<div class="subCtns"><?php echo $subCtns; ?></div>
<div class="subTotal"><?php echo $subTotal; ?></div>
//Initialisation
var searchInputValue;
var action;
var editingID;
// Make products window fit the page.
function productsResize() {
newHeight = $(window).height()-211;
$("#products").css('height', newHeight);
}
// Refresh product entries (via search query)
function refreshEntries(){
if($('#searchInput').val()!='Search'){
searchInputValue = $("#searchInput").val();
}
else{
searchInputValue = '';
}
$.post("search.php", {searchInputValue: searchInputValue}, function(data){
$("#products").html(data);
$(".footerList .ctns").html($(".subCtns").html());
$(".footerList .total").html($(".subTotal").html());
});
}
//////////////////////////////////////////////
// When Document Is Loaded
$(document).ready(function() {
// Search Input KeyUp
$("#searchInput").keyup(function(){
refreshEntries();
});
// Products Pane Height
productsResize();
// Entry Hover {
$('.entry').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
$(this).css('background-color','#E6E6E6');
$(this).find(".deleteBtn").css('display','block');
$(this).find(".editBtn").css('display','block');
}
else {
$(this).css('background','none');
$(this).find(".deleteBtn").css('display','none');
$(this).find(".editBtn").css('display','none');
}
});
// Search Field {
$('#searchInput').focus(function(){
if($(this).val()=="Search"){
$(this).val('');
$(this).css('color','#4e565b');
}
});
$('#searchInput').blur(function(){
if($(this).val()==""){
$(this).val('Search');
$(this).css('color','#B5B5B5');
}
});
// Add New Btn
$('#newBtn').click(function(){
action = 'add';
$('.editWindow_title').html('Add New');
$('.updateBtn').hide();
$('.addBtn').show();
$('#deleteWindow').hide();
$('#editWindow').show();
$('#overlay').show();
});
// Add Btn
$('.addBtn').click(function(){
var id = $('#idInput').val();
var description = $('#descInput').val();
var notes = $('#notesInput').val();
var location = $('#locInput').val();
var ctns = $('#ctnsInput').val();
var ppc = $('#ppcInput').val();
var total = $('#totalInput').val();
$.post("add.php", {id: id, description: description, notes: notes, location: location, ctns: ctns, ppc: ppc, total: total}, function(data) {
if(data.added=="true"){
refreshEntries();
$('.windowX').click();
}
else {
alert("Error: Could not access the database. Tell an administrator, and then press (F5) and try again.");
}
}, "json");
});
//Update Button
$('.updateBtn').click(function(){
var id = $('#idInput').val();
var description = $('#descInput').val();
var notes = $('#notesInput').val();
var location = $('#locInput').val();
var ctns = $('#ctnsInput').val();
var ppc = $('#ppcInput').val();
var total = $('#totalInput').val();
$.post("update.php", {id: id, description: description, notes: notes, location: location, ctns: ctns, ppc: ppc, total: total, primaryID: editingID}, function(data) {
if(data.updated=="true"){
refreshEntries();
$('.windowX').click();
}
else {
alert("Error: Could not access the database. Tell an administrator, and then press (F5) and try again.");
}
}, "json");
});
© AshConnell.com | All rights reserved