PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.10
5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / wizard_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 4 months ago auth_controller.php 4 months ago booking_form_settings_controller.php 5 months ago bookings_controller.php 1 year ago calendars_controller.php 9 months ago carts_controller.php 1 year ago controller.php 9 months ago customer_cabinet_controller.php 4 months ago customers_controller.php 4 months ago dashboard_controller.php 9 months ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 9 months ago integrations_controller.php 9 months ago invoices_controller.php 4 months ago manage_booking_by_key_controller.php 4 months ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 4 months ago pro_controller.php 1 year ago process_jobs_controller.php 4 months ago processes_controller.php 4 months ago search_controller.php 1 year ago services_controller.php 9 months ago settings_controller.php 4 months ago steps_controller.php 9 months ago stripe_connect_controller.php 9 months ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 4 months ago wizard_controller.php 4 months ago
wizard_controller.php
376 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsWizardController' ) ) :
8
9
10 class OsWizardController extends OsController {
11
12 var $steps_info, $steps_in_order;
13
14 protected $show_next_btn = false,
15 $show_prev_btn = false;
16
17
18 function __construct() {
19 parent::__construct();
20
21 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'wizard/';
22 $this->vars['page_header'] = __( 'Wizard', 'latepoint' );
23
24 $this->set_layout( 'wizard' );
25 $this->steps_info = array(
26 'default_agent' => array(
27 'show_in_sidemenu' => true,
28 'name' => __( 'Setup Notifications', 'latepoint' )
29 ),
30 'agents' => array( 'show_in_sidemenu' => true, 'name' => __( 'Create Agents', 'latepoint' ) ),
31 'intro' => array( 'show_in_sidemenu' => false, 'name' => __( 'Intro', 'latepoint' ) ),
32 'services' => array( 'show_in_sidemenu' => true, 'name' => __( 'Add Services', 'latepoint' ) ),
33 'work_periods' => array(
34 'show_in_sidemenu' => true,
35 'name' => __( 'Set Working Hours', 'latepoint' )
36 ),
37 'info' => array(
38 'show_in_sidemenu' => true,
39 'name' => __( 'Fill Business Info', 'latepoint' )
40 ),
41 'complete' => array( 'show_in_sidemenu' => true, 'name' => __( 'Setup Complete', 'latepoint' ) ),
42 'personal_info' => array(
43 'show_in_sidemenu' => true,
44 'name' => __( 'Personal Info', 'latepoint' )
45 ),
46 );
47 $this->steps_in_order = array( 'intro', 'default_agent', 'services', 'work_periods', 'personal_info', 'complete' );
48
49 $this->vars['steps_in_order'] = $this->steps_in_order;
50 $this->vars['steps_info'] = $this->steps_info;
51 }
52
53 function save_service() {
54 $this->check_nonce( 'save_service' );
55 $service = new OsServiceModel();
56 $service->set_data( $this->params['service'] );
57
58 if ( $service->save() && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
59 $this->vars['current_step_code'] = 'agents';
60 $this->step_services();
61 $response_html = $this->render( $this->get_view_uri( 'steps/_list_services' ) );
62 $status = LATEPOINT_STATUS_SUCCESS;
63 } else {
64 $response_html = $service->get_error_messages();
65 $status = LATEPOINT_STATUS_ERROR;
66 }
67 if ( $this->get_return_format() == 'json' ) {
68 $this->send_json( array( 'status' => $status,
69 'message' => $response_html,
70 'show_prev_btn' => true,
71 'show_next_btn' => $this->show_next_btn
72 ) );
73 }
74 }
75
76 function save_agent() {
77 $this->check_nonce( 'save_agent' );
78 $agent = new OsAgentModel();
79 $agent->set_data( $this->params['agent'] );
80 if ( $agent->save() ) {
81 $this->vars['current_step_code'] = 'agents';
82 $this->step_agents();
83 $response_html = $this->render( $this->get_view_uri( 'steps/_list_agents' ) );
84 $status = LATEPOINT_STATUS_SUCCESS;
85 } else {
86 $response_html = $agent->get_error_messages();
87 $status = LATEPOINT_STATUS_ERROR;
88 }
89 if ( $this->get_return_format() == 'json' ) {
90 $this->send_json( array( 'status' => $status,
91 'message' => $response_html,
92 'show_prev_btn' => $this->show_prev_btn,
93 'show_next_btn' => $this->show_next_btn
94 ) );
95 }
96 }
97
98
99 function setup() {
100 $current_step_code = $this->steps_in_order[0];
101 $step_function_name = 'step_' . $current_step_code;
102 self::$step_function_name();
103
104 add_option( 'latepoint_wizard_visited', true );
105
106 $this->vars['current_step_code'] = $current_step_code;
107 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
108 $this->vars['step_file_to_include'] = 'steps/_' . $current_step_code . '.php';
109
110 $this->format_render( __FUNCTION__ );
111 }
112
113 function next_step() {
114 $this->show_prev_btn = true;
115 $this->show_next_btn = true;
116
117 // Check if a valid step_code name
118 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
119 $current_step_code = $this->params['current_step_code'];
120 } else {
121 $current_step_code = $this->steps_in_order[0];
122 }
123
124
125 $process_step_function_name = 'process_step_' . $current_step_code;
126 self::$process_step_function_name();
127
128 $new_current_step_code = $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) + 1 ];
129 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
130 $this->show_prev_btn = false;
131 }
132
133 $step_function_name = 'step_' . $new_current_step_code;
134 self::$step_function_name();
135
136 $this->vars['current_step_code'] = $new_current_step_code;
137 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
138 $this->format_render(
139 'steps/_' . $new_current_step_code,
140 array(),
141 array(
142 'step_code' => $new_current_step_code,
143 'show_prev_btn' => $this->show_prev_btn,
144 'show_next_btn' => $this->show_next_btn
145 )
146 );
147 }
148
149 function prev_step() {
150
151 // For every back step there is next step.
152 $this->show_next_btn = true;
153
154 // Check if a valid step_code name.
155 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
156 $current_step_code = $this->params['current_step_code'];
157 } else {
158 $current_step_code = $this->steps_in_order[0];
159 }
160
161 $new_current_step_code = ( array_search( $current_step_code, $this->steps_in_order ) > 0 ) ? $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) - 1 ] : $this->steps_in_order[0];
162 $this->show_prev_btn = array_search( $new_current_step_code, $this->steps_in_order ) > 0;
163
164 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
165 $this->show_prev_btn = false;
166 }
167
168 $step_function_name = 'step_' . $new_current_step_code;
169 self::$step_function_name();
170
171 $this->vars['current_step_code'] = $new_current_step_code;
172 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
173 $this->format_render(
174 'steps/_' . $new_current_step_code,
175 array(),
176 array(
177 'step_code' => $new_current_step_code,
178 'show_prev_btn' => $this->show_prev_btn,
179 'show_next_btn' => $this->show_next_btn
180 )
181 );
182 }
183
184 function load_step() {
185 // Check if a valid step_code name
186 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
187 $current_step_code = $this->params['current_step_code'];
188 } else {
189 $current_step_code = $this->steps_in_order[0];
190 }
191
192 $step_function_name = 'step_' . $current_step_code;
193 self::$step_function_name();
194
195 $this->vars['current_step_code'] = $current_step_code;
196 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
197 $this->format_render( 'steps/_' . $current_step_code, array(), array( 'step_code' => $current_step_code ) );
198 }
199
200 function add_or_edit_agent() {
201 $agents = new OsAgentModel();
202 $this->vars['agents'] = $agents->get_results_as_models();
203
204 $agent = new OsAgentModel();
205 if ( ! empty( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
206 $agent->load_by_id( $this->params['id'] );
207 }
208 $this->vars['agent'] = $agent;
209 $this->format_render( 'steps/_form_agent', array(), array() );
210 }
211
212 function add_or_edit_service() {
213 $services = new OsServiceModel();
214 $this->vars['services'] = $services->get_results_as_models();
215
216 $service = new OsServiceModel();
217 if ( isset( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
218 $service->load_by_id( $this->params['id'] );
219 }
220 $agents = new OsAgentModel();
221 $service_categories = new OsServiceCategoryModel();
222
223 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
224 $this->vars['agents'] = $agents->get_results_as_models();
225 $this->vars['location'] = OsLocationHelper::get_default_location();
226
227 $this->vars['service'] = $service;
228 $this->format_render( 'steps/_form_service', array(), array() );
229 }
230
231
232 function step_services() {
233 $services = new OsServiceModel();
234 $services = $services->get_results_as_models();
235 $this->show_prev_btn = false;
236 $this->vars['services'] = $services;
237 $this->vars['location'] = OsLocationHelper::get_default_location();
238 $agents = new OsAgentModel();
239 $this->vars['agents'] = $agents->get_results_as_models();
240 if ( ! $services ) {
241 $service = new OsServiceModel();
242 $this->vars['service'] = $service;
243 $this->show_next_btn = false;
244 } else {
245 $this->show_next_btn = true;
246 $this->show_prev_btn = true;
247 }
248 }
249
250 function step_agents() {
251 $agents = new OsAgentModel();
252 $agents = $agents->get_results_as_models();
253 $this->vars['agents'] = $agents;
254 $this->show_prev_btn = false;
255 if ( ! $agents ) {
256 $agent = new OsAgentModel();
257 $this->vars['agent'] = $agent;
258 $this->show_next_btn = false;
259 } else {
260 $this->show_next_btn = true;
261 }
262 }
263
264
265 function step_default_agent(){
266
267 $this->vars['agent'] = OsAgentHelper::get_default_agent();
268 $this->show_next_btn = true;
269 }
270
271 function step_work_periods() {
272 $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() );
273 $working_periods_with_weekdays = array();
274 if ( $work_periods ) {
275 foreach ( $work_periods as $work_period ) {
276 $working_periods_with_weekdays[ 'day_' . $work_period->week_day ][] = $work_period;
277 }
278 }
279 $this->vars['working_periods_with_weekdays'] = $working_periods_with_weekdays;
280 }
281
282 function step_intro() {
283 $this->show_next_btn = true;
284 }
285
286
287 function step_settings() {
288
289 }
290
291 function step_personal_info() {
292 $this->vars['wizard_first_name'] = OsSettingsHelper::get_settings_value( 'wizard_first_name', '' );
293 $this->vars['wizard_last_name'] = OsSettingsHelper::get_settings_value( 'wizard_last_name', '' );
294 $this->vars['wizard_email'] = OsSettingsHelper::get_settings_value( 'wizard_email', '' );
295 $this->vars['wizard_email_optin'] = OsSettingsHelper::get_settings_value( 'wizard_email_optin', 'off' );
296 $this->show_next_btn = true;
297 }
298
299 function step_complete() {
300 $this->show_next_btn = false;
301 $this->show_prev_btn = false;
302 }
303
304
305 function process_step_agents() {
306
307 }
308
309 function process_step_services() {
310
311 }
312
313 function process_step_intro() {
314
315 }
316
317 function process_step_default_agent() {
318
319 $default_agent = OsAgentHelper::get_default_agent();
320 if ( ! $default_agent->is_new_record() ) {
321 $default_agent->set_data( $this->params['agent'] );
322 $default_agent->save();
323 }
324
325 }
326
327 function process_step_work_periods() {
328 $work_periods_form_data = $this->params['work_periods'];
329 OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data );
330 }
331
332 function process_step_info() {
333
334 }
335
336 function process_step_personal_info() {
337 $first_name = isset( $this->params['personal_info']['first_name'] ) ? sanitize_text_field( $this->params['personal_info']['first_name'] ) : '';
338 $last_name = isset( $this->params['personal_info']['last_name'] ) ? sanitize_text_field( $this->params['personal_info']['last_name'] ) : '';
339 $email = isset( $this->params['personal_info']['email'] ) ? sanitize_email( $this->params['personal_info']['email'] ) : '';
340 $email_optin = isset( $this->params['personal_info']['email_optin'] ) && $this->params['personal_info']['email_optin'] === 'on' ? 'on' : 'off';
341
342 OsSettingsHelper::save_setting_by_name( 'wizard_first_name', $first_name );
343 OsSettingsHelper::save_setting_by_name( 'wizard_last_name', $last_name );
344 OsSettingsHelper::save_setting_by_name( 'wizard_email', $email );
345 OsSettingsHelper::save_setting_by_name( 'wizard_email_optin', $email_optin );
346
347 if ( $email_optin === 'on' ) {
348 update_option( 'latepoint_usage_optin', 'yes' );
349 }
350
351 $this->send_registration_data( $first_name, $last_name, $email, $email_optin );
352 }
353
354 private function send_registration_data( $first_name, $last_name, $email, $email_optin ) {
355 $subscribe_api_url = LATEPOINT_APP_CONNECT_URL . '/api/wp/v1/subscribe';
356
357 wp_remote_post(
358 $subscribe_api_url,
359 array(
360 'body' => array(
361 'first_name' => $first_name,
362 'last_name' => $last_name,
363 'email' => $email,
364 'optin' => $email_optin,
365 'site_url' => get_site_url(),
366 ),
367 'timeout' => 30,
368 'blocking' => false,
369 )
370 );
371 }
372 }
373
374
375 endif;
376