| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,83 @@ |
| 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 |
+ // header('Set-Cookie: PHPSESSID= ' . session_id() . '; SameSite=strict; Secure=true; HttpOnly=true;');
|
|
| 12 |
+ |
|
| 13 |
+if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {
|
|
| 14 |
+ |
|
| 15 |
+ define('ACCESSCONST', TRUE);
|
|
| 16 |
+ |
|
| 17 |
+ require('db-connect.php');
|
|
| 18 |
+ |
|
| 19 |
+ $username = $_POST['username']; |
|
| 20 |
+ $startDate = $_POST['delstartdate']; |
|
| 21 |
+ $endDate = $_POST['delenddate']; |
|
| 22 |
+ $startDateFmt = new DateTime($startDate . " 00:00:00"); |
|
| 23 |
+ $endDateFmt = new DateTime($endDate . " 24:59:59"); |
|
| 24 |
+ |
|
| 25 |
+ // Get the id of the current user from the 'app_users' table |
|
| 26 |
+ $queryid = $mysqli->prepare("SELECT id, username FROM app_users WHERE BINARY username = ?");
|
|
| 27 |
+ $queryid->bind_param("s", $username);
|
|
| 28 |
+ $queryid->execute(); |
|
| 29 |
+ $queryres = $queryid->get_result()->fetch_assoc(); |
|
| 30 |
+ $userID = $queryres['id']; |
|
| 31 |
+ |
|
| 32 |
+ // Get the contacts for the current user |
|
| 33 |
+ $querycont = $mysqli->prepare("SELECT id, user_id, contact_name, contact_desc, contact_long_desc, address_street, address_zip, address_town, address_country, address_state,
|
|
| 34 |
+ extension_number, contact_mobile, contact_num1, contact_num2, contact_fax, contact_email, profile_picture_c, groups, date_added, date_modified |
|
| 35 |
+ FROM contacts WHERE user_id = ?"); |
|
| 36 |
+ $querycont->bind_param("i", $userID);
|
|
| 37 |
+ $querycont->execute(); |
|
| 38 |
+ $queryres = $querycont->get_result(); |
|
| 39 |
+ |
|
| 40 |
+ $msgdel = 0; |
|
| 41 |
+ while ($querycontres = $queryres->fetch_assoc()) {
|
|
| 42 |
+ |
|
| 43 |
+ $dateAddedFmt = new DateTime($querycontres['date_added']); |
|
| 44 |
+ |
|
| 45 |
+ if ($startDate == "" && $endDate != "") {
|
|
| 46 |
+ |
|
| 47 |
+ if ($dateAddedFmt <= $endDateFmt) {
|
|
| 48 |
+ |
|
| 49 |
+ // Remove the contact from the 'contacts' table |
|
| 50 |
+ $querycont = $mysqli->prepare("DELETE FROM contacts WHERE id = ? AND user_id = ?");
|
|
| 51 |
+ $querycont->bind_param("ii", $querycontres['id'], $userID);
|
|
| 52 |
+ if ($querycont->execute()) { /* OK */ } else { $msgdel++; }
|
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ } elseif ($startDate != "" && $endDate != "") {
|
|
| 56 |
+ |
|
| 57 |
+ if ($startDateFmt <= $dateAddedFmt && $dateAddedFmt <= $endDateFmt) {
|
|
| 58 |
+ |
|
| 59 |
+ // Remove the contact from the 'contacts' table |
|
| 60 |
+ $querycont = $mysqli->prepare("DELETE FROM contacts WHERE id = ? AND user_id = ?");
|
|
| 61 |
+ $querycont->bind_param("ii", $querycontres['id'], $userID);
|
|
| 62 |
+ if ($querycont->execute()) { /* OK */ } else { $msgdel++; }
|
|
| 63 |
+ } |
|
| 64 |
+ } |
|
| 65 |
+ } |
|
| 66 |
+ |
|
| 67 |
+ if ($msgdel == 0) { $messagedel = "success"; } else { $messagedel = "failure"; }
|
|
| 68 |
+ |
|
| 69 |
+ // Reindex the 'contacts' table |
|
| 70 |
+ $reindexset = $mysqli->prepare("SET @resetrec = 0");
|
|
| 71 |
+ $reindexup = $mysqli->prepare("UPDATE contacts SET id = @resetrec := @resetrec + 1");
|
|
| 72 |
+ $reindexalt = $mysqli->prepare("ALTER TABLE contacts auto_increment = 1");
|
|
| 73 |
+ if ($reindexset->execute() && $reindexup->execute() && $reindexalt->execute()) { $reindexmsg = "success"; } else { $reindexmsg = "failure"; }
|
|
| 74 |
+ |
|
| 75 |
+ $delresult = array('removeresult' => $messagedel, 'reindex' => $reindexmsg);
|
|
| 76 |
+ |
|
| 77 |
+ echo json_encode($delresult); |
|
| 78 |
+ |
|
| 79 |
+} else {
|
|
| 80 |
+ header("Location: ../login.php");
|
|
| 81 |
+} |
|
| 82 |
+ |
|
| 83 |
+?> |