1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,61 @@ |
1 |
+<?php |
|
2 |
+/** |
|
3 |
+ * Copyright (C) 2021 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 |
+ |
|
15 |
+ define('ACCESSCONST', TRUE); |
|
16 |
+ |
|
17 |
+ require('db-connect.php'); |
|
18 |
+ |
|
19 |
+ $username = $_POST['username']; |
|
20 |
+ $contactName = $_POST['contact_name']; |
|
21 |
+ $contactDesc = $_POST['contact_desc']; |
|
22 |
+ $extensionNumber = $_POST['extension_number']; |
|
23 |
+ $contactMobile = $_POST['contact_mobile']; |
|
24 |
+ $contactNum1 = $_POST['contact_num1']; |
|
25 |
+ $contactNum2 = $_POST['contact_num2']; |
|
26 |
+ $contact_email = $_POST['contact_email']; |
|
27 |
+ |
|
28 |
+ // Get the id of the user for which we want to insert the contact data |
|
29 |
+ $query1 = $mysqli->query("SELECT id, username, enabled FROM app_users WHERE BINARY username = '$username' AND enabled = 1"); |
|
30 |
+ $queryres = $query1->fetch_array(); |
|
31 |
+ $userID = $queryres[0]; |
|
32 |
+ |
|
33 |
+ // Check if the contact is already in the 'contacts' table |
|
34 |
+ $query2 = $mysqli->prepare("SELECT id, user_id, contact_name FROM contacts WHERE user_id=? AND contact_name=?"); |
|
35 |
+ $query2->bind_param("is", $userID, $contactName); |
|
36 |
+ $query2->execute(); |
|
37 |
+ $fetchInfo = $query2->get_result(); |
|
38 |
+ $contactdata = $fetchInfo->fetch_row(); |
|
39 |
+ $contactExists = $contactdata[0]; |
|
40 |
+ |
|
41 |
+ $currentTime = date('Y-m-d H:i:s'); |
|
42 |
+ |
|
43 |
+ if ($contactExists == '') { |
|
44 |
+ $query3 = $mysqli->prepare("INSERT INTO contacts (user_id, contact_name, contact_desc, extension_number, contact_mobile, contact_num1, contact_num2, |
|
45 |
+ contact_email, date_added) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
|
46 |
+ $query3->bind_param("issssssss", $userID, $contactName, $contactDesc, $extensionNumber, $contactMobile, $contactNum1, $contactNum2, $contact_email, $currentTime); |
|
47 |
+ |
|
48 |
+ if ($query3->execute()) { |
|
49 |
+ $messagetosend = 'success'; |
|
50 |
+ } else { $messagetosend = 'An error occurred while attempting to save the contact to the database!'; } |
|
51 |
+ |
|
52 |
+ } else { $messagetosend = 'Error! A contact with the same name is already in the database!'; } |
|
53 |
+ |
|
54 |
+ $response = array('result' => $messagetosend); |
|
55 |
+ echo json_encode($response); |
|
56 |
+ |
|
57 |
+} else { |
|
58 |
+ header("Location: roundpin-login.php"); |
|
59 |
+} |
|
60 |
+ |
|
61 |
+?> |