summaryrefslogtreecommitdiffstats
path: root/web/html/account.php
blob: 7c6c424aca0dd10a5a3098738e1b7e66567d1714 (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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');

include_once('aur.inc.php');         # access AUR common functions
include_once('acctfuncs.inc.php');   # access Account specific functions

$action = in_request("Action");

$need_userinfo = array(
	"DisplayAccount", "DeleteAccount", "AccountInfo", "UpdateAccount", "ListComments"
);

if (in_array($action, $need_userinfo)) {
	$row = account_details(in_request("ID"), in_request("U"));
	$PK = implode("\n", account_get_ssh_keys($row["ID"]));
}

/* This has to be done before the navigation headers are written,
 * because html_header() fetches the current username from the database,
 * which could be changed by process_account_form()
 */
if ($action == "UpdateAccount") {
	$success = false;
	$update_account_message = '';
	/* Details for account being updated */
	/* Verify user permissions and that the request is a valid POST */
	if (can_edit_account($row) && check_token()) {
		/* Update the details for the existing account */
		list($success, $update_account_message) = process_account_form(
			"edit", "UpdateAccount",
			in_request("U"),
			in_request("T"),
			in_request("S"),
			in_request("E"),
			in_request("H"),
			in_request("PO"),
			in_request("P"),
			in_request("C"),
			in_request("R"),
			in_request("L"),
			in_request("TZ"),
			in_request("HP"),
			in_request("I"),
			in_request("K"),
			in_request("PK"),
			in_request("J"),
			in_request("CN"),
			in_request("UN"),
			in_request("ON"),
			in_request("ID"),
			$row["Username"]);
	}
}

if ($action == "AccountInfo") {
	html_header(__('Account') . ' ' . $row['Username']);
} else {
	html_header(__('Accounts'));
}

# Main page processing here
#
echo "<div class=\"box\">\n";
echo "  <h2>".__("Accounts")."</h2>\n";

if (isset($_COOKIE["AURSID"])) {
	if ($action == "SearchAccounts") {

		# security check
		#
		if (has_credential(CRED_ACCOUNT_SEARCH)) {
			# the user has entered search criteria, find any matching accounts
			#
			search_results_page(in_request("O"), in_request("SB"),
					in_request("U"), in_request("T"), in_request("S"),
					in_request("E"), in_request("R"), in_request("I"),
					in_request("K"));

		} else {
			# a non-privileged user is trying to access the search page
			#
			print __("You are not allowed to access this area.")."<br />\n";
		}

	} elseif ($action == "DisplayAccount") {
		# the user has clicked 'edit', display the account details in a form
		#
		if (empty($row)) {
			print __("Could not retrieve information for the specified user.");
		} else {
			/* Verify user has permission to edit the account */
			if (can_edit_account($row)) {
				display_account_form("UpdateAccount",
					$row["Username"],
					$row["AccountTypeID"],
					$row["Suspended"],
					$row["Email"],
					$row["HideEmail"],
					"",
					"",
					$row["RealName"],
					$row["LangPreference"],
					$row["Timezone"],
					$row["Homepage"],
					$row["IRCNick"],
					$row["PGPKey"],
					$PK,
					$row["InactivityTS"] ? 1 : 0,
					$row["CommentNotify"],
					$row["UpdateNotify"],
					$row["OwnershipNotify"],
					$row["ID"],
					$row["Username"]);
			} else {
				print __("You do not have permission to edit this account.");
			}
		}

	} elseif ($action == "DeleteAccount") {
		/* Details for account being deleted. */
		if (can_edit_account($row)) {
			$UID = $row['ID'];
			if (in_request('confirm') && check_token()) {
				user_delete($UID);
				header('Location: /');
			} else {
				$username = $row['Username'];
				include("account_delete.php");
			}
		} else {
			print __("You do not have permission to edit this account.");
		}
	} elseif ($action == "AccountInfo") {
		# no editing, just looking up user info
		#
		if (empty($row)) {
			print __("Could not retrieve information for the specified user.");
		} else {
			include("account_details.php");
		}

	} elseif ($action == "UpdateAccount") {
		print $update_account_message;

		if (!$success) {
			display_account_form("UpdateAccount",
				in_request("U"),
				in_request("T"),
				in_request("S"),
				in_request("E"),
				in_request("H"),
				in_request("P"),
				in_request("C"),
				in_request("R"),
				in_request("L"),
				in_request("TZ"),
				in_request("HP"),
				in_request("I"),
				in_request("K"),
				in_request("PK"),
				in_request("J"),
				in_request("CN"),
				in_request("UN"),
				in_request("ON"),
				in_request("ID"),
				$row["Username"]);
		}

	} elseif ($action == "ListComments") {
		if (has_credential(CRED_ACCOUNT_LIST_COMMENTS, array($row["ID"]))) {
			# display the comment list if they're a TU/dev

			$total_comment_count = account_comments_count($row["ID"]);
			list($pagination_templs, $per_page, $offset) = calculate_pagination($total_comment_count);

			$username = $row["Username"];
			$uid = $row["ID"];
			$comments = account_comments($uid, $per_page, $offset);

			$comment_section = "account";
			include('pkg_comments.php');

		} else {
			print __("You are not allowed to access this area.");
		}

	} else {
		if (has_credential(CRED_ACCOUNT_SEARCH)) {
			# display the search page if they're a TU/dev
			#
			print __("Use this form to search existing accounts.")."<br />\n";
			include('search_accounts_form.php');

		} else {
			print __("You are not allowed to access this area.");
		}
	}

} else {
	# visitor is not logged in
	#
	print __("You must log in to view user information.");
}

echo "</div>";

html_footer(AURWEB_VERSION);

?>