<?php
/**
 *  Copyright (C) 2021  Cover Tower 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'];
    $extensionNumber = $_POST['extension_number'];
    $contactMobile = $_POST['contact_mobile'];
    $contactNum1 = $_POST['contact_num1'];
    $contactNum2 = $_POST['contact_num2'];
    $contact_email = $_POST['contact_email'];
    $contactDatabaseID = (int) $_POST['contactDBID'];

    $currentTime = date('Y-m-d H:i:s');

    $query4 = $mysqli->prepare("UPDATE `contacts` SET `contact_name`=?, `contact_desc`=?, `extension_number`=?, `contact_mobile`=?, `contact_num1`=?, `contact_num2`=?,
                                `contact_email`=?, `date_modified`=? WHERE `id`=?");
    $query4->bind_param("ssssssssi", $contactName, $contactDesc, $extensionNumber, $contactMobile, $contactNum1, $contactNum2, $contact_email, $currentTime, $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: roundpin-login.php");
}

?>