root/reports.php

Revision 317, 8.0 kB (checked in by Nafania, 2 years ago)

Изменена функция pager немного, для удобного построения LIMIT запросов.
Мелкие фиксы.
Обновлен jquery до последней версии.
Фикс ошибки, вызывающей sql ошибку Duplicate entry 'n' for key 'PRIMARY' occured in sql query UPDATE forum_search_results SET search_id = n, search_time = t, search_array = WHERE session_id = 'x', для этого апдейт базы.

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3 require ($root_path . 'include/config.php');
4
5 $userdata = session_pagestart($user_ip);
6 init_userprefs($userdata);
7 loggedinorreturn();
8
9 $action = request_var('action', 'view');
10 $type = request_var('type', '');</span>
11 <span class="code-lang">
12 switch ( $action ) {
13     case 'view':
14
15         if ( $userdata['class'] < UC_MODERATOR ) {
16             trigger_error($lang['access_denied']);
17         }
18
19         $delreport = request_var('delreport', array( 0 => 0 ) );
20
21         if ( sizeof($delreport) ) {
22             if ( isset($_POST['done']) ) {
23                     $sql = 'UPDATE ' . REPORTS_TABLE . ' SET dealtwith=1, dealtby = ' . $userdata['uid'] . ' WHERE id IN (' . implode(', ', $delreport) . ') AND dealtwith = 0';
24                     $db->sql_query($sql);
25             }
26             elseif ( isset($_POST['delreport']) ) {
27                 if ( $userdata['class'] < UC_ADMINISTRATOR ) {
28                         trigger_error($lang['access_denied']);
29                     }
30
31                     $sql = 'DELETE FROM ' . REPORTS_TABLE . ' WHERE id IN (' . implode(', ', $delreport) . ')';
32                     $db->sql_query($sql);
33             }
34
35             $count_reports = $config['count_reports_not_solved'] - sizeof($delreport);
36             set_config('count_reports_not_solved', $count_reports, true);
37
38             redirect( append_sid($root_path . 'reports.php?action=view'));
39         }
40
41         $sql = 'SELECT COUNT(*) AS count FROM ' . REPORTS_TABLE;
42          $result = $db->sql_query($sql);
43          $count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0;
44
45         $perpage = 25;
46
47          list($pagertop, $pagerbottom, $offset, $limit) = pager($perpage, $count, 'reports.php?action=view&amp;');
48
49         $template->assign_vars(array(
50             'S_FORM_ACTION' => append_sid($root_path . 'reports.php'),
51               'PAGERTOP' => $pagertop,
52               'PAGERBOTTOM' => $pagerbottom,
53               'DELETE_INPUT' => ( $userdata['class'] >= UC_ADMINISTRATOR ? ' <input type="submit" value="' . $lang['delete'] . '" name="delete" />' : '' )
54         ));
55
56         $sql = 'SELECT r.id, r.dealtwith, r.dealtby, r.addedby, r.votedfor, r.reason, r.type, u.name, u2.name AS dealtby_username, u3.name AS votedfor_username, t.name AS torrent_name, t.category
57                 FROM ' . REPORTS_TABLE . ' r
58                 LEFT JOIN ' . USERS_TABLE . ' u2 ON r.dealtby = u2.uid
59                    LEFT JOIN ' . USERS_TABLE . ' u3 ON r.votedfor = u3.uid
60                    LEFT JOIN ' . TORRENTS_TABLE . ' t ON r.votedfor = t.fid,
61                    ' . USERS_TABLE . " u
62                    WHERE r.addedby = u.uid
63                    ORDER BY r.id DESC";
64         $result = $db->sql_query_limit($sql, $limit, $offset);
65
66         $count_reports_not_solved = 0;
67
68          while ( $arr = $db->sql_fetchrow($result) ) {
69
70             if ( $arr['dealtwith'] ) {
71                 $dealtwith = '<span style="color:green;"><b>' . $lang['yes'] . '</b> - <a href="' . append_sid($root_path . 'userdetails.php?id=' . $arr['dealtby']) . '"><b>' . $arr['dealtby_username'] . '</b></a></span>';
72             }
73             else {
74                 $dealtwith = '<span style="color:red;"><b>' . $lang['no'] . '</b></span>';
75                 ++$count_reports_not_solved;
76             }
77
78             switch ( $arr['type'] ) {
79                   case 1:
80                        $type = 'userdetails.php?id';
81                     $name = $arr['votedfor_username'];
82                         $reason_type = $lang['user'];
83                    break;
84
85                 case 2:
86                     $type = 'details.php?id';
87                         $name = $arr['torrent_name'];
88                         $reason_type = $lang['torrent'];
89                     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
90                     @$seo->set_torrent_url($arr['votedfor'], $name, $arr['category']);
91                     // www.phpBB-SEO.com SEO TOOLKIT END
92                   break;
93
94                 case 3:
95                         $type = 'comment.php?cid';
96                         $name = $lang['comment'] . ' #' . $arr['votedfor'];
97                         $reason_type = $lang['comment'];
98                    break;
99             }
100
101               $template->assign_block_vars('reports_row', array(
102                   'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $arr['addedby']),
103                    'U_REPORT' => append_sid($root_path . $type . '=' . $arr['votedfor']),
104                    'ADDED_BY_ID' => $arr['addedby'],
105                    'ADDED_BY_USERNAME' => $arr['name'],
106                    'TYPE' => $type,
107                    'VOTEDFOR_ID' => $arr['votedfor'],
108                    'NAME' => $name,
109                    'REASON_TYPE' => $reason_type,
110                    'REASON' => $arr['reason'],
111                    'DEALTWITH' => $dealtwith,
112                    'ID' => $arr['id']
113             ));
114         }
115
116         if ( $count_reports_not_solved <> $config['count_reports_not_solved'] ) {
117             set_config('count_reports_not_solved', $count_reports_not_solved, true);
118         }
119
120         stdhead($lang['reports']);
121         $template->set_filenames(array(
122              'body' => 'reports_view_body.html'
123         ));
124          stdfoot();
125     break;
126
127     case 'send_report':
128         $id = request_var('id', 0);
129         $reason = request_var('reason', '');
130
131         if ( !$id ) {
132             trigger_error($lang['post_something']);
133         }
134
135         if ( isset($_POST['submit']) ) {
136             if ( !$reason ) {
137                 trigger_error($lang['post_something']);
138             }
139
140             switch ( $type ) {
141
142                 case 'user':
143                     $sql = 'SELECT uid FROM ' . USERS_TABLE . ' WHERE uid = ' . $id;
144                     $type = 1;
145                     $return = 'userdetails.php?id=' . $id;
146                 break;
147
148                 case 'torrent':
149                     $sql = 'SELECT fid, name, category FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $id;
150                     $type = 2;
151                     $return = 'details.php?id=' . $id;
152                 break;
153
154                 case 'comment':
155                     $sql = 'SELECT comment_id FROM ' . COMMENTS_TABLE . ' WHERE comment_id = ' . $id;
156                     $type = 3;
157                     $return = 'comment.php?cid=' . $id;
158                 break;
159
160                 default:
161                     trigger_error($lang['bad_data']);
162                 break;
163             }
164
165             $result = $db->sql_query($sql);
166             if ( !$row = $db->sql_fetchrow($result) ) {
167                 trigger_error ( sprintf($lang['invalid_id'], $id) );
168             }
169
170             switch ( $type ) {
171                 case 2:
172                     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
173                     $seo->set_torrent_url($row['fid'], $row['name'], $row['category']);
174                     // www.phpBB-SEO.com SEO TOOLKIT END
175                 break;
176             }
177
178             $sql = 'SELECT id FROM ' . REPORTS_TABLE . ' WHERE addedby = ' . $userdata['uid'] . ' AND votedfor = ' . $id . ' AND type = ' . $type;
179             $result = $db->sql_query($sql);
180
181             if ( !($row = $db->sql_fetchrow($result) ) ) {
182                 $db->sql_query('INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', array('addedby'   => $userdata['uid'],
183                                                                                              'votedfor'  => $id,
184                                                                                              'type'      => $type,
185                                                                                              'reason'    => $reason
186                 )));
187
188                 $count_reports = $config['count_reports_not_solved'] + 1;
189                 set_config('count_reports_not_solved', $count_reports, true);
190
191                 meta_refresh(3, append_sid($root_path . $return));
192                 trigger_error($lang['report_sended_sucefully']);
193             }
194              else {
195                 trigger_error($lang['already_reported']);
196             }
197
198         }
199         else {
200
201             switch ( $type ) {
202
203                 case 'user':
204                     $sql = 'SELECT name, class FROM ' . USERS_TABLE . ' WHERE uid = ' . $id;
205                 break;
206
207                 case 'torrent':
208                     $sql = 'SELECT name FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $id;
209                 break;
210
211                 case 'comment':
212                     $sql = 'SELECT c.comment_id, u.class FROM ' . COMMENTS_TABLE . ' c, ' . USERS_TABLE . ' u WHERE u.uid = c.comment_user AND c.comment_id= ' . $id;
213                 break;
214
215                 default:
216                     trigger_error($lang['bad_data']);
217                 break;
218             }
219
220             $result = $db->sql_query($sql);
221             if ( !($row = $db->sql_fetchrow($result)) ) {
222                 trigger_error ( sprintf($lang['invalid_id'], $id) );
223             }
224             if ( isset($row['class']) && ( $row['class'] >= UC_MODERATOR ) ) {
225                 trigger_error($lang['you_cant_report_this_user']);
226             }
227             $template->assign_vars(array(
228                     'S_FORM_ACTION' => append_sid($root_path . 'reports.php'),
229                     'ID' => $id,
230                     'TYPE' => $type
231             ));
232
233             stdhead($lang['reports']);
234             $template->set_filenames(array(
235                     'body' => 'reports_send_body.html')
236             );
237             stdfoot();
238         }
239     break;
240
241     default:
242         trigger_error('bad_type');
243     break;
244 }
245 ?>
Note: See TracBrowser for help on using the browser.