/**
  * Creates a new instance of this class.
  *
  * @return NelioABFreeTrialPage the new instance of this class.
  *
  * @since 4.1.3
  */
 public function __construct()
 {
     $colorscheme = NelioABWpHelper::get_current_colorscheme();
     $title = __('Nelio A/B Testing — Free Trial', 'nelioab');
     $title .= sprintf(' <span class="nelio-ftcode" style="color:%1$s;border-color:%1$s;">%2$s%3$s</span>', $colorscheme['primary'], __('Code:', 'nelioab'), NelioABAccountSettings::get_nelioab_option('free_trial_code'));
     parent::__construct($title);
 }
 public function __construct($title)
 {
     parent::__construct($title);
     $this->set_icon('icon-nelioab');
     $this->exp = null;
     $this->goal = null;
     $this->results = null;
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     $this->colorscheme = NelioABWpHelper::get_current_colorscheme();
 }
        public function print_alternative_box()
        {
            ?>
			<div id="submitdiv"><?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
				<script>
					var nelioab_style_metabox = document.createElement("style");
					nelioab_style_metabox.setAttribute("type", "text/css");
					nelioab_style_metabox.innerHTML = "#save_nelioab_alternative_box h3.hndle { " +
						"color:<?php 
            echo $colorscheme['foreground'];
            ?>
; " +
						"background: <?php 
            echo $colorscheme['focus'];
            ?>
;" +
						"border: 1px solid <?php 
            echo $colorscheme['focus'];
            ?>
;" +
					"}" +
					"#favorite-actions, #message, .add-new-h2, .tablenav, #edit-slug-box { display:none; }" +
					"#save_nelioab_alternative_box .handlediv," +
					"#save_nelioab_alternative_box .handlediv:hover { visibility:visible; color:white; }";
					document.getElementsByTagName('head')[0].appendChild(nelioab_style_metabox);
				</script>
				<div class="submitbox" id="submitpost">
					<div class="misc-pub-section" style="min-height:4em;">
						<div style="float:right;margin-top:1em;">
							<input name="original_publish" type="hidden" id="original_publish" value="Update">
							<input name="save" type="submit"
								class="button button-primary" id="publish"
								tabindex="5"
								value="<?php 
            _e('Update');
            ?>
" />
						</div>
						<?php 
            $the_post_id = 0;
            if (isset($_GET['post'])) {
                $the_post_id = $_GET['post'];
            }
            $url = admin_url('admin.php?page=nelioab-experiments');
            $values = explode(',', get_post_meta($the_post_id, '_is_nelioab_alternative', true));
            $exp_id = $values[0];
            $exp_status = $values[1];
            ?>
						<div style="float:right;margin-top:1em;margin-right:1em;">
							<div id="preview-action">
								<?php 
            $type = 'post';
            $ori_id = get_post_meta($_GET['post'], '_nelioab_original_id', true);
            if (NelioABExperiment::STATUS_RUNNING == $exp_status || NelioABExperiment::STATUS_FINISHED == $exp_status) {
                $preview_button = __('Preview Changes');
            } else {
                $preview_button = __('Preview');
            }
            $preview_link = get_permalink($_GET['post']);
            $preview_link = esc_url(add_query_arg('preview', 'true', $preview_link));
            ?>
								<a class="preview button" href="<?php 
            echo $preview_link;
            ?>
" target="wp-preview-<?php 
            echo $_GET['post'];
            ?>
" id="post-preview"><?php 
            echo $preview_button;
            ?>
</a>
								<input type="hidden" name="wp-preview" id="wp-preview" value="" />
							</div>
						</div>
					</div>
					<div style="margin:0.8em 0.2em 0.8em 0.2em;">
						<b><?php 
            _e('Go back to...', 'nelioab');
            ?>
</b>
						<ul style="margin-left:1.5em;">
							<?php 
            switch ($exp_status) {
                case NelioABExperiment::STATUS_DRAFT:
                case NelioABExperiment::STATUS_READY:
                    ?>
<li><a href="<?php 
                    echo $url . '&action=edit&ctab=tab-alts&id=' . $exp_id . '&exp_type=' . NelioABExperiment::PAGE_OR_POST_ALT_EXP;
                    ?>
"><?php 
                    _e('Editing this experiment', 'nelioab');
                    ?>
</a></li><?php 
                    break;
                case NelioABExperiment::STATUS_RUNNING:
                case NelioABExperiment::STATUS_FINISHED:
                    ?>
<li><a href="<?php 
                    echo $url . '&action=progress&id=' . $exp_id . '&exp_type=' . NelioABExperiment::PAGE_OR_POST_ALT_EXP;
                    ?>
"><?php 
                    _e('The results of the related experiment', 'nelioab');
                    ?>
</a></li><?php 
                    break;
                case NelioABExperiment::STATUS_TRASH:
                case NelioABExperiment::STATUS_PAUSED:
                default:
                    // Nothing here
            }
            ?>
							<li><a href="<?php 
            echo $url;
            ?>
"><?php 
            _e('My list of experiments', 'nelioab');
            ?>
</a></li>
							<?php 
            if ($exp_status == NelioABExperiment::STATUS_RUNNING) {
                ?>
								<li><a href="<?php 
                echo admin_url('admin.php?page=nelioab-dashboard');
                ?>
"><?php 
                _e('The Dashboard', 'nelioab');
                ?>
</a></li>
							<?php 
            }
            ?>
						</ul>
					</div>
				</div>
			</div><?php 
        }
 private static function prepare_pro_label($label, $help = true)
 {
     if (!NelioABAccountSettings::is_plan_at_least(NelioABAccountSettings::PROFESSIONAL_SUBSCRIPTION_PLAN)) {
         $res = '<span class="pro-setting-label setting-disabled">' . $label;
         if ($help) {
             $res .= ' ' . self::get_icon('#AAA');
         }
         $res .= '</span>';
         return $res;
     } else {
         $aux = NelioABWpHelper::get_current_colorscheme();
         $color = $aux['primary'];
         $res = '<span class="pro-setting-label">' . $label;
         if ($help) {
             $res .= ' ' . self::get_icon($color);
         }
         $res .= '</span>';
         return $res;
     }
 }
        protected function print_the_real_alternatives()
        {
            // REAL ALTERNATIVES
            // -----------------------------------------
            $exp = $this->exp;
            if ($this->results == null) {
                $alt_results = null;
                $ori_conversions = 0;
            } else {
                $alt_results = $this->results->get_alternative_results();
                $ori_conversions = $alt_results[0]->get_num_of_conversions();
                // in this function, the original alternative is NOT used
                $alt_results = array_slice($alt_results, 1);
            }
            $conversions_label = __('Conversions', 'nelioab');
            $pageviews_label = __('Pageviews', 'nelioab');
            $conversion_views_label = __('Conversions / Views', 'nelioab');
            $conversion_rate_label = __('Conversion Rate', 'nelioab');
            $alternative_label = __('Alternative', 'nelioab');
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            $color = $colorscheme['primary'];
            $base_color = $color;
            $i = 0;
            foreach ($exp->get_alternatives() as $alt) {
                $i++;
                $name = $this->trunk($alt->get_name());
                $icon = $this->get_experiment_icon($exp);
                $id = $alt->get_id();
                $graphic_id = 'graphic-' . $id;
                if ($alt_results != null) {
                    $alt_result = $alt_results[$i - 1];
                    $pageviews = $alt_result->get_num_of_visitors();
                    $conversions = $alt_result->get_num_of_conversions();
                    $conversion_rate = $alt_result->get_conversion_rate();
                    $improvement_factor = $alt_result->get_improvement_factor();
                } else {
                    $pageviews = 0;
                    $conversions = 0;
                    $conversion_rate = 0.0;
                    $improvement_factor = 0.0;
                }
                $alt_conversion_views = $conversions . ' / ' . $pageviews;
                $aux = $ori_conversions * $this->goal->get_benefit() * $improvement_factor / 100;
                $print_improvement = true;
                // format improvement factor
                if ($improvement_factor < 0) {
                    $arrow = 'fa-arrow-down';
                    $stats_color = 'red';
                    $improvement_factor = $improvement_factor * -1;
                } else {
                    if ($improvement_factor > 0) {
                        $arrow = 'fa-arrow-up';
                        $stats_color = 'green';
                    } else {
                        // $improvement_factor = 0.0
                        $arrow = 'fa-none';
                        $stats_color = 'black';
                        $print_improvement = false;
                    }
                }
                if ($aux > 0) {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux, 2));
                } else {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux * -1, 2));
                }
                $alt_conversion_rate = number_format_i18n(floatval($conversion_rate), 2) . ' %';
                $alt_improvement_factor = number_format_i18n(floatval($improvement_factor), 2) . ' %';
                $alternative_number = $i;
                $winner = false;
                $winner_color = '';
                if ($this->is_winner($alt->get_id())) {
                    $icon = $this->get_winner_icon($exp);
                    $color = $colorscheme['winner'];
                    $winner_color = 'style="background-color:' . $colorscheme['primary'] . ';color:' . $colorscheme['foreground'] . ';"';
                    $winner = true;
                } else {
                    $color = $base_color;
                }
                $action_links = $this->get_action_links($exp, $alt->get_id(), $winner);
                $buttons = implode(' ', $action_links);
                if (!$print_improvement) {
                    $gain = '';
                    $alt_improvement_factor = '';
                }
                $result = <<<HTML
\t\t\t\t<div class="nelio-alternative alternative-{$i} postbox nelio-card">
\t\t\t\t\t<div class="alt-info-header" {$winner_color}>
\t\t\t\t\t\t{$icon}
\t\t\t\t\t\t<span class="alt-title">{$name}</span>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-body">
\t\t\t\t\t\t<div class="alt-screen no-hover" id="{$id}" style="color:{$color};">
\t\t\t\t\t\t\t\t<div class="alt-name">
\t\t\t\t\t\t\t\t\t{$alternative_label}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-number">
\t\t\t\t\t\t\t\t\t{$alternative_number}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t\t<div class="alt-stats">
\t\t\t\t\t\t\t<div class="alt-stats-graphic" id="{$graphic_id}"></div>
\t\t\t\t\t\t\t<div class="alt-status">
\t\t\t\t\t\t\t\t<div class="alt-cv">
\t\t\t\t\t\t\t\t\t<span class="alt-cv-title">{$conversion_views_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cv">{$alt_conversion_views}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-cr">
\t\t\t\t\t\t\t\t\t<span class="alt-cr-title">{$conversion_rate_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cr">{$alt_conversion_rate}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-stats" style="color:{$stats_color};">
\t\t\t\t\t\t\t\t\t<span class="alt-if"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$alt_improvement_factor}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-ii"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$gain}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-footer">
\t\t\t\t\t\t<div class="alt-info-footer-content">
\t\t\t\t\t\t\t{$buttons}
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t<script>
\t\t\t\tjQuery(document).ready(function() {
\t\t\t\t\tdrawAlternativeGraphic('{$graphic_id}',
\t\t\t\t\t\t{$conversions},
\t\t\t\t\t\t'{$conversions_label}',
\t\t\t\t\t\t'{$color}',
\t\t\t\t\t\t{$pageviews},
\t\t\t\t\t\t'{$pageviews_label}');
\t\t\t\t});
\t\t\t\t</script>
HTML;
                echo $result;
            }
        }
        /**
         * This function adds just one script in the nav-menus.php page. The script
         * checks if the user is currently editing a menu exp alternative and, if
         * it is, it'll hide all menus except the alternative's.
         */
        public function add_code_to_hide_menus_when_editing_menu_exp()
        {
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
			<div id="nelioab-edit-alt-menus" class="widgets-holder-wrap" style="margin-bottom:1em;display:none;border: 1px solid #e5e5e5;-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);box-shadow: 0 1px 1px rgba(0,0,0,.04);">
				<div class="widgets-sortables ui-sortable">
					<div class="sidebar-name" style="padding:0.2em 1em;background-color:<?php 
            echo $colorscheme['focus'];
            ?>
;">
						<div class="sidebar-name-arrow"><br></div>
						<h3 style="color:<?php 
            echo $colorscheme['foreground'];
            ?>
;"><?php 
            _e('Alternative Menu', 'nelioab');
            ?>
</h3>
					</div>
				</div>

				<div class="content" style="padding:0em 1em 1em 1em;">
					<p><strong><?php 
            _e('Go back to...', 'nelioab');
            ?>
</strong></p>
					<ul style="margin-left:1.5em;">
						<?php 
            if (isset($_GET['back_to_edit'])) {
                $url = admin_url('admin.php?page=nelioab-experiments&action=edit&id=' . $_GET['nelioab_exp'] . '&ctab=tab-alts&exp_type=' . NelioABExperiment::MENU_ALT_EXP);
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('Editing this experiment', 'nelioab');
                ?>
</a></li>
						<?php 
            } else {
                $url = admin_url('admin.php?page=nelioab-experiments&action=progress&id=' . $_GET['nelioab_exp'] . '&exp_type=' . NelioABExperiment::MENU_ALT_EXP);
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('The results of the related experiment', 'nelioab');
                ?>
</a></li>
						<?php 
            }
            ?>
						<?php 
            $url = admin_url('admin.php?page=nelioab-experiments');
            ?>
						<li><a href="<?php 
            echo $url;
            ?>
"><?php 
            _e('My list of experiments', 'nelioab');
            ?>
</a></li>
					</ul>
				</div>

			</div>

			<script type="text/javascript">
			(function($) {
				// Hide Top Area
				$('.nav-tab-wrapper').hide();
				$('.manage-menus').hide();
				$('#nav-menus-frame').css('padding-top', '30px');
				// Hide Menu Box
				$('.menu-name-label').hide();
				$('.menu-settings').hide();
				$('.delete-action').hide();
				// Add Alternative Box
				$content = $('#nelioab-edit-alt-menus .content');
				$('#nelioab-edit-alt-menus .sidebar-name').on('click', function() {
					$content.toggle();
				});
				var $aux = $('#nelioab-edit-alt-menus').detach();
				$('#nav-menu-meta').prepend($aux);
				$aux.show();
				var $msg = $('#message');
				$msg.html($msg.html().replace(/Menu[0-9.\s]+(\s)?/, '<?php 
            echo esc_html(__('Alternative Menu', 'nelioab'));
            ?>
\1'));
			})(jQuery);
			</script>
			<?php 
        }
        protected function print_the_real_alternatives()
        {
            // REAL ALTERNATIVES
            // -----------------------------------------
            $exp = $this->exp;
            $the_themes = wp_get_themes();
            if ($this->results == null) {
                $alt_results = null;
                $ori_conversions = 0;
            } else {
                $alt_results = $this->results->get_alternative_results();
                $ori_conversions = $alt_results[0]->get_num_of_conversions();
                // in this function, the original alternative is NOT used
                $alt_results = array_slice($alt_results, 1);
            }
            $conversions_label = __('Conversions', 'nelioab');
            $pageviews_label = __('Pageviews', 'nelioab');
            $conversion_views_label = __('Conversions / Views', 'nelioab');
            $conversion_rate_label = __('Conversion Rate', 'nelioab');
            $alternative_label = __('Alternative', 'nelioab');
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            $color = $colorscheme['primary'];
            $base_color = $color;
            $i = 0;
            foreach ($exp->get_alternatives() as $alt) {
                $i++;
                $action_links = array();
                $name = $this->trunk($alt->get_name());
                $icon = $this->get_experiment_icon($exp);
                $id = $alt->get_id();
                $graphic_id = 'graphic-' . $id;
                if ($alt_results != null) {
                    $alt_result = $alt_results[$i - 1];
                    $pageviews = $alt_result->get_num_of_visitors();
                    $conversions = $alt_result->get_num_of_conversions();
                    $conversion_rate = $alt_result->get_conversion_rate();
                    $improvement_factor = $alt_result->get_improvement_factor();
                } else {
                    $pageviews = 0;
                    $conversions = 0;
                    $conversion_rate = 0.0;
                    $improvement_factor = 0.0;
                }
                $alt_conversion_views = $conversions . ' / ' . $pageviews;
                $aux = $ori_conversions * $this->goal->get_benefit() * $improvement_factor / 100;
                $print_improvement = true;
                // format improvement factor
                if ($improvement_factor < 0) {
                    $arrow = 'fa-arrow-down';
                    $stats_color = 'red';
                    $improvement_factor = $improvement_factor * -1;
                } else {
                    if ($improvement_factor > 0) {
                        $arrow = 'fa-arrow-up';
                        $stats_color = 'green';
                    } else {
                        // $improvement_factor = 0.0
                        $arrow = 'fa-none';
                        $stats_color = 'black';
                        $print_improvement = false;
                    }
                }
                if ($aux > 0) {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux, 2));
                } else {
                    $gain = sprintf(__('%1$s%2$s', 'nelioab', 'money'), NelioABSettings::get_conv_unit(), number_format_i18n($aux * -1, 2));
                }
                $alt_conversion_rate = number_format_i18n(floatval($conversion_rate), 2) . ' %';
                $alt_improvement_factor = number_format_i18n(floatval($improvement_factor), 2) . ' %';
                $alternative_number = $i;
                $winner_color = '';
                if ($this->is_winner($alt->get_id())) {
                    $icon = $this->get_winner_icon($exp);
                    $color = $colorscheme['winner'];
                    $winner_color = 'style="background-color:' . $colorscheme['primary'] . ';color:' . $colorscheme['foreground'] . ';"';
                } else {
                    $color = $base_color;
                }
                $theme = null;
                $theme_image = '#';
                foreach ($the_themes as $t) {
                    if ($t['Stylesheet'] == $alt->get_value()) {
                        $theme = $t;
                        $theme_image = $t->get_screenshot();
                        break;
                    }
                }
                if ($theme != NULL && $exp->get_status() == NelioABExperiment::STATUS_FINISHED) {
                    $img = '<span id="loading-' . $alt->get_value() . '" class="dashicons dashicons-update fa-spin animated nelio-apply"></span>';
                    $aux = sprintf(' <a class="apply-link button" href="javascript:nelioab_confirm_overwriting(\'%1$s\', \'%2$s\', \'%3$s\');">%4$s %5$s</a>', $alt->get_value(), $theme['Stylesheet'], $theme['Template'], $img, __('Apply', 'nelioab'));
                    array_push($action_links, $aux);
                }
                $buttons = implode(' ', $action_links);
                if (!$print_improvement) {
                    $gain = '';
                    $alt_improvement_factor = '';
                }
                $result = <<<HTML
\t\t\t\t<div class="nelio-alternative alternative-{$i} postbox nelio-card">
\t\t\t\t\t<div class="alt-info-header" {$winner_color}>
\t\t\t\t\t\t{$icon}
\t\t\t\t\t\t<span class="alt-title">{$name}</span>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-body">
\t\t\t\t\t\t<div class="alt-screen hover-img-fade" id="{$id}" style="color:{$color};">
\t\t\t\t\t\t\t<img class="alt-theme-img" src="{$theme_image}" width="320" height="240">
\t\t\t\t\t\t\t\t<div class="alt-name">
\t\t\t\t\t\t\t\t\t{$alternative_label}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-number">
\t\t\t\t\t\t\t\t\t{$alternative_number}
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t\t<div class="alt-stats">
\t\t\t\t\t\t\t<div class="alt-stats-graphic" id="{$graphic_id}"></div>
\t\t\t\t\t\t\t<div class="alt-status">
\t\t\t\t\t\t\t\t<div class="alt-cv">
\t\t\t\t\t\t\t\t\t<span class="alt-cv-title">{$conversion_views_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cv">{$alt_conversion_views}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-cr">
\t\t\t\t\t\t\t\t\t<span class="alt-cr-title">{$conversion_rate_label}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-cr">{$alt_conversion_rate}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t<div class="alt-stats" style="color:{$stats_color};">
\t\t\t\t\t\t\t\t\t<span class="alt-if"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$alt_improvement_factor}</span>
\t\t\t\t\t\t\t\t\t<span class="alt-ii"><i class="fa {$arrow}" style="vertical-align: top;"></i>{$gain}</span>
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="alt-info-footer">
\t\t\t\t\t\t<div class="alt-info-footer-content">
\t\t\t\t\t\t\t{$buttons}
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t<script>
\t\t\t\tjQuery(document).ready(function() {
\t\t\t\t\tdrawAlternativeGraphic('{$graphic_id}',
\t\t\t\t\t\t{$conversions},
\t\t\t\t\t\t'{$conversions_label}',
\t\t\t\t\t\t'{$color}',
\t\t\t\t\t\t{$pageviews},
\t\t\t\t\t\t'{$pageviews_label}');
\t\t\t\t});
\t\t\t\t</script>
HTML;
                echo $result;
            }
        }
    protected function do_render()
    {
        ?>

		<div id="post-body" class="metabox-holder columns-2">
		<form id="css_edit_value" method="POST" action="#">
			<input type="hidden" name="css_save_alt" id="css_save_alt" value="true"></input>
			<div id="post-body-content">

				<div id="titlediv">

					<div id="titlewrap">
						<label class="screen-reader-text" id="title-prompt-text" for="title">Enter title here</label>
						<input type="text" name="post_title" size="30" value="<?php 
        echo $this->css_alt->get_name();
        ?>
" id="title" autocomplete="off"></input>
					</div>

					<div class="inside">
						<div id="postdivrich" class="postarea edit-form-section">
							<div id="wp-content-wrap" class="wp-core-ui wp-editor-wrap tmce-active">
								<div class="wp-editor-tabs">
									<br>
									<!-- <a id="content-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Plain</a> -->
									<!-- <a id="content-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</a> -->
								</div>
							</div>
								<input type="hidden" id="content" name="content"></input>
								<pre id="editor"><?php 
        echo $this->css_alt->get_value();
        ?>
</pre>
								<script type="text/javascript" src="<?php 
        echo nelioab_admin_asset_link('/lib/ace-editor/ace.js');
        ?>
"></script>
								<script type="text/javascript">
									var nelioabCssEditor = ace.edit('editor');
									nelioabCssEditor.setTheme('ace/theme/tomorrow');
									nelioabCssEditor.session.setMode('ace/mode/css');
									nelioabCssEditor.setAutoScrollEditorIntoView(true);
									nelioabCssEditor.setOption('minLines', 20);
									nelioabCssEditor.setOption('maxLines', 100);
									nelioabCssEditor.setFontSize(15);
								</script>
						</div>
					</div>

				</div>
			</div><!-- /post-body-content -->

			<div id="postbox-container-1" class="postbox-container">

				<div id="save_nelioab_alternative_box" class="meta-box-sortables ui-sortable">
					<div id="submitdiv" class="postbox"><?php 
        require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
        $colorscheme = NelioABWpHelper::get_current_colorscheme();
        ?>
						<script>
							var nelioab_style_metabox = document.createElement("style");
							nelioab_style_metabox.setAttribute("type", "text/css");
							nelioab_style_metabox.innerHTML = "#save_nelioab_alternative_box h3.hndle { " +
								"color:<?php 
        echo $colorscheme['foreground'];
        ?>
; " +
								"background: <?php 
        echo $colorscheme['focus'];
        ?>
;" +
								"border: 1px solid <?php 
        echo $colorscheme['focus'];
        ?>
;" +
							"}" +
							"#favorite-actions, #message, .add-new-h2, .tablenav, #edit-slug-box { display:none; }" +
							"#save_nelioab_alternative_box .handlediv," +
							"#save_nelioab_alternative_box .handlediv:hover { visibility:visible; color:white; }";
							document.getElementsByTagName('head')[0].appendChild(nelioab_style_metabox);
						</script>

						<h3 style="cursor:auto;" class="hndle"><span><?php 
        _e('Update');
        ?>
</span></h3>
						<div class="inside">
							<div class="submitbox" id="submitpost">

								<div style="margin:1em;">
									<p><?php 
        _e('Select a page or post for preview', 'nelioab');
        ?>
</p>
									<?php 
        require_once NELIOAB_UTILS_DIR . '/html-generator.php';
        NelioABHtmlGenerator::print_full_searcher('post-options', false, 'show-drafts');
        ?>
								</div>

								<div class="misc-pub-section" style="min-height:4em;">
									<div style="float:right;margin-top:1em;">
										<input name="original_publish" type="hidden" id="original_publish" value="Update">
										<input name="save" type="submit"
											class="button button-primary" id="publish"
											tabindex="5"
											value="<?php 
        _e('Update');
        ?>
" />
										<script type="text/javascript">
										jQuery( "#css_edit_value" ).on( 'submit', function() {
											jQuery("#content").attr('value', nelioabCssEditor.getValue());
										});
										</script>
									</div>
									<div style="float:right;margin-top:1em;margin-right:1em;">
										<div id="preview-action">
											<a id="preview-button" class="preview button" target="wp-preview" id="post-preview" tabindex="4"><?php 
        _e('Preview');
        ?>
</a>
											<input type="hidden" name="wp-preview" id="wp-preview" value="" />
										</div>
									</div>
								</div>
								<?php 
        $url = admin_url('admin.php');
        $url = add_query_arg(array('nelioab-page' => 'save-css', 'preview' => 'true', 'nelioab_preview_css' => $_REQUEST['css_id']), $url);
        ?>
								<script>
									jQuery("#preview-button").click(function(e) {
										var aux = jQuery("#post-options").attr('value');
										if ( aux == -1 || aux == "" || aux == undefined ) return;
										if ( aux == <?php 
        echo NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS;
        ?>
 ) aux = "";
										else aux = "&p=" + aux;
										jQuery("#css_edit_value").attr('action', "<?php 
        echo $url;
        ?>
" + aux);
										jQuery("#css_edit_value").attr('target', '_blank');
										jQuery("#css_edit_value").submit();
										jQuery("#css_edit_value").attr('action', '#');
										jQuery("#css_edit_value").attr('target', '');
									});
								</script>

								<div style="margin:10px;">
									<b><?php 
        _e('Go back to...', 'nelioab');
        ?>
</b>
									<?php 
        $url = admin_url('admin.php?page=nelioab-experiments');
        $exp_id = $this->experiment->get_id();
        $exp_status = $this->experiment->get_status();
        ?>
									<ul style="margin-left:1.5em;">
										<?php 
        require_once NELIOAB_MODELS_DIR . '/experiment.php';
        switch ($exp_status) {
            case NelioABExperiment::STATUS_DRAFT:
            case NelioABExperiment::STATUS_READY:
                ?>
<li><a href="<?php 
                echo $url . '&action=edit&ctab=tab-alts&id=' . $exp_id . '&exp_type=' . $this->experiment->get_type();
                ?>
"><?php 
                _e('Editing this experiment', 'nelioab');
                ?>
</a></li><?php 
                break;
            case NelioABExperiment::STATUS_RUNNING:
            case NelioABExperiment::STATUS_FINISHED:
                ?>
<li><a href="<?php 
                echo $url . '&action=progress&id=' . $exp_id . '&exp_type=' . $this->experiment->get_type();
                ?>
"><?php 
                _e('The results of the related experiment', 'nelioab');
                ?>
</a></li><?php 
                break;
            case NelioABExperiment::STATUS_TRASH:
            case NelioABExperiment::STATUS_PAUSED:
            default:
                // Nothing here
        }
        ?>
									   <li><a href="<?php 
        echo $url;
        ?>
"><?php 
        _e('My list of experiments', 'nelioab');
        ?>
</a></li>
									   <li><a href="<?php 
        echo admin_url('admin.php?page=nelioab-dashboard');
        ?>
"><?php 
        _e('The Dashboard', 'nelioab');
        ?>
</a></li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- END OF SIDEBAR -->

			</div>
		</form>
		</div>
		<?php 
    }
        protected function print_alternatives()
        {
            ?>
			<h2 style="padding-top:2em;"><?php 
            _e('Alternatives', 'nelioab');
            ?>
</h2>

			<?php 
            $this->print_theme($this->current_theme['id'], $this->current_theme['name'], $this->current_theme['image'], $this->current_theme['creator'], true, true);
            foreach ($this->themes as $theme) {
                $this->print_theme($theme['id'], $theme['name'], $theme['image'], $theme['creator'], $theme['selected']);
            }
            ?>

			<input type="hidden" name="nelioab_selected_themes" id="nelioab_selected_themes" value="<?php 
            echo rawurlencode(json_encode($this->selected_themes));
            ?>
" />

			<input type="hidden" name="nelioab_appspot_ids" id="nelioab_appspot_ids" value="<?php 
            echo rawurlencode(json_encode($this->appspot_ids));
            ?>
" />

			<script type="text/javascript">
				var NelioABSelectedThemes;
				(function($) {

					<?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $colorscheme = NelioABWpHelper::get_current_colorscheme();
            ?>
					NelioABParams = {css:{}};
					NelioABParams.css.value	= document.createElement('style');
					NelioABParams.css.value.setAttribute('type', 'text/css');
					NelioABParams.css.value.innerHTML = '' +
						'.nelioab-selected .theme-image-selector { ' +
						'  border-color:<?php 
            echo $colorscheme['primary'];
            ?>
 !important;' +
						'} ' +
						'.nelioab-theme.nelioab-selected, .nelioab-theme.nelioab-selected:hover { ' +
						'  background:<?php 
            echo $colorscheme['primary'];
            ?>
 !important;' +
						'}';
					document.getElementsByTagName('head')[0].appendChild(NelioABParams.css.value);


					NelioABSelectedThemes = JSON.parse( decodeURIComponent(
							jQuery('#nelioab_selected_themes').attr('value')
						)	);

					function validate() {
						var isOneSelected = false;
						for( var i = 0; i < NelioABSelectedThemes.length && !isOneSelected; ++i )
							if ( NelioABSelectedThemes[i].isSelected )
								isOneSelected = true;
						if ( isOneSelected )
							return [true,true];
						else
							return [true,false];
					}

					function toggleTheme( theme ) {
						if ( theme.hasClass( 'nelioab-is-current-theme' ) )
							return;
						var selected;
						if ( theme.hasClass('nelioab-selected') ) {
							theme.removeClass('nelioab-selected');
							selected = false;
						}
						else {
							theme.addClass('nelioab-selected');
							selected = true;
						}

						var id = theme.attr('id');
						var name = theme.find('.the-whole-name').first().text();
						var found = false;
						for( var i = 0; i < NelioABSelectedThemes.length && !found; ++i ) {
							var st = NelioABSelectedThemes[i];
							if ( st.value == id )
								found = st;
						}
						if ( !found ) {
							found = { value: id, name: name };
							NelioABSelectedThemes.push( found );
						}
						found.isSelected = selected;
						validate();
					}

					$('.nelioab-theme').click(function() {
						toggleTheme($(this));
					});

					// Save the experiment (and encode the alternatives)
					$(document).on('save-experiment', function() {
						$( '#nelioab_selected_themes' ).attr('value',
							encodeURIComponent( JSON.stringify( NelioABSelectedThemes ) )
								.replace( /'/g, "%27") );
					});

					$(document).on( 'tab-changed', function( e, tabId ) {
						if ( tabId == 'tab-theme-alts' )
							NelioABEditExperiment.validateCurrentTab = validate;
					});

				})(jQuery);
			</script>
			<?php 
        }
        /**
         * This function adds just one script in the widgets.php page. The script
         * checks if the user is currently editing a widget exp alternative and, if
         * it is, it'll hide all widgets except the alternative's.
         *
         * If he's editing no alternative, then all widgets that belong to one will
         * be hidden.
         */
        public function add_code_to_hide_widgets_when_editing_widget_exp()
        {
            $widgets_in_experiments = self::get_widgets_in_experiments();
            $viewing_original = !$this->validate($_GET, 'check');
            $exp_id = '';
            $alt_id = '';
            if ($viewing_original) {
                $widgets_to_hide = array_keys($widgets_in_experiments);
                $exp_id = 'original';
                $alt_id = 'original';
                ?>
				<script type="text/javascript">
				jQuery(document).ready(function() {
					var ids = <?php 
                echo json_encode($widgets_to_hide);
                ?>
;
					for ( i = 0; i < ids.length; ++i ) {
						jQuery('#widgets-right .nelioab-widget-' + ids[i]).closest('.widget').hide();
						jQuery('#wp_inactive_widgets .nelioab-widget-' + ids[i]).closest('.widget').hide();
					}
				});
				</script>
				<?php 
            } else {
                $widgets_to_show = array();
                $exp_id = $_GET['nelioab_exp'];
                $alt_id = $_GET['nelioab_alt'];
                foreach ($widgets_in_experiments as $widget_id => $exp_info) {
                    if ($exp_info['exp'] == $exp_id && $exp_info['alt'] == $alt_id) {
                        array_push($widgets_to_show, $widget_id);
                    }
                }
                require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
                $colorscheme = NelioABWpHelper::get_current_colorscheme();
                ?>

				<div id="nelioab-edit-alt-widgets" class="widgets-holder-wrap" style="border: 1px solid #e5e5e5;-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);box-shadow: 0 1px 1px rgba(0,0,0,.04);">
					<div class="widgets-sortables ui-sortable">
						<div class="sidebar-name" style="padding:0.2em 1em;background-color:<?php 
                echo $colorscheme['focus'];
                ?>
;">
							<div class="sidebar-name-arrow"><br></div>
							<h3 style="color:<?php 
                echo $colorscheme['foreground'];
                ?>
;"><?php 
                _e('Alternative Widget Set', 'nelioab');
                ?>
</h3>
						</div>
					</div>

					<div class="content" style="padding:0em 1em 1em 1em;">
						<p><?php 
                _e('Use the following button to duplicate the widgets you\'re currently using in your site.', 'nelioab');
                ?>
</p>
						<a class="button button-primary" id="duplicate-widgets"><?php 
                _e('Duplicate Widgets', 'nelioab');
                ?>
</a>
						<span class="spinner" style="float:none;"></span>
						<p><strong><?php 
                _e('Go back to...', 'nelioab');
                ?>
</strong></p>
						<ul style="margin-left:1.5em;">
							<?php 
                if (isset($_GET['back_to_edit'])) {
                    $url = admin_url('admin.php?page=nelioab-experiments&action=edit&id=' . $_GET['nelioab_exp'] . '&ctab=tab-alts&exp_type=' . NelioABExperiment::WIDGET_ALT_EXP);
                    ?>
								<li><a href="<?php 
                    echo $url;
                    ?>
"><?php 
                    _e('Editing this experiment', 'nelioab');
                    ?>
</a></li>
							<?php 
                } else {
                    $url = admin_url('admin.php?page=nelioab-experiments&action=progress&id=' . $_GET['nelioab_exp'] . '&exp_type=' . NelioABExperiment::WIDGET_ALT_EXP);
                    ?>
								<li><a href="<?php 
                    echo $url;
                    ?>
"><?php 
                    _e('The results of the related experiment', 'nelioab');
                    ?>
</a></li>
							<?php 
                }
                ?>
							<?php 
                $url = admin_url('admin.php?page=nelioab-experiments');
                ?>
							<li><a href="<?php 
                echo $url;
                ?>
"><?php 
                _e('My list of experiments', 'nelioab');
                ?>
</a></li>
						</ul>
					</div>

				</div>

				<script type="text/javascript">
				(function($) {
					var $content = jQuery('#nelioab-edit-alt-widgets .content');
					$('#nelioab-edit-alt-widgets .sidebar-name').on('click', function() {
						$content.toggle();
					});

					$('#duplicate-widgets').on('click', function() {
						if ( $(this).hasClass('disabled') )
							return;
						$(this).addClass('disabled');
						$('#nelioab-edit-alt-widgets .spinner').css('display', 'inline-block');
						$('#available-widgets,.inactive-sidebar,.widget-liquid-right').fadeOut();

						jQuery.ajax({
							type:  'POST',
							async: false,
							url:   ajaxurl,
							data: {
									action: 'nelioab_duplicate_original_widgets',
									exp_id: <?php 
                echo $_GET['nelioab_exp'];
                ?>
,
									alt_id: <?php 
                echo $_GET['nelioab_alt'];
                ?>
,
									check:  '<?php 
                echo hash('md5', $_GET['nelioab_exp'] . $_GET['nelioab_alt']);
                ?>
',
								},
							success: function(data) {
								window.location.reload();
							},
							error: function(data) {
								// Something failed :-(
							},
						});

					});

					$(document).ajaxComplete(function() {
						if ( jQuery("#widgets-right .widget:visible").length > 0 )
							jQuery('#duplicate-widgets').addClass('disabled');
						else
							jQuery('#duplicate-widgets').removeClass('disabled');
					});

				})(jQuery);

				jQuery(document).ready(function() {
					// Hide all widgets and then show only those that belong to this alt/exp combo
					jQuery('#widgets-right .widget').hide();
					jQuery('#wp_inactive_widgets .widget').hide();
					var ids = <?php 
                echo json_encode($widgets_to_show);
                ?>
;
					for ( i = 0; i < ids.length; ++i )
						jQuery('.nelioab-widget-' + ids[i]).closest('.widget').css('display','');

					// Disable "duplicate widgets" button if there are widgets
					if ( jQuery("#widgets-right .widget:visible").length > 0 )
						jQuery('#duplicate-widgets').addClass('disabled');
					else
						jQuery('#duplicate-widgets').removeClass('disabled');

					// Add controls
					var $block = jQuery('#nelioab-edit-alt-widgets').detach();
					jQuery('#widgets-left').prepend($block);
					$block.show();
				});
				</script>
				<?php 
            }
            // Set the proper EXP/ALT combo values for new widgets
            ?>
			<script type="text/javascript">
			jQuery(document).ready(function() {
				jQuery('#available-widgets .widget input[name=nelioab_exp]').attr('value','<?php 
            echo $exp_id;
            ?>
');
				jQuery('#available-widgets .widget input[name=nelioab_alt]').attr('value','<?php 
            echo $alt_id;
            ?>
');
			});
			</script>
			<?php 
        }
        public function do_render()
        {
            echo '<div id="post-body" class="metabox-holder columns-2">';
            echo '<div id="post-body-content">';
            if (count($this->experiments) == 0) {
                echo "<div class='nelio-message'>";
                echo sprintf('<img class="animated flipInY" src="%s" alt="%s" />', nelioab_admin_asset_link('/images/dashboard.png'), __('Dashboard Icon', 'nelioab'));
                echo '<h2 style="max-width:750px;">';
                printf('%1$s<br><br><a class="button button-primary" href="%3$s">%2$s</a>', __('Here you\'ll find relevant information about your running experiments.', 'nelioab'), __('Create One Now!', 'nelioab', 'create-experiment'), 'admin.php?page=nelioab-add-experiment');
                echo '</h2>';
                echo '</div>';
            } else {
                echo '<h2>' . __('Running Experiments', 'nelioab') . '</h2>';
                $this->print_cards();
            }
            echo '</div>';
            ?>
			<div id="postbox-container-1" class="postbox-container" style="overflow:hidden;">
				<h2>&nbsp;</h2>
				<?php 
            require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
            $cs = NelioABWpHelper::get_current_colorscheme();
            ?>

				<div class="numbers" style="height:40px;">
					<div class="left" style="float:left; width:55%;">
						<span style="font-weight:bold;"><?php 
            _e('AVAILABLE QUOTA', 'nelioab');
            ?>
</span><br>
						<span style="color:<?php 
            echo $cs['primary'];
            ?>
; font-size:10px;"><?php 
            echo number_format_i18n($this->quota['regular'], 0);
            ?>
</span><span style="font-size:10px;"> / <?php 
            echo number_format_i18n($this->quota['monthly'], 0);
            if ($this->quota['extra'] > 0) {
                echo ' <span style="color:#999;">';
                printf(__('(+%s extra)', 'nelioab'), number_format_i18n($this->quota['extra'], 0));
                echo '</span>';
            }
            ?>
</span>
					</div>
					<div class="right" style="font-size:32px; text-align:right; float:right; width:38%; padding-right:5%; margin-top:8px; opacity:0.7;">
						<span><?php 
            // Let's compute the size of the extra quota (if any)
            if ($this->quota['extra'] > 0) {
                $extra = $this->quota['extra'];
                $max_extra = $this->quota['monthly'] / 2;
                if ($extra > $max_extra) {
                    $extra = $max_extra;
                }
                $extra_perc = $extra / $max_extra * 20;
            } else {
                $extra_perc = 0;
            }
            $extra_perc = number_format($extra_perc, 0);
            // Now let's compute the size of the regular bar
            if ($this->quota['regular'] > 0) {
                $perc = $this->quota['regular'] / $this->quota['monthly'] * 100;
            } else {
                $perc = 0;
            }
            $num_of_decs = 1;
            if (100 == $perc) {
                $num_of_decs = 0;
            }
            echo number_format($perc, $num_of_decs);
            ?>
%</span>
					</div>
				</div>

				<div class="progress-bar-container" style="background:none;border:2px solid rgba(0,0,0,0.1); width:95%; margin:0px; height:20px;"><?php 
            $bar = '<div class="progress-bar" style="margin:0;padding:0;display:inline-block;height:20px;background-color:%s;width:%s%%;"></div>';
            $perc = number_format($perc, 0);
            if ($perc + $extra_perc > 100) {
                $perc = 100 - $extra_perc;
            }
            printf($bar, $cs['primary'], $perc);
            printf($bar, $cs['secondary'], $extra_perc);
            ?>
</div>
			<?php 
            $this->print_rss();
            echo '</div>';
            // #post-body
        }