root/uploadapp.php

Revision 317, 16.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 require ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_modcomment_log.php');
5
6 $userdata = session_pagestart($user_ip);
7 init_userprefs($userdata);
8 loggedinorreturn();</span>
9 <span class="code-lang">
10 if ( $userdata['class'] >= UC_MODERATOR ) {
11     $action = request_var('action', 'view_candidates');
12 }
13 else {
14     $action = '';
15 }
16
17 switch ( $action ) {
18     default:
19         $sql = 'SELECT * FROM ' . UPLOADAPP_TABLE . ' WHERE userid=' . $userdata['uid'];
20         $result = $db->sql_query($sql);
21         if( $row = $db->sql_fetchrow($result) ) {
22             $votesyes = $votesno = 0;
23             if( $row['votes'] != '' ) {
24                 $votes=explode(' ',$row['votes']);
25                 for( $i = 0; $i < sizeof($votes); $i++ ) {
26                     $votei = explode(':', $votes[$i]);
27                     $votei[1] ? $votesyes++ : $votesno++;
28                  }
29             }
30             trigger_error(sprintf($lang['uploadapp_poll_results'], $votesyes, $votesno, ( !$row['active'] ? $lang['polls_close'] : $lang['polls_open']) ));
31         }
32
33         if ( isset($_POST['submit']) ) {
34             $comment = request_var('comment', '');
35             $plans = request_var('plans', '');
36             $rbseed = request_var('rbseed', 0);
37             $rbseed = ( $rbseed ? 1 : 0 );
38             $speed = request_var('speed', 0);
39             $speed = ( $speed ? 1 : 0 );
40             $rbrelease = request_var('rbrelease', 0);
41             $rbrelease = ( $rbrelease ? 1 : 0 );
42             $rbstime = request_var('rbstime', 0);
43             $rbstime = ( $rbstime ? 1 : 0 );
44             if ( !$speed ) {
45                 trigger_error(sprintf($lang['please_set_upload_speed'], 'my.php'));
46             }
47             if (!$comment || !$plans) {
48                 trigger_error($lang['dont_empty_fields']);
49             }
50
51             $db->sql_query('INSERT INTO ' . UPLOADAPP_TABLE . ' ' . $db->sql_build_array('INSERT', array('userid'    => $userdata['uid'],
52                                                                            'applied'   => time(),
53                                                                            'content'   => $plans,
54                                                                            'comment'   => $comment,
55                                                                            'seeding'   => $rbseed,
56                                                                            'othergrps' => $rbrelease,
57                                                                            'seedtime'  => $rbstime)
58             ));
59
60             $count_candidates_waiting = $config['count_candidates_waiting'] + 1;
61             set_config('count_candidates_waiting', $count_candidates_waiting, true);
62
63             meta_refresh(3, append_sid($root_path));
64             trigger_error($lang['succefully_sended_uploadapp']);
65         }
66
67
68         $ratio = ( $userdata['downloaded'] > 0 ? $userdata['uploaded'] / $userdata['downloaded'] : ( $userdata['uploaded'] > 0 ? 1 : 0 ) );
69         if ( ( $userdata['added'] > ( time() - $config['uploadapp_min_added'] * 24 * 60 * 60 ) ) || ( $ratio < $config['uploadapp_min_ratio'] ) ) {
70                 trigger_error($lang['uploadapp_cant_upload']);
71         }
72         else {
73             $template->assign_vars(array(
74                 'S_FORM_ACTION' => append_sid('uploadapp.php'),
75                 'USERNAME' => $userdata['name'],
76                 'RATIO' => ( $ratio >= $config['uploadapp_min_ratio'] ? $lang['yes'] : $lang['no'] ),
77                 'REGISTER_DATE' => create_date($userdata['added']),
78                 'UPREQ' => sprintf($lang['uploaded_above'], $config['uploadapp_min_uploaded']),
79                 'UPREQ_HIDDEN_VALUE' => ( $userdata['uploaded'] >= ( $config['uploadapp_min_uploaded'] * 1024 * 1024 * 1024 ) ? 'yes' : 'no' ),
80                 'UPREQ_VALUE' => ( $userdata['uploaded'] >= ( $config['uploadapp_min_uploaded'] * 1024 * 1024 * 1024 ) ? $lang['yes'] : $lang['no']),
81                 'L_UPLOADAPP_WARNING_AUTODEMOTE' => ( !empty($config['uploader_promoted_demote_days']) ?  sprintf($lang['uploadapp_warning_autodemote'], $config['uploader_promoted_demote_days']) : '' )
82             ));
83
84             stdhead($lang['uploadapp']);
85             $template->set_filenames(array(
86                     'body' => 'uploadapp_polls.html'
87             ));
88             stdfoot();
89         }
90     break;
91
92     case 'view_candidates':
93         if( $userdata['class'] < UC_MODERATOR ) {
94             trigger_error($lang['access_denied']);
95         }
96
97         if ( isset($_POST['send_info']) ) {
98             $pollid = request_var('pollid', 0);
99             $sql = 'SELECT upl.* , u.name AS username, u.language, u.email, u.notifs, u.class, u.modcomment
100                      FROM ' . UPLOADAPP_TABLE . ' upl, ' . USERS_TABLE . ' u
101                      WHERE upl.id = ' . $pollid . ' AND upl.userid = u.uid';
102             $result = $db->sql_query($sql);
103             if ( !($row = $db->sql_fetchrow($result)) ) {
104                 trigger_error( sprintf($lang['invalid_id'], $pollid) );
105             }
106
107             $user_modcomment = $row['modcomment'];
108             $votesyes = $votesno = $voted = 0;
109             $votes = array();
110             if( $row['votes'] != '' ) {
111                 $votes = explode(' ', $row['votes']);
112                 for($i = 0; $i < count($votes); $i++) {
113                     $votei = explode(':', $votes[$i]);
114                     if( $userdata['uid'] == $votei[0] ) {
115                         $voted++;
116                     }
117                     $votei[1] ? $votesyes++ : $votesno++;
118                 }
119             }
120
121             if ( ( isset($_POST['vote_yes']) || isset($_POST['vote_no']) ) && !$voted ) {
122                 $user_vote = ( isset($_POST['vote_yes']) ? 1 : 0 );
123                 $user_vote_lang = ( $user_vote ? $lang['yes'] : $lang['no'] );
124
125                 $votes = ( $row['votes'] ? $row['votes'] . ' ': '') . $userdata['uid'] . ':' . $user_vote;
126
127                 $sql = 'UPDATE ' . UPLOADAPP_TABLE . ' SET votes = ' . "'" . $db->sql_escape($votes) . "'" . ' WHERE id=' . $pollid;
128                 $db->sql_query($sql);
129                 $message = sprintf($lang['uploadapp_vote_recived'], $pollid, $user_vote_lang);
130             }
131
132             elseif( isset($_POST['closepoll']) && $row['active'] ) {
133                 $user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']);
134                 $close_votes = 5;
135                 $message = sprintf($lang['uploadapp_poll_close_recived'], $pollid);
136                 if( sizeof($votes) < $close_votes ) {
137                     $message = sprintf($lang['uploadapp_poll_close_denied'], $close_votes);
138                 }
139                 else {
140                     $pm_ary = array();
141
142                     $sql = 'UPDATE ' . UPLOADAPP_TABLE . ' SET active = 0 WHERE id = ' . $pollid;
143                     $db->sql_query($sql);
144                     $tvotes = $votesyes + $votesno;
145                     $votea = $votesyes > $votesno;
146                     $modcomment = $user_modcomment . "\n" . sprintf($lang['modcomment_uploadapp'], 't' . time(), ( $votea? $lang['allowed'] : $lang['denied'] ), $votesyes, $votesno, ( ( $votea ? $votesyes : $votesno) / $tvotes ) * 100 );
147                     $message = preg_replace('/t([0-9]{10})/e', "create_date('\\1')", $modcomment) . '<br />';
148
149                     include($root_path . 'languages/lang_' . $row['language'] . '/lang_pms.php');
150
151                     if( $votea ) {
152                         $sql = 'UPDATE ' . USERS_TABLE . ' SET class = ' . UC_UPLOADER . ', modcomment = \'' . $db->sql_escape($modcomment) . '\', torrents_limit = ' . $user_limit_ary_torrents[UC_UPLOADER] . ' WHERE uid = '. $row['userid'];
153                         $db->sql_query($sql);
154
155                         $sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_UPLOADER] . ' WHERE user_id = ' . $row['userid'] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')';
156                         $db->sql_query($sql);
157                         $msg = $lang['pm_uploadapp_body_applied'];
158
159                         if ( !empty($config['uploadapp_promote_text']) ) {
160                             $config['uploadapp_promote_text'] = str_replace('{TRACKER_URL}', generate_base_url(), $config['uploadapp_promote_text']);
161                              $msg .= "\n" . $config['uploadapp_promote_text'];
162                         }
163                         if ( !empty($config['uploader_promoted_demote_days']) ) {
164                             $msg .= "\n" . sprintf($lang['uploadapp_warning_autodemote'], $config['uploader_promoted_demote_days']);
165                         }
166                     }
167                     else {
168                         $sql = 'UPDATE ' . USERS_TABLE . ' SET modcomment = \'' . $db->sql_escape($modcomment) . '\' WHERE uid = '.$row['userid'];
169                         $db->sql_query($sql);
170                         $msg = $lang['pm_uploadapp_body_denied'];
171                     }
172
173                     $pm_ary[] = array(
174                         'sender' => 0,
175                         'receiver' => $row['userid'],
176                         'msg' => $msg,
177                         'subject' => $lang['pm_uploadapp_subject'],
178                         'name' => $row['username'],
179                         'email' => $row['email'],
180                         'notifs' => $row['notifs'],
181                         'language' => $row['language'],
182                         'class' => $row['class']
183                     );
184
185                     send_pm($pm_ary);
186                 }
187                 $count_candidates_waiting = $config['count_candidates_waiting'] + 1;
188                 set_config('count_candidates_waiting', $count_candidates_waiting, true);
189             }
190             elseif( isset($_POST['removepoll']) ) {
191                 $sql = 'DELETE FROM ' . UPLOADAPP_TABLE . ' where id = ' . $pollid;
192                 $db->sql_query($sql);
193                 $message = sprintf($lang['uploadapp_poll_deleted'], $pollid);
194
195                 $count_candidates_waiting = $config['count_candidates_waiting'] + 1;
196                 set_config('count_candidates_waiting', $count_candidates_waiting, true);
197             }
198             elseif( isset($_POST['addcomment']) ) {
199                 $comment = request_var('newcomments', '');
200                 $message = sprintf($lang['uploadapp_poll_comment'], $comment);
201                 if( $comment ) {
202                     $comment = $userdata['name'] . ': ' . $comment . "\n";
203                     $comment = $row['modcomments'] . $comment;
204
205                     $sql = 'UPDATE ' . UPLOADAPP_TABLE . ' SET modcomments = \'' . $db->sql_escape($comment) . '\' WHERE id = ' . $pollid;
206                     $db->sql_query($sql);
207                     $message .= sprintf($lang['uploadapp_poll_comment_added'], $pollid);
208                 }
209                 else {
210                     $message .= sprintf($lang['uploadapp_poll_comment_not_added'], $pollid);
211                 }
212             }
213         }
214
215         $user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']);
216
217         //start delete old records
218         if ( !empty($config['uploadapp_delete_records_days']) ) {
219             $sql = 'DELETE FROM ' . UPLOADAPP_TABLE . ' WHERE applied < ' . ( time() - $config['uploadapp_delete_records_days'] * 24 * 60 * 60 ) . ' AND active = 0';
220             $db->sql_query($sql);
221         }
222         //end delete old records
223
224         //start demote uploaders, who been promoted, but not upload torrents
225         if ( !empty($config['uploader_promoted_demote_days']) ) {
226             $sql = 'SELECT u.uid, u.language, u.name, up.votes, u.modcomment
227                 FROM ' . UPLOADAPP_TABLE . ' up,
228                 ' . USERS_TABLE . ' u
229                 LEFT JOIN ' . TORRENTS_TABLE . ' t ON u.uid = t.owner
230                 WHERE up.applied < ' . ( time() - $config['uploader_promoted_demote_days'] * 24 * 60 * 60 ) . ' AND up.active = 0 AND u.class = ' . UC_UPLOADER . ' AND u.autodemote = 1 AND u.uid = up.userid
231                 GROUP BY u.uid
232                 HAVING COUNT(t.fid) = 0';
233             $result = $db->sql_query($sql);
234             if ( $row = $db->sql_fetchrow($result) ) {
235                 $modcomment_demote = sprintf($lang['modcomment_uploadapp_autodemoted'], 't'. time(), $config['uploader_promoted_demote_days']);
236                 do {
237                     $votesyes = $votesno = 0;
238                     if( !empty($row['votes']) ) {
239                             $votes = explode(' ', $row['votes']);
240                             for($i = 0; $i < count($votes); $i++) {
241                             $votei = explode(':', $votes[$i]);
242                             $votei[1] ? $votesyes++ : $votesno++;
243                            }
244
245                            //check if user been promoted through this form we do action
246                            if ( $votesyes > $votesno ) {
247                                @include($root_path . 'languages/lang_' . $row['language'] . '/lang_pms.php');
248
249                             $db->sql_query('INSERT INTO ' . PRIVATE_MESSAGES_TABLE . ' ' . $db->sql_build_array('INSERT', array(
250                                     'sender'   => 0,
251                                     'receiver' => $row['uid'],
252                                     'added'    => time(),
253                                     'msg'      => sprintf($lang['pm_uploadapp_demote_uploader_body'], $config['uploader_promoted_demote_days'] ) ,
254                                     'location' => 1,
255                                     'subject'  => $lang['pm_demote_to_user_subject'])
256                             ));
257
258                             $modcomment = $row['modcomment'] . "\n" . $modcomment_demote;
259
260                                 $sql = 'UPDATE ' . USERS_TABLE . ' SET class = ' . UC_USER . ', modcomment = \'' . $db->sql_escape($modcomment) . '\', torrents_limit = ' . $user_limit_ary_torrents[UC_USER] . ', user_unread_pms = user_unread_pms + 1 WHERE uid = '. $row['uid'];
261                                 $db->sql_query($sql);
262                                 $sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_USER] . ' WHERE user_id = ' . $row['uid'] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')';
263                                 $db->sql_query($sql);
264
265                                 write_log(sprintf($lang['log_uploadapp_autodemoted'], $row['uid'], $row['name'], $config['uploader_promoted_demote_days']), LOG_VIEW_MOD);
266                            }
267                        }
268
269                 }
270                 while ( $row = $db->sql_fetchrow($result) );
271             }
272             $db->sql_freeresult();
273         }
274         //end demote uploaders, who been promoted, but not upload torrents
275
276         $sql = 'SELECT COUNT(*) AS count FROM ' . UPLOADAPP_TABLE;
277         $result = $db->sql_query($sql);
278         $count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0;
279
280         $perpage = 20;
281         list($pagertop, $pagerbottom, $offset, $limit) = pager(20, $count, 'uploadapp.php?');
282         $sql = 'SELECT up.*, u.uploaded, u.downloaded, u.name AS username, u.upload, u.class, u.enabled, u.parked, u.warneduntil, u.donor
283                 FROM ' . UPLOADAPP_TABLE . ' up, ' . USERS_TABLE . ' u
284                 WHERE up.userid = u.uid
285                 ORDER BY applied DESC';
286         $result = $db->sql_query_limit($sql, $limit, $offset);
287         if( !$count ) {
288             if ( $config['count_candidates_waiting'] <> 0 ) {
289                 set_config('count_candidates_waiting', 0, true);
290             }
291             trigger_error($lang['nothing_found']);
292         }
293
294         /* */
295         require ($root_path . 'include/bbcode/bbcode.lib.php');
296         $bb_code = new bbcode();
297         /* */
298
299         $template->assign_vars(array(
300               'MESSAGE' => ( isset($message) ? $message : '' ),
301               'UPLOAD_GOOD' => sprintf($lang['uploadapp_upload'], $config['uploadapp_min_uploaded']),
302               'PAGERBOTTOM' => $pagerbottom,
303               'S_FORM_ACTION' => append_sid('uploadapp.php'),
304         ));
305
306         $count_candidates_waiting = 0;
307
308         while( $row = $db->sql_fetchrow($result) ) {
309             $voted = $tvotes = $votesyes = $votesno = 0;
310             if( $row['votes'] != '' ) {
311                 $votes = explode(' ', $row['votes']);
312                 for($i=0; $i < count($votes); $i++) {
313                     $votei = explode(':', $votes[$i]);
314                     if( $userdata["uid"] == $votei[0] ) {
315                         $voted++;
316                     }
317                     $votei[1] ? $votesyes++:$votesno++;
318                     $tvotes++;
319                 }
320             }
321
322             $ratio = ( $row['downloaded'] > 0 ? $row['uploaded'] / $row['downloaded'] : ( $row['uploaded'] > 0 ? 1 : 0 ) );
323             if ( $row['upload'] ) {
324                 if ( $row['upload'] < 1000 * 1024 ) {
325                     $upload = ($row['upload'] / 1024) . ' ' . utf_ucfirst(utf_strtolower($lang['kilobytes'])) . '/' . $lang['seconds_short'];
326                 }
327                 elseif ( $row['upload'] < 1000 * 1048576 ) {
328                     $upload = ($row['upload'] / 1048576) . ' ' . utf_ucfirst(utf_strtolower($lang['megabytes'])) . '/' . $lang['seconds_short'];
329                 }
330             }
331
332             if ( $row['content'] ) {
333                 $bb_code->parse($row['content']);
334                   $row['content'] = $bb_code->get_html();
335             }
336
337             if ( $row['comment'] ) {
338                 $bb_code->parse($row['comment']);
339                   $row['comment'] = $bb_code->get_html();
340             }
341
342             if ( $row['modcomments'] ) {
343                 $bb_code->parse($row['modcomments']);
344                   $row['modcomments'] = $bb_code->get_html();
345             }
346
347             $template->assign_block_vars('polls_row', array(
348                 'U_USERDETAILS' => append_sid('userdetails.php?id=' . $row['userid']),
349                 'POLL_ID' => $row['id'],
350                 'USER_ID' => $row['userid'],
351                 'USERNAME' => get_user_class_color($row['class'], $row['username']),
352                 'USER_ICONS' => get_user_icons($row),
353                 'APPLIED' => create_date($row['applied']),
354                 'RATIO_BGCOLOR' => ( $ratio >= $config['uploadapp_min_ratio'] ? 'green' : 'red' ),
355                 'UPLOADED_BGCOLOR' => ( $row['uploaded'] >= ( $config['uploadapp_min_uploaded'] * 1024 * 1024 * 1024 ) ? 'green' : 'red' ),
356                 'SEEDING_BGCOLOR' => ( $row['seeding'] ? 'green' : 'red' ),
357                 'SEEDTIME_BGCOLOR' => ( $row['seedtime'] ? 'green' : 'red' ),
358                 'UPLOAD' => $upload,
359                 'POLL_ACTIVE' => ( $row['active'] ? TRUE : FALSE ),
360                 'VOTES_YES' => $votesyes,
361                 'VOTES_NO' => $votesno,
362                 'TOTAL_VOTES' => $tvotes,
363                 'SHOW_VOTES' => ( $voted || !$row['active'] ? TRUE : FALSE ),
364                 'SHOW_CLOSE_INPUT' => ( $userdata['class'] >= UC_ADMINISTRATOR && $row['active'] ? TRUE : FALSE ),
365                 'SHOW_DELETE_INPUT' => ( $userdata['class'] >= UC_ADMINISTRATOR ? TRUE : FALSE ),
366                 'CONTENT' => $row['content'],
367                 'COMMENT' => $row['comment'],
368                 'MODCOMMENTS' => ( $row['modcomments'] ? $row['modcomments'] : ( $row['active'] ? $lang['no_comments_yet'] : '' )  ),
369                 'DISABLED' => ( $row['active'] ? '' : 'disabled="disabled"')
370             ));
371
372             if ( $row['active'] ) {
373                 ++$count_candidates_waiting;
374             }
375         }
376
377         if ( $count_candidates_waiting <> $config['count_candidates_waiting'] ) {
378             set_config('count_candidates_waiting', $count_candidates_waiting, true);
379         }
380
381         stdhead($lang['uploadapp']);
382         $template->set_filenames(array(
383             'body' => 'uploadapp_view_candidates_body.html'
384         ));
385         stdfoot();
386     break;
387 }
388 ?>
Note: See TracBrowser for help on using the browser.