summaryrefslogtreecommitdiff
path: root/user.php
blob: 5a841566fc8ddcbced18fcd75f1dab19a44fc5d5 (plain)
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
<?php
include_once 'header.php';
include_once 'includes/db_inc.php';
include_once 'includes/functions_inc.php';
?>

<?php
function nobody_is_here() {
	echo 'Nobody\'s here! <a href=index.php>Go home.</a>';
}

if (!isset($_GET['id'])) {
	nobody_is_here();
} else {
	// If this is the user's own page, show the 'options' bar
	echo '<section>';

	$sql = 'SELECT user_id, user_name, user_date FROM users WHERE user_id=?';
	$stmt = mysqli_stmt_init($dbc);

	if (!mysqli_stmt_prepare($stmt, $sql)) {
		die('Could not create thread due to internal error: ' . mysqli_error($dbc));
	}
	mysqli_stmt_bind_param($stmt, 'i', $_GET['id']);
	mysqli_stmt_execute($stmt);
	$res = mysqli_stmt_get_result($stmt);
	$user = mysqli_fetch_assoc($res);

	if (!$user) {
		nobody_is_here();
	} else {
		echo '<div><h1>'. $user['user_name'] .'</h1></div>';
		echo 'Member since '. date('M d, Y', strtotime($user['user_date']));
	}

	if ($_SESSION['user_id'] == $_GET['id']) {
		echo '<br><p><a href=change_passw.php>Change Password</a></p>';
	}

	echo '</section>';

	$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name, cat_id, cat_name FROM threads JOIN users ON thread_author = user_id JOIN categories ON thread_cat = cat_id WHERE thread_author = " . $user['user_id'] . " ORDER BY thread_id DESC";
	$result = mysqli_query($dbc, $sql);

	if (!$result) {
		die('Error trying to display threads: ' . mysqli_error($dbc));
	}

	echo '<table><tr><th class="left">' . $user['user_name'] . '\'s Threads</th><th class="right">Latest Post</th></tr>';
	display_threads($dbc, $result, true);
	mysqli_free_result($result);
	echo '</table>';
}
?>

<?php include_once 'footer.php'; ?>