PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / admin / class-setup-wizard.php

class-setup-wizard.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/admin/class-setup-wizard.php

501 lines 18.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setup wizard class
4 *
5 * Walkthrough to the basic setup upon installation
6 *
7 * @package WP-ERP\Admin
8 */
9
10 namespace WeDevs\ERP\Admin;
11
12 /**
13 * The class
14 */
15 class Setup_Wizard {
16
17 /** @var string Currenct Step */
18 private $step = '';
19
20 /** @var array Steps for the setup wizard */
21 private $steps = array();
22
23 /**
24 * Hook in tabs.
25 */
26 public function __construct() {
27
28 // if we are here, we assume we don't need to run the wizard again
29 // and the user doesn't need to be redirected here
30 update_option( 'erp_setup_wizard_ran', '1' );
31
32 if ( apply_filters( 'erp_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
33 add_action( 'admin_menu', array( $this, 'admin_menus' ) );
34 add_action( 'admin_init', array( $this, 'setup_wizard' ) );
35 }
36 }
37
38 /**
39 * Add admin menus/screens.
40 */
41 public function admin_menus() {
42 add_dashboard_page( '', '', 'manage_options', 'erp-setup', '' );
43 }
44
45 /**
46 * Show the setup wizard
47 */
48 public function setup_wizard() {
49 if ( empty( $_GET['page'] ) || 'erp-setup' !== $_GET['page'] ) {
50 return;
51 }
52
53 $this->steps = array(
54 'introduction' => array(
55 'name' => __( 'Introduction', 'erp' ),
56 'view' => array( $this, 'setup_step_introduction' ),
57 'handler' => ''
58 ),
59 'basic' => array(
60 'name' => __( 'Basic Settings', 'erp' ),
61 'view' => array( $this, 'setup_step_basic' ),
62 'handler' => array( $this, 'setup_step_basic_save' )
63 ),
64 'department' => array(
65 'name' => __( 'Departments', 'erp' ),
66 'view' => array( $this, 'setup_step_departments' ),
67 'handler' => array( $this, 'setup_step_departments_save' )
68 ),
69 'designation' => array(
70 'name' => __( 'Designations', 'erp' ),
71 'view' => array( $this, 'setup_step_designation' ),
72 'handler' => array( $this, 'setup_step_designation_save' ),
73 ),
74 'workdays' => array(
75 'name' => __( 'Work Days', 'erp' ),
76 'view' => array( $this, 'setup_step_workdays' ),
77 'handler' => array( $this, 'setup_step_workdays_save' ),
78 ),
79 'next_steps' => array(
80 'name' => __( 'Ready!', 'erp' ),
81 'view' => array( $this, 'setup_step_ready' ),
82 'handler' => ''
83 )
84 );
85
86 $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
87 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '';
88
89 wp_enqueue_style( 'jquery-ui', WPERP_ASSETS . '/vendor/jquery-ui/jquery-ui-1.9.1.custom.css' );
90 wp_enqueue_style( 'erp-setup', WPERP_ASSETS . '/css/setup.css', array( 'dashicons', 'install' ) );
91
92 wp_register_script( 'erp-select2', WPERP_ASSETS . '/vendor/select2/select2.full.min.js', false, false, true );
93 wp_register_script( 'erp-setup', WPERP_ASSETS . "/js/erp$suffix.js", array( 'jquery', 'jquery-ui-datepicker', 'erp-select2' ), date( 'Ymd' ), true );
94
95 if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
96 call_user_func( $this->steps[ $this->step ]['handler'] );
97 }
98
99 ob_start();
100 $this->setup_wizard_header();
101 $this->setup_wizard_steps();
102 $this->setup_wizard_content();
103 $this->setup_wizard_footer();
104 exit;
105 }
106
107 public function get_next_step_link() {
108 $keys = array_keys( $this->steps );
109 return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) );
110 }
111
112 /**
113 * Setup Wizard Header
114 */
115 public function setup_wizard_header() {
116 ?>
117 <!DOCTYPE html>
118 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
119 <head>
120 <meta name="viewport" content="width=device-width" />
121 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
122 <title><?php _e( 'WP ERP &rsaquo; Setup Wizard', 'erp' ); ?></title>
123 <?php wp_print_scripts( 'erp-setup' ); ?>
124 <?php do_action( 'admin_print_styles' ); ?>
125 <?php do_action( 'admin_head' ); ?>
126 </head>
127 <body class="erp-setup wp-core-ui">
128 <h1 class="erp-logo"><a href="http://wperp.com/">WP ERP</a></h1>
129 <?php
130 }
131
132 /**
133 * Setup Wizard Footer
134 */
135 public function setup_wizard_footer() {
136 ?>
137 <?php if ( 'next_steps' === $this->step ) : ?>
138 <a class="erp-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php _e( 'Return to the WordPress Dashboard', 'erp' ); ?></a>
139 <?php endif; ?>
140 </body>
141 </html>
142 <?php
143 }
144
145 /**
146 * Output the steps
147 */
148 public function setup_wizard_steps() {
149 $ouput_steps = $this->steps;
150 array_shift( $ouput_steps );
151 ?>
152 <ol class="erp-setup-steps">
153 <?php foreach ( $ouput_steps as $step_key => $step ) : ?>
154 <li class="<?php
155 if ( $step_key === $this->step ) {
156 echo 'active';
157 } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
158 echo 'done';
159 }
160 ?>"><?php echo esc_html( $step['name'] ); ?></li>
161 <?php endforeach; ?>
162 </ol>
163 <?php
164 }
165
166 /**
167 * Output the content for the current step
168 */
169 public function setup_wizard_content() {
170 echo '<div class="erp-setup-content">';
171 call_user_func( $this->steps[ $this->step ]['view'] );
172 echo '</div>';
173 }
174
175 public function next_step_buttons() {
176 ?>
177 <p class="erp-setup-actions step">
178 <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'erp' ); ?>" name="save_step" />
179 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php _e( 'Skip this step', 'erp' ); ?></a>
180 <?php wp_nonce_field( 'erp-setup' ); ?>
181 </p>
182 <?php
183 }
184
185 /**
186 * Introduction step
187 */
188 public function setup_step_introduction() {
189 ?>
190 <h1><?php _e( 'Welcome to WP ERP!', 'erp' ); ?></h1>
191 <p><?php _e( 'Thank you for choosing WP-ERP. An easier way to manage your company! This quick setup wizard will help you configure the basic settings. <strong>It’s completely optional and shouldn’t take longer than three minutes.</strong>', 'erp' ); ?></p>
192 <p><?php _e( 'No time right now? If you don’t want to go through the wizard, you can skip and return to the WordPress dashboard. Come back anytime if you change your mind!', 'erp' ); ?></p>
193 <p class="erp-setup-actions step">
194 <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button-primary button button-large button-next"><?php _e( 'Let\'s Go!', 'erp' ); ?></a>
195 <a href="<?php echo esc_url( wp_get_referer() ? wp_get_referer() : admin_url( 'plugins.php' ) ); ?>" class="button button-large"><?php _e( 'Not right now', 'erp' ); ?></a>
196 </p>
197 <?php
198 }
199
200 public function setup_step_basic() {
201 $general = get_option( 'erp_settings_general', array() );
202 $accounting = get_option( 'erp_settings_accounting', array() );
203
204 $financial_month = isset( $general['gen_financial_month'] ) ? $general['gen_financial_month'] : '1';
205 $company_started = isset( $general['gen_com_start'] ) ? $general['gen_com_start'] : '';
206 ?>
207 <h1><?php _e( 'Basic Settings', 'erp' ); ?></h1>
208
209 <form method="post">
210
211 <table class="form-table">
212 <tr>
213 <th scope="row"><label for="gen_financial_month"><?php _e( 'Financial Year Starts', 'erp' ); ?></label></th>
214 <td>
215 <?php erp_html_form_input([
216 'name' => 'gen_financial_month',
217 'id' => 'gen_financial_month',
218 'type' => 'select',
219 'value' => $financial_month,
220 'options' => erp_months_dropdown(),
221 'help' => __( 'Financial and tax calculation starts from this month of every year.', 'erp' ),
222 ]); ?>
223 </td>
224 </tr>
225 <tr>
226 <th scope="row"><label for="gen_com_start"><?php _e( 'Company Start Date', 'erp' ); ?></label></th>
227 <td>
228 <?php erp_html_form_input([
229 'name' => 'gen_com_start',
230 'type' => 'text',
231 'value' => $company_started,
232 'help' => __( 'The date the company officially started.', 'erp' ),
233 'class' => 'erp-date-field',
234 'placeholder' => 'YYYY-MM-DD'
235 ]); ?>
236 </td>
237 </tr>
238 <tr>
239 <th scope="row"><label for="base_currency"><?php _e( 'Currency', 'erp' ); ?></label></th>
240 <td>
241 <?php erp_html_form_input([
242 'name' => 'base_currency',
243 'type' => 'select',
244 'value' => 'USD',
245 'options' => erp_get_currencies(),
246 'desc' => __( 'Format of date to show accross the system.', 'erp' ),
247 ]); ?>
248 </td>
249 </tr>
250 <tr>
251 <th scope="row"><label for="date_format"><?php _e( 'Date Format', 'erp' ); ?></label></th>
252 <td>
253 <?php erp_html_form_input([
254 'name' => 'date_format',
255 'type' => 'select',
256 'value' => 'd-m-Y',
257 'options' => [
258 'm-d-Y' => 'mm-dd-yyyy',
259 'd-m-Y' => 'dd-mm-yyyy',
260 'm/d/Y' => 'mm/dd/yyyy',
261 'd/m/Y' => 'dd/mm/yyyy',
262 'Y-m-d' => 'yyyy-mm-dd',
263 ],
264 'help' => __( 'Format of date to show accross the system.', 'erp' ),
265 ]); ?>
266 </td>
267 </tr>
268 </table>
269
270 <?php $this->next_step_buttons(); ?>
271 </form>
272 <?php
273 }
274
275 public function setup_step_basic_save() {
276 check_admin_referer( 'erp-setup' );
277
278 $financial_month = sanitize_text_field( $_POST['gen_financial_month'] );
279 $company_started = sanitize_text_field( $_POST['gen_com_start'] );
280 $base_currency = sanitize_text_field( $_POST['base_currency'] );
281 $date_format = sanitize_text_field( $_POST['date_format'] );
282
283 update_option( 'erp_settings_general', [
284 'gen_financial_month' => $financial_month,
285 'gen_com_start' => $company_started,
286 'date_format' => $date_format,
287 'erp_debug_mode' => 0
288 ] );
289
290 update_option( 'erp_settings_accounting', [
291 'base_currency' => $base_currency,
292 ] );
293
294 wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
295 exit;
296 }
297
298 public function setup_step_departments() {
299 ?>
300 <h1><?php _e( 'Departments Setup', 'erp' ); ?></h1>
301 <form method="post" class="form-table">
302
303 <div class="two-col">
304 <div class="col-first">
305 <p><?php _e( 'Create some departments for your company. e.g. HR, Engineering, Marketing, Support, etc. ', 'erp' ); ?></p>
306 <p><?php _e( 'Leave empty for not to create any departments.', 'erp' ); ?></p>
307 </div>
308
309 <div class="col-last">
310 <ul class="unstyled">
311 <li>
312 <input type="text" name="departments[]" class="regular-text" placeholder="<?php esc_attr_e( 'Department name', 'erp' ); ?>">
313 </li>
314 <li>
315 <input type="text" name="departments[]" class="regular-text" placeholder="<?php esc_attr_e( 'Department name', 'erp' ); ?>">
316 </li>
317 <li class="add-new"><a href="#" class="button"><?php _e( 'Add New', 'erp' ); ?></a></li>
318 </ul>
319 </div>
320 </div>
321
322 <?php $this->next_step_buttons(); ?>
323 </form>
324 <?php
325
326 $this->script_input_duplicator();
327 }
328
329 public function script_input_duplicator() {
330 ?>
331 <script type="text/javascript">
332 jQuery(function($) {
333 $('.add-new').on('click', 'a', function(e) {
334 e.preventDefault();
335
336 var self = $(this),
337 parent = self.closest('li');
338
339 parent.prev().clone().insertBefore( parent ).find('input').val('');
340 });
341 });
342 </script>
343 <?php
344 }
345
346 public function setup_step_departments_save() {
347 check_admin_referer( 'erp-setup' );
348
349 $departments = array_map( 'sanitize_text_field', $_POST['departments'] );
350
351 if ( $departments ) {
352 foreach ($departments as $department) {
353 if ( ! empty( $department ) ) {
354 erp_hr_create_department([
355 'title' => $department
356 ]);
357 }
358 }
359 }
360
361 wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
362 exit;
363 }
364
365 public function setup_step_designation() {
366 ?>
367 <h1><?php _e( 'Designation Setup', 'erp' ); ?></h1>
368 <form method="post" class="form-table">
369
370 <div class="two-col">
371 <div class="col-first">
372 <p><?php _e( 'Create some designations for your company. e.g. Manager, Senior Developer, Marketing Manager, Support Executive, etc. ', 'erp' ); ?></p>
373 <p><?php _e( 'Leave empty for not to create any designations.', 'erp' ); ?></p>
374 </div>
375
376 <div class="col-last">
377 <ul class="unstyled">
378 <li>
379 <input type="text" name="designations[]" class="regular-text" placeholder="<?php esc_attr_e( 'Designation name', 'erp' ); ?>">
380 </li>
381 <li>
382 <input type="text" name="designations[]" class="regular-text" placeholder="<?php esc_attr_e( 'Designation name', 'erp' ); ?>">
383 </li>
384 <li class="add-new"><a href="#" class="button"><?php _e( 'Add New', 'erp' ); ?></a></li>
385 </ul>
386 </div>
387 </div>
388
389 <?php $this->next_step_buttons(); ?>
390 </form>
391 <?php
392
393 $this->script_input_duplicator();
394 }
395
396 public function setup_step_designation_save() {
397 check_admin_referer( 'erp-setup' );
398
399 $designations = array_map( 'sanitize_text_field', $_POST['designations'] );
400
401 if ( $designations ) {
402 foreach ($designations as $designation) {
403 if ( ! empty( $designation ) ) {
404 erp_hr_create_designation([
405 'title' => $designation
406 ]);
407 }
408 }
409 }
410
411 wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
412 exit;
413 }
414
415 public function setup_step_workdays() {
416 $working_days = erp_company_get_working_days();
417 $options = array(
418 '8' => __( 'Full Day', 'erp' ),
419 '4' => __( 'Half Day', 'erp' ),
420 '0' => __( 'Non-working Day', 'erp' )
421 );
422 $days = array(
423 'mon' => __( 'Monday', 'erp' ),
424 'tue' => __( 'Tuesday', 'erp' ),
425 'wed' => __( 'Wednesday', 'erp' ),
426 'thu' => __( 'Thursday', 'erp' ),
427 'fri' => __( 'Friday', 'erp' ),
428 'sat' => __( 'Saturday', 'erp' ),
429 'sun' => __( 'Sunday', 'erp' )
430 );
431 ?>
432 <h1><?php _e( 'Workdays Setup', 'erp' ); ?></h1>
433 <form method="post">
434
435 <table class="form-table">
436
437 <?php
438 foreach( $days as $key => $day ) {
439 ?>
440 <tr>
441 <th scope="row"><label for="gen_financial_month"><?php echo $day; ?></label></th>
442 <td>
443 <?php erp_html_form_input( array(
444 'name' => 'day[' . $key . ']',
445 'value' => $working_days[ $key ],
446 'type' => 'select',
447 'options' => $options
448 ) ); ?>
449 </td>
450 </tr>
451 <?php } ?>
452
453 </table>
454
455 <?php $this->next_step_buttons(); ?>
456 </form>
457 <?php
458 }
459
460 /**
461 * Save company working days data
462 *
463 * @since 1.0.0
464 * @since 1.1.14 Saving data in sun, mon etc keys, instead of `erp_settings_erp-hr_workdays`
465 * since ERP Settings saves data with these keys
466 *
467 * @return void
468 */
469 public function setup_step_workdays_save() {
470 check_admin_referer( 'erp-setup' );
471
472 if ( 7 === count( $_POST['day'] ) ) {
473 foreach ( $_POST['day'] as $day => $hour_limit ) {
474 update_option( $day, $hour_limit );
475 }
476 }
477
478 wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
479 exit;
480 }
481
482 public function setup_step_ready() {
483 ?>
484
485 <div class="final-step">
486 <h1><?php _e( 'Your Site is Ready!', 'erp' ); ?></h1>
487
488 <div class="erp-setup-next-steps">
489 <div class="erp-setup-next-steps-first">
490 <h2><?php _e( 'Next Steps &rarr;', 'erp' ); ?></h2>
491
492 <a class="button button-primary button-large" href="<?php echo esc_url( admin_url( 'admin.php?page=erp-hr-employee' ) ); ?>"><?php _e( 'Add your employees!', 'erp' ); ?></a>
493 </div>
494 </div>
495 </div>
496 <?php
497 }
498 }
499
500 return new Setup_Wizard();
501