diff --git a/post/client.php b/post/client.php index 5dbed678..9cc78531 100644 --- a/post/client.php +++ b/post/client.php @@ -36,7 +36,7 @@ if (isset($_POST['add_client'])) { //Add Location if (!empty($location_phone) || !empty($address) || !empty($city) || !empty($state) || !empty($zip)) { - mysqli_query($mysqli, "INSERT INTO locations SET location_name = 'Primary', location_address = '$address', location_city = '$city', location_state = '$state', location_zip = '$zip', location_phone = '$location_phone', location_country = '$country', location_client_id = $client_id"); + mysqli_query($mysqli, "INSERT INTO locations SET location_name = 'Primary', location_address = '$address', location_city = '$city', location_state = '$state', location_zip = '$zip', location_phone = '$location_phone', location_country = '$country', location_primary = 1, location_client_id = $client_id"); //Update Primay location in clients $location_id = mysqli_insert_id($mysqli); @@ -49,7 +49,7 @@ if (isset($_POST['add_client'])) { //Add Contact if (!empty($contact) || !empty($title) || !empty($contact_phone) || !empty($contact_mobile) || !empty($contact_email)) { - mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '$contact', contact_title = '$title', contact_phone = '$contact_phone', contact_extension = '$contact_extension', contact_mobile = '$contact_mobile', contact_email = '$contact_email', contact_client_id = $client_id"); + mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '$contact', contact_title = '$title', contact_phone = '$contact_phone', contact_extension = '$contact_extension', contact_mobile = '$contact_mobile', contact_email = '$contact_email', contact_primary = 1, contact_important = 1, contact_client_id = $client_id"); //Update Primary contact in clients $contact_id = mysqli_insert_id($mysqli); diff --git a/post/contact.php b/post/contact.php index 17cc4527..6844a08c 100644 --- a/post/contact.php +++ b/post/contact.php @@ -21,8 +21,13 @@ if (isset($_POST['add_contact'])) { $contact_id = mysqli_insert_id($mysqli); //Update Primary contact in clients if primary contact is checked - if ($primary_contact > 0) { - mysqli_query($mysqli,"UPDATE clients SET primary_contact = $contact_id WHERE client_id = $client_id"); + if ($contact_primary > 0) { + // Old way of adding contact_primary Set for Removal + mysqli_query($mysqli,"UPDATE clients SET primary_contact = $contact_id WHERE client_id = $client_id"); + + // New Way of setting primary contact + mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 0 WHERE contact_client_id = $client_id"); + mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 1, contact_important = 1 WHERE contact_id = $contact_id"); } // Check for and process image/photo @@ -67,7 +72,6 @@ if (isset($_POST['edit_contact'])) { $row = mysqli_fetch_array($sql); $existing_file_name = sanitizeInput($row['contact_photo']); - if (!file_exists("uploads/clients/$client_id")) { mkdir("uploads/clients/$client_id"); } @@ -75,8 +79,12 @@ 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 ($primary_contact > 0) { + if ($contact_primary > 0) { + // Old way of adding contact_primary Set for Removal mysqli_query($mysqli,"UPDATE clients SET primary_contact = $contact_id WHERE client_id = $client_id"); + + mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 0 WHERE contact_client_id = $client_id"); + mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 1, contact_important = 1 WHERE contact_id = $contact_id"); } // Set password diff --git a/post/contact_model.php b/post/contact_model.php index d1123678..22fda2c0 100644 --- a/post/contact_model.php +++ b/post/contact_model.php @@ -8,8 +8,8 @@ $phone = preg_replace("/[^0-9]/", '', $_POST['phone']); $extension = preg_replace("/[^0-9]/", '', $_POST['extension']); $mobile = preg_replace("/[^0-9]/", '', $_POST['mobile']); $email = sanitizeInput($_POST['email']); -$primary_contact = intval($_POST['primary_contact']); $notes = sanitizeInput($_POST['notes']); +$contact_primary = intval($_POST['primary_contact']); $contact_important = intval($_POST['contact_important']); $contact_billing = intval($_POST['contact_billing']); $contact_technical = intval($_POST['contact_technical']);