mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-02-22 08:53:23 -05:00
This resolves the issue with contacts created on multiple terminals.
0) concurrency issue, one contact_id was edited by 2 or more terminals 1) Better than having a new contact_id created everytime the contact_add_edit page is opened which was the behavior of the original program. 2) Still need to clean-up the code a little, and do a little bit more testing, but appears to be working nicely. 3) Still uses GET for initial setup, a todo to change. 4) Glad the bug was found, and now is fixed.
This commit is contained in:
parent
ef058ba56b
commit
a671e41ffd
@ -35,13 +35,10 @@ default:
|
||||
$page_shop_log = PAGE_SHOP_LOG . "?shop_id=$shop_id";
|
||||
|
||||
|
||||
// setup the proper form action and form values .. not that $_GET is such a brilliant approach :)
|
||||
if($_GET['contact_id'] == 'new_contact'){
|
||||
|
||||
|
||||
/* Discover if previous contact creation attempt was abandoned
|
||||
There should be at least a first and last name, if not we use
|
||||
previous contact_id, update it and start fresh
|
||||
*/
|
||||
mysql_select_db($database_YBDB, $YBDB);
|
||||
|
||||
// Find previous contact_id
|
||||
@ -50,35 +47,10 @@ if($_GET['contact_id'] == 'new_contact'){
|
||||
$result = mysql_fetch_assoc($query);
|
||||
$previous_contact_id = $result['previous_contact_id'];
|
||||
|
||||
// If full_name is empty we will use this contact_id
|
||||
$sql = "SELECT CONCAT(first_name, ' ', last_name) as full_name FROM contacts WHERE contact_id=" . $previous_contact_id. ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($query);
|
||||
|
||||
$full_name = $result['full_name'];
|
||||
|
||||
//adds contact if new_contact is selected .. it's " " not ""
|
||||
if ($full_name != " ") {
|
||||
|
||||
$new_contact_id = $previous_contact_id + 1;
|
||||
|
||||
$insertSQL = sprintf("INSERT INTO contacts (date_created) VALUES (%s)",
|
||||
GetSQLValueString('current_time', "date"));
|
||||
$Result1 = mysql_query($insertSQL, $YBDB) or die(mysql_error());
|
||||
|
||||
$contact_id = $new_contact_id;
|
||||
$contact_id_entry = 'new_contact';
|
||||
|
||||
} else {
|
||||
|
||||
$insertSQL = sprintf("UPDATE contacts SET date_created=%s WHERE contact_id=" . $previous_contact_id,
|
||||
GetSQLValueString('current_time', "date"));
|
||||
$Result1 = mysql_query($insertSQL, $YBDB) or die(mysql_error());
|
||||
|
||||
$contact_id = $previous_contact_id;
|
||||
$contact_id_entry = 'new_contact';
|
||||
|
||||
}
|
||||
$new_contact_id = $previous_contact_id + 1;
|
||||
$contact_id = $new_contact_id;
|
||||
$contact_id_entry = 'new_contact';
|
||||
|
||||
|
||||
} elseif(isset($_GET['contact_id'])) {
|
||||
@ -90,27 +62,97 @@ if($_GET['contact_id'] == 'new_contact'){
|
||||
$contact_id_entry = -1;
|
||||
}
|
||||
|
||||
$editFormAction = "?contact_id={$contact_id}&shop_id={$shop_id}";
|
||||
|
||||
$editFormAction = "?contact_id={$contact_id}&shop_id={$shop_id}";
|
||||
|
||||
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
|
||||
|
||||
$updateSQL = sprintf("UPDATE contacts SET first_name=%s, middle_initial=%s, last_name=%s, email=%s,
|
||||
DOB=%s, phone=%s, address1=%s, address2=%s, city=%s,
|
||||
`state`=%s, zip=%s, pass=ENCODE(%s,'yblcatx') WHERE contact_id=%s",
|
||||
GetSQLValueString($_POST['first_name'], "text"),
|
||||
GetSQLValueString($_POST['middle_initial'], "text"),
|
||||
GetSQLValueString($_POST['last_name'], "text"),
|
||||
GetSQLValueString($_POST['email'], "text"),
|
||||
GetSQLValueString($_POST['DOB'], "date"),
|
||||
GetSQLValueString($_POST['phone'], "text"),
|
||||
GetSQLValueString($_POST['address1'], "text"),
|
||||
GetSQLValueString($_POST['address2'], "text"),
|
||||
GetSQLValueString($_POST['city'], "text"),
|
||||
GetSQLValueString($_POST['state'], "text"),
|
||||
GetSQLValueString($_POST['zip'], "text"),
|
||||
GetSQLValueString($_POST['password'], "text"),
|
||||
GetSQLValueString($_POST['contact_id'], "int"));
|
||||
|
||||
/* Discover if submitted contact creation attempt is new.
|
||||
There should be at least a first and last name.
|
||||
*/
|
||||
mysql_select_db($database_YBDB, $YBDB);
|
||||
|
||||
$query = 'SELECT MAX(contact_id) as contact_id FROM contacts;';
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($sql);
|
||||
$submitted_contact_id = $result['contact_id'] + 1;
|
||||
|
||||
/*
|
||||
$handler->debug("submitted_contact_id",$submitted_contact_id - 1);
|
||||
$handler->debug("$_POST",$_POST['contact_id']);
|
||||
exit();
|
||||
*/
|
||||
|
||||
// contact already exists it is less than $submitted_contact_id
|
||||
if($submitted_contact_id > $_POST['contact_id']) {
|
||||
$submitted_contact_id = $_POST['contact_id'];
|
||||
}
|
||||
|
||||
// if contact already exists, $submitted_contact_id now equals $_POST['contact_id], and it isn't new_contact
|
||||
if ($submitted_contact_id != $_POST['contact_id'] || $_POST === 'new_contact') {
|
||||
$submitted_contact_id = $_POST['contact_id'];
|
||||
} else {
|
||||
|
||||
// If full_name is empty we will use this contact_id
|
||||
$sql = "SELECT CONCAT(first_name, ' ', last_name) as full_name FROM contacts WHERE contact_id=" . $submitted_contact_id . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($query);
|
||||
$full_name = $result['full_name'];
|
||||
}
|
||||
|
||||
//adds contact if new_contact is selected .. it's " " not ""
|
||||
if (empty($full_name)) {
|
||||
$contact_id_entry = 'new_contact';
|
||||
}
|
||||
|
||||
if ( $contact_id_entry === 'new_contact' ) {
|
||||
|
||||
// Get the actual contact_id because it may have changed on multiple terminals
|
||||
$query = 'SELECT MAX(contact_id) as contact_id FROM contacts;';
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($sql);
|
||||
$submitted_contact_id = $result['contact_id'] + 1;
|
||||
|
||||
// Insert new contact information into a new record
|
||||
$updateSQL = 'INSERT INTO contacts (contact_id, first_name, middle_initial, last_name, email,' .
|
||||
' phone, address1, address2, city, state, DOB, receive_newsletter, waiver, pass, zip)' .
|
||||
' VALUES (' .
|
||||
$submitted_contact_id . ', ' .
|
||||
'"' . $_POST['first_name'] . '", ' .
|
||||
'"' . $_POST['middle_initial'] . '", ' .
|
||||
'"' . $_POST['last_name'] . '", ' .
|
||||
'"' . $_POST['email'] . '", ' .
|
||||
'"' . $_POST['phone'] . '", ' .
|
||||
'"' . $_POST['address1'] . '", ' .
|
||||
'"' . $_POST['address2'] . '", ' .
|
||||
'"' . $_POST['city'] . '", ' .
|
||||
'"' . $_POST['state'] . '", ' .
|
||||
'"' . $_POST['DOB'] . '", ' .
|
||||
'"' . $_POST['email_list'] . '", ' .
|
||||
1 . ', ' .
|
||||
'ENCODE("' . $_POST['password'] . '",' . '"yblcatx"), ' .
|
||||
'"' . $_POST['zip'] . '");';
|
||||
} else {
|
||||
|
||||
// Update existing contact record
|
||||
$updateSQL = sprintf("UPDATE contacts SET first_name=%s, middle_initial=%s, last_name=%s, email=%s,
|
||||
DOB=%s, phone=%s, address1=%s, address2=%s, city=%s,
|
||||
`state`=%s, zip=%s, pass=ENCODE(%s,'yblcatx') WHERE contact_id=%s",
|
||||
GetSQLValueString($_POST['first_name'], "text"),
|
||||
GetSQLValueString($_POST['middle_initial'], "text"),
|
||||
GetSQLValueString($_POST['last_name'], "text"),
|
||||
GetSQLValueString($_POST['email'], "text"),
|
||||
GetSQLValueString($_POST['DOB'], "date"),
|
||||
GetSQLValueString($_POST['phone'], "text"),
|
||||
GetSQLValueString($_POST['address1'], "text"),
|
||||
GetSQLValueString($_POST['address2'], "text"),
|
||||
GetSQLValueString($_POST['city'], "text"),
|
||||
GetSQLValueString($_POST['state'], "text"),
|
||||
GetSQLValueString($_POST['zip'], "text"),
|
||||
GetSQLValueString($_POST['password'], "text"),
|
||||
GetSQLValueString($submitted_contact_id, "int"));
|
||||
}
|
||||
|
||||
mysql_select_db($database_YBDB, $YBDB);
|
||||
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
|
||||
@ -163,7 +205,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
|
||||
|
||||
// Find out if any selections are in the database,
|
||||
// to decide whether an INSERT or DELETE needs to be done
|
||||
$sql = "SELECT selection FROM selections WHERE contact_id=" . $_POST['contact_id'] . ";";
|
||||
$sql = "SELECT selection FROM selections WHERE contact_id=" . $submitted_contact_id . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
$selections = [];
|
||||
while ($result = mysql_fetch_assoc($query)) {
|
||||
@ -174,13 +216,13 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
|
||||
if ( is_null($selections[$interest_id]) ) { //INSERT
|
||||
if( !is_null($interest_checked[$selection]) ) {
|
||||
$sql = "INSERT INTO selections (contact_id, selection, selection_value)
|
||||
VALUES (" . $_POST['contact_id'] . "," . $interest_id . ",1);";
|
||||
VALUES (" . $submitted_contact_id . "," . $interest_id . ",1);";
|
||||
$result = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
}
|
||||
} else { //DELETE
|
||||
if( is_null($interest_checked[$selection]) ) {
|
||||
$sql = "DELETE FROM selections WHERE selection=" . $interest_id .
|
||||
" AND contact_id=" . $_POST['contact_id'] . ";";
|
||||
" AND contact_id=" . $submitted_contact_id . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
}
|
||||
}
|
||||
@ -189,11 +231,11 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
|
||||
// insert as update? But it works.
|
||||
if ($_POST['comments']) {
|
||||
$sql = "INSERT INTO selections (contact_id, selection, selection_value)
|
||||
VALUES (" . $_POST['contact_id'] . ", 1,'" . $_POST['comments'] . "');";
|
||||
VALUES (" . $submitted_contact_id . ", 1,'" . $_POST['comments'] . "');";
|
||||
$result = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
}
|
||||
|
||||
if ($_POST['contact_id_entry'] == 'new_contact' || $_POST['contact_id_entry'] == $_POST['contact_id']){
|
||||
if ($_POST['contact_id_entry'] == 'new_contact' || $_POST['contact_id_entry'] == $submitted_contact_id){
|
||||
|
||||
//navigate back to shop that it came from
|
||||
$pagegoto = PAGE_SHOP_LOG . "?shop_id={$shop_id}&new_user_id={$contact_id}";
|
||||
@ -201,7 +243,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} // Submitted
|
||||
|
||||
mysql_select_db($database_YBDB, $YBDB);
|
||||
$query_Recordset1 = "SELECT *, DECODE(pass,'yblcatx') AS passdecode FROM contacts WHERE contact_id = $contact_id";
|
||||
@ -222,7 +264,15 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
|
||||
<table border="0" cellpadding="1" cellspacing="0" bordercolor="#CCCCCC">
|
||||
<tr>
|
||||
<td><label class="contacts">Contact_id:</label></td>
|
||||
<td><?php echo $row_Recordset1['contact_id']; ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if($_GET['contact_id'] == 'new_contact'){
|
||||
echo 'New Contact';
|
||||
} else {
|
||||
echo $row_Recordset1['contact_id'];
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr >
|
||||
<td><label class="contacts">Name:</label></td>
|
||||
@ -293,7 +343,7 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
|
||||
<?php include("Connections/waiver.txt"); ?>
|
||||
<br />
|
||||
</p>
|
||||
</div><input id="waiver_checkbox" type="checkbox"> I agree <span id="waiver_error"></span>
|
||||
</div><input id="waiver_checkbox" name="waiver_checkbox" type="checkbox"> I agree <span id="waiver_error"></span>
|
||||
<input type="submit" id="waiver_button" value="Show Waiver" \>
|
||||
|
||||
</td>
|
||||
@ -309,25 +359,33 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
|
||||
<table>
|
||||
<tr><td> </td></tr>
|
||||
<?php
|
||||
$sql = "SELECT options.option_name AS selection FROM selections, options
|
||||
WHERE selections.selection=options.option_name_id AND
|
||||
contact_id=" . $row_Recordset1['contact_id'] . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
|
||||
if($_GET['contact_id'] != 'new_contact'){
|
||||
$sql = "SELECT options.option_name AS selection FROM selections, options
|
||||
WHERE selections.selection=options.option_name_id AND
|
||||
contact_id=" . $row_Recordset1['contact_id'] . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
}
|
||||
|
||||
$selections = [];
|
||||
while ($result = mysql_fetch_assoc($query)) {
|
||||
$selections[$result["selection"]] = $result["selection"];
|
||||
}
|
||||
|
||||
|
||||
if($_GET['contact_id'] != 'new_contact'){
|
||||
while ($result = mysql_fetch_assoc($query)) {
|
||||
$selections[$result["selection"]] = $result["selection"];
|
||||
}
|
||||
}
|
||||
|
||||
$columns = 3;
|
||||
$c = 0;
|
||||
$rows = 0;
|
||||
$interest_count = count($volunteer_interests);
|
||||
|
||||
while($rows < $interest_count + 3) {
|
||||
echo "<tr>";
|
||||
|
||||
for($i = $rows - $columns; $i < $rows; $i++) {
|
||||
if($volunteer_interests[$i]) {
|
||||
|
||||
if($volunteer_interests[$i]) {
|
||||
|
||||
if($volunteer_interests[$i] === $selections[$volunteer_interests[$i]]) {
|
||||
echo "<td><input name='interest_checkboxes[]' class='interest_checkboxes'
|
||||
value='$volunteer_interests[$i]' type='checkbox' checked>" .
|
||||
@ -343,11 +401,14 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
|
||||
$rows = $rows + $columns;
|
||||
}
|
||||
?>
|
||||
<?php if($volunteer_interest_comments) {
|
||||
$sql = "SELECT selection_value AS comments FROM selections
|
||||
WHERE selection=1 AND contact_id=" . $row_Recordset1['contact_id'] . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($query);
|
||||
<?php if($volunteer_interest_comments) {
|
||||
|
||||
if($_GET['contact_id'] != 'new_contact'){
|
||||
$sql = "SELECT selection_value AS comments FROM selections
|
||||
WHERE selection=1 AND contact_id=" . $row_Recordset1['contact_id'] . ";";
|
||||
$query = mysql_query($sql, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($query);
|
||||
}
|
||||
|
||||
?>
|
||||
<tr><td> </td></tr>
|
||||
@ -371,7 +432,15 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
|
||||
</table>
|
||||
|
||||
<input type="hidden" name="MM_insert" value="form1">
|
||||
<input type="hidden" id="contact_id" name="contact_id" value="<?php echo $row_Recordset1['contact_id']; ?>">
|
||||
<input type="hidden" id="contact_id" name="contact_id"
|
||||
<?php
|
||||
if($_GET['contact_id'] === 'new_contact'){
|
||||
echo "value='new_contact'";
|
||||
} else {
|
||||
echo "value='" . $row_Recordset1['contact_id'] . "'";
|
||||
}
|
||||
?>>
|
||||
<input type="hidden" name="email_list" id="email_list">
|
||||
<input type="hidden" name="contact_id_entry" value="<?php echo $contact_id_entry; ?>">
|
||||
</form>
|
||||
</tr>
|
||||
|
@ -126,6 +126,10 @@ $(function(){
|
||||
if (success === "Success") {
|
||||
|
||||
var email_list = $("#email_list_toggle").val();
|
||||
|
||||
// send email_list val to $_POST
|
||||
$("#email_list").val(email_list);
|
||||
|
||||
var waiver = waiver_checkbox.prop("checked");
|
||||
if (!email_list) {
|
||||
email_list = 0;
|
||||
@ -137,6 +141,9 @@ $(function(){
|
||||
} else if (waiver === false) {
|
||||
waiver = 0;
|
||||
}
|
||||
|
||||
$.post("json/contact.php", {most_recent_contact_id: 1});
|
||||
|
||||
// update receive_newsletter and waiver in the database
|
||||
$.post("json/contact.php", {contact_id: contact_id, email_list: email_list, waiver: waiver });
|
||||
|
||||
@ -253,6 +260,10 @@ $(function(){
|
||||
|
||||
// beginning or stored state
|
||||
$.post("json/contact.php", {contact_id: contact_id, email_list_value: 1 }, function(data) {
|
||||
|
||||
if (data === "") {
|
||||
data = 1;
|
||||
}
|
||||
|
||||
$("#email_list_toggle").noUiSlider({
|
||||
orientation: "horizontal",
|
||||
|
@ -7,6 +7,7 @@ $email_list_connector = EMAIL_LIST_CONNECTOR;
|
||||
$email_list_connector_password = EMAIL_LIST_CONNECTOR_PASSWORD;
|
||||
$ssl_certificate = SSL_CERTIFICATE;
|
||||
|
||||
|
||||
// update waiver
|
||||
if( isset($_POST['waiver']) ) {
|
||||
|
||||
@ -30,12 +31,11 @@ $ssl_certificate = SSL_CERTIFICATE;
|
||||
|
||||
// update email_list
|
||||
if( isset($_POST['email_list']) ) {
|
||||
|
||||
|
||||
$email_list = $_POST['email_list'];
|
||||
$query = "UPDATE contacts SET receive_newsletter=" . $email_list .
|
||||
" WHERE contact_id=" . $_POST['contact_id'] . ";";
|
||||
$result = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
|
||||
$result = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
}
|
||||
|
||||
// return email_list value
|
||||
@ -80,5 +80,12 @@ $ssl_certificate = SSL_CERTIFICATE;
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['most_recent_contact_id'])) {
|
||||
$query = 'SELECT MAX(contact_id) as contact_id FROM contacts;';
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($sql);
|
||||
echo $result['contact_id'];
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user