1
0
mirror of https://github.com/fspc/Yellow-Bike-Database.git synced 2025-02-22 00:53:22 -05:00

jQuery - when paid checkbox is checked/unchecked database is updated.

Color changes, too.
This commit is contained in:
Jonathan Rosenbaum 2014-12-26 06:26:26 +00:00
parent 87eb7fba3a
commit 508ed7c3b9
4 changed files with 51 additions and 2 deletions

View File

@ -24,6 +24,7 @@ function resetTimer()
<title>YBDB</title> <title>YBDB</title>
<link href="css_yb_standard.css" rel="stylesheet" type="text/css" /> <link href="css_yb_standard.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-2.1.1.js"></script> <script src="js/jquery-2.1.1.js"></script>
<script src="js/transaction.js"></script>
</head> </head>

20
js/transaction.js Normal file
View File

@ -0,0 +1,20 @@
/* jQuery fun with transactions - Jonathan Rosenbaum */
// currently css is just hardwired, but that reflects the coding style of YBDB :)
$(function() {
$(".paid").click(function() {
if ($(this).prop("checked")) {
//console.log("turn color on");
$(this).closest("tr").css("background-color","#99CC33");
$.post("json/transaction.php",{ paid: 1, transaction_id: this.name } );
}
else {
//console.log("turn color off");
$(this).closest("tr").css("background-color","transparent");
$.post("json/transaction.php",{ paid: 0, transaction_id: this.name } );
}
});
});

21
json/transaction.php Normal file
View File

@ -0,0 +1,21 @@
<?php
require_once('../Connections/YBDB.php');
mysql_select_db($database_YBDB, $YBDB);
if(isset($_POST['paid'])) {
if ($_POST['paid'] == 1) {
$query = "UPDATE transaction_log SET paid=1 WHERE transaction_id=" . $_POST['transaction_id'] . ";";
$result = mysql_query($query, $YBDB) or die(mysql_error());
} elseif($_POST['paid'] == 0) {
$query = "UPDATE transaction_log SET paid=0 WHERE transaction_id=" . $_POST['transaction_id'] . ";";
$result = mysql_query($query, $YBDB) or die(mysql_error());
}
}
?>

View File

@ -385,7 +385,10 @@ FROM transaction_log WHERE transaction_id = $trans_id; ";
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { //do { ?> <?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { //do { ?>
<form method="post" name="FormView_<?php echo $row_Recordset1['transaction_id']; ?>" action="<?php echo $editFormAction; ?>"> <form method="post" name="FormView_<?php echo $row_Recordset1['transaction_id']; ?>" action="<?php echo $editFormAction; ?>">
<tr bordercolor='#CCCCCC' <?php echo ((intval($row_Recordset1['transaction_id']) == intval($trans_id)) ? "bgcolor='#CCCC33'" : "")?> > <tr bordercolor='#CCCCCC' <?php
echo ((intval($row_Recordset1['transaction_id']) == intval($trans_id)) ? "bgcolor='#CCCC33'" : "");
if ($row_Recordset1['paid'] == 1) { echo "bgcolor='#99CC33'"; }
?> >
<td><?php echo $row_Recordset1['shop_id']; ?></td> <td><?php echo $row_Recordset1['shop_id']; ?></td>
<td><?php echo $row_Recordset1['date_wday']; ?></td> <td><?php echo $row_Recordset1['date_wday']; ?></td>
<td><?php echo $row_Recordset1['transaction_type']; ?></td> <td><?php echo $row_Recordset1['transaction_type']; ?></td>
@ -393,7 +396,11 @@ FROM transaction_log WHERE transaction_id = $trans_id; ";
<td><?php echo $row_Recordset1['description_with_locations']; ?>&nbsp;</td> <td><?php echo $row_Recordset1['description_with_locations']; ?>&nbsp;</td>
<td><?php echo $row_Recordset1['full_name']; ?></td> <td><?php echo $row_Recordset1['full_name']; ?></td>
<td><?php $record_trans_id = $row_Recordset1['transaction_id']; echo "<a href=\"{$_SERVER['PHP_SELF']}?trans_id={$record_trans_id}\">edit</a>"; ?></td> <td><?php $record_trans_id = $row_Recordset1['transaction_id']; echo "<a href=\"{$_SERVER['PHP_SELF']}?trans_id={$record_trans_id}\">edit</a>"; ?></td>
<td><input class="paid" type="checkbox" name="<?php echo $row_Recordset1['transaction_id']; ?>" value="<?php echo $row_Recordset1['paid']; ?>"></td> <td><input class="paid" type="checkbox" name="<?php echo $row_Recordset1['transaction_id']; ?>"
value="<?php echo $row_Recordset1['paid'];?>"
<?php if ($row_Recordset1['paid'] == 1) { echo " checked"; } ?>
>
</td>
</tr> </tr>
<input type="hidden" name="MM_insert" value="FormUpdate"> <input type="hidden" name="MM_insert" value="FormUpdate">
<input type="hidden" name="shop_visit_id" value="<?php echo $row_Recordset1['transaction_id']; ?>"> <input type="hidden" name="shop_visit_id" value="<?php echo $row_Recordset1['transaction_id']; ?>">