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