public static function validate_account()
 {
     global $nelioab_admin_controller;
     $email = '';
     if (isset($_POST['settings_email'])) {
         $email = $_POST['settings_email'];
     }
     $reg_num = '';
     if (isset($_POST['settings_reg_num'])) {
         $reg_num = $_POST['settings_reg_num'];
     }
     $errors = array();
     try {
         NelioABAccountSettings::validate_email_and_reg_num($email, $reg_num);
         $nelioab_admin_controller->message = __('Account information was successfully updated.', 'nelioab');
     } catch (Exception $e) {
         require_once NELIOAB_UTILS_DIR . '/backend.php';
         $errCode = $e->getCode();
         if ($errCode == NelioABErrCodes::INVALID_PRODUCT_REG_NUM) {
             array_push($errors, array('settings_reg_num', __('Invalid Registration Number', 'nelioab')));
         }
         if ($errCode == NelioABErrCodes::INVALID_MAIL) {
             array_push($errors, array('settings_email', __('E-Mail is not registered in our service', 'nelioab')));
         }
     }
     $settings_tac = NelioABAccountSettings::are_terms_and_conditions_accepted();
     if (isset($_POST['settings_tac'])) {
         $settings_tac = $_POST['settings_tac'];
     }
     NelioABAccountSettings::check_terms_and_conditions($settings_tac);
     $nelioab_admin_controller->validation_errors = $errors;
     return count($nelioab_admin_controller->validation_errors) == 0;
 }
 /**
  * Returns true if everything is OK. If it isn't, an exception is thrown.
  *
  * @return boolean true if everything is OK. Otherwise, an exception is thrown.
  *
  * @throws Exception `INVALID_MAIL`
  * @throws Exception `INVALID_PRODUCT_REG_NUM`
  * @throws Exception `NON_ACCEPTED_TAC`
  * @throws Exception `BACKEND_NO_SITE_CONFIGURED`
  * @throws Exception `DEACTIVATED_USER`
  *
  * @since 2.1.0
  */
 public static function check_user_settings()
 {
     if (!NelioABAccountSettings::is_email_valid()) {
         $err = NelioABErrCodes::INVALID_MAIL;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::is_reg_num_valid()) {
         $err = NelioABErrCodes::INVALID_PRODUCT_REG_NUM;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::are_terms_and_conditions_accepted()) {
         $err = NelioABErrCodes::NON_ACCEPTED_TAC;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     if (!NelioABAccountSettings::has_a_configured_site()) {
         $err = NelioABErrCodes::BACKEND_NO_SITE_CONFIGURED;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     NelioABAccountSettings::check_account_status();
     if (!NelioABAccountSettings::is_account_active()) {
         $err = NelioABErrCodes::DEACTIVATED_USER;
         throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     return true;
 }
        protected function do_render()
        {
            echo "<div class='nelio-message'>";
            printf('<img class="animated flipInY" src="%s" alt="%s" />', nelioab_admin_asset_link('/images/settings-icon.png'), __('Information Notice', 'nelioab'));
            $tac_text = '';
            if (NelioABAccountSettings::can_free_trial_be_started()) {
                echo '<h2>' . __('Welcome!', 'nelioab') . '</h2>';
                printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('Thank you very much for installing <strong>Nelio A/B Testing</strong> by <em>Nelio Software</em>. You\'re just one step away from optimizing your WordPress site.', 'nelioab'));
                printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Let\'s get started!', 'nelioab'));
                $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                $my_account_button = $this->make_button(__('Use Nelio Account', 'nelioab'), $account_url, false);
                $free_trial_button = $this->make_button(__('Start Free Trial', 'nelioab'), '#', true);
                $tac_text = sprintf(__('By starting the free trial you agree to be legally bound by these <a href="%s" target="_blank">terms</a>.', 'nelioab'), 'https://nelioabtesting.com/terms-and-conditions/');
            } else {
                if (!NelioABAccountSettings::is_email_valid() || !NelioABAccountSettings::is_reg_num_valid() || !NelioABAccountSettings::are_terms_and_conditions_accepted()) {
                    echo '<h2>' . __('Welcome!', 'nelioab') . '</h2>';
                    printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('Thank you very much for installing <strong>Nelio A/B Testing</strong> by <em>Nelio Software</em>. You\'re just one step away from optimizing your WordPress site.', 'nelioab'));
                    printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Let\'s get started!', 'nelioab'));
                    $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                    $my_account_button = $this->make_button(__('Use Nelio Account', 'nelioab'), $account_url, true);
                    $free_trial_button = '';
                } else {
                    echo '<h2>' . __('Setup', 'nelioab') . '</h2>';
                    printf("<p class=\"nelio-admin-explanation\">%s</p>\n", __('You\'re just one step away from optimizing WordPress with <strong style="white-space:nowrap;">Nelio A/B Testing</strong> by <em>Nelio Software</em>. Are you ready?', 'nelioab'));
                    printf("<p class=\"nelio-admin-explanation\"><strong>%s</strong></p>\n", __('Activate this site in your account.', 'nelioab'));
                    $account_url = admin_url('admin.php?page=nelioab-account&nabmode=my-account');
                    $my_account_button = $this->make_button(__('Open My Account', 'nelioab'), $account_url, true);
                    $free_trial_button = '';
                }
            }
            printf("<p id=\"nelio-cta-buttons\" class=\"nelio-admin-explanation\">%s %s</p>\n", $my_account_button, $free_trial_button);
            if (strlen($tac_text) > 0) {
                echo '<p style="padding-top:3em;font-size:95%;color:gray;">' . $tac_text . '</p>';
            }
            if (NelioABAccountSettings::can_free_trial_be_started()) {
                ?>
				<script type="text/javascript">
				(function($) {
					$('#nelio-cta-buttons .button-primary').click(function() {
						smoothTransitions();
						$.ajax({
							url: ajaxurl,
							data: {
								action: 'nelioab_start_free_trial'
							},
							type: 'post',
							success: function(res) {
								if ( "OK" === res ) {
									window.location = "<?php 
                echo admin_url('admin.php?page=nelioab-account&nabmode=free-trial');
                ?>
";
								} else {
									window.location.reload();
								}
							},
						});
					});
				})(jQuery);
				</script>
				<?php 
            }
            echo '</div>';
        }