<?php
/**
 *  Copyright (C) 2022, 2024  Double Bastion LLC
 *
 *  This file is part of Roundpin, which is licensed under the
 *  GNU Affero General Public License Version 3.0. The license terms
 *  are detailed in the "LICENSE.txt" file located in the root directory.
 */

session_start();

if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {


 define('ACCESSCONST', TRUE);

 require('db-connect.php');

    $contactName = $_POST['contact_name'];
    $contactDesc = $_POST['contact_desc'];
    $contactLongDesc = $_POST['contact_long_desc'];
    $addressStreet = $_POST['address_street'];
    $addressZip = $_POST['address_zip'];
    $addressTown = $_POST['address_town'];
    $addressCountry = $_POST['address_country'];
    $addressState = $_POST['address_state'];
    $extensionNumber = $_POST['extension_number'];
    $contactMobile = $_POST['contact_mobile'];
    $contactNum1 = $_POST['contact_num1'];
    $contactNum2 = $_POST['contact_num2'];
    $contact_fax = $_POST['contact_fax'];
    $contact_email = $_POST['contact_email'];
    $groups = $_POST['groups'];
    $dateModified = $_POST['date_modified'];
    $contactDatabaseID = (int) $_POST['contactDBID'];

    $query4 = $mysqli->prepare("UPDATE `contacts` SET `contact_name`=?, `contact_desc`=?, `contact_long_desc`=?, `address_street`=?, `address_zip`=?, `address_town`=?, 
                               `address_country`=?, `address_state`=?, `extension_number`=?, `contact_mobile`=?, `contact_num1`=?, `contact_num2`=?, `contact_fax`=?, 
                               `contact_email`=?, `groups`=?, `date_modified`=? WHERE `id`=?");
    $query4->bind_param("ssssssssssssssssi", $contactName, $contactDesc, $contactLongDesc, $addressStreet, $addressZip, $addressTown, $addressCountry, $addressState, $extensionNumber, 
                         $contactMobile, $contactNum1, $contactNum2, $contact_fax, $contact_email, $groups, $dateModified, $contactDatabaseID);

    if ($query4->execute()) { $messagetosend = 'success'; } else { $messagetosend = 'An error occurred while attempting to save the data!'; }

    $response = array('result' => $messagetosend);
    echo json_encode($response);

} else {
    header("Location: ../login.php");
}

?>
