| 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', 'erp' ), |
| 61 |
'view' => array( $this, 'setup_step_basic' ), |
| 62 |
'handler' => array( $this, 'setup_step_basic_save' ) |
| 63 |
), |
| 64 |
'module' => array( |
| 65 |
'name' => __( 'Module', 'erp' ), |
| 66 |
'view' => array( $this, 'setup_step_module' ), |
| 67 |
'handler' => array( $this, 'setup_step_module_save' ) |
| 68 |
), |
| 69 |
'department' => array( |
| 70 |
'name' => __( 'Departments', 'erp' ), |
| 71 |
'view' => array( $this, 'setup_step_departments' ), |
| 72 |
'handler' => array( $this, 'setup_step_departments_save' ) |
| 73 |
), |
| 74 |
'designation' => array( |
| 75 |
'name' => __( 'Designations', 'erp' ), |
| 76 |
'view' => array( $this, 'setup_step_designation' ), |
| 77 |
'handler' => array( $this, 'setup_step_designation_save' ), |
| 78 |
), |
| 79 |
'workdays' => array( |
| 80 |
'name' => __( 'Work Days', 'erp' ), |
| 81 |
'view' => array( $this, 'setup_step_workdays' ), |
| 82 |
'handler' => array( $this, 'setup_step_workdays_save' ), |
| 83 |
), |
| 84 |
// 'newsletter' => array( |
| 85 |
// 'name' => __( 'Newsletter', 'erp' ), |
| 86 |
// 'view' => array( $this, 'setup_step_newsletter' ), |
| 87 |
// 'handler' => array( $this, 'setup_step_newsletter_save' ), |
| 88 |
// ), |
| 89 |
'next_steps' => array( |
| 90 |
'name' => __( 'Ready!', 'erp' ), |
| 91 |
'view' => array( $this, 'setup_step_ready' ), |
| 92 |
'handler' => '' |
| 93 |
) |
| 94 |
); |
| 95 |
|
| 96 |
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); |
| 97 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : ''; |
| 98 |
|
| 99 |
wp_enqueue_style( 'jquery-ui', WPERP_ASSETS . '/vendor/jquery-ui/jquery-ui-1.9.1.custom.css' ); |
| 100 |
wp_enqueue_style( 'erp-setup', WPERP_ASSETS . '/css/setup.css', array( 'dashicons', 'install' ) ); |
| 101 |
|
| 102 |
wp_register_script( 'erp-select2', WPERP_ASSETS . '/vendor/select2/select2.full.min.js', false, false, true ); |
| 103 |
wp_register_script( 'erp-setup', WPERP_ASSETS . "/js/erp$suffix.js", array( 'jquery', 'jquery-ui-datepicker', 'erp-select2' ), date( 'Ymd' ), true ); |
| 104 |
|
| 105 |
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { |
| 106 |
call_user_func( $this->steps[ $this->step ]['handler'] ); |
| 107 |
} |
| 108 |
|
| 109 |
ob_start(); |
| 110 |
$this->setup_wizard_header(); |
| 111 |
$this->setup_wizard_steps(); |
| 112 |
$this->setup_wizard_content(); |
| 113 |
$this->setup_wizard_footer(); |
| 114 |
exit; |
| 115 |
} |
| 116 |
|
| 117 |
public function get_next_step_link() { |
| 118 |
$keys = array_keys( $this->steps ); |
| 119 |
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) ); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Setup Wizard Header |
| 124 |
*/ |
| 125 |
public function setup_wizard_header() { |
| 126 |
?> |
| 127 |
<!DOCTYPE html> |
| 128 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> |
| 129 |
<head> |
| 130 |
<meta name="viewport" content="width=device-width" /> |
| 131 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 132 |
<title><?php _e( 'WP ERP › Setup Wizard', 'erp' ); ?></title> |
| 133 |
<?php wp_print_scripts( 'erp-setup' ); ?> |
| 134 |
<?php do_action( 'admin_print_styles' ); ?> |
| 135 |
<?php do_action( 'admin_head' ); ?> |
| 136 |
</head> |
| 137 |
<body class="erp-setup wp-core-ui"> |
| 138 |
<h1 class="erp-logo"><a href="http://wperp.com/">WP ERP</a></h1> |
| 139 |
<?php |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Setup Wizard Footer |
| 144 |
*/ |
| 145 |
public function setup_wizard_footer() { |
| 146 |
?> |
| 147 |
<?php if ( 'next_steps' === $this->step ) : ?> |
| 148 |
<a class="erp-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php _e( 'Return to the WordPress Dashboard', 'erp' ); ?></a> |
| 149 |
<?php endif; ?> |
| 150 |
</body> |
| 151 |
</html> |
| 152 |
<?php |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Output the steps |
| 157 |
*/ |
| 158 |
public function setup_wizard_steps() { |
| 159 |
$output_steps = $this->steps; |
| 160 |
array_shift( $output_steps ); |
| 161 |
?> |
| 162 |
<ol class="erp-setup-steps"> |
| 163 |
<?php foreach ( $output_steps as $step_key => $step ) : ?> |
| 164 |
<li class="<?php |
| 165 |
if ( $step_key === $this->step ) { |
| 166 |
echo 'active'; |
| 167 |
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) { |
| 168 |
echo 'done'; |
| 169 |
} |
| 170 |
?>"><a href="<?php echo admin_url( 'index.php?page=erp-setup&step=' . $step_key ); ?>"><?php echo esc_html( $step['name'] ); ?></a> |
| 171 |
</li> |
| 172 |
<?php endforeach; ?> |
| 173 |
</ol> |
| 174 |
<?php |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Output the content for the current step |
| 179 |
*/ |
| 180 |
public function setup_wizard_content() { |
| 181 |
echo '<div class="erp-setup-content">'; |
| 182 |
call_user_func( $this->steps[ $this->step ]['view'] ); |
| 183 |
echo '</div>'; |
| 184 |
} |
| 185 |
|
| 186 |
public function next_step_buttons() { |
| 187 |
?> |
| 188 |
<p class="erp-setup-actions step"> |
| 189 |
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'erp' ); ?>" name="save_step" /> |
| 190 |
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php _e( 'Skip this step', 'erp' ); ?></a> |
| 191 |
<?php wp_nonce_field( 'erp-setup' ); ?> |
| 192 |
</p> |
| 193 |
<?php |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Introduction step |
| 198 |
*/ |
| 199 |
public function setup_step_introduction() { |
| 200 |
?> |
| 201 |
<h1><?php _e( 'Welcome to WP ERP!', 'erp' ); ?></h1> |
| 202 |
<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> |
| 203 |
<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> |
| 204 |
<p class="erp-setup-actions step"> |
| 205 |
<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> |
| 206 |
<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> |
| 207 |
</p> |
| 208 |
<?php |
| 209 |
} |
| 210 |
|
| 211 |
public function setup_step_basic() { |
| 212 |
$general = get_option( 'erp_settings_general', array() ); |
| 213 |
$accounting = get_option( 'erp_settings_accounting', array() ); |
| 214 |
$company = new \WeDevs\ERP\Company(); |
| 215 |
$business_type = $company->business_type; |
| 216 |
|
| 217 |
$financial_month = isset( $general['gen_financial_month'] ) ? $general['gen_financial_month'] : '1'; |
| 218 |
$company_started = isset( $general['gen_com_start'] ) ? $general['gen_com_start'] : ''; |
| 219 |
?> |
| 220 |
<h1><?php _e( 'Basic Settings', 'erp' ); ?></h1> |
| 221 |
|
| 222 |
<form method="post"> |
| 223 |
|
| 224 |
<table class="form-table"> |
| 225 |
<tr> |
| 226 |
<th scope="row"><label for="company_name"><?php _e( 'Company Name', 'erp' ); ?></label></th> |
| 227 |
<td> |
| 228 |
<?php erp_html_form_input([ |
| 229 |
'name' => 'company_name', |
| 230 |
'id' => 'company_name', |
| 231 |
'type' => 'text', |
| 232 |
'value' => $company->name, |
| 233 |
'help' => __( 'This name will be shown as your company name.', 'erp' ), |
| 234 |
]); ?> |
| 235 |
</td> |
| 236 |
</tr> |
| 237 |
<tr> |
| 238 |
<th scope="row"><label for="gen_financial_month"><?php _e( 'Financial Year Starts', 'erp' ); ?></label></th> |
| 239 |
<td> |
| 240 |
<?php erp_html_form_input([ |
| 241 |
'name' => 'gen_financial_month', |
| 242 |
'id' => 'gen_financial_month', |
| 243 |
'type' => 'select', |
| 244 |
'value' => $financial_month, |
| 245 |
'options' => erp_months_dropdown(), |
| 246 |
'help' => __( 'Financial and tax calculation starts from this month of every year.', 'erp' ), |
| 247 |
]); ?> |
| 248 |
</td> |
| 249 |
</tr> |
| 250 |
<tr> |
| 251 |
<th scope="row"><label for="gen_com_start"><?php _e( 'Company Start Date', 'erp' ); ?></label></th> |
| 252 |
<td> |
| 253 |
<?php erp_html_form_input([ |
| 254 |
'name' => 'gen_com_start', |
| 255 |
'type' => 'text', |
| 256 |
'value' => $company_started, |
| 257 |
'help' => __( 'The date the company officially started.', 'erp' ), |
| 258 |
'class' => 'erp-date-field', |
| 259 |
'placeholder' => 'YYYY-MM-DD' |
| 260 |
]); ?> |
| 261 |
</td> |
| 262 |
</tr> |
| 263 |
<tr> |
| 264 |
<th scope="row"><label for="base_currency"><?php _e( 'Currency', 'erp' ); ?></label></th> |
| 265 |
<td> |
| 266 |
<?php erp_html_form_input([ |
| 267 |
'name' => 'base_currency', |
| 268 |
'type' => 'select', |
| 269 |
'value' => 'USD', |
| 270 |
'options' => erp_get_currencies(), |
| 271 |
'desc' => __( 'Format of date to show accross the system.', 'erp' ), |
| 272 |
]); ?> |
| 273 |
</td> |
| 274 |
</tr> |
| 275 |
<tr> |
| 276 |
<th scope="row"><label for="date_format"><?php _e( 'Date Format', 'erp' ); ?></label></th> |
| 277 |
<td> |
| 278 |
<?php erp_html_form_input([ |
| 279 |
'name' => 'date_format', |
| 280 |
'type' => 'select', |
| 281 |
'value' => 'd-m-Y', |
| 282 |
'options' => [ |
| 283 |
'm-d-Y' => 'mm-dd-yyyy', |
| 284 |
'd-m-Y' => 'dd-mm-yyyy', |
| 285 |
'm/d/Y' => 'mm/dd/yyyy', |
| 286 |
'd/m/Y' => 'dd/mm/yyyy', |
| 287 |
'Y-m-d' => 'yyyy-mm-dd', |
| 288 |
], |
| 289 |
'help' => __( 'Format of date to show accross the system.', 'erp' ), |
| 290 |
]); ?> |
| 291 |
</td> |
| 292 |
</tr> |
| 293 |
<tr> |
| 294 |
<th scope="row"><label for="business_type"><?php _e( 'What sort of business do you do?', 'erp' ); ?></label></th> |
| 295 |
<td> |
| 296 |
<?php erp_html_form_input([ |
| 297 |
'name' => 'business_type', |
| 298 |
'type' => 'select', |
| 299 |
'value' => $business_type, |
| 300 |
'options' => [ |
| 301 |
'' => '-- select --', |
| 302 |
'Freelance' => 'Freelance', |
| 303 |
'FreelanceDev' => 'Freelance (Developer)', |
| 304 |
'FreelanceDes' => 'Freelance (Design)', |
| 305 |
'SmallBLocal' => 'Small Business: Local Service (e.g. Hairdresser)', |
| 306 |
'SmallBWeb' => 'Small Business: Web Business', |
| 307 |
'SmallBOther' => 'Small Business (Other)', |
| 308 |
'ecommerceWoo' => 'eCommerce (WooCommerce)', |
| 309 |
'ecommerceShopify' => 'eCommerce (Shopify)', |
| 310 |
'ecommerceOther' => 'eCommerce (Other)', |
| 311 |
'Other' => 'Other' |
| 312 |
] |
| 313 |
]); ?> |
| 314 |
</td> |
| 315 |
</tr> |
| 316 |
|
| 317 |
<?php if ( null !== get_option( 'erp_allow_tracking') ) : ?> |
| 318 |
|
| 319 |
<tr> |
| 320 |
<th scope="row"><label for="share_essentials"><?php _e( 'Share Essentials', 'erp' ); ?></label></th> |
| 321 |
|
| 322 |
<td class="updated"> |
| 323 |
<input type="checkbox" name="share_essentials" id="share_essentials" class="switch-input" checked> |
| 324 |
<label for="share_essentials" class="switch-label"> |
| 325 |
<span class="toggle--on">On</span> |
| 326 |
<span class="toggle--off">Off</span> |
| 327 |
</label> |
| 328 |
<span class="description"> |
| 329 |
Want to help make WP ERP even more awesome? Allow weDevs to collect non-sensitive diagnostic data and usage information. <a class="insights-data-we-collect" href="#">what we collect</a> |
| 330 |
</span> |
| 331 |
<p class="description" style="display:none;">Server environment details (php, mysql, server, WordPress versions), Number of users in your site, Site language, Number of active and inactive plugins, Site name and url, Your name and email address. No sensitive data is tracked.</p> |
| 332 |
</td> |
| 333 |
|
| 334 |
<script type="text/javascript"> |
| 335 |
jQuery('.insights-data-we-collect').on('click', function(e) { |
| 336 |
e.preventDefault(); |
| 337 |
jQuery(this).parents('.updated').find('p.description').slideToggle('fast'); |
| 338 |
}); |
| 339 |
</script> |
| 340 |
</tr> |
| 341 |
<?php endif; ?> |
| 342 |
</table> |
| 343 |
|
| 344 |
<?php $this->next_step_buttons(); ?> |
| 345 |
</form> |
| 346 |
<?php |
| 347 |
} |
| 348 |
|
| 349 |
public function setup_step_basic_save() { |
| 350 |
check_admin_referer( 'erp-setup' ); |
| 351 |
|
| 352 |
$company_name = sanitize_text_field( $_POST['company_name'] ); |
| 353 |
$business_type = sanitize_text_field( $_POST['business_type'] ); |
| 354 |
$financial_month = sanitize_text_field( $_POST['gen_financial_month'] ); |
| 355 |
$company_started = sanitize_text_field( $_POST['gen_com_start'] ); |
| 356 |
$base_currency = sanitize_text_field( $_POST['base_currency'] ); |
| 357 |
$date_format = sanitize_text_field( $_POST['date_format'] ); |
| 358 |
$share_essentials = sanitize_text_field( isset( $_POST['share_essentials'] ) ); |
| 359 |
$company = new \WeDevs\ERP\Company(); |
| 360 |
$allowed = '1'; |
| 361 |
|
| 362 |
if ( $share_essentials === $allowed ) { |
| 363 |
update_option( 'erp_allow_tracking', 'yes' ); |
| 364 |
update_option( 'erp_tracking_notice', 'hide' ); |
| 365 |
|
| 366 |
wp_clear_scheduled_hook( 'erp_tracker_send_event' ); |
| 367 |
wp_schedule_event( time(), 'weekly', 'erp_tracker_send_event' ); |
| 368 |
|
| 369 |
$tracker = new \WeDevs\ERP\Tracker(); |
| 370 |
$tracker->send_tracking_data(); |
| 371 |
} |
| 372 |
|
| 373 |
$company->update( array( |
| 374 |
'name' => $company_name, |
| 375 |
'business_type' => $business_type |
| 376 |
) ); |
| 377 |
|
| 378 |
update_option( 'erp_settings_general', [ |
| 379 |
'gen_financial_month' => $financial_month, |
| 380 |
'gen_com_start' => $company_started, |
| 381 |
'date_format' => $date_format, |
| 382 |
'erp_currency' => $base_currency, |
| 383 |
'erp_debug_mode' => 0 |
| 384 |
] ); |
| 385 |
|
| 386 |
update_option( 'erp_settings_accounting', [ |
| 387 |
'base_currency' => $base_currency, |
| 388 |
] ); |
| 389 |
|
| 390 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 391 |
exit; |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Module setup step |
| 396 |
* @since 1.3.4 |
| 397 |
*/ |
| 398 |
public function setup_step_module() { |
| 399 |
$modules = wperp()->modules->get_query_modules(); |
| 400 |
$all_active_modules = wperp()->modules->get_active_modules(); |
| 401 |
?> |
| 402 |
|
| 403 |
<h1><?php _e( 'Active Modules', 'erp' ); ?></h1> |
| 404 |
|
| 405 |
<form method="post"> |
| 406 |
<table class="form-table"> |
| 407 |
<?php |
| 408 |
foreach ( $modules as $slug => $module ) { |
| 409 |
$checked = array_key_exists( $slug, $all_active_modules ) ? $slug : ''; |
| 410 |
?> |
| 411 |
<tr> |
| 412 |
<th scope="row"> |
| 413 |
<label for="erp_module_<?php echo $slug; ?>"><?php echo isset( $module['title'] ) ? $module['title'] : ''; ?></label> |
| 414 |
</th> |
| 415 |
<td> |
| 416 |
<input type="checkbox" name="modules[]" id="erp_module_<?php echo $slug; ?>" class="switch-input" value="<?php echo $slug; ?>" <?php checked( $slug, $checked ); ?>> |
| 417 |
<label for="erp_module_<?php echo $slug; ?>" class="switch-label"> |
| 418 |
<span class="toggle--on">On</span> |
| 419 |
<span class="toggle--off">Off</span> |
| 420 |
</label> |
| 421 |
<span class="description"><?php echo isset( $module['description'] ) ? $module['description'] : ''; ?></span> |
| 422 |
</td> |
| 423 |
</tr> |
| 424 |
<?php } ?> |
| 425 |
</table> |
| 426 |
|
| 427 |
<?php $this->next_step_buttons(); ?> |
| 428 |
</form> |
| 429 |
<?php |
| 430 |
} |
| 431 |
|
| 432 |
/** |
| 433 |
* Module setup step save |
| 434 |
* @since 1.3.4 |
| 435 |
*/ |
| 436 |
public function setup_step_module_save() { |
| 437 |
check_admin_referer( 'erp-setup' ); |
| 438 |
|
| 439 |
$all_modules = wperp()->modules->get_modules(); |
| 440 |
$modules = array_map( 'sanitize_text_field', wp_unslash( $_POST['modules'] ) ); |
| 441 |
|
| 442 |
foreach ( $all_modules as $key => $module ) { |
| 443 |
if ( ! in_array( $key, $modules ) ) { |
| 444 |
unset( $all_modules[$key] ); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
update_option( 'erp_modules', $all_modules ); |
| 449 |
|
| 450 |
// when HRM is inactive hide related steps |
| 451 |
if ( ! in_array( 'hrm', $modules ) ) { |
| 452 |
unset( $this->steps['department'] ); |
| 453 |
unset( $this->steps['designation'] ); |
| 454 |
unset( $this->steps['workdays'] ); |
| 455 |
} |
| 456 |
|
| 457 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 458 |
exit; |
| 459 |
} |
| 460 |
|
| 461 |
public function setup_step_departments() { |
| 462 |
?> |
| 463 |
<h1><?php _e( 'Departments Setup', 'erp' ); ?></h1> |
| 464 |
<form method="post" class="form-table"> |
| 465 |
|
| 466 |
<div class="two-col"> |
| 467 |
<div class="col-first"> |
| 468 |
<p><?php _e( 'Create some departments for your company. e.g. HR, Engineering, Marketing, Support, etc. ', 'erp' ); ?></p> |
| 469 |
<p><?php _e( 'Leave empty for not to create any departments.', 'erp' ); ?></p> |
| 470 |
</div> |
| 471 |
|
| 472 |
<div class="col-last"> |
| 473 |
<ul class="unstyled"> |
| 474 |
<li> |
| 475 |
<input type="text" name="departments[]" class="regular-text" placeholder="<?php esc_attr_e( 'Department name', 'erp' ); ?>"> |
| 476 |
</li> |
| 477 |
<li> |
| 478 |
<input type="text" name="departments[]" class="regular-text" placeholder="<?php esc_attr_e( 'Department name', 'erp' ); ?>"> |
| 479 |
</li> |
| 480 |
<li class="add-new"><a href="#" class="button"><?php _e( 'Add New', 'erp' ); ?></a></li> |
| 481 |
</ul> |
| 482 |
</div> |
| 483 |
</div> |
| 484 |
|
| 485 |
<?php $this->next_step_buttons(); ?> |
| 486 |
</form> |
| 487 |
<?php |
| 488 |
|
| 489 |
$this->script_input_duplicator(); |
| 490 |
} |
| 491 |
|
| 492 |
public function script_input_duplicator() { |
| 493 |
?> |
| 494 |
<script type="text/javascript"> |
| 495 |
jQuery(function($) { |
| 496 |
$('.add-new').on('click', 'a', function(e) { |
| 497 |
e.preventDefault(); |
| 498 |
|
| 499 |
var self = $(this), |
| 500 |
parent = self.closest('li'); |
| 501 |
|
| 502 |
parent.prev().clone().insertBefore( parent ).find('input').val(''); |
| 503 |
}); |
| 504 |
}); |
| 505 |
</script> |
| 506 |
<?php |
| 507 |
} |
| 508 |
|
| 509 |
public function setup_step_departments_save() { |
| 510 |
check_admin_referer( 'erp-setup' ); |
| 511 |
|
| 512 |
$departments = array_map( 'sanitize_text_field', $_POST['departments'] ); |
| 513 |
|
| 514 |
if ( $departments ) { |
| 515 |
foreach ($departments as $department) { |
| 516 |
if ( ! empty( $department ) ) { |
| 517 |
erp_hr_create_department([ |
| 518 |
'title' => $department |
| 519 |
]); |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 525 |
exit; |
| 526 |
} |
| 527 |
|
| 528 |
public function setup_step_designation() { |
| 529 |
?> |
| 530 |
<h1><?php _e( 'Designation Setup', 'erp' ); ?></h1> |
| 531 |
<form method="post" class="form-table"> |
| 532 |
|
| 533 |
<div class="two-col"> |
| 534 |
<div class="col-first"> |
| 535 |
<p><?php _e( 'Create some designations for your company. e.g. Manager, Senior Developer, Marketing Manager, Support Executive, etc. ', 'erp' ); ?></p> |
| 536 |
<p><?php _e( 'Leave empty for not to create any designations.', 'erp' ); ?></p> |
| 537 |
</div> |
| 538 |
|
| 539 |
<div class="col-last"> |
| 540 |
<ul class="unstyled"> |
| 541 |
<li> |
| 542 |
<input type="text" name="designations[]" class="regular-text" placeholder="<?php esc_attr_e( 'Designation name', 'erp' ); ?>"> |
| 543 |
</li> |
| 544 |
<li> |
| 545 |
<input type="text" name="designations[]" class="regular-text" placeholder="<?php esc_attr_e( 'Designation name', 'erp' ); ?>"> |
| 546 |
</li> |
| 547 |
<li class="add-new"><a href="#" class="button"><?php _e( 'Add New', 'erp' ); ?></a></li> |
| 548 |
</ul> |
| 549 |
</div> |
| 550 |
</div> |
| 551 |
|
| 552 |
<?php $this->next_step_buttons(); ?> |
| 553 |
</form> |
| 554 |
<?php |
| 555 |
|
| 556 |
$this->script_input_duplicator(); |
| 557 |
} |
| 558 |
|
| 559 |
public function setup_step_designation_save() { |
| 560 |
check_admin_referer( 'erp-setup' ); |
| 561 |
|
| 562 |
$designations = array_map( 'sanitize_text_field', $_POST['designations'] ); |
| 563 |
|
| 564 |
if ( $designations ) { |
| 565 |
foreach ($designations as $designation) { |
| 566 |
if ( ! empty( $designation ) ) { |
| 567 |
erp_hr_create_designation([ |
| 568 |
'title' => $designation |
| 569 |
]); |
| 570 |
} |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 575 |
exit; |
| 576 |
} |
| 577 |
|
| 578 |
public function setup_step_workdays() { |
| 579 |
$working_days = erp_company_get_working_days(); |
| 580 |
$options = array( |
| 581 |
'8' => __( 'Full Day', 'erp' ), |
| 582 |
'4' => __( 'Half Day', 'erp' ), |
| 583 |
'0' => __( 'Non-working Day', 'erp' ) |
| 584 |
); |
| 585 |
$days = array( |
| 586 |
'mon' => __( 'Monday', 'erp' ), |
| 587 |
'tue' => __( 'Tuesday', 'erp' ), |
| 588 |
'wed' => __( 'Wednesday', 'erp' ), |
| 589 |
'thu' => __( 'Thursday', 'erp' ), |
| 590 |
'fri' => __( 'Friday', 'erp' ), |
| 591 |
'sat' => __( 'Saturday', 'erp' ), |
| 592 |
'sun' => __( 'Sunday', 'erp' ) |
| 593 |
); |
| 594 |
?> |
| 595 |
<h1><?php _e( 'Workdays Setup', 'erp' ); ?></h1> |
| 596 |
|
| 597 |
<form method="post"> |
| 598 |
<table class="form-table"> |
| 599 |
|
| 600 |
<?php |
| 601 |
foreach( $days as $key => $day ) { |
| 602 |
?> |
| 603 |
<tr> |
| 604 |
<th scope="row"><label for="gen_financial_month"><?php echo $day; ?></label></th> |
| 605 |
<td> |
| 606 |
<?php erp_html_form_input( array( |
| 607 |
'name' => 'day[' . $key . ']', |
| 608 |
'value' => $working_days[ $key ], |
| 609 |
'type' => 'select', |
| 610 |
'options' => $options |
| 611 |
) ); ?> |
| 612 |
</td> |
| 613 |
</tr> |
| 614 |
<?php } ?> |
| 615 |
|
| 616 |
</table> |
| 617 |
|
| 618 |
<?php $this->next_step_buttons(); ?> |
| 619 |
</form> |
| 620 |
<?php |
| 621 |
} |
| 622 |
|
| 623 |
/** |
| 624 |
* Save company working days data |
| 625 |
* |
| 626 |
* @since 1.0.0 |
| 627 |
* @since 1.1.14 Saving data in sun, mon etc keys, instead of `erp_settings_erp-hr_workdays` |
| 628 |
* since ERP Settings saves data with these keys |
| 629 |
* |
| 630 |
* @return void |
| 631 |
*/ |
| 632 |
public function setup_step_workdays_save() { |
| 633 |
check_admin_referer( 'erp-setup' ); |
| 634 |
|
| 635 |
if ( 7 === count( $_POST['day'] ) ) { |
| 636 |
foreach ( $_POST['day'] as $day => $hour_limit ) { |
| 637 |
update_option( $day, $hour_limit ); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 642 |
exit; |
| 643 |
} |
| 644 |
|
| 645 |
/** |
| 646 |
* Newsletter setup step |
| 647 |
* @since 1.3.4 |
| 648 |
*/ |
| 649 |
public function setup_step_newsletter() { |
| 650 |
?> |
| 651 |
<h1><?php _e( 'Newsletter Setup', 'erp' ); ?></h1> |
| 652 |
|
| 653 |
<?php |
| 654 |
$subscription = new \WeDevs\ERP\CRM\Subscription(); |
| 655 |
?> |
| 656 |
|
| 657 |
<form method="post"> |
| 658 |
|
| 659 |
<table class="form-table"> |
| 660 |
<tr> |
| 661 |
<th scope="row"> |
| 662 |
<label for="full_name"><?php _e( 'Your Name', 'erp' ); ?></label> |
| 663 |
</th> |
| 664 |
<td> |
| 665 |
<?php erp_html_form_input( array( |
| 666 |
'name' => 'full_name', |
| 667 |
'value' => '', |
| 668 |
'type' => 'text', |
| 669 |
'help' => __( 'This name will be used for newsletter name.', 'erp' ), |
| 670 |
) ); ?> |
| 671 |
</td> |
| 672 |
</tr> |
| 673 |
|
| 674 |
<tr> |
| 675 |
<th scope="row"> |
| 676 |
<label for="subs_email"><?php _e( 'Your Email', 'erp' ); ?></label> |
| 677 |
</th> |
| 678 |
<td> |
| 679 |
<?php erp_html_form_input( array( |
| 680 |
'name' => 'full_name', |
| 681 |
'value' => '', |
| 682 |
'type' => 'email', |
| 683 |
'help' => __( 'Email to get update critical updates.', 'erp' ), |
| 684 |
) ); ?> |
| 685 |
</td> |
| 686 |
</tr> |
| 687 |
</table> |
| 688 |
|
| 689 |
<?php $this->next_step_buttons(); ?> |
| 690 |
</form> |
| 691 |
<?php |
| 692 |
} |
| 693 |
|
| 694 |
/** |
| 695 |
* Newsletter setup step save |
| 696 |
* @since 1.3.4 |
| 697 |
*/ |
| 698 |
public function setup_step_newsletter_save() { |
| 699 |
check_admin_referer( 'erp-setup' ); |
| 700 |
|
| 701 |
// |
| 702 |
|
| 703 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 704 |
exit; |
| 705 |
} |
| 706 |
|
| 707 |
public function setup_step_ready() { |
| 708 |
?> |
| 709 |
|
| 710 |
<div class="final-step"> |
| 711 |
<h1><?php _e( 'Your Site is Ready!', 'erp' ); ?></h1> |
| 712 |
|
| 713 |
<div class="erp-setup-next-steps"> |
| 714 |
<div class="erp-setup-next-steps-first"> |
| 715 |
<h2><?php _e( 'Next Steps →', 'erp' ); ?></h2> |
| 716 |
<?php |
| 717 |
$is_hrm_activated = erp_is_module_active( 'hrm' ); |
| 718 |
|
| 719 |
if ( $is_hrm_activated ) : ?> |
| 720 |
<a class="button button-primary button-large" |
| 721 |
href="<?php echo esc_url( admin_url( 'admin.php?page=erp-hr-employee' ) ); ?>"> |
| 722 |
<?php _e( 'Add your employees!', 'erp' ); ?> |
| 723 |
</a> |
| 724 |
<?php else: ?> |
| 725 |
<a class="button button-primary button-large" |
| 726 |
href="<?php echo esc_url( admin_url() ); ?>"> |
| 727 |
<?php _e( 'Go to Dashboard!', 'erp' ); ?> |
| 728 |
</a> |
| 729 |
<?php endif; |
| 730 |
?> |
| 731 |
</div> |
| 732 |
</div> |
| 733 |
</div> |
| 734 |
<?php |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
return new Setup_Wizard(); |
| 739 |
|