-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo_pnc.php
150 lines (105 loc) · 4.58 KB
/
go_pnc.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
<?php
function testbutton(){
?>
<form method="post" action="">
<input type="submit" name="button" />
</form>
<?php
if(isset($_POST['button'])){
update_totals( 15, 0, 11, 0); }
}
//adds currency and points for reasons that are not post tied.
function go_add_currency($user_id, $reason, $status, $points, $currency, $update){
global $wpdb;
$table_name_go = $wpdb->prefix . "go";
if($update == false){
$wpdb->insert($table_name_go, array('uid'=> $user_id, 'reason'=> $reason, 'status'=> $status, 'points'=> $points, 'currency'=>$currency));
} else if($update == true) {
$wpdb->update($table_name_go,array('status'=>$status, 'points'=>$points, 'currency'=> $currency), array('uid'=>$user_id, 'reason'=>$reason));
}
go_update_totals($user_id,$points,$currency,0);
}
// Adds currency and points for reasons that are post tied.
function go_add_post($user_id, $post_id, $status, $points, $currency){
global $wpdb;
$table_name_go = $wpdb->prefix . "go";
if($status == 0){
$wpdb->insert($table_name_go, array('uid'=> $user_id, 'post_id'=> $post_id, 'status'=> 1, 'points'=> $points, 'currency'=>$currency));
} else {
$old_points = $wpdb->get_results("select points, currency from ".$table_name_go." where uid = $user_id and post_id = $post_id ");
$wpdb->update($table_name_go,array('status'=>$status, 'points'=>$points+ $old_points['points'], 'currency'=> $currency+$old_points['currency']), array('uid'=>$user_id, 'post_id'=>$post_id));
}
go_update_totals($user_id,$points,$currency,0);
}
// Adds minutes.
function go_add_minutes($user_id, $minutes, $reason){
global $wpdb;
$table_name_go = $wpdb->prefix . "go";
$time = date('m/d@H:i',current_time('timestamp',0));
$minutes_reason = array('reason'=>$reason, 'time'=>$time);
$minutes_reason_serialized = serialize($minutes_reason);
$wpdb->insert($table_name_go, array('uid'=> $user_id, 'minutes'=> $minutes, 'reason'=> $minutes_reason_serialized) );
go_update_totals($user_id,0,0,$minutes);
}
function go_notify($type, $points='', $currency='', $time='') {
if ($points < 0 || $currency < 0) {
$sym = '';
} else {
$sym = '+';
}
global $counter;
$counter++;
$space = $counter*85;
echo '<div id="go_notification" class="go_notification" style="top: '.$space.'px">'.$sym.$points.' '.$type.'</div><script type="text/javascript" language="javascript">go_notification();</script>';
}
function go_update_admin_bar($type, $title, $points_currency){
echo '<script language="javascript">
jQuery("#go_admin_bar_'.$type.'").html("'.$points_currency.' '.$title.'");
</script>';
}
//Update totals
function go_update_totals($user_id,$points, $currency, $minutes){
global $wpdb;
if($points != 0){
$table_name_go_totals = $wpdb->prefix . "go_totals";
$totalpoints = go_return_points($user_id);
$wpdb->update($table_name_go_totals, array('points'=> $totalpoints+$points), array('uid'=>$user_id));
go_update_ranks($user_id, ($totalpoints+$points));
go_notify(get_option('go_points_name'), $points);
$p = (string)($totalpoints+$points);
go_update_admin_bar(strtolower(get_option('go_points_name')),get_option('go_points_name'),$p);
}
if($currency != 0){
$table_name_go_totals = $wpdb->prefix . "go_totals";
$totalcurrency = go_return_currency($user_id);
$wpdb->update($table_name_go_totals, array('currency'=> $totalcurrency+$currency), array('uid'=>$user_id));
go_notify(get_option('go_currency_name'), $currency);
go_update_admin_bar(strtolower(get_option('go_currency_name')), get_option('go_currency_name'), ($totalcurrency+$currency));
}
if($minutes != 0){
$table_name_go_totals = $wpdb->prefix . "go_totals";
$totalminutes = go_return_minutes($user_id);
$wpdb->update($table_name_go_totals, array('minutes'=> $totalminutes+$minutes), array('uid'=>$user_id));
go_notify('Minutes', $minutes);
}
}
function go_admin_bar_add(){
$points_points = $_POST['go_admin_bar_points_points'];
$points_reason = $_POST['go_admin_bar_points_reason'];
$currency_points = $_POST['go_admin_bar_currency_points'];
$currency_reason = $_POST['go_admin_bar_currency_reason'];
$minutes_points = $_POST['go_admin_bar_minutes_points'];
$minutes_reason = $_POST['go_admin_bar_minutes_reason'];
$user_id = get_current_user_id();
if($points_points != ''&& $points_reason != ''){
go_add_currency($user_id,$points_reason, 6, $points_points, 0, false);
}
if($currency_points!= ''&&$currency_reason!= ''){
go_add_currency($user_id, $currency_reason, 6, 0, $currency_points, false);
}
if($minutes_points!= ''&&$minutes_reason != ''){
go_add_minutes($user_id, $minutes_points, $minutes_reason);
}
die();
}
?>