@@ -177,7 +177,7 @@ |
||
177 | 177 | |
178 | 178 | /** |
179 | 179 | * @since 4.1.0 |
180 | - * @return int |
|
180 | + * @return string |
|
181 | 181 | */ |
182 | 182 | public function get_permissions() |
183 | 183 | { |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | '_upload_to' => $this->_get_wp_uploads_dir(), |
65 | 65 | '_download_from' => '', |
66 | 66 | '_permissions' => 0644, |
67 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
67 | + '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default' |
|
68 | 68 | ); |
69 | 69 | |
70 | 70 | $props = array_merge($defaults, $init); |
71 | 71 | |
72 | 72 | foreach ($props as $property => $val) { |
73 | - $setter = 'set' . $property; |
|
73 | + $setter = 'set'.$property; |
|
74 | 74 | if (method_exists($this, $setter)) { |
75 | 75 | $this->$setter($val); |
76 | 76 | } else { |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | // make sure we include the required wp file for needed functions |
95 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
95 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | // setup temp dir |
219 | 219 | $temp_file = wp_tempnam($this->_download_from); |
220 | 220 | |
221 | - if (!$temp_file) { |
|
221 | + if ( ! $temp_file) { |
|
222 | 222 | EE_Error::add_error( |
223 | 223 | esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
224 | 224 | __FILE__, |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
232 | 232 | |
233 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
233 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file); |
|
234 | 234 | |
235 | 235 | $response = wp_safe_remote_get($this->_download_from, $wp_remote_args); |
236 | 236 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $file = $temp_file; |
270 | 270 | |
271 | 271 | // now we have the file, let's get it in the right directory with the right name. |
272 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
272 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this); |
|
273 | 273 | |
274 | 274 | // move file in |
275 | 275 | if (false === @ rename($file, $path)) { |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | public function set_upload_from($upload_from) |
311 | 311 | { |
312 | 312 | EE_Error::doing_it_wrong( |
313 | - __CLASS__ . '::' . __FUNCTION__, |
|
313 | + __CLASS__.'::'.__FUNCTION__, |
|
314 | 314 | __( |
315 | 315 | 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from', |
316 | 316 | 'event_espresso' |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | public function get_upload_from() |
330 | 330 | { |
331 | 331 | EE_Error::doing_it_wrong( |
332 | - __CLASS__ . '::' . __FUNCTION__, |
|
332 | + __CLASS__.'::'.__FUNCTION__, |
|
333 | 333 | __( |
334 | 334 | 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from', |
335 | 335 | 'event_espresso' |
@@ -14,328 +14,328 @@ |
||
14 | 14 | class EEH_Sideloader extends EEH_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @since 4.1.0 |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private $_upload_to; |
|
22 | - |
|
23 | - /** |
|
24 | - * @since 4.10.5.p |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private $_download_from; |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 4.1.0 |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private $_permissions; |
|
34 | - |
|
35 | - /** |
|
36 | - * @since 4.1.0 |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $_new_file_name; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
44 | - * |
|
45 | - * @since 4.1.0 |
|
46 | - * @param array $init array fo initializing the sideloader if keys match the properties. |
|
47 | - */ |
|
48 | - public function __construct($init = array()) |
|
49 | - { |
|
50 | - $this->_init($init); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * sets the properties for class either to defaults or using incoming initialization array |
|
56 | - * |
|
57 | - * @since 4.1.0 |
|
58 | - * @param array $init array on init (keys match properties others ignored) |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - private function _init($init) |
|
62 | - { |
|
63 | - $defaults = array( |
|
64 | - '_upload_to' => $this->_get_wp_uploads_dir(), |
|
65 | - '_download_from' => '', |
|
66 | - '_permissions' => 0644, |
|
67 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
68 | - ); |
|
69 | - |
|
70 | - $props = array_merge($defaults, $init); |
|
71 | - |
|
72 | - foreach ($props as $property => $val) { |
|
73 | - $setter = 'set' . $property; |
|
74 | - if (method_exists($this, $setter)) { |
|
75 | - $this->$setter($val); |
|
76 | - } else { |
|
77 | - // No setter found. |
|
78 | - EE_Error::add_error( |
|
79 | - sprintf( |
|
80 | - esc_html__( |
|
81 | - 'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $setter, |
|
85 | - $property |
|
86 | - ), |
|
87 | - __FILE__, |
|
88 | - __FUNCTION__, |
|
89 | - __LINE__ |
|
90 | - ); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - // make sure we include the required wp file for needed functions |
|
95 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - // utilities |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @since 4.1.0 |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - private function _get_wp_uploads_dir() |
|
107 | - { |
|
108 | - } |
|
109 | - |
|
110 | - // setters |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * sets the _upload_to property to the directory to upload to. |
|
115 | - * |
|
116 | - * @since 4.1.0 |
|
117 | - * @param $upload_to_folder |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function set_upload_to($upload_to_folder) |
|
121 | - { |
|
122 | - $this->_upload_to = $upload_to_folder; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * sets the _download_from property to the location we should download the file from. |
|
128 | - * |
|
129 | - * @since 4.10.5.p |
|
130 | - * @param string $download_from The full path to the file we should sideload. |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function set_download_from($download_from) |
|
134 | - { |
|
135 | - $this->_download_from = $download_from; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * sets the _permissions property used on the sideloaded file. |
|
141 | - * |
|
142 | - * @since 4.1.0 |
|
143 | - * @param int $permissions |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function set_permissions($permissions) |
|
147 | - { |
|
148 | - $this->_permissions = $permissions; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * sets the _new_file_name property used on the sideloaded file. |
|
154 | - * |
|
155 | - * @since 4.1.0 |
|
156 | - * @param string $new_file_name |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function set_new_file_name($new_file_name) |
|
160 | - { |
|
161 | - $this->_new_file_name = $new_file_name; |
|
162 | - } |
|
163 | - |
|
164 | - // getters |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @since 4.1.0 |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_upload_to() |
|
172 | - { |
|
173 | - return $this->_upload_to; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @since 4.10.5.p |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_download_from() |
|
182 | - { |
|
183 | - return $this->_download_from; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @since 4.1.0 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_permissions() |
|
192 | - { |
|
193 | - return $this->_permissions; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @since 4.1.0 |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function get_new_file_name() |
|
202 | - { |
|
203 | - return $this->_new_file_name; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - // upload methods |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Downloads the file using the WordPress HTTP API. |
|
212 | - * |
|
213 | - * @since 4.1.0 |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function sideload() |
|
217 | - { |
|
218 | - // setup temp dir |
|
219 | - $temp_file = wp_tempnam($this->_download_from); |
|
220 | - |
|
221 | - if (!$temp_file) { |
|
222 | - EE_Error::add_error( |
|
223 | - esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
224 | - __FILE__, |
|
225 | - __FUNCTION__, |
|
226 | - __LINE__ |
|
227 | - ); |
|
228 | - return false; |
|
229 | - } |
|
230 | - |
|
231 | - do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
232 | - |
|
233 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
234 | - |
|
235 | - $response = wp_safe_remote_get($this->_download_from, $wp_remote_args); |
|
236 | - |
|
237 | - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
238 | - unlink($temp_file); |
|
239 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
240 | - EE_Error::add_error( |
|
241 | - sprintf( |
|
242 | - esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
243 | - $this->_download_from |
|
244 | - ), |
|
245 | - __FILE__, |
|
246 | - __FUNCTION__, |
|
247 | - __LINE__ |
|
248 | - ); |
|
249 | - } |
|
250 | - return false; |
|
251 | - } |
|
252 | - |
|
253 | - // possible md5 check |
|
254 | - $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
255 | - if ($content_md5) { |
|
256 | - $md5_check = verify_file_md5($temp_file, $content_md5); |
|
257 | - if (is_wp_error($md5_check)) { |
|
258 | - unlink($temp_file); |
|
259 | - EE_Error::add_error( |
|
260 | - $md5_check->get_error_message(), |
|
261 | - __FILE__, |
|
262 | - __FUNCTION__, |
|
263 | - __LINE__ |
|
264 | - ); |
|
265 | - return false; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - $file = $temp_file; |
|
270 | - |
|
271 | - // now we have the file, let's get it in the right directory with the right name. |
|
272 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
273 | - |
|
274 | - // move file in |
|
275 | - if (false === @ rename($file, $path)) { |
|
276 | - unlink($temp_file); |
|
277 | - EE_Error::add_error( |
|
278 | - sprintf( |
|
279 | - esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
280 | - $path |
|
281 | - ), |
|
282 | - __FILE__, |
|
283 | - __FUNCTION__, |
|
284 | - __LINE__ |
|
285 | - ); |
|
286 | - return false; |
|
287 | - } |
|
288 | - |
|
289 | - // set permissions |
|
290 | - $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
291 | - chmod($path, $permissions); |
|
292 | - |
|
293 | - // that's it. let's allow for actions after file uploaded. |
|
294 | - do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | - |
|
296 | - // unlink tempfile |
|
297 | - @unlink($temp_file); |
|
298 | - return true; |
|
299 | - } |
|
300 | - |
|
301 | - // deprecated |
|
302 | - |
|
303 | - /** |
|
304 | - * sets the _upload_from property to the location we should download the file from. |
|
305 | - * |
|
306 | - * @param string $upload_from The full path to the file we should sideload. |
|
307 | - * @return void |
|
308 | - * @deprecated since version 4.10.5.p |
|
309 | - */ |
|
310 | - public function set_upload_from($upload_from) |
|
311 | - { |
|
312 | - EE_Error::doing_it_wrong( |
|
313 | - __CLASS__ . '::' . __FUNCTION__, |
|
314 | - __( |
|
315 | - 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from', |
|
316 | - 'event_espresso' |
|
317 | - ), |
|
318 | - '4.10.5.p' |
|
319 | - ); |
|
320 | - $this->set_download_from($upload_from); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @since 4.1.0 |
|
326 | - * @return string |
|
327 | - * @deprecated since version 4.10.5.p |
|
328 | - */ |
|
329 | - public function get_upload_from() |
|
330 | - { |
|
331 | - EE_Error::doing_it_wrong( |
|
332 | - __CLASS__ . '::' . __FUNCTION__, |
|
333 | - __( |
|
334 | - 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from', |
|
335 | - 'event_espresso' |
|
336 | - ), |
|
337 | - '4.10.5.p' |
|
338 | - ); |
|
339 | - return $this->_download_from; |
|
340 | - } |
|
17 | + /** |
|
18 | + * @since 4.1.0 |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private $_upload_to; |
|
22 | + |
|
23 | + /** |
|
24 | + * @since 4.10.5.p |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private $_download_from; |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 4.1.0 |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private $_permissions; |
|
34 | + |
|
35 | + /** |
|
36 | + * @since 4.1.0 |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $_new_file_name; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
44 | + * |
|
45 | + * @since 4.1.0 |
|
46 | + * @param array $init array fo initializing the sideloader if keys match the properties. |
|
47 | + */ |
|
48 | + public function __construct($init = array()) |
|
49 | + { |
|
50 | + $this->_init($init); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * sets the properties for class either to defaults or using incoming initialization array |
|
56 | + * |
|
57 | + * @since 4.1.0 |
|
58 | + * @param array $init array on init (keys match properties others ignored) |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + private function _init($init) |
|
62 | + { |
|
63 | + $defaults = array( |
|
64 | + '_upload_to' => $this->_get_wp_uploads_dir(), |
|
65 | + '_download_from' => '', |
|
66 | + '_permissions' => 0644, |
|
67 | + '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
68 | + ); |
|
69 | + |
|
70 | + $props = array_merge($defaults, $init); |
|
71 | + |
|
72 | + foreach ($props as $property => $val) { |
|
73 | + $setter = 'set' . $property; |
|
74 | + if (method_exists($this, $setter)) { |
|
75 | + $this->$setter($val); |
|
76 | + } else { |
|
77 | + // No setter found. |
|
78 | + EE_Error::add_error( |
|
79 | + sprintf( |
|
80 | + esc_html__( |
|
81 | + 'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $setter, |
|
85 | + $property |
|
86 | + ), |
|
87 | + __FILE__, |
|
88 | + __FUNCTION__, |
|
89 | + __LINE__ |
|
90 | + ); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + // make sure we include the required wp file for needed functions |
|
95 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + // utilities |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @since 4.1.0 |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + private function _get_wp_uploads_dir() |
|
107 | + { |
|
108 | + } |
|
109 | + |
|
110 | + // setters |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * sets the _upload_to property to the directory to upload to. |
|
115 | + * |
|
116 | + * @since 4.1.0 |
|
117 | + * @param $upload_to_folder |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function set_upload_to($upload_to_folder) |
|
121 | + { |
|
122 | + $this->_upload_to = $upload_to_folder; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * sets the _download_from property to the location we should download the file from. |
|
128 | + * |
|
129 | + * @since 4.10.5.p |
|
130 | + * @param string $download_from The full path to the file we should sideload. |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function set_download_from($download_from) |
|
134 | + { |
|
135 | + $this->_download_from = $download_from; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * sets the _permissions property used on the sideloaded file. |
|
141 | + * |
|
142 | + * @since 4.1.0 |
|
143 | + * @param int $permissions |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function set_permissions($permissions) |
|
147 | + { |
|
148 | + $this->_permissions = $permissions; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * sets the _new_file_name property used on the sideloaded file. |
|
154 | + * |
|
155 | + * @since 4.1.0 |
|
156 | + * @param string $new_file_name |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function set_new_file_name($new_file_name) |
|
160 | + { |
|
161 | + $this->_new_file_name = $new_file_name; |
|
162 | + } |
|
163 | + |
|
164 | + // getters |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @since 4.1.0 |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_upload_to() |
|
172 | + { |
|
173 | + return $this->_upload_to; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @since 4.10.5.p |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_download_from() |
|
182 | + { |
|
183 | + return $this->_download_from; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @since 4.1.0 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_permissions() |
|
192 | + { |
|
193 | + return $this->_permissions; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @since 4.1.0 |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function get_new_file_name() |
|
202 | + { |
|
203 | + return $this->_new_file_name; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + // upload methods |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Downloads the file using the WordPress HTTP API. |
|
212 | + * |
|
213 | + * @since 4.1.0 |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function sideload() |
|
217 | + { |
|
218 | + // setup temp dir |
|
219 | + $temp_file = wp_tempnam($this->_download_from); |
|
220 | + |
|
221 | + if (!$temp_file) { |
|
222 | + EE_Error::add_error( |
|
223 | + esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
224 | + __FILE__, |
|
225 | + __FUNCTION__, |
|
226 | + __LINE__ |
|
227 | + ); |
|
228 | + return false; |
|
229 | + } |
|
230 | + |
|
231 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
232 | + |
|
233 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
234 | + |
|
235 | + $response = wp_safe_remote_get($this->_download_from, $wp_remote_args); |
|
236 | + |
|
237 | + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
238 | + unlink($temp_file); |
|
239 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
240 | + EE_Error::add_error( |
|
241 | + sprintf( |
|
242 | + esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
243 | + $this->_download_from |
|
244 | + ), |
|
245 | + __FILE__, |
|
246 | + __FUNCTION__, |
|
247 | + __LINE__ |
|
248 | + ); |
|
249 | + } |
|
250 | + return false; |
|
251 | + } |
|
252 | + |
|
253 | + // possible md5 check |
|
254 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
255 | + if ($content_md5) { |
|
256 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
257 | + if (is_wp_error($md5_check)) { |
|
258 | + unlink($temp_file); |
|
259 | + EE_Error::add_error( |
|
260 | + $md5_check->get_error_message(), |
|
261 | + __FILE__, |
|
262 | + __FUNCTION__, |
|
263 | + __LINE__ |
|
264 | + ); |
|
265 | + return false; |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + $file = $temp_file; |
|
270 | + |
|
271 | + // now we have the file, let's get it in the right directory with the right name. |
|
272 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
273 | + |
|
274 | + // move file in |
|
275 | + if (false === @ rename($file, $path)) { |
|
276 | + unlink($temp_file); |
|
277 | + EE_Error::add_error( |
|
278 | + sprintf( |
|
279 | + esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
280 | + $path |
|
281 | + ), |
|
282 | + __FILE__, |
|
283 | + __FUNCTION__, |
|
284 | + __LINE__ |
|
285 | + ); |
|
286 | + return false; |
|
287 | + } |
|
288 | + |
|
289 | + // set permissions |
|
290 | + $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
291 | + chmod($path, $permissions); |
|
292 | + |
|
293 | + // that's it. let's allow for actions after file uploaded. |
|
294 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | + |
|
296 | + // unlink tempfile |
|
297 | + @unlink($temp_file); |
|
298 | + return true; |
|
299 | + } |
|
300 | + |
|
301 | + // deprecated |
|
302 | + |
|
303 | + /** |
|
304 | + * sets the _upload_from property to the location we should download the file from. |
|
305 | + * |
|
306 | + * @param string $upload_from The full path to the file we should sideload. |
|
307 | + * @return void |
|
308 | + * @deprecated since version 4.10.5.p |
|
309 | + */ |
|
310 | + public function set_upload_from($upload_from) |
|
311 | + { |
|
312 | + EE_Error::doing_it_wrong( |
|
313 | + __CLASS__ . '::' . __FUNCTION__, |
|
314 | + __( |
|
315 | + 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from', |
|
316 | + 'event_espresso' |
|
317 | + ), |
|
318 | + '4.10.5.p' |
|
319 | + ); |
|
320 | + $this->set_download_from($upload_from); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @since 4.1.0 |
|
326 | + * @return string |
|
327 | + * @deprecated since version 4.10.5.p |
|
328 | + */ |
|
329 | + public function get_upload_from() |
|
330 | + { |
|
331 | + EE_Error::doing_it_wrong( |
|
332 | + __CLASS__ . '::' . __FUNCTION__, |
|
333 | + __( |
|
334 | + 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from', |
|
335 | + 'event_espresso' |
|
336 | + ), |
|
337 | + '4.10.5.p' |
|
338 | + ); |
|
339 | + return $this->_download_from; |
|
340 | + } |
|
341 | 341 | } //end EEH_Sideloader class |
@@ -20,1409 +20,1409 @@ |
||
20 | 20 | class General_Settings_Admin_Page extends EE_Admin_Page |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * _question_group |
|
25 | - * holds the specific question group object for the question group details screen |
|
26 | - * |
|
27 | - * @var object |
|
28 | - */ |
|
29 | - protected $_question_group; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Initialize basic properties. |
|
34 | - */ |
|
35 | - protected function _init_page_props() |
|
36 | - { |
|
37 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
38 | - $this->page_label = GEN_SET_LABEL; |
|
39 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
40 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Set ajax hooks |
|
46 | - */ |
|
47 | - protected function _ajax_hooks() |
|
48 | - { |
|
49 | - add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
50 | - add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
51 | - add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
52 | - add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * More page properties initialization. |
|
58 | - */ |
|
59 | - protected function _define_page_props() |
|
60 | - { |
|
61 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
62 | - $this->_labels = array( |
|
63 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Set page routes property. |
|
70 | - */ |
|
71 | - protected function _set_page_routes() |
|
72 | - { |
|
73 | - $this->_page_routes = array( |
|
74 | - |
|
75 | - 'critical_pages' => array( |
|
76 | - 'func' => '_espresso_page_settings', |
|
77 | - 'capability' => 'manage_options', |
|
78 | - ), |
|
79 | - 'update_espresso_page_settings' => array( |
|
80 | - 'func' => '_update_espresso_page_settings', |
|
81 | - 'capability' => 'manage_options', |
|
82 | - 'noheader' => true, |
|
83 | - ), |
|
84 | - 'default' => array( |
|
85 | - 'func' => '_your_organization_settings', |
|
86 | - 'capability' => 'manage_options', |
|
87 | - ), |
|
88 | - |
|
89 | - 'update_your_organization_settings' => array( |
|
90 | - 'func' => '_update_your_organization_settings', |
|
91 | - 'capability' => 'manage_options', |
|
92 | - 'noheader' => true, |
|
93 | - ), |
|
94 | - |
|
95 | - 'admin_option_settings' => array( |
|
96 | - 'func' => '_admin_option_settings', |
|
97 | - 'capability' => 'manage_options', |
|
98 | - ), |
|
99 | - |
|
100 | - 'update_admin_option_settings' => array( |
|
101 | - 'func' => '_update_admin_option_settings', |
|
102 | - 'capability' => 'manage_options', |
|
103 | - 'noheader' => true, |
|
104 | - ), |
|
105 | - |
|
106 | - 'country_settings' => array( |
|
107 | - 'func' => '_country_settings', |
|
108 | - 'capability' => 'manage_options', |
|
109 | - ), |
|
110 | - |
|
111 | - 'update_country_settings' => array( |
|
112 | - 'func' => '_update_country_settings', |
|
113 | - 'capability' => 'manage_options', |
|
114 | - 'noheader' => true, |
|
115 | - ), |
|
116 | - |
|
117 | - 'display_country_settings' => array( |
|
118 | - 'func' => 'display_country_settings', |
|
119 | - 'capability' => 'manage_options', |
|
120 | - 'noheader' => true, |
|
121 | - ), |
|
122 | - |
|
123 | - 'add_new_state' => array( |
|
124 | - 'func' => 'add_new_state', |
|
125 | - 'capability' => 'manage_options', |
|
126 | - 'noheader' => true, |
|
127 | - ), |
|
128 | - |
|
129 | - 'delete_state' => array( |
|
130 | - 'func' => 'delete_state', |
|
131 | - 'capability' => 'manage_options', |
|
132 | - 'noheader' => true, |
|
133 | - ), |
|
134 | - 'privacy_settings' => array( |
|
135 | - 'func' => 'privacySettings', |
|
136 | - 'capability' => 'manage_options', |
|
137 | - ), |
|
138 | - 'update_privacy_settings' => array( |
|
139 | - 'func' => 'updatePrivacySettings', |
|
140 | - 'capability' => 'manage_options', |
|
141 | - 'noheader' => true, |
|
142 | - 'headers_sent_route' => 'privacy_settings', |
|
143 | - ), |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Set page configuration property |
|
150 | - */ |
|
151 | - protected function _set_page_config() |
|
152 | - { |
|
153 | - $this->_page_config = array( |
|
154 | - 'critical_pages' => array( |
|
155 | - 'nav' => array( |
|
156 | - 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
157 | - 'order' => 50, |
|
158 | - ), |
|
159 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
160 | - 'help_tabs' => array( |
|
161 | - 'general_settings_critical_pages_help_tab' => array( |
|
162 | - 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
163 | - 'filename' => 'general_settings_critical_pages', |
|
164 | - ), |
|
165 | - ), |
|
166 | - 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
167 | - 'require_nonce' => false, |
|
168 | - ), |
|
169 | - 'default' => array( |
|
170 | - 'nav' => array( |
|
171 | - 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
172 | - 'order' => 20, |
|
173 | - ), |
|
174 | - 'help_tabs' => array( |
|
175 | - 'general_settings_your_organization_help_tab' => array( |
|
176 | - 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
177 | - 'filename' => 'general_settings_your_organization', |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'help_tour' => array('Your_Organization_Help_Tour'), |
|
181 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
182 | - 'require_nonce' => false, |
|
183 | - ), |
|
184 | - 'admin_option_settings' => array( |
|
185 | - 'nav' => array( |
|
186 | - 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
187 | - 'order' => 60, |
|
188 | - ), |
|
189 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
190 | - 'help_tabs' => array( |
|
191 | - 'general_settings_admin_options_help_tab' => array( |
|
192 | - 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
193 | - 'filename' => 'general_settings_admin_options', |
|
194 | - ), |
|
195 | - ), |
|
196 | - 'help_tour' => array('Admin_Options_Help_Tour'), |
|
197 | - 'require_nonce' => false, |
|
198 | - ), |
|
199 | - 'country_settings' => array( |
|
200 | - 'nav' => array( |
|
201 | - 'label' => esc_html__('Countries', 'event_espresso'), |
|
202 | - 'order' => 70, |
|
203 | - ), |
|
204 | - 'help_tabs' => array( |
|
205 | - 'general_settings_countries_help_tab' => array( |
|
206 | - 'title' => esc_html__('Countries', 'event_espresso'), |
|
207 | - 'filename' => 'general_settings_countries', |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'help_tour' => array('Countries_Help_Tour'), |
|
211 | - 'require_nonce' => false, |
|
212 | - ), |
|
213 | - 'privacy_settings' => array( |
|
214 | - 'nav' => array( |
|
215 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
216 | - 'order' => 80, |
|
217 | - ), |
|
218 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
219 | - 'require_nonce' => false, |
|
220 | - ), |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - protected function _add_screen_options() |
|
226 | - { |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - protected function _add_feature_pointers() |
|
231 | - { |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
237 | - */ |
|
238 | - public function load_scripts_styles() |
|
239 | - { |
|
240 | - // styles |
|
241 | - wp_enqueue_style('espresso-ui-theme'); |
|
242 | - // scripts |
|
243 | - wp_enqueue_script('ee_admin_js'); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Execute logic running on `admin_init` |
|
249 | - */ |
|
250 | - public function admin_init() |
|
251 | - { |
|
252 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__( |
|
253 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
254 | - 'event_espresso' |
|
255 | - )); |
|
256 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__( |
|
257 | - 'An error occurred! Please refresh the page and try again.', |
|
258 | - 'event_espresso' |
|
259 | - )); |
|
260 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__( |
|
261 | - 'Are you sure you want to delete this State / Province?', |
|
262 | - 'event_espresso' |
|
263 | - )); |
|
264 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
265 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
266 | - 'admin-ajax.php?page=espresso_general_settings', |
|
267 | - $protocol |
|
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - public function admin_notices() |
|
273 | - { |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - public function admin_footer_scripts() |
|
278 | - { |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Enqueue scripts and styles for the default route. |
|
284 | - */ |
|
285 | - public function load_scripts_styles_default() |
|
286 | - { |
|
287 | - // styles |
|
288 | - wp_enqueue_style('thickbox'); |
|
289 | - // scripts |
|
290 | - wp_enqueue_script('media-upload'); |
|
291 | - wp_enqueue_script('thickbox'); |
|
292 | - wp_register_script( |
|
293 | - 'organization_settings', |
|
294 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
295 | - array('jquery', 'media-upload', 'thickbox'), |
|
296 | - EVENT_ESPRESSO_VERSION, |
|
297 | - true |
|
298 | - ); |
|
299 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
300 | - wp_enqueue_script('organization_settings'); |
|
301 | - wp_enqueue_style('organization-css'); |
|
302 | - $confirm_image_delete = array( |
|
303 | - 'text' => wp_strip_all_tags( |
|
304 | - __( |
|
305 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
306 | - 'event_espresso' |
|
307 | - ) |
|
308 | - ), |
|
309 | - ); |
|
310 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Enqueue scripts and styles for the country settings route. |
|
316 | - */ |
|
317 | - public function load_scripts_styles_country_settings() |
|
318 | - { |
|
319 | - // scripts |
|
320 | - wp_register_script( |
|
321 | - 'gen_settings_countries', |
|
322 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
323 | - array('ee_admin_js'), |
|
324 | - EVENT_ESPRESSO_VERSION, |
|
325 | - true |
|
326 | - ); |
|
327 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
328 | - wp_enqueue_script('gen_settings_countries'); |
|
329 | - wp_enqueue_style('organization-css'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /************* Espresso Pages *************/ |
|
334 | - /** |
|
335 | - * _espresso_page_settings |
|
336 | - * |
|
337 | - * @throws \EE_Error |
|
338 | - * @throws DomainException |
|
339 | - * @throws DomainException |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - * @throws InvalidArgumentException |
|
342 | - */ |
|
343 | - protected function _espresso_page_settings() |
|
344 | - { |
|
345 | - // Check to make sure all of the main pages are setup properly, |
|
346 | - // if not create the default pages and display an admin notice |
|
347 | - EEH_Activation::verify_default_pages_exist(); |
|
348 | - $this->_transient_garbage_collection(); |
|
349 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
350 | - $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
351 | - ? EE_Registry::instance()->CFG->core->reg_page_id |
|
352 | - : null; |
|
353 | - $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
354 | - ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
355 | - : false; |
|
356 | - $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
357 | - ? EE_Registry::instance()->CFG->core->txn_page_id |
|
358 | - : null; |
|
359 | - $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
360 | - ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
361 | - : false; |
|
362 | - $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
363 | - ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
364 | - : null; |
|
365 | - $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
366 | - ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
367 | - : false; |
|
368 | - $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
369 | - ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
370 | - : null; |
|
371 | - $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
372 | - ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
373 | - : false; |
|
374 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
375 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
376 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
377 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
378 | - $this->_template_args, |
|
379 | - true |
|
380 | - ); |
|
381 | - $this->display_admin_page_with_sidebar(); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Handler for updating espresso page settings. |
|
387 | - * |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - protected function _update_espresso_page_settings() |
|
391 | - { |
|
392 | - // capture incoming request data && set page IDs |
|
393 | - EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
394 | - ? absint($this->_req_data['reg_page_id']) |
|
395 | - : EE_Registry::instance()->CFG->core->reg_page_id; |
|
396 | - EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
397 | - ? absint($this->_req_data['txn_page_id']) |
|
398 | - : EE_Registry::instance()->CFG->core->txn_page_id; |
|
399 | - EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
400 | - ? absint($this->_req_data['thank_you_page_id']) |
|
401 | - : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
402 | - EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
403 | - ? absint($this->_req_data['cancel_page_id']) |
|
404 | - : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
405 | - |
|
406 | - EE_Registry::instance()->CFG->core = apply_filters( |
|
407 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
408 | - EE_Registry::instance()->CFG->core, |
|
409 | - $this->_req_data |
|
410 | - ); |
|
411 | - $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
412 | - $this->_redirect_after_action( |
|
413 | - $this->_update_espresso_configuration( |
|
414 | - $what, |
|
415 | - EE_Registry::instance()->CFG->core, |
|
416 | - __FILE__, |
|
417 | - __FUNCTION__, |
|
418 | - __LINE__ |
|
419 | - ), |
|
420 | - $what, |
|
421 | - '', |
|
422 | - array( |
|
423 | - 'action' => 'critical_pages', |
|
424 | - ), |
|
425 | - true |
|
426 | - ); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /************* Your Organization *************/ |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @throws DomainException |
|
435 | - * @throws EE_Error |
|
436 | - * @throws InvalidArgumentException |
|
437 | - * @throws InvalidDataTypeException |
|
438 | - * @throws InvalidInterfaceException |
|
439 | - */ |
|
440 | - protected function _your_organization_settings() |
|
441 | - { |
|
442 | - $this->_template_args['admin_page_content'] = ''; |
|
443 | - try { |
|
444 | - /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
445 | - $organization_settings_form = $this->loader->getShared( |
|
446 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
447 | - ); |
|
448 | - $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
449 | - } catch (Exception $e) { |
|
450 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
451 | - } |
|
452 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
453 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
454 | - $this->display_admin_page_with_sidebar(); |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * Handler for updating organization settings. |
|
460 | - * |
|
461 | - * @throws EE_Error |
|
462 | - */ |
|
463 | - protected function _update_your_organization_settings() |
|
464 | - { |
|
465 | - try { |
|
466 | - /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
467 | - $organization_settings_form = $this->loader->getShared( |
|
468 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
469 | - ); |
|
470 | - $success = $organization_settings_form->process($this->_req_data); |
|
471 | - EE_Registry::instance()->CFG = apply_filters( |
|
472 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
473 | - EE_Registry::instance()->CFG |
|
474 | - ); |
|
475 | - } catch (Exception $e) { |
|
476 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
477 | - $success = false; |
|
478 | - } |
|
479 | - |
|
480 | - if ($success) { |
|
481 | - $success = $this->_update_espresso_configuration( |
|
482 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
483 | - EE_Registry::instance()->CFG, |
|
484 | - __FILE__, |
|
485 | - __FUNCTION__, |
|
486 | - __LINE__ |
|
487 | - ); |
|
488 | - } |
|
489 | - |
|
490 | - $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /************* Admin Options *************/ |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * _admin_option_settings |
|
500 | - * |
|
501 | - * @throws \EE_Error |
|
502 | - * @throws \LogicException |
|
503 | - */ |
|
504 | - protected function _admin_option_settings() |
|
505 | - { |
|
506 | - $this->_template_args['admin_page_content'] = ''; |
|
507 | - try { |
|
508 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
509 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
510 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
511 | - // also need to account for the do_action that was in the old template |
|
512 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
513 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
514 | - } catch (Exception $e) { |
|
515 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
516 | - } |
|
517 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
518 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
519 | - $this->display_admin_page_with_sidebar(); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * _update_admin_option_settings |
|
525 | - * |
|
526 | - * @throws \EE_Error |
|
527 | - * @throws InvalidDataTypeException |
|
528 | - * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
529 | - * @throws \InvalidArgumentException |
|
530 | - * @throws \LogicException |
|
531 | - */ |
|
532 | - protected function _update_admin_option_settings() |
|
533 | - { |
|
534 | - try { |
|
535 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
536 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
537 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
538 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
539 | - EE_Registry::instance()->CFG->admin |
|
540 | - ); |
|
541 | - } catch (Exception $e) { |
|
542 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
543 | - } |
|
544 | - $this->_redirect_after_action( |
|
545 | - apply_filters( |
|
546 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
547 | - $this->_update_espresso_configuration( |
|
548 | - 'Admin Options', |
|
549 | - EE_Registry::instance()->CFG->admin, |
|
550 | - __FILE__, |
|
551 | - __FUNCTION__, |
|
552 | - __LINE__ |
|
553 | - ) |
|
554 | - ), |
|
555 | - 'Admin Options', |
|
556 | - 'updated', |
|
557 | - array('action' => 'admin_option_settings') |
|
558 | - ); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /************* Countries *************/ |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * @return string |
|
567 | - */ |
|
568 | - protected function getCountryIsoForSite() |
|
569 | - { |
|
570 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
571 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
572 | - : 'US'; |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * @param string $CNT_ISO |
|
578 | - * @param EE_Country|null $country |
|
579 | - * @return EE_Base_Class|EE_Country |
|
580 | - * @throws EE_Error |
|
581 | - * @throws InvalidArgumentException |
|
582 | - * @throws InvalidDataTypeException |
|
583 | - * @throws InvalidInterfaceException |
|
584 | - * @throws ReflectionException |
|
585 | - */ |
|
586 | - protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null) |
|
587 | - { |
|
588 | - /** @var EE_Country $country */ |
|
589 | - return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
590 | - ? $country |
|
591 | - : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * Output Country Settings view. |
|
597 | - * |
|
598 | - * @throws DomainException |
|
599 | - * @throws EE_Error |
|
600 | - * @throws InvalidArgumentException |
|
601 | - * @throws InvalidDataTypeException |
|
602 | - * @throws InvalidInterfaceException |
|
603 | - * @throws ReflectionException |
|
604 | - */ |
|
605 | - protected function _country_settings() |
|
606 | - { |
|
607 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
608 | - $CNT_ISO = isset($this->_req_data['country']) |
|
609 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
610 | - : $CNT_ISO_for_site; |
|
611 | - |
|
612 | - // load field generator helper |
|
613 | - |
|
614 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
615 | - |
|
616 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
617 | - EE_Question::new_instance( |
|
618 | - array( |
|
619 | - 'QST_ID' => 0, |
|
620 | - 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
621 | - 'QST_system' => 'admin-country', |
|
622 | - ) |
|
623 | - ), |
|
624 | - EE_Answer::new_instance( |
|
625 | - array( |
|
626 | - 'ANS_ID' => 0, |
|
627 | - 'ANS_value' => $CNT_ISO, |
|
628 | - ) |
|
629 | - ), |
|
630 | - array( |
|
631 | - 'input_id' => 'country', |
|
632 | - 'input_name' => 'country', |
|
633 | - 'input_prefix' => '', |
|
634 | - 'append_qstn_id' => false, |
|
635 | - ) |
|
636 | - ); |
|
637 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site); |
|
638 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
639 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
640 | - $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
641 | - $country->ID(), |
|
642 | - $country |
|
643 | - ); |
|
644 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
645 | - $country->ID(), |
|
646 | - $country |
|
647 | - ); |
|
648 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
649 | - |
|
650 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
651 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
652 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
653 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
654 | - $this->_template_args, |
|
655 | - true |
|
656 | - ); |
|
657 | - $this->display_admin_page_with_no_sidebar(); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * display_country_settings |
|
663 | - * |
|
664 | - * @param string $CNT_ISO |
|
665 | - * @param EE_Country|null $country |
|
666 | - * @return mixed string | array$country |
|
667 | - * @throws DomainException |
|
668 | - * @throws EE_Error |
|
669 | - * @throws InvalidArgumentException |
|
670 | - * @throws InvalidDataTypeException |
|
671 | - * @throws InvalidInterfaceException |
|
672 | - * @throws ReflectionException |
|
673 | - */ |
|
674 | - public function display_country_settings($CNT_ISO = '', EE_Country $country = null) |
|
675 | - { |
|
676 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
677 | - |
|
678 | - $CNT_ISO = isset($this->_req_data['country']) |
|
679 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
680 | - : $CNT_ISO; |
|
681 | - if (! $CNT_ISO) { |
|
682 | - return ''; |
|
683 | - } |
|
684 | - |
|
685 | - // for ajax |
|
686 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
687 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
688 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
689 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
690 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
691 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
692 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
693 | - |
|
694 | - $country_input_types = array( |
|
695 | - 'CNT_active' => array( |
|
696 | - 'type' => 'RADIO_BTN', |
|
697 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
698 | - 'class' => '', |
|
699 | - 'options' => $this->_yes_no_values, |
|
700 | - 'use_desc_4_label' => true, |
|
701 | - ), |
|
702 | - 'CNT_ISO' => array( |
|
703 | - 'type' => 'TEXT', |
|
704 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
705 | - 'class' => 'small-text', |
|
706 | - ), |
|
707 | - 'CNT_ISO3' => array( |
|
708 | - 'type' => 'TEXT', |
|
709 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
710 | - 'class' => 'small-text', |
|
711 | - ), |
|
712 | - 'RGN_ID' => array( |
|
713 | - 'type' => 'TEXT', |
|
714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
715 | - 'class' => 'small-text', |
|
716 | - ), |
|
717 | - 'CNT_name' => array( |
|
718 | - 'type' => 'TEXT', |
|
719 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
720 | - 'class' => 'regular-text', |
|
721 | - ), |
|
722 | - 'CNT_cur_code' => array( |
|
723 | - 'type' => 'TEXT', |
|
724 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
725 | - 'class' => 'small-text', |
|
726 | - 'disabled' => $CNT_cur_disabled, |
|
727 | - ), |
|
728 | - 'CNT_cur_single' => array( |
|
729 | - 'type' => 'TEXT', |
|
730 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
731 | - 'class' => 'medium-text', |
|
732 | - 'disabled' => $CNT_cur_disabled, |
|
733 | - ), |
|
734 | - 'CNT_cur_plural' => array( |
|
735 | - 'type' => 'TEXT', |
|
736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
737 | - 'class' => 'medium-text', |
|
738 | - 'disabled' => $CNT_cur_disabled, |
|
739 | - ), |
|
740 | - 'CNT_cur_sign' => array( |
|
741 | - 'type' => 'TEXT', |
|
742 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
743 | - 'class' => 'small-text', |
|
744 | - 'htmlentities' => false, |
|
745 | - 'disabled' => $CNT_cur_disabled, |
|
746 | - ), |
|
747 | - 'CNT_cur_sign_b4' => array( |
|
748 | - 'type' => 'RADIO_BTN', |
|
749 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
750 | - 'class' => '', |
|
751 | - 'options' => $this->_yes_no_values, |
|
752 | - 'use_desc_4_label' => true, |
|
753 | - 'disabled' => $CNT_cur_disabled, |
|
754 | - ), |
|
755 | - 'CNT_cur_dec_plc' => array( |
|
756 | - 'type' => 'RADIO_BTN', |
|
757 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
758 | - 'class' => '', |
|
759 | - 'options' => array( |
|
760 | - array('id' => 0, 'text' => ''), |
|
761 | - array('id' => 1, 'text' => ''), |
|
762 | - array('id' => 2, 'text' => ''), |
|
763 | - array('id' => 3, 'text' => ''), |
|
764 | - ), |
|
765 | - 'disabled' => $CNT_cur_disabled, |
|
766 | - ), |
|
767 | - 'CNT_cur_dec_mrk' => array( |
|
768 | - 'type' => 'RADIO_BTN', |
|
769 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
770 | - 'class' => '', |
|
771 | - 'options' => array( |
|
772 | - array( |
|
773 | - 'id' => ',', |
|
774 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
775 | - ), |
|
776 | - array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')), |
|
777 | - ), |
|
778 | - 'use_desc_4_label' => true, |
|
779 | - 'disabled' => $CNT_cur_disabled, |
|
780 | - ), |
|
781 | - 'CNT_cur_thsnds' => array( |
|
782 | - 'type' => 'RADIO_BTN', |
|
783 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
784 | - 'class' => '', |
|
785 | - 'options' => array( |
|
786 | - array( |
|
787 | - 'id' => ',', |
|
788 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
789 | - ), |
|
790 | - array( |
|
791 | - 'id' => '.', |
|
792 | - 'text' => esc_html__('. (decimal)', 'event_espresso') |
|
793 | - ), |
|
794 | - array( |
|
795 | - 'id' => ' ', |
|
796 | - 'text' => esc_html__('(space)', 'event_espresso') |
|
797 | - ) |
|
798 | - ), |
|
799 | - 'use_desc_4_label' => true, |
|
800 | - 'disabled' => $CNT_cur_disabled, |
|
801 | - ), |
|
802 | - 'CNT_tel_code' => array( |
|
803 | - 'type' => 'TEXT', |
|
804 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
805 | - 'class' => 'small-text', |
|
806 | - ), |
|
807 | - 'CNT_is_EU' => array( |
|
808 | - 'type' => 'RADIO_BTN', |
|
809 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
810 | - 'class' => '', |
|
811 | - 'options' => $this->_yes_no_values, |
|
812 | - 'use_desc_4_label' => true, |
|
813 | - ), |
|
814 | - ); |
|
815 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
816 | - $country, |
|
817 | - $country_input_types |
|
818 | - ); |
|
819 | - $country_details_settings = EEH_Template::display_template( |
|
820 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
821 | - $this->_template_args, |
|
822 | - true |
|
823 | - ); |
|
824 | - |
|
825 | - if (defined('DOING_AJAX')) { |
|
826 | - $notices = EE_Error::get_notices(false, false, false); |
|
827 | - echo wp_json_encode( |
|
828 | - array( |
|
829 | - 'return_data' => $country_details_settings, |
|
830 | - 'success' => $notices['success'], |
|
831 | - 'errors' => $notices['errors'], |
|
832 | - ) |
|
833 | - ); |
|
834 | - die(); |
|
835 | - } else { |
|
836 | - return $country_details_settings; |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * @param string $CNT_ISO |
|
843 | - * @param EE_Country|null $country |
|
844 | - * @return string |
|
845 | - * @throws DomainException |
|
846 | - * @throws EE_Error |
|
847 | - * @throws InvalidArgumentException |
|
848 | - * @throws InvalidDataTypeException |
|
849 | - * @throws InvalidInterfaceException |
|
850 | - * @throws ReflectionException |
|
851 | - */ |
|
852 | - public function display_country_states($CNT_ISO = '', EE_Country $country = null) |
|
853 | - { |
|
854 | - |
|
855 | - $CNT_ISO = isset($this->_req_data['country']) |
|
856 | - ? sanitize_text_field($this->_req_data['country']) |
|
857 | - : $CNT_ISO; |
|
858 | - if (! $CNT_ISO) { |
|
859 | - return ''; |
|
860 | - } |
|
861 | - // for ajax |
|
862 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
863 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
864 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
865 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
866 | - $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
867 | - if (empty($states)) { |
|
868 | - /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
869 | - $countrySubRegionDao = $this->loader->getShared( |
|
870 | - 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
871 | - ); |
|
872 | - if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
873 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
874 | - if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
875 | - $states = EEM_State::instance()->get_all_states_for_these_countries( |
|
876 | - array($CNT_ISO => $CNT_ISO) |
|
877 | - ); |
|
878 | - } |
|
879 | - } |
|
880 | - } |
|
881 | - if (is_array($states)) { |
|
882 | - foreach ($states as $STA_ID => $state) { |
|
883 | - if ($state instanceof EE_State) { |
|
884 | - // STA_abbrev STA_name STA_active |
|
885 | - $state_input_types = array( |
|
886 | - 'STA_abbrev' => array( |
|
887 | - 'type' => 'TEXT', |
|
888 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
889 | - 'class' => 'mid-text', |
|
890 | - ), |
|
891 | - 'STA_name' => array( |
|
892 | - 'type' => 'TEXT', |
|
893 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
894 | - 'class' => 'regular-text', |
|
895 | - ), |
|
896 | - 'STA_active' => array( |
|
897 | - 'type' => 'RADIO_BTN', |
|
898 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
899 | - 'options' => $this->_yes_no_values, |
|
900 | - 'use_desc_4_label' => true, |
|
901 | - ), |
|
902 | - ); |
|
903 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
904 | - EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
905 | - $state, |
|
906 | - $state_input_types |
|
907 | - ); |
|
908 | - $query_args = array( |
|
909 | - 'action' => 'delete_state', |
|
910 | - 'STA_ID' => $STA_ID, |
|
911 | - 'CNT_ISO' => $CNT_ISO, |
|
912 | - 'STA_abbrev' => $state->abbrev(), |
|
913 | - ); |
|
914 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
915 | - EE_Admin_Page::add_query_args_and_nonce( |
|
916 | - $query_args, |
|
917 | - GEN_SET_ADMIN_URL |
|
918 | - ); |
|
919 | - } |
|
920 | - } |
|
921 | - } else { |
|
922 | - $this->_template_args['states'] = false; |
|
923 | - } |
|
924 | - |
|
925 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
926 | - array('action' => 'add_new_state'), |
|
927 | - GEN_SET_ADMIN_URL |
|
928 | - ); |
|
929 | - |
|
930 | - $state_details_settings = EEH_Template::display_template( |
|
931 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
932 | - $this->_template_args, |
|
933 | - true |
|
934 | - ); |
|
935 | - |
|
936 | - if (defined('DOING_AJAX')) { |
|
937 | - $notices = EE_Error::get_notices(false, false, false); |
|
938 | - echo wp_json_encode( |
|
939 | - array( |
|
940 | - 'return_data' => $state_details_settings, |
|
941 | - 'success' => $notices['success'], |
|
942 | - 'errors' => $notices['errors'], |
|
943 | - ) |
|
944 | - ); |
|
945 | - die(); |
|
946 | - } else { |
|
947 | - return $state_details_settings; |
|
948 | - } |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * add_new_state |
|
954 | - * |
|
955 | - * @access public |
|
956 | - * @return void |
|
957 | - * @throws EE_Error |
|
958 | - * @throws InvalidArgumentException |
|
959 | - * @throws InvalidDataTypeException |
|
960 | - * @throws InvalidInterfaceException |
|
961 | - */ |
|
962 | - public function add_new_state() |
|
963 | - { |
|
964 | - |
|
965 | - $success = true; |
|
966 | - |
|
967 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
968 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
969 | - : false; |
|
970 | - if (! $CNT_ISO) { |
|
971 | - EE_Error::add_error( |
|
972 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
973 | - __FILE__, |
|
974 | - __FUNCTION__, |
|
975 | - __LINE__ |
|
976 | - ); |
|
977 | - $success = false; |
|
978 | - } |
|
979 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
980 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
981 | - : false; |
|
982 | - if (! $STA_abbrev) { |
|
983 | - EE_Error::add_error( |
|
984 | - esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
985 | - __FILE__, |
|
986 | - __FUNCTION__, |
|
987 | - __LINE__ |
|
988 | - ); |
|
989 | - $success = false; |
|
990 | - } |
|
991 | - $STA_name = isset($this->_req_data['STA_name']) |
|
992 | - ? sanitize_text_field($this->_req_data['STA_name']) |
|
993 | - : false; |
|
994 | - if (! $STA_name) { |
|
995 | - EE_Error::add_error( |
|
996 | - esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
997 | - __FILE__, |
|
998 | - __FUNCTION__, |
|
999 | - __LINE__ |
|
1000 | - ); |
|
1001 | - $success = false; |
|
1002 | - } |
|
1003 | - |
|
1004 | - if ($success) { |
|
1005 | - $cols_n_values = array( |
|
1006 | - 'CNT_ISO' => $CNT_ISO, |
|
1007 | - 'STA_abbrev' => $STA_abbrev, |
|
1008 | - 'STA_name' => $STA_name, |
|
1009 | - 'STA_active' => true, |
|
1010 | - ); |
|
1011 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
1012 | - EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1013 | - } |
|
1014 | - |
|
1015 | - if (defined('DOING_AJAX')) { |
|
1016 | - $notices = EE_Error::get_notices(false, false, false); |
|
1017 | - echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
1018 | - die(); |
|
1019 | - } else { |
|
1020 | - $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * delete_state |
|
1027 | - * |
|
1028 | - * @access public |
|
1029 | - * @return boolean |
|
1030 | - * @throws EE_Error |
|
1031 | - * @throws InvalidArgumentException |
|
1032 | - * @throws InvalidDataTypeException |
|
1033 | - * @throws InvalidInterfaceException |
|
1034 | - */ |
|
1035 | - public function delete_state() |
|
1036 | - { |
|
1037 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
1038 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
1039 | - : false; |
|
1040 | - $STA_ID = isset($this->_req_data['STA_ID']) |
|
1041 | - ? sanitize_text_field($this->_req_data['STA_ID']) |
|
1042 | - : false; |
|
1043 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
1044 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
1045 | - : false; |
|
1046 | - if (! $STA_ID) { |
|
1047 | - EE_Error::add_error( |
|
1048 | - esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1049 | - __FILE__, |
|
1050 | - __FUNCTION__, |
|
1051 | - __LINE__ |
|
1052 | - ); |
|
1053 | - return false; |
|
1054 | - } |
|
1055 | - |
|
1056 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1057 | - if ($success !== false) { |
|
1058 | - do_action( |
|
1059 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1060 | - $CNT_ISO, |
|
1061 | - $STA_ID, |
|
1062 | - array('STA_abbrev' => $STA_abbrev) |
|
1063 | - ); |
|
1064 | - EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1065 | - } |
|
1066 | - if (defined('DOING_AJAX')) { |
|
1067 | - $notices = EE_Error::get_notices(false, false); |
|
1068 | - $notices['return_data'] = true; |
|
1069 | - echo wp_json_encode($notices); |
|
1070 | - die(); |
|
1071 | - } else { |
|
1072 | - $this->_redirect_after_action( |
|
1073 | - $success, |
|
1074 | - 'State', |
|
1075 | - 'deleted', |
|
1076 | - array('action' => 'country_settings') |
|
1077 | - ); |
|
1078 | - } |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * _update_country_settings |
|
1084 | - * |
|
1085 | - * @access protected |
|
1086 | - * @return void |
|
1087 | - * @throws EE_Error |
|
1088 | - * @throws InvalidArgumentException |
|
1089 | - * @throws InvalidDataTypeException |
|
1090 | - * @throws InvalidInterfaceException |
|
1091 | - */ |
|
1092 | - protected function _update_country_settings() |
|
1093 | - { |
|
1094 | - // grab the country ISO code |
|
1095 | - $CNT_ISO = isset($this->_req_data['country']) |
|
1096 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
1097 | - : false; |
|
1098 | - if (! $CNT_ISO) { |
|
1099 | - EE_Error::add_error( |
|
1100 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1101 | - __FILE__, |
|
1102 | - __FUNCTION__, |
|
1103 | - __LINE__ |
|
1104 | - ); |
|
1105 | - |
|
1106 | - return; |
|
1107 | - } |
|
1108 | - $cols_n_values = array(); |
|
1109 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1110 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1111 | - : false; |
|
1112 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1113 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1114 | - : null; |
|
1115 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1116 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1117 | - : null; |
|
1118 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1119 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1120 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1121 | - ); |
|
1122 | - } |
|
1123 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1124 | - $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
1125 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1129 | - $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
1130 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1131 | - ); |
|
1132 | - } |
|
1133 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1134 | - $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
1135 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1139 | - $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
1140 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1141 | - ); |
|
1142 | - } |
|
1143 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1144 | - $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
1145 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1146 | - ); |
|
1147 | - } |
|
1148 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1149 | - $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
1150 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1151 | - ); |
|
1152 | - } |
|
1153 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1154 | - $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
1155 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1156 | - ); |
|
1157 | - } |
|
1158 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1159 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1160 | - : null; |
|
1161 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1162 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1163 | - : false; |
|
1164 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1165 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1166 | - : false; |
|
1167 | - // allow filtering of country data |
|
1168 | - $cols_n_values = apply_filters( |
|
1169 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1170 | - $cols_n_values |
|
1171 | - ); |
|
1172 | - |
|
1173 | - // where values |
|
1174 | - $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
1175 | - // run the update |
|
1176 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1177 | - |
|
1178 | - if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
1179 | - // allow filtering of states data |
|
1180 | - $states = apply_filters( |
|
1181 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1182 | - $this->_req_data['states'] |
|
1183 | - ); |
|
1184 | - |
|
1185 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
1186 | - foreach ($states as $STA_ID => $state) { |
|
1187 | - $cols_n_values = array( |
|
1188 | - 'CNT_ISO' => $CNT_ISO, |
|
1189 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1190 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1191 | - 'STA_active' => (bool) absint($state['STA_active']), |
|
1192 | - ); |
|
1193 | - // where values |
|
1194 | - $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
1195 | - // run the update |
|
1196 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1197 | - if ($success !== false) { |
|
1198 | - do_action( |
|
1199 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1200 | - $CNT_ISO, |
|
1201 | - $STA_ID, |
|
1202 | - $cols_n_values |
|
1203 | - ); |
|
1204 | - } |
|
1205 | - } |
|
1206 | - } |
|
1207 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1208 | - if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1209 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1210 | - ) { |
|
1211 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1212 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
1213 | - } |
|
1214 | - |
|
1215 | - if ($success !== false) { |
|
1216 | - EE_Error::add_success( |
|
1217 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1218 | - ); |
|
1219 | - } |
|
1220 | - $this->_redirect_after_action( |
|
1221 | - $success, |
|
1222 | - '', |
|
1223 | - '', |
|
1224 | - array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
1225 | - true |
|
1226 | - ); |
|
1227 | - } |
|
1228 | - |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * form_form_field_label_wrap |
|
1232 | - * |
|
1233 | - * @access public |
|
1234 | - * @param string $label |
|
1235 | - * @return string |
|
1236 | - */ |
|
1237 | - public function country_form_field_label_wrap($label, $required_text) |
|
1238 | - { |
|
1239 | - return ' |
|
23 | + /** |
|
24 | + * _question_group |
|
25 | + * holds the specific question group object for the question group details screen |
|
26 | + * |
|
27 | + * @var object |
|
28 | + */ |
|
29 | + protected $_question_group; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Initialize basic properties. |
|
34 | + */ |
|
35 | + protected function _init_page_props() |
|
36 | + { |
|
37 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
38 | + $this->page_label = GEN_SET_LABEL; |
|
39 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
40 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Set ajax hooks |
|
46 | + */ |
|
47 | + protected function _ajax_hooks() |
|
48 | + { |
|
49 | + add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
50 | + add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
51 | + add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
52 | + add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * More page properties initialization. |
|
58 | + */ |
|
59 | + protected function _define_page_props() |
|
60 | + { |
|
61 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
62 | + $this->_labels = array( |
|
63 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Set page routes property. |
|
70 | + */ |
|
71 | + protected function _set_page_routes() |
|
72 | + { |
|
73 | + $this->_page_routes = array( |
|
74 | + |
|
75 | + 'critical_pages' => array( |
|
76 | + 'func' => '_espresso_page_settings', |
|
77 | + 'capability' => 'manage_options', |
|
78 | + ), |
|
79 | + 'update_espresso_page_settings' => array( |
|
80 | + 'func' => '_update_espresso_page_settings', |
|
81 | + 'capability' => 'manage_options', |
|
82 | + 'noheader' => true, |
|
83 | + ), |
|
84 | + 'default' => array( |
|
85 | + 'func' => '_your_organization_settings', |
|
86 | + 'capability' => 'manage_options', |
|
87 | + ), |
|
88 | + |
|
89 | + 'update_your_organization_settings' => array( |
|
90 | + 'func' => '_update_your_organization_settings', |
|
91 | + 'capability' => 'manage_options', |
|
92 | + 'noheader' => true, |
|
93 | + ), |
|
94 | + |
|
95 | + 'admin_option_settings' => array( |
|
96 | + 'func' => '_admin_option_settings', |
|
97 | + 'capability' => 'manage_options', |
|
98 | + ), |
|
99 | + |
|
100 | + 'update_admin_option_settings' => array( |
|
101 | + 'func' => '_update_admin_option_settings', |
|
102 | + 'capability' => 'manage_options', |
|
103 | + 'noheader' => true, |
|
104 | + ), |
|
105 | + |
|
106 | + 'country_settings' => array( |
|
107 | + 'func' => '_country_settings', |
|
108 | + 'capability' => 'manage_options', |
|
109 | + ), |
|
110 | + |
|
111 | + 'update_country_settings' => array( |
|
112 | + 'func' => '_update_country_settings', |
|
113 | + 'capability' => 'manage_options', |
|
114 | + 'noheader' => true, |
|
115 | + ), |
|
116 | + |
|
117 | + 'display_country_settings' => array( |
|
118 | + 'func' => 'display_country_settings', |
|
119 | + 'capability' => 'manage_options', |
|
120 | + 'noheader' => true, |
|
121 | + ), |
|
122 | + |
|
123 | + 'add_new_state' => array( |
|
124 | + 'func' => 'add_new_state', |
|
125 | + 'capability' => 'manage_options', |
|
126 | + 'noheader' => true, |
|
127 | + ), |
|
128 | + |
|
129 | + 'delete_state' => array( |
|
130 | + 'func' => 'delete_state', |
|
131 | + 'capability' => 'manage_options', |
|
132 | + 'noheader' => true, |
|
133 | + ), |
|
134 | + 'privacy_settings' => array( |
|
135 | + 'func' => 'privacySettings', |
|
136 | + 'capability' => 'manage_options', |
|
137 | + ), |
|
138 | + 'update_privacy_settings' => array( |
|
139 | + 'func' => 'updatePrivacySettings', |
|
140 | + 'capability' => 'manage_options', |
|
141 | + 'noheader' => true, |
|
142 | + 'headers_sent_route' => 'privacy_settings', |
|
143 | + ), |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Set page configuration property |
|
150 | + */ |
|
151 | + protected function _set_page_config() |
|
152 | + { |
|
153 | + $this->_page_config = array( |
|
154 | + 'critical_pages' => array( |
|
155 | + 'nav' => array( |
|
156 | + 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
157 | + 'order' => 50, |
|
158 | + ), |
|
159 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
160 | + 'help_tabs' => array( |
|
161 | + 'general_settings_critical_pages_help_tab' => array( |
|
162 | + 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
163 | + 'filename' => 'general_settings_critical_pages', |
|
164 | + ), |
|
165 | + ), |
|
166 | + 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
167 | + 'require_nonce' => false, |
|
168 | + ), |
|
169 | + 'default' => array( |
|
170 | + 'nav' => array( |
|
171 | + 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
172 | + 'order' => 20, |
|
173 | + ), |
|
174 | + 'help_tabs' => array( |
|
175 | + 'general_settings_your_organization_help_tab' => array( |
|
176 | + 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
177 | + 'filename' => 'general_settings_your_organization', |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'help_tour' => array('Your_Organization_Help_Tour'), |
|
181 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
182 | + 'require_nonce' => false, |
|
183 | + ), |
|
184 | + 'admin_option_settings' => array( |
|
185 | + 'nav' => array( |
|
186 | + 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
187 | + 'order' => 60, |
|
188 | + ), |
|
189 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
190 | + 'help_tabs' => array( |
|
191 | + 'general_settings_admin_options_help_tab' => array( |
|
192 | + 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
193 | + 'filename' => 'general_settings_admin_options', |
|
194 | + ), |
|
195 | + ), |
|
196 | + 'help_tour' => array('Admin_Options_Help_Tour'), |
|
197 | + 'require_nonce' => false, |
|
198 | + ), |
|
199 | + 'country_settings' => array( |
|
200 | + 'nav' => array( |
|
201 | + 'label' => esc_html__('Countries', 'event_espresso'), |
|
202 | + 'order' => 70, |
|
203 | + ), |
|
204 | + 'help_tabs' => array( |
|
205 | + 'general_settings_countries_help_tab' => array( |
|
206 | + 'title' => esc_html__('Countries', 'event_espresso'), |
|
207 | + 'filename' => 'general_settings_countries', |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'help_tour' => array('Countries_Help_Tour'), |
|
211 | + 'require_nonce' => false, |
|
212 | + ), |
|
213 | + 'privacy_settings' => array( |
|
214 | + 'nav' => array( |
|
215 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
216 | + 'order' => 80, |
|
217 | + ), |
|
218 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
219 | + 'require_nonce' => false, |
|
220 | + ), |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + protected function _add_screen_options() |
|
226 | + { |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + protected function _add_feature_pointers() |
|
231 | + { |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
237 | + */ |
|
238 | + public function load_scripts_styles() |
|
239 | + { |
|
240 | + // styles |
|
241 | + wp_enqueue_style('espresso-ui-theme'); |
|
242 | + // scripts |
|
243 | + wp_enqueue_script('ee_admin_js'); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Execute logic running on `admin_init` |
|
249 | + */ |
|
250 | + public function admin_init() |
|
251 | + { |
|
252 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__( |
|
253 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
254 | + 'event_espresso' |
|
255 | + )); |
|
256 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__( |
|
257 | + 'An error occurred! Please refresh the page and try again.', |
|
258 | + 'event_espresso' |
|
259 | + )); |
|
260 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__( |
|
261 | + 'Are you sure you want to delete this State / Province?', |
|
262 | + 'event_espresso' |
|
263 | + )); |
|
264 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
265 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
266 | + 'admin-ajax.php?page=espresso_general_settings', |
|
267 | + $protocol |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + public function admin_notices() |
|
273 | + { |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + public function admin_footer_scripts() |
|
278 | + { |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Enqueue scripts and styles for the default route. |
|
284 | + */ |
|
285 | + public function load_scripts_styles_default() |
|
286 | + { |
|
287 | + // styles |
|
288 | + wp_enqueue_style('thickbox'); |
|
289 | + // scripts |
|
290 | + wp_enqueue_script('media-upload'); |
|
291 | + wp_enqueue_script('thickbox'); |
|
292 | + wp_register_script( |
|
293 | + 'organization_settings', |
|
294 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
295 | + array('jquery', 'media-upload', 'thickbox'), |
|
296 | + EVENT_ESPRESSO_VERSION, |
|
297 | + true |
|
298 | + ); |
|
299 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
300 | + wp_enqueue_script('organization_settings'); |
|
301 | + wp_enqueue_style('organization-css'); |
|
302 | + $confirm_image_delete = array( |
|
303 | + 'text' => wp_strip_all_tags( |
|
304 | + __( |
|
305 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
306 | + 'event_espresso' |
|
307 | + ) |
|
308 | + ), |
|
309 | + ); |
|
310 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Enqueue scripts and styles for the country settings route. |
|
316 | + */ |
|
317 | + public function load_scripts_styles_country_settings() |
|
318 | + { |
|
319 | + // scripts |
|
320 | + wp_register_script( |
|
321 | + 'gen_settings_countries', |
|
322 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
323 | + array('ee_admin_js'), |
|
324 | + EVENT_ESPRESSO_VERSION, |
|
325 | + true |
|
326 | + ); |
|
327 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
328 | + wp_enqueue_script('gen_settings_countries'); |
|
329 | + wp_enqueue_style('organization-css'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /************* Espresso Pages *************/ |
|
334 | + /** |
|
335 | + * _espresso_page_settings |
|
336 | + * |
|
337 | + * @throws \EE_Error |
|
338 | + * @throws DomainException |
|
339 | + * @throws DomainException |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + * @throws InvalidArgumentException |
|
342 | + */ |
|
343 | + protected function _espresso_page_settings() |
|
344 | + { |
|
345 | + // Check to make sure all of the main pages are setup properly, |
|
346 | + // if not create the default pages and display an admin notice |
|
347 | + EEH_Activation::verify_default_pages_exist(); |
|
348 | + $this->_transient_garbage_collection(); |
|
349 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
350 | + $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
351 | + ? EE_Registry::instance()->CFG->core->reg_page_id |
|
352 | + : null; |
|
353 | + $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
354 | + ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
355 | + : false; |
|
356 | + $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
357 | + ? EE_Registry::instance()->CFG->core->txn_page_id |
|
358 | + : null; |
|
359 | + $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
360 | + ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
361 | + : false; |
|
362 | + $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
363 | + ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
364 | + : null; |
|
365 | + $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
366 | + ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
367 | + : false; |
|
368 | + $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
369 | + ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
370 | + : null; |
|
371 | + $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
372 | + ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
373 | + : false; |
|
374 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
375 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
376 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
377 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
378 | + $this->_template_args, |
|
379 | + true |
|
380 | + ); |
|
381 | + $this->display_admin_page_with_sidebar(); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Handler for updating espresso page settings. |
|
387 | + * |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + protected function _update_espresso_page_settings() |
|
391 | + { |
|
392 | + // capture incoming request data && set page IDs |
|
393 | + EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
394 | + ? absint($this->_req_data['reg_page_id']) |
|
395 | + : EE_Registry::instance()->CFG->core->reg_page_id; |
|
396 | + EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
397 | + ? absint($this->_req_data['txn_page_id']) |
|
398 | + : EE_Registry::instance()->CFG->core->txn_page_id; |
|
399 | + EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
400 | + ? absint($this->_req_data['thank_you_page_id']) |
|
401 | + : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
402 | + EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
403 | + ? absint($this->_req_data['cancel_page_id']) |
|
404 | + : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
405 | + |
|
406 | + EE_Registry::instance()->CFG->core = apply_filters( |
|
407 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
408 | + EE_Registry::instance()->CFG->core, |
|
409 | + $this->_req_data |
|
410 | + ); |
|
411 | + $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
412 | + $this->_redirect_after_action( |
|
413 | + $this->_update_espresso_configuration( |
|
414 | + $what, |
|
415 | + EE_Registry::instance()->CFG->core, |
|
416 | + __FILE__, |
|
417 | + __FUNCTION__, |
|
418 | + __LINE__ |
|
419 | + ), |
|
420 | + $what, |
|
421 | + '', |
|
422 | + array( |
|
423 | + 'action' => 'critical_pages', |
|
424 | + ), |
|
425 | + true |
|
426 | + ); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /************* Your Organization *************/ |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @throws DomainException |
|
435 | + * @throws EE_Error |
|
436 | + * @throws InvalidArgumentException |
|
437 | + * @throws InvalidDataTypeException |
|
438 | + * @throws InvalidInterfaceException |
|
439 | + */ |
|
440 | + protected function _your_organization_settings() |
|
441 | + { |
|
442 | + $this->_template_args['admin_page_content'] = ''; |
|
443 | + try { |
|
444 | + /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
445 | + $organization_settings_form = $this->loader->getShared( |
|
446 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
447 | + ); |
|
448 | + $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
449 | + } catch (Exception $e) { |
|
450 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
451 | + } |
|
452 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
453 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
454 | + $this->display_admin_page_with_sidebar(); |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * Handler for updating organization settings. |
|
460 | + * |
|
461 | + * @throws EE_Error |
|
462 | + */ |
|
463 | + protected function _update_your_organization_settings() |
|
464 | + { |
|
465 | + try { |
|
466 | + /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */ |
|
467 | + $organization_settings_form = $this->loader->getShared( |
|
468 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' |
|
469 | + ); |
|
470 | + $success = $organization_settings_form->process($this->_req_data); |
|
471 | + EE_Registry::instance()->CFG = apply_filters( |
|
472 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
473 | + EE_Registry::instance()->CFG |
|
474 | + ); |
|
475 | + } catch (Exception $e) { |
|
476 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
477 | + $success = false; |
|
478 | + } |
|
479 | + |
|
480 | + if ($success) { |
|
481 | + $success = $this->_update_espresso_configuration( |
|
482 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
483 | + EE_Registry::instance()->CFG, |
|
484 | + __FILE__, |
|
485 | + __FUNCTION__, |
|
486 | + __LINE__ |
|
487 | + ); |
|
488 | + } |
|
489 | + |
|
490 | + $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /************* Admin Options *************/ |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * _admin_option_settings |
|
500 | + * |
|
501 | + * @throws \EE_Error |
|
502 | + * @throws \LogicException |
|
503 | + */ |
|
504 | + protected function _admin_option_settings() |
|
505 | + { |
|
506 | + $this->_template_args['admin_page_content'] = ''; |
|
507 | + try { |
|
508 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
509 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
510 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
511 | + // also need to account for the do_action that was in the old template |
|
512 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
513 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
514 | + } catch (Exception $e) { |
|
515 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
516 | + } |
|
517 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
518 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
519 | + $this->display_admin_page_with_sidebar(); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * _update_admin_option_settings |
|
525 | + * |
|
526 | + * @throws \EE_Error |
|
527 | + * @throws InvalidDataTypeException |
|
528 | + * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
529 | + * @throws \InvalidArgumentException |
|
530 | + * @throws \LogicException |
|
531 | + */ |
|
532 | + protected function _update_admin_option_settings() |
|
533 | + { |
|
534 | + try { |
|
535 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
536 | + $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
537 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
538 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
539 | + EE_Registry::instance()->CFG->admin |
|
540 | + ); |
|
541 | + } catch (Exception $e) { |
|
542 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
543 | + } |
|
544 | + $this->_redirect_after_action( |
|
545 | + apply_filters( |
|
546 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
547 | + $this->_update_espresso_configuration( |
|
548 | + 'Admin Options', |
|
549 | + EE_Registry::instance()->CFG->admin, |
|
550 | + __FILE__, |
|
551 | + __FUNCTION__, |
|
552 | + __LINE__ |
|
553 | + ) |
|
554 | + ), |
|
555 | + 'Admin Options', |
|
556 | + 'updated', |
|
557 | + array('action' => 'admin_option_settings') |
|
558 | + ); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /************* Countries *************/ |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * @return string |
|
567 | + */ |
|
568 | + protected function getCountryIsoForSite() |
|
569 | + { |
|
570 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
571 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
572 | + : 'US'; |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * @param string $CNT_ISO |
|
578 | + * @param EE_Country|null $country |
|
579 | + * @return EE_Base_Class|EE_Country |
|
580 | + * @throws EE_Error |
|
581 | + * @throws InvalidArgumentException |
|
582 | + * @throws InvalidDataTypeException |
|
583 | + * @throws InvalidInterfaceException |
|
584 | + * @throws ReflectionException |
|
585 | + */ |
|
586 | + protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null) |
|
587 | + { |
|
588 | + /** @var EE_Country $country */ |
|
589 | + return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
590 | + ? $country |
|
591 | + : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * Output Country Settings view. |
|
597 | + * |
|
598 | + * @throws DomainException |
|
599 | + * @throws EE_Error |
|
600 | + * @throws InvalidArgumentException |
|
601 | + * @throws InvalidDataTypeException |
|
602 | + * @throws InvalidInterfaceException |
|
603 | + * @throws ReflectionException |
|
604 | + */ |
|
605 | + protected function _country_settings() |
|
606 | + { |
|
607 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
608 | + $CNT_ISO = isset($this->_req_data['country']) |
|
609 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
610 | + : $CNT_ISO_for_site; |
|
611 | + |
|
612 | + // load field generator helper |
|
613 | + |
|
614 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
615 | + |
|
616 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
617 | + EE_Question::new_instance( |
|
618 | + array( |
|
619 | + 'QST_ID' => 0, |
|
620 | + 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
621 | + 'QST_system' => 'admin-country', |
|
622 | + ) |
|
623 | + ), |
|
624 | + EE_Answer::new_instance( |
|
625 | + array( |
|
626 | + 'ANS_ID' => 0, |
|
627 | + 'ANS_value' => $CNT_ISO, |
|
628 | + ) |
|
629 | + ), |
|
630 | + array( |
|
631 | + 'input_id' => 'country', |
|
632 | + 'input_name' => 'country', |
|
633 | + 'input_prefix' => '', |
|
634 | + 'append_qstn_id' => false, |
|
635 | + ) |
|
636 | + ); |
|
637 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site); |
|
638 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
639 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
640 | + $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
641 | + $country->ID(), |
|
642 | + $country |
|
643 | + ); |
|
644 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
645 | + $country->ID(), |
|
646 | + $country |
|
647 | + ); |
|
648 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
649 | + |
|
650 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
651 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
652 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
653 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
654 | + $this->_template_args, |
|
655 | + true |
|
656 | + ); |
|
657 | + $this->display_admin_page_with_no_sidebar(); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * display_country_settings |
|
663 | + * |
|
664 | + * @param string $CNT_ISO |
|
665 | + * @param EE_Country|null $country |
|
666 | + * @return mixed string | array$country |
|
667 | + * @throws DomainException |
|
668 | + * @throws EE_Error |
|
669 | + * @throws InvalidArgumentException |
|
670 | + * @throws InvalidDataTypeException |
|
671 | + * @throws InvalidInterfaceException |
|
672 | + * @throws ReflectionException |
|
673 | + */ |
|
674 | + public function display_country_settings($CNT_ISO = '', EE_Country $country = null) |
|
675 | + { |
|
676 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
677 | + |
|
678 | + $CNT_ISO = isset($this->_req_data['country']) |
|
679 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
680 | + : $CNT_ISO; |
|
681 | + if (! $CNT_ISO) { |
|
682 | + return ''; |
|
683 | + } |
|
684 | + |
|
685 | + // for ajax |
|
686 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
687 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
688 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
689 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
690 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
691 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
692 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
693 | + |
|
694 | + $country_input_types = array( |
|
695 | + 'CNT_active' => array( |
|
696 | + 'type' => 'RADIO_BTN', |
|
697 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
698 | + 'class' => '', |
|
699 | + 'options' => $this->_yes_no_values, |
|
700 | + 'use_desc_4_label' => true, |
|
701 | + ), |
|
702 | + 'CNT_ISO' => array( |
|
703 | + 'type' => 'TEXT', |
|
704 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
705 | + 'class' => 'small-text', |
|
706 | + ), |
|
707 | + 'CNT_ISO3' => array( |
|
708 | + 'type' => 'TEXT', |
|
709 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
710 | + 'class' => 'small-text', |
|
711 | + ), |
|
712 | + 'RGN_ID' => array( |
|
713 | + 'type' => 'TEXT', |
|
714 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
715 | + 'class' => 'small-text', |
|
716 | + ), |
|
717 | + 'CNT_name' => array( |
|
718 | + 'type' => 'TEXT', |
|
719 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
720 | + 'class' => 'regular-text', |
|
721 | + ), |
|
722 | + 'CNT_cur_code' => array( |
|
723 | + 'type' => 'TEXT', |
|
724 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
725 | + 'class' => 'small-text', |
|
726 | + 'disabled' => $CNT_cur_disabled, |
|
727 | + ), |
|
728 | + 'CNT_cur_single' => array( |
|
729 | + 'type' => 'TEXT', |
|
730 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
731 | + 'class' => 'medium-text', |
|
732 | + 'disabled' => $CNT_cur_disabled, |
|
733 | + ), |
|
734 | + 'CNT_cur_plural' => array( |
|
735 | + 'type' => 'TEXT', |
|
736 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
737 | + 'class' => 'medium-text', |
|
738 | + 'disabled' => $CNT_cur_disabled, |
|
739 | + ), |
|
740 | + 'CNT_cur_sign' => array( |
|
741 | + 'type' => 'TEXT', |
|
742 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
743 | + 'class' => 'small-text', |
|
744 | + 'htmlentities' => false, |
|
745 | + 'disabled' => $CNT_cur_disabled, |
|
746 | + ), |
|
747 | + 'CNT_cur_sign_b4' => array( |
|
748 | + 'type' => 'RADIO_BTN', |
|
749 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
750 | + 'class' => '', |
|
751 | + 'options' => $this->_yes_no_values, |
|
752 | + 'use_desc_4_label' => true, |
|
753 | + 'disabled' => $CNT_cur_disabled, |
|
754 | + ), |
|
755 | + 'CNT_cur_dec_plc' => array( |
|
756 | + 'type' => 'RADIO_BTN', |
|
757 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
758 | + 'class' => '', |
|
759 | + 'options' => array( |
|
760 | + array('id' => 0, 'text' => ''), |
|
761 | + array('id' => 1, 'text' => ''), |
|
762 | + array('id' => 2, 'text' => ''), |
|
763 | + array('id' => 3, 'text' => ''), |
|
764 | + ), |
|
765 | + 'disabled' => $CNT_cur_disabled, |
|
766 | + ), |
|
767 | + 'CNT_cur_dec_mrk' => array( |
|
768 | + 'type' => 'RADIO_BTN', |
|
769 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
770 | + 'class' => '', |
|
771 | + 'options' => array( |
|
772 | + array( |
|
773 | + 'id' => ',', |
|
774 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
775 | + ), |
|
776 | + array('id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')), |
|
777 | + ), |
|
778 | + 'use_desc_4_label' => true, |
|
779 | + 'disabled' => $CNT_cur_disabled, |
|
780 | + ), |
|
781 | + 'CNT_cur_thsnds' => array( |
|
782 | + 'type' => 'RADIO_BTN', |
|
783 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
784 | + 'class' => '', |
|
785 | + 'options' => array( |
|
786 | + array( |
|
787 | + 'id' => ',', |
|
788 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
789 | + ), |
|
790 | + array( |
|
791 | + 'id' => '.', |
|
792 | + 'text' => esc_html__('. (decimal)', 'event_espresso') |
|
793 | + ), |
|
794 | + array( |
|
795 | + 'id' => ' ', |
|
796 | + 'text' => esc_html__('(space)', 'event_espresso') |
|
797 | + ) |
|
798 | + ), |
|
799 | + 'use_desc_4_label' => true, |
|
800 | + 'disabled' => $CNT_cur_disabled, |
|
801 | + ), |
|
802 | + 'CNT_tel_code' => array( |
|
803 | + 'type' => 'TEXT', |
|
804 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
805 | + 'class' => 'small-text', |
|
806 | + ), |
|
807 | + 'CNT_is_EU' => array( |
|
808 | + 'type' => 'RADIO_BTN', |
|
809 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
810 | + 'class' => '', |
|
811 | + 'options' => $this->_yes_no_values, |
|
812 | + 'use_desc_4_label' => true, |
|
813 | + ), |
|
814 | + ); |
|
815 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
816 | + $country, |
|
817 | + $country_input_types |
|
818 | + ); |
|
819 | + $country_details_settings = EEH_Template::display_template( |
|
820 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
821 | + $this->_template_args, |
|
822 | + true |
|
823 | + ); |
|
824 | + |
|
825 | + if (defined('DOING_AJAX')) { |
|
826 | + $notices = EE_Error::get_notices(false, false, false); |
|
827 | + echo wp_json_encode( |
|
828 | + array( |
|
829 | + 'return_data' => $country_details_settings, |
|
830 | + 'success' => $notices['success'], |
|
831 | + 'errors' => $notices['errors'], |
|
832 | + ) |
|
833 | + ); |
|
834 | + die(); |
|
835 | + } else { |
|
836 | + return $country_details_settings; |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * @param string $CNT_ISO |
|
843 | + * @param EE_Country|null $country |
|
844 | + * @return string |
|
845 | + * @throws DomainException |
|
846 | + * @throws EE_Error |
|
847 | + * @throws InvalidArgumentException |
|
848 | + * @throws InvalidDataTypeException |
|
849 | + * @throws InvalidInterfaceException |
|
850 | + * @throws ReflectionException |
|
851 | + */ |
|
852 | + public function display_country_states($CNT_ISO = '', EE_Country $country = null) |
|
853 | + { |
|
854 | + |
|
855 | + $CNT_ISO = isset($this->_req_data['country']) |
|
856 | + ? sanitize_text_field($this->_req_data['country']) |
|
857 | + : $CNT_ISO; |
|
858 | + if (! $CNT_ISO) { |
|
859 | + return ''; |
|
860 | + } |
|
861 | + // for ajax |
|
862 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
863 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
864 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
865 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
866 | + $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
867 | + if (empty($states)) { |
|
868 | + /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
869 | + $countrySubRegionDao = $this->loader->getShared( |
|
870 | + 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
871 | + ); |
|
872 | + if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
873 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
874 | + if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
875 | + $states = EEM_State::instance()->get_all_states_for_these_countries( |
|
876 | + array($CNT_ISO => $CNT_ISO) |
|
877 | + ); |
|
878 | + } |
|
879 | + } |
|
880 | + } |
|
881 | + if (is_array($states)) { |
|
882 | + foreach ($states as $STA_ID => $state) { |
|
883 | + if ($state instanceof EE_State) { |
|
884 | + // STA_abbrev STA_name STA_active |
|
885 | + $state_input_types = array( |
|
886 | + 'STA_abbrev' => array( |
|
887 | + 'type' => 'TEXT', |
|
888 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
889 | + 'class' => 'mid-text', |
|
890 | + ), |
|
891 | + 'STA_name' => array( |
|
892 | + 'type' => 'TEXT', |
|
893 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
894 | + 'class' => 'regular-text', |
|
895 | + ), |
|
896 | + 'STA_active' => array( |
|
897 | + 'type' => 'RADIO_BTN', |
|
898 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
899 | + 'options' => $this->_yes_no_values, |
|
900 | + 'use_desc_4_label' => true, |
|
901 | + ), |
|
902 | + ); |
|
903 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
904 | + EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
905 | + $state, |
|
906 | + $state_input_types |
|
907 | + ); |
|
908 | + $query_args = array( |
|
909 | + 'action' => 'delete_state', |
|
910 | + 'STA_ID' => $STA_ID, |
|
911 | + 'CNT_ISO' => $CNT_ISO, |
|
912 | + 'STA_abbrev' => $state->abbrev(), |
|
913 | + ); |
|
914 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
915 | + EE_Admin_Page::add_query_args_and_nonce( |
|
916 | + $query_args, |
|
917 | + GEN_SET_ADMIN_URL |
|
918 | + ); |
|
919 | + } |
|
920 | + } |
|
921 | + } else { |
|
922 | + $this->_template_args['states'] = false; |
|
923 | + } |
|
924 | + |
|
925 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
926 | + array('action' => 'add_new_state'), |
|
927 | + GEN_SET_ADMIN_URL |
|
928 | + ); |
|
929 | + |
|
930 | + $state_details_settings = EEH_Template::display_template( |
|
931 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
932 | + $this->_template_args, |
|
933 | + true |
|
934 | + ); |
|
935 | + |
|
936 | + if (defined('DOING_AJAX')) { |
|
937 | + $notices = EE_Error::get_notices(false, false, false); |
|
938 | + echo wp_json_encode( |
|
939 | + array( |
|
940 | + 'return_data' => $state_details_settings, |
|
941 | + 'success' => $notices['success'], |
|
942 | + 'errors' => $notices['errors'], |
|
943 | + ) |
|
944 | + ); |
|
945 | + die(); |
|
946 | + } else { |
|
947 | + return $state_details_settings; |
|
948 | + } |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * add_new_state |
|
954 | + * |
|
955 | + * @access public |
|
956 | + * @return void |
|
957 | + * @throws EE_Error |
|
958 | + * @throws InvalidArgumentException |
|
959 | + * @throws InvalidDataTypeException |
|
960 | + * @throws InvalidInterfaceException |
|
961 | + */ |
|
962 | + public function add_new_state() |
|
963 | + { |
|
964 | + |
|
965 | + $success = true; |
|
966 | + |
|
967 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
968 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
969 | + : false; |
|
970 | + if (! $CNT_ISO) { |
|
971 | + EE_Error::add_error( |
|
972 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
973 | + __FILE__, |
|
974 | + __FUNCTION__, |
|
975 | + __LINE__ |
|
976 | + ); |
|
977 | + $success = false; |
|
978 | + } |
|
979 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
980 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
981 | + : false; |
|
982 | + if (! $STA_abbrev) { |
|
983 | + EE_Error::add_error( |
|
984 | + esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
985 | + __FILE__, |
|
986 | + __FUNCTION__, |
|
987 | + __LINE__ |
|
988 | + ); |
|
989 | + $success = false; |
|
990 | + } |
|
991 | + $STA_name = isset($this->_req_data['STA_name']) |
|
992 | + ? sanitize_text_field($this->_req_data['STA_name']) |
|
993 | + : false; |
|
994 | + if (! $STA_name) { |
|
995 | + EE_Error::add_error( |
|
996 | + esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
997 | + __FILE__, |
|
998 | + __FUNCTION__, |
|
999 | + __LINE__ |
|
1000 | + ); |
|
1001 | + $success = false; |
|
1002 | + } |
|
1003 | + |
|
1004 | + if ($success) { |
|
1005 | + $cols_n_values = array( |
|
1006 | + 'CNT_ISO' => $CNT_ISO, |
|
1007 | + 'STA_abbrev' => $STA_abbrev, |
|
1008 | + 'STA_name' => $STA_name, |
|
1009 | + 'STA_active' => true, |
|
1010 | + ); |
|
1011 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
1012 | + EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1013 | + } |
|
1014 | + |
|
1015 | + if (defined('DOING_AJAX')) { |
|
1016 | + $notices = EE_Error::get_notices(false, false, false); |
|
1017 | + echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
1018 | + die(); |
|
1019 | + } else { |
|
1020 | + $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * delete_state |
|
1027 | + * |
|
1028 | + * @access public |
|
1029 | + * @return boolean |
|
1030 | + * @throws EE_Error |
|
1031 | + * @throws InvalidArgumentException |
|
1032 | + * @throws InvalidDataTypeException |
|
1033 | + * @throws InvalidInterfaceException |
|
1034 | + */ |
|
1035 | + public function delete_state() |
|
1036 | + { |
|
1037 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
1038 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
1039 | + : false; |
|
1040 | + $STA_ID = isset($this->_req_data['STA_ID']) |
|
1041 | + ? sanitize_text_field($this->_req_data['STA_ID']) |
|
1042 | + : false; |
|
1043 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
1044 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
1045 | + : false; |
|
1046 | + if (! $STA_ID) { |
|
1047 | + EE_Error::add_error( |
|
1048 | + esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1049 | + __FILE__, |
|
1050 | + __FUNCTION__, |
|
1051 | + __LINE__ |
|
1052 | + ); |
|
1053 | + return false; |
|
1054 | + } |
|
1055 | + |
|
1056 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1057 | + if ($success !== false) { |
|
1058 | + do_action( |
|
1059 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1060 | + $CNT_ISO, |
|
1061 | + $STA_ID, |
|
1062 | + array('STA_abbrev' => $STA_abbrev) |
|
1063 | + ); |
|
1064 | + EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1065 | + } |
|
1066 | + if (defined('DOING_AJAX')) { |
|
1067 | + $notices = EE_Error::get_notices(false, false); |
|
1068 | + $notices['return_data'] = true; |
|
1069 | + echo wp_json_encode($notices); |
|
1070 | + die(); |
|
1071 | + } else { |
|
1072 | + $this->_redirect_after_action( |
|
1073 | + $success, |
|
1074 | + 'State', |
|
1075 | + 'deleted', |
|
1076 | + array('action' => 'country_settings') |
|
1077 | + ); |
|
1078 | + } |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * _update_country_settings |
|
1084 | + * |
|
1085 | + * @access protected |
|
1086 | + * @return void |
|
1087 | + * @throws EE_Error |
|
1088 | + * @throws InvalidArgumentException |
|
1089 | + * @throws InvalidDataTypeException |
|
1090 | + * @throws InvalidInterfaceException |
|
1091 | + */ |
|
1092 | + protected function _update_country_settings() |
|
1093 | + { |
|
1094 | + // grab the country ISO code |
|
1095 | + $CNT_ISO = isset($this->_req_data['country']) |
|
1096 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
1097 | + : false; |
|
1098 | + if (! $CNT_ISO) { |
|
1099 | + EE_Error::add_error( |
|
1100 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1101 | + __FILE__, |
|
1102 | + __FUNCTION__, |
|
1103 | + __LINE__ |
|
1104 | + ); |
|
1105 | + |
|
1106 | + return; |
|
1107 | + } |
|
1108 | + $cols_n_values = array(); |
|
1109 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1110 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1111 | + : false; |
|
1112 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1113 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1114 | + : null; |
|
1115 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1116 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1117 | + : null; |
|
1118 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1119 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1120 | + sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1121 | + ); |
|
1122 | + } |
|
1123 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1124 | + $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
1125 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1129 | + $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
1130 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1131 | + ); |
|
1132 | + } |
|
1133 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1134 | + $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
1135 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1139 | + $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
1140 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1141 | + ); |
|
1142 | + } |
|
1143 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1144 | + $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
1145 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1146 | + ); |
|
1147 | + } |
|
1148 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1149 | + $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
1150 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1151 | + ); |
|
1152 | + } |
|
1153 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1154 | + $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
1155 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1156 | + ); |
|
1157 | + } |
|
1158 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1159 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1160 | + : null; |
|
1161 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1162 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1163 | + : false; |
|
1164 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1165 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1166 | + : false; |
|
1167 | + // allow filtering of country data |
|
1168 | + $cols_n_values = apply_filters( |
|
1169 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1170 | + $cols_n_values |
|
1171 | + ); |
|
1172 | + |
|
1173 | + // where values |
|
1174 | + $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
1175 | + // run the update |
|
1176 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1177 | + |
|
1178 | + if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
1179 | + // allow filtering of states data |
|
1180 | + $states = apply_filters( |
|
1181 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1182 | + $this->_req_data['states'] |
|
1183 | + ); |
|
1184 | + |
|
1185 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
1186 | + foreach ($states as $STA_ID => $state) { |
|
1187 | + $cols_n_values = array( |
|
1188 | + 'CNT_ISO' => $CNT_ISO, |
|
1189 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1190 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1191 | + 'STA_active' => (bool) absint($state['STA_active']), |
|
1192 | + ); |
|
1193 | + // where values |
|
1194 | + $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
1195 | + // run the update |
|
1196 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1197 | + if ($success !== false) { |
|
1198 | + do_action( |
|
1199 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1200 | + $CNT_ISO, |
|
1201 | + $STA_ID, |
|
1202 | + $cols_n_values |
|
1203 | + ); |
|
1204 | + } |
|
1205 | + } |
|
1206 | + } |
|
1207 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1208 | + if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1209 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1210 | + ) { |
|
1211 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1212 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
1213 | + } |
|
1214 | + |
|
1215 | + if ($success !== false) { |
|
1216 | + EE_Error::add_success( |
|
1217 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1218 | + ); |
|
1219 | + } |
|
1220 | + $this->_redirect_after_action( |
|
1221 | + $success, |
|
1222 | + '', |
|
1223 | + '', |
|
1224 | + array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
1225 | + true |
|
1226 | + ); |
|
1227 | + } |
|
1228 | + |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * form_form_field_label_wrap |
|
1232 | + * |
|
1233 | + * @access public |
|
1234 | + * @param string $label |
|
1235 | + * @return string |
|
1236 | + */ |
|
1237 | + public function country_form_field_label_wrap($label, $required_text) |
|
1238 | + { |
|
1239 | + return ' |
|
1240 | 1240 | <tr> |
1241 | 1241 | <th> |
1242 | 1242 | ' . $label . ' |
1243 | 1243 | </th>'; |
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * form_form_field_input__wrap |
|
1249 | - * |
|
1250 | - * @access public |
|
1251 | - * @param string $label |
|
1252 | - * @return string |
|
1253 | - */ |
|
1254 | - public function country_form_field_input__wrap($input, $label) |
|
1255 | - { |
|
1256 | - return ' |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * form_form_field_input__wrap |
|
1249 | + * |
|
1250 | + * @access public |
|
1251 | + * @param string $label |
|
1252 | + * @return string |
|
1253 | + */ |
|
1254 | + public function country_form_field_input__wrap($input, $label) |
|
1255 | + { |
|
1256 | + return ' |
|
1257 | 1257 | <td class="general-settings-country-input-td"> |
1258 | 1258 | ' . $input . ' |
1259 | 1259 | </td> |
1260 | 1260 | </tr>'; |
1261 | - } |
|
1262 | - |
|
1263 | - |
|
1264 | - /** |
|
1265 | - * form_form_field_label_wrap |
|
1266 | - * |
|
1267 | - * @access public |
|
1268 | - * @param string $label |
|
1269 | - * @param string $required_text |
|
1270 | - * @return string |
|
1271 | - */ |
|
1272 | - public function state_form_field_label_wrap($label, $required_text) |
|
1273 | - { |
|
1274 | - return $required_text; |
|
1275 | - } |
|
1276 | - |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * form_form_field_input__wrap |
|
1280 | - * |
|
1281 | - * @access public |
|
1282 | - * @param string $label |
|
1283 | - * @return string |
|
1284 | - */ |
|
1285 | - public function state_form_field_input__wrap($input, $label) |
|
1286 | - { |
|
1287 | - return ' |
|
1261 | + } |
|
1262 | + |
|
1263 | + |
|
1264 | + /** |
|
1265 | + * form_form_field_label_wrap |
|
1266 | + * |
|
1267 | + * @access public |
|
1268 | + * @param string $label |
|
1269 | + * @param string $required_text |
|
1270 | + * @return string |
|
1271 | + */ |
|
1272 | + public function state_form_field_label_wrap($label, $required_text) |
|
1273 | + { |
|
1274 | + return $required_text; |
|
1275 | + } |
|
1276 | + |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * form_form_field_input__wrap |
|
1280 | + * |
|
1281 | + * @access public |
|
1282 | + * @param string $label |
|
1283 | + * @return string |
|
1284 | + */ |
|
1285 | + public function state_form_field_input__wrap($input, $label) |
|
1286 | + { |
|
1287 | + return ' |
|
1288 | 1288 | <td class="general-settings-country-state-input-td"> |
1289 | 1289 | ' . $input . ' |
1290 | 1290 | </td>'; |
1291 | - } |
|
1292 | - |
|
1293 | - |
|
1294 | - /***********/ |
|
1295 | - |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * displays edit and view links for critical EE pages |
|
1299 | - * |
|
1300 | - * @access public |
|
1301 | - * @param int $ee_page_id |
|
1302 | - * @return string |
|
1303 | - */ |
|
1304 | - public static function edit_view_links($ee_page_id) |
|
1305 | - { |
|
1306 | - $links = '<a href="' |
|
1307 | - . add_query_arg( |
|
1308 | - array('post' => $ee_page_id, 'action' => 'edit'), |
|
1309 | - admin_url('post.php') |
|
1310 | - ) |
|
1311 | - . '" >' |
|
1312 | - . esc_html__('Edit', 'event_espresso') |
|
1313 | - . '</a>'; |
|
1314 | - $links .= ' | '; |
|
1315 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1316 | - |
|
1317 | - return $links; |
|
1318 | - } |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * displays page and shortcode status for critical EE pages |
|
1323 | - * |
|
1324 | - * @param WP page object $ee_page |
|
1325 | - * @return string |
|
1326 | - */ |
|
1327 | - public static function page_and_shortcode_status($ee_page, $shortcode) |
|
1328 | - { |
|
1329 | - |
|
1330 | - // page status |
|
1331 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1332 | - $pg_colour = 'green'; |
|
1333 | - $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1334 | - } else { |
|
1335 | - $pg_colour = 'red'; |
|
1336 | - $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1337 | - } |
|
1338 | - |
|
1339 | - // shortcode status |
|
1340 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1341 | - $sc_colour = 'green'; |
|
1342 | - $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1343 | - } else { |
|
1344 | - $sc_colour = 'red'; |
|
1345 | - $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1346 | - } |
|
1347 | - |
|
1348 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1349 | - . $pg_status |
|
1350 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1351 | - } |
|
1352 | - |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * generates a dropdown of all parent pages - copied from WP core |
|
1356 | - * |
|
1357 | - * @param int $default |
|
1358 | - * @param int $parent |
|
1359 | - * @param int $level |
|
1360 | - */ |
|
1361 | - public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
1362 | - { |
|
1363 | - global $wpdb; |
|
1364 | - $items = $wpdb->get_results( |
|
1365 | - $wpdb->prepare( |
|
1366 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1367 | - $parent |
|
1368 | - ) |
|
1369 | - ); |
|
1370 | - |
|
1371 | - if ($items) { |
|
1372 | - foreach ($items as $item) { |
|
1373 | - $pad = str_repeat(' ', $level * 3); |
|
1374 | - if ($item->ID == $default) { |
|
1375 | - $current = ' selected="selected"'; |
|
1376 | - } else { |
|
1377 | - $current = ''; |
|
1378 | - } |
|
1379 | - |
|
1380 | - echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
1381 | - . esc_html($item->post_title) |
|
1382 | - . "</option>"; |
|
1383 | - parent_dropdown($default, $item->ID, $level + 1); |
|
1384 | - } |
|
1385 | - } |
|
1386 | - } |
|
1387 | - |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * Loads the scripts for the privacy settings form |
|
1391 | - */ |
|
1392 | - public function load_scripts_styles_privacy_settings() |
|
1393 | - { |
|
1394 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1395 | - $form_handler->enqueueStylesAndScripts(); |
|
1396 | - } |
|
1397 | - |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * display the privacy settings form |
|
1401 | - */ |
|
1402 | - public function privacySettings() |
|
1403 | - { |
|
1404 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1405 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1406 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1407 | - $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
1408 | - $this->display_admin_page_with_sidebar(); |
|
1409 | - } |
|
1410 | - |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * Update the privacy settings from form data |
|
1414 | - * |
|
1415 | - * @throws EE_Error |
|
1416 | - */ |
|
1417 | - public function updatePrivacySettings() |
|
1418 | - { |
|
1419 | - $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1420 | - $success = $form_handler->process($this->get_request_data()); |
|
1421 | - $this->_redirect_after_action( |
|
1422 | - $success, |
|
1423 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1424 | - 'updated', |
|
1425 | - array('action' => 'privacy_settings') |
|
1426 | - ); |
|
1427 | - } |
|
1291 | + } |
|
1292 | + |
|
1293 | + |
|
1294 | + /***********/ |
|
1295 | + |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * displays edit and view links for critical EE pages |
|
1299 | + * |
|
1300 | + * @access public |
|
1301 | + * @param int $ee_page_id |
|
1302 | + * @return string |
|
1303 | + */ |
|
1304 | + public static function edit_view_links($ee_page_id) |
|
1305 | + { |
|
1306 | + $links = '<a href="' |
|
1307 | + . add_query_arg( |
|
1308 | + array('post' => $ee_page_id, 'action' => 'edit'), |
|
1309 | + admin_url('post.php') |
|
1310 | + ) |
|
1311 | + . '" >' |
|
1312 | + . esc_html__('Edit', 'event_espresso') |
|
1313 | + . '</a>'; |
|
1314 | + $links .= ' | '; |
|
1315 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1316 | + |
|
1317 | + return $links; |
|
1318 | + } |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * displays page and shortcode status for critical EE pages |
|
1323 | + * |
|
1324 | + * @param WP page object $ee_page |
|
1325 | + * @return string |
|
1326 | + */ |
|
1327 | + public static function page_and_shortcode_status($ee_page, $shortcode) |
|
1328 | + { |
|
1329 | + |
|
1330 | + // page status |
|
1331 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1332 | + $pg_colour = 'green'; |
|
1333 | + $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1334 | + } else { |
|
1335 | + $pg_colour = 'red'; |
|
1336 | + $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1337 | + } |
|
1338 | + |
|
1339 | + // shortcode status |
|
1340 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1341 | + $sc_colour = 'green'; |
|
1342 | + $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1343 | + } else { |
|
1344 | + $sc_colour = 'red'; |
|
1345 | + $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1346 | + } |
|
1347 | + |
|
1348 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1349 | + . $pg_status |
|
1350 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1351 | + } |
|
1352 | + |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * generates a dropdown of all parent pages - copied from WP core |
|
1356 | + * |
|
1357 | + * @param int $default |
|
1358 | + * @param int $parent |
|
1359 | + * @param int $level |
|
1360 | + */ |
|
1361 | + public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
1362 | + { |
|
1363 | + global $wpdb; |
|
1364 | + $items = $wpdb->get_results( |
|
1365 | + $wpdb->prepare( |
|
1366 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1367 | + $parent |
|
1368 | + ) |
|
1369 | + ); |
|
1370 | + |
|
1371 | + if ($items) { |
|
1372 | + foreach ($items as $item) { |
|
1373 | + $pad = str_repeat(' ', $level * 3); |
|
1374 | + if ($item->ID == $default) { |
|
1375 | + $current = ' selected="selected"'; |
|
1376 | + } else { |
|
1377 | + $current = ''; |
|
1378 | + } |
|
1379 | + |
|
1380 | + echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
1381 | + . esc_html($item->post_title) |
|
1382 | + . "</option>"; |
|
1383 | + parent_dropdown($default, $item->ID, $level + 1); |
|
1384 | + } |
|
1385 | + } |
|
1386 | + } |
|
1387 | + |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * Loads the scripts for the privacy settings form |
|
1391 | + */ |
|
1392 | + public function load_scripts_styles_privacy_settings() |
|
1393 | + { |
|
1394 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1395 | + $form_handler->enqueueStylesAndScripts(); |
|
1396 | + } |
|
1397 | + |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * display the privacy settings form |
|
1401 | + */ |
|
1402 | + public function privacySettings() |
|
1403 | + { |
|
1404 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1405 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1406 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1407 | + $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
1408 | + $this->display_admin_page_with_sidebar(); |
|
1409 | + } |
|
1410 | + |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * Update the privacy settings from form data |
|
1414 | + * |
|
1415 | + * @throws EE_Error |
|
1416 | + */ |
|
1417 | + public function updatePrivacySettings() |
|
1418 | + { |
|
1419 | + $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1420 | + $success = $form_handler->process($this->get_request_data()); |
|
1421 | + $this->_redirect_after_action( |
|
1422 | + $success, |
|
1423 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1424 | + 'updated', |
|
1425 | + array('action' => 'privacy_settings') |
|
1426 | + ); |
|
1427 | + } |
|
1428 | 1428 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | wp_enqueue_script('thickbox'); |
292 | 292 | wp_register_script( |
293 | 293 | 'organization_settings', |
294 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
294 | + GEN_SET_ASSETS_URL.'your_organization_settings.js', |
|
295 | 295 | array('jquery', 'media-upload', 'thickbox'), |
296 | 296 | EVENT_ESPRESSO_VERSION, |
297 | 297 | true |
298 | 298 | ); |
299 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
299 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
300 | 300 | wp_enqueue_script('organization_settings'); |
301 | 301 | wp_enqueue_style('organization-css'); |
302 | 302 | $confirm_image_delete = array( |
@@ -319,12 +319,12 @@ discard block |
||
319 | 319 | // scripts |
320 | 320 | wp_register_script( |
321 | 321 | 'gen_settings_countries', |
322 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
322 | + GEN_SET_ASSETS_URL.'gen_settings_countries.js', |
|
323 | 323 | array('ee_admin_js'), |
324 | 324 | EVENT_ESPRESSO_VERSION, |
325 | 325 | true |
326 | 326 | ); |
327 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
327 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
328 | 328 | wp_enqueue_script('gen_settings_countries'); |
329 | 329 | wp_enqueue_style('organization-css'); |
330 | 330 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
375 | 375 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
376 | 376 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
377 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
377 | + GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php', |
|
378 | 378 | $this->_template_args, |
379 | 379 | true |
380 | 380 | ); |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | { |
534 | 534 | try { |
535 | 535 | $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
536 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
536 | + $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
537 | 537 | EE_Registry::instance()->CFG->admin = apply_filters( |
538 | 538 | 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
539 | 539 | EE_Registry::instance()->CFG->admin |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | $this->_set_add_edit_form_tags('update_country_settings'); |
651 | 651 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
652 | 652 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
653 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
653 | + GEN_SET_TEMPLATE_PATH.'countries_settings.template.php', |
|
654 | 654 | $this->_template_args, |
655 | 655 | true |
656 | 656 | ); |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | $CNT_ISO = isset($this->_req_data['country']) |
679 | 679 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
680 | 680 | : $CNT_ISO; |
681 | - if (! $CNT_ISO) { |
|
681 | + if ( ! $CNT_ISO) { |
|
682 | 682 | return ''; |
683 | 683 | } |
684 | 684 | |
@@ -694,59 +694,59 @@ discard block |
||
694 | 694 | $country_input_types = array( |
695 | 695 | 'CNT_active' => array( |
696 | 696 | 'type' => 'RADIO_BTN', |
697 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
697 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
698 | 698 | 'class' => '', |
699 | 699 | 'options' => $this->_yes_no_values, |
700 | 700 | 'use_desc_4_label' => true, |
701 | 701 | ), |
702 | 702 | 'CNT_ISO' => array( |
703 | 703 | 'type' => 'TEXT', |
704 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
704 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
705 | 705 | 'class' => 'small-text', |
706 | 706 | ), |
707 | 707 | 'CNT_ISO3' => array( |
708 | 708 | 'type' => 'TEXT', |
709 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
709 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
710 | 710 | 'class' => 'small-text', |
711 | 711 | ), |
712 | 712 | 'RGN_ID' => array( |
713 | 713 | 'type' => 'TEXT', |
714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
714 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
715 | 715 | 'class' => 'small-text', |
716 | 716 | ), |
717 | 717 | 'CNT_name' => array( |
718 | 718 | 'type' => 'TEXT', |
719 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
719 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
720 | 720 | 'class' => 'regular-text', |
721 | 721 | ), |
722 | 722 | 'CNT_cur_code' => array( |
723 | 723 | 'type' => 'TEXT', |
724 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
724 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
725 | 725 | 'class' => 'small-text', |
726 | 726 | 'disabled' => $CNT_cur_disabled, |
727 | 727 | ), |
728 | 728 | 'CNT_cur_single' => array( |
729 | 729 | 'type' => 'TEXT', |
730 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
730 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
731 | 731 | 'class' => 'medium-text', |
732 | 732 | 'disabled' => $CNT_cur_disabled, |
733 | 733 | ), |
734 | 734 | 'CNT_cur_plural' => array( |
735 | 735 | 'type' => 'TEXT', |
736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
736 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
737 | 737 | 'class' => 'medium-text', |
738 | 738 | 'disabled' => $CNT_cur_disabled, |
739 | 739 | ), |
740 | 740 | 'CNT_cur_sign' => array( |
741 | 741 | 'type' => 'TEXT', |
742 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
742 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
743 | 743 | 'class' => 'small-text', |
744 | 744 | 'htmlentities' => false, |
745 | 745 | 'disabled' => $CNT_cur_disabled, |
746 | 746 | ), |
747 | 747 | 'CNT_cur_sign_b4' => array( |
748 | 748 | 'type' => 'RADIO_BTN', |
749 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
749 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
750 | 750 | 'class' => '', |
751 | 751 | 'options' => $this->_yes_no_values, |
752 | 752 | 'use_desc_4_label' => true, |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | ), |
755 | 755 | 'CNT_cur_dec_plc' => array( |
756 | 756 | 'type' => 'RADIO_BTN', |
757 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
757 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
758 | 758 | 'class' => '', |
759 | 759 | 'options' => array( |
760 | 760 | array('id' => 0, 'text' => ''), |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | ), |
767 | 767 | 'CNT_cur_dec_mrk' => array( |
768 | 768 | 'type' => 'RADIO_BTN', |
769 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
769 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
770 | 770 | 'class' => '', |
771 | 771 | 'options' => array( |
772 | 772 | array( |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | ), |
781 | 781 | 'CNT_cur_thsnds' => array( |
782 | 782 | 'type' => 'RADIO_BTN', |
783 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
783 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
784 | 784 | 'class' => '', |
785 | 785 | 'options' => array( |
786 | 786 | array( |
@@ -801,12 +801,12 @@ discard block |
||
801 | 801 | ), |
802 | 802 | 'CNT_tel_code' => array( |
803 | 803 | 'type' => 'TEXT', |
804 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
804 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
805 | 805 | 'class' => 'small-text', |
806 | 806 | ), |
807 | 807 | 'CNT_is_EU' => array( |
808 | 808 | 'type' => 'RADIO_BTN', |
809 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
809 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
810 | 810 | 'class' => '', |
811 | 811 | 'options' => $this->_yes_no_values, |
812 | 812 | 'use_desc_4_label' => true, |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | $country_input_types |
818 | 818 | ); |
819 | 819 | $country_details_settings = EEH_Template::display_template( |
820 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
820 | + GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php', |
|
821 | 821 | $this->_template_args, |
822 | 822 | true |
823 | 823 | ); |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | $CNT_ISO = isset($this->_req_data['country']) |
856 | 856 | ? sanitize_text_field($this->_req_data['country']) |
857 | 857 | : $CNT_ISO; |
858 | - if (! $CNT_ISO) { |
|
858 | + if ( ! $CNT_ISO) { |
|
859 | 859 | return ''; |
860 | 860 | } |
861 | 861 | // for ajax |
@@ -885,22 +885,22 @@ discard block |
||
885 | 885 | $state_input_types = array( |
886 | 886 | 'STA_abbrev' => array( |
887 | 887 | 'type' => 'TEXT', |
888 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
888 | + 'input_name' => 'states['.$STA_ID.']', |
|
889 | 889 | 'class' => 'mid-text', |
890 | 890 | ), |
891 | 891 | 'STA_name' => array( |
892 | 892 | 'type' => 'TEXT', |
893 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
893 | + 'input_name' => 'states['.$STA_ID.']', |
|
894 | 894 | 'class' => 'regular-text', |
895 | 895 | ), |
896 | 896 | 'STA_active' => array( |
897 | 897 | 'type' => 'RADIO_BTN', |
898 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
898 | + 'input_name' => 'states['.$STA_ID.']', |
|
899 | 899 | 'options' => $this->_yes_no_values, |
900 | 900 | 'use_desc_4_label' => true, |
901 | 901 | ), |
902 | 902 | ); |
903 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
903 | + $this->_template_args['states'][$STA_ID]['inputs'] = |
|
904 | 904 | EE_Question_Form_Input::generate_question_form_inputs_for_object( |
905 | 905 | $state, |
906 | 906 | $state_input_types |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | 'CNT_ISO' => $CNT_ISO, |
912 | 912 | 'STA_abbrev' => $state->abbrev(), |
913 | 913 | ); |
914 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
914 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
915 | 915 | EE_Admin_Page::add_query_args_and_nonce( |
916 | 916 | $query_args, |
917 | 917 | GEN_SET_ADMIN_URL |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | ); |
929 | 929 | |
930 | 930 | $state_details_settings = EEH_Template::display_template( |
931 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
931 | + GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php', |
|
932 | 932 | $this->_template_args, |
933 | 933 | true |
934 | 934 | ); |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
968 | 968 | ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
969 | 969 | : false; |
970 | - if (! $CNT_ISO) { |
|
970 | + if ( ! $CNT_ISO) { |
|
971 | 971 | EE_Error::add_error( |
972 | 972 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
973 | 973 | __FILE__, |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
980 | 980 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
981 | 981 | : false; |
982 | - if (! $STA_abbrev) { |
|
982 | + if ( ! $STA_abbrev) { |
|
983 | 983 | EE_Error::add_error( |
984 | 984 | esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
985 | 985 | __FILE__, |
@@ -991,7 +991,7 @@ discard block |
||
991 | 991 | $STA_name = isset($this->_req_data['STA_name']) |
992 | 992 | ? sanitize_text_field($this->_req_data['STA_name']) |
993 | 993 | : false; |
994 | - if (! $STA_name) { |
|
994 | + if ( ! $STA_name) { |
|
995 | 995 | EE_Error::add_error( |
996 | 996 | esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
997 | 997 | __FILE__, |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
1044 | 1044 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
1045 | 1045 | : false; |
1046 | - if (! $STA_ID) { |
|
1046 | + if ( ! $STA_ID) { |
|
1047 | 1047 | EE_Error::add_error( |
1048 | 1048 | esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
1049 | 1049 | __FILE__, |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | $CNT_ISO = isset($this->_req_data['country']) |
1096 | 1096 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
1097 | 1097 | : false; |
1098 | - if (! $CNT_ISO) { |
|
1098 | + if ( ! $CNT_ISO) { |
|
1099 | 1099 | EE_Error::add_error( |
1100 | 1100 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
1101 | 1101 | __FILE__, |
@@ -1106,63 +1106,63 @@ discard block |
||
1106 | 1106 | return; |
1107 | 1107 | } |
1108 | 1108 | $cols_n_values = array(); |
1109 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1110 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1109 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
1110 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
1111 | 1111 | : false; |
1112 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1113 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1112 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
1113 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
1114 | 1114 | : null; |
1115 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1116 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1115 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
1116 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
1117 | 1117 | : null; |
1118 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1118 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) { |
|
1119 | 1119 | $cols_n_values['CNT_cur_code'] = strtoupper( |
1120 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1120 | + sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
1121 | 1121 | ); |
1122 | 1122 | } |
1123 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1123 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) { |
|
1124 | 1124 | $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
1125 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1125 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'] |
|
1126 | 1126 | ); |
1127 | 1127 | } |
1128 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1128 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) { |
|
1129 | 1129 | $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
1130 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1130 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'] |
|
1131 | 1131 | ); |
1132 | 1132 | } |
1133 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1133 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) { |
|
1134 | 1134 | $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
1135 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1135 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'] |
|
1136 | 1136 | ); |
1137 | 1137 | } |
1138 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1138 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) { |
|
1139 | 1139 | $cols_n_values['CNT_cur_sign_b4'] = absint( |
1140 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1140 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'] |
|
1141 | 1141 | ); |
1142 | 1142 | } |
1143 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1143 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) { |
|
1144 | 1144 | $cols_n_values['CNT_cur_dec_plc'] = absint( |
1145 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1145 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'] |
|
1146 | 1146 | ); |
1147 | 1147 | } |
1148 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1148 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) { |
|
1149 | 1149 | $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
1150 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1150 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'] |
|
1151 | 1151 | ); |
1152 | 1152 | } |
1153 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1153 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) { |
|
1154 | 1154 | $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
1155 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1155 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'] |
|
1156 | 1156 | ); |
1157 | 1157 | } |
1158 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1159 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1158 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
1159 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
1160 | 1160 | : null; |
1161 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1162 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1161 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
1162 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
1163 | 1163 | : false; |
1164 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1165 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1164 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
1165 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
1166 | 1166 | : false; |
1167 | 1167 | // allow filtering of country data |
1168 | 1168 | $cols_n_values = apply_filters( |
@@ -1239,7 +1239,7 @@ discard block |
||
1239 | 1239 | return ' |
1240 | 1240 | <tr> |
1241 | 1241 | <th> |
1242 | - ' . $label . ' |
|
1242 | + ' . $label.' |
|
1243 | 1243 | </th>'; |
1244 | 1244 | } |
1245 | 1245 | |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | { |
1256 | 1256 | return ' |
1257 | 1257 | <td class="general-settings-country-input-td"> |
1258 | - ' . $input . ' |
|
1258 | + ' . $input.' |
|
1259 | 1259 | </td> |
1260 | 1260 | </tr>'; |
1261 | 1261 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | { |
1287 | 1287 | return ' |
1288 | 1288 | <td class="general-settings-country-state-input-td"> |
1289 | - ' . $input . ' |
|
1289 | + ' . $input.' |
|
1290 | 1290 | </td>'; |
1291 | 1291 | } |
1292 | 1292 | |
@@ -1312,7 +1312,7 @@ discard block |
||
1312 | 1312 | . esc_html__('Edit', 'event_espresso') |
1313 | 1313 | . '</a>'; |
1314 | 1314 | $links .= ' | '; |
1315 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1315 | + $links .= '<a href="'.get_permalink($ee_page_id).'" >'.esc_html__('View', 'event_espresso').'</a>'; |
|
1316 | 1316 | |
1317 | 1317 | return $links; |
1318 | 1318 | } |
@@ -1345,9 +1345,9 @@ discard block |
||
1345 | 1345 | $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1348 | + return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>' |
|
1349 | 1349 | . $pg_status |
1350 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1350 | + . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>'; |
|
1351 | 1351 | } |
1352 | 1352 | |
1353 | 1353 |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | /* @var EE_Question[] $all_questions */ |
12 | 12 | assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions |
13 | 13 | foreach ($all_questions as $unused_question) { |
14 | - assert($unused_question); |
|
15 | - assert($unused_question instanceof EE_Question); |
|
14 | + assert($unused_question); |
|
15 | + assert($unused_question instanceof EE_Question); |
|
16 | 16 | } |
17 | 17 | /* @var array $values . Array of arrays, where each sub-array contains 2 keys: 'id' (internal value) and 'name' (label for displaying) */ |
18 | 18 | assert(is_array($values)); |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | <th> |
32 | 32 | <label for="QSG_name"> |
33 | 33 | <?php _e('Group Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
34 | - 'group_name_info' |
|
35 | - ); ?> |
|
34 | + 'group_name_info' |
|
35 | + ); ?> |
|
36 | 36 | </label> |
37 | 37 | </th> |
38 | 38 | <td> |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | <th> |
47 | 47 | <label for="QSG_identifier"> |
48 | 48 | <?php _e('Group Identifier', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
49 | - 'group_identifier_info' |
|
50 | - ); ?> |
|
49 | + 'group_identifier_info' |
|
50 | + ); ?> |
|
51 | 51 | </label> |
52 | 52 | </th> |
53 | 53 | <td> |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | <th> |
67 | 67 | <label for="QSG_desc"> |
68 | 68 | <?php _e('Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
69 | - 'group_description_info' |
|
70 | - ); ?> |
|
69 | + 'group_description_info' |
|
70 | + ); ?> |
|
71 | 71 | </label> |
72 | 72 | </th> |
73 | 73 | <td> |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | <th> |
81 | 81 | <label for="QSG_order"> |
82 | 82 | <?php _e('Question Group Order', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
83 | - 'group_order_info' |
|
84 | - ); ?> |
|
83 | + 'group_order_info' |
|
84 | + ); ?> |
|
85 | 85 | </label> |
86 | 86 | </th> |
87 | 87 | <td> |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | <th> |
95 | 95 | <label> |
96 | 96 | <?php _e('Show Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
97 | - 'show_group_name_info' |
|
98 | - ); ?> |
|
97 | + 'show_group_name_info' |
|
98 | + ); ?> |
|
99 | 99 | </label> |
100 | 100 | </th> |
101 | 101 | <td> |
102 | 102 | <label for="QSG_show_group_name"> |
103 | 103 | <?php echo EEH_Form_Fields::select_input( |
104 | - 'QSG_show_group_name', |
|
105 | - $values, |
|
106 | - $question_group->show_group_name() |
|
107 | - ); ?> |
|
104 | + 'QSG_show_group_name', |
|
105 | + $values, |
|
106 | + $question_group->show_group_name() |
|
107 | + ); ?> |
|
108 | 108 | <p class="description"><?php _e('Show Group Name on Registration Page?', 'event_espresso'); ?></p> |
109 | 109 | </label> |
110 | 110 | </td> |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | <th> |
115 | 115 | <label> |
116 | 116 | <?php _e(' Show Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
117 | - 'show_group_description_info' |
|
118 | - ); ?> |
|
117 | + 'show_group_description_info' |
|
118 | + ); ?> |
|
119 | 119 | </label> |
120 | 120 | </th> |
121 | 121 | <td> |
122 | 122 | <label for="QSG_show_group_order"> |
123 | 123 | <?php echo EEH_Form_Fields::select_input( |
124 | - 'QSG_show_group_desc', |
|
125 | - $values, |
|
126 | - $question_group->show_group_desc() |
|
127 | - ); ?> |
|
124 | + 'QSG_show_group_desc', |
|
125 | + $values, |
|
126 | + $question_group->show_group_desc() |
|
127 | + ); ?> |
|
128 | 128 | <p class="description"><?php |
129 | - _e(' Show Group Description on Registration Page?', 'event_espresso'); |
|
130 | - ?></p> |
|
129 | + _e(' Show Group Description on Registration Page?', 'event_espresso'); |
|
130 | + ?></p> |
|
131 | 131 | </label> |
132 | 132 | <input type="hidden" name="QSG_system" value="<?php echo $question_group->system_group(); ?>"> |
133 | 133 | </td> |
@@ -143,82 +143,82 @@ discard block |
||
143 | 143 | <div class="form-table question-group-questions inside"> |
144 | 144 | <div class="padding"> |
145 | 145 | <p><span class="description"><?php |
146 | - _e( |
|
147 | - 'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.', |
|
148 | - 'event_espresso' |
|
149 | - ); ?></span></p> |
|
146 | + _e( |
|
147 | + 'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.', |
|
148 | + 'event_espresso' |
|
149 | + ); ?></span></p> |
|
150 | 150 | <div> |
151 | 151 | <ul class="question-list-sortable"> |
152 | 152 | <?php |
153 | - $question_order = 0; |
|
154 | - $question_group_questions = $question_group->questions(); |
|
155 | - foreach ($all_questions as $question_ID => $question) { |
|
156 | - if ($question instanceof EE_Question) { |
|
157 | - /*@var $question EE_Question*/ |
|
158 | - $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
159 | - // disable questions from the personal information question group |
|
160 | - // is it required in the current question group? if so don't allow admins to remove it |
|
161 | - $disabled = in_array( |
|
162 | - $question->system_ID(), |
|
163 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
164 | - $QSG_system |
|
165 | - ) |
|
166 | - ) ? 'disabled="disabled"' : ''; |
|
167 | - // limit where system questions can appear |
|
168 | - if ($question->system_ID() && |
|
169 | - ! in_array( |
|
170 | - $question->system_ID(), |
|
171 | - EEM_Question::instance()->allowed_system_questions_in_system_question_group( |
|
172 | - $QSG_system |
|
173 | - ) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions). The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions. |
|
177 | - } |
|
178 | - ?> |
|
153 | + $question_order = 0; |
|
154 | + $question_group_questions = $question_group->questions(); |
|
155 | + foreach ($all_questions as $question_ID => $question) { |
|
156 | + if ($question instanceof EE_Question) { |
|
157 | + /*@var $question EE_Question*/ |
|
158 | + $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
159 | + // disable questions from the personal information question group |
|
160 | + // is it required in the current question group? if so don't allow admins to remove it |
|
161 | + $disabled = in_array( |
|
162 | + $question->system_ID(), |
|
163 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
164 | + $QSG_system |
|
165 | + ) |
|
166 | + ) ? 'disabled="disabled"' : ''; |
|
167 | + // limit where system questions can appear |
|
168 | + if ($question->system_ID() && |
|
169 | + ! in_array( |
|
170 | + $question->system_ID(), |
|
171 | + EEM_Question::instance()->allowed_system_questions_in_system_question_group( |
|
172 | + $QSG_system |
|
173 | + ) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions). The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions. |
|
177 | + } |
|
178 | + ?> |
|
179 | 179 | <li class="ee-question-sortable"> |
180 | 180 | <label for="question-<?php echo $question_ID ?>"> |
181 | 181 | <input type="checkbox" name="questions[<?php echo $question_ID; ?>]" |
182 | 182 | id="question-<?php echo $question_ID; ?>" |
183 | 183 | value="<?php echo $question_ID; ?>"<?php echo $disabled; ?><?php echo $checked; ?>/> |
184 | 184 | <span class="question-text"><?php |
185 | - echo trim($question->display_text()) |
|
186 | - . (95 <= strlen(trim($question->display_text())) |
|
187 | - ? "…" |
|
188 | - : ''); |
|
189 | - ?> |
|
185 | + echo trim($question->display_text()) |
|
186 | + . (95 <= strlen(trim($question->display_text())) |
|
187 | + ? "…" |
|
188 | + : ''); |
|
189 | + ?> |
|
190 | 190 | </span> |
191 | 191 | <input class="question-group-QGQ_order" type="hidden" |
192 | 192 | name="question_orders[<?php echo $question_ID; ?>]" |
193 | 193 | value="<?php echo $question_order; ?>"> |
194 | 194 | </label> |
195 | 195 | <?php |
196 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
197 | - 'ee_edit_question', |
|
198 | - 'espresso_registration_form_edit_question', |
|
199 | - $question->ID() |
|
200 | - )) { |
|
201 | - $edit_query_args = array( |
|
202 | - 'action' => 'edit_question', |
|
203 | - 'QST_ID' => $question->ID(), |
|
204 | - ); |
|
205 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
|
196 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
197 | + 'ee_edit_question', |
|
198 | + 'espresso_registration_form_edit_question', |
|
199 | + $question->ID() |
|
200 | + )) { |
|
201 | + $edit_query_args = array( |
|
202 | + 'action' => 'edit_question', |
|
203 | + 'QST_ID' => $question->ID(), |
|
204 | + ); |
|
205 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
|
206 | 206 | |
207 | - echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
208 | - sprintf( |
|
209 | - esc_attr__('Edit %s', 'event_espresso'), |
|
210 | - $question->admin_label() |
|
211 | - ) |
|
212 | - . '"><span class="dashicons dashicons-edit"></span> |
|
207 | + echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
208 | + sprintf( |
|
209 | + esc_attr__('Edit %s', 'event_espresso'), |
|
210 | + $question->admin_label() |
|
211 | + ) |
|
212 | + . '"><span class="dashicons dashicons-edit"></span> |
|
213 | 213 | </a>'; |
214 | - } |
|
215 | - ?> |
|
214 | + } |
|
215 | + ?> |
|
216 | 216 | </li> |
217 | 217 | <?php |
218 | - $question_order++; |
|
219 | - } |
|
220 | - } |
|
221 | - ?> |
|
218 | + $question_order++; |
|
219 | + } |
|
220 | + } |
|
221 | + ?> |
|
222 | 222 | </ul> |
223 | 223 | </div> |
224 | 224 | </div> |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | assert($question_group); |
10 | 10 | assert($question_group instanceof EE_Question_Group); |
11 | 11 | /* @var EE_Question[] $all_questions */ |
12 | -assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions |
|
12 | +assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions))); // list of unused questions |
|
13 | 13 | foreach ($all_questions as $unused_question) { |
14 | 14 | assert($unused_question); |
15 | 15 | assert($unused_question instanceof EE_Question); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | <input id="QSG_identifier" name="QSG_identifier<?php echo $id; ?>" |
55 | 55 | value="<?php $question_group->f('QSG_identifier') ?>" type="text" |
56 | 56 | class="regular-text"<?php echo $disabled; ?>> |
57 | - <?php if (! empty($QSG_system)) { ?> |
|
57 | + <?php if ( ! empty($QSG_system)) { ?> |
|
58 | 58 | <p><span class="description" style="color:#D54E21;"> |
59 | 59 | <?php _e('System question group! This field cannot be changed.', 'event_espresso') ?> |
60 | 60 | </span><br/></p> |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | foreach ($all_questions as $question_ID => $question) { |
156 | 156 | if ($question instanceof EE_Question) { |
157 | 157 | /*@var $question EE_Question*/ |
158 | - $checked = isset($question_group_questions[ $question_ID ]) ? ' checked="checked"' : ''; |
|
158 | + $checked = isset($question_group_questions[$question_ID]) ? ' checked="checked"' : ''; |
|
159 | 159 | // disable questions from the personal information question group |
160 | 160 | // is it required in the current question group? if so don't allow admins to remove it |
161 | 161 | $disabled = in_array( |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | ); |
205 | 205 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL); |
206 | 206 | |
207 | - echo '<a href="' . $edit_link . '" target="_blank" title="' . |
|
207 | + echo '<a href="'.$edit_link.'" target="_blank" title="'. |
|
208 | 208 | sprintf( |
209 | 209 | esc_attr__('Edit %s', 'event_espresso'), |
210 | 210 | $question->admin_label() |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | if ($QST_system === 'country') { |
19 | 19 | echo EEH_HTML::div( |
20 | 20 | EEH_HTML::h4( |
21 | - '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
22 | - ) . |
|
21 | + '<span class="dashicons dashicons-info"></span>'.esc_html__('Did you know...', 'event_espresso') |
|
22 | + ). |
|
23 | 23 | EEH_HTML::p( |
24 | 24 | esc_html__( |
25 | 25 | 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | value="<?php $question->f('QST_admin_label') ?>"<?php echo $disabled_attr ?>/> |
63 | 63 | <input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" |
64 | 64 | name="QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>"/> |
65 | - <?php if (! empty($QST_system)) { ?> |
|
65 | + <?php if ( ! empty($QST_system)) { ?> |
|
66 | 66 | <input type="hidden" id="QST_admin_label" name="QST_admin_label" |
67 | 67 | value="<?php echo $question->admin_label() ?>"/> |
68 | 68 | <?php } ?> |
69 | 69 | <br/> |
70 | 70 | <p class="description"> |
71 | - <?php if (! empty($QST_system)) { ?> |
|
71 | + <?php if ( ! empty($QST_system)) { ?> |
|
72 | 72 | <span class="description" style="color:#D54E21;"> |
73 | 73 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
74 | 74 | </span> |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | <br/> |
97 | 97 | <p class="description"> |
98 | 98 | <?php |
99 | - if (! empty($QST_system)) { ?> |
|
99 | + if ( ! empty($QST_system)) { ?> |
|
100 | 100 | <span class="description" style="color:#D54E21;"> |
101 | 101 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
102 | 102 | </span> |
@@ -124,16 +124,16 @@ discard block |
||
124 | 124 | |
125 | 125 | // Only display Confirm email for |
126 | 126 | if (empty($QST_system) |
127 | - || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
127 | + || ( ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
128 | 128 | ) { |
129 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
129 | + unset($question_types[EEM_Question::QST_type_email_confirm]); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | echo EEH_Form_Fields::select_input( |
133 | - 'QST_type' . $id, |
|
133 | + 'QST_type'.$id, |
|
134 | 134 | $question_types, |
135 | 135 | $question->type(), |
136 | - 'id="QST_type' . $id . '"' . $disabled_attr |
|
136 | + 'id="QST_type'.$id.'"'.$disabled_attr |
|
137 | 137 | ); |
138 | 138 | if ($disabled) { ?> |
139 | 139 | <input type="hidden" id="QST_type" name="QST_type" value="<?php echo $question->type() ?>"/> |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | <?php |
234 | 234 | $count = 0; |
235 | 235 | $question_options = $question->options(); |
236 | - if (! empty($question_options)) { |
|
236 | + if ( ! empty($question_options)) { |
|
237 | 237 | foreach ($question_options as $option_id => $option) { |
238 | 238 | $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
239 | 239 | ?> |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | value="<?php $option->f('QSO_desc') ?>"> |
257 | 257 | </td> |
258 | 258 | <td> |
259 | - <?php if (! $option->system()) { ?> |
|
259 | + <?php if ( ! $option->system()) { ?> |
|
260 | 260 | <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span> |
261 | 261 | <?php } ?> |
262 | 262 | <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span> |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
347 | 347 | ); |
348 | 348 | echo EEH_Form_Fields::select_input( |
349 | - 'QST_required' . $id, |
|
349 | + 'QST_required'.$id, |
|
350 | 350 | $requiredOptions, |
351 | 351 | $question->required(), |
352 | - 'id="QST_required' . $id . '"' . $disabled_attr |
|
352 | + 'id="QST_required'.$id.'"'.$disabled_attr |
|
353 | 353 | ); |
354 | 354 | ?> |
355 | 355 | <p><span id="required_toggled_on" class="description" |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'event_espresso' |
366 | 366 | ) ?> |
367 | 367 | </span></p> |
368 | - <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
368 | + <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
|
369 | 369 | <input type="hidden" id="QST_required" name="QST_required" value="1"/> |
370 | 370 | <p><span class="description" style="color:#D54E21;"> |
371 | 371 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
@@ -19,32 +19,32 @@ discard block |
||
19 | 19 | $has_answers = $question->has_answers(); |
20 | 20 | |
21 | 21 | if ($QST_system === 'country') { |
22 | - echo EEH_HTML::div( |
|
23 | - EEH_HTML::h4( |
|
24 | - '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
25 | - ) . |
|
26 | - EEH_HTML::p( |
|
27 | - esc_html__( |
|
28 | - 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
|
29 | - 'event_espresso' |
|
30 | - ) |
|
31 | - ), |
|
32 | - '', |
|
33 | - 'ee-info-box' |
|
34 | - ); |
|
22 | + echo EEH_HTML::div( |
|
23 | + EEH_HTML::h4( |
|
24 | + '<span class="dashicons dashicons-info"></span>' . esc_html__('Did you know...', 'event_espresso') |
|
25 | + ) . |
|
26 | + EEH_HTML::p( |
|
27 | + esc_html__( |
|
28 | + 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
|
29 | + 'event_espresso' |
|
30 | + ) |
|
31 | + ), |
|
32 | + '', |
|
33 | + 'ee-info-box' |
|
34 | + ); |
|
35 | 35 | } |
36 | 36 | ?> |
37 | 37 | |
38 | 38 | <?php |
39 | - do_action('AHEE__questions_main_meta_box__template__inner_admin_page_content', $question); |
|
39 | + do_action('AHEE__questions_main_meta_box__template__inner_admin_page_content', $question); |
|
40 | 40 | ?> |
41 | 41 | |
42 | 42 | <div class="padding"> |
43 | 43 | <table class="form-table"> |
44 | 44 | <tbody> |
45 | 45 | <?php |
46 | - do_action('AHEE__questions_main_meta_box__template__before_table_form_table', $question); |
|
47 | - ?> |
|
46 | + do_action('AHEE__questions_main_meta_box__template__before_table_form_table', $question); |
|
47 | + ?> |
|
48 | 48 | <tr> |
49 | 49 | <th> |
50 | 50 | <label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | </th> |
65 | 65 | <td> |
66 | 66 | <?php |
67 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
68 | - $id = ! empty($QST_system) ? '_disabled' : ''; |
|
69 | - ?> |
|
67 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
68 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
69 | + ?> |
|
70 | 70 | <input type="text" class="regular-text" id="QST_admin_label<?php echo $id ?>" |
71 | 71 | name="QST_admin_label<?php echo $id ?>" |
72 | 72 | value="<?php $question->f('QST_admin_label') ?>"<?php echo $disabled_attr ?>/> |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | </th> |
96 | 96 | <td> |
97 | 97 | <?php |
98 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
99 | - $id = ! empty($QST_system) ? '_disabled' : ''; |
|
100 | - $admin_only = $question->get('QST_admin_only'); |
|
101 | - $checked = ! empty($admin_only) ? ' checked="checked"' : ''; |
|
102 | - ?> |
|
98 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
99 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
100 | + $admin_only = $question->get('QST_admin_only'); |
|
101 | + $checked = ! empty($admin_only) ? ' checked="checked"' : ''; |
|
102 | + ?> |
|
103 | 103 | <input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" |
104 | 104 | name="QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled_attr; |
105 | - echo $checked; ?>/> |
|
105 | + echo $checked; ?>/> |
|
106 | 106 | <br/> |
107 | 107 | <p class="description"> |
108 | 108 | <?php |
109 | - if (! empty($QST_system)) { ?> |
|
109 | + if (! empty($QST_system)) { ?> |
|
110 | 110 | <span class="description" style="color:#D54E21;"> |
111 | 111 | <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> |
112 | 112 | </span> |
@@ -123,39 +123,39 @@ discard block |
||
123 | 123 | </th> |
124 | 124 | <td> |
125 | 125 | <?php |
126 | - $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; |
|
127 | - if ($disabled) { |
|
128 | - $disabled_attr = 'disabled="disabled"'; |
|
129 | - $id = '_disabled'; |
|
130 | - } else { |
|
131 | - $disabled_attr = ''; |
|
132 | - $id = ''; |
|
133 | - } |
|
126 | + $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; |
|
127 | + if ($disabled) { |
|
128 | + $disabled_attr = 'disabled="disabled"'; |
|
129 | + $id = '_disabled'; |
|
130 | + } else { |
|
131 | + $disabled_attr = ''; |
|
132 | + $id = ''; |
|
133 | + } |
|
134 | 134 | |
135 | - // Only display Confirm email for |
|
136 | - if (empty($QST_system) |
|
137 | - || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
138 | - ) { |
|
139 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
140 | - } |
|
135 | + // Only display Confirm email for |
|
136 | + if (empty($QST_system) |
|
137 | + || (! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_email_confirm) |
|
138 | + ) { |
|
139 | + unset($question_types[ EEM_Question::QST_type_email_confirm ]); |
|
140 | + } |
|
141 | 141 | |
142 | - echo EEH_Form_Fields::select_input( |
|
143 | - 'QST_type' . $id, |
|
144 | - $question_types, |
|
145 | - $question->type(), |
|
146 | - 'id="QST_type' . $id . '"' . $disabled_attr |
|
147 | - ); |
|
148 | - if ($disabled) { ?> |
|
142 | + echo EEH_Form_Fields::select_input( |
|
143 | + 'QST_type' . $id, |
|
144 | + $question_types, |
|
145 | + $question->type(), |
|
146 | + 'id="QST_type' . $id . '"' . $disabled_attr |
|
147 | + ); |
|
148 | + if ($disabled) { ?> |
|
149 | 149 | <input type="hidden" id="QST_type" name="QST_type" value="<?php echo $question->type() ?>"/> |
150 | 150 | <?php |
151 | - $explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso'); |
|
152 | - } else { |
|
153 | - $explanatory_text = esc_html__( |
|
154 | - 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', |
|
155 | - 'event_espresso' |
|
156 | - ); |
|
157 | - } |
|
158 | - if ($disabled || $has_answers) { ?> |
|
151 | + $explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso'); |
|
152 | + } else { |
|
153 | + $explanatory_text = esc_html__( |
|
154 | + 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', |
|
155 | + 'event_espresso' |
|
156 | + ); |
|
157 | + } |
|
158 | + if ($disabled || $has_answers) { ?> |
|
159 | 159 | <p><span class="description" style="color:#D54E21;"> |
160 | 160 | <?php echo $explanatory_text; ?> |
161 | 161 | </span></p> |
@@ -173,25 +173,25 @@ discard block |
||
173 | 173 | </th> |
174 | 174 | <td> |
175 | 175 | <input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' |
176 | - : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1"> |
|
176 | + : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1"> |
|
177 | 177 | <p> |
178 | 178 | <span class="description"> |
179 | 179 | <?php esc_html_e( |
180 | - 'Maximum number of characters allowed when answering this question', |
|
181 | - 'event_espresso' |
|
182 | - ); ?> |
|
180 | + 'Maximum number of characters allowed when answering this question', |
|
181 | + 'event_espresso' |
|
182 | + ); ?> |
|
183 | 183 | </span> |
184 | 184 | </p> |
185 | 185 | <?php if ($QST_system) { ?> |
186 | 186 | <p> |
187 | 187 | <span class="description" style="color:#D54E21;"> |
188 | 188 | <?php printf( |
189 | - esc_html__( |
|
190 | - 'System question! The maximum number of characters that can be used for this question is %1$s', |
|
191 | - 'event_espresso' |
|
192 | - ), |
|
193 | - $max_max |
|
194 | - ); ?> |
|
189 | + esc_html__( |
|
190 | + 'System question! The maximum number of characters that can be used for this question is %1$s', |
|
191 | + 'event_espresso' |
|
192 | + ), |
|
193 | + $max_max |
|
194 | + ); ?> |
|
195 | 195 | </span> |
196 | 196 | </p> |
197 | 197 | <?php } ?> |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | </th> |
214 | 214 | <th class="option-desc-header"> |
215 | 215 | <?php esc_html_e( |
216 | - 'Description (optional, only shown on registration form)', |
|
217 | - 'event_espresso' |
|
218 | - ) ?> |
|
216 | + 'Description (optional, only shown on registration form)', |
|
217 | + 'event_espresso' |
|
218 | + ) ?> |
|
219 | 219 | </th> |
220 | 220 | <th> |
221 | 221 | </th> |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | </tr> |
242 | 242 | |
243 | 243 | <?php |
244 | - $count = 0; |
|
245 | - $question_options = $question->options(); |
|
246 | - if (! empty($question_options)) { |
|
247 | - foreach ($question_options as $option_id => $option) { |
|
248 | - $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
249 | - ?> |
|
244 | + $count = 0; |
|
245 | + $question_options = $question->options(); |
|
246 | + if (! empty($question_options)) { |
|
247 | + foreach ($question_options as $option_id => $option) { |
|
248 | + $disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
249 | + ?> |
|
250 | 250 | <tr class="question-option ee-options-sortable"> |
251 | 251 | <td class="option-value-cell"> |
252 | 252 | <input type="hidden" class="QSO_order" |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span> |
273 | 273 | </td> |
274 | 274 | <?php |
275 | - echo EEH_Form_Fields::hidden_input( |
|
276 | - "question_options[{$count}][QST_ID])", |
|
277 | - $option->question_ID() |
|
278 | - ); |
|
279 | - echo EEH_Form_Fields::hidden_input( |
|
280 | - "question_options[{$count}][QSO_ID])", |
|
281 | - $option->ID() |
|
282 | - ); |
|
283 | - $count++; |
|
284 | - ?> |
|
275 | + echo EEH_Form_Fields::hidden_input( |
|
276 | + "question_options[{$count}][QST_ID])", |
|
277 | + $option->question_ID() |
|
278 | + ); |
|
279 | + echo EEH_Form_Fields::hidden_input( |
|
280 | + "question_options[{$count}][QSO_ID])", |
|
281 | + $option->ID() |
|
282 | + ); |
|
283 | + $count++; |
|
284 | + ?> |
|
285 | 285 | </tr> |
286 | 286 | <?php |
287 | - } |
|
288 | - } else { |
|
289 | - ?> |
|
287 | + } |
|
288 | + } else { |
|
289 | + ?> |
|
290 | 290 | <tr class="question-option ee-options-sortable"> |
291 | 291 | <td class="option-value-cell"> |
292 | 292 | <input type="hidden" class="QSO_order" name="question_options[0][QSO_order]" value="0"/> |
@@ -299,19 +299,19 @@ discard block |
||
299 | 299 | </td> |
300 | 300 | <td> |
301 | 301 | <?php |
302 | - echo EEH_Form_Fields::hidden_input("question_options_count", $count); |
|
303 | - ?> |
|
302 | + echo EEH_Form_Fields::hidden_input("question_options_count", $count); |
|
303 | + ?> |
|
304 | 304 | </td> |
305 | 305 | </tr> |
306 | 306 | <?php |
307 | - } |
|
308 | - ?> |
|
307 | + } |
|
308 | + ?> |
|
309 | 309 | <tr style="display:none"> |
310 | 310 | <td colspan="3"> |
311 | 311 | <?php echo EEH_Form_Fields::hidden_input( |
312 | - "question_options_count", |
|
313 | - $count |
|
314 | - ); ?></td> |
|
312 | + "question_options_count", |
|
313 | + $count |
|
314 | + ); ?></td> |
|
315 | 315 | </tr> |
316 | 316 | </tbody> |
317 | 317 | </table> |
@@ -322,16 +322,16 @@ discard block |
||
322 | 322 | |
323 | 323 | <p class="description"> |
324 | 324 | <?php esc_html_e( |
325 | - 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', |
|
326 | - 'event_espresso' |
|
327 | - ) ?> |
|
325 | + 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', |
|
326 | + 'event_espresso' |
|
327 | + ) ?> |
|
328 | 328 | </p> |
329 | 329 | <?php if ($has_answers) : ?> |
330 | 330 | <p class="description" style="color:#D54E21;"> |
331 | 331 | <?php esc_html_e( |
332 | - 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', |
|
333 | - 'event_espresso' |
|
334 | - ); ?> |
|
332 | + 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', |
|
333 | + 'event_espresso' |
|
334 | + ); ?> |
|
335 | 335 | </p> |
336 | 336 | |
337 | 337 | <?php endif; ?> |
@@ -345,35 +345,35 @@ discard block |
||
345 | 345 | </th> |
346 | 346 | <td> |
347 | 347 | <?php |
348 | - $system_required = array('fname', 'email'); |
|
349 | - $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; |
|
350 | - $required_on = $question->get('QST_admin_only'); |
|
351 | - $show_required_msg = $required_on ? '' : ' display:none;'; |
|
352 | - $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; |
|
353 | - $id = ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; |
|
354 | - $requiredOptions = array( |
|
355 | - array('text' => esc_html__('Optional', 'event_espresso'), 'id' => 0), |
|
356 | - array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
|
357 | - ); |
|
358 | - echo EEH_Form_Fields::select_input( |
|
359 | - 'QST_required' . $id, |
|
360 | - $requiredOptions, |
|
361 | - $question->required(), |
|
362 | - 'id="QST_required' . $id . '"' . $disabled_attr |
|
363 | - ); |
|
364 | - ?> |
|
348 | + $system_required = array('fname', 'email'); |
|
349 | + $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; |
|
350 | + $required_on = $question->get('QST_admin_only'); |
|
351 | + $show_required_msg = $required_on ? '' : ' display:none;'; |
|
352 | + $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; |
|
353 | + $id = ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; |
|
354 | + $requiredOptions = array( |
|
355 | + array('text' => esc_html__('Optional', 'event_espresso'), 'id' => 0), |
|
356 | + array('text' => esc_html__('Required', 'event_espresso'), 'id' => 1), |
|
357 | + ); |
|
358 | + echo EEH_Form_Fields::select_input( |
|
359 | + 'QST_required' . $id, |
|
360 | + $requiredOptions, |
|
361 | + $question->required(), |
|
362 | + 'id="QST_required' . $id . '"' . $disabled_attr |
|
363 | + ); |
|
364 | + ?> |
|
365 | 365 | <p><span id="required_toggled_on" class="description" |
366 | 366 | style="color:#D54E21;<?php echo $show_required_msg; ?>"> |
367 | 367 | <?php esc_html_e( |
368 | - 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', |
|
369 | - 'event_espresso' |
|
370 | - ) ?> |
|
368 | + 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', |
|
369 | + 'event_espresso' |
|
370 | + ) ?> |
|
371 | 371 | </span></p> |
372 | 372 | <p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;"> |
373 | 373 | <?php esc_html_e( |
374 | - 'Required option field is no longer disabled because the question is not Admin-Only', |
|
375 | - 'event_espresso' |
|
376 | - ) ?> |
|
374 | + 'Required option field is no longer disabled because the question is not Admin-Only', |
|
375 | + 'event_espresso' |
|
376 | + ) ?> |
|
377 | 377 | </span></p> |
378 | 378 | <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> |
379 | 379 | <input type="hidden" id="QST_required" name="QST_required" value="1"/> |
@@ -389,9 +389,9 @@ discard block |
||
389 | 389 | <th> |
390 | 390 | <label for="QST_required_text"> |
391 | 391 | <?php esc_html_e( |
392 | - 'Required Text', |
|
393 | - 'event_espresso' |
|
394 | - ); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?> |
|
392 | + 'Required Text', |
|
393 | + 'event_espresso' |
|
394 | + ); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?> |
|
395 | 395 | </th> |
396 | 396 | <td> |
397 | 397 | <input type="text" maxlength="100" class="regular-text" id="QST_required_text" name="QST_required_text" |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | </td> |
401 | 401 | </tr> |
402 | 402 | <?php |
403 | - do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); |
|
404 | - ?> |
|
403 | + do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); |
|
404 | + ?> |
|
405 | 405 | </tbody> |
406 | 406 | </table> |
407 | 407 | |
@@ -409,5 +409,5 @@ discard block |
||
409 | 409 | </div> |
410 | 410 | |
411 | 411 | <?php |
412 | - do_action('AHEE__questions_main_meta_box__template__after_admin_page_content', $question); |
|
412 | + do_action('AHEE__questions_main_meta_box__template__after_admin_page_content', $question); |
|
413 | 413 |
@@ -18,1458 +18,1458 @@ |
||
18 | 18 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @type bool $_print_copy_info |
|
23 | - */ |
|
24 | - private $_print_copy_info = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type array $_attendee_data |
|
28 | - */ |
|
29 | - private $_attendee_data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @type array $_required_questions |
|
33 | - */ |
|
34 | - private $_required_questions = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * @type array $_registration_answers |
|
38 | - */ |
|
39 | - private $_registration_answers = array(); |
|
21 | + /** |
|
22 | + * @type bool $_print_copy_info |
|
23 | + */ |
|
24 | + private $_print_copy_info = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type array $_attendee_data |
|
28 | + */ |
|
29 | + private $_attendee_data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @type array $_required_questions |
|
33 | + */ |
|
34 | + private $_required_questions = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * @type array $_registration_answers |
|
38 | + */ |
|
39 | + private $_registration_answers = array(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @type int $reg_form_count |
|
43 | - */ |
|
44 | - protected $reg_form_count = 0; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * class constructor |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param EE_Checkout $checkout |
|
52 | - */ |
|
53 | - public function __construct(EE_Checkout $checkout) |
|
54 | - { |
|
55 | - $this->_slug = 'attendee_information'; |
|
56 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
57 | - $this->checkout = $checkout; |
|
58 | - $this->_reset_success_message(); |
|
59 | - $this->set_instructions( |
|
60 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - public function translate_js_strings() |
|
66 | - { |
|
67 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
68 | - ' is a required question.', |
|
69 | - 'event_espresso' |
|
70 | - ); |
|
71 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
72 | - ' is a required question. Please enter a value for at least one of the options.', |
|
73 | - 'event_espresso' |
|
74 | - ); |
|
75 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
76 | - 'Please answer all required questions correctly before proceeding.', |
|
77 | - 'event_espresso' |
|
78 | - ); |
|
79 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
80 | - esc_html_x( |
|
81 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
82 | - 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '<br/>' |
|
86 | - ); |
|
87 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
88 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
89 | - 'event_espresso' |
|
90 | - ); |
|
91 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
92 | - 'You must enter a valid email address.', |
|
93 | - 'event_espresso' |
|
94 | - ); |
|
95 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
96 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
97 | - 'event_espresso' |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - public function enqueue_styles_and_scripts() |
|
103 | - { |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - public function initialize_reg_step() |
|
111 | - { |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return EE_Form_Section_Proper |
|
118 | - * @throws DomainException |
|
119 | - * @throws EE_Error |
|
120 | - * @throws InvalidArgumentException |
|
121 | - * @throws ReflectionException |
|
122 | - * @throws EntityNotFoundException |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - * @throws InvalidInterfaceException |
|
125 | - */ |
|
126 | - public function generate_reg_form() |
|
127 | - { |
|
128 | - /** |
|
129 | - * @var $reg_config EE_Registration_Config |
|
130 | - */ |
|
131 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
41 | + /** |
|
42 | + * @type int $reg_form_count |
|
43 | + */ |
|
44 | + protected $reg_form_count = 0; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * class constructor |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param EE_Checkout $checkout |
|
52 | + */ |
|
53 | + public function __construct(EE_Checkout $checkout) |
|
54 | + { |
|
55 | + $this->_slug = 'attendee_information'; |
|
56 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
57 | + $this->checkout = $checkout; |
|
58 | + $this->_reset_success_message(); |
|
59 | + $this->set_instructions( |
|
60 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + public function translate_js_strings() |
|
66 | + { |
|
67 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
68 | + ' is a required question.', |
|
69 | + 'event_espresso' |
|
70 | + ); |
|
71 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
72 | + ' is a required question. Please enter a value for at least one of the options.', |
|
73 | + 'event_espresso' |
|
74 | + ); |
|
75 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
76 | + 'Please answer all required questions correctly before proceeding.', |
|
77 | + 'event_espresso' |
|
78 | + ); |
|
79 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
80 | + esc_html_x( |
|
81 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
82 | + 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '<br/>' |
|
86 | + ); |
|
87 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
88 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
89 | + 'event_espresso' |
|
90 | + ); |
|
91 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
92 | + 'You must enter a valid email address.', |
|
93 | + 'event_espresso' |
|
94 | + ); |
|
95 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
96 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
97 | + 'event_espresso' |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + public function enqueue_styles_and_scripts() |
|
103 | + { |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + public function initialize_reg_step() |
|
111 | + { |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return EE_Form_Section_Proper |
|
118 | + * @throws DomainException |
|
119 | + * @throws EE_Error |
|
120 | + * @throws InvalidArgumentException |
|
121 | + * @throws ReflectionException |
|
122 | + * @throws EntityNotFoundException |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + * @throws InvalidInterfaceException |
|
125 | + */ |
|
126 | + public function generate_reg_form() |
|
127 | + { |
|
128 | + /** |
|
129 | + * @var $reg_config EE_Registration_Config |
|
130 | + */ |
|
131 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
132 | 132 | |
133 | - $this->_print_copy_info = $reg_config->copyAttendeeInfo(); |
|
134 | - |
|
135 | - // Init reg forms count. |
|
136 | - $this->reg_form_count = 0; |
|
137 | - |
|
138 | - $primary_registrant = null; |
|
139 | - // autoload Line_Item_Display classes |
|
140 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
141 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
142 | - // calculate taxes |
|
143 | - $Line_Item_Display->display_line_item( |
|
144 | - $this->checkout->cart->get_grand_total(), |
|
145 | - array('set_tax_rate' => true) |
|
146 | - ); |
|
147 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
148 | - $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
149 | - $subsections = array( |
|
150 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
151 | - ); |
|
152 | - |
|
153 | - // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
154 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
155 | - $extra_inputs_section->add_subsections( |
|
156 | - array( |
|
157 | - 'consent_box' => new EE_Form_Section_Proper( |
|
158 | - array( |
|
159 | - 'layout_strategy' => |
|
160 | - new EE_Template_Layout( |
|
161 | - array( |
|
162 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
163 | - ) |
|
164 | - ), |
|
165 | - 'subsections' => array( |
|
166 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
167 | - array( |
|
168 | - 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
169 | - ), |
|
170 | - array( |
|
171 | - 'required' => true, |
|
172 | - 'required_validation_error_message' => esc_html__( |
|
173 | - 'You must consent to these terms in order to register.', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - 'html_label_text' => '', |
|
177 | - ) |
|
178 | - ), |
|
179 | - ), |
|
180 | - ) |
|
181 | - ), |
|
182 | - ), |
|
183 | - null, |
|
184 | - false |
|
185 | - ); |
|
186 | - } |
|
187 | - $template_args = array( |
|
188 | - 'revisit' => $this->checkout->revisit, |
|
189 | - 'registrations' => array(), |
|
190 | - 'ticket_count' => array(), |
|
191 | - ); |
|
192 | - // grab the saved registrations from the transaction |
|
193 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
194 | - if ($registrations) { |
|
195 | - foreach ($registrations as $registration) { |
|
196 | - // can this registration be processed during this visit ? |
|
197 | - if ($registration instanceof EE_Registration |
|
198 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
199 | - ) { |
|
200 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
201 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
202 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
203 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
204 | - ) |
|
205 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
206 | - : 1; |
|
207 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
208 | - $this->checkout->cart->get_grand_total(), |
|
209 | - 'Ticket', |
|
210 | - array($registration->ticket()->ID()) |
|
211 | - ); |
|
212 | - $ticket_line_item = is_array($ticket_line_item) |
|
213 | - ? reset($ticket_line_item) |
|
214 | - : $ticket_line_item; |
|
215 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
216 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
217 | - if ($registration->is_primary_registrant()) { |
|
218 | - $primary_registrant = $registration->reg_url_link(); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($primary_registrant && count($registrations) > 1) { |
|
224 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
225 | - ? $this->_copy_attendee_info_form() |
|
226 | - : $this->_auto_copy_attendee_info(); |
|
227 | - // generate hidden input |
|
228 | - if (isset($subsections[ $primary_registrant ]) |
|
229 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
230 | - ) { |
|
231 | - $subsections[ $primary_registrant ]->add_subsections( |
|
232 | - $copy_options, |
|
233 | - 'primary_registrant', |
|
234 | - false |
|
235 | - ); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - // Set the registration form template (default: one form per ticket details table). |
|
241 | - // We decide the template to used based on the number of forms. |
|
242 | - $this->_template = $this->reg_form_count > 1 |
|
243 | - ? SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php' |
|
244 | - : SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_single.template.php'; |
|
245 | - |
|
246 | - return new EE_Form_Section_Proper( |
|
247 | - array( |
|
248 | - 'name' => $this->reg_form_name(), |
|
249 | - 'html_id' => $this->reg_form_name(), |
|
250 | - 'subsections' => $subsections, |
|
251 | - 'layout_strategy' => new EE_Template_Layout( |
|
252 | - array( |
|
253 | - 'layout_template_file' => $this->_template, // layout_template |
|
254 | - 'template_args' => $template_args, |
|
255 | - ) |
|
256 | - ), |
|
257 | - ) |
|
258 | - ); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param EE_Registration $registration |
|
264 | - * @return EE_Form_Section_Base |
|
265 | - * @throws EE_Error |
|
266 | - * @throws InvalidArgumentException |
|
267 | - * @throws EntityNotFoundException |
|
268 | - * @throws InvalidDataTypeException |
|
269 | - * @throws InvalidInterfaceException |
|
270 | - * @throws ReflectionException |
|
271 | - */ |
|
272 | - private function _registrations_reg_form(EE_Registration $registration) |
|
273 | - { |
|
274 | - static $attendee_nmbr = 1; |
|
275 | - $form_args = array(); |
|
276 | - // verify that registration has valid event |
|
277 | - if ($registration->event() instanceof EE_Event) { |
|
278 | - $field_name = 'Event_Question_Group.' |
|
279 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
280 | - $registration->is_primary_registrant() |
|
281 | - ); |
|
282 | - $question_groups = $registration->event()->question_groups( |
|
283 | - apply_filters( |
|
284 | - // @codingStandardsIgnoreStart |
|
285 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
286 | - // @codingStandardsIgnoreEnd |
|
287 | - [ |
|
288 | - [ |
|
289 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
290 | - $field_name => true, |
|
291 | - ], |
|
292 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
293 | - ], |
|
294 | - $registration, |
|
295 | - $this |
|
296 | - ) |
|
297 | - ); |
|
298 | - if ($question_groups) { |
|
299 | - // array of params to pass to parent constructor |
|
300 | - $form_args = array( |
|
301 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
302 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
303 | - 'html_style' => $this->checkout->admin_request |
|
304 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
305 | - : '', |
|
306 | - 'subsections' => array(), |
|
307 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
308 | - array( |
|
309 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
310 | - 'legend_text' => sprintf( |
|
311 | - esc_html_x( |
|
312 | - 'Attendee %d', |
|
313 | - 'Attendee 123', |
|
314 | - 'event_espresso' |
|
315 | - ), |
|
316 | - $attendee_nmbr |
|
317 | - ), |
|
318 | - ) |
|
319 | - ), |
|
320 | - ); |
|
321 | - foreach ($question_groups as $question_group) { |
|
322 | - if ($question_group instanceof EE_Question_Group) { |
|
323 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
324 | - $registration, |
|
325 | - $question_group |
|
326 | - ); |
|
327 | - } |
|
328 | - } |
|
329 | - // add hidden input |
|
330 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
331 | - $registration |
|
332 | - ); |
|
333 | - |
|
334 | - /** |
|
335 | - * @var $reg_config EE_Registration_Config |
|
336 | - */ |
|
337 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
338 | - |
|
339 | - // If we have question groups for additional attendees, then display the copy options |
|
340 | - $this->_print_copy_info = apply_filters( |
|
341 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
342 | - $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false, |
|
343 | - $attendee_nmbr |
|
344 | - ); |
|
345 | - |
|
346 | - if ($registration->is_primary_registrant()) { |
|
347 | - // generate hidden input |
|
348 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
349 | - $registration |
|
350 | - ); |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
354 | - $attendee_nmbr++; |
|
133 | + $this->_print_copy_info = $reg_config->copyAttendeeInfo(); |
|
134 | + |
|
135 | + // Init reg forms count. |
|
136 | + $this->reg_form_count = 0; |
|
137 | + |
|
138 | + $primary_registrant = null; |
|
139 | + // autoload Line_Item_Display classes |
|
140 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
141 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
142 | + // calculate taxes |
|
143 | + $Line_Item_Display->display_line_item( |
|
144 | + $this->checkout->cart->get_grand_total(), |
|
145 | + array('set_tax_rate' => true) |
|
146 | + ); |
|
147 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
148 | + $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
149 | + $subsections = array( |
|
150 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
151 | + ); |
|
152 | + |
|
153 | + // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
154 | + if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
155 | + $extra_inputs_section->add_subsections( |
|
156 | + array( |
|
157 | + 'consent_box' => new EE_Form_Section_Proper( |
|
158 | + array( |
|
159 | + 'layout_strategy' => |
|
160 | + new EE_Template_Layout( |
|
161 | + array( |
|
162 | + 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
163 | + ) |
|
164 | + ), |
|
165 | + 'subsections' => array( |
|
166 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
167 | + array( |
|
168 | + 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
169 | + ), |
|
170 | + array( |
|
171 | + 'required' => true, |
|
172 | + 'required_validation_error_message' => esc_html__( |
|
173 | + 'You must consent to these terms in order to register.', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + 'html_label_text' => '', |
|
177 | + ) |
|
178 | + ), |
|
179 | + ), |
|
180 | + ) |
|
181 | + ), |
|
182 | + ), |
|
183 | + null, |
|
184 | + false |
|
185 | + ); |
|
186 | + } |
|
187 | + $template_args = array( |
|
188 | + 'revisit' => $this->checkout->revisit, |
|
189 | + 'registrations' => array(), |
|
190 | + 'ticket_count' => array(), |
|
191 | + ); |
|
192 | + // grab the saved registrations from the transaction |
|
193 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
194 | + if ($registrations) { |
|
195 | + foreach ($registrations as $registration) { |
|
196 | + // can this registration be processed during this visit ? |
|
197 | + if ($registration instanceof EE_Registration |
|
198 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
199 | + ) { |
|
200 | + $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
201 | + $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
202 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
203 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
204 | + ) |
|
205 | + ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
206 | + : 1; |
|
207 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
208 | + $this->checkout->cart->get_grand_total(), |
|
209 | + 'Ticket', |
|
210 | + array($registration->ticket()->ID()) |
|
211 | + ); |
|
212 | + $ticket_line_item = is_array($ticket_line_item) |
|
213 | + ? reset($ticket_line_item) |
|
214 | + : $ticket_line_item; |
|
215 | + $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
216 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
217 | + if ($registration->is_primary_registrant()) { |
|
218 | + $primary_registrant = $registration->reg_url_link(); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($primary_registrant && count($registrations) > 1) { |
|
224 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
225 | + ? $this->_copy_attendee_info_form() |
|
226 | + : $this->_auto_copy_attendee_info(); |
|
227 | + // generate hidden input |
|
228 | + if (isset($subsections[ $primary_registrant ]) |
|
229 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
230 | + ) { |
|
231 | + $subsections[ $primary_registrant ]->add_subsections( |
|
232 | + $copy_options, |
|
233 | + 'primary_registrant', |
|
234 | + false |
|
235 | + ); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + // Set the registration form template (default: one form per ticket details table). |
|
241 | + // We decide the template to used based on the number of forms. |
|
242 | + $this->_template = $this->reg_form_count > 1 |
|
243 | + ? SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php' |
|
244 | + : SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_single.template.php'; |
|
245 | + |
|
246 | + return new EE_Form_Section_Proper( |
|
247 | + array( |
|
248 | + 'name' => $this->reg_form_name(), |
|
249 | + 'html_id' => $this->reg_form_name(), |
|
250 | + 'subsections' => $subsections, |
|
251 | + 'layout_strategy' => new EE_Template_Layout( |
|
252 | + array( |
|
253 | + 'layout_template_file' => $this->_template, // layout_template |
|
254 | + 'template_args' => $template_args, |
|
255 | + ) |
|
256 | + ), |
|
257 | + ) |
|
258 | + ); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param EE_Registration $registration |
|
264 | + * @return EE_Form_Section_Base |
|
265 | + * @throws EE_Error |
|
266 | + * @throws InvalidArgumentException |
|
267 | + * @throws EntityNotFoundException |
|
268 | + * @throws InvalidDataTypeException |
|
269 | + * @throws InvalidInterfaceException |
|
270 | + * @throws ReflectionException |
|
271 | + */ |
|
272 | + private function _registrations_reg_form(EE_Registration $registration) |
|
273 | + { |
|
274 | + static $attendee_nmbr = 1; |
|
275 | + $form_args = array(); |
|
276 | + // verify that registration has valid event |
|
277 | + if ($registration->event() instanceof EE_Event) { |
|
278 | + $field_name = 'Event_Question_Group.' |
|
279 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
280 | + $registration->is_primary_registrant() |
|
281 | + ); |
|
282 | + $question_groups = $registration->event()->question_groups( |
|
283 | + apply_filters( |
|
284 | + // @codingStandardsIgnoreStart |
|
285 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
286 | + // @codingStandardsIgnoreEnd |
|
287 | + [ |
|
288 | + [ |
|
289 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
290 | + $field_name => true, |
|
291 | + ], |
|
292 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
293 | + ], |
|
294 | + $registration, |
|
295 | + $this |
|
296 | + ) |
|
297 | + ); |
|
298 | + if ($question_groups) { |
|
299 | + // array of params to pass to parent constructor |
|
300 | + $form_args = array( |
|
301 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
302 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
303 | + 'html_style' => $this->checkout->admin_request |
|
304 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
305 | + : '', |
|
306 | + 'subsections' => array(), |
|
307 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
308 | + array( |
|
309 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
310 | + 'legend_text' => sprintf( |
|
311 | + esc_html_x( |
|
312 | + 'Attendee %d', |
|
313 | + 'Attendee 123', |
|
314 | + 'event_espresso' |
|
315 | + ), |
|
316 | + $attendee_nmbr |
|
317 | + ), |
|
318 | + ) |
|
319 | + ), |
|
320 | + ); |
|
321 | + foreach ($question_groups as $question_group) { |
|
322 | + if ($question_group instanceof EE_Question_Group) { |
|
323 | + $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
324 | + $registration, |
|
325 | + $question_group |
|
326 | + ); |
|
327 | + } |
|
328 | + } |
|
329 | + // add hidden input |
|
330 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
331 | + $registration |
|
332 | + ); |
|
333 | + |
|
334 | + /** |
|
335 | + * @var $reg_config EE_Registration_Config |
|
336 | + */ |
|
337 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
338 | + |
|
339 | + // If we have question groups for additional attendees, then display the copy options |
|
340 | + $this->_print_copy_info = apply_filters( |
|
341 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
342 | + $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false, |
|
343 | + $attendee_nmbr |
|
344 | + ); |
|
345 | + |
|
346 | + if ($registration->is_primary_registrant()) { |
|
347 | + // generate hidden input |
|
348 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
349 | + $registration |
|
350 | + ); |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | + $attendee_nmbr++; |
|
355 | 355 | |
356 | - // Increment the reg forms number if form is valid. |
|
357 | - if (!empty($form_args)) { |
|
358 | - $this->reg_form_count++; |
|
359 | - } |
|
360 | - |
|
361 | - return ! empty($form_args) |
|
362 | - ? new EE_Form_Section_Proper($form_args) |
|
363 | - : new EE_Form_Section_HTML(); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * @param EE_Registration $registration |
|
369 | - * @param bool $additional_attendee_reg_info |
|
370 | - * @return EE_Form_Input_Base |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - private function _additional_attendee_reg_info_input( |
|
374 | - EE_Registration $registration, |
|
375 | - $additional_attendee_reg_info = true |
|
376 | - ) { |
|
377 | - // generate hidden input |
|
378 | - return new EE_Hidden_Input( |
|
379 | - array( |
|
380 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
381 | - 'default' => $additional_attendee_reg_info, |
|
382 | - ) |
|
383 | - ); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param EE_Registration $registration |
|
389 | - * @param EE_Question_Group $question_group |
|
390 | - * @return EE_Form_Section_Proper |
|
391 | - * @throws EE_Error |
|
392 | - * @throws InvalidArgumentException |
|
393 | - * @throws InvalidDataTypeException |
|
394 | - * @throws InvalidInterfaceException |
|
395 | - * @throws ReflectionException |
|
396 | - */ |
|
397 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
398 | - { |
|
399 | - // array of params to pass to parent constructor |
|
400 | - $form_args = array( |
|
401 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
402 | - 'html_class' => $this->checkout->admin_request |
|
403 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
404 | - : 'ee-reg-form-qstn-grp-dv', |
|
405 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
406 | - . $registration->ID() . '-lbl', |
|
407 | - 'subsections' => array( |
|
408 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
409 | - ), |
|
410 | - 'layout_strategy' => $this->checkout->admin_request |
|
411 | - ? new EE_Admin_Two_Column_Layout() |
|
412 | - : new EE_Div_Per_Section_Layout(), |
|
413 | - ); |
|
414 | - // where params |
|
415 | - $query_params = array('QST_deleted' => 0); |
|
416 | - // don't load admin only questions on the frontend |
|
417 | - if (! $this->checkout->admin_request) { |
|
418 | - $query_params['QST_admin_only'] = array('!=', true); |
|
419 | - } |
|
420 | - $questions = $question_group->get_many_related( |
|
421 | - 'Question', |
|
422 | - apply_filters( |
|
423 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
424 | - array( |
|
425 | - $query_params, |
|
426 | - 'order_by' => array( |
|
427 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
428 | - ), |
|
429 | - ), |
|
430 | - $question_group, |
|
431 | - $registration, |
|
432 | - $this |
|
433 | - ) |
|
434 | - ); |
|
435 | - // filter for additional content before questions |
|
436 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
437 | - apply_filters( |
|
438 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
439 | - '', |
|
440 | - $registration, |
|
441 | - $question_group, |
|
442 | - $this |
|
443 | - ) |
|
444 | - ); |
|
445 | - // loop thru questions |
|
446 | - foreach ($questions as $question) { |
|
447 | - if ($question instanceof EE_Question) { |
|
448 | - $identifier = $question->is_system_question() |
|
449 | - ? $question->system_ID() |
|
450 | - : $question->ID(); |
|
451 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
452 | - } |
|
453 | - } |
|
454 | - $form_args['subsections'] = apply_filters( |
|
455 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
456 | - $form_args['subsections'], |
|
457 | - $registration, |
|
458 | - $question_group, |
|
459 | - $this |
|
460 | - ); |
|
461 | - // filter for additional content after questions |
|
462 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
463 | - apply_filters( |
|
464 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
465 | - '', |
|
466 | - $registration, |
|
467 | - $question_group, |
|
468 | - $this |
|
469 | - ) |
|
470 | - ); |
|
471 | - // d($form_args); |
|
472 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
473 | - return apply_filters( |
|
474 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
475 | - $question_group_reg_form, |
|
476 | - $registration, |
|
477 | - $question_group, |
|
478 | - $this |
|
479 | - ); |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param EE_Question_Group $question_group |
|
485 | - * @return EE_Form_Section_HTML |
|
486 | - */ |
|
487 | - private function _question_group_header(EE_Question_Group $question_group) |
|
488 | - { |
|
489 | - $html = ''; |
|
490 | - // group_name |
|
491 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
492 | - if ($this->checkout->admin_request) { |
|
493 | - $html .= EEH_HTML::br(); |
|
494 | - $html .= EEH_HTML::h3( |
|
495 | - $question_group->name(), |
|
496 | - '', |
|
497 | - 'ee-reg-form-qstn-grp-title title', |
|
498 | - 'font-size: 1.3em; padding-left:0;' |
|
499 | - ); |
|
500 | - } else { |
|
501 | - $html .= EEH_HTML::h4( |
|
502 | - $question_group->name(), |
|
503 | - '', |
|
504 | - 'ee-reg-form-qstn-grp-title section-title' |
|
505 | - ); |
|
506 | - } |
|
507 | - } |
|
508 | - // group_desc |
|
509 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
510 | - $html .= EEH_HTML::p( |
|
511 | - $question_group->desc(), |
|
512 | - '', |
|
513 | - $this->checkout->admin_request |
|
514 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
515 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
516 | - ); |
|
517 | - } |
|
518 | - return new EE_Form_Section_HTML($html); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @return EE_Form_Section_Proper |
|
524 | - * @throws EE_Error |
|
525 | - * @throws InvalidArgumentException |
|
526 | - * @throws ReflectionException |
|
527 | - * @throws InvalidDataTypeException |
|
528 | - * @throws InvalidInterfaceException |
|
529 | - */ |
|
530 | - private function _copy_attendee_info_form() |
|
531 | - { |
|
532 | - // array of params to pass to parent constructor |
|
533 | - return new EE_Form_Section_Proper( |
|
534 | - array( |
|
535 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
536 | - 'layout_strategy' => new EE_Template_Layout( |
|
537 | - array( |
|
538 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
539 | - . $this->_slug |
|
540 | - . '/copy_attendee_info.template.php', |
|
541 | - 'begin_template_file' => null, |
|
542 | - 'input_template_file' => null, |
|
543 | - 'subsection_template_file' => null, |
|
544 | - 'end_template_file' => null, |
|
545 | - ) |
|
546 | - ), |
|
547 | - ) |
|
548 | - ); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * @return EE_Form_Section_HTML |
|
554 | - * @throws DomainException |
|
555 | - * @throws InvalidArgumentException |
|
556 | - * @throws InvalidDataTypeException |
|
557 | - * @throws InvalidInterfaceException |
|
558 | - */ |
|
559 | - private function _auto_copy_attendee_info() |
|
560 | - { |
|
561 | - return new EE_Form_Section_HTML( |
|
562 | - EEH_Template::locate_template( |
|
563 | - SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
564 | - apply_filters( |
|
565 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
566 | - array() |
|
567 | - ), |
|
568 | - true, |
|
569 | - true |
|
570 | - ) |
|
571 | - ); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * @return array |
|
577 | - * @throws EE_Error |
|
578 | - * @throws InvalidArgumentException |
|
579 | - * @throws ReflectionException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidInterfaceException |
|
582 | - */ |
|
583 | - private function _copy_attendee_info_inputs() |
|
584 | - { |
|
585 | - $copy_attendee_info_inputs = array(); |
|
586 | - $prev_ticket = null; |
|
587 | - // grab the saved registrations from the transaction |
|
588 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
589 | - foreach ($registrations as $registration) { |
|
590 | - // for all attendees other than the primary attendee |
|
591 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
592 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
593 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
594 | - $item_name = $registration->ticket()->name(); |
|
595 | - $item_name .= $registration->ticket()->description() !== '' |
|
596 | - ? ' - ' . $registration->ticket()->description() |
|
597 | - : ''; |
|
598 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
599 | - ) . ']' ] = |
|
600 | - new EE_Form_Section_HTML( |
|
601 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
602 | - ); |
|
603 | - $prev_ticket = $registration->ticket()->ID(); |
|
604 | - } |
|
605 | - |
|
606 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
607 | - new EE_Checkbox_Multi_Input( |
|
608 | - array( |
|
609 | - $registration->ID() => sprintf( |
|
610 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
611 | - $registration->count() |
|
612 | - ), |
|
613 | - ), |
|
614 | - array( |
|
615 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
616 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
617 | - 'display_html_label_text' => false, |
|
618 | - ) |
|
619 | - ); |
|
620 | - } |
|
621 | - } |
|
622 | - return $copy_attendee_info_inputs; |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * @param EE_Registration $registration |
|
628 | - * @return EE_Form_Input_Base |
|
629 | - * @throws EE_Error |
|
630 | - */ |
|
631 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
632 | - { |
|
633 | - // generate hidden input |
|
634 | - return new EE_Hidden_Input( |
|
635 | - array( |
|
636 | - 'html_id' => 'primary_registrant', |
|
637 | - 'default' => $registration->reg_url_link(), |
|
638 | - ) |
|
639 | - ); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * @param EE_Registration $registration |
|
645 | - * @param EE_Question $question |
|
646 | - * @return EE_Form_Input_Base |
|
647 | - * @throws EE_Error |
|
648 | - * @throws InvalidArgumentException |
|
649 | - * @throws InvalidDataTypeException |
|
650 | - * @throws InvalidInterfaceException |
|
651 | - * @throws ReflectionException |
|
652 | - */ |
|
653 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
654 | - { |
|
655 | - |
|
656 | - // if this question was for an attendee detail, then check for that answer |
|
657 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
658 | - $registration, |
|
659 | - $question->system_ID() |
|
660 | - ); |
|
661 | - $answer = $answer_value === null |
|
662 | - ? EEM_Answer::instance()->get_one( |
|
663 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
664 | - ) |
|
665 | - : null; |
|
666 | - // if NOT returning to edit an existing registration |
|
667 | - // OR if this question is for an attendee property |
|
668 | - // OR we still don't have an EE_Answer object |
|
669 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
670 | - // create an EE_Answer object for storing everything in |
|
671 | - $answer = EE_Answer::new_instance( |
|
672 | - array( |
|
673 | - 'QST_ID' => $question->ID(), |
|
674 | - 'REG_ID' => $registration->ID(), |
|
675 | - ) |
|
676 | - ); |
|
677 | - } |
|
678 | - // verify instance |
|
679 | - if ($answer instanceof EE_Answer) { |
|
680 | - if (! empty($answer_value)) { |
|
681 | - $answer->set('ANS_value', $answer_value); |
|
682 | - } |
|
683 | - $answer->cache('Question', $question); |
|
684 | - // remember system ID had a bug where sometimes it could be null |
|
685 | - $answer_cache_id = $question->is_system_question() |
|
686 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
687 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
688 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
689 | - } |
|
690 | - return $this->_generate_question_input($registration, $question, $answer); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * @param EE_Registration $registration |
|
696 | - * @param EE_Question $question |
|
697 | - * @param $answer |
|
698 | - * @return EE_Form_Input_Base |
|
699 | - * @throws EE_Error |
|
700 | - * @throws InvalidArgumentException |
|
701 | - * @throws ReflectionException |
|
702 | - * @throws InvalidDataTypeException |
|
703 | - * @throws InvalidInterfaceException |
|
704 | - */ |
|
705 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
706 | - { |
|
707 | - $identifier = $question->is_system_question() |
|
708 | - ? $question->system_ID() |
|
709 | - : $question->ID(); |
|
710 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
711 | - add_filter( |
|
712 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | - array($this, 'use_cached_countries_for_form_input'), |
|
714 | - 10, |
|
715 | - 4 |
|
716 | - ); |
|
717 | - add_filter( |
|
718 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
719 | - array($this, 'use_cached_states_for_form_input'), |
|
720 | - 10, |
|
721 | - 4 |
|
722 | - ); |
|
723 | - $input_constructor_args = array( |
|
724 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
725 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
726 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
727 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
728 | - 'html_label_class' => 'ee-reg-qstn', |
|
729 | - ); |
|
730 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
731 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
732 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
733 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
734 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
735 | - } |
|
736 | - $form_input = $question->generate_form_input( |
|
737 | - $registration, |
|
738 | - $answer, |
|
739 | - $input_constructor_args |
|
740 | - ); |
|
741 | - remove_filter( |
|
742 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
743 | - array($this, 'use_cached_countries_for_form_input') |
|
744 | - ); |
|
745 | - remove_filter( |
|
746 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
747 | - array($this, 'use_cached_states_for_form_input') |
|
748 | - ); |
|
749 | - return $form_input; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Gets the list of countries for the form input |
|
755 | - * |
|
756 | - * @param array|null $countries_list |
|
757 | - * @param EE_Question $question |
|
758 | - * @param EE_Registration $registration |
|
759 | - * @param EE_Answer $answer |
|
760 | - * @return array 2d keys are country IDs, values are their names |
|
761 | - * @throws EE_Error |
|
762 | - * @throws InvalidArgumentException |
|
763 | - * @throws InvalidDataTypeException |
|
764 | - * @throws InvalidInterfaceException |
|
765 | - * @throws ReflectionException |
|
766 | - */ |
|
767 | - public function use_cached_countries_for_form_input( |
|
768 | - $countries_list, |
|
769 | - EE_Question $question = null, |
|
770 | - EE_Registration $registration = null, |
|
771 | - EE_Answer $answer = null |
|
772 | - ) { |
|
773 | - $country_options = array('' => ''); |
|
774 | - // get possibly cached list of countries |
|
775 | - $countries = $this->checkout->action === 'process_reg_step' |
|
776 | - ? EEM_Country::instance()->get_all_countries() |
|
777 | - : EEM_Country::instance()->get_all_active_countries(); |
|
778 | - if (! empty($countries)) { |
|
779 | - foreach ($countries as $country) { |
|
780 | - if ($country instanceof EE_Country) { |
|
781 | - $country_options[ $country->ID() ] = $country->name(); |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
786 | - $answer = EEM_Answer::instance()->get_one( |
|
787 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
788 | - ); |
|
789 | - } else { |
|
790 | - $answer = EE_Answer::new_instance(); |
|
791 | - } |
|
792 | - $country_options = apply_filters( |
|
793 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
794 | - $country_options, |
|
795 | - $this, |
|
796 | - $registration, |
|
797 | - $question, |
|
798 | - $answer |
|
799 | - ); |
|
800 | - return $country_options; |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * Gets the list of states for the form input |
|
806 | - * |
|
807 | - * @param array|null $states_list |
|
808 | - * @param EE_Question $question |
|
809 | - * @param EE_Registration $registration |
|
810 | - * @param EE_Answer $answer |
|
811 | - * @return array 2d keys are state IDs, values are their names |
|
812 | - * @throws EE_Error |
|
813 | - * @throws InvalidArgumentException |
|
814 | - * @throws InvalidDataTypeException |
|
815 | - * @throws InvalidInterfaceException |
|
816 | - * @throws ReflectionException |
|
817 | - */ |
|
818 | - public function use_cached_states_for_form_input( |
|
819 | - $states_list, |
|
820 | - EE_Question $question = null, |
|
821 | - EE_Registration $registration = null, |
|
822 | - EE_Answer $answer = null |
|
823 | - ) { |
|
824 | - $state_options = array('' => array('' => '')); |
|
825 | - $states = $this->checkout->action === 'process_reg_step' |
|
826 | - ? EEM_State::instance()->get_all_states() |
|
827 | - : EEM_State::instance()->get_all_active_states(); |
|
828 | - if (! empty($states)) { |
|
829 | - foreach ($states as $state) { |
|
830 | - if ($state instanceof EE_State) { |
|
831 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
832 | - } |
|
833 | - } |
|
834 | - } |
|
835 | - $state_options = apply_filters( |
|
836 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
837 | - $state_options, |
|
838 | - $this, |
|
839 | - $registration, |
|
840 | - $question, |
|
841 | - $answer |
|
842 | - ); |
|
843 | - return $state_options; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - /********************************************************************************************************/ |
|
848 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
849 | - /********************************************************************************************************/ |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * @return bool |
|
854 | - * @throws EE_Error |
|
855 | - * @throws InvalidArgumentException |
|
856 | - * @throws ReflectionException |
|
857 | - * @throws RuntimeException |
|
858 | - * @throws InvalidDataTypeException |
|
859 | - * @throws InvalidInterfaceException |
|
860 | - */ |
|
861 | - public function process_reg_step() |
|
862 | - { |
|
863 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
864 | - // grab validated data from form |
|
865 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
866 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
867 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
868 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
869 | - if (empty($valid_data)) { |
|
870 | - EE_Error::add_error( |
|
871 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
872 | - __FILE__, |
|
873 | - __FUNCTION__, |
|
874 | - __LINE__ |
|
875 | - ); |
|
876 | - return false; |
|
877 | - } |
|
878 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
879 | - EE_Error::add_error( |
|
880 | - esc_html__( |
|
881 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
882 | - 'event_espresso' |
|
883 | - ), |
|
884 | - __FILE__, |
|
885 | - __FUNCTION__, |
|
886 | - __LINE__ |
|
887 | - ); |
|
888 | - return false; |
|
889 | - } |
|
890 | - // get cached registrations |
|
891 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
892 | - // verify we got the goods |
|
893 | - if (empty($registrations)) { |
|
894 | - // combine the old translated string with a new one, in order to not break translations |
|
895 | - $error_message = esc_html__( |
|
896 | - 'Your form data could not be applied to any valid registrations.', |
|
897 | - 'event_espresso' |
|
898 | - ) |
|
899 | - . sprintf( |
|
900 | - esc_html_x( |
|
901 | - '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
902 | - '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
903 | - 'event_espresso' |
|
904 | - ), |
|
905 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
906 | - '</a>', |
|
907 | - '<br />' |
|
908 | - ); |
|
909 | - EE_Error::add_error( |
|
910 | - $error_message, |
|
911 | - __FILE__, |
|
912 | - __FUNCTION__, |
|
913 | - __LINE__ |
|
914 | - ); |
|
915 | - return false; |
|
916 | - } |
|
917 | - // extract attendee info from form data and save to model objects |
|
918 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
919 | - // if first pass thru SPCO, |
|
920 | - // then let's check processed registrations against the total number of tickets in the cart |
|
921 | - if ($registrations_processed === false) { |
|
922 | - // but return immediately if the previous step exited early due to errors |
|
923 | - return false; |
|
924 | - } |
|
925 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
926 | - // generate a correctly translated string for all possible singular/plural combinations |
|
927 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
928 | - $error_msg = sprintf( |
|
929 | - esc_html_x( |
|
930 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
931 | - 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
932 | - 'event_espresso' |
|
933 | - ), |
|
934 | - $this->checkout->total_ticket_count, |
|
935 | - $registrations_processed |
|
936 | - ); |
|
937 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
938 | - $error_msg = sprintf( |
|
939 | - esc_html_x( |
|
940 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
941 | - 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
942 | - 'event_espresso' |
|
943 | - ), |
|
944 | - $this->checkout->total_ticket_count, |
|
945 | - $registrations_processed |
|
946 | - ); |
|
947 | - } else { |
|
948 | - $error_msg = sprintf( |
|
949 | - esc_html__( |
|
950 | - 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
951 | - 'event_espresso' |
|
952 | - ), |
|
953 | - $this->checkout->total_ticket_count, |
|
954 | - $registrations_processed |
|
955 | - ); |
|
956 | - } |
|
957 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
958 | - return false; |
|
959 | - } |
|
960 | - // mark this reg step as completed |
|
961 | - $this->set_completed(); |
|
962 | - $this->_set_success_message( |
|
963 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
964 | - ); |
|
965 | - // do action in case a plugin wants to do something with the data submitted in step 1. |
|
966 | - // passes EE_Single_Page_Checkout, and it's posted data |
|
967 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
968 | - return true; |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * _process_registrations |
|
974 | - * |
|
975 | - * @param EE_Registration[] $registrations |
|
976 | - * @param array[][] $valid_data |
|
977 | - * @return bool|int |
|
978 | - * @throws EntityNotFoundException |
|
979 | - * @throws EE_Error |
|
980 | - * @throws InvalidArgumentException |
|
981 | - * @throws ReflectionException |
|
982 | - * @throws RuntimeException |
|
983 | - * @throws InvalidDataTypeException |
|
984 | - * @throws InvalidInterfaceException |
|
985 | - */ |
|
986 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
987 | - { |
|
988 | - // load resources and set some defaults |
|
989 | - EE_Registry::instance()->load_model('Attendee'); |
|
990 | - // holder for primary registrant attendee object |
|
991 | - $this->checkout->primary_attendee_obj = null; |
|
992 | - // array for tracking reg form data for the primary registrant |
|
993 | - $primary_registrant = array( |
|
994 | - 'line_item_id' => null, |
|
995 | - ); |
|
996 | - $copy_primary = false; |
|
997 | - // reg form sections that do not contain inputs |
|
998 | - $non_input_form_sections = array( |
|
999 | - 'primary_registrant', |
|
1000 | - 'additional_attendee_reg_info', |
|
1001 | - 'spco_copy_attendee_chk', |
|
1002 | - ); |
|
1003 | - // attendee counter |
|
1004 | - $att_nmbr = 0; |
|
1005 | - // grab the saved registrations from the transaction |
|
1006 | - foreach ($registrations as $registration) { |
|
1007 | - // verify EE_Registration object |
|
1008 | - if (! $registration instanceof EE_Registration) { |
|
1009 | - EE_Error::add_error( |
|
1010 | - esc_html__( |
|
1011 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
1012 | - 'event_espresso' |
|
1013 | - ), |
|
1014 | - __FILE__, |
|
1015 | - __FUNCTION__, |
|
1016 | - __LINE__ |
|
1017 | - ); |
|
1018 | - return false; |
|
1019 | - } |
|
1020 | - /** @var string $reg_url_link */ |
|
1021 | - $reg_url_link = $registration->reg_url_link(); |
|
1022 | - // reg_url_link exists ? |
|
1023 | - if (! empty($reg_url_link)) { |
|
1024 | - // should this registration be processed during this visit ? |
|
1025 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
1026 | - // if NOT revisiting, then let's save the registration now, |
|
1027 | - // so that we have a REG_ID to use when generating other objects |
|
1028 | - if (! $this->checkout->revisit) { |
|
1029 | - $registration->save(); |
|
1030 | - } |
|
1031 | - /** |
|
1032 | - * This allows plugins to trigger a fail on processing of a |
|
1033 | - * registration for any conditions they may have for it to pass. |
|
1034 | - * |
|
1035 | - * @var bool if true is returned by the plugin then the |
|
1036 | - * registration processing is halted. |
|
1037 | - */ |
|
1038 | - if (apply_filters( |
|
1039 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1040 | - false, |
|
1041 | - $att_nmbr, |
|
1042 | - $registration, |
|
1043 | - $registrations, |
|
1044 | - $valid_data, |
|
1045 | - $this |
|
1046 | - )) { |
|
1047 | - return false; |
|
1048 | - } |
|
1049 | - |
|
1050 | - // Houston, we have a registration! |
|
1051 | - $att_nmbr++; |
|
1052 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
1053 | - // grab any existing related answer objects |
|
1054 | - $this->_registration_answers = $registration->answers(); |
|
1055 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1056 | - if (isset($valid_data[ $reg_url_link ])) { |
|
1057 | - // do we need to copy basic info from primary attendee ? |
|
1058 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1059 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1060 | - // filter form input data for this registration |
|
1061 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1062 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1063 | - $valid_data[ $reg_url_link ] |
|
1064 | - ); |
|
1065 | - if (isset($valid_data['primary_attendee'])) { |
|
1066 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1067 | - ? $valid_data['primary_attendee'] |
|
1068 | - : false; |
|
1069 | - unset($valid_data['primary_attendee']); |
|
1070 | - } |
|
1071 | - // now loop through our array of valid post data && process attendee reg forms |
|
1072 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1073 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1074 | - foreach ($form_inputs as $form_input => $input_value) { |
|
1075 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1076 | - // check for critical inputs |
|
1077 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1078 | - $form_input, |
|
1079 | - $input_value |
|
1080 | - ) |
|
1081 | - ) { |
|
1082 | - return false; |
|
1083 | - } |
|
1084 | - // store a bit of data about the primary attendee |
|
1085 | - if ($att_nmbr === 1 |
|
1086 | - && ! empty($input_value) |
|
1087 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
1088 | - ) { |
|
1089 | - $primary_registrant[ $form_input ] = $input_value; |
|
1090 | - } elseif ($copy_primary |
|
1091 | - && $input_value === null |
|
1092 | - && isset($primary_registrant[ $form_input ]) |
|
1093 | - ) { |
|
1094 | - $input_value = $primary_registrant[ $form_input ]; |
|
1095 | - } |
|
1096 | - // now attempt to save the input data |
|
1097 | - if (! $this->_save_registration_form_input( |
|
1098 | - $registration, |
|
1099 | - $form_input, |
|
1100 | - $input_value |
|
1101 | - ) |
|
1102 | - ) { |
|
1103 | - EE_Error::add_error( |
|
1104 | - sprintf( |
|
1105 | - esc_html_x( |
|
1106 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1107 | - 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1108 | - 'event_espresso' |
|
1109 | - ), |
|
1110 | - $form_input, |
|
1111 | - $input_value |
|
1112 | - ), |
|
1113 | - __FILE__, |
|
1114 | - __FUNCTION__, |
|
1115 | - __LINE__ |
|
1116 | - ); |
|
1117 | - return false; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - } |
|
1121 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1122 | - } |
|
1123 | - // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1124 | - // this registration does not require additional attendee information ? |
|
1125 | - if ($copy_primary |
|
1126 | - && $att_nmbr > 1 |
|
1127 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1128 | - ) { |
|
1129 | - // just copy the primary registrant |
|
1130 | - $attendee = $this->checkout->primary_attendee_obj; |
|
1131 | - } else { |
|
1132 | - // ensure critical details are set for additional attendees |
|
1133 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1134 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1135 | - $this->_attendee_data[ $reg_url_link ] |
|
1136 | - ) |
|
1137 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1138 | - // execute create attendee command (which may return an existing attendee) |
|
1139 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
1140 | - new CreateAttendeeCommand( |
|
1141 | - $this->_attendee_data[ $reg_url_link ], |
|
1142 | - $registration |
|
1143 | - ) |
|
1144 | - ); |
|
1145 | - // who's #1 ? |
|
1146 | - if ($att_nmbr === 1) { |
|
1147 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1148 | - } |
|
1149 | - } |
|
1150 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1151 | - // add relation to registration, set attendee ID, and cache attendee |
|
1152 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
1153 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1154 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1155 | - EE_Error::add_error( |
|
1156 | - sprintf( |
|
1157 | - esc_html_x( |
|
1158 | - 'Registration %s has an invalid or missing Attendee object.', |
|
1159 | - 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1160 | - 'event_espresso' |
|
1161 | - ), |
|
1162 | - $reg_url_link |
|
1163 | - ), |
|
1164 | - __FILE__, |
|
1165 | - __FUNCTION__, |
|
1166 | - __LINE__ |
|
1167 | - ); |
|
1168 | - return false; |
|
1169 | - } |
|
1170 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1171 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1172 | - // at this point, we should have enough details about the registrant to consider the registration |
|
1173 | - // NOT incomplete |
|
1174 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1175 | - $registration, |
|
1176 | - false, |
|
1177 | - new Context( |
|
1178 | - 'spco_reg_step_attendee_information_process_registrations', |
|
1179 | - esc_html__( |
|
1180 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1181 | - 'event_espresso' |
|
1182 | - ) |
|
1183 | - ) |
|
1184 | - ); |
|
1185 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1186 | - // abandoned |
|
1187 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1188 | - // if we've gotten this far, then let's save what we have |
|
1189 | - $registration->save(); |
|
1190 | - // add relation between TXN and registration |
|
1191 | - $this->_associate_registration_with_transaction($registration); |
|
1192 | - } |
|
1193 | - } else { |
|
1194 | - EE_Error::add_error( |
|
1195 | - esc_html__( |
|
1196 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1197 | - 'event_espresso' |
|
1198 | - ), |
|
1199 | - __FILE__, |
|
1200 | - __FUNCTION__, |
|
1201 | - __LINE__ |
|
1202 | - ); |
|
1203 | - // remove malformed data |
|
1204 | - unset($valid_data[ $reg_url_link ]); |
|
1205 | - return false; |
|
1206 | - } |
|
1207 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1208 | - return $att_nmbr; |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * _save_registration_form_input |
|
1214 | - * |
|
1215 | - * @param EE_Registration $registration |
|
1216 | - * @param string $form_input |
|
1217 | - * @param string $input_value |
|
1218 | - * @return bool |
|
1219 | - * @throws EE_Error |
|
1220 | - * @throws InvalidArgumentException |
|
1221 | - * @throws InvalidDataTypeException |
|
1222 | - * @throws InvalidInterfaceException |
|
1223 | - * @throws ReflectionException |
|
1224 | - */ |
|
1225 | - private function _save_registration_form_input( |
|
1226 | - EE_Registration $registration, |
|
1227 | - $form_input = '', |
|
1228 | - $input_value = '' |
|
1229 | - ) { |
|
1230 | - // If email_confirm is sent it's not saved |
|
1231 | - if ((string) $form_input === 'email_confirm') { |
|
1232 | - return true; |
|
1233 | - } |
|
1234 | - |
|
1235 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1236 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1237 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1238 | - // allow for plugins to hook in and do their own processing of the form input. |
|
1239 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1240 | - if (apply_filters( |
|
1241 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1242 | - false, |
|
1243 | - $registration, |
|
1244 | - $form_input, |
|
1245 | - $input_value, |
|
1246 | - $this |
|
1247 | - )) { |
|
1248 | - return true; |
|
1249 | - } |
|
1250 | - /* |
|
356 | + // Increment the reg forms number if form is valid. |
|
357 | + if (!empty($form_args)) { |
|
358 | + $this->reg_form_count++; |
|
359 | + } |
|
360 | + |
|
361 | + return ! empty($form_args) |
|
362 | + ? new EE_Form_Section_Proper($form_args) |
|
363 | + : new EE_Form_Section_HTML(); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * @param EE_Registration $registration |
|
369 | + * @param bool $additional_attendee_reg_info |
|
370 | + * @return EE_Form_Input_Base |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + private function _additional_attendee_reg_info_input( |
|
374 | + EE_Registration $registration, |
|
375 | + $additional_attendee_reg_info = true |
|
376 | + ) { |
|
377 | + // generate hidden input |
|
378 | + return new EE_Hidden_Input( |
|
379 | + array( |
|
380 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
381 | + 'default' => $additional_attendee_reg_info, |
|
382 | + ) |
|
383 | + ); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param EE_Registration $registration |
|
389 | + * @param EE_Question_Group $question_group |
|
390 | + * @return EE_Form_Section_Proper |
|
391 | + * @throws EE_Error |
|
392 | + * @throws InvalidArgumentException |
|
393 | + * @throws InvalidDataTypeException |
|
394 | + * @throws InvalidInterfaceException |
|
395 | + * @throws ReflectionException |
|
396 | + */ |
|
397 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
398 | + { |
|
399 | + // array of params to pass to parent constructor |
|
400 | + $form_args = array( |
|
401 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
402 | + 'html_class' => $this->checkout->admin_request |
|
403 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
404 | + : 'ee-reg-form-qstn-grp-dv', |
|
405 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
406 | + . $registration->ID() . '-lbl', |
|
407 | + 'subsections' => array( |
|
408 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
409 | + ), |
|
410 | + 'layout_strategy' => $this->checkout->admin_request |
|
411 | + ? new EE_Admin_Two_Column_Layout() |
|
412 | + : new EE_Div_Per_Section_Layout(), |
|
413 | + ); |
|
414 | + // where params |
|
415 | + $query_params = array('QST_deleted' => 0); |
|
416 | + // don't load admin only questions on the frontend |
|
417 | + if (! $this->checkout->admin_request) { |
|
418 | + $query_params['QST_admin_only'] = array('!=', true); |
|
419 | + } |
|
420 | + $questions = $question_group->get_many_related( |
|
421 | + 'Question', |
|
422 | + apply_filters( |
|
423 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
424 | + array( |
|
425 | + $query_params, |
|
426 | + 'order_by' => array( |
|
427 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
428 | + ), |
|
429 | + ), |
|
430 | + $question_group, |
|
431 | + $registration, |
|
432 | + $this |
|
433 | + ) |
|
434 | + ); |
|
435 | + // filter for additional content before questions |
|
436 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
437 | + apply_filters( |
|
438 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
439 | + '', |
|
440 | + $registration, |
|
441 | + $question_group, |
|
442 | + $this |
|
443 | + ) |
|
444 | + ); |
|
445 | + // loop thru questions |
|
446 | + foreach ($questions as $question) { |
|
447 | + if ($question instanceof EE_Question) { |
|
448 | + $identifier = $question->is_system_question() |
|
449 | + ? $question->system_ID() |
|
450 | + : $question->ID(); |
|
451 | + $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
452 | + } |
|
453 | + } |
|
454 | + $form_args['subsections'] = apply_filters( |
|
455 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
456 | + $form_args['subsections'], |
|
457 | + $registration, |
|
458 | + $question_group, |
|
459 | + $this |
|
460 | + ); |
|
461 | + // filter for additional content after questions |
|
462 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
463 | + apply_filters( |
|
464 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
465 | + '', |
|
466 | + $registration, |
|
467 | + $question_group, |
|
468 | + $this |
|
469 | + ) |
|
470 | + ); |
|
471 | + // d($form_args); |
|
472 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
473 | + return apply_filters( |
|
474 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
475 | + $question_group_reg_form, |
|
476 | + $registration, |
|
477 | + $question_group, |
|
478 | + $this |
|
479 | + ); |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param EE_Question_Group $question_group |
|
485 | + * @return EE_Form_Section_HTML |
|
486 | + */ |
|
487 | + private function _question_group_header(EE_Question_Group $question_group) |
|
488 | + { |
|
489 | + $html = ''; |
|
490 | + // group_name |
|
491 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
492 | + if ($this->checkout->admin_request) { |
|
493 | + $html .= EEH_HTML::br(); |
|
494 | + $html .= EEH_HTML::h3( |
|
495 | + $question_group->name(), |
|
496 | + '', |
|
497 | + 'ee-reg-form-qstn-grp-title title', |
|
498 | + 'font-size: 1.3em; padding-left:0;' |
|
499 | + ); |
|
500 | + } else { |
|
501 | + $html .= EEH_HTML::h4( |
|
502 | + $question_group->name(), |
|
503 | + '', |
|
504 | + 'ee-reg-form-qstn-grp-title section-title' |
|
505 | + ); |
|
506 | + } |
|
507 | + } |
|
508 | + // group_desc |
|
509 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
510 | + $html .= EEH_HTML::p( |
|
511 | + $question_group->desc(), |
|
512 | + '', |
|
513 | + $this->checkout->admin_request |
|
514 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
515 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
516 | + ); |
|
517 | + } |
|
518 | + return new EE_Form_Section_HTML($html); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @return EE_Form_Section_Proper |
|
524 | + * @throws EE_Error |
|
525 | + * @throws InvalidArgumentException |
|
526 | + * @throws ReflectionException |
|
527 | + * @throws InvalidDataTypeException |
|
528 | + * @throws InvalidInterfaceException |
|
529 | + */ |
|
530 | + private function _copy_attendee_info_form() |
|
531 | + { |
|
532 | + // array of params to pass to parent constructor |
|
533 | + return new EE_Form_Section_Proper( |
|
534 | + array( |
|
535 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
536 | + 'layout_strategy' => new EE_Template_Layout( |
|
537 | + array( |
|
538 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
539 | + . $this->_slug |
|
540 | + . '/copy_attendee_info.template.php', |
|
541 | + 'begin_template_file' => null, |
|
542 | + 'input_template_file' => null, |
|
543 | + 'subsection_template_file' => null, |
|
544 | + 'end_template_file' => null, |
|
545 | + ) |
|
546 | + ), |
|
547 | + ) |
|
548 | + ); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * @return EE_Form_Section_HTML |
|
554 | + * @throws DomainException |
|
555 | + * @throws InvalidArgumentException |
|
556 | + * @throws InvalidDataTypeException |
|
557 | + * @throws InvalidInterfaceException |
|
558 | + */ |
|
559 | + private function _auto_copy_attendee_info() |
|
560 | + { |
|
561 | + return new EE_Form_Section_HTML( |
|
562 | + EEH_Template::locate_template( |
|
563 | + SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
564 | + apply_filters( |
|
565 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
566 | + array() |
|
567 | + ), |
|
568 | + true, |
|
569 | + true |
|
570 | + ) |
|
571 | + ); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * @return array |
|
577 | + * @throws EE_Error |
|
578 | + * @throws InvalidArgumentException |
|
579 | + * @throws ReflectionException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidInterfaceException |
|
582 | + */ |
|
583 | + private function _copy_attendee_info_inputs() |
|
584 | + { |
|
585 | + $copy_attendee_info_inputs = array(); |
|
586 | + $prev_ticket = null; |
|
587 | + // grab the saved registrations from the transaction |
|
588 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
589 | + foreach ($registrations as $registration) { |
|
590 | + // for all attendees other than the primary attendee |
|
591 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
592 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
593 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
594 | + $item_name = $registration->ticket()->name(); |
|
595 | + $item_name .= $registration->ticket()->description() !== '' |
|
596 | + ? ' - ' . $registration->ticket()->description() |
|
597 | + : ''; |
|
598 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
599 | + ) . ']' ] = |
|
600 | + new EE_Form_Section_HTML( |
|
601 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
602 | + ); |
|
603 | + $prev_ticket = $registration->ticket()->ID(); |
|
604 | + } |
|
605 | + |
|
606 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
607 | + new EE_Checkbox_Multi_Input( |
|
608 | + array( |
|
609 | + $registration->ID() => sprintf( |
|
610 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
611 | + $registration->count() |
|
612 | + ), |
|
613 | + ), |
|
614 | + array( |
|
615 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
616 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
617 | + 'display_html_label_text' => false, |
|
618 | + ) |
|
619 | + ); |
|
620 | + } |
|
621 | + } |
|
622 | + return $copy_attendee_info_inputs; |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * @param EE_Registration $registration |
|
628 | + * @return EE_Form_Input_Base |
|
629 | + * @throws EE_Error |
|
630 | + */ |
|
631 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
632 | + { |
|
633 | + // generate hidden input |
|
634 | + return new EE_Hidden_Input( |
|
635 | + array( |
|
636 | + 'html_id' => 'primary_registrant', |
|
637 | + 'default' => $registration->reg_url_link(), |
|
638 | + ) |
|
639 | + ); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * @param EE_Registration $registration |
|
645 | + * @param EE_Question $question |
|
646 | + * @return EE_Form_Input_Base |
|
647 | + * @throws EE_Error |
|
648 | + * @throws InvalidArgumentException |
|
649 | + * @throws InvalidDataTypeException |
|
650 | + * @throws InvalidInterfaceException |
|
651 | + * @throws ReflectionException |
|
652 | + */ |
|
653 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
654 | + { |
|
655 | + |
|
656 | + // if this question was for an attendee detail, then check for that answer |
|
657 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
658 | + $registration, |
|
659 | + $question->system_ID() |
|
660 | + ); |
|
661 | + $answer = $answer_value === null |
|
662 | + ? EEM_Answer::instance()->get_one( |
|
663 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
664 | + ) |
|
665 | + : null; |
|
666 | + // if NOT returning to edit an existing registration |
|
667 | + // OR if this question is for an attendee property |
|
668 | + // OR we still don't have an EE_Answer object |
|
669 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
670 | + // create an EE_Answer object for storing everything in |
|
671 | + $answer = EE_Answer::new_instance( |
|
672 | + array( |
|
673 | + 'QST_ID' => $question->ID(), |
|
674 | + 'REG_ID' => $registration->ID(), |
|
675 | + ) |
|
676 | + ); |
|
677 | + } |
|
678 | + // verify instance |
|
679 | + if ($answer instanceof EE_Answer) { |
|
680 | + if (! empty($answer_value)) { |
|
681 | + $answer->set('ANS_value', $answer_value); |
|
682 | + } |
|
683 | + $answer->cache('Question', $question); |
|
684 | + // remember system ID had a bug where sometimes it could be null |
|
685 | + $answer_cache_id = $question->is_system_question() |
|
686 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
687 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
688 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
689 | + } |
|
690 | + return $this->_generate_question_input($registration, $question, $answer); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * @param EE_Registration $registration |
|
696 | + * @param EE_Question $question |
|
697 | + * @param $answer |
|
698 | + * @return EE_Form_Input_Base |
|
699 | + * @throws EE_Error |
|
700 | + * @throws InvalidArgumentException |
|
701 | + * @throws ReflectionException |
|
702 | + * @throws InvalidDataTypeException |
|
703 | + * @throws InvalidInterfaceException |
|
704 | + */ |
|
705 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
706 | + { |
|
707 | + $identifier = $question->is_system_question() |
|
708 | + ? $question->system_ID() |
|
709 | + : $question->ID(); |
|
710 | + $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
711 | + add_filter( |
|
712 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | + array($this, 'use_cached_countries_for_form_input'), |
|
714 | + 10, |
|
715 | + 4 |
|
716 | + ); |
|
717 | + add_filter( |
|
718 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
719 | + array($this, 'use_cached_states_for_form_input'), |
|
720 | + 10, |
|
721 | + 4 |
|
722 | + ); |
|
723 | + $input_constructor_args = array( |
|
724 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
725 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
726 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
727 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
728 | + 'html_label_class' => 'ee-reg-qstn', |
|
729 | + ); |
|
730 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
731 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
732 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
733 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
734 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
735 | + } |
|
736 | + $form_input = $question->generate_form_input( |
|
737 | + $registration, |
|
738 | + $answer, |
|
739 | + $input_constructor_args |
|
740 | + ); |
|
741 | + remove_filter( |
|
742 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
743 | + array($this, 'use_cached_countries_for_form_input') |
|
744 | + ); |
|
745 | + remove_filter( |
|
746 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
747 | + array($this, 'use_cached_states_for_form_input') |
|
748 | + ); |
|
749 | + return $form_input; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Gets the list of countries for the form input |
|
755 | + * |
|
756 | + * @param array|null $countries_list |
|
757 | + * @param EE_Question $question |
|
758 | + * @param EE_Registration $registration |
|
759 | + * @param EE_Answer $answer |
|
760 | + * @return array 2d keys are country IDs, values are their names |
|
761 | + * @throws EE_Error |
|
762 | + * @throws InvalidArgumentException |
|
763 | + * @throws InvalidDataTypeException |
|
764 | + * @throws InvalidInterfaceException |
|
765 | + * @throws ReflectionException |
|
766 | + */ |
|
767 | + public function use_cached_countries_for_form_input( |
|
768 | + $countries_list, |
|
769 | + EE_Question $question = null, |
|
770 | + EE_Registration $registration = null, |
|
771 | + EE_Answer $answer = null |
|
772 | + ) { |
|
773 | + $country_options = array('' => ''); |
|
774 | + // get possibly cached list of countries |
|
775 | + $countries = $this->checkout->action === 'process_reg_step' |
|
776 | + ? EEM_Country::instance()->get_all_countries() |
|
777 | + : EEM_Country::instance()->get_all_active_countries(); |
|
778 | + if (! empty($countries)) { |
|
779 | + foreach ($countries as $country) { |
|
780 | + if ($country instanceof EE_Country) { |
|
781 | + $country_options[ $country->ID() ] = $country->name(); |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
786 | + $answer = EEM_Answer::instance()->get_one( |
|
787 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
788 | + ); |
|
789 | + } else { |
|
790 | + $answer = EE_Answer::new_instance(); |
|
791 | + } |
|
792 | + $country_options = apply_filters( |
|
793 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
794 | + $country_options, |
|
795 | + $this, |
|
796 | + $registration, |
|
797 | + $question, |
|
798 | + $answer |
|
799 | + ); |
|
800 | + return $country_options; |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * Gets the list of states for the form input |
|
806 | + * |
|
807 | + * @param array|null $states_list |
|
808 | + * @param EE_Question $question |
|
809 | + * @param EE_Registration $registration |
|
810 | + * @param EE_Answer $answer |
|
811 | + * @return array 2d keys are state IDs, values are their names |
|
812 | + * @throws EE_Error |
|
813 | + * @throws InvalidArgumentException |
|
814 | + * @throws InvalidDataTypeException |
|
815 | + * @throws InvalidInterfaceException |
|
816 | + * @throws ReflectionException |
|
817 | + */ |
|
818 | + public function use_cached_states_for_form_input( |
|
819 | + $states_list, |
|
820 | + EE_Question $question = null, |
|
821 | + EE_Registration $registration = null, |
|
822 | + EE_Answer $answer = null |
|
823 | + ) { |
|
824 | + $state_options = array('' => array('' => '')); |
|
825 | + $states = $this->checkout->action === 'process_reg_step' |
|
826 | + ? EEM_State::instance()->get_all_states() |
|
827 | + : EEM_State::instance()->get_all_active_states(); |
|
828 | + if (! empty($states)) { |
|
829 | + foreach ($states as $state) { |
|
830 | + if ($state instanceof EE_State) { |
|
831 | + $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
832 | + } |
|
833 | + } |
|
834 | + } |
|
835 | + $state_options = apply_filters( |
|
836 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
837 | + $state_options, |
|
838 | + $this, |
|
839 | + $registration, |
|
840 | + $question, |
|
841 | + $answer |
|
842 | + ); |
|
843 | + return $state_options; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + /********************************************************************************************************/ |
|
848 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
849 | + /********************************************************************************************************/ |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * @return bool |
|
854 | + * @throws EE_Error |
|
855 | + * @throws InvalidArgumentException |
|
856 | + * @throws ReflectionException |
|
857 | + * @throws RuntimeException |
|
858 | + * @throws InvalidDataTypeException |
|
859 | + * @throws InvalidInterfaceException |
|
860 | + */ |
|
861 | + public function process_reg_step() |
|
862 | + { |
|
863 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
864 | + // grab validated data from form |
|
865 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
866 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
867 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
868 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
869 | + if (empty($valid_data)) { |
|
870 | + EE_Error::add_error( |
|
871 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
872 | + __FILE__, |
|
873 | + __FUNCTION__, |
|
874 | + __LINE__ |
|
875 | + ); |
|
876 | + return false; |
|
877 | + } |
|
878 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
879 | + EE_Error::add_error( |
|
880 | + esc_html__( |
|
881 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
882 | + 'event_espresso' |
|
883 | + ), |
|
884 | + __FILE__, |
|
885 | + __FUNCTION__, |
|
886 | + __LINE__ |
|
887 | + ); |
|
888 | + return false; |
|
889 | + } |
|
890 | + // get cached registrations |
|
891 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
892 | + // verify we got the goods |
|
893 | + if (empty($registrations)) { |
|
894 | + // combine the old translated string with a new one, in order to not break translations |
|
895 | + $error_message = esc_html__( |
|
896 | + 'Your form data could not be applied to any valid registrations.', |
|
897 | + 'event_espresso' |
|
898 | + ) |
|
899 | + . sprintf( |
|
900 | + esc_html_x( |
|
901 | + '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
902 | + '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
903 | + 'event_espresso' |
|
904 | + ), |
|
905 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
906 | + '</a>', |
|
907 | + '<br />' |
|
908 | + ); |
|
909 | + EE_Error::add_error( |
|
910 | + $error_message, |
|
911 | + __FILE__, |
|
912 | + __FUNCTION__, |
|
913 | + __LINE__ |
|
914 | + ); |
|
915 | + return false; |
|
916 | + } |
|
917 | + // extract attendee info from form data and save to model objects |
|
918 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
919 | + // if first pass thru SPCO, |
|
920 | + // then let's check processed registrations against the total number of tickets in the cart |
|
921 | + if ($registrations_processed === false) { |
|
922 | + // but return immediately if the previous step exited early due to errors |
|
923 | + return false; |
|
924 | + } |
|
925 | + if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
926 | + // generate a correctly translated string for all possible singular/plural combinations |
|
927 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
928 | + $error_msg = sprintf( |
|
929 | + esc_html_x( |
|
930 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
931 | + 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
932 | + 'event_espresso' |
|
933 | + ), |
|
934 | + $this->checkout->total_ticket_count, |
|
935 | + $registrations_processed |
|
936 | + ); |
|
937 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
938 | + $error_msg = sprintf( |
|
939 | + esc_html_x( |
|
940 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
941 | + 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
942 | + 'event_espresso' |
|
943 | + ), |
|
944 | + $this->checkout->total_ticket_count, |
|
945 | + $registrations_processed |
|
946 | + ); |
|
947 | + } else { |
|
948 | + $error_msg = sprintf( |
|
949 | + esc_html__( |
|
950 | + 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
951 | + 'event_espresso' |
|
952 | + ), |
|
953 | + $this->checkout->total_ticket_count, |
|
954 | + $registrations_processed |
|
955 | + ); |
|
956 | + } |
|
957 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
958 | + return false; |
|
959 | + } |
|
960 | + // mark this reg step as completed |
|
961 | + $this->set_completed(); |
|
962 | + $this->_set_success_message( |
|
963 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
964 | + ); |
|
965 | + // do action in case a plugin wants to do something with the data submitted in step 1. |
|
966 | + // passes EE_Single_Page_Checkout, and it's posted data |
|
967 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
968 | + return true; |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * _process_registrations |
|
974 | + * |
|
975 | + * @param EE_Registration[] $registrations |
|
976 | + * @param array[][] $valid_data |
|
977 | + * @return bool|int |
|
978 | + * @throws EntityNotFoundException |
|
979 | + * @throws EE_Error |
|
980 | + * @throws InvalidArgumentException |
|
981 | + * @throws ReflectionException |
|
982 | + * @throws RuntimeException |
|
983 | + * @throws InvalidDataTypeException |
|
984 | + * @throws InvalidInterfaceException |
|
985 | + */ |
|
986 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
987 | + { |
|
988 | + // load resources and set some defaults |
|
989 | + EE_Registry::instance()->load_model('Attendee'); |
|
990 | + // holder for primary registrant attendee object |
|
991 | + $this->checkout->primary_attendee_obj = null; |
|
992 | + // array for tracking reg form data for the primary registrant |
|
993 | + $primary_registrant = array( |
|
994 | + 'line_item_id' => null, |
|
995 | + ); |
|
996 | + $copy_primary = false; |
|
997 | + // reg form sections that do not contain inputs |
|
998 | + $non_input_form_sections = array( |
|
999 | + 'primary_registrant', |
|
1000 | + 'additional_attendee_reg_info', |
|
1001 | + 'spco_copy_attendee_chk', |
|
1002 | + ); |
|
1003 | + // attendee counter |
|
1004 | + $att_nmbr = 0; |
|
1005 | + // grab the saved registrations from the transaction |
|
1006 | + foreach ($registrations as $registration) { |
|
1007 | + // verify EE_Registration object |
|
1008 | + if (! $registration instanceof EE_Registration) { |
|
1009 | + EE_Error::add_error( |
|
1010 | + esc_html__( |
|
1011 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
1012 | + 'event_espresso' |
|
1013 | + ), |
|
1014 | + __FILE__, |
|
1015 | + __FUNCTION__, |
|
1016 | + __LINE__ |
|
1017 | + ); |
|
1018 | + return false; |
|
1019 | + } |
|
1020 | + /** @var string $reg_url_link */ |
|
1021 | + $reg_url_link = $registration->reg_url_link(); |
|
1022 | + // reg_url_link exists ? |
|
1023 | + if (! empty($reg_url_link)) { |
|
1024 | + // should this registration be processed during this visit ? |
|
1025 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
1026 | + // if NOT revisiting, then let's save the registration now, |
|
1027 | + // so that we have a REG_ID to use when generating other objects |
|
1028 | + if (! $this->checkout->revisit) { |
|
1029 | + $registration->save(); |
|
1030 | + } |
|
1031 | + /** |
|
1032 | + * This allows plugins to trigger a fail on processing of a |
|
1033 | + * registration for any conditions they may have for it to pass. |
|
1034 | + * |
|
1035 | + * @var bool if true is returned by the plugin then the |
|
1036 | + * registration processing is halted. |
|
1037 | + */ |
|
1038 | + if (apply_filters( |
|
1039 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1040 | + false, |
|
1041 | + $att_nmbr, |
|
1042 | + $registration, |
|
1043 | + $registrations, |
|
1044 | + $valid_data, |
|
1045 | + $this |
|
1046 | + )) { |
|
1047 | + return false; |
|
1048 | + } |
|
1049 | + |
|
1050 | + // Houston, we have a registration! |
|
1051 | + $att_nmbr++; |
|
1052 | + $this->_attendee_data[ $reg_url_link ] = array(); |
|
1053 | + // grab any existing related answer objects |
|
1054 | + $this->_registration_answers = $registration->answers(); |
|
1055 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1056 | + if (isset($valid_data[ $reg_url_link ])) { |
|
1057 | + // do we need to copy basic info from primary attendee ? |
|
1058 | + $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1059 | + && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1060 | + // filter form input data for this registration |
|
1061 | + $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1062 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1063 | + $valid_data[ $reg_url_link ] |
|
1064 | + ); |
|
1065 | + if (isset($valid_data['primary_attendee'])) { |
|
1066 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1067 | + ? $valid_data['primary_attendee'] |
|
1068 | + : false; |
|
1069 | + unset($valid_data['primary_attendee']); |
|
1070 | + } |
|
1071 | + // now loop through our array of valid post data && process attendee reg forms |
|
1072 | + foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1073 | + if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1074 | + foreach ($form_inputs as $form_input => $input_value) { |
|
1075 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1076 | + // check for critical inputs |
|
1077 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1078 | + $form_input, |
|
1079 | + $input_value |
|
1080 | + ) |
|
1081 | + ) { |
|
1082 | + return false; |
|
1083 | + } |
|
1084 | + // store a bit of data about the primary attendee |
|
1085 | + if ($att_nmbr === 1 |
|
1086 | + && ! empty($input_value) |
|
1087 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
1088 | + ) { |
|
1089 | + $primary_registrant[ $form_input ] = $input_value; |
|
1090 | + } elseif ($copy_primary |
|
1091 | + && $input_value === null |
|
1092 | + && isset($primary_registrant[ $form_input ]) |
|
1093 | + ) { |
|
1094 | + $input_value = $primary_registrant[ $form_input ]; |
|
1095 | + } |
|
1096 | + // now attempt to save the input data |
|
1097 | + if (! $this->_save_registration_form_input( |
|
1098 | + $registration, |
|
1099 | + $form_input, |
|
1100 | + $input_value |
|
1101 | + ) |
|
1102 | + ) { |
|
1103 | + EE_Error::add_error( |
|
1104 | + sprintf( |
|
1105 | + esc_html_x( |
|
1106 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1107 | + 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1108 | + 'event_espresso' |
|
1109 | + ), |
|
1110 | + $form_input, |
|
1111 | + $input_value |
|
1112 | + ), |
|
1113 | + __FILE__, |
|
1114 | + __FUNCTION__, |
|
1115 | + __LINE__ |
|
1116 | + ); |
|
1117 | + return false; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + } |
|
1121 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1122 | + } |
|
1123 | + // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1124 | + // this registration does not require additional attendee information ? |
|
1125 | + if ($copy_primary |
|
1126 | + && $att_nmbr > 1 |
|
1127 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1128 | + ) { |
|
1129 | + // just copy the primary registrant |
|
1130 | + $attendee = $this->checkout->primary_attendee_obj; |
|
1131 | + } else { |
|
1132 | + // ensure critical details are set for additional attendees |
|
1133 | + $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1134 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1135 | + $this->_attendee_data[ $reg_url_link ] |
|
1136 | + ) |
|
1137 | + : $this->_attendee_data[ $reg_url_link ]; |
|
1138 | + // execute create attendee command (which may return an existing attendee) |
|
1139 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
1140 | + new CreateAttendeeCommand( |
|
1141 | + $this->_attendee_data[ $reg_url_link ], |
|
1142 | + $registration |
|
1143 | + ) |
|
1144 | + ); |
|
1145 | + // who's #1 ? |
|
1146 | + if ($att_nmbr === 1) { |
|
1147 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1148 | + } |
|
1149 | + } |
|
1150 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1151 | + // add relation to registration, set attendee ID, and cache attendee |
|
1152 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1153 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1154 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
1155 | + EE_Error::add_error( |
|
1156 | + sprintf( |
|
1157 | + esc_html_x( |
|
1158 | + 'Registration %s has an invalid or missing Attendee object.', |
|
1159 | + 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1160 | + 'event_espresso' |
|
1161 | + ), |
|
1162 | + $reg_url_link |
|
1163 | + ), |
|
1164 | + __FILE__, |
|
1165 | + __FUNCTION__, |
|
1166 | + __LINE__ |
|
1167 | + ); |
|
1168 | + return false; |
|
1169 | + } |
|
1170 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1171 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1172 | + // at this point, we should have enough details about the registrant to consider the registration |
|
1173 | + // NOT incomplete |
|
1174 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1175 | + $registration, |
|
1176 | + false, |
|
1177 | + new Context( |
|
1178 | + 'spco_reg_step_attendee_information_process_registrations', |
|
1179 | + esc_html__( |
|
1180 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1181 | + 'event_espresso' |
|
1182 | + ) |
|
1183 | + ) |
|
1184 | + ); |
|
1185 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1186 | + // abandoned |
|
1187 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1188 | + // if we've gotten this far, then let's save what we have |
|
1189 | + $registration->save(); |
|
1190 | + // add relation between TXN and registration |
|
1191 | + $this->_associate_registration_with_transaction($registration); |
|
1192 | + } |
|
1193 | + } else { |
|
1194 | + EE_Error::add_error( |
|
1195 | + esc_html__( |
|
1196 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1197 | + 'event_espresso' |
|
1198 | + ), |
|
1199 | + __FILE__, |
|
1200 | + __FUNCTION__, |
|
1201 | + __LINE__ |
|
1202 | + ); |
|
1203 | + // remove malformed data |
|
1204 | + unset($valid_data[ $reg_url_link ]); |
|
1205 | + return false; |
|
1206 | + } |
|
1207 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1208 | + return $att_nmbr; |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * _save_registration_form_input |
|
1214 | + * |
|
1215 | + * @param EE_Registration $registration |
|
1216 | + * @param string $form_input |
|
1217 | + * @param string $input_value |
|
1218 | + * @return bool |
|
1219 | + * @throws EE_Error |
|
1220 | + * @throws InvalidArgumentException |
|
1221 | + * @throws InvalidDataTypeException |
|
1222 | + * @throws InvalidInterfaceException |
|
1223 | + * @throws ReflectionException |
|
1224 | + */ |
|
1225 | + private function _save_registration_form_input( |
|
1226 | + EE_Registration $registration, |
|
1227 | + $form_input = '', |
|
1228 | + $input_value = '' |
|
1229 | + ) { |
|
1230 | + // If email_confirm is sent it's not saved |
|
1231 | + if ((string) $form_input === 'email_confirm') { |
|
1232 | + return true; |
|
1233 | + } |
|
1234 | + |
|
1235 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1236 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1237 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1238 | + // allow for plugins to hook in and do their own processing of the form input. |
|
1239 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1240 | + if (apply_filters( |
|
1241 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1242 | + false, |
|
1243 | + $registration, |
|
1244 | + $form_input, |
|
1245 | + $input_value, |
|
1246 | + $this |
|
1247 | + )) { |
|
1248 | + return true; |
|
1249 | + } |
|
1250 | + /* |
|
1251 | 1251 | * $answer_cache_id is the key used to find the EE_Answer we want |
1252 | 1252 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1253 | 1253 | */ |
1254 | - $answer_cache_id = $this->checkout->reg_url_link |
|
1255 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1256 | - : $form_input; |
|
1257 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1258 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1259 | - // rename form_inputs if they are EE_Attendee properties |
|
1260 | - switch ((string) $form_input) { |
|
1261 | - case 'state': |
|
1262 | - case 'STA_ID': |
|
1263 | - $attendee_property = true; |
|
1264 | - $form_input = 'STA_ID'; |
|
1265 | - break; |
|
1266 | - |
|
1267 | - case 'country': |
|
1268 | - case 'CNT_ISO': |
|
1269 | - $attendee_property = true; |
|
1270 | - $form_input = 'CNT_ISO'; |
|
1271 | - break; |
|
1272 | - |
|
1273 | - default: |
|
1274 | - $ATT_input = 'ATT_' . $form_input; |
|
1275 | - // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1276 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1277 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1278 | - } |
|
1279 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1280 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1281 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1282 | - // if this form input has a corresponding attendee property |
|
1283 | - if ($attendee_property) { |
|
1284 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1285 | - if ($answer_is_obj) { |
|
1286 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
1287 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1288 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1289 | - } |
|
1290 | - return true; |
|
1291 | - } |
|
1292 | - if ($answer_is_obj) { |
|
1293 | - // save this data to the answer object |
|
1294 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1295 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1296 | - return $result !== false; |
|
1297 | - } |
|
1298 | - foreach ($this->_registration_answers as $answer) { |
|
1299 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1300 | - $answer->set_value($input_value); |
|
1301 | - $result = $answer->save(); |
|
1302 | - return $result !== false; |
|
1303 | - } |
|
1304 | - } |
|
1305 | - return false; |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * _verify_critical_attendee_details_are_set |
|
1311 | - * |
|
1312 | - * @param string $form_input |
|
1313 | - * @param string $input_value |
|
1314 | - * @return boolean |
|
1315 | - */ |
|
1316 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1317 | - $form_input = '', |
|
1318 | - $input_value = '' |
|
1319 | - ) { |
|
1320 | - if (empty($input_value)) { |
|
1321 | - // if the form input isn't marked as being required, then just return |
|
1322 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1323 | - return true; |
|
1324 | - } |
|
1325 | - switch ($form_input) { |
|
1326 | - case 'fname': |
|
1327 | - EE_Error::add_error( |
|
1328 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
1329 | - __FILE__, |
|
1330 | - __FUNCTION__, |
|
1331 | - __LINE__ |
|
1332 | - ); |
|
1333 | - return false; |
|
1334 | - break; |
|
1335 | - case 'lname': |
|
1336 | - EE_Error::add_error( |
|
1337 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1338 | - __FILE__, |
|
1339 | - __FUNCTION__, |
|
1340 | - __LINE__ |
|
1341 | - ); |
|
1342 | - return false; |
|
1343 | - break; |
|
1344 | - case 'email': |
|
1345 | - EE_Error::add_error( |
|
1346 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1347 | - __FILE__, |
|
1348 | - __FUNCTION__, |
|
1349 | - __LINE__ |
|
1350 | - ); |
|
1351 | - return false; |
|
1352 | - break; |
|
1353 | - } |
|
1354 | - } |
|
1355 | - return true; |
|
1356 | - } |
|
1357 | - |
|
1358 | - |
|
1359 | - /** |
|
1360 | - * _associate_attendee_with_registration |
|
1361 | - * |
|
1362 | - * @param EE_Registration $registration |
|
1363 | - * @param EE_Attendee $attendee |
|
1364 | - * @return void |
|
1365 | - * @throws EE_Error |
|
1366 | - * @throws InvalidArgumentException |
|
1367 | - * @throws ReflectionException |
|
1368 | - * @throws RuntimeException |
|
1369 | - * @throws InvalidDataTypeException |
|
1370 | - * @throws InvalidInterfaceException |
|
1371 | - */ |
|
1372 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1373 | - { |
|
1374 | - // add relation to attendee |
|
1375 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1376 | - $registration->set_attendee_id($attendee->ID()); |
|
1377 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * _associate_registration_with_transaction |
|
1383 | - * |
|
1384 | - * @param EE_Registration $registration |
|
1385 | - * @return void |
|
1386 | - * @throws EE_Error |
|
1387 | - * @throws InvalidArgumentException |
|
1388 | - * @throws ReflectionException |
|
1389 | - * @throws InvalidDataTypeException |
|
1390 | - * @throws InvalidInterfaceException |
|
1391 | - */ |
|
1392 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1393 | - { |
|
1394 | - // add relation to registration |
|
1395 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1396 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1397 | - } |
|
1398 | - |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * _copy_critical_attendee_details_from_primary_registrant |
|
1402 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
1403 | - * |
|
1404 | - * @param array $attendee_data |
|
1405 | - * @return array |
|
1406 | - * @throws EE_Error |
|
1407 | - * @throws InvalidArgumentException |
|
1408 | - * @throws ReflectionException |
|
1409 | - * @throws InvalidDataTypeException |
|
1410 | - * @throws InvalidInterfaceException |
|
1411 | - */ |
|
1412 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1413 | - { |
|
1414 | - // bare minimum critical details include first name, last name, email address |
|
1415 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1416 | - // add address info to critical details? |
|
1417 | - if (apply_filters( |
|
1418 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1419 | - false |
|
1420 | - )) { |
|
1421 | - $address_details = array( |
|
1422 | - 'ATT_address', |
|
1423 | - 'ATT_address2', |
|
1424 | - 'ATT_city', |
|
1425 | - 'STA_ID', |
|
1426 | - 'CNT_ISO', |
|
1427 | - 'ATT_zip', |
|
1428 | - 'ATT_phone', |
|
1429 | - ); |
|
1430 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1431 | - } |
|
1432 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1433 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1434 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
1435 | - ) { |
|
1436 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1437 | - $critical_attendee_detail |
|
1438 | - ); |
|
1439 | - } |
|
1440 | - } |
|
1441 | - return $attendee_data; |
|
1442 | - } |
|
1443 | - |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * update_reg_step |
|
1447 | - * this is the final step after a user revisits the site to edit their attendee information |
|
1448 | - * this gets called AFTER the process_reg_step() method above |
|
1449 | - * |
|
1450 | - * @return bool |
|
1451 | - * @throws EE_Error |
|
1452 | - * @throws InvalidArgumentException |
|
1453 | - * @throws ReflectionException |
|
1454 | - * @throws RuntimeException |
|
1455 | - * @throws InvalidDataTypeException |
|
1456 | - * @throws InvalidInterfaceException |
|
1457 | - */ |
|
1458 | - public function update_reg_step() |
|
1459 | - { |
|
1460 | - // save everything |
|
1461 | - if ($this->process_reg_step()) { |
|
1462 | - $this->checkout->redirect = true; |
|
1463 | - $this->checkout->redirect_url = add_query_arg( |
|
1464 | - array( |
|
1465 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1466 | - 'revisit' => true, |
|
1467 | - ), |
|
1468 | - $this->checkout->thank_you_page_url |
|
1469 | - ); |
|
1470 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1471 | - return true; |
|
1472 | - } |
|
1473 | - return false; |
|
1474 | - } |
|
1254 | + $answer_cache_id = $this->checkout->reg_url_link |
|
1255 | + ? $form_input . '-' . $registration->reg_url_link() |
|
1256 | + : $form_input; |
|
1257 | + $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1258 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1259 | + // rename form_inputs if they are EE_Attendee properties |
|
1260 | + switch ((string) $form_input) { |
|
1261 | + case 'state': |
|
1262 | + case 'STA_ID': |
|
1263 | + $attendee_property = true; |
|
1264 | + $form_input = 'STA_ID'; |
|
1265 | + break; |
|
1266 | + |
|
1267 | + case 'country': |
|
1268 | + case 'CNT_ISO': |
|
1269 | + $attendee_property = true; |
|
1270 | + $form_input = 'CNT_ISO'; |
|
1271 | + break; |
|
1272 | + |
|
1273 | + default: |
|
1274 | + $ATT_input = 'ATT_' . $form_input; |
|
1275 | + // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1276 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1277 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1278 | + } |
|
1279 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1280 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1281 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1282 | + // if this form input has a corresponding attendee property |
|
1283 | + if ($attendee_property) { |
|
1284 | + $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1285 | + if ($answer_is_obj) { |
|
1286 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
1287 | + $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1288 | + $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1289 | + } |
|
1290 | + return true; |
|
1291 | + } |
|
1292 | + if ($answer_is_obj) { |
|
1293 | + // save this data to the answer object |
|
1294 | + $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1295 | + $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1296 | + return $result !== false; |
|
1297 | + } |
|
1298 | + foreach ($this->_registration_answers as $answer) { |
|
1299 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1300 | + $answer->set_value($input_value); |
|
1301 | + $result = $answer->save(); |
|
1302 | + return $result !== false; |
|
1303 | + } |
|
1304 | + } |
|
1305 | + return false; |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * _verify_critical_attendee_details_are_set |
|
1311 | + * |
|
1312 | + * @param string $form_input |
|
1313 | + * @param string $input_value |
|
1314 | + * @return boolean |
|
1315 | + */ |
|
1316 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1317 | + $form_input = '', |
|
1318 | + $input_value = '' |
|
1319 | + ) { |
|
1320 | + if (empty($input_value)) { |
|
1321 | + // if the form input isn't marked as being required, then just return |
|
1322 | + if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1323 | + return true; |
|
1324 | + } |
|
1325 | + switch ($form_input) { |
|
1326 | + case 'fname': |
|
1327 | + EE_Error::add_error( |
|
1328 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
1329 | + __FILE__, |
|
1330 | + __FUNCTION__, |
|
1331 | + __LINE__ |
|
1332 | + ); |
|
1333 | + return false; |
|
1334 | + break; |
|
1335 | + case 'lname': |
|
1336 | + EE_Error::add_error( |
|
1337 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1338 | + __FILE__, |
|
1339 | + __FUNCTION__, |
|
1340 | + __LINE__ |
|
1341 | + ); |
|
1342 | + return false; |
|
1343 | + break; |
|
1344 | + case 'email': |
|
1345 | + EE_Error::add_error( |
|
1346 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1347 | + __FILE__, |
|
1348 | + __FUNCTION__, |
|
1349 | + __LINE__ |
|
1350 | + ); |
|
1351 | + return false; |
|
1352 | + break; |
|
1353 | + } |
|
1354 | + } |
|
1355 | + return true; |
|
1356 | + } |
|
1357 | + |
|
1358 | + |
|
1359 | + /** |
|
1360 | + * _associate_attendee_with_registration |
|
1361 | + * |
|
1362 | + * @param EE_Registration $registration |
|
1363 | + * @param EE_Attendee $attendee |
|
1364 | + * @return void |
|
1365 | + * @throws EE_Error |
|
1366 | + * @throws InvalidArgumentException |
|
1367 | + * @throws ReflectionException |
|
1368 | + * @throws RuntimeException |
|
1369 | + * @throws InvalidDataTypeException |
|
1370 | + * @throws InvalidInterfaceException |
|
1371 | + */ |
|
1372 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1373 | + { |
|
1374 | + // add relation to attendee |
|
1375 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1376 | + $registration->set_attendee_id($attendee->ID()); |
|
1377 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * _associate_registration_with_transaction |
|
1383 | + * |
|
1384 | + * @param EE_Registration $registration |
|
1385 | + * @return void |
|
1386 | + * @throws EE_Error |
|
1387 | + * @throws InvalidArgumentException |
|
1388 | + * @throws ReflectionException |
|
1389 | + * @throws InvalidDataTypeException |
|
1390 | + * @throws InvalidInterfaceException |
|
1391 | + */ |
|
1392 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1393 | + { |
|
1394 | + // add relation to registration |
|
1395 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1396 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1397 | + } |
|
1398 | + |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * _copy_critical_attendee_details_from_primary_registrant |
|
1402 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
1403 | + * |
|
1404 | + * @param array $attendee_data |
|
1405 | + * @return array |
|
1406 | + * @throws EE_Error |
|
1407 | + * @throws InvalidArgumentException |
|
1408 | + * @throws ReflectionException |
|
1409 | + * @throws InvalidDataTypeException |
|
1410 | + * @throws InvalidInterfaceException |
|
1411 | + */ |
|
1412 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1413 | + { |
|
1414 | + // bare minimum critical details include first name, last name, email address |
|
1415 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1416 | + // add address info to critical details? |
|
1417 | + if (apply_filters( |
|
1418 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1419 | + false |
|
1420 | + )) { |
|
1421 | + $address_details = array( |
|
1422 | + 'ATT_address', |
|
1423 | + 'ATT_address2', |
|
1424 | + 'ATT_city', |
|
1425 | + 'STA_ID', |
|
1426 | + 'CNT_ISO', |
|
1427 | + 'ATT_zip', |
|
1428 | + 'ATT_phone', |
|
1429 | + ); |
|
1430 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1431 | + } |
|
1432 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1433 | + if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1434 | + || empty($attendee_data[ $critical_attendee_detail ]) |
|
1435 | + ) { |
|
1436 | + $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1437 | + $critical_attendee_detail |
|
1438 | + ); |
|
1439 | + } |
|
1440 | + } |
|
1441 | + return $attendee_data; |
|
1442 | + } |
|
1443 | + |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * update_reg_step |
|
1447 | + * this is the final step after a user revisits the site to edit their attendee information |
|
1448 | + * this gets called AFTER the process_reg_step() method above |
|
1449 | + * |
|
1450 | + * @return bool |
|
1451 | + * @throws EE_Error |
|
1452 | + * @throws InvalidArgumentException |
|
1453 | + * @throws ReflectionException |
|
1454 | + * @throws RuntimeException |
|
1455 | + * @throws InvalidDataTypeException |
|
1456 | + * @throws InvalidInterfaceException |
|
1457 | + */ |
|
1458 | + public function update_reg_step() |
|
1459 | + { |
|
1460 | + // save everything |
|
1461 | + if ($this->process_reg_step()) { |
|
1462 | + $this->checkout->redirect = true; |
|
1463 | + $this->checkout->redirect_url = add_query_arg( |
|
1464 | + array( |
|
1465 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1466 | + 'revisit' => true, |
|
1467 | + ), |
|
1468 | + $this->checkout->thank_you_page_url |
|
1469 | + ); |
|
1470 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1471 | + return true; |
|
1472 | + } |
|
1473 | + return false; |
|
1474 | + } |
|
1475 | 1475 | } |
@@ -10,437 +10,437 @@ |
||
10 | 10 | class EEM_Question extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - // constant used to indicate that the question type is COUNTRY |
|
14 | - const QST_type_country = 'COUNTRY'; |
|
13 | + // constant used to indicate that the question type is COUNTRY |
|
14 | + const QST_type_country = 'COUNTRY'; |
|
15 | 15 | |
16 | - // constant used to indicate that the question type is DATE |
|
17 | - const QST_type_date = 'DATE'; |
|
18 | - |
|
19 | - // constant used to indicate that the question type is DROPDOWN |
|
20 | - const QST_type_dropdown = 'DROPDOWN'; |
|
21 | - |
|
22 | - // constant used to indicate that the question type is CHECKBOX |
|
23 | - const QST_type_checkbox = 'CHECKBOX'; |
|
24 | - |
|
25 | - // constant used to indicate that the question type is RADIO_BTN |
|
26 | - const QST_type_radio = 'RADIO_BTN'; |
|
27 | - |
|
28 | - // constant used to indicate that the question type is STATE |
|
29 | - const QST_type_state = 'STATE'; |
|
30 | - |
|
31 | - // constant used to indicate that the question type is TEXT |
|
32 | - const QST_type_text = 'TEXT'; |
|
33 | - |
|
34 | - // constant used to indicate that the question type is TEXTAREA |
|
35 | - const QST_type_textarea = 'TEXTAREA'; |
|
36 | - |
|
37 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | - |
|
40 | - // constant used to indicate that the question type is an email input |
|
41 | - const QST_type_email = 'EMAIL'; |
|
42 | - |
|
43 | - // constant used to indicate that the question type is an email input |
|
44 | - const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | - |
|
46 | - // constant used to indicate that the question type is a US-formatted phone number |
|
47 | - const QST_type_us_phone = 'US_PHONE'; |
|
48 | - |
|
49 | - // constant used to indicate that the question type is an integer (whole number) |
|
50 | - const QST_type_int = 'INTEGER'; |
|
51 | - |
|
52 | - // constant used to indicate that the question type is a decimal (float) |
|
53 | - const QST_type_decimal = 'DECIMAL'; |
|
54 | - |
|
55 | - // constant used to indicate that the question type is a valid URL |
|
56 | - const QST_type_url = 'URL'; |
|
57 | - |
|
58 | - // constant used to indicate that the question type is a YEAR |
|
59 | - const QST_type_year = 'YEAR'; |
|
60 | - |
|
61 | - // constant used to indicate that the question type is a multi-select |
|
62 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | - * |
|
69 | - * @access protected |
|
70 | - * @var array $_question_type_categories { |
|
71 | - * @type string $text |
|
72 | - * @type string $single -answer-enum |
|
73 | - * @type string $multi -answer-enum |
|
74 | - * } |
|
75 | - */ |
|
76 | - protected $_question_type_categories = array(); |
|
77 | - |
|
78 | - /** |
|
79 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | - * |
|
81 | - * @access protected |
|
82 | - * @var array $_allowed_question_types |
|
83 | - */ |
|
84 | - protected $_allowed_question_types = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * brief descriptions for all the question types |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @var EEM_Question $_instance |
|
91 | - */ |
|
92 | - protected $_question_descriptions; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Question types that should have an admin-defined max input length |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - protected $question_types_with_max_lengh; |
|
100 | - |
|
101 | - |
|
102 | - // private instance of the Attendee object |
|
103 | - protected static $_instance = null; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * EEM_Question constructor. |
|
108 | - * |
|
109 | - * @param null $timezone |
|
110 | - */ |
|
111 | - protected function __construct($timezone = null) |
|
112 | - { |
|
113 | - $this->singular_item = __('Question', 'event_espresso'); |
|
114 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
115 | - $this->_allowed_question_types = apply_filters( |
|
116 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
117 | - array( |
|
118 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
119 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
120 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
121 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
122 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
123 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
124 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
125 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
126 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
127 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
128 | - EEM_Question::QST_type_email_confirm => __('Confirm Email', 'event_espresso'), |
|
129 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
130 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
131 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
132 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
133 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
134 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
135 | - ) |
|
136 | - ); |
|
137 | - $this->_question_descriptions = apply_filters( |
|
138 | - 'FHEE__EEM_Question__construct__question_descriptions', |
|
139 | - array( |
|
140 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
141 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
142 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
143 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
144 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
145 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
146 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
147 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
148 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
149 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
150 | - EEM_Question::QST_type_email_confirm => __('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
151 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
152 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
153 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
154 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
155 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
156 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
157 | - ) |
|
158 | - ); |
|
159 | - $this->_question_type_categories = (array) apply_filters( |
|
160 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
161 | - array( |
|
162 | - 'text' => array( |
|
163 | - EEM_Question::QST_type_text, |
|
164 | - EEM_Question::QST_type_textarea, |
|
165 | - EEM_Question::QST_type_date, |
|
166 | - EEM_Question::QST_type_html_textarea, |
|
167 | - EEM_Question::QST_type_email, |
|
168 | - EEM_Question::QST_type_email_confirm, |
|
169 | - EEM_Question::QST_type_us_phone, |
|
170 | - EEM_Question::QST_type_decimal, |
|
171 | - EEM_Question::QST_type_int, |
|
172 | - EEM_Question::QST_type_url, |
|
173 | - EEM_Question::QST_type_year |
|
174 | - ), |
|
175 | - 'single-answer-enum' => array( |
|
176 | - EEM_Question::QST_type_radio, |
|
177 | - EEM_Question::QST_type_dropdown |
|
178 | - ), |
|
179 | - 'multi-answer-enum' => array( |
|
180 | - EEM_Question::QST_type_checkbox, |
|
181 | - EEM_Question::QST_type_multi_select |
|
182 | - ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - $this->question_types_with_max_lengh = apply_filters( |
|
186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | - array( |
|
188 | - EEM_Question::QST_type_text, |
|
189 | - EEM_Question::QST_type_textarea, |
|
190 | - EEM_Question::QST_type_html_textarea |
|
191 | - ) |
|
192 | - ); |
|
193 | - |
|
194 | - $this->_tables = array( |
|
195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | - ); |
|
197 | - $this->_fields = array( |
|
198 | - 'Question' => array( |
|
199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | - ) |
|
212 | - ); |
|
213 | - $this->_model_relations = array( |
|
214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | - // for QST_order column |
|
219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | - ); |
|
221 | - // this model is generally available for reading |
|
222 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
223 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | - parent::__construct($timezone); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | - * but they can be extended |
|
232 | - * @return string[] |
|
233 | - */ |
|
234 | - public function allowed_question_types() |
|
235 | - { |
|
236 | - return $this->_allowed_question_types; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the question types in the same category |
|
241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
243 | - */ |
|
244 | - public function question_types_in_same_category($question_type) |
|
245 | - { |
|
246 | - $question_types = array($question_type); |
|
247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | - if (in_array($question_type, $question_types_in_category)) { |
|
249 | - $question_types = $question_types_in_category; |
|
250 | - break; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Determines if the given question type is in the given question type category |
|
259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | - * @return boolean |
|
262 | - */ |
|
263 | - public function question_type_is_in_category($question_type, $category) |
|
264 | - { |
|
265 | - if (!isset($this->_question_type_categories[ $category ])) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns all the question types in the given category |
|
274 | - * @param string $category |
|
275 | - * @return array|mixed |
|
276 | - */ |
|
277 | - public function question_types_in_category($category) |
|
278 | - { |
|
279 | - if (isset($this->_question_type_categories[ $category ])) { |
|
280 | - return $this->_question_type_categories[ $category ]; |
|
281 | - } |
|
282 | - return array(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Returns all the question types that should have question options |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function question_types_with_options() |
|
291 | - { |
|
292 | - return array_merge( |
|
293 | - $this->question_types_in_category('single-answer-enum'), |
|
294 | - $this->question_types_in_category('multi-answer-enum') |
|
295 | - ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the question type categories 2d array |
|
300 | - * @return array see EEM_Question::_question_type_categories |
|
301 | - */ |
|
302 | - public function question_type_categories() |
|
303 | - { |
|
304 | - return $this->_question_type_categories; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | - * identified by $system_question_group_id |
|
310 | - * @param string $system_question_group_id QSG_system |
|
311 | - * @return array of system question names (QST_system) |
|
312 | - */ |
|
313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | - { |
|
315 | - $question_system_ids = array(); |
|
316 | - switch ($system_question_group_id) { |
|
317 | - case EEM_Question_Group::system_personal: |
|
318 | - $question_system_ids = array( |
|
319 | - EEM_Attendee::system_question_fname, |
|
320 | - EEM_Attendee::system_question_lname, |
|
321 | - EEM_Attendee::system_question_email, |
|
322 | - EEM_Attendee::system_question_email_confirm, |
|
323 | - EEM_Attendee::system_question_phone |
|
324 | - ); |
|
325 | - break; |
|
326 | - case EEM_Question_Group::system_address: |
|
327 | - $question_system_ids = array( |
|
328 | - EEM_Attendee::system_question_address, |
|
329 | - EEM_Attendee::system_question_address2, |
|
330 | - EEM_Attendee::system_question_city, |
|
331 | - EEM_Attendee::system_question_state, |
|
332 | - EEM_Attendee::system_question_country, |
|
333 | - EEM_Attendee::system_question_zip, |
|
334 | - EEM_Attendee::system_question_phone |
|
335 | - ); |
|
336 | - break; |
|
337 | - } |
|
338 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns an array of all the QST_system values that are required in the system question group |
|
343 | - * identified by $system_question_group_id |
|
344 | - * @param string $system_question_group_id QSG_system |
|
345 | - * @return array of system question names (QST_system) |
|
346 | - */ |
|
347 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
348 | - { |
|
349 | - $question_system_ids = null; |
|
350 | - switch ($system_question_group_id) { |
|
351 | - case EEM_Question_Group::system_personal: |
|
352 | - $question_system_ids = array( |
|
353 | - EEM_Attendee::system_question_fname, |
|
354 | - EEM_Attendee::system_question_email, |
|
355 | - ); |
|
356 | - break; |
|
357 | - default: |
|
358 | - $question_system_ids = array(); |
|
359 | - } |
|
360 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
366 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
367 | - * @param $QST_system |
|
368 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
369 | - */ |
|
370 | - public function get_Question_ID_from_system_string($QST_system) |
|
371 | - { |
|
372 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * searches the db for the question with the latest question order and returns that value. |
|
378 | - * @access public |
|
379 | - * @return int |
|
380 | - */ |
|
381 | - public function get_latest_question_order() |
|
382 | - { |
|
383 | - $columns_to_select = array( |
|
384 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
385 | - ); |
|
386 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
387 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns an array where keys are system question QST_system values, |
|
392 | - * and values are the highest question max the admin can set on the question |
|
393 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
394 | - * of 5, but no larger than 12) |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function system_question_maxes() |
|
398 | - { |
|
399 | - return array( |
|
400 | - 'fname' => 45, |
|
401 | - 'lname' => 45, |
|
402 | - 'address' => 255, |
|
403 | - 'address2' => 255, |
|
404 | - 'city' => 45, |
|
405 | - 'zip' => 12, |
|
406 | - 'email' => 255, |
|
407 | - 'email_confirm' => 255, |
|
408 | - 'phone' => 45, |
|
409 | - ); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
414 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
415 | - * @param string $system_question_value |
|
416 | - * @return int|float |
|
417 | - */ |
|
418 | - public function absolute_max_for_system_question($system_question_value) |
|
419 | - { |
|
420 | - $maxes = $this->system_question_maxes(); |
|
421 | - if (isset($maxes[ $system_question_value ])) { |
|
422 | - return $maxes[ $system_question_value ]; |
|
423 | - } else { |
|
424 | - return EE_INF; |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @return array |
|
431 | - */ |
|
432 | - public function question_descriptions() |
|
433 | - { |
|
434 | - return $this->_question_descriptions; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * Returns all the question types that should have an admin-defined max input length |
|
440 | - * @return array |
|
441 | - */ |
|
442 | - public function questionTypesWithMaxLength() |
|
443 | - { |
|
444 | - return (array) $this->question_types_with_max_lengh; |
|
445 | - } |
|
16 | + // constant used to indicate that the question type is DATE |
|
17 | + const QST_type_date = 'DATE'; |
|
18 | + |
|
19 | + // constant used to indicate that the question type is DROPDOWN |
|
20 | + const QST_type_dropdown = 'DROPDOWN'; |
|
21 | + |
|
22 | + // constant used to indicate that the question type is CHECKBOX |
|
23 | + const QST_type_checkbox = 'CHECKBOX'; |
|
24 | + |
|
25 | + // constant used to indicate that the question type is RADIO_BTN |
|
26 | + const QST_type_radio = 'RADIO_BTN'; |
|
27 | + |
|
28 | + // constant used to indicate that the question type is STATE |
|
29 | + const QST_type_state = 'STATE'; |
|
30 | + |
|
31 | + // constant used to indicate that the question type is TEXT |
|
32 | + const QST_type_text = 'TEXT'; |
|
33 | + |
|
34 | + // constant used to indicate that the question type is TEXTAREA |
|
35 | + const QST_type_textarea = 'TEXTAREA'; |
|
36 | + |
|
37 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | + |
|
40 | + // constant used to indicate that the question type is an email input |
|
41 | + const QST_type_email = 'EMAIL'; |
|
42 | + |
|
43 | + // constant used to indicate that the question type is an email input |
|
44 | + const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | + |
|
46 | + // constant used to indicate that the question type is a US-formatted phone number |
|
47 | + const QST_type_us_phone = 'US_PHONE'; |
|
48 | + |
|
49 | + // constant used to indicate that the question type is an integer (whole number) |
|
50 | + const QST_type_int = 'INTEGER'; |
|
51 | + |
|
52 | + // constant used to indicate that the question type is a decimal (float) |
|
53 | + const QST_type_decimal = 'DECIMAL'; |
|
54 | + |
|
55 | + // constant used to indicate that the question type is a valid URL |
|
56 | + const QST_type_url = 'URL'; |
|
57 | + |
|
58 | + // constant used to indicate that the question type is a YEAR |
|
59 | + const QST_type_year = 'YEAR'; |
|
60 | + |
|
61 | + // constant used to indicate that the question type is a multi-select |
|
62 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | + * |
|
69 | + * @access protected |
|
70 | + * @var array $_question_type_categories { |
|
71 | + * @type string $text |
|
72 | + * @type string $single -answer-enum |
|
73 | + * @type string $multi -answer-enum |
|
74 | + * } |
|
75 | + */ |
|
76 | + protected $_question_type_categories = array(); |
|
77 | + |
|
78 | + /** |
|
79 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | + * |
|
81 | + * @access protected |
|
82 | + * @var array $_allowed_question_types |
|
83 | + */ |
|
84 | + protected $_allowed_question_types = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * brief descriptions for all the question types |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @var EEM_Question $_instance |
|
91 | + */ |
|
92 | + protected $_question_descriptions; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Question types that should have an admin-defined max input length |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + protected $question_types_with_max_lengh; |
|
100 | + |
|
101 | + |
|
102 | + // private instance of the Attendee object |
|
103 | + protected static $_instance = null; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * EEM_Question constructor. |
|
108 | + * |
|
109 | + * @param null $timezone |
|
110 | + */ |
|
111 | + protected function __construct($timezone = null) |
|
112 | + { |
|
113 | + $this->singular_item = __('Question', 'event_espresso'); |
|
114 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
115 | + $this->_allowed_question_types = apply_filters( |
|
116 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
117 | + array( |
|
118 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
119 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
120 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
121 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_email_confirm => __('Confirm Email', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
130 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
131 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
132 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
133 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
134 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
135 | + ) |
|
136 | + ); |
|
137 | + $this->_question_descriptions = apply_filters( |
|
138 | + 'FHEE__EEM_Question__construct__question_descriptions', |
|
139 | + array( |
|
140 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
141 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
142 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
143 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
144 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
145 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
146 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
147 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
148 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
149 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
150 | + EEM_Question::QST_type_email_confirm => __('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
151 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
152 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
153 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
154 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
155 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
156 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
157 | + ) |
|
158 | + ); |
|
159 | + $this->_question_type_categories = (array) apply_filters( |
|
160 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
161 | + array( |
|
162 | + 'text' => array( |
|
163 | + EEM_Question::QST_type_text, |
|
164 | + EEM_Question::QST_type_textarea, |
|
165 | + EEM_Question::QST_type_date, |
|
166 | + EEM_Question::QST_type_html_textarea, |
|
167 | + EEM_Question::QST_type_email, |
|
168 | + EEM_Question::QST_type_email_confirm, |
|
169 | + EEM_Question::QST_type_us_phone, |
|
170 | + EEM_Question::QST_type_decimal, |
|
171 | + EEM_Question::QST_type_int, |
|
172 | + EEM_Question::QST_type_url, |
|
173 | + EEM_Question::QST_type_year |
|
174 | + ), |
|
175 | + 'single-answer-enum' => array( |
|
176 | + EEM_Question::QST_type_radio, |
|
177 | + EEM_Question::QST_type_dropdown |
|
178 | + ), |
|
179 | + 'multi-answer-enum' => array( |
|
180 | + EEM_Question::QST_type_checkbox, |
|
181 | + EEM_Question::QST_type_multi_select |
|
182 | + ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + $this->question_types_with_max_lengh = apply_filters( |
|
186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | + array( |
|
188 | + EEM_Question::QST_type_text, |
|
189 | + EEM_Question::QST_type_textarea, |
|
190 | + EEM_Question::QST_type_html_textarea |
|
191 | + ) |
|
192 | + ); |
|
193 | + |
|
194 | + $this->_tables = array( |
|
195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | + ); |
|
197 | + $this->_fields = array( |
|
198 | + 'Question' => array( |
|
199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | + ) |
|
212 | + ); |
|
213 | + $this->_model_relations = array( |
|
214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | + // for QST_order column |
|
219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | + ); |
|
221 | + // this model is generally available for reading |
|
222 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
223 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | + parent::__construct($timezone); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | + * but they can be extended |
|
232 | + * @return string[] |
|
233 | + */ |
|
234 | + public function allowed_question_types() |
|
235 | + { |
|
236 | + return $this->_allowed_question_types; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the question types in the same category |
|
241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
243 | + */ |
|
244 | + public function question_types_in_same_category($question_type) |
|
245 | + { |
|
246 | + $question_types = array($question_type); |
|
247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | + if (in_array($question_type, $question_types_in_category)) { |
|
249 | + $question_types = $question_types_in_category; |
|
250 | + break; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Determines if the given question type is in the given question type category |
|
259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | + * @return boolean |
|
262 | + */ |
|
263 | + public function question_type_is_in_category($question_type, $category) |
|
264 | + { |
|
265 | + if (!isset($this->_question_type_categories[ $category ])) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns all the question types in the given category |
|
274 | + * @param string $category |
|
275 | + * @return array|mixed |
|
276 | + */ |
|
277 | + public function question_types_in_category($category) |
|
278 | + { |
|
279 | + if (isset($this->_question_type_categories[ $category ])) { |
|
280 | + return $this->_question_type_categories[ $category ]; |
|
281 | + } |
|
282 | + return array(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Returns all the question types that should have question options |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function question_types_with_options() |
|
291 | + { |
|
292 | + return array_merge( |
|
293 | + $this->question_types_in_category('single-answer-enum'), |
|
294 | + $this->question_types_in_category('multi-answer-enum') |
|
295 | + ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the question type categories 2d array |
|
300 | + * @return array see EEM_Question::_question_type_categories |
|
301 | + */ |
|
302 | + public function question_type_categories() |
|
303 | + { |
|
304 | + return $this->_question_type_categories; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | + * identified by $system_question_group_id |
|
310 | + * @param string $system_question_group_id QSG_system |
|
311 | + * @return array of system question names (QST_system) |
|
312 | + */ |
|
313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | + { |
|
315 | + $question_system_ids = array(); |
|
316 | + switch ($system_question_group_id) { |
|
317 | + case EEM_Question_Group::system_personal: |
|
318 | + $question_system_ids = array( |
|
319 | + EEM_Attendee::system_question_fname, |
|
320 | + EEM_Attendee::system_question_lname, |
|
321 | + EEM_Attendee::system_question_email, |
|
322 | + EEM_Attendee::system_question_email_confirm, |
|
323 | + EEM_Attendee::system_question_phone |
|
324 | + ); |
|
325 | + break; |
|
326 | + case EEM_Question_Group::system_address: |
|
327 | + $question_system_ids = array( |
|
328 | + EEM_Attendee::system_question_address, |
|
329 | + EEM_Attendee::system_question_address2, |
|
330 | + EEM_Attendee::system_question_city, |
|
331 | + EEM_Attendee::system_question_state, |
|
332 | + EEM_Attendee::system_question_country, |
|
333 | + EEM_Attendee::system_question_zip, |
|
334 | + EEM_Attendee::system_question_phone |
|
335 | + ); |
|
336 | + break; |
|
337 | + } |
|
338 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns an array of all the QST_system values that are required in the system question group |
|
343 | + * identified by $system_question_group_id |
|
344 | + * @param string $system_question_group_id QSG_system |
|
345 | + * @return array of system question names (QST_system) |
|
346 | + */ |
|
347 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
348 | + { |
|
349 | + $question_system_ids = null; |
|
350 | + switch ($system_question_group_id) { |
|
351 | + case EEM_Question_Group::system_personal: |
|
352 | + $question_system_ids = array( |
|
353 | + EEM_Attendee::system_question_fname, |
|
354 | + EEM_Attendee::system_question_email, |
|
355 | + ); |
|
356 | + break; |
|
357 | + default: |
|
358 | + $question_system_ids = array(); |
|
359 | + } |
|
360 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
366 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
367 | + * @param $QST_system |
|
368 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
369 | + */ |
|
370 | + public function get_Question_ID_from_system_string($QST_system) |
|
371 | + { |
|
372 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * searches the db for the question with the latest question order and returns that value. |
|
378 | + * @access public |
|
379 | + * @return int |
|
380 | + */ |
|
381 | + public function get_latest_question_order() |
|
382 | + { |
|
383 | + $columns_to_select = array( |
|
384 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
385 | + ); |
|
386 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
387 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns an array where keys are system question QST_system values, |
|
392 | + * and values are the highest question max the admin can set on the question |
|
393 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
394 | + * of 5, but no larger than 12) |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function system_question_maxes() |
|
398 | + { |
|
399 | + return array( |
|
400 | + 'fname' => 45, |
|
401 | + 'lname' => 45, |
|
402 | + 'address' => 255, |
|
403 | + 'address2' => 255, |
|
404 | + 'city' => 45, |
|
405 | + 'zip' => 12, |
|
406 | + 'email' => 255, |
|
407 | + 'email_confirm' => 255, |
|
408 | + 'phone' => 45, |
|
409 | + ); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
414 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
415 | + * @param string $system_question_value |
|
416 | + * @return int|float |
|
417 | + */ |
|
418 | + public function absolute_max_for_system_question($system_question_value) |
|
419 | + { |
|
420 | + $maxes = $this->system_question_maxes(); |
|
421 | + if (isset($maxes[ $system_question_value ])) { |
|
422 | + return $maxes[ $system_question_value ]; |
|
423 | + } else { |
|
424 | + return EE_INF; |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @return array |
|
431 | + */ |
|
432 | + public function question_descriptions() |
|
433 | + { |
|
434 | + return $this->_question_descriptions; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * Returns all the question types that should have an admin-defined max input length |
|
440 | + * @return array |
|
441 | + */ |
|
442 | + public function questionTypesWithMaxLength() |
|
443 | + { |
|
444 | + return (array) $this->question_types_with_max_lengh; |
|
445 | + } |
|
446 | 446 | } |
@@ -12,432 +12,432 @@ |
||
12 | 12 | class EEM_Attendee extends EEM_CPT_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance of the Attendee object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the Attendee object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * QST_system for questions are strings not integers now, |
|
20 | - * so these constants are deprecated. |
|
21 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | - * |
|
23 | - * @deprecated |
|
24 | - */ |
|
25 | - const fname_question_id = 1; |
|
18 | + /** |
|
19 | + * QST_system for questions are strings not integers now, |
|
20 | + * so these constants are deprecated. |
|
21 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | + * |
|
23 | + * @deprecated |
|
24 | + */ |
|
25 | + const fname_question_id = 1; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @deprecated |
|
29 | - */ |
|
30 | - const lname_question_id = 2; |
|
27 | + /** |
|
28 | + * @deprecated |
|
29 | + */ |
|
30 | + const lname_question_id = 2; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @deprecated |
|
35 | - */ |
|
36 | - const email_question_id = 3; |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + */ |
|
36 | + const email_question_id = 3; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @deprecated |
|
41 | - */ |
|
42 | - const address_question_id = 4; |
|
39 | + /** |
|
40 | + * @deprecated |
|
41 | + */ |
|
42 | + const address_question_id = 4; |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @deprecated |
|
47 | - */ |
|
48 | - const address2_question_id = 5; |
|
45 | + /** |
|
46 | + * @deprecated |
|
47 | + */ |
|
48 | + const address2_question_id = 5; |
|
49 | 49 | |
50 | - |
|
51 | - /** |
|
52 | - * @deprecated |
|
53 | - */ |
|
54 | - const city_question_id = 6; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @deprecated |
|
59 | - */ |
|
60 | - const state_question_id = 7; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @deprecated |
|
65 | - */ |
|
66 | - const country_question_id = 8; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @deprecated |
|
71 | - */ |
|
72 | - const zip_question_id = 9; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @deprecated |
|
77 | - */ |
|
78 | - const phone_question_id = 10; |
|
79 | - |
|
80 | - /** |
|
81 | - * When looking for questions that correspond to attendee fields, |
|
82 | - * look for the question with this QST_system value. |
|
83 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | - */ |
|
85 | - const system_question_fname = 'fname'; |
|
86 | - |
|
87 | - const system_question_lname = 'lname'; |
|
88 | - |
|
89 | - const system_question_email = 'email'; |
|
90 | - |
|
91 | - const system_question_email_confirm = 'email_confirm'; |
|
92 | - |
|
93 | - const system_question_address = 'address'; |
|
94 | - |
|
95 | - const system_question_address2 = 'address2'; |
|
96 | - |
|
97 | - const system_question_city = 'city'; |
|
98 | - |
|
99 | - const system_question_state = 'state'; |
|
100 | - |
|
101 | - const system_question_country = 'country'; |
|
102 | - |
|
103 | - const system_question_zip = 'zip'; |
|
104 | - |
|
105 | - const system_question_phone = 'phone'; |
|
106 | - |
|
107 | - /** |
|
108 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
109 | - * also all the values of QST_system in the questions table, and values |
|
110 | - * are their corresponding Attendee field names |
|
111 | - * |
|
112 | - * @var array |
|
113 | - */ |
|
114 | - protected $_system_question_to_attendee_field_name = array( |
|
115 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
116 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
117 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
118 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
119 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
120 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
121 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
122 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
123 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
124 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
125 | - ); |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * EEM_Attendee constructor. |
|
131 | - * |
|
132 | - * @param null $timezone |
|
133 | - * @param ModelFieldFactory $model_field_factory |
|
134 | - * @throws EE_Error |
|
135 | - * @throws InvalidArgumentException |
|
136 | - */ |
|
137 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
138 | - { |
|
139 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
140 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
141 | - $this->_tables = array( |
|
142 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
143 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
144 | - 'esp_attendee_meta', |
|
145 | - 'ATTM_ID', |
|
146 | - 'ATT_ID' |
|
147 | - ), |
|
148 | - ); |
|
149 | - $this->_fields = array( |
|
150 | - 'Attendee_CPT' => array( |
|
151 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
152 | - 'ID', |
|
153 | - esc_html__('Attendee ID', 'event_espresso') |
|
154 | - ), |
|
155 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
156 | - 'post_title', |
|
157 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
158 | - false, |
|
159 | - esc_html__('Unknown', 'event_espresso') |
|
160 | - ), |
|
161 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
162 | - 'post_content', |
|
163 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
164 | - false, |
|
165 | - esc_html__('No Biography Provided', 'event_espresso') |
|
166 | - ), |
|
167 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
168 | - 'post_name', |
|
169 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
170 | - ), |
|
171 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
172 | - 'post_date', |
|
173 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
174 | - ), |
|
175 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
176 | - 'post_excerpt', |
|
177 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
178 | - true, |
|
179 | - esc_html__('No Biography Provided', 'event_espresso') |
|
180 | - ), |
|
181 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
182 | - 'post_modified', |
|
183 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
184 | - ), |
|
185 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
186 | - 'post_author', |
|
187 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
188 | - false |
|
189 | - ), |
|
190 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
191 | - 'post_parent', |
|
192 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
193 | - false, |
|
194 | - 0 |
|
195 | - ), |
|
196 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
197 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
198 | - 'post_status', |
|
199 | - esc_html__('Attendee Status', 'event_espresso'), |
|
200 | - false, |
|
201 | - 'publish' |
|
202 | - ), |
|
203 | - 'password' => new EE_Password_Field( |
|
204 | - 'post_password', |
|
205 | - __('Password', 'event_espresso'), |
|
206 | - false, |
|
207 | - '', |
|
208 | - array( |
|
209 | - 'ATT_bio', |
|
210 | - 'ATT_short_bio', |
|
211 | - 'ATT_address', |
|
212 | - 'ATT_address2', |
|
213 | - 'ATT_city', |
|
214 | - 'STA_ID', |
|
215 | - 'CNT_ISO', |
|
216 | - 'ATT_zip', |
|
217 | - 'ATT_email', |
|
218 | - 'ATT_phone' |
|
219 | - ) |
|
220 | - ) |
|
221 | - ), |
|
222 | - 'Attendee_Meta' => array( |
|
223 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
224 | - 'ATTM_ID', |
|
225 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
226 | - false |
|
227 | - ), |
|
228 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
229 | - 'ATT_ID', |
|
230 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
231 | - false |
|
232 | - ), |
|
233 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
234 | - 'ATT_fname', |
|
235 | - esc_html__('First Name', 'event_espresso') |
|
236 | - ), |
|
237 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
238 | - 'ATT_lname', |
|
239 | - esc_html__('Last Name', 'event_espresso') |
|
240 | - ), |
|
241 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
242 | - 'ATT_address', |
|
243 | - esc_html__('Address Part 1', 'event_espresso') |
|
244 | - ), |
|
245 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
246 | - 'ATT_address2', |
|
247 | - esc_html__('Address Part 2', 'event_espresso') |
|
248 | - ), |
|
249 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
250 | - 'ATT_city', |
|
251 | - esc_html__('City', 'event_espresso') |
|
252 | - ), |
|
253 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
254 | - 'STA_ID', |
|
255 | - esc_html__('State', 'event_espresso'), |
|
256 | - true, |
|
257 | - 0, |
|
258 | - 'State' |
|
259 | - ), |
|
260 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
261 | - 'CNT_ISO', |
|
262 | - esc_html__('Country', 'event_espresso'), |
|
263 | - true, |
|
264 | - '', |
|
265 | - 'Country' |
|
266 | - ), |
|
267 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
268 | - 'ATT_zip', |
|
269 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
270 | - ), |
|
271 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
272 | - 'ATT_email', |
|
273 | - esc_html__('Email Address', 'event_espresso') |
|
274 | - ), |
|
275 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
276 | - 'ATT_phone', |
|
277 | - esc_html__('Phone', 'event_espresso') |
|
278 | - ), |
|
279 | - ), |
|
280 | - ); |
|
281 | - $this->_model_relations = array( |
|
282 | - 'Registration' => new EE_Has_Many_Relation(), |
|
283 | - 'State' => new EE_Belongs_To_Relation(), |
|
284 | - 'Country' => new EE_Belongs_To_Relation(), |
|
285 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
286 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
287 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
288 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
289 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | - ); |
|
292 | - $this->_caps_slug = 'contacts'; |
|
293 | - $this->model_chain_to_password = ''; |
|
294 | - parent::__construct($timezone); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
301 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
302 | - * |
|
303 | - * @param string $system_question_string |
|
304 | - * @return string|null if not found |
|
305 | - */ |
|
306 | - public function get_attendee_field_for_system_question($system_question_string) |
|
307 | - { |
|
308 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
309 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
310 | - : null; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
317 | - * |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - public function system_question_to_attendee_field_mapping() |
|
321 | - { |
|
322 | - return $this->_system_question_to_attendee_field_name; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
329 | - * |
|
330 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
331 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
335 | - { |
|
336 | - return $this->get_all( |
|
337 | - array( |
|
338 | - array( |
|
339 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
340 | - ? $transaction_id_or_obj->ID() |
|
341 | - : $transaction_id_or_obj, |
|
342 | - ), |
|
343 | - ) |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * retrieve a single attendee from db via their ID |
|
351 | - * |
|
352 | - * @param $ATT_ID |
|
353 | - * @return mixed array on success, FALSE on fail |
|
354 | - * @deprecated |
|
355 | - */ |
|
356 | - public function get_attendee_by_ID($ATT_ID = false) |
|
357 | - { |
|
358 | - // retrieve a particular EE_Attendee |
|
359 | - return $this->get_one_by_ID($ATT_ID); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * retrieve a single attendee from db via their ID |
|
366 | - * |
|
367 | - * @param array $where_cols_n_values |
|
368 | - * @return mixed array on success, FALSE on fail |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public function get_attendee($where_cols_n_values = array()) |
|
372 | - { |
|
373 | - if (empty($where_cols_n_values)) { |
|
374 | - return false; |
|
375 | - } |
|
376 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
377 | - if (! empty($attendee)) { |
|
378 | - return array_shift($attendee); |
|
379 | - } |
|
380 | - return false; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Search for an existing Attendee record in the DB |
|
387 | - * |
|
388 | - * @param array $where_cols_n_values |
|
389 | - * @return bool|mixed |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function find_existing_attendee($where_cols_n_values = null) |
|
393 | - { |
|
394 | - // search by combo of first and last names plus the email address |
|
395 | - $attendee_data_keys = array( |
|
396 | - 'ATT_fname' => $this->_ATT_fname, |
|
397 | - 'ATT_lname' => $this->_ATT_lname, |
|
398 | - 'ATT_email' => $this->_ATT_email, |
|
399 | - ); |
|
400 | - // no search params means attendee object already exists. |
|
401 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
402 | - ? $where_cols_n_values |
|
403 | - : $attendee_data_keys; |
|
404 | - $valid_data = true; |
|
405 | - // check for required values |
|
406 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
407 | - ? $valid_data |
|
408 | - : false; |
|
409 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
410 | - ? $valid_data |
|
411 | - : false; |
|
412 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
413 | - ? $valid_data |
|
414 | - : false; |
|
415 | - if ($valid_data) { |
|
416 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
417 | - if ($attendee instanceof EE_Attendee) { |
|
418 | - return $attendee; |
|
419 | - } |
|
420 | - } |
|
421 | - return false; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Takes an incoming array of EE_Registration ids |
|
428 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
429 | - * |
|
430 | - * @since 4.3.0 |
|
431 | - * @param array $ids array of EE_Registration ids |
|
432 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
433 | - * @throws EE_Error |
|
434 | - */ |
|
435 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
436 | - { |
|
437 | - $ids = (array) $ids; |
|
438 | - $_where = array( |
|
439 | - 'Registration.REG_ID' => array('in', $ids), |
|
440 | - ); |
|
441 | - return $this->get_all(array($_where)); |
|
442 | - } |
|
50 | + |
|
51 | + /** |
|
52 | + * @deprecated |
|
53 | + */ |
|
54 | + const city_question_id = 6; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @deprecated |
|
59 | + */ |
|
60 | + const state_question_id = 7; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @deprecated |
|
65 | + */ |
|
66 | + const country_question_id = 8; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @deprecated |
|
71 | + */ |
|
72 | + const zip_question_id = 9; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @deprecated |
|
77 | + */ |
|
78 | + const phone_question_id = 10; |
|
79 | + |
|
80 | + /** |
|
81 | + * When looking for questions that correspond to attendee fields, |
|
82 | + * look for the question with this QST_system value. |
|
83 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | + */ |
|
85 | + const system_question_fname = 'fname'; |
|
86 | + |
|
87 | + const system_question_lname = 'lname'; |
|
88 | + |
|
89 | + const system_question_email = 'email'; |
|
90 | + |
|
91 | + const system_question_email_confirm = 'email_confirm'; |
|
92 | + |
|
93 | + const system_question_address = 'address'; |
|
94 | + |
|
95 | + const system_question_address2 = 'address2'; |
|
96 | + |
|
97 | + const system_question_city = 'city'; |
|
98 | + |
|
99 | + const system_question_state = 'state'; |
|
100 | + |
|
101 | + const system_question_country = 'country'; |
|
102 | + |
|
103 | + const system_question_zip = 'zip'; |
|
104 | + |
|
105 | + const system_question_phone = 'phone'; |
|
106 | + |
|
107 | + /** |
|
108 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
109 | + * also all the values of QST_system in the questions table, and values |
|
110 | + * are their corresponding Attendee field names |
|
111 | + * |
|
112 | + * @var array |
|
113 | + */ |
|
114 | + protected $_system_question_to_attendee_field_name = array( |
|
115 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
116 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
117 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
118 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
119 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
120 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
121 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
122 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
123 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
124 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
125 | + ); |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * EEM_Attendee constructor. |
|
131 | + * |
|
132 | + * @param null $timezone |
|
133 | + * @param ModelFieldFactory $model_field_factory |
|
134 | + * @throws EE_Error |
|
135 | + * @throws InvalidArgumentException |
|
136 | + */ |
|
137 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
138 | + { |
|
139 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
140 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
141 | + $this->_tables = array( |
|
142 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
143 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
144 | + 'esp_attendee_meta', |
|
145 | + 'ATTM_ID', |
|
146 | + 'ATT_ID' |
|
147 | + ), |
|
148 | + ); |
|
149 | + $this->_fields = array( |
|
150 | + 'Attendee_CPT' => array( |
|
151 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
152 | + 'ID', |
|
153 | + esc_html__('Attendee ID', 'event_espresso') |
|
154 | + ), |
|
155 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
156 | + 'post_title', |
|
157 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
158 | + false, |
|
159 | + esc_html__('Unknown', 'event_espresso') |
|
160 | + ), |
|
161 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
162 | + 'post_content', |
|
163 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
164 | + false, |
|
165 | + esc_html__('No Biography Provided', 'event_espresso') |
|
166 | + ), |
|
167 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
168 | + 'post_name', |
|
169 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
170 | + ), |
|
171 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
172 | + 'post_date', |
|
173 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
174 | + ), |
|
175 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
176 | + 'post_excerpt', |
|
177 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
178 | + true, |
|
179 | + esc_html__('No Biography Provided', 'event_espresso') |
|
180 | + ), |
|
181 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
182 | + 'post_modified', |
|
183 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
184 | + ), |
|
185 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
186 | + 'post_author', |
|
187 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
188 | + false |
|
189 | + ), |
|
190 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
191 | + 'post_parent', |
|
192 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
193 | + false, |
|
194 | + 0 |
|
195 | + ), |
|
196 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
197 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
198 | + 'post_status', |
|
199 | + esc_html__('Attendee Status', 'event_espresso'), |
|
200 | + false, |
|
201 | + 'publish' |
|
202 | + ), |
|
203 | + 'password' => new EE_Password_Field( |
|
204 | + 'post_password', |
|
205 | + __('Password', 'event_espresso'), |
|
206 | + false, |
|
207 | + '', |
|
208 | + array( |
|
209 | + 'ATT_bio', |
|
210 | + 'ATT_short_bio', |
|
211 | + 'ATT_address', |
|
212 | + 'ATT_address2', |
|
213 | + 'ATT_city', |
|
214 | + 'STA_ID', |
|
215 | + 'CNT_ISO', |
|
216 | + 'ATT_zip', |
|
217 | + 'ATT_email', |
|
218 | + 'ATT_phone' |
|
219 | + ) |
|
220 | + ) |
|
221 | + ), |
|
222 | + 'Attendee_Meta' => array( |
|
223 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
224 | + 'ATTM_ID', |
|
225 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
226 | + false |
|
227 | + ), |
|
228 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
229 | + 'ATT_ID', |
|
230 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
231 | + false |
|
232 | + ), |
|
233 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
234 | + 'ATT_fname', |
|
235 | + esc_html__('First Name', 'event_espresso') |
|
236 | + ), |
|
237 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
238 | + 'ATT_lname', |
|
239 | + esc_html__('Last Name', 'event_espresso') |
|
240 | + ), |
|
241 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
242 | + 'ATT_address', |
|
243 | + esc_html__('Address Part 1', 'event_espresso') |
|
244 | + ), |
|
245 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
246 | + 'ATT_address2', |
|
247 | + esc_html__('Address Part 2', 'event_espresso') |
|
248 | + ), |
|
249 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
250 | + 'ATT_city', |
|
251 | + esc_html__('City', 'event_espresso') |
|
252 | + ), |
|
253 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
254 | + 'STA_ID', |
|
255 | + esc_html__('State', 'event_espresso'), |
|
256 | + true, |
|
257 | + 0, |
|
258 | + 'State' |
|
259 | + ), |
|
260 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
261 | + 'CNT_ISO', |
|
262 | + esc_html__('Country', 'event_espresso'), |
|
263 | + true, |
|
264 | + '', |
|
265 | + 'Country' |
|
266 | + ), |
|
267 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
268 | + 'ATT_zip', |
|
269 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
270 | + ), |
|
271 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
272 | + 'ATT_email', |
|
273 | + esc_html__('Email Address', 'event_espresso') |
|
274 | + ), |
|
275 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
276 | + 'ATT_phone', |
|
277 | + esc_html__('Phone', 'event_espresso') |
|
278 | + ), |
|
279 | + ), |
|
280 | + ); |
|
281 | + $this->_model_relations = array( |
|
282 | + 'Registration' => new EE_Has_Many_Relation(), |
|
283 | + 'State' => new EE_Belongs_To_Relation(), |
|
284 | + 'Country' => new EE_Belongs_To_Relation(), |
|
285 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
286 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
287 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
288 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
289 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | + ); |
|
292 | + $this->_caps_slug = 'contacts'; |
|
293 | + $this->model_chain_to_password = ''; |
|
294 | + parent::__construct($timezone); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
301 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
302 | + * |
|
303 | + * @param string $system_question_string |
|
304 | + * @return string|null if not found |
|
305 | + */ |
|
306 | + public function get_attendee_field_for_system_question($system_question_string) |
|
307 | + { |
|
308 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
309 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
310 | + : null; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
317 | + * |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + public function system_question_to_attendee_field_mapping() |
|
321 | + { |
|
322 | + return $this->_system_question_to_attendee_field_name; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
329 | + * |
|
330 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
331 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
335 | + { |
|
336 | + return $this->get_all( |
|
337 | + array( |
|
338 | + array( |
|
339 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
340 | + ? $transaction_id_or_obj->ID() |
|
341 | + : $transaction_id_or_obj, |
|
342 | + ), |
|
343 | + ) |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * retrieve a single attendee from db via their ID |
|
351 | + * |
|
352 | + * @param $ATT_ID |
|
353 | + * @return mixed array on success, FALSE on fail |
|
354 | + * @deprecated |
|
355 | + */ |
|
356 | + public function get_attendee_by_ID($ATT_ID = false) |
|
357 | + { |
|
358 | + // retrieve a particular EE_Attendee |
|
359 | + return $this->get_one_by_ID($ATT_ID); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * retrieve a single attendee from db via their ID |
|
366 | + * |
|
367 | + * @param array $where_cols_n_values |
|
368 | + * @return mixed array on success, FALSE on fail |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public function get_attendee($where_cols_n_values = array()) |
|
372 | + { |
|
373 | + if (empty($where_cols_n_values)) { |
|
374 | + return false; |
|
375 | + } |
|
376 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
377 | + if (! empty($attendee)) { |
|
378 | + return array_shift($attendee); |
|
379 | + } |
|
380 | + return false; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Search for an existing Attendee record in the DB |
|
387 | + * |
|
388 | + * @param array $where_cols_n_values |
|
389 | + * @return bool|mixed |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function find_existing_attendee($where_cols_n_values = null) |
|
393 | + { |
|
394 | + // search by combo of first and last names plus the email address |
|
395 | + $attendee_data_keys = array( |
|
396 | + 'ATT_fname' => $this->_ATT_fname, |
|
397 | + 'ATT_lname' => $this->_ATT_lname, |
|
398 | + 'ATT_email' => $this->_ATT_email, |
|
399 | + ); |
|
400 | + // no search params means attendee object already exists. |
|
401 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
402 | + ? $where_cols_n_values |
|
403 | + : $attendee_data_keys; |
|
404 | + $valid_data = true; |
|
405 | + // check for required values |
|
406 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
407 | + ? $valid_data |
|
408 | + : false; |
|
409 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
410 | + ? $valid_data |
|
411 | + : false; |
|
412 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
413 | + ? $valid_data |
|
414 | + : false; |
|
415 | + if ($valid_data) { |
|
416 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
417 | + if ($attendee instanceof EE_Attendee) { |
|
418 | + return $attendee; |
|
419 | + } |
|
420 | + } |
|
421 | + return false; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Takes an incoming array of EE_Registration ids |
|
428 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
429 | + * |
|
430 | + * @since 4.3.0 |
|
431 | + * @param array $ids array of EE_Registration ids |
|
432 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
433 | + * @throws EE_Error |
|
434 | + */ |
|
435 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
436 | + { |
|
437 | + $ids = (array) $ids; |
|
438 | + $_where = array( |
|
439 | + 'Registration.REG_ID' => array('in', $ids), |
|
440 | + ); |
|
441 | + return $this->get_all(array($_where)); |
|
442 | + } |
|
443 | 443 | } |
@@ -10,29 +10,29 @@ |
||
10 | 10 | class EE_Email_Confirm_Input extends EE_Form_Input_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | - $this->_add_validation_strategy( |
|
21 | - new EE_Email_Validation_Strategy( |
|
22 | - isset($input_settings['validation_error_message']) |
|
23 | - ? $input_settings['validation_error_message'] |
|
24 | - : null |
|
25 | - ) |
|
26 | - ); |
|
27 | - $this->_add_validation_strategy( |
|
28 | - new EE_Equal_To_Validation_Strategy( |
|
29 | - isset($input_settings['validation_error_message']) |
|
30 | - ? $input_settings['validation_error_message'] |
|
31 | - : null, |
|
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | - ) |
|
34 | - ); |
|
35 | - parent::__construct($input_settings); |
|
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
37 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | + $this->_add_validation_strategy( |
|
21 | + new EE_Email_Validation_Strategy( |
|
22 | + isset($input_settings['validation_error_message']) |
|
23 | + ? $input_settings['validation_error_message'] |
|
24 | + : null |
|
25 | + ) |
|
26 | + ); |
|
27 | + $this->_add_validation_strategy( |
|
28 | + new EE_Equal_To_Validation_Strategy( |
|
29 | + isset($input_settings['validation_error_message']) |
|
30 | + ? $input_settings['validation_error_message'] |
|
31 | + : null, |
|
32 | + '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | + ) |
|
34 | + ); |
|
35 | + parent::__construct($input_settings); |
|
36 | + $this->set_html_class($this->html_class() . ' email'); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,10 +29,10 @@ |
||
29 | 29 | isset($input_settings['validation_error_message']) |
30 | 30 | ? $input_settings['validation_error_message'] |
31 | 31 | : null, |
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
32 | + '#'.str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | parent::__construct($input_settings); |
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
36 | + $this->set_html_class($this->html_class().' email'); |
|
37 | 37 | } |
38 | 38 | } |
@@ -15,49 +15,49 @@ |
||
15 | 15 | class EE_Equal_To_Validation_Strategy extends EE_Text_Validation_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - protected $_compare_to = null; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * @param string $validation_error_message |
|
23 | - */ |
|
24 | - public function __construct($validation_error_message = '', $compare_to) |
|
25 | - { |
|
26 | - if (! $validation_error_message) { |
|
27 | - $validation_error_message = apply_filters( |
|
28 | - 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | - esc_html__('Fields do not match.', 'event_espresso') |
|
30 | - ); |
|
31 | - } |
|
32 | - parent::__construct($validation_error_message); |
|
33 | - $this->_compare_to = $compare_to; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * just checks the field isn't blank |
|
40 | - * |
|
41 | - * @param $normalized_value |
|
42 | - * @return bool |
|
43 | - * @throws InvalidArgumentException |
|
44 | - * @throws InvalidInterfaceException |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws EE_Validation_Error |
|
47 | - */ |
|
48 | - public function validate($normalized_value) |
|
49 | - { |
|
50 | - // No need to be validated |
|
51 | - return true; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function get_jquery_validation_rule_array() |
|
60 | - { |
|
61 | - return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | - } |
|
18 | + protected $_compare_to = null; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * @param string $validation_error_message |
|
23 | + */ |
|
24 | + public function __construct($validation_error_message = '', $compare_to) |
|
25 | + { |
|
26 | + if (! $validation_error_message) { |
|
27 | + $validation_error_message = apply_filters( |
|
28 | + 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | + esc_html__('Fields do not match.', 'event_espresso') |
|
30 | + ); |
|
31 | + } |
|
32 | + parent::__construct($validation_error_message); |
|
33 | + $this->_compare_to = $compare_to; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * just checks the field isn't blank |
|
40 | + * |
|
41 | + * @param $normalized_value |
|
42 | + * @return bool |
|
43 | + * @throws InvalidArgumentException |
|
44 | + * @throws InvalidInterfaceException |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws EE_Validation_Error |
|
47 | + */ |
|
48 | + public function validate($normalized_value) |
|
49 | + { |
|
50 | + // No need to be validated |
|
51 | + return true; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function get_jquery_validation_rule_array() |
|
60 | + { |
|
61 | + return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | + } |
|
63 | 63 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct($validation_error_message = '', $compare_to) |
25 | 25 | { |
26 | - if (! $validation_error_message) { |
|
26 | + if ( ! $validation_error_message) { |
|
27 | 27 | $validation_error_message = apply_filters( |
28 | 28 | 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
29 | 29 | esc_html__('Fields do not match.', 'event_espresso') |