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.SalesRepForm.class.php

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

377 lines 9.5 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 sales rep form on the front end.
5 *
6 * @since 3.0.0
7 */
8 class ewdotpViewSalesRepForm extends ewdotpView {
9
10 // Holds any matching orders based on submitted Sales Rep ID and (optionally) email
11 public $sales_rep_orders = array();
12
13 /**
14 * Render the view and enqueue required stylesheets
15 * @since 3.0.0
16 */
17 public function render() {
18 global $ewd_otp_controller;
19
20 $this->set_sales_rep_orders();
21
22 $this->set_sales_rep_options();
23
24 // Add any dependent stylesheets or javascript
25 $this->enqueue_assets();
26
27 // Add css classes to the slider
28 $this->classes = $this->get_classes();
29
30 ob_start();
31
32 $this->add_custom_styling();
33
34 $template = $this->find_template( 'sales-rep-form' );
35
36 if ( $template ) {
37 include( $template );
38 }
39
40 $output = ob_get_clean();
41
42 return apply_filters( 'ewd_otp_sales_rep_form_output', $output, $this );
43 }
44
45 /**
46 * Print the sales rep's orders, if any
47 *
48 * @since 3.0.0
49 */
50 public function maybe_print_sales_rep_results() {
51
52 $form_submitted = isset($_POST['ewd_otp_form_type']) && 'sales_rep_form' == $_POST['ewd_otp_form_type'];
53
54 if ( $form_submitted && empty( $this->sales_rep_orders ) ) {
55
56 $this->error_message = __( 'No orders were found associated with the submitted sales rep number', 'order-tracking' );
57
58 $this->print_error_message();
59
60 return;
61 }
62
63 if ( empty( $this->sales_rep_orders ) ) { return; }
64
65 $template = $this->find_template( 'sales-rep-results' );
66
67 if ( $template ) {
68 include( $template );
69 }
70 }
71
72 /**
73 * Print the sales rep ID input
74 *
75 * @since 3.0.0
76 */
77 public function print_sales_rep_identifier_input() {
78
79 $template = $this->find_template( 'form-identifier-number' );
80
81 if ( $template ) {
82 include( $template );
83 }
84 }
85
86 /**
87 * Print the sales rep email input, if enabled
88 *
89 * @since 3.0.0
90 */
91 public function maybe_print_sales_rep_email_input() {
92 global $ewd_otp_controller;
93
94 if ( ! $ewd_otp_controller->settings->get_setting( 'email-verification' ) ) { return; }
95
96 $template = $this->find_template( 'form-email' );
97
98 if ( $template ) {
99 include( $template );
100 }
101 }
102
103 /**
104 * Print the sales rep's first name, if selected
105 *
106 * @since 3.0.0
107 */
108 public function maybe_print_sales_rep_first_name() {
109 global $ewd_otp_controller;
110
111 if ( ! in_array( 'sales_rep_first_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
112
113 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->first_name ) ) ) { return; }
114
115 $template = $this->find_template( 'sales-rep-first-name' );
116
117 if ( $template ) {
118 include( $template );
119 }
120 }
121
122 /**
123 * Print the sales rep's last name, if selected
124 *
125 * @since 3.0.0
126 */
127 public function maybe_print_sales_rep_last_name() {
128 global $ewd_otp_controller;
129
130 if ( ! in_array( 'sales_rep_last_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
131
132 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->last_name ) ) ) { return; }
133
134 $template = $this->find_template( 'sales-rep-last-name' );
135
136 if ( $template ) {
137 include( $template );
138 }
139 }
140
141 /**
142 * Print the sales rep's email, if selected
143 *
144 * @since 3.0.0
145 */
146 public function maybe_print_sales_rep_email() {
147 global $ewd_otp_controller;
148
149 if ( ! in_array( 'sales_rep_email', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return; }
150
151 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->email ) ) ) { return; }
152
153 $template = $this->find_template( 'sales-rep-email' );
154
155 if ( $template ) {
156 include( $template );
157 }
158 }
159
160 /**
161 * Print any custom fields that should be displayed
162 *
163 * @since 3.0.0
164 */
165 public function print_sales_rep_custom_fields() {
166 global $ewd_otp_controller;
167
168 $custom_fields = $ewd_otp_controller->settings->get_sales_rep_custom_fields();
169
170 foreach ( $custom_fields as $custom_field ) {
171
172 if ( ! $custom_field->front_end_display ) { continue; }
173
174 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->custom_fields[ $custom_field->id ] ) ) ) { continue; }
175
176 $custom_field->value = $this->sales_rep->custom_fields[ $custom_field->id ];
177
178 $this->custom_field = $custom_field;
179
180 $this->print_custom_field();
181 }
182 }
183
184 /**
185 * Print the header for the sales rep orders table
186 *
187 * @since 3.0.0
188 */
189 public function print_sales_rep_orders_header() {
190
191 $template = $this->find_template( 'matching-order-header' );
192
193 if ( $template ) {
194 include( $template );
195 }
196 }
197
198 /**
199 * Print the orders for the sales rep orders table
200 *
201 * @since 3.0.0
202 */
203 public function print_sales_rep_orders() {
204
205 $template = $this->find_template( 'matching-order' );
206
207 foreach ( $this->sales_rep_orders as $order ) {
208
209 $this->current_order = $order;
210
211 if ( $template ) {
212 include( $template );
213 }
214 }
215 }
216
217 /**
218 * Print the download button for sales rep orders, if enabled
219 *
220 * @since 3.0.0
221 */
222 public function maybe_print_sales_rep_download_button() {
223 global $ewd_otp_controller;
224
225 if ( empty( $ewd_otp_controller->settings->get_setting( 'allow-sales-rep-downloads' ) ) ) { return; }
226
227 $template = $this->find_template( 'sales-rep-download-button' );
228
229 if ( $template ) {
230 include( $template );
231 }
232 }
233
234 /**
235 * Print the sales rep form submit button
236 *
237 * @since 3.0.0
238 */
239 public function print_sales_rep_form_submit() {
240
241 $template = $this->find_template( 'form-submit' );
242
243 if ( $template ) {
244 include( $template );
245 }
246 }
247
248 /**
249 * Returns the placeholder for the sales rep number field
250 *
251 * @since 3.0.0
252 */
253 public function get_identifier_placeholder_label() {
254
255 return $this->get_label( 'label-sales-rep-form-number-placeholder' );
256 }
257
258 /**
259 * Returns the placeholder for the sales rep email field
260 *
261 * @since 3.0.0
262 */
263 public function get_email_placeholder_label() {
264
265 return $this->get_label( 'label-sales-rep-form-email-placeholder' );
266 }
267
268 /**
269 * Returns true if a link to order tracking results should be included, false otherwise
270 *
271 * @since 3.0.0
272 */
273 public function include_separate_tracking_link() {
274
275 if ( empty( $this->get_option( 'disable-ajax-loading' ) ) ) { return false; }
276
277 if ( empty( $this->get_option( 'tracking-page-url' ) ) ) { return false; }
278
279 return true;
280 }
281
282 /**
283 * Get the initial sales rep css classes
284 * @since 3.0.0
285 */
286 public function get_classes( $classes = array() ) {
287 global $ewd_otp_controller;
288
289 $classes = array_merge(
290 $classes,
291 array(
292 'ewd-otp-sales-rep-form-div',
293 'ewd-otp-form'
294 )
295 );
296
297 if ( ! empty( $ewd_otp_controller->settings->get_setting( 'disable-ajax-loading' ) ) ) {
298
299 $classes[] = 'ewd-otp-disable-ajax';
300 }
301
302 return apply_filters( 'ewd_otp_sales_rep_form_classes', $classes, $this );
303 }
304
305 /**
306 * Allow some parameters to be overwritten with $_REQUEST parameters
307 * @since 3.0.0
308 */
309 public function set_request_parameters() {
310 global $ewd_otp_controller;
311
312 if ( empty( $_POST['ewd_otp_form_type'] ) or $_POST['ewd_otp_form_type'] != 'sales_rep_form' ) { return; }
313
314 if ( empty( $_POST['ewd_otp_identifier_number'] ) ) { return; }
315
316 $sales_rep = new ewdotpSalesRep();
317
318 $sales_rep->load_sales_rep_from_number( sanitize_text_field( trim( $_POST['ewd_otp_identifier_number'] ) ) );
319
320 if ( $ewd_otp_controller->settings->get_setting( 'email-verification' ) and ! $sales_rep->verify_sales_rep_email( sanitize_email( $_POST['ewd_otp_form_email'] ) ) ) { return; }
321
322 $this->sales_rep = $sales_rep;
323 }
324
325 /**
326 * If a sales rep is set, fetch their matching orders
327 * @since 3.0.0
328 */
329 public function set_sales_rep_orders() {
330
331 if ( empty( $this->sales_rep->id ) ) { return; }
332
333 $args = array(
334 'after' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
335 'orders_per_page' => -1
336 );
337
338 $this->sales_rep_orders = $this->sales_rep->get_sales_rep_orders( $args );
339 }
340
341 /**
342 * Add in default options when displaying in the admin appointments area
343 *
344 * @since 3.0.0
345 */
346 public function set_sales_rep_options() {
347 global $ewd_otp_controller;
348
349 $this->nonce = wp_create_nonce( basename( __FILE__ ) );
350 $this->sales_rep_form_title = ! empty( $this->order_form_title ) ? $this->order_form_title : $this->get_label( 'label-sales-rep-form-title' );
351 $this->sales_rep_form_instructions = ! empty( $this->order_instructions ) ? $this->order_instructions : $this->get_label( 'label-sales-rep-form-instructions' );
352 $this->order_field_text = ! empty( $this->order_field_text ) ? $this->order_field_text : $this->get_label( 'label-sales-rep-form-number' );
353 $this->email_field_text = ! empty( $this->email_field_text ) ? $this->email_field_text : $this->get_label( 'label-sales-rep-form-email' );
354 $this->submit_text = ! empty( $this->submit_text ) ? $this->submit_text : $this->get_label( 'label-sales-rep-form-button' );
355 }
356
357 /**
358 * Enqueue the necessary CSS and JS files
359 * @since 3.0.0
360 */
361 public function enqueue_assets() {
362 global $ewd_otp_controller;
363
364 wp_enqueue_style( 'ewd-otp-css' );
365
366 $args = array(
367 'nonce' => wp_create_nonce( 'ewd-otp-js' ),
368 'retrieving_results' => $ewd_otp_controller->settings->get_setting( 'label-retrieving-results' ),
369 'customer_notes_submit' => $this->get_label( 'label-order-add-note-button' )
370 );
371
372 $ewd_otp_controller->add_front_end_php_data( 'ewd-otp-js', 'ewd_otp_php_data', $args );
373
374 wp_enqueue_script( 'ewd-otp-js' );
375 }
376 }
377