This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
userinfo.php
148 lines (113 loc) · 3.18 KB
/
userinfo.php
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
<?php
/**
* Make sure you started your'e sessions!
* You need to include su.inc.php to make SimpleUsers Work
* After that, create an instance of SimpleUsers and your'e all set!
*/
session_start();
require_once(dirname(__FILE__)."/simpleusers/su.inc.php");
$SimpleUsers = new SimpleUsers();
// This is a simple way of validating if a user is logged in or not.
// If the user is logged in, the value is (bool)true - otherwise (bool)false.
if( !$SimpleUsers->logged_in )
{
header("Location: login.php");
exit;
}
// If the user is logged in, we can safely proceed.
$userId = $_GET["userId"];
$user = $SimpleUsers->getSingleUser($userId);
if( !$user )
die("The user could not be found...");
$userInfo = $SimpleUsers->getInfoArray($userId);
if( isset($_POST["newkey"]) )
{
if( strlen($_POST["newkey"]) > 0 ) {
try {
$SimpleUsers->setInfo($_POST["newkey"], $_POST["newvalue"], $userId);
}
catch (Exception $e) {
// Ignore errors for this demo purpose
}
}
if( isset($_POST["userInfo"]) )
{
foreach ($_POST["userInfo"] as $pKey => $pValue) {
try {
$SimpleUsers->setInfo($pKey, $pValue, $userId);
}
catch (Exception $e) {
// Ignore errors for this demo purpose
}
}
}
header("Location: users.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
* { margin: 0px; padding: 0px; }
body
{
padding: 30px;
font-family: Calibri, Verdana, "Sans Serif";
font-size: 12px;
}
table
{
width: 800px;
margin: 0px auto;
}
th, td
{
padding: 3px;
}
.right
{
text-align: right;
}
h1
{
color: #FF0000;
border-bottom: 2px solid #000000;
margin-bottom: 15px;
}
p { margin: 10px 0px; }
p.faded { color: #A0A0A0; }
</style>
</head>
<body>
<h1>User information for <?php echo $user["uUsername"]; ?></h1>
<?php if( isset($error) ): ?>
<p>
<?php echo $error; ?>
</p>
<?php endif; ?>
<form method="post" action="">
<?php foreach($userInfo as $key => $value): ?>
<p>
<label for="db_<?php echo $key; ?>">Database key "<?php echo $key; ?>"</label><br />
<input type="text" name="userInfo[<?php echo $key; ?>]" id="db_<?php echo $key; ?>" value="<?php echo htmlspecialchars($value); ?>" /><br />
<a href="removeinfo.php?userId=<?php echo $userId; ?>&db_key=<?php echo urlencode($key); ?>">Permanently remove this key</a>
</p>
<?php endforeach; ?>
<h4>Create new database key?</h4>
<p>
<label for="newkey">Key name</label><br />
<input type="text" name="newkey" id="newkey" />
</p>
<p>
<label for="newvalue">Key value</label><br />
<input type="text" name="newvalue" id="newvalue" />
</p>
<p>
<input type="submit" name="submit" value="Save" />
</p>
</form>
</body>
</html>