-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_registration.php
258 lines (250 loc) · 7.69 KB
/
update_registration.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
<?php
//Makes registration edits to campers
header("Content-Type: application/json; charset=UTF-8");
$obj = json_decode( stripslashes($_POST["x"]), true);
$arrayKeys = array_keys($obj);
//Database shtuff
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
if (!is_user_logged_in()) exit("Thus I refute thee.... P.H.");
global $wpdb;
//Pull in our payments class
require_once __DIR__ . '/requires/payments.php';
if (isset($obj["delete_payment_id"]))
{
if(wp_verify_nonce( $obj["wp_nonce"], 'delete_payment_'.$obj["delete_payment_id"] ))
{
$wpdb->query($wpdb->prepare("DELETE FROM " . $GLOBALS['srbc_payments']. " WHERE payment_id=%d;",$obj["delete_payment_id"]));
echo "Payment Sucessfully Deleted!";
}
else
wp_nonce_ays("");
}
else if (isset($obj["reactivate_id"]))
{
//Move inactive registration to active registration database
$query = $wpdb->query($wpdb->prepare("INSERT INTO " . $GLOBALS['srbc_registration'] . " SELECT * FROM " . $GLOBALS['srbc_registration_inactive'].
" WHERE registration_id=%d;",$obj["reactivate_id"]));
if($query === 0 || $query === false)
{
exit("Something went wrong with the moving query");
}
else
{
$wpdb->query($wpdb->prepare("DELETE FROM " . $GLOBALS['srbc_registration_inactive']. " WHERE registration_id=%d;",$obj["reactivate_id"]));
echo "Reactivated Registration and Saved Sucessfully";
}
}
else if (isset($obj["deactivate_id"]))
{
//Delete the requested registration
$query = $wpdb->query($wpdb->prepare("INSERT INTO " . $GLOBALS['srbc_registration_inactive']. " SELECT * FROM " .
$GLOBALS['srbc_registration']. " WHERE registration_id=%d;",$obj["deactivate_id"]));
if($query === false || $query === 0 )
{
//Thanks so much to :https://dba.stackexchange.com/questions/75532/query-to-compare-the-structure-of-two-tables-in-mysql/75651#75651?newreg=52c95cc1e3144bc287f834a1a25b2923
//TODO add this to peter hawke health report.
//Checks if the srbc_registration and srbc_registration_inactive database have the same structure.
$error_msg = $wpdb->get_var("SELECT IF(COUNT(1)>0,'Differences','No Differences') Comparison FROM
(
SELECT
column_name,ordinal_position,
data_type,column_type,COUNT(1) rowcount
FROM information_schema.columns
WHERE table_schema=DATABASE()
AND table_name IN ('srbc_registration','srbc_registration_inactive')
GROUP BY
column_name,ordinal_position,
data_type,column_type
HAVING COUNT(1)=1
) A;");
/*Saving this code for the Peter Hawke console update
$error_verbose = $wpdb->get_results("SELECT column_name,ordinal_position,data_type,column_type FROM
(
SELECT
column_name,ordinal_position,
data_type,column_type,COUNT(1) rowcount
FROM information_schema.columns
WHERE table_schema=DATABASE()
AND table_name IN ('srbc_registration','srbc_registration_inactive')
GROUP BY
column_name,ordinal_position,
data_type,column_type
HAVING COUNT(1)=1
) A;"); */
echo "\rDatabase " . $error_msg;
//echo "\rDatabase message: " . var_dump($error_verbose);
exit("\rSomething went wrong with the moving query");
}
else
{
$wpdb->query($wpdb->prepare("DELETE FROM " . $GLOBALS['srbc_registration']. " WHERE registration_id=%d;",$obj["deactivate_id"]));
echo "Deactivated Registration and Saved Sucessfully";
}
}
//Add the camper to another camp
else if(isset($obj["add_camp_id"]))
{
$currentDate = new DateTime("now", new DateTimeZone('America/Anchorage'));
//Insert query into database
try
{
$wpdb->insert(
'srbc_registration',
array(
'registration_id' =>0,
'camp_id' => $obj["add_camp_id"],
'camper_id' => $obj["camper_id"],
'date' => $currentDate->format("m/d/Y h:i A"),
'horse_opt' => 0,
'busride' => "none",
'waitlist' => 0,
'horse_waitlist' => 0,
'registration_notes' => ""
),
array(
'%d',
'%d',
'%d',
'%s',
'%d',
'%s',
'%d',
'%d',
'%s'
)
);
}
catch(Exception $e)
{
Email::emailDeveloper($e->getMessage());
}
}
else if(isset($obj["registration_id"])){
//Change registration to another camp
//Check if they didn't actually change the camp
if ($obj["change_to_id"] == "none"){
echo "Please specify a camp to change to!";
return;
}
$wpdb->update(
$GLOBALS['srbc_registration'],
array(
'camp_id' => $obj["change_to_id"],
),
array( 'registration_id' => $obj["registration_id"] ),
array(
'%d',
),
array( '%d' )
);
echo "Change Successful";
//Also change over all the payments made for that camp
}
else {
//TODO: Use an array or something so I don't have to manually enter a new field everytime I add one
//Update Camper
$wpdb->update(
$GLOBALS['srbc_campers'],
array(
'camper_first_name' => $obj["camper"]["camper_first_name"],
'camper_last_name' => $obj["camper"]["camper_last_name"],
'birthday' => $obj["camper"]["birthday"],
'age' => $obj["camper"]["age"],
'gender' => $obj["camper"]["gender"],
'grade' => $obj["camper"]["grade"],
'parent_first_name' => $obj["camper"]["parent_first_name"],
'parent_last_name' => $obj["camper"]["parent_last_name"],
'email' => $obj["camper"]["email"],
'phone' => $obj["camper"]["phone"],
'phone2' => $obj["camper"]["phone2"],
'address' => $obj["camper"]["address"],
'city' => $obj["camper"]["city"],
'state' => $obj["camper"]["state"],
'zipcode' => $obj["camper"]["zipcode"],
'notes' => $obj["camper"]["notes"],
'tshirt_size' => $obj["camper"]["tshirt_size"]
),
array( 'camper_id' => $obj["camper"]["id"] ),
array(
'%s',
'%s',
'%s',
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
),
array( '%d' )
);
//Update registrations
//Make this one less because our last key is camper
for($i = 0;$i < (count($obj)-1); $i++){
//Current registration key for database
$key = $arrayKeys[$i];
//Update camper first - essential to payments since we check this stuff. So make sure we write this stuff first
$wpdb->update(
$GLOBALS['srbc_registration'],
array(
'assistant_counselor' => $obj[$key]["assistant_counselor"],
'counselor' => $obj[$key]["counselor"],
'lodging' => $obj[$key]["lodging"],
'horse_opt' => $obj[$key]["horse_opt"],
'busride' => $obj[$key]["busride"],
'discount' => $obj[$key]["discount"],
'discount_type' => $obj[$key]["discount_type"],
'scholarship_amt' => $obj[$key]["scholarship_amt"],
'scholarship_type' => $obj[$key]["scholarship_type"],
'checked_in' => $obj[$key]["checked_in"],
'health_form' => $obj[$key]["health_form"],
'waitlist' => $obj[$key]["waitlist"],
'horse_waitlist' => $obj[$key]["horse_waitlist"],
'packing_list_sent' => $obj[$key]["packing_list_sent"],
'registration_notes' => $obj[$key]["registration_notes"]
),
array( 'registration_id' => $key ),
array(
'%s',
'%s',
'%s',
'%d',
'%s',
'%f',
'%s',
'%f',
'%s',
'%d',
'%d',
'%d',
'%d',
'%d',
'%s'
),
array( '%d' )
);
if ($obj[$key]["snackshop"] != "")
{
Payments::makePayment($key,$obj[$key]['snackshop_payment_type'],$obj[$key]["snackshop"],
"","Store");
}
if($obj[$key]["auto_payment_amt"] != "")
{
//Last argument is for archiveFriendly which we do want
Payments::autoPayment($key,$obj[$key]["auto_payment_amt"],$obj[$key]["auto_payment_type"],
$obj[$key]["auto_note"], true);
}
else if ($obj[$key]["payment_type"] != "none"){
Payments::makePayment($key,$obj[$key]["payment_type"],$obj[$key]["payment_amt"],
$obj[$key]["note"],$obj[$key]["fee_type"]);
}
}
echo "Data Saved Sucessfully";
}
?>