When Adding new client add contact as important as well, when assigning a new contact as primary contact label them as important updated the logic add and edit logic to include the new field primary contact field under contacts

This commit is contained in:
johnnyq 2023-07-03 17:31:37 -04:00
parent 70a080a24e
commit 18274d532e
3 changed files with 15 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -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']);