PluginProbe
Order Tracking – WordPress Status Tracking Plugin / 3.2.2
Order Tracking – WordPress Status Tracking Plugin v3.2.2
3.5.4 3.5.3 3.5.2 3.5.1 3.5.0 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.3.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 All 235 releases
order-tracking / views / View.OrderForm.class.php

View.OrderForm.class.php in Order Tracking – WordPress Status Tracking Plugin 3.2.2, at views/View.OrderForm.class.php

487 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class to display the order tracking form on the front end.
5 *
6 * @since 3.0.0
7 */
8 class ewdotpViewOrderForm extends ewdotpView {
9
10 /**
11 * Render the view and enqueue required stylesheets
12 * @since 3.0.0
13 */
14 public function render() {
15 global $ewd_otp_controller;
16
17 $this->set_order_form_options();
18
19 $this->get_order_results();
20
21 // Add any dependent stylesheets or javascript
22 $this->enqueue_assets();
23
24 // Add css classes to the slider
25 $this->classes = $this->get_classes();
26
27 ob_start();
28
29 $this->add_custom_styling();
30
31 $template = $this->find_template( 'order-form' );
32
33 if ( $template ) {
34 include( $template );
35 }
36
37 $output = ob_get_clean();
38
39 return apply_filters( 'ewd_otp_order_form_output', $output, $this );
40 }
41
42 /**
43 * Print the matching order, if any
44 *
45 * @since 3.0.0
46 */
47 public function maybe_print_order_results() {
48
49 if ( empty( $this->order ) ) { return; }
50
51 $this->order->increase_view_count();
52
53 $template = $this->find_template( 'order-results' );
54
55 if ( $template ) {
56 include( $template );
57 }
58 }
59
60 /**
61 * Print the order number input
62 *
63 * @since 3.0.0
64 */
65 public function print_order_number_input() {
66
67 $template = $this->find_template( 'form-identifier-number' );
68
69 if ( $template ) {
70 include( $template );
71 }
72 }
73
74 /**
75 * Print the order email input, if enabled
76 *
77 * @since 3.0.0
78 */
79 public function maybe_print_order_email_input() {
80 global $ewd_otp_controller;
81
82 if ( ! $ewd_otp_controller->settings->get_setting( 'email-verification' ) ) { return; }
83
84 $template = $this->find_template( 'form-email' );
85
86 if ( $template ) {
87 include( $template );
88 }
89 }
90
91 /**
92 * Print any custom fields that should be displayed
93 *
94 * @since 3.0.0
95 */
96 public function print_order_custom_fields() {
97 global $ewd_otp_controller;
98
99 $custom_fields = $ewd_otp_controller->settings->get_order_custom_fields();
100
101 foreach ( $custom_fields as $custom_field ) {
102
103 if ( ! $custom_field->front_end_display ) { continue; }
104
105 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->custom_fields[ $custom_field->id ] ) ) ) { continue; }
106
107 $custom_field->value = $this->order->custom_fields[ $custom_field->id ];
108
109 $this->custom_field = $custom_field;
110
111 $this->print_custom_field();
112 }
113 }
114
115 /**
116 * Print links to all orders that exist
117 *
118 * @since 3.0.0
119 */
120 public function print_all_available_order_links() {
121 global $ewd_otp_controller;
122
123 $template = $this->find_template( 'order-form-all-available-order-links' );
124
125 if ( $template ) {
126 include( $template );
127 }
128 }
129
130 /**
131 * Print the order tracking graphic, if enabled
132 *
133 * @since 3.0.0
134 */
135 public function maybe_print_order_graphic() {
136 global $ewd_otp_controller;
137
138 if ( ! in_array( 'order_graphic', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
139
140 if ( in_array( $ewd_otp_controller->settings->get_setting( 'tracking-graphic' ), array( 'default', 'streamlined', 'sleek' ) ) ) {
141
142 $template = $this->find_template( 'order-graphic-image' );
143 }
144 else { $template = $this->find_template( 'order-graphic-progress' ); }
145
146 if ( $template ) {
147 include( $template );
148 }
149 }
150
151 /**
152 * Print the order payment link, if enabled
153 *
154 * @since 3.0.0
155 */
156 public function maybe_print_order_payment() {
157 global $ewd_otp_controller;
158
159 if ( empty( $ewd_otp_controller->settings->get_setting( 'allow-order-payments' ) ) ) { return; }
160
161 if ( empty( $this->order ) or empty( $this->order->payment_price ) ) { return; }
162
163 $template = $this->find_template( 'order-payment' );
164
165 if ( $template ) {
166 include( $template );
167 }
168 }
169
170 /**
171 * Print the order map, if enabled
172 *
173 * @since 3.0.0
174 */
175 public function maybe_print_order_map() {
176 global $ewd_otp_controller;
177
178 if ( ! in_array( 'order_map', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
179
180 if ( empty( $this->order ) or empty( $this->order->current_location->latitude ) or empty( $this->order->current_location->longitude ) ) { return; }
181
182 $template = $this->find_template( 'order-map' );
183
184 if ( $template ) {
185 include( $template );
186 }
187 }
188
189 /**
190 * Print the order statuses header
191 *
192 * @since 3.0.0
193 */
194 public function print_order_statuses_header() {
195 global $ewd_otp_controller;
196
197 $template = $this->find_template( 'order-statuses-header' );
198
199 if ( $template ) {
200 include( $template );
201 }
202 }
203
204 /**
205 * Print the order statuses
206 *
207 * @since 3.0.0
208 */
209 public function print_order_statuses() {
210 global $ewd_otp_controller;
211
212 $template = $this->find_template( 'order-statuses' );
213
214 if ( $template ) {
215 include( $template );
216 }
217 }
218
219 /**
220 * Print the order statuses
221 *
222 * @since 3.0.0
223 */
224 public function maybe_print_order_update_location_and_status() {
225 global $ewd_otp_controller;
226
227 $current_user_cannot = !current_user_can( $ewd_otp_controller->settings->get_setting( 'access-role' ) );
228 $order_has_no_sales_rep = 1 > intval( $this->order->sales_rep );
229 $different_sales_rep = get_current_user_id() !== intval( $this->order->get_sales_rep_wp_id() );
230
231 if ( $current_user_cannot and ( $order_has_no_sales_rep or $different_sales_rep) ) {
232 return;
233 }
234
235 $template = $this->find_template( 'order-update-status-and-location' );
236
237 if ( $template ) {
238 include( $template );
239 }
240 }
241
242 /**
243 * Print the order form submit button
244 *
245 * @since 3.0.0
246 */
247 public function print_order_form_submit() {
248
249 $template = $this->find_template( 'form-submit' );
250
251 if ( $template ) {
252 include( $template );
253 }
254 }
255
256 /**
257 * Return all available statuses
258 *
259 * @since 3.0.0
260 */
261 public function get_possible_statuses() {
262 global $ewd_otp_controller;
263
264 return ewd_otp_decode_infinite_table_setting( $ewd_otp_controller->settings->get_setting( 'statuses' ) );
265 }
266
267 /**
268 * Return all available locations
269 *
270 * @since 3.0.0
271 */
272 public function get_possible_locations() {
273 global $ewd_otp_controller;
274
275 return ewd_otp_decode_infinite_table_setting( $ewd_otp_controller->settings->get_setting( 'locations' ) );
276 }
277
278 /**
279 * Return the lowest percentage status
280 *
281 * @since 3.0.0
282 */
283 public function get_starting_status() {
284 global $ewd_otp_controller;
285
286 $statuses = ewd_otp_decode_infinite_table_setting( $ewd_otp_controller->settings->get_setting( 'statuses' ) );
287
288 $starting_status = reset( $statuses );
289
290 return $starting_status->status;
291 }
292
293 /**
294 * Return the highest percentage status
295 *
296 * @since 3.0.0
297 */
298 public function get_ending_status() {
299 global $ewd_otp_controller;
300
301 $statuses = ewd_otp_decode_infinite_table_setting( $ewd_otp_controller->settings->get_setting( 'statuses' ) );
302
303 $highest_status = reset( $statuses );
304
305 foreach ( $statuses as $status ) {
306
307 if ( $status->percentage > $highest_status->percentage ) { $highest_status = $status; }
308 }
309
310 return $highest_status->status;
311 }
312
313 /**
314 * Returns all of the orders that currently exist
315 *
316 * @since 3.0.0
317 */
318 public function get_all_orders() {
319 global $ewd_otp_controller;
320
321 $args = array(
322 'orders_per_page' => -1
323 );
324
325 return $ewd_otp_controller->order_manager->get_matching_orders( $args );
326 }
327
328 /**
329 * Returns the placeholder for the order number field
330 *
331 * @since 3.0.0
332 */
333 public function get_identifier_placeholder_label() {
334
335 return $this->get_label( 'label-order-form-number-placeholder' );
336 }
337
338 /**
339 * Returns the placeholder for the order email field
340 *
341 * @since 3.0.0
342 */
343 public function get_email_placeholder_label() {
344
345 return $this->get_label( 'label-order-form-email-placeholder' );
346 }
347
348 /**
349 * Get the initial order form css classes
350 * @since 3.0.0
351 */
352 public function get_classes( $classes = array() ) {
353 global $ewd_otp_controller;
354
355 $classes = array_merge(
356 $classes,
357 array(
358 'ewd-otp-form',
359 'ewd-otp-tracking-form-div'
360 )
361 );
362
363 if ( ! empty( $ewd_otp_controller->settings->get_setting( 'disable-ajax-loading' ) ) ) {
364
365 $classes[] = 'ewd-otp-disable-ajax';
366 }
367
368 return apply_filters( 'ewd_otp_order_form_classes', $classes, $this );
369 }
370
371 /**
372 * Allow some parameters to be overwritten with URL parameters, find a specific order
373 * @since 3.0.0
374 */
375 public function get_order_results() {
376 global $ewd_otp_controller;
377
378 if ( empty( $_POST['ewd_otp_form_type'] ) or $_POST['ewd_otp_form_type'] != 'order_form' ) { return; }
379
380 if ( empty( $_POST['ewd_otp_identifier_number'] ) ) { return; }
381
382 $order = new ewdotpOrder();
383
384 $order->load_order_from_tracking_number( sanitize_text_field( $_POST['ewd_otp_identifier_number'] ) );
385
386 if ( empty( $order->id ) ) {
387
388 $this->update_message = __( 'There are no order statuses for tracking number: ', 'order-tracking' ) . sanitize_text_field( $_POST['ewd_otp_identifier_number'] );
389
390 return;
391 }
392
393 if ( $ewd_otp_controller->settings->get_setting( 'email-verification' ) and
394 ! $order->verify_order_email( sanitize_email( $_POST['ewd_otp_form_email'] ) ) and
395 ! $order->verify_order_user( get_current_user_id() ) and
396 ! current_user_can( $ewd_otp_controller->settings->get_setting( 'access-role' ) ) ) {
397
398 $this->update_message = __( 'The email submitted does not match the email associated with this order.', 'order-tracking' );
399
400 return;
401 }
402
403 $this->order = $order;
404
405 $this->order->load_order_status_history();
406
407 $this->customer = new ewdotpCustomer();
408
409 $this->customer->load_customer_from_id( $this->order->customer );
410
411 $this->sales_rep = new ewdotpSalesRep();
412
413 $this->sales_rep->load_sales_rep_from_id( $this->order->sales_rep );
414 }
415
416 /**
417 * Allow some parameters to be overwritten with URL parameters, find a specific order
418 * @since 3.0.0
419 */
420 public function set_request_parameters() {
421 global $ewd_otp_controller;
422
423 if ( empty( $_REQUEST['tracking_number'] ) ) { return; }
424
425 $order = new ewdotpOrder();
426
427 $order->load_order_from_tracking_number( sanitize_text_field( $_REQUEST['tracking_number'] ) );
428
429 if ( $ewd_otp_controller->settings->get_setting( 'email-verification' ) and ! $order->verify_order_email( ( ! empty( $_REQUEST['order_email'] ) ? sanitize_email( $_REQUEST['order_email'] ) : '' ) ) ) { return; }
430
431 if ( ! empty( $_REQUEST['tracking_link_code'] ) ) {
432
433 $order->set_tracking_link_clicked();
434 }
435
436 $this->order = $order;
437
438 $this->order->load_order_status_history();
439
440 $this->customer = new ewdotpCustomer();
441
442 $this->customer->load_customer_from_id( $this->order->customer );
443
444 $this->sales_rep = new ewdotpSalesRep();
445
446 $this->sales_rep->load_sales_rep_from_id( $this->order->sales_rep );
447 }
448
449 /**
450 * Add in default options when displaying in the admin appointments area
451 *
452 * @since 3.0.0
453 */
454 public function set_order_form_options() {
455 global $ewd_otp_controller;
456
457 $this->nonce = wp_create_nonce( basename( __FILE__ ) );
458 $this->show_orders = strtolower( $this->show_orders ) == 'yes' ? true : false;
459 $this->order_form_title = ! empty( $this->order_form_title ) ? $this->order_form_title : $this->get_label( 'label-order-form-title' );
460 $this->order_form_instructions = ! empty( $this->order_instructions ) ? $this->order_instructions : $this->get_option( 'form-instructions' );
461 $this->order_field_text = ! empty( $this->order_field_text ) ? $this->order_field_text : $this->get_label( 'label-order-form-number' );
462 $this->email_field_text = ! empty( $this->email_field_text ) ? $this->email_field_text : $this->get_label( 'label-order-form-email' );
463 $this->customer_notes_submit = ! empty( $this->notes_submit ) ? $this->notes_submit : $this->get_label( 'label-order-add-note-button' );
464 $this->submit_text = ! empty( $this->submit_text ) ? $this->submit_text : $this->get_label( 'label-order-form-button' );
465 }
466
467 /**
468 * Enqueue the necessary CSS and JS files
469 * @since 3.0.0
470 */
471 public function enqueue_assets() {
472 global $ewd_otp_controller;
473
474 wp_enqueue_style( 'ewd-otp-css' );
475
476 $args = array(
477 'nonce' => wp_create_nonce( 'ewd-otp-js' ),
478 'retrieving_results' => $ewd_otp_controller->settings->get_setting( 'label-retrieving-results' ),
479 'customer_notes_submit' => $this->customer_notes_submit
480 );
481
482 $ewd_otp_controller->add_front_end_php_data( 'ewd-otp-js', 'ewd_otp_php_data', $args );
483
484 wp_enqueue_script( 'ewd-otp-js' );
485 }
486 }
487