forked from Bigjoos/U-232-V1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reputation_ad.php
719 lines (556 loc) · 25.4 KB
/
reputation_ad.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
<?php
/**
* http://btdev.net:1337/svn/test/Installer09_Beta
* Licence Info: GPL
* Copyright (C) 2010 BTDev Installer v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn.
**/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(INCL_DIR.'user_functions.php');
dbconn( false );
loggedinorreturn();
$lang = load_language('global');
if (!min_class(UC_SYSOP)) // or just simply: if (!min_class(UC_STAFF))
header( "Location: {$TBDEV['baseurl']}/index.php");
$input = array_merge($_GET, $_POST);
$input['mode'] = isset( $input['mode'] ) ? $input['mode'] : '';
$now_date = "";
$reputationid = 0;
$time_offset = 0;
$a = explode(",", gmdate("Y,n,j,G,i,s", time() + $time_offset));
$now_date = array( 'year' => $a[0], 'mon' => $a[1], 'mday' => $a[2],
'hours' => $a[3], 'minutes' => $a[4], 'seconds' => $a[5] );
switch( $input['mode'] )
{
case 'modify':
show_level();
break;
case 'add':
show_form('new');
break;
case 'doadd':
do_update('new');
break;
case 'edit':
show_form('edit');
break;
case 'doedit':
do_update('edit');
break;
case 'doupdate':
do_update();
break;
case 'dodelete':
do_delete();
break;
case 'list':
view_list();
break;
case 'dolist':
do_list();
break;
case 'editrep':
show_form_rep('edit');
break;
case 'doeditrep':
do_edit_rep();
break;
case 'dodelrep':
do_delete_rep();
break;
default:
show_level();
break;
}
function show_level()
{
$title = "User Reputation Manager - Overview";
$html = "<p>On this page you can modify the minimum amount required for each reputation level. Make sure you press Update Minimum Levels to save your changes. You cannot set the same minimum amount to more than one level.<br />From here you can also choose to edit or remove any single level. Click the Edit link to modify the Level description (see Editing a Reputation Level) or click Remove to delete a level. If you remove a level or modify the minimum reputation needed to be at a level, all users will be updated to reflect their new level if necessary.</p><br />";
$query = sql_query( 'SELECT * FROM reputationlevel ORDER BY minimumreputation ASC' );
if( ! mysql_num_rows( $query ) )
{
do_update( 'new' );
return;
}
$css = "style='font-weight: bold;color: #ffffff;background-color: #0055A4;padding: 5px;'";
$html .= "<h2>User Reputation Manager</h2>" ;
$html .= "<p><span class='btn'><a href='reputation_ad.php?mode=list'>View comments</a></span></p><br />";
$html .= "<form action='reputation_ad.php' name='show_rep_form' method='post'>
<input name='mode' value='doupdate' type='hidden' />";
$html .= "<table cellpadding='3px'><tr>
<td width='5%' $css>ID</td>
<td width='60%'$css>Reputation Level</td>
<td width='20%' $css>Minimum Reputation Level</td>
<td width='15%' $css>Controls</td></tr>";
while( $res = mysql_fetch_assoc( $query ) )
{
$html .= "<tr>\n".
" <td>#".$res['reputationlevelid']."</td>\n".
" <td>User <b>".htmlentities( $res['level'] )."</b></td>\n".
" <td align='center'><input type='text' name='reputation[".$res['reputationlevelid']."]' value='".$res['minimumreputation']."' size='12' /></td>\n".
" <td align='center'><span class='btn'><a href='reputation_ad.php?mode=edit&reputationlevelid=".$res['reputationlevelid']."'>Edit</a></span> <span class='btn'><a href='reputation_ad.php?mode=dodelete&reputationlevelid=".$res['reputationlevelid']."'>Delete</a></span></td>\n".
"</tr>\n";
}
$html .= "<tr><td colspan='3' align='center'>
<input type='submit' value='Update' accesskey='s' class='btn' />
<input type='reset' value='Reset' accesskey='r' class='btn' /></td>
<td align='center'><span class='btn'><a href='reputation_ad.php?mode=add'>Add New</a></span>
</td></tr>";
$html .= "</table>";
$html .= "</form>";
html_out( $html, $title );
}
function show_form($type='edit')
{
global $input;
$html = "This allows you to add a new reputation level or edit an existing reputation level.";
if( $type == 'edit' )
{
$query = sql_query( 'SELECT * FROM reputationlevel WHERE reputationlevelid='.intval($input['reputationlevelid']) ) or sqlerr(__LINE__,__FILE__);
if( ! $res = mysql_fetch_assoc( $query ) )
{
stderr( "Error:", "Please specify an ID." );
}
$title = "Edit Reputation Level";
$html .= "<br /><span style='font-weight:normal;'>".htmlspecialchars($res['level'])." (ID:#{$res['reputationlevelid']})</span><br />";
$button = "Update";
$extra = "<input type='button' class='button' value='Back' accesskey='b' class='btn' onclick='javascript:history.back(1)' />";
$mode = 'doedit';
}
else
{
$title = "Add New Reputation Level";
$button = "Save";
$mode = 'doadd';
$extra = "<input type='button' value='Back' accesskey='b' class='btn' onclick='javascript:history.back(1)' />";
}
$css = "style='font-weight: bold;color: #ffffff;background-color: #0055A4;padding: 5px;'";
$replevid = isset($res['reputationlevelid']) ? $res['reputationlevelid'] : '';
$replevel = isset($res['level']) ? $res['level'] : '';
$minrep = isset($res['minimumreputation']) ? $res['minimumreputation'] : '';
$html .= "<form action='reputation_ad.php' name='show_rep_form' method='post'>
<input name='reputationlevelid' value='{$replevid}' type='hidden' />
<input name='mode' value='{$mode}' type='hidden' />";
$html .= "<h2>$title</h2><table width='500px' cellpadding='5px'><tr>
<td width='67%' $css> </td>
<td width='33%' $css> </td></tr>";
$html .= "<tr><td>Level Description<div class='desctext'>This is what is displayed for the user when their reputation points are above the amount entered as the minimum.</div></td>";
$html .= "<td><input type='text' name='level' value=\"{$replevel}\" size='35' maxlength='250' /></td></tr>";
$html .= "<tr><td>Minimum amount of reputation points required for this level<div>This can be a positive or a negative amount. When the user's reputation points reaches this amount, the above description will be displayed.</div></td>";
$html .= "<td><input type='text' name='minimumreputation' value=\"{$minrep}\" size='35' maxlength='10' /></td></tr>";
$html .= "<tr><td colspan='2' align='center'><input type='submit' value='$button' accesskey='s' class='btn' /> <input type='reset' value='Reset' accesskey='r' class='btn' /> $extra</td></tr>";
$html .= "</table>";
$html .= "</form>";
html_out( $html, $title );
}
/////////////////////////////////////
// Update rep function
/////////////////////////////////////
function do_update($type="")
{
global $input;
if( $type != "" )
{
$level = strip_tags( $input['level'] );
$level = trim( $level );
if( ( strlen( $input['level'] ) < 2 ) || ( $level == "" ) )
{
stderr( '', 'The text you entered was too short.' );
}
if( strlen( $input['level'] ) > 250 )
{
stderr( '', 'The text entry is too long.' );
}
$level = sqlesc( $level );
$minrep = sqlesc( intval( $input['minimumreputation'] ) );
$redirect = 'Saved Reputation Level <i>'.htmlentities( $input['level'], ENT_QUOTES ).'</i> Successfully.';
}
// what we gonna do?
if( $type == 'new' )
{
@sql_query( "INSERT INTO reputationlevel ( minimumreputation, level )
VALUES ($minrep, $level )" );
}
elseif( $type == 'edit' )
{
$levelid = intval( $input['reputationlevelid'] );
if( ! is_valid_id($levelid) ) stderr('', 'Not a valid try');
// check it's a valid rep id
$query = sql_query( "SELECT reputationlevelid FROM reputationlevel WHERE
reputationlevelid={$levelid}" );
if( ! mysql_num_rows( $query ) )
{
stderr( '', 'Not a valid ID.' );
}
@sql_query( "UPDATE reputationlevel SET minimumreputation = $minrep, level = $level
WHERE reputationlevelid = $levelid" );
}
else
{
$ids = $input['reputation'];
if( is_array($ids) && count($ids) )
{
foreach( $ids as $k => $v )
{
@sql_query( "UPDATE reputationlevel SET minimumreputation = ".intval($v)." WHERE reputationlevelid = ".intval($k) );
}
}
else
{
stderr( '', 'No valid ID.' );
}
$redirect = "Saved Reputation Level Successfully.";
}
rep_cache();
redirect( 'reputation_ad.php?mode=done', $redirect );
}
//////////////////////////////////////
// Reputaion delete
//////////////////////////////////////
function do_delete()
{
global $input;
if( ! isset($input['reputationlevelid']) || ! is_valid_id($input['reputationlevelid']) )
stderr( '', 'No valid ID.' );
$levelid = intval($input['reputationlevelid']);
// check the id is valid within db
$query = sql_query( "SELECT reputationlevelid FROM reputationlevel WHERE reputationlevelid=$levelid" );
if( ! mysql_num_rows( $query ) )
{
stderr( '', 'Rep ID doesn\'t exist' );
}
// if we here, we delete it!
@sql_query( "DELETE FROM reputationlevel WHERE reputationlevelid=$levelid" );
rep_cache();
redirect( 'reputation_ad.php?mode=done', 'Reputation deleted successfully', 5 );
}
//////////////////////////////////////
// Reputaion edit
//////////////////////////////////////
function show_form_rep()
{
global $input;
if( ! isset($input['reputationid']) || ! is_valid_id($input['reputationid']) )
stderr( '', 'Nothing here by that ID.' );
$title = 'User Reputation Manager';
$query = sql_query( "SELECT r.*, p.topicid, t.subject, leftfor.username as leftfor_name,
leftby.username as leftby_name
FROM reputation r
left join posts p on p.id=r.postid
left join topics t on p.topicid=t.id
left join users leftfor on leftfor.id=r.userid
left join users leftby on leftby.id=r.whoadded
WHERE reputationid = ".intval($input['reputationid']) );
if( ! $res = mysql_fetch_assoc( $query ) )
{
stderr( '', 'Erm, it\'s not there!' );
}
$html = "<form action='reputation_ad.php' name='show_rep_form' method='post'>
<input name='reputationid' value='{$res['reputationid']}' type='hidden' />
<input name='oldreputation' value='{$res['reputation']}' type='hidden' />
<input name='mode' value='doeditrep' type='hidden' />";
$html .= "<h2>Edit Reputation</h2>";
$html .= "<table cellpadding='5px'>";
$html .= "<tr><td width='37%'>Topic</td><td width='63%'><a href='forums.php?action=viewtopic&topicid={$res['topicid']}&page=p{$res['postid']}#{$res['postid']}' target='_blank'>".htmlspecialchars($res['subject'])."</a></td></tr>";
$html .= "<tr><td>Left By</td><td>{$res['leftby_name']}</td></tr>";
$html .= "<tr><td>Left For</td><td width='63%'>{$res['leftfor_name']}</td></tr>";
$html .= "<tr><td>Comment</td><td width='63%'><input type='text' name='reason' value='".htmlspecialchars($res['reason'])."' size='35' maxlength='250' /></td></tr>";
$html .= "<tr><td>Reputation</td><td><input type='text' name='reputation' value='{$res['reputation']}' size='35' maxlength='10' /></td></tr>";
$html .= "<tr><td colspan='2' align='center'><input type='submit' value='Save' accesskey='s' class='btn' /> <input type='reset' tabindex='1' value='Reset' accesskey='r' class='btn' /></td></tr>";
$html .= "</table></form>";
html_out( $html, $title );
}
/////////////////////////////////////
// View reputation comments function
/////////////////////////////////////
function view_list()
{
global $now_date, $time_offset, $input;
$title = 'User Reputation Manager';
$html = "<h2>View Reputation Comments</h2>";
$html .= "<p>This page allows you to search for reputation comments left by / for specific users over the specified date range.</p>";
$html .= "<form action='reputation_ad.php' name='list_form' method='post'>
<input name='mode' value='list' type='hidden' />
<input name='dolist' value='1' type='hidden' />";
$html .= "<table width='500px' cellpadding='5px'>";
$html .= "<tr><td width='20%'>Left For</td><td width='80%'><input type='text' name='leftfor' value='' size='35' maxlength='250' tabindex='1' /></td></tr>";
$html .= "<tr><td colspan='2'><div>To limit the comments left for a specific user, enter the username here. Leave this field empty to receive comments left for every user.</div></td></tr>";
$html .= "<tr><td>Left By</td><td><input type='text' name='leftby' value='' size='35' maxlength='250' tabindex='2' /></td></tr>";
$html .= "<tr><td colspan='2'><div>To limit the comments left by a specific user, enter the username here. Leave this field empty to receive comments left by every user.</div></td></tr>";
$html .= "<tr><td>Start Date</td><td>
<div>
<span style='padding-right:5px; float:left;'>Month<br /><select name='start[month]' tabindex='3'>".get_month_dropdown(1)."</select></span>
<span style='padding-right:5px; float:left;'>Day<br /><input type='text' name='start[day]' value='".($now_date['mday']+1)."' size='4' maxlength='2' tabindex='3' /></span>
<span>Year<br /><input type='text' name='start[year]' value='".$now_date['year']."' size='4' maxlength='4' tabindex='3' /></span>
</div></td></tr>";
$html .= "<tr><td class='tdrow2' colspan='2'><div class='desctext'>Select a start date for this report. Select a month, day, and year. The selected statistic must be no older than this date for it to be included in the report.</div></td></tr>";
$html .= "<tr><td>End Date</td><td>
<div>
<span style='padding-right:5px; float:left;'>Month<br /><select name='end[month]' class='textinput' tabindex='4'>".get_month_dropdown()."</select></span>
<span style='padding-right:5px; float:left;'>Day<br /><input type='text' class='textinput' name='end[day]' value='".$now_date['mday']."' size='4' maxlength='2' tabindex='4' /></span>
<span>Year<br /><input type='text' class='textinput' name='end[year]' value='".$now_date['year']."' size='4' maxlength='4' tabindex='4' /></span>
</div></td></tr>";
$html .= "<tr><td class='tdrow2' colspan='2'><div class='desctext'>Select an end date for this report. Select a month, day, and year. The selected statistic must not be newer than this date for it to be included in the report. You can use this setting in conjunction with the 'Start Date' setting to create a window of time for this report.</div></td></tr>";
$html .= "<tr><td colspan='2' align='center'><input type='submit' value='Search' accesskey='s' class='btn' tabindex='5' /> <input type='reset' value='Reset' accesskey='r' class='btn' tabindex='6' /></td></tr>";
$html .= "</table></form>";
//print $html; exit;
// I hate work, but someone has to do it!
if( isset($input['dolist']) )
{
$links = "";
$input['orderby'] = isset($input['orderby']) ? $input['orderby'] : '';
//$cond = ''; //experiment
$who = isset($input['who']) ? (int)$input['who'] : 0;
$user = isset($input['user']) ? $input['user'] : 0;
$first = isset($input['page']) ? intval($input['page']) : 0;
$cond = $who ?"r.whoadded=".sqlesc($who) : '';
$start = isset($input['startstamp']) ? intval($input['startstamp']) : mktime(0, 0, 0, $input['start']['month'], $input['start']['day'], $input['start']['year']) + $time_offset;
$end = isset($input['endstamp']) ? intval($input['endstamp']) : mktime(0, 0, 0, $input['end']['month'], $input['end']['day'] + 1, $input['end']['year']) + $time_offset;
if( ! $start )
{
$start = time() - (3600 * 24 * 30);
}
if( ! $end )
{
$end = time();
}
if( $start >= $end )
{
stderr( 'Time', 'Start date is after the end date.' );
}
if( ! empty($input['leftby']) )
{
$left_b = @sql_query( "SELECT id FROM users WHERE username = ".sqlesc($input['leftby']) );
if( ! mysql_num_rows($left_b) )
{
stderr( 'DB ERROR', 'Could not find user '.htmlentities($input['leftby'], ENT_QUOTES) );
}
$leftby = mysql_fetch_assoc($left_b);
$who = $leftby['id'];
$cond = "r.whoadded=".$who;
}
if( ! empty($input['leftfor']) )
{
$left_f = @sql_query( "SELECT id FROM users WHERE username = ".sqlesc($input['leftfor']) );
if( ! mysql_num_rows($left_f) )
{
stderr( 'DB ERROR', 'Could not find user '.htmlentities($input['leftfor'], ENT_QUOTES) );
}
$leftfor = mysql_fetch_assoc($left_f);
$user = $leftfor['id'];
$cond .= ($cond ? " AND" : "")." r.userid=".$user;
}
if( $start )
{
$cond .= ($cond ? " AND" : "")." r.dateadd >= $start";
}
if( $end )
{
$cond .= ($cond ? " AND" : "")." r.dateadd <= $end";
}
switch( $input['orderby'] )
{
case 'leftbyuser':
$order = 'leftby.username';
$orderby = 'leftbyuser';
break;
case 'leftforuser':
$order = 'leftfor.username';
$orderby = 'leftforuser';
break;
default:
$order = 'r.dateadd';
$orderby = 'dateadd';
}
$css = "style='font-weight: bold;color: #ffffff;background-color: #0055A4;padding: 5px;'";
$html = "<h2>Reputation Comments</h2>";
$table_header = "<table width='80%' cellpadding='5' border='1'><tr $css>";
$table_header .= "<td width='5%'>ID</td>";
$table_header .= "<td width='20%'><a href='reputation_ad.php?mode=list&dolist=1&who=".intval($who)."&user=".intval($user)."&orderby=leftbyuser&startstamp=$start&endstamp=$end&page=$first'>Left By</a></td>";
$table_header .= "<td width='20%'><a href='reputation_ad.php?mode=list&dolist=1&who=".intval($who)."&user=".intval($user)."&orderby=leftforuser&startstamp=$start&endstamp=$end&page=$first'>Left For</a></td>";
$table_header .= "<td width='17%'><a href='reputation_ad.php?mode=list&dolist=1&who=".intval($who)."&user=".intval($user)."&orderby=date&startstamp=$start&endstamp=$end&page=$first'>Date</a></td>";
$table_header .= "<td width='5%'>Point</td>";
$table_header .= "<td width='23%'>Reason</td>";
$table_header .= "<td width='10%'>Controls</td></tr>";
$html .= $table_header;
// do the count for pager etc
$query = sql_query( "SELECT COUNT(*) AS cnt FROM reputation r WHERE $cond" );
//print_r($input); exit;
$total = mysql_fetch_assoc( $query );
if( ! $total['cnt'] )
{
$html .= "<tr><td colspan='7' align='center'>No Matches Found!</td></tr>";
}
// do the pager thang!
$deflimit = 10;
$links = "<span style=\"background: #F0F5FA; border: 1px solid #072A66;padding: 1px 3px 1px 3px;\">{$total['cnt']} Records</span>";
if( $total['cnt'] > $deflimit )
{
require_once "include/pager.php";
$links = pager(
array(
'count' => $total['cnt'],
'perpage' => $deflimit,
'start_value' => $first,
'url' => "reputation_ad.php?mode=list&dolist=1&who=".intval($who)."&user=".intval($user)."&orderby=$orderby&startstamp=$start&endstamp=$end"
)
);
}
// mofo query!
$query = sql_query( "SELECT r.*, p.topicid, leftfor.id as leftfor_id,
leftfor.username as leftfor_name, leftby.id as leftby_id,
leftby.username as leftby_name
FROM reputation r
left join posts p on p.id=r.postid
left join users leftfor on leftfor.id=r.userid
left join users leftby on leftby.id=r.whoadded
WHERE $cond ORDER BY $order LIMIT $first,$deflimit" );
if( ! mysql_num_rows( $query ) ) stderr('DB ERROR', 'Nothing here');
while( $r = mysql_fetch_assoc( $query ) )
{
$r['dateadd'] = date( "M j, Y, g:i a", $r['dateadd'] );
$html .= "<tr><td>#{$r['reputationid']}</td>";
$html .= "<td><a href='userdetails.php?id={$r['leftby_id']}' target='_blank'>{$r['leftby_name']}</a></td>";
$html .= "<td><a href='userdetails.php?id={$r['leftfor_id']}' target='_blank'>{$r['leftfor_name']}</a></td>";
$html .= "<td>{$r['dateadd']}</td>";
$html .= "<td align='right'>{$r['reputation']}</td>";
$html .= "<td><a href='forums.php?action=viewtopic&topicid={$r['topicid']}&page=p{$r['postid']}#{$r['postid']}' target='_blank'>".htmlspeciachars($r['reason'])."</a></td>";
$html .= "<td><a href='reputation_ad.php?mode=editrep&reputationid={$r['reputationid']}'><span class='btn'>Edit</span></a> <a href='reputation_ad.php?mode=dodelrep&reputationid={$r['reputationid']}'><span class='btn'>Delete</span></a></td></tr>";
}
$html .= "</table>";
$html .= "<br /><div>$links</div>";
}
html_out( $html, $title);
}
///////////////////////////////////////////////
// Reputation do_delete_rep function
///////////////////////////////////////////////
function do_delete_rep()
{
global $input;
if( ! is_valid_id($input['reputationid']) )
stderr('ERROR', 'Can\'t find ID');
// check it's a valid ID.
$query = sql_query( "SELECT reputationid, reputation, userid FROM reputation WHERE reputationid=".intval($input['reputationid'] ) );
if( false === ( $r = mysql_fetch_assoc($query) ) )
{
stderr( 'DELETE', 'No valid ID.' );
}
// do the delete
@sql_query( "DELETE FROM reputation WHERE reputationid=".intval($r['reputationid'] ) );
@sql_query( "UPDATE users SET reputation = (reputation-{$r['reputation']} ) WHERE id=".intval($r['userid']) );
redirect( "reputation_ad.php?mode=list", "Deleted Reputation Successfully", 5 );
}
///////////////////////////////////////////////
// Reputation do_edit_rep function
///////////////////////////////////////////////
function do_edit_rep()
{
global $input;
if( isset($input['reason']) && ! empty($input['reason']) )
{
$reason = str_replace("<br />", "", $input['reason']);
$reason = trim($reason);
if( ( strlen(trim($reason)) < 2 ) || ( $reason == "" ) )
{
stderr( 'TEXT', 'The text you entered was too short.' );
}
if( strlen( $input['reason'] ) > 250 )
{
stderr( 'TEXT', 'The text entry is too long.' );
}
}
$oldrep = intval($input['oldreputation']);
$newrep = intval($input['reputation']);
// valid ID?
$query = sql_query( "SELECT reputationid, reason, userid FROM reputation WHERE reputationid=".intval($input['reputationid'] ) );
if( false === $r = mysql_fetch_assoc($query) )
{
stderr( 'INPUT', 'No ID' );
}
if( $oldrep != $newrep )
{
if( $r['reason'] != $reason )
{
@sql_query( "UPDATE reputation SET reputation = ".intval($newrep).", reason = ".sqlesc($reason)." WHERE reputationid = ".intval($r['reputationid']) );
}
$diff = $oldrep - $newrep;
@sql_query( "UPDATE users SET reputation = (reputation-{$diff}) WHERE id=".intval($r['userid']) );
}
redirect( "reputation_ad.php?mode=list", "Saved Reputation #ID{$r['reputationid']} Successfully.", 5);
}
///////////////////////////////////////////////
// Reputation output function
// $msg -> string
// $html -> string
///////////////////////////////////////////////
function html_out( $html="", $title="" )
{
if( empty($html) )
{
stderr( "Error", "Nothing to output" );
}
print stdhead( $title ) . $html . stdfoot();
exit();
}
function redirect($url, $text, $time=2)
{
global $TBDEV;
$page_title = "Admin Rep Redirection";
$page_detail = "<em>Redirecting...</em>";
$html = "<meta http-equiv='refresh' content=\"{$time}; url={$TBDEV['baseurl']}/{$url}\">
<div>
<div>Redirecting</div>
<div style='padding:8px'>
<div style='font-size:12px'>$text
<br />
<br />
<center><a href='{$TBDEV['baseurl']}/{$url}'>Click here if not redirected...</a></center>
</div>
</div>
</div>";
print $html;
exit;
}
/////////////////////////////
// get_month worker function
/////////////////////////////
function get_month_dropdown($i=0)
{
global $now_date;
$return = '';
$month = array('----','January','February','March','April','May','June','July','August','September','October','November','December');
foreach( $month as $k => $m )
{
$return .= "\t<option value='".$k."'";
$return .= ( ( $k + $i ) == $now_date['mon'] ) ? " selected='selected'" : "";
$return .= ">".$m."</option>\n";
}
return $return;
}
/////////////////////////////
// cache rep function
/////////////////////////////
function rep_cache()
{
$query = @sql_query( "SELECT * FROM reputationlevel" );
if( ! mysql_num_rows($query) )
stderr( 'CACHE', 'No items to cache' );
$rep_cache_file = "cache/rep_cache.php";
$rep_out = "<"."?php\n\n\$reputations = array(\n";
while( $row = mysql_fetch_assoc($query) )
{
$rep_out .= "\t{$row['minimumreputation']} => '{$row['level']}',\n";
}
$rep_out .= "\n);\n\n?".">";
clearstatcache( $rep_cache_file );
if( is_file( $rep_cache_file ) && is_writable( $rep_cache_file ) )
{
$filenum = fopen ( $rep_cache_file, 'w' );
ftruncate( $filenum, 0 );
fwrite( $filenum, $rep_out );
fclose( $filenum );
}
}
?>