-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
170 lines (159 loc) · 7.17 KB
/
Copy pathmain.php
File metadata and controls
170 lines (159 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
session_start(); // Start the session
// Check if the user is logged in (i.e., username session is set)
if (!isset($_SESSION['userid'])) {
// If not logged in, redirect to the login page
header("Location: login.html");
exit;
}
$userid = $_SESSION['userid']; // Get the username from the session
$dispname = $_SESSION['dispname']; // Get the username from the session
include 'config.php';
// Establish database connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(json_encode(['success' => false, 'message' => 'Database connection failed: ' . $conn->connect_error]));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wish List</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="page-container">
<div class="header-container">
<h1>Family Gift List</h1>
<button class="global-button" id="passwd" onclick="location.href='changePasswd.php'">Change Password</button>
</div>
<div class="column-container" id="table-container">
<?php
$access_stmt = $conn->prepare("SELECT can_view, dispname FROM access inner join users on access.can_view = users.id WHERE uid = ? order by users.id");
if (!$access_stmt) die("failed to prepare statement");
$access_stmt->bind_param("s", $userid); // Bind the username parameter
$access_stmt->execute();
$access_result = $access_stmt->get_result();
$stmt = $conn->prepare("SELECT id,text,link,recurring,claimed FROM list WHERE userid = ?");
if (!$stmt) die("failed to prepare statement");
$person = NULL;
do {
echo '
<div class="column"';
if ($person == NULL) echo 'id="column-1"';
echo '>
<h2>';
if ($person == NULL) echo $dispname;
else echo $person['dispname'];
echo '</h2>
<table>';
if ($person == NULL) $stmt->bind_param("i", $userid); // Bind the username parameter
else $stmt->bind_param("i", $person['can_view']);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$notes = '';
$userClaimed = false;
$userItem = NULL;
if ($person != NULL && $row['recurring']) {
$getNotes = $conn->prepare('select note from notes where itemid = ?;');
$getNotes->bind_param("i", $row['id']);
$getNotes->execute();
$allNotes = $getNotes->get_result();
while ($next_note = $allNotes->fetch_assoc()) $notes = $notes . $next_note['note'] . ', ';
if (strlen($notes) > 1) $notes = substr($notes, 0, -2);
if (!$notes) $notes = 'none';
$getNotes->close();
$getNotes = $conn->prepare('select note from notes where itemid = ? && userid = ?;');
$getNotes->bind_param('ii', $row['id'], $userid);
$getNotes->execute();
$rows = $getNotes->get_result()->fetch_row();
$userClaimed = $rows !== NULL;
if ($userClaimed) $userItem = $rows[0];
if ($userItem) $userItem = " <b>(you: " . $userItem . ')</b>';
$getNotes->close();
}
$claimed_button_code = 'type="button" onclick="openDatePicker(' . $row['id'] . ',\'' . $notes . '\')"';
if ($row['claimed'] == $userid || $userClaimed) {
$claimed_button_code = 'type="submit" style="background-color: red"';
}
$row_classes = '';
if ($person != NULL && ($userClaimed || $row['claimed'] && !$row['recurring'])) $row_classes .= 'claimed ';
if ($person == NULL && $row['recurring']) $row_classes .= 'recurring ';
echo "
<tr class=\"$row_classes\" id=\"item${row['id']}\">
<td>${row['text']}$userItem</td>
<td class=\"buttons\">";
if ($row['link']) echo '
<a class="button" href="'.$row['link'].'"><img class="icon" src="icon_open.png"></a>';
echo '
<form action="listEdit.php" method="post">
<input hidden name="itemid" value="' . $row['id'] . '">';
if ($person == NULL) echo '
<button type="button" onclick="openItemWindow(' . $row['id'] .', '. $row['recurring'] .')" name="edit" class="edit">
<img class="icon" src="icon_edit.png" />
</button>
<button type="submit" name="delete" class="trash">
<img class="icon" src="icon_delete.png">
</button>';
else if (!$row['claimed'] || $row['claimed'] == $userid || $row['recurring']) echo '
<button '.$claimed_button_code.' name="unclaim" class="check">
<img class="icon" src="icon_check.png" />
</button>';
echo '
</form>
</td>
</tr>';
}
echo '
</table>';
if ($person == NULL) echo '
<p>Green highlight denotes multiple items</p>
<button class="global-button check" onclick="openItemWindow(0,\'\')">Add New</button>';
echo '
</div>';
} while ($person = $access_result->fetch_assoc());
$stmt->close();
$access_stmt->close();
?>
</div>
</div>
<div id="datePickerModal" class="modal">
<div class="modal-content">
<form action="listEdit.php" method="post">
<h2>Select date gift will be opened</h2>
<input required type="date" id="selectedDate" name="giftDate">
<div id="multiple-notes">
<p>Already taken:</p>
<p id="notes-text"></p>
<input name="note" id="userNote" type="text" maxlength="20" placeholder="color, type, etc">
</div>
<input hidden name="itemid" id="dateItemId" value="0">
<div class="button-container">
<button class="dateSubmit" name="claim">Claim</button>
<button class="dateSubmit trash" id="closeDateForm">Close</button>
</div>
</form>
</div>
</div>
<div id="itemModal" class="modal">
<div class="modal-content">
<form action="addItem.php" method="post">
<h2>Enter item information</h2>
<input name="item" id="desc" type="text" maxlength="255" placeholder="description" required>
<textarea name="link" id="link" type="text" maxlength="400" placeholder="link [optional]"></textarea>
<input type="checkbox" name="recurring" id="recurring">
<label for="recurring">Multiple</label>
<input hidden name="itemid" id="editItemId" value="0">
<div class="button-container">
<button class="dateSubmit" name="submit">Done</button>
<button class="dateSubmit trash" id="closeItemForm">Close</button>
</div>
</form>
</div>
</div>
<script src="main.js"></script>
</body>
</html>