public static function print_notification_email_field() { $field_name = 'notification_email'; printf('<div class="nelio-sect"><input type="text" id="%1$s" name="nelioab_settings[%1$s]" style="max-width:400px;width:100%%;" value="%3$s" placeholder="%4$s" %2$s></div>', $field_name, self::get_basic_details(), esc_html(NelioABSettings::get_notification_email()), sprintf(__('Default: %s', 'nelioab'), esc_html(NelioABAccountSettings::get_email()))); ?> <div class="the-descr" style="display:none;"><span class="description"><?php printf(__('If you type an e-mail address, all Nelio A/B Testing notifications will be sent to both the new address and «%s».', 'nelioab'), NelioABAccountSettings::get_email()); ?> </span></div> <script type="text/javascript"> (function($) { var mail = $('#<?php echo $field_name; ?> '); var form = $('#nelioab-settings'); var save; function validateMail() { var x = mail.attr('value'); if ( x.length == 0 ) return true; var atpos = x.indexOf('@'); var dotpos = x.lastIndexOf('.'); if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) return false; return true; } function control() { if ( validateMail() ) { mail.removeClass('error'); save.removeClass('disabled'); form.unbind('submit', returnFalse); } else { mail.addClass('error'); save.addClass('disabled'); form.on('submit', returnFalse); } } function returnFalse() { return false; } mail.on('keyup focusout', control); $(document).ready(function() { save = $('#submit'); control(); }); })(jQuery); </script> <?php }
public static function generate_html_content() { require_once NELIOAB_ADMIN_DIR . '/views/account-page.php'; // Check data against APPENGINE $email = NelioABAccountSettings::get_email(); $reg_num = NelioABAccountSettings::get_reg_num(); if (NelioABAccountSettings::is_using_free_trial()) { $email = ''; $reg_num = ''; } $sites = array(); $max_sites = 1; try { NelioABAccountSettings::check_account_status('now'); } catch (Exception $e) { } $current_site_status = NelioABSite::NOT_REGISTERED; $error_retrieving_registered_sites = false; try { $sites_info = NelioABAccountSettings::get_registered_sites_information(); $max_sites = $sites_info->get_max_sites(); $sites = $sites_info->get_registered_sites(); // CHECKING WHETHER WE HAVE INFORMATION ABOUT THIS SITE BEING REGISTERED, // EITHER BY ID OR BY URL // 1. We check if this user has a registered site whose URL is this site's url $registered_site_based_on_url = false; foreach ($sites as $site) { if ($site->get_url() == get_option('siteurl')) { $registered_site_based_on_url = $site->get_id(); } } // 2. We check if the WP installation has a SITE_ID // If it does, but it's none of the user's regitered sites, // we have a problem, and we'll say the status is INVALID_ID. if (NelioABAccountSettings::has_a_configured_site()) { $site_id = NelioABAccountSettings::get_site_id(); $current_site_status = NelioABSite::INVALID_ID; foreach ($sites as $site) { if ($site->get_id() == $site_id) { $current_site_status = NelioABSite::ACTIVE; } } } // POSSIBLE RESULTS OF THE PREVIOUS CHECKS: // (a) The site is properly registered (== it has a valid ID) //if ( NelioABSite::ACTIVE == $current_site_status ) // Nothing to do here // (b) We have information about an ID that the user, in AE, does not have if (NelioABSite::INVALID_ID == $current_site_status) { $current_site_status = NelioABSite::NOT_REGISTERED; NelioABAccountSettings::fix_registration_info('not-registered'); } // (c) The site is not registered if (NelioABSite::NOT_REGISTERED == $current_site_status) { if ($registered_site_based_on_url) { $current_site_status = NelioABSite::ACTIVE; NelioABAccountSettings::fix_registration_info('registered', $registered_site_based_on_url); } } // (d) Other scenarios are: // - INACTIVE. We don't care. // - NON_MATCHING_URLS. We no longer use it. } catch (Exception $e) { $error_retrieving_registered_sites = true; } // Querying account information $user_info = array(); try { $customer_id = NelioABAccountSettings::get_customer_id(); if (strlen($customer_id) > 0) { $url = sprintf(NELIOAB_BACKEND_URL . '/customer/%s', $customer_id); $json = NelioABBackend::remote_get($url, true); $json = json_decode($json['body']); if (isset($user_info['firstname'])) { $user_info['firstname'] = $json->firstname; } else { $user_info['firstname'] = ''; } $user_info['subscription_url'] = $json->subscriptionUrl; $user_info['subscription_plan'] = $json->subscriptionPlan; $user_info['status'] = $json->status; $user_info['total_quota'] = intval($json->quotaPerMonth); $user_info['quota'] = intval($json->quota + $json->quotaExtra); } // Agency stuff if (isset($json->hasAgency) && $json->hasAgency) { $user_info['agency'] = true; $user_info['agencyname'] = $json->agencyName; $user_info['agencymail'] = $json->agencyEmail; } else { $user_info['agency'] = false; $user_info['agencyname'] = 'Agency Name'; $user_info['agencymail'] = '*****@*****.**'; } } catch (Exception $e) { } // Render content $title = __('My Account', 'nelioab'); $view = new NelioABAccountPage($title); $view->set_email($email); $view->set_email_validity(NelioABAccountSettings::is_email_valid()); $view->set_reg_num($reg_num); $view->set_reg_num_validity(NelioABAccountSettings::is_reg_num_valid()); $view->set_tac_checked(NelioABAccountSettings::are_terms_and_conditions_accepted()); $view->set_registered_sites($sites); $view->set_max_sites($max_sites); $view->set_current_site_status($current_site_status); $view->set_user_info($user_info); if ($error_retrieving_registered_sites) { $view->set_error_retrieving_registered_sites(); } $view->render_content(); die; }
protected function do_render() { ?> <form id="nelioab_account_form" method="post"> <input type="hidden" name="nelioab_account_form" value="true" /> <?php $fields = array(array('label' => __('E-Mail', 'nelioab'), 'id' => 'settings_email', 'callback' => array(&$this, 'print_email_field'), 'mandatory' => true), array('label' => __('Registration Number', 'nelioab'), 'id' => 'settings_reg_num', 'callback' => array(&$this, 'print_reg_num_field'), 'mandatory' => true)); if (!NelioABAccountSettings::is_using_free_trial()) { array_push($fields, array('label' => __('I have read and accept the <a href="https://nelioabtesting.com/terms-and-conditions" target="_blank">Terms and Conditions</a> of this service.', 'nelioab'), 'id' => 'settings_tac', 'mandatory' => true, 'checkbox' => true, 'checked' => $this->tac, 'pre' => '<br />')); } $this->make_section(__('Nelio AB Testing – Account Access Details', 'nelioab'), $fields); ?> </form> <?php echo $this->make_submit_button(__('Access', 'nelioab'), 'nelioab_account_form'); ?> <br /><br /><br /> <?php $print_plans = true; if (isset($this->user_info['status']) && ($this->user_info['status'] == 1 || $this->user_info['status'] == 2)) { $print_plans = false; } if ($print_plans) { $this->set_message(__('Haven\'t you subscribed to any of our plans? <b><a href="http://nelioabtesting.com/subscription-plans/" target="_blank">Check them out and choose the one that best fits you</a></b>! All our plans come with a <b>14-day free trial period</b>.', 'nelioab')); } ?> <h2 style="margin-bottom:0px;padding-bottom:0px;"><?php $is_status_defined = false; $status_fg_color = '#777777'; $status_bg_color = '#EFEFEF'; $status_text = __('UNDEFINED', 'nelioab'); if (isset($this->user_info['status'])) { if ($this->user_info['status'] == 1) { $status_fg_color = '#008800'; $status_bg_color = '#D9FFD9'; $status_text = __('ACTIVE', 'nelioab'); $is_status_defined = true; } else { if ($this->user_info['status'] == 2) { $status_fg_color = '#CC0000'; $status_bg_color = '#FD9D9'; $status_text = __('NOT ACTIVE', 'nelioab'); $is_status_defined = true; } } } if (!$this->tac) { $status_fg_color = '#777777'; $status_bg_color = '#EFEFEF'; $status_text = __('UNKNOWN', 'nelioab'); } $status_title = sprintf('<span style="color:%s;background-color:%s;font-size:0.5em;" class="add-new-h2">%s</span>', $status_fg_color, $status_bg_color, $status_text); echo __('Account Information', 'nelioab') . ' ' . $status_title; ?> </h2> <?php if (!$this->tac || !$is_status_defined) { echo '<p>' . __('Please, fill in all required fields in order to view your account details and use our service.', 'nelioab') . '</p>'; } else { ?> <?php if (!$this->user_info['agency'] && !empty($this->user_info['firstname'])) { ?> <p style="margin-top:0em;margin-left:3em;"><?php printf(__('Hi %s!', 'nelioab'), $this->user_info['firstname']); ?> </p> <?php } ?> <p style="margin-top:0em;margin-left:3em;"><?php if (!isset($this->user_info['subscription_url'])) { _e('No subscription information available.', 'nelioab'); } else { if ($this->user_info['subscription_url'] == 'BETA') { _e('You are using a <b>beta free-pass</b>.', 'nelioab'); } else { if ($this->user_info['subscription_plan'] == 0) { printf('%s<br /><a href="%s">%s</a>', __('You are using the <b>Free Trial</b> version of Nelio A/B Testing.', 'nelioab'), $this->user_info['subscription_url'], __('Subscribe now and continue using our service!', 'nelioab')); } else { if (!$this->user_info['agency']) { switch ($this->user_info['subscription_plan']) { case NelioABAccountSettings::BASIC_SUBSCRIPTION_PLAN: _e('You are subscribed to our <b>Basic Plan</b>.', 'nelioab'); break; case NelioABAccountSettings::PROFESSIONAL_SUBSCRIPTION_PLAN: _e('You are subscribed to our <b>Professional Plan</b>.', 'nelioab'); break; case NelioABAccountSettings::ENTERPRISE_SUBSCRIPTION_PLAN: _e('You are subscribed to our <b>Enterprise Plan</b>.', 'nelioab'); break; } echo '<br><span class="subscription-actions">'; printf('<a class="edit" href="%s">%s</a> ', $this->user_info['subscription_url'], __('Edit Subscription', 'nelioab')); printf('<a class="delete" href="%s">%s</a> ', $this->user_info['subscription_url'], __('Cancel Subscription', 'nelioab')); echo '</span>'; if ($this->user_info['subscription_plan'] == NelioABAccountSettings::BASIC_SUBSCRIPTION_PLAN) { echo '<br />'; printf('<a href="%2$s">%1$s</a>', __('Upgrade to our Professional Plan.', 'nelioab'), 'mailto:support@neliosoftware.com?' . 'subject=Nelio%20A%2FB%20Testing%20-%20Upgrade%20to%20Professional%20Plan&' . 'body=' . esc_html('I\'d like to upgrade to the Professional Plan. I\'m subscribed to Nelio A/B Testing with the following e-mail address: ' . NelioABAccountSettings::get_email() . '.')); } if ($this->user_info['subscription_plan'] == NelioABAccountSettings::PROFESSIONAL_SUBSCRIPTION_PLAN) { echo '<br />'; printf('<a href="%2$s">%1$s</a>', __('Upgrade to our Enterprise Plan.', 'nelioab'), 'mailto:support@neliosoftware.com?' . 'subject=Nelio%20A%2FB%20Testing%20-%20Upgrade%20to%20Enterprise%20Plan&' . 'body=' . esc_html('I\'d like to upgrade to the Enterprise Plan. I\'m subscribed to Nelio A/B Testing with the following e-mail address: ' . NelioABAccountSettings::get_email() . '.')); } } else { switch ($this->user_info['subscription_plan']) { case NelioABAccountSettings::BASIC_SUBSCRIPTION_PLAN: printf(__('You are subscribed to Nelio A/B Testing <b>Basic Plan</b> thanks to %s.', 'nelioab'), $this->user_info['agencyname']); echo '<br />'; break; case NelioABAccountSettings::PROFESSIONAL_SUBSCRIPTION_PLAN: printf(__('You are subscribed to Nelio A/B Testing <b>Professional Plan</b> thanks to %s.', 'nelioab'), $this->user_info['agencyname']); echo '<br />'; break; case NelioABAccountSettings::ENTERPRISE_SUBSCRIPTION_PLAN: printf(__('You are subscribed to Nelio A/B Testing <b>Enterprise Plan</b> thanks to %s.', 'nelioab'), $this->user_info['agencyname']); echo '<br />'; break; } } } } } ?> </p> <?php $post_quota = ''; if (!$this->user_info['agency']) { if (isset($this->user_info['total_quota'])) { $post_quota = sprintf(__('<br />Your current plan permits up to %1$s page views under test per month. If you need more quota, please consider buying additional page views as you need them using the button below, or <a href="%2$s">contact us for an update of your monthly quota</a>.', 'nelioab'), number_format_i18n($this->user_info['total_quota']), 'mailto:support@neliosoftware.com?subject=Nelio%20A%2FB%20Testing%20-%20Monthly%20Quota%20Update'); } } else { $post_quota = sprintf(__('<br />Your current plan permits up to %1$s page views under test per month. If you need more quota, please contact <a href="%2$s">%3$s</a>.', 'nelioab'), number_format_i18n($this->user_info['total_quota']), $this->user_info['agencymail'], $this->user_info['agencyname']); } if (!NelioABAccountSettings::is_using_free_trial() && isset($this->user_info['quota'])) { ?> <p style="margin-top:0em;margin-left:3em;max-width:600px;"> <b><?php _e('Available Quota:', 'nelioab'); ?> </b> <?php $the_total_quota = $this->user_info['total_quota']; $the_quota = $this->user_info['quota']; $quota_color = '#00AA00'; if ($the_quota < $the_total_quota * 0.15) { $quota_color = '#FF9532'; } if ($the_quota < $the_total_quota * 0.05) { $quota_color = 'red'; } ?> <b><?php printf(__('<span style="font-size:120%%;color:%1$s;">%2$s</span> Page Views'), $quota_color, number_format_i18n($the_quota)); ?> </b> <small>(<a href="http://support.nelioabtesting.com/support/solutions/articles/1000129162"><?php _e('Help', 'nelioab'); ?> </a>)</small><?php echo $post_quota; ?> </p><?php if (!$this->user_info['agency']) { ?> <a style="margin-left:3em;margin-bottom:1.5em;" class="button" target="_blank" href="http://sites.fastspring.com/nelio/product/nelioextrapageviewsforthepersonalserviceplan"><?php _e('Buy More', 'nelioab'); ?> </a> <?php } } ?> <?php if (!NelioABAccountSettings::is_using_free_trial() && $this->is_email_valid && $this->is_reg_num_valid && $this->tac) { ?> <?php if ($this->error_retrieving_registered_sites) { ?> <h3><?php _e('Active Sites', 'nelioab'); ?> </h3><?php ?> <p style="margin-top:0em;margin-left:3em;"><?php echo __('There was an error while retrieving the list of active sites related to this account.', 'nelioab'); if (NelioABAccountSettings::has_a_configured_site()) { echo ' '; echo __('Nonetheless, this site is active and ready to be tested.', 'nelioab'); } ?> </p><?php } else { $print_table = true; $sites = array(); switch ($this->current_site_status) { case NelioABSite::NON_MATCHING_URLS: ?> <h3><?php _e('Active Sites', 'nelioab'); ?> </h3><?php $this->print_site_non_matching(); $print_table = false; break; case NelioABSite::ACTIVE: $this->print_table_of_registered_sites(); break; default: ?> <h3><?php _e('This Site is Not Active', 'nelioab'); ?> </h3> <?php $can_register = count($this->sites) < $this->max_sites; if ($can_register) { $this->print_site_should_be_registered(); } else { $this->print_site_cannot_be_registered(); } $this->print_table_of_registered_sites(); } ?> <form id="nelioab_registration_form" method="post"> <input type="hidden" name="nelioab_registration_form" value="true" /> <input type="hidden" id="nelioab_registration_action" name="nelioab_registration_action" value="" /> <input type="hidden" id="nelioab_registration_type" name="nelioab_registration_type" value="" /> <input type="hidden" id="nelioab_registration_sector" name="nelioab_registration_sector" value="" /> </form> <?php } ?> <script type="text/javascript"> (function($) { $dialog = $('#dialog-modal'); $dialog.dialog({ dialogClass : 'wp-dialog', modal : true, autoOpen : false, closeOnEscape : true, width : 400, title : "<?php echo esc_html(__('About Your Site', 'nelioab')); ?> ", buttons: [ { text: "<?php echo esc_html(__('Skip and Activate', 'nelioab')); ?> ", click: function() { $(this).dialog('close'); $('#nelioab_registration_type').attr('value', 'unknown' ); $('#nelioab_registration_sector').attr('value', 'unknown' ); $('#nelioab_registration_action').attr('value', 'register'); $('#nelioab_registration_form').submit(); } }, { text: "<?php echo esc_html(__('Activate', 'nelioab')); ?> ", 'class': 'button button-primary', click: function() { if ( $okButton.hasClass('disabled') ) return; $('#nelioab_registration_action').attr('value', 'register'); $('#nelioab_registration_form').submit(); } } ] }); var $okButton = $dialog.closest('.ui-dialog').find('.button-primary'); $okButton.addClass('disabled'); var $typeSelector = $('#business-type-selector'); $typeSelector.on('change', function() { var ts = $typeSelector.attr('value'); var ss = $sectorSelector.attr('value'); if ( 'unknown' == ts || 'unknown' == ss ) $okButton.addClass('disabled'); else $okButton.removeClass('disabled'); $('#nelioab_registration_type').attr('value', ts ); }); var $sectorSelector = $('#business-sector-selector'); $sectorSelector.on('change', function() { var ts = $typeSelector.attr('value'); var ss = $sectorSelector.attr('value'); if ( 'unknown' == ts || 'unknown' == ss ) $okButton.addClass('disabled'); else $okButton.removeClass('disabled'); $('#nelioab_registration_sector').attr('value', ss ); }); function openDialog() { if ( $typeSelector.attr('value') == 'unknown' ) $okButton.addClass('disabled'); if ( $sectorSelector.attr('value') == 'unknown' ) $okButton.addClass('disabled'); $dialog.dialog('open'); } $("#register-site-button").click(function(ev) { ev.preventDefault(); openDialog(); }); })(jQuery); </script> <?php } } }
/** * It creates a new instance of this class. * * @param string $title The title of the page. * Default: empty string. * * @return NelioABAdminPage a new instance of this class. * * @since PHPDOC */ public function __construct($title = '') { $this->title = $title; $this->title_action = ''; $this->icon_id = 'icon-options-general'; $this->classes = array(); $this->message = false; try { $config = NelioABAccountSettings::check_user_settings(); } catch (Exception $e) { $config = false; } if ($config && NelioABSettings::is_upgrade_message_visible()) { $this->message = sprintf(__('<b><a href="%s">Upgrade to our Professional Plan</a></b> and get the most out of Nelio A/B Testing. Track <b>more visitors</b>, use the service on <b>more sites</b>, and benefit from our <b>consulting services</b>. <small><a class="dismiss-upgrade-notice" href="#" onClick="javascript:dismissUpgradeNotice();">Dismiss</a></small>', 'nelioab'), 'mailto:support@neliosoftware.com?' . 'subject=Nelio%20A%2FB%20Testing%20-%20Upgrade%20my%20Subscription&' . 'body=' . esc_html('I\'d like to upgrade my subscription plan. I\'m subscribed to Nelio A/B Testing with the following e-mail address: ' . NelioABAccountSettings::get_email() . '.')); } }