-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass-registration-actions-hooks.php
More file actions
231 lines (177 loc) · 6.92 KB
/
class-registration-actions-hooks.php
File metadata and controls
231 lines (177 loc) · 6.92 KB
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
<?php
/**
* Register a custom menu page.
*/
function ifl_register_class_reg_menu_page() {
add_menu_page(
__( 'Class Registration', 'textdomain' ),
'Class Registration',
'edit_posts',
'class-registration',
'ifl_test_function',
'',
6
);
}
add_action( 'admin_menu', 'ifl_register_class_reg_menu_page' );
function ifl_test_function() {
if (isset($_POST['update_class_name'])) {
if ( ! isset( $_POST['class-select-nonce'] ) || ! wp_verify_nonce( $_POST['class-select-nonce'], 'class-select' ) ) {
$errors['nonce-error'] = "Nonce check failed.";
} else {
$update_selected_class_name = $_POST['update_class_name'];
$instructor_email_address = $_POST['instructor_email_address'];
update_option('ifl_selected_class_name', $update_selected_class_name);
}
} else if (isset($_POST['submit'])) {
///Needs Nonce
}
$selected_class_name = get_option('ifl_selected_class_name');
$form_id = '27';
$class_names = array();
$paging = array('offset' => 0, 'page_size' => 100);
$entries = GFAPI::get_entries($form_id, $paging);
?>
<div class="wrap">
<p>
<form name="select_event" method="post" action="#">
<input type='hidden' name='instructor_email_address' value='<?php echo $instructor_email_address;?>'/>
<?php wp_nonce_field('class-select','class-select-nonce'); ?>
<select id="selected_class_name" name="update_class_name" onchange="this.form.submit()">
<?php
foreach($entries as $key => $entry) {
$class_name = $entry[15];
if (!in_array($class_name,$class_names)) {
array_push($class_names,$class_name);
$selected = ($selected_class_name == $class_name) ? 'selected = "selected"' : '';
echo '<option value="'.$class_name.'" '.$selected.'>'.$class_name.'</option>';
}
}
echo '</select></form></p>';
// pr($res);
//pr($class_names);
$search_criteria = array(
'status' => 'active',
'field_filters' => array(
'mode' => 'any',
array(
'key' => '15',
'value' => $selected_class_name
)
)
);
// Getting the entries
$result = GFAPI::get_entries( $form_id, $search_criteria );
$studentEmailAddresses = array();
echo '<table class="wp-list-table widefat fixed striped table-view-list"><thead><tr><td>Date Created</td><td>Name</td><td>Email</td><td>Entry Link</td><td>Transaction Link</td></tr></thead><tbody>';
foreach($result as $key => $entry) {
echo '<tr><td>'.$entry['date_created'].'</td><td>'.$entry['1.3'].' '. $entry['1.6'] . '</td><td><a href="mailto:'.$entry[2].'">'.$entry[2].'</a></td><td><a href="/wp-admin/admin.php?page=gf_entries&view=entry&lid='.$entry['id'].'&id='.$entry['form_id'].'" target="_blank">Entry #'.$entry['id'].'</a></td><td><a href="https://dashboard.stripe.com/payments/'.$entry['transaction_id'].'" target="_blank">Tr Link</a><td> </tr>';
array_push($studentEmailAddresses, $entry[2]);
$instructor_email_address = $entry['23'];
// //wp-admin/admin.php?page=gf_entries&view=entry&id='.$entry['id'].'&lid='.$entry['lid']
//pr($entry);
}
echo "</tbody></table>";
// echo "<p><code>".implode(',', $studentEmailAddresses)."</code></p>";
// construct mailto with instructor email address (if entered) and to bcc all students
//if ($instructor_email_address != "") {
$mailtoAllStr = "mailto:" . $instructor_email_address . "?bcc=" . implode(';', $studentEmailAddresses);
//} else {
// $mailtoAllStr = "mailto:?bcc=" . implode(';', $studentEmailAddresses);
//}
// Button to email the instructor (if email address entered) and BCC all students
echo "<p><a href=" . $mailtoAllStr . "><button id='emailAll'>Email all</button></a></p>";
?>
</div>
<?php
/*
[status] => active
[15] => test
[1.3] => Jordan
[1.6] => Layman
[2] => santacruz@ideafablabs.com
[22.1] => active
[10.1] => Price
[10.2] => 160
[10.3] => 1
*/
}
/**
* Shortcode wrapper for event registration form.
* @shortcode definition
* Usage: [classregister event="Event Title Goes Here" instructor="example@gmail.com" memberpricing="active" memberprice="45" price="60" capacity="8" ]
*/
add_shortcode( 'classregister', 'ifl_classregistration_wrapper' );
function ifl_classregistration_wrapper($atts) {
$args = shortcode_atts(array(
'regform' => 27,
'class' => '',
'instructor' => '',
'price' => '',
'memberpricing' => 'inactive',
'memberprice' => '',
'capacity' => '0',
'classFieldID' => '15'
), $atts);
$response = "";
$regform = $args['regform'];
$class = $args['class'];
$classFieldID = $args['classFieldID'];
$capacity = $args['capacity'];
$instructor = $args['instructor'];
$classFull = 0;
// get entries from this form where $class is the same and check entry count.
// if price = '' then show there is supposed to be a form here but ...;
// if cap is met, show class is full...
if ($capacity > 0) {
$search_criteria = array(
'field_filters' => array(
array(
'key' => '15',
'value' => $class
),
)
);
$entry_count = GFAPI::count_entries($regform,$search_criteria);
/// need to add a check for something like "enrolled == 1" to filter people who unenrolled.
if ($entry_count >= $capacity) {
$classFull = 1;
}
}
//$class = (isset($args['event_id'])) ? $_REQUEST['event_id'] : $args['event_id'];
$submit = (isset($_REQUEST['submit'])) ? $_REQUEST['submit'] : '0';
// pr($attendee_count);
// Begin response html string.
// $response .= '<div class="registration container">';
// Complete with Entry GForm and go back to Entry List or Create New User again.
if ($submit) {
// $response .= "<p>Submitted</p>";
// pr($_REQUEST['submit']);
} else {
/// we want to also check if the registration entry has a 'cancelled' flag on it...
$response .= '<p><strong>Seats remaining: '.($capacity - $entry_count).'/'.$capacity.'</strong></p>';
if ($classFull) {
$response .= '<p class="notice">Sorry this class is full...</p>';
} else {
$field_values = array(
'class' => $args['class'],
'price' => $args['price'],
'memberprice' => $args['memberprice'],
'memberpricing' => $args['memberpricing'],
'instructor' => $args['instructor'],
);
//[gravityform id="27" title="true" description="true" ajax="true" field_values='class=Introduction to Wood Shop&price=160&memberprice=140&memberpricing=active&instructor=altavistaforest@gmail.com']
// class=Introduction to Wood Shop&
// price=160
// memberprice=140
// memberpricing=active
// instructor=altavistaforest@gmail.com
//gravity_form( $id_or_title, $display_title = true, $display_description = true, $display_inactive = false, $field_values = null, $ajax = false, $tabindex, $echo = true );
$response .= '<div class="heh">';
$response .= gravity_form( $regform, true, true, false, $field_values, true, 1, false);
$response .= "</div>";
}
}
return $response;
}
?>