diff --git a/post/client_locations_model.php b/post/client_locations_model.php index ab163d2d..242681be 100644 --- a/post/client_locations_model.php +++ b/post/client_locations_model.php @@ -10,4 +10,4 @@ $phone = preg_replace("/[^0-9]/", '',$_POST['phone']); $hours = sanitizeInput($_POST['hours']); $notes = sanitizeInput($_POST['notes']); $contact = intval($_POST['contact']); -$primary_location = intval($_POST['primary_location']); \ No newline at end of file +$location_primary = intval($_POST['primary_location']); \ No newline at end of file diff --git a/post/contact.php b/post/contact.php index 6844a08c..e28d478f 100644 --- a/post/contact.php +++ b/post/contact.php @@ -21,7 +21,7 @@ if (isset($_POST['add_contact'])) { $contact_id = mysqli_insert_id($mysqli); //Update Primary contact in clients if primary contact is checked - if ($contact_primary > 0) { + if ($contact_primary == 1) { // Old way of adding contact_primary Set for Removal mysqli_query($mysqli,"UPDATE clients SET primary_contact = $contact_id WHERE client_id = $client_id"); @@ -79,7 +79,7 @@ if (isset($_POST['edit_contact'])) { mysqli_query($mysqli,"UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_auth_method = '$auth_method', contact_department = '$department', contact_location_id = $location_id WHERE contact_id = $contact_id"); // Update Primary contact in clients if primary contact is checked - if ($contact_primary > 0) { + if ($contact_primary == 1) { // Old way of adding contact_primary Set for Removal mysqli_query($mysqli,"UPDATE clients SET primary_contact = $contact_id WHERE client_id = $client_id"); diff --git a/post/location.php b/post/location.php index 71fb982d..3b9e671a 100644 --- a/post/location.php +++ b/post/location.php @@ -18,9 +18,14 @@ if(isset($_POST['add_location'])){ $location_id = mysqli_insert_id($mysqli); - //Update Primay location in clients if primary location is checked - if($primary_location > 0){ + // Update Primay location in clients if primary location is checked + if($location_primary == 1){ + // Old way of adding contact_primary Set for Removal mysqli_query($mysqli,"UPDATE clients SET primary_location = $location_id WHERE client_id = $client_id"); + + // New Way of setting primary location + mysqli_query($mysqli,"UPDATE locations SET location_primary = 0 WHERE location_client_id = $client_id"); + mysqli_query($mysqli,"UPDATE locations SET location_primary = 1 WHERE location_id = $location_id"); } //Check to see if a file is attached @@ -73,9 +78,14 @@ if(isset($_POST['edit_location'])){ mysqli_query($mysqli,"UPDATE locations SET location_name = '$name', location_country = '$country', location_address = '$address', location_city = '$city', location_state = '$state', location_zip = '$zip', location_phone = '$phone', location_hours = '$hours', location_notes = '$notes', location_contact_id = $contact WHERE location_id = $location_id"); - //Update Primay location in clients if primary location is checked - if($primary_location > 0){ + // Update Primay location in clients if primary location is checked + if($location_primary == 1){ + // Old way of adding contact_primary Set for Removal mysqli_query($mysqli,"UPDATE clients SET primary_location = $location_id WHERE client_id = $client_id"); + + // New Way of setting primary location + mysqli_query($mysqli,"UPDATE locations SET location_primary = 0 WHERE location_client_id = $client_id"); + mysqli_query($mysqli,"UPDATE locations SET location_primary = 1 WHERE location_id = $location_id"); } //Check to see if a file is attached