-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditprofilex.php
73 lines (62 loc) · 2.32 KB
/
editprofilex.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
<?php
require "lib/function.php";
$_GET['id'] = filter_int($_GET['id']);
if ($isadmin && $_GET['id']) {
$user = $sql->fetchq("SELECT {$userfields}, extrafields FROM users u WHERE id = {$_GET['id']}");
if (!$user)
errorpage("This user doesn't exist.");
} else {
$user = $loguser;
}
if (isset($_POST['submit'])) {
$_POST['del'] = filter_array($_POST['del']);
$_POST['title'] = filter_array($_POST['title']);
$_POST['val'] = filter_array($_POST['val']);
$fields = [];
for ($i = 0, $c = count($_POST['title']); $i < $c; ++$i) {
if (!filter_bool($_POST['del'][$i]) && ($_POST['title'][$i] || $_POST['val'][$i]))
$fields[$_POST['title'][$i]] = filter_string($_POST['val'][$i]);
}
$sql->queryp("UPDATE users SET extrafields = ? WHERE id = ?", [json_encode($fields), $user['id']]);
header("Location: ?id={$user['id']}");
die;
//errorpage("Extra fields updated!", "?id={$user['id']}", "the extra fields editor");
}
pageheader("Extra fields");
$fields = json_decode($user['extrafields'], true);
if (!is_array($fields))
$fields = [];
?>
<form method="POST" action="?id=<?=$_GET['id']?>">
<table class="table">
<tr>
<td class="tdbgc center" colspan=3><?= getuserlink($user) ?>'s profile fields</td>
</tr>
<tr>
<td class="tdbgh center" style="width: 10px">DEL</td>
<td class="tdbgh center" style="width: 250px">Field title</td>
<td class="tdbgh center">Field value</td>
</tr>
<?php
$i = 0;
foreach ($fields as $title => $val) { ?>
<tr>
<td class="tdbg1 center"><input type="checkbox" name="del[<?=$i?>]" value="1"></td>
<td class="tdbg1 vatop"><input type="text" name="title[<?=$i?>]" class="w" style="resize: vertical" value="<?=htmlspecialchars($title)?>"></td>
<td class="tdbg2"><textarea name="val[]" class="w" style="resize: vertical" rows="1"><?=htmlspecialchars($val)?></textarea></td>
</tr>
<?php ++$i;
} ?>
<tr>
<td class="tdbg1 center">-</td>
<td class="tdbg1 vatop"><input type="text" name="title[<?=$i?>]" class="w" style="resize: vertical" value=""></td>
<td class="tdbg2"><textarea name="val[<?=$i?>]" class="w" style="resize: vertical" rows="1"></textarea></td>
</tr>
<tr>
<td class="tdbg1" colspan=2></td>
<td class="tdbg2"><input type="submit" name="submit" value="Save changes"></td>
</tr>
</table>
</form>
<?php
pagefooter();