This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifcrush_frat.php
289 lines (252 loc) · 7.3 KB
/
ifcrush_frat.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
<?php
/**
** This file contains all the support functions for the table ifcrush_frat
**/
/**
* ifcrush_frat() shortcode entry point
* Fraternities can view their events, create events, register PNMs
*
* KBL todo - on failure to access due to login, maybe we should add a link to the
* login page
**/
function ifcrush_frat(){
global $debug;
if ( $debug ) echo "[ifcrush_frat] ";
if ( false == is_user_logged_in() ) {
echo "sorry you must logged in as a recruitment chair to use this page.";
return;
}
$current_user = wp_get_current_user();
if ( is_user_an_rc( $current_user ) ){
$frat_letters = get_frat_letters( $current_user );
} else {
echo "sorry you must be a recruitment chair to use this page";
return;
}
/* Now I know who I am.
* Lets see if there are any forms to handle
*/
if ( isset( $_POST['action'] ) ){
ifcrush_frat_handle_forms( $_POST['action'], $frat_letters );
} else {
/* Create the options for a fraternity.*/
echo "Hello $frat_letters.";
ifcrush_frat_show_options();
}
}
function ifcrush_frat_handle_forms( $action,$frat_letters ){
ifcrush_frat_show_options();
switch ( $action ) {
case "View Reports":
//ifcrush_display_done_form( "Return to Event List" );
echo "<h2>Reports for $frat_letters</h2>";
echo '<div id="accordion">';
ifcrush_create_frat_report( $frat_letters );
echo '</div>';
break;
case "Update Event":
case "Delete Event":
case "Add Event":
ifcrush_event_handle_form( $frat_letters );
ifcrush_display_events( $frat_letters );
break;
case "Show PNMS":
ifcrush_display_done_form( "Return to Event List" );
ifcrush_display_register_pnm_at_event( $_POST['eventID'], $frat_letters );
break;
case "Delete Event Reg":
ifcrush_display_done_form( "Finished showing PNMS" );
/* add function call to delete this event registration */
ifcrush_eventreg_handle_form( "delete registration" );
ifcrush_display_register_pnm_at_event( $_POST['eventID'], $frat_letters );
break;
case "Register this PMN":
ifcrush_display_done_form( "Finished showing PNMS" );
/* add this specific PMN to the event, and then display everything */
ifcrush_eventreg_handle_form( "add registration" );
ifcrush_display_register_pnm_at_event( $_POST['eventID'] );
break;
case "Register PMNs":
ifcrush_display_done_form( "Finished showing PNMS" );
/* display the pmns registered for this event and a form for one more */
ifcrush_display_register_pnm_at_event( $_POST['eventID'] );
break;
case "View Event Table":
echo "<h2>Event Table for $frat_letters</h2>";
ifcrush_display_events( $frat_letters );
break;
case "View Bid Offer Form":
ifcrush_bid_show_bid_form( $frat_letters );
break;
case "Create Bid":
ifcrush_bid_handle_bid_form( $frat_letters );
break;
default:
echo "unknown action : $action<br>";
//die();
}
}
/**
* I want an array of arrays (or objects) where each element is a pmn with their name
* and netID. I'd like to use a select so there is only one query.
* So, I get all the meta data for users (I don't need the user table)
* and create one array element for each user with meta data.
* Then I copy just the users I want into another array.
**/
function ifcrush_get_all_frats(){
global $wpdb;
$table_name = $wpdb->prefix . "usermeta";
$query = "select
um1.meta_value as ifcrush_frat_letters,
um2.meta_value as ifcrush_frat_fullname
from $table_name as um1
left join $table_name as um2 on um1.user_id = um2.user_id
where
um1.meta_key='ifcrush_frat_letters' AND
um2.meta_key='ifcrush_frat_fullname' AND
um1.user_id IN (SELECT user_id FROM $table_name WHERE meta_key='ifcrush_role' and meta_value='rc')
order by ifcrush_frat_fullname";
$all_frats = $wpdb->get_results( $query );
return($all_frats);
}
function is_rc( $user ){
return isset( $user['ifcrush_role'] ) && ( $user['ifcrush_role'] == 'rc' );
}
function ifcrush_frat_show_options(){
?>
<form method="post">
<input type="submit" name="action" value="View Reports"/>
<input type="submit" name="action" value="View Event Table"/>
<input type="submit" name="action" value="View Bid Offer Form"/>
</form>
<?php
}
function ifcrush_display_done_form( $label ){
?>
<br><form method="post">
<input type="submit" value="<?php echo $label; ?>"/>
</form>
<hr>
<?php
}
/* display frats in a list */
function ifcrush_list_frats(){
global $wpdb;
$allfrats = ifcrush_get_all_frats();
echo "<h3>List of Fraternities</h3><div>";
if ( $allfrats ) {
echo "<table>";
echo "<tr><th>Letters</th><th>Fullname</th><th></th></tr>
";
foreach ( $allfrats as $thisfrat ){
$letters = $thisfrat->ifcrush_frat_letters;
$fullname = $thisfrat->ifcrush_frat_fullname;
echo "<tr><td>$letters</td><td>$fullname</td><td></td></tr>
";
}
echo "</table>
";
} else {
echo "No Frats to list!";
}
echo "</div>";
}
function ifcrush_list_frats_and_events(){
global $wpdb;
$allfrats = ifcrush_get_all_frats();
if ( $allfrats ) {
echo "<h3>Fraternities and Events</h3>";
echo "<table>";
echo "<tr><th>Letters</th><th>Fullname</th><th></th></tr>";
foreach ( $allfrats as $thisfrat ){
$letters = $thisfrat->ifcrush_frat_letters;
$fullname = $thisfrat->ifcrush_frat_fullname;
echo "<tr><td>$letters</td><td>$fullname</td><td>Add Report</td></tr>";
}
echo "</table>";
} else {
?><h2>No Frats to list events for!</h2><?php
}
}
/**
* ifcrush_display_frats - this is an admin function
**/
function ifcrush_display_frats(){
// if ( false == is_user_admin() ) {
// echo "sorry you must be an admin to view fraternities";
// return;
// }
global $wpdb;
$allfrats = ifcrush_get_all_frats();
if ( $allfrats ) {
create_frat_table_header();
foreach ( $allfrats as $frat ){
create_frat_table_row($frat);
}
create_frat_table_footer();
} else {
?><h2>No Frats to display!</h2><?php
}
}
function create_frat_table_header(){
?>
<div class="ifcrushtable">
<div class="ifcrushtablerow">
<div class="ifcrushtablecellnarrow">
Fraternity
</div>
<div class="ifcrushtablecellnarrow">
Recruitment chair
</div>
<div class="ifcrushtablecellauto">
Action
</div>
</div><!--end ifcrushtablerow-->
<?php
}
function create_frat_table_footer(){
?>
</div><!-- end frat table-->
<?php
}
function create_frat_table_row($thisfrat){
$letters = $thisfrat->ifcrush_frat_letters;
$fullname = $thisfrat->ifcrush_frat_fullname;
?>
<br>
<div class="ifcrushtablerow">
<div class="ifcrushtablecellnarrow">
<?php
echo $fullname;
?>
</div><!-- end fratid-->
<div class="ifcrushtablecellnarrow">
<?php
echo $letters;
?>
</div><!-- end rushchair-->
<div class="ifcrushtableauto">
</div><!-- end frataction-->
</div><!-- end ifcrushtablerow-->
<?php
}
/** just keeping this around **/
function create_rc_frat_menu( $current ){
$allfrats = ifcrush_get_all_frats();
?>
<select name="fratID">
<option value="none">select fraternity</option>
<?php
foreach ( $allfrat as $thisfrat ) {
$letters = $thisfrat->ifcrush_frat_letters;
$fullname = $thisfrat->ifcrush_frat_fullname;
if ( $frat_letters == $current ) {
echo "<option value=\"$letters\" selected=\"selected\">$fullname</option>\n";
} else {
echo "<option value=\"$letters\">$fullname</option>\n";
}
}
?>
</select>
<?php
}