| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,79 @@ |
| 1 |
+<?php |
|
| 2 |
+/** |
|
| 3 |
+ * Copyright (C) 2022, 2024 Double Bastion LLC |
|
| 4 |
+ * |
|
| 5 |
+ * This file is part of Roundpin, which is licensed under the |
|
| 6 |
+ * GNU Affero General Public License Version 3.0. The license terms |
|
| 7 |
+ * are detailed in the "LICENSE.txt" file located in the root directory. |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+session_start(); |
|
| 11 |
+ |
|
| 12 |
+if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {
|
|
| 13 |
+ |
|
| 14 |
+ define('ACCESSCONST', TRUE);
|
|
| 15 |
+ |
|
| 16 |
+ require('db-connect.php');
|
|
| 17 |
+ |
|
| 18 |
+ $username = $_POST['username']; |
|
| 19 |
+ $contactName = $_POST['contact_name']; |
|
| 20 |
+ $contactDesc = $_POST['contact_desc']; |
|
| 21 |
+ $contactLongDesc = $_POST['contact_long_desc']; |
|
| 22 |
+ $addressStreet = $_POST['address_street']; |
|
| 23 |
+ $addressZip = $_POST['address_zip']; |
|
| 24 |
+ $addressTown = $_POST['address_town']; |
|
| 25 |
+ $addressCountry = $_POST['address_country']; |
|
| 26 |
+ $addressState = $_POST['address_state']; |
|
| 27 |
+ $extensionNumber = $_POST['extension_number']; |
|
| 28 |
+ $contactMobile = $_POST['contact_mobile']; |
|
| 29 |
+ $contactNum1 = $_POST['contact_num1']; |
|
| 30 |
+ $contactNum2 = $_POST['contact_num2']; |
|
| 31 |
+ $contact_fax = $_POST['contact_fax']; |
|
| 32 |
+ $contact_email = $_POST['contact_email']; |
|
| 33 |
+ $groups = $_POST['groups']; |
|
| 34 |
+ $dateAdded = $_POST['date_added']; |
|
| 35 |
+ $dateModified = $_POST['date_modified']; |
|
| 36 |
+ |
|
| 37 |
+ // Get the id of the user for which we want to insert the contact data |
|
| 38 |
+ $query1 = $mysqli->prepare("SELECT id, username FROM app_users WHERE BINARY username = ?");
|
|
| 39 |
+ $query1->bind_param("s", $username);
|
|
| 40 |
+ $query1->execute(); |
|
| 41 |
+ $queryres = $query1->get_result()->fetch_assoc(); |
|
| 42 |
+ $userID = $queryres['id']; |
|
| 43 |
+ |
|
| 44 |
+ // Check if the contact is already in the 'contacts' table |
|
| 45 |
+ $query2 = $mysqli->prepare("SELECT id, user_id, contact_name FROM contacts WHERE user_id = ? AND contact_name = ?");
|
|
| 46 |
+ $query2->bind_param("is", $userID, $contactName);
|
|
| 47 |
+ $query2->execute(); |
|
| 48 |
+ $fetchInfo = $query2->get_result()->fetch_assoc(); |
|
| 49 |
+ |
|
| 50 |
+ if (!$fetchInfo) {
|
|
| 51 |
+ |
|
| 52 |
+ $query3 = $mysqli->prepare("INSERT INTO contacts (user_id, contact_name, contact_desc, contact_long_desc, address_street, address_zip, address_town, address_country,
|
|
| 53 |
+ address_state, extension_number, contact_mobile, contact_num1, contact_num2, contact_fax, contact_email, groups, date_added, date_modified) |
|
| 54 |
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
|
| 55 |
+ $query3->bind_param("isssssssssssssssss", $userID, $contactName, $contactDesc, $contactLongDesc, $addressStreet, $addressZip, $addressTown, $addressCountry, $addressState,
|
|
| 56 |
+ $extensionNumber, $contactMobile, $contactNum1, $contactNum2, $contact_fax, $contact_email, $groups, $dateAdded, $dateModified); |
|
| 57 |
+ |
|
| 58 |
+ if ($query3->execute()) {
|
|
| 59 |
+ $messagetosend1 = 'success'; |
|
| 60 |
+ } else { $messagetosend1 = 'An error occurred while attempting to save the contact to the database!'; }
|
|
| 61 |
+ |
|
| 62 |
+ // Reindex the 'contacts' table |
|
| 63 |
+ $reindexset = $mysqli->prepare("SET @resetrec = 0");
|
|
| 64 |
+ $reindexup = $mysqli->prepare("UPDATE contacts SET id = @resetrec := @resetrec + 1");
|
|
| 65 |
+ $reindexalt = $mysqli->prepare("ALTER TABLE contacts auto_increment = 1");
|
|
| 66 |
+ if ($reindexset->execute() && $reindexup->execute() && $reindexalt->execute()) { $messagetosend2 = 'success'; } else { $messagetosend2 = 'failure'; }
|
|
| 67 |
+ |
|
| 68 |
+ if ($messagetosend1 == 'success' && $messagetosend2 == 'success') { $messagetosend = 'success'; } else { $messagetosend = 'Error while saving the data'; }
|
|
| 69 |
+ |
|
| 70 |
+ } else { $messagetosend = 'Error! A contact with the same name is already in the database!'; }
|
|
| 71 |
+ |
|
| 72 |
+ $response = array('result' => $messagetosend);
|
|
| 73 |
+ echo json_encode($response); |
|
| 74 |
+ |
|
| 75 |
+} else {
|
|
| 76 |
+ header("Location: ../login.php");
|
|
| 77 |
+} |
|
| 78 |
+ |
|
| 79 |
+?> |