-
Notifications
You must be signed in to change notification settings - Fork 29
/
news.php
189 lines (145 loc) · 7.3 KB
/
news.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
188
189
<?php
/*
// +--------------------------------------------------------------------------+
// | Project: TBDevYSE - TBDev Yuna Scatari Edition |
// +--------------------------------------------------------------------------+
// | This file is part of TBDevYSE. TBDevYSE is based on TBDev, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | TBDevYSE is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | TBDevYSE is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with TBDevYSE; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
require "include/bittorrent.php";
dbconn();
loggedinorreturn();
if (get_user_class() < UC_ADMINISTRATOR)
stderr($tracker_lang['error'], 'Îøèáêà äîñòóïà.');
$action = (string)$_GET["action"];
///////// Óäàëåíèÿ íîâîñòåé /////////
if ($action == 'delete')
{
$newsid = (int)$_GET["newsid"];
if (!is_valid_id($newsid))
stderr($tracker_lang['error'], 'Íåâåðíûé èäåíòèôèêàòîð.');
$sure = $_GET["sure"];
if (!$sure)
stderr('Óäàëèòü íîâîñòü', 'Âû äåéñòâèòåëíüî õîòèòå óäàëèòü ýòó íîâîñòü? Íàæìèòå <a href="?action=delete&newsid='.$newsid.'&sure=1">ñþäà</a> åñëè âû óâåðåíû.');
sql_query("DELETE FROM news WHERE id=$newsid") or sqlerr(__FILE__, __LINE__);
$warning = 'Íîâîñòü <b>óñïåøíî</b> óäàëåíà';
}
///////// Äîáàâëåíèÿ íîâîñòåé /////////
if ($action == 'add')
{
$subject = $_POST["subject"];
if (!$subject)
stderr($tracker_lang['error'], 'Òåìà íîâîñòè íå ìîæåò áûòü ïóñòîé!');
$body = $_POST["body"];
if (!$body)
stderr($tracker_lang['error'], 'Òåëî íîâîñòè íå ìîæåò áûòü ïóñòûì!');
sql_query("INSERT INTO news (userid, added, body, subject) VALUES (" . $CURUSER['id'] . ", NOW(), " . sqlesc($body) . ", " . sqlesc($subject) . ")") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 1)
$warning = 'Íîâîñòü <b>óñïåøíî äîáàâëåíà</b>';
else
stderr($tracker_lang['error'], 'Îøèáêà çàïðîñà.');
}
///////// Ðåäàêòèðîâàíèÿ íîâîñòåé /////////
if ($action == 'edit')
{
$newsid = (int)$_GET["newsid"];
if (!is_valid_id($newsid))
stderr($tracker_lang['error'], 'Íåâåðíûé èäåíòèôèêàòîð.');
$res = sql_query("SELECT * FROM news WHERE id=$newsid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr($tracker_lang['error'], "Íîâîñòü íå íàéäåíî.");
$arr = mysql_fetch_array($res);
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$body = $_POST['body'];
$subject = $_POST['subject'];
if ($subject == '')
stderr($tracker_lang['error'], 'Òåìà íîâîñòè íå ìîæåò áûòü ïóñòîé!');
if ($body == '')
stderr($tracker_lang['error'], 'Òåëî íîâîñòè íå ìîæåò áûòü ïóñòûì!');
$body = sqlesc($body);
$subject = sqlesc($subject);
sql_query("UPDATE news SET body=$body, subject=$subject WHERE id=$newsid") or sqlerr(__FILE__, __LINE__);
$warning = 'Íîâîñòü <b>óñïåøíî</b> îòðåäàêòèðîâàíà';
} else {
$returnto = htmlentities($_GET['returnto']);
stdhead("Ðåäàêòèðîâàíèå íîâîñòè");
echo '<form name="news" method=post action=?action=edit&newsid='.$newsid.'>';
echo '<table border=1 cellspacing=0 cellpadding=5>';
echo '<tr><td class=colhead>Ðåäàêòèðîâàíèå íîâîñòè</td></tr>';
echo '<tr><td>Òåìà: <input type=text name=subject maxlength=70 size=50 value="' . htmlspecialchars_uni($arr["subject"]) . '"/></td></tr>';
echo '<tr><td>';
echo textbbcode("news", "body", htmlspecialchars_uni($arr["body"]));
echo '</td></tr>';
echo '<input type=hidden name=returnto value='.$returnto.'>';
echo '<tr><td align=center><input type=submit value="Îòðåäàêòèðîâàòü"></td></tr>';
echo '</table>';
echo '</form>';
stdfoot();
die;
}
}
stdhead("Íîâîñòè");
if ($warning)
echo '<p><font size=-3>('.$warning.')</font></p>';
echo '<form name="news" method="post" action="?action=add">';
echo '<table border=1 cellspacing=0 cellpadding=5>';
echo '<tr><td class=colhead>Äîáàâèòü íîâîñòü</td></tr>';
echo '<tr><td>Òåìà: <input type=text name=subject maxlength=40 size=50 value="' . htmlspecialchars_uni($arr["subject"]) . '"/></td></tr>';
echo '<tr><td>';
echo textbbcode("news", "body");
echo '</td></tr>';
echo '<tr><td align=center><input type="submit" value="Äîáàâèòü" class="btn"></td></tr>';
echo '</table>';
echo '</form><br /><br />';
$query = sql_query("SELECT news.*, users.username FROM news LEFT JOIN users ON news.userid = users.id ORDER BY news.added DESC") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($query) > 0)
{
begin_main_frame();
begin_frame();
while ($result = mysql_fetch_array($query))
{
$newsid = $result["id"];
$body = $result["body"];
$subject = $result["subject"];
$userid = $result["userid"];
$added = $result["added"] . ' GMT (' . (get_elapsed_time(sql_timestamp_to_unix_timestamp($result["added"]))) . ' íàçàä)';
$username = $result["username"];
if ($username == "")
$by = 'Íåèçâåñòíî ['.$userid.']';
else
$by = '<a href="userdetails.php?id='.$userid.'"><b>'.$username.'</b></a>';
echo '<p class=sub><table border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>';
echo 'Äîáàâëåíà '.$added.' - '.$by;
echo ' - [<a href="?action=edit&newsid='.$newsid.'"><b>Ðåäàêòèðîâàòü</b></a>]';
echo ' - [<a href="?action=delete&newsid='.$newsid.'"><b>Óäàëèòü</b></a>]';
echo '</td></tr></table></p>';
begin_table(true);
echo '<tr valign=top><td><b>'.htmlspecialchars_uni($subject).'</b></td></tr>';
echo '<tr valign=top><td class=comment>'.format_comment($body).'</td></tr>';
end_table();
}
end_frame();
end_main_frame();
}
else
stdmsg('Èçâèíèòå', 'Íîâîñòåé íåò!');
stdfoot();