forked from TheMacLab/game-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo_clipboard.php
269 lines (258 loc) · 11.6 KB
/
go_clipboard.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
<?php
function go_clipboard() {
add_submenu_page( 'game-on-options.php', 'Clipboard', 'Clipboard', 'manage_options', 'go_clipboard', 'go_clipboard_menu' );
}
function go_clipboard_menu() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
} else {
go_style_clipboard();
go_jquery_clipboard();
?>
<div id="records_tabs">
<ul>
<li><a href="#clipboard_wrap">Clipboard</a></li>
<li><a href="#clipboard_messages_wrap">Messages</a></li>
</ul>
<div id="clipboard_wrap">
<select class="menuitem" id="go_clipboard_class_a_choice" onchange="go_clipboard_class_a_choice();">
<option>...</option>
<?php
$class_a = get_option( 'go_class_a' );
if ( $class_a ) {
foreach ( $class_a as $key => $value ) {
echo "<option class='ui-corner-all'>{$value}</option>";
}
}
?>
</select>
<div id="go_clipboard_add">
<?php go_options_help( 'http://maclab.guhsd.net/go/video/clipboard/clipboard.mp4', 'Clipboard Help' ); ?>
<label for="go_clipboard_points"><?php echo go_return_options( 'go_points_name' ); ?>: </label><input name="go_clipboard_points" id="go_clipboard_points" class='go_clipboard_add'/>
<label for="go_clipboard_currency"><?php echo go_return_options( 'go_currency_name' ); ?>: </label><input name="go_clipboard_currency" id="go_clipboard_currency" class='go_clipboard_add'/>
<label for="go_clipboard_bonus_currency"><?php echo go_return_options( 'go_bonus_currency_name' ); ?>: </label> <input name="go_clipboard_bonus_currency" id="go_clipboard_bonus_currency" class='go_clipboard_add'/>
<label for="go_clipboard_penalty"><?php echo go_return_options( 'go_penalty_name' ); ?>: </label><input name="go_clipboard_penalty" id="go_clipboard_penalty" class='go_clipboard_add'/>
<label for="go_clipboard_minutes"><?php echo go_return_options( 'go_minutes_name' ); ?>: </label><input name="go_clipboard_minutes" id="go_clipboard_minutes" class='go_clipboard_add'/>
<label for="go_clipboard_badge">Badge ID:</label><input name="go_clipboard_badge" id="go_clipboard_badge" class='go_clipboard_add'/><br/>
<label name="go_clipboard_reason">Message: </label>
<div>
<textarea name="go_clipboard_reason" id="go_clipboard_reason" placeholder='See me'></textarea><br/>
<button class="ui-button-text" id="go_send_message" onclick="go_clipboard_add();">Add</button>
<button id="go_fix_messages" onclick="fixmessages()">Fix Messages</button>
</div>
<table id="go_clipboard_table" class="pretty">
<thead>
<tr>
<th><input type="checkbox" onClick="go_toggle(this);" /></th>
<th class="header"><a href="#" >ID</a></th>
<th class="header"><a href="#" ><?php echo go_return_options( 'go_class_b_name' ); ?></a></th>
<th class="header"><a href="#" >Student Name</a></th>
<th class="header"><a href="#" >Display Name</a></th>
<th class="header"><a href="#" ><?php echo go_return_options( 'go_level_names' ); ?></a></th>
<?php if ( go_return_options( 'go_focus_switch' ) == 'On' ) { ?><th class="header"><a href="#" ><?php echo go_return_options( 'go_focus_name' ); ?></a></th><?php } ?>
<th class="header"><a href="#"><?php echo go_return_options( 'go_points_name' ); ?></a></th>
<th class="header"><a href="#"><?php echo go_return_options( 'go_currency_name' ); ?></a></th>
<th class="header"><a href="#"><?php echo go_return_options( 'go_bonus_currency_name' ); ?></a></th>
<th class="header"><a href="#"><?php echo go_return_options( 'go_penalty_name' ); ?></a></th>
<th class="header"><a href="#"><?php echo go_return_options( 'go_minutes_name' ); ?></a></th>
<th class="header"><a href="#"><?php echo go_return_options( 'go_badges_name' ); ?></a></th>
</tr>
</thead>
<tbody id="go_clipboard_table_body"></tbody>
</table>
</div>
</div>
<div id="clipboard_messages_wrap">
<select class="menuitem" id="go_clipboard_class_a_choice_messages" onchange="go_clipboard_class_a_choice_messages();">
<option>...</option>
<?php
$class_a_messages = get_option( 'go_class_a' );
if ( $class_a_messages ) {
foreach ( $class_a_messages as $key => $value ) {
echo "<option class='ui-corner-all'>{$value}</option>";
}
}
?>
<option>All</option>
</select>
<table id="go_clipboard_messages" class="pretty">
<thead>
<tr>
<th class="header" width="5%" id="messages_id"><a href="#" >ID</a></th>
<th class="header" width="5%" id="messages_computer"><a href="#"><?php echo go_return_options( 'go_class_b_name' ); ?></a></th>
<th class="header" width="6.5%" id="messages_student"><a href="#">Student Name</a></th>
<th class="header" width="6.5%" id="messages_display"><a href="#">Display Name</a></th>
<th class="header" width="6%" id="messages_date"><a href="#">Date</a></th>
<th class="header" id="messages_message"><a href="#">Message</a></th>
</tr>
</thead>
<tbody id="go_clipboard_messages_body"></tbody>
</table>
</div>
</div>
<?php
}
}
function go_clipboard_intable() {
global $wpdb;
$class_a_choice = $_POST[ 'go_clipboard_class_a_choice' ];
$table_name_user_meta = $wpdb->prefix.'usermeta';
$uid = $wpdb->get_results( "SELECT user_id
FROM {$table_name_user_meta}
WHERE meta_key = '{$wpdb->prefix}capabilities'
AND meta_value NOT LIKE '%administrator%'"
);
foreach ( $uid as $id ) {
$class_a = get_user_meta( $id->user_id, 'go_classifications', true );
if ( ! empty( $class_a[ $class_a_choice ] ) ) {
$user_data_key = get_userdata( $id->user_id );
$user_login = $user_data_key->user_login;
$user_display = $user_data_key->display_name;
$user_first_name = $user_data_key->user_firstname;
$user_last_name = $user_data_key->user_lastname;
$user_url = $user_data_key->user_url;
if ( go_return_options( 'go_focus_switch' ) == 'On' ) {
$user_focuses = go_display_user_focuses( $id->user_id );
$focus_name = get_option( 'go_focus_name' );
$focuses = get_option( 'go_focus' );
$focuses_list = "<option>{$user_focuses}</option><option ".( ( empty( $user_focuses) || $user_focuses == "No {$focus_name}" ) ? "selected" : '' ).">No {$focus_name}</option>";
foreach ( $focuses as $focus ) {
$focuses_list .= "<option value='".esc_attr( $focus )."' >{$focus}</option>";
}
}
$bonus_currency = go_return_bonus_currency( $id->user_id );
$penalty = go_return_penalty( $id->user_id );
$minutes = go_return_minutes( $id->user_id );
$currency = go_return_currency( $id->user_id );
$points = go_return_points( $id->user_id );
$badge_count = go_return_badge_count( $id->user_id );
go_get_rank( $id->user_id );
global $current_rank;
echo "<tr id='user_{$id->user_id}'>
<td><input class='go_checkbox' type='checkbox' name='go_selected' value='{$id->user_id}'/></td>
<td><span><a href='#' onclick='go_admin_bar_stats_page_button("{$id->user_id}");'>{$user_login}</a></td>
<td>{$class_a[ $class_a_choice]}</td>
<td><a href='{$user_url}' target='_blank'>{$user_last_name}, {$user_first_name}</a></td>
<td>{$user_display}</td>
<td>{$current_rank}</td>
".( (go_return_options( 'go_focus_switch' ) == 'On' ) ? "<td><select class='go_focus' onchange='go_user_focus_change("{$id->user_id}", this);'>{$focuses_list}</select</td>" : '' )."
<td class='user_points'>{$points}</td>
<td class='user_currency'>{$currency}</td>
<td class='user_bonus_currency'>{$bonus_currency}</td>
<td class='user_penalty'>{$penalty}</td>
<td class='user_minutes'>{$minutes}</td>
<td class='user_badge_count'>{$badge_count}</td>
</tr>";
}
}
die();
}
function go_clipboard_intable_messages() {
global $wpdb;
$admin_messages = get_user_meta(get_current_user_id(), 'go_admin_message_history', true );
foreach ( $admin_messages as $student_id => $messages ) {
$user_data_key = get_userdata( $student_id );
$class_a_messages = get_user_meta( $student_id, 'go_classifications', true );
$class_a_choice_messages = $_POST['go_clipboard_class_a_choice_messages'];
$user_login = $user_data_key->user_login;
$user_display = $user_data_key->display_name;
$user_first_name = $user_data_key->user_firstname;
$user_last_name = $user_data_key->user_lastname;
$user_url = $user_data_key->user_url;
$array_count = count( $messages );
if ( ! empty( $class_a_messages[ $class_a_choice_messages ] ) ) {
for ( $i = $array_count - 1; $i >= 0; $i-- ) {
echo "<tr id='user_{$student_id}'>
<td><span><a href='#' onclick='go_admin_bar_stats_page_button("{$student_id}");'>{$user_login}</a></td>
<td>{$class_a_messages[$class_a_choice_messages]}</td>
<td><a href='{$user_url}' target='_blank'>{$user_last_name}, {$user_first_name}</a></td>
<td>{$user_display}</td>
<td>{$messages[$i]['time']}</td>
<td class='message'>{$messages[$i]['message']}</td>
</tr>";
}
} elseif ( $class_a_choice_messages == 'All' ) {
foreach ( $class_a_messages as $computer ) {
for ( $i = $array_count - 1; $i >= 0; $i-- ) {
echo "<tr id='user_{$student_id}'>
<td><span><a href='#' onclick='go_admin_bar_stats_page_button("{$student_id}");'>{$user_login}</a></td>
<td>{$computer}</td>
<td><a href='{$user_url}' target='_blank'>{$user_last_name}, {$user_first_name}</a></td>
<td>{$user_display}</td>
<td>{$messages[$i]['time']}</td>
<td class='message'>{$messages[$i]['message']}</td>
</tr>";
}
}
}
}
die();
}
add_action( 'wp_ajax_go_clipboard_add','go_clipboard_add' );
function go_clipboard_add() {
$ids = $_POST['ids'];
$points = $_POST['points'];
$currency = $_POST['currency'];
$bonus_currency = $_POST['bonus_currency'];
$penalty = $_POST['penalty'];
$minutes = $_POST['minutes'];
$reason = $_POST['reason'];
$badge_ID = $_POST['badge_ID'];
foreach ( $ids as $key => $value ) {
if ( $reason != '' ) {
if ( $points != '' ) {
go_add_currency( $value, $reason, 6, $points, 0, false );
}
if ( $currency!= '' ) {
go_add_currency( $value, $reason, 6, 0, $currency, false );
}
if ( $bonus_currency!= '' ) {
go_add_bonus_currency( $value, $bonus_currency, $reason );
}
if ( $penalty!= '' ) {
go_add_penalty( $value, $penalty, $reason );
}
if ( $minutes!= '' ) {
go_add_minutes( $value, $minutes, $reason );
}
if ( $badge_ID != '' ) {
do_shortcode( "[go_award_badge id='{$badge_ID}' repeat = 'off' uid='{$value}']" );
}
go_message_user( $value, $reason );
}
}
die();
}
function go_update_user_focuses() {
$new_user_focus = stripslashes( $_POST['new_user_focus'] );
$user_id = $_POST['user_id'];
if ( $new_user_focus != 'No '.go_return_options( 'go_focus_name' ) ) {
update_user_meta( $user_id, 'go_focus', array( $new_user_focus ) );
} else {
update_user_meta( $user_id, 'go_focus', array() );
}
echo $new_user_focus;
die();
}
add_action( 'wp_ajax_fixmessages', 'fixmessages' );
function fixmessages() {
global $wpdb;
$users = get_users(array( 'role' => 'Subscriber' ) );
foreach ( $users as $user ) {
$messages = get_user_meta( $user->ID, 'go_admin_messages',true );
$messages_array = $messages[1];
$messages_unread = array_values( $messages_array );
$messages_unread_count = 0;
foreach ( $messages_unread as $message_unread ) {
if ( $message_unread[1] == 1) {
$messages_unread_count++;
}
}
if ( $messages[0] != $message_unread_count ) {
$messages[0] = $messages_unread_count;
update_user_meta( $user->ID, 'go_admin_messages', $messages );
}
}
die();
}
?>