-
Notifications
You must be signed in to change notification settings - Fork 1
/
privatefolders.php
187 lines (173 loc) · 6.08 KB
/
privatefolders.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
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
<?php
// Quick redirect to cancel out _POST if nothing was selected
if (isset($_POST['dodel']) && !isset($_POST['delcheck'])) {
return header("Location: ?{$_SERVER['QUERY_STRING']}");
}
require "lib/function.php";
$meta['noindex'] = true;
if (!$loguser['id']) {
errorpage("You need to be logged in to edit your private message folders.", 'login.php', 'log in (then try again)');
}
//$config['pmthread-folder-limit'] = 4;
if ($config['pmthread-folder-limit'] < 0) {
errorpage("The editing of custom folders has been disabled.", 'private.php', 'the private message box');
}
$windowtitle = "Private Message Folders";
$_GET['id'] = filter_int($_GET['id']); // User
$_GET['edit'] = filter_int($_GET['edit']); // Folder edit
$_POST['delcheck'] = filter_array($_POST['delcheck']); // Folder delete
// Viewing someone else?
if (!$isadmin || !valid_user($_GET['id'])) {
$u = $loguser['id'];
$_GET['id'] = 0;
} else {
$u = $_GET['id'];
}
$idparam = opt_param(['id']);
// Endless folders are no fun
if ($config['pmthread-folder-limit']) {
$limit = $sql->resultq("SELECT COUNT(*) FROM pm_folders WHERE user = {$u}");
define('LIMIT_REACHED', $limit >= $config['pmthread-folder-limit']);
unset($limit);
} else {
define('LIMIT_REACHED', false);
}
if (isset($_POST['edit'])) { // Add or edit a folder
check_token($_POST['auth']);
$_POST['title'] = filter_string($_POST['title']);
$_POST['ord'] = filter_int($_POST['ord']);
if (!$_POST['title']) {
errorpage("The folder name cannot be blank.");
}
$sql->beginTransaction();
if ($_GET['edit'] <= -1) {
if (LIMIT_REACHED) {
errorpage("Go delete at least one folder before continuing, okay?", "?{$idparam}", "the folder editor");
}
create_pm_folder($_POST['title'], $u, $_POST['ord']);
} else {
edit_pm_folder($_GET['edit'], $_POST['title'], $u, $_POST['ord']);
}
$sql->commit();
return header("Location: ?{$idparam}");
}
else if ($_POST['delcheck']) { // Delete folders and merge every PM in a new folder
$_POST['delcheck'] = array_map('intval', $_POST['delcheck']);
if (!valid_pm_folder($_POST['delcheck'], $u, true)) {
errorpage("You have selected at least one invalid folder.", "?{$idparam}", "the folder editor");
}
$delfield = "";
foreach ($_POST['delcheck'] as $x) {
$delfield .= "<input type='hidden' name='delcheck[]' value='{$x}'>";
}
$message = "{$delfield}
You are about to delete ".count($_POST['delcheck'])." folder(s).<br>
<br>
All private messages will be moved to the folder below.<br>
".pm_folder_select('mergeid', $u, $_POST['delcheck'], PMSELECT_MERGE);
$form_link = "?{$idparam}";
$buttons = array(
0 => ["Delete folder"],
1 => ["Cancel", "?{$idparam}"]
);
if (confirmpage($message, $form_link, $buttons)) {
$_POST['mergeid'] = filter_int($_POST['mergeid']);
if (in_array($_POST['mergeid'], $_POST['delcheck']) || !valid_pm_folder($_POST['mergeid'], $u)) {
errorpage("No valid folder selected to merge to.", "?{$idparam}", "the folder editor");
}
$sql->beginTransaction(); // All OK
delete_pm_folder($_POST['delcheck'], $_POST['mergeid'], $u);
$sql->commit();
return header("Location: ?{$idparam}");
}
}
pageheader($windowtitle);
$folders = get_pm_folder($u);
if (!$folders) {
$list = "<tr><td class='tdbg1 center' colspan=4><i>No custom folders defined.</i></td></tr>";
} else {
$totals = get_pm_count($u);
$list = "";
foreach ($folders as $x) {
$cell = ($_GET['edit'] == $x['folder'] ? '1' : '2');
$list .= "
<tr>
<td class='tdbg{$cell} center'>
<a href='?{$idparam}&edit={$x['folder']}'>Edit</a>
</td>
<td class='tdbg{$cell}'>
<a href='private.php?{$idparam}&dir={$x['folder']}'>".htmlspecialchars($x['title'])."</a>
</td>
<td class='tdbg{$cell} center'>".filter_int($totals[$x['folder']])."</td>
<td class='tdbg{$cell} center'><input type='checkbox' name='delcheck[]' value='{$x['folder']}'></td>
</tr>";
}
}
if (LIMIT_REACHED) {
$newtag = "Max number of folders reached.";
} else {
$newtag = "<a href='?{$idparam}&edit=-1'>< Create a new folder ></a>";
}
$users_p = ($u != $loguser['id']) ? htmlspecialchars(load_user($u)['name'])."'s p" : "P";
$links = array(
["{$users_p}rivate messages", "private.php?{$idparam}"],
["Manage folders", NULL],
);
$right = "<a href='sendprivate.php?'>New conversation</a> - Manage folders";
?>
<form method="POST" action="?<?=$idparam?>">
<?= dobreadcrumbs($links, $right) ?>
<table class="table">
<tr>
<td class="tdbgh center" style="width: 110px"> </td>
<td class="tdbgh center b">Folder Title</td>
<td class="tdbgh center b" style="width: 40px">PMs</td>
<td class="tdbgh center b" style="width: 110px">Delete</td>
</tr>
<?= $list ?>
<tr>
<td class="tdbg2 center"> </td>
<td class="tdbg2 center" colspan=2><?= $newtag ?></td>
<td class="tdbg2 center"><input type="submit" name="dodel" class="fonts" value="Delete selected"></td>
</tr>
</table>
</form>
<?php
if ($_GET['edit']) { // Edit window
if (!isset($folders[$_GET['edit']])) {
$_GET['edit'] = -1;
$folder = array('title' => '', 'ord' => 0);
$editingWhat = "a new folder";
} else {
$folder = $folders[$_GET['edit']];
$editingWhat = htmlspecialchars($folder['title']);
}
?>
<center>
<form method="post" action="?<?=$idparam?>&edit=<?=$_GET['edit']?>">
<table class='table' style="max-width: 600px">
<tr><td class='tdbgh center' colspan=2>Editing <b><?=$editingWhat?></b></td></tr>
<tr>
<td class='tdbg1 center b' style='width: 140px'>Folder Title:</td>
<td class='tdbg2'><input type="text" name="title" value="<?=htmlspecialchars($folder['title'])?>" size=48 maxlength=64></td>
</tr>
<tr id="ordtr" style="display: none">
<td class='tdbg1 center b'>Reverse priority:</td>
<td class='tdbg2'>
<input type="text" class="right" name="ord" value="<?=$folder['ord']?>" size=3 maxlength=3>
<span class="fonts">Higher the value, further down the list the folder appears.</span>
</td>
</tr>
<tr>
<td class='tdbg1 center'> </td>
<td class="tdbg2">
<input type="submit" name="edit" value="Save settings">
<?= auth_tag() ?>
</td>
</tr>
</table>
</form>
</center>
<?php
}
pagefooter();