Browse code

Changed majority of files.

DoubleBastionAdmin authored on 30/11/2024 06:56:40
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,78 @@
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
+    $selectedGroups = $_POST['selectedgroups'];
21
+    $selectedGroupsArr = explode("|", $selectedGroups);
22
+    array_shift($selectedGroupsArr);
23
+    array_pop($selectedGroupsArr);   
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
+           $contactGroupsArr = explode("|", $querycontres['groups']);
44
+           array_shift($contactGroupsArr);
45
+           array_pop($contactGroupsArr);
46
+
47
+           $gck = 0;
48
+           foreach ($contactGroupsArr as $key => $arrval) {
49
+                    if (in_array($arrval, $selectedGroupsArr)) { $gck++; }
50
+           }
51
+
52
+           if ($gck > 0) {
53
+
54
+	       // Remove the contact from the 'contacts' table
55
+	       $querycont = $mysqli->prepare("DELETE FROM contacts WHERE id = ? AND user_id = ?");
56
+	       $querycont->bind_param("ii", $querycontres['id'], $userID);
57
+	       if ($querycont->execute()) { /* OK */ } else { $msgdel++; }
58
+
59
+           }
60
+    }
61
+
62
+    if ($msgdel == 0) { $messagedel = "success"; } else { $messagedel = "failure"; }
63
+
64
+    // Reindex the 'contacts' table
65
+    $reindexset = $mysqli->prepare("SET @resetrec = 0");
66
+    $reindexup = $mysqli->prepare("UPDATE contacts SET id = @resetrec := @resetrec + 1");
67
+    $reindexalt = $mysqli->prepare("ALTER TABLE contacts auto_increment = 1");
68
+    if ($reindexset->execute() && $reindexup->execute() && $reindexalt->execute()) { $reindexmsg = "success"; } else { $reindexmsg = "failure"; }
69
+
70
+    $delresult = array('removeresult' => $messagedel, 'reindex' => $reindexmsg);
71
+
72
+    echo json_encode($delresult);
73
+
74
+} else {
75
+        header("Location: ../login.php");
76
+}
77
+
78
+?>