This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
/
ifcrush_event.php
167 lines (143 loc) · 4.7 KB
/
ifcrush_event.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
<?php
/**
** This file contains all the support functions for the table ifcrush_events.
** Events can only be created by recruitment (or rush) chairs.
** The event table is created with the SQL below.
** fratID is user meta ifcrush_frat_letters
**
** CREATE TABLE $event_table_name (
** eventDate date not null,
** title varchar(30) not null,
** eventID int not null auto_increment,
** fratID varchar(3) not null,
** PRIMARY KEY(eventID)
** ) engine = InnoDB;
**/
/**
* Display events for a fraternity
* Args - the fraternity letters specified by the meta data ifcrush_frat_letters
*
**/
function ifcrush_display_events( $frat_letters ) {
global $wpdb;
$event_table_name = $wpdb->prefix . "ifc_event";
$query = "SELECT * FROM $event_table_name where fratID='$frat_letters'";
$allevents = $wpdb->get_results( $query );
create_event_table_header();
create_event_add_row( $frat_letters );
if ( $allevents ) {
foreach ( $allevents as $event ) {
create_event_table_row( $event );
}
} else {
?><h3>No events. Add one!</h3><?php
}
create_event_table_footer(); // end the table
}
/**
* Fraternity events are displayed with three action buttons:
* Updated, Delete, and Show PNMs.
* This function is the form handler for all three.
* This function is going to add an event for the passed $frat_letters
* This function is called from ifcrush_frat with $frat_letters
**/
function ifcrush_event_handle_form($frat_letters) {
global $debug;
if ( $debug ){
echo "[ifcrush_event_handle_form] $frat_letters";
echo "<pre>"; print_r($_POST); echo "</pre>";
}
$thisevent = array(
/** eventID will be null on insert **/
'eventID' => ( isset( $_POST['eventID'] ) ? $_POST['eventID']: ""),
'eventDate' => $_POST['eventDate'],
'title' => $_POST['eventTitle'],
'fratID' => $frat_letters
); // put the form input into an array
switch ( $_POST['action'] ) {
case "Update Event":
updateEvent( $thisevent );
break;
case "Delete Event":
deleteEvent( $thisevent );
break;
case "Add Event":
addEvent( $thisevent );
break;
default:
echo "[ifcrush_event_handle_form]: bad action";
}
}
/* Event_handler_form helpers */
function addEvent( $thisevent ) {
global $wpdb;
$table_name = $wpdb->prefix . "ifc_event";
$rows_affected = $wpdb->insert( $table_name, $thisevent );
if (0 == $rows_affected ) {
echo "INSERT ERROR for " . $thisevent['eventDate']. $thisevent['title'] . $thisevent['frat'];
}
return $rows_affected;
} // adds a event to the table if addEvent is tagged
function updateEvent( $thisevent ) {
global $wpdb;
$table_name = $wpdb->prefix . "ifc_event";
$where = array( 'eventID' => $thisevent['eventID'] );
$wpdb->update( $table_name, $thisevent, $where );
} // updates a event with a matching eventID if updateEvent is tagged
function deleteEvent( $thisevent ) {
global $wpdb;
$table_name = $wpdb->prefix . "ifc_event";
$wpdb->delete( $table_name, $thisevent );
} // deletes a event if deleteEvent is tagged
function create_event_table_header() {
?>
<div id="eventError"></div>
<div class="ifcrushtable">
<div class="ifcrushtablerow">
<div class="ifcrushtablecellnarrow">Date</div>
<div class="ifcrushtablecellnarrow">Title</div>
<div class="ifcrushtablecellauto"></div>
</div>
<?php
}
function create_event_table_footer() {
?></div><?php
}
function create_event_add_row($frat_letters) {
?>
<div class="ifcrushtableaddrow">
<form method="post" class="eventForm">
<div class="ifcrushtablecellnarrow">
<input type="text" name="eventDate" id="addDate" class="datepicker" value="select date">
</div>
<div class="ifcrushtablecellnarrow">
<input type="text" name="eventTitle" id="addEventTitle" size=20 value="enter event title"/>
</div>
<div class="ifcrushtablecellauto">
<input type="submit" name="action" id="addEventButton" value="Add Event"/>
</div>
</form>
</div><!-- end ifcrushtableaddrow -->
<?php
}
function create_event_table_row($event) {
?>
<div class="ifcrushtablerow">
<form method="post" class="eventForm">
<div class="ifcrushtablecellnarrow">
<input type="text" name="eventDate" class="datepicker" value="<?php echo $event->eventDate;?>"/>
</div>
<div class="ifcrushtablecellnarrow">
<input type="text" name="eventTitle" size=20 value="<?php echo $event->title; ?>"/>
<input type="hidden" name="eventID" value="<?php echo $event->eventID; ?>" />
</div>
<div class="ifcrushtablecellauto">
<input type="submit" name="action" value="Update Event"/>
<input type="submit" name="action" value="Delete Event"/>
<input type="submit" name="action" value="Show PNMS"/>
</div>
</form>
</div>
<?php
}
?>