/**
     * Displays quick stats metabox
     */
    public static function display_quick_stats_metabox()
    {
        global $post;
        $variations = Landing_Pages_Variations::get_variations($post->ID);
        $variations = array_filter($variations, 'is_numeric');
        ?>
        <div>
            <style type="text/css">

            </style>
            <div class="inside" id="a-b-testing">
                <div id="bab-stat-box">
                    <?php 
        if (isset($_GET['new_meta_key']) && is_numeric($_GET['new_meta_key'])) {
            ?>
                        <script type="text/javascript">
                            jQuery(document).ready(function($) {
                                /* This fixes meta data saves for cloned pages */
                                function isNumber (o) {
                                    return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
                                }
                                var new_meta_key = "<?php 
            echo $_GET['new_meta_key'];
            ?>
";
                                jQuery('#template-display-options input[type=text], #template-display-options select, #template-display-options input[type=radio], #template-display-options textarea').each(function(){
                                    var this_id = jQuery(this).attr("id");
                                    var final_number = this_id.match(/[^-]+$/g);
                                    var new_id = this_id.replace(/[^-]+$/g, new_meta_key);
                                    var is_number = isNumber(final_number);

                                    if (is_number === false) {
                                        jQuery(this).attr("id", this_id + "-" + new_meta_key);
                                        jQuery(this).attr("name", this_id + "-" + new_meta_key);
                                    } else {
                                        jQuery(this).attr("id", new_id);
                                        jQuery(this).attr("name", new_id);
                                    }
                                });
                            });
                        </script>
                    <?php 
        }
        $howmany = count($variations);
        foreach ($variations as $key => $vid) {
            $variation_status = Landing_Pages_Variations::get_variation_status($post->ID, $vid);
            $variation_status_class = $variation_status == 1 ? "variation-on" : 'variation-off';
            $permalink = Landing_Pages_Variations::get_variation_permalink($post->ID, $vid);
            $impressions = Landing_Pages_Variations::get_impressions($post->ID, $vid);
            $conversions = Landing_Pages_Variations::get_conversions($post->ID, $vid);
            $conversion_rate = Landing_Pages_Variations::get_conversion_rate($post->ID, $vid);
            $title = Landing_Pages_Variations::get_main_headline($post->ID, $vid);
            ?>

                        <div id="lp-variation-<?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
"
                             class="bab-variation-row <?php 
            echo $variation_status_class;
            ?>
">
                            <div class='bab-varation-header'>
								<span class='bab-variation-name'><?php 
            _e('Variation', 'landing-pages');
            ?>
 <span
                                        class='bab-stat-letter'><?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
</span>
                                    <?php 
            if ($variation_status != 1) {
                ?>
                                        <span class='is-paused'>(<?php 
                _e('Paused', 'landing-pages');
                ?>
)</span>
                                    <?php 
            }
            ?>
								</span>


                                <span class="lp-delete-var-stats" data-letter='<?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
'
                                      data-vid='<?php 
            echo $vid;
            ?>
' rel='<?php 
            echo $post->ID;
            ?>
'
                                      title="<?php 
            _e('Delete this variations stats', 'landing-pages');
            ?>
"><?php 
            _e('Clear Stats', 'landing-pages');
            ?>
</span>
                            </div>
                            <div class="bab-stat-row">
                                <div class='bab-stat-stats' colspan='2'>
                                    <div class='bab-stat-container-impressions bab-number-box'>
                                        <span class='bab-stat-span-impressions'><?php 
            echo $impressions;
            ?>
</span>
                                        <span class="bab-stat-id"><?php 
            _e('Views', 'landing-pages');
            ?>
 </span>
                                    </div>
                                    <div class='bab-stat-container-conversions bab-number-box'>
                                        <span class='bab-stat-span-conversions'><?php 
            echo $conversions;
            ?>
</span>
                                        <span
                                            class="bab-stat-id"><?php 
            _e('Conversions', 'landing-pages');
            ?>
</span></span>
                                    </div>
                                    <div class='bab-stat-container-conversion_rate bab-number-box'>
                                        <span
                                            class='bab-stat-span-conversion_rate'><?php 
            echo $conversion_rate;
            ?>
</span>
                                        <span
                                            class="bab-stat-id bab-rate"><?php 
            _e('Conversion Rate', 'landing-pages');
            ?>
</span>
                                    </div>
                                    <div class='bab-stat-control-container'>
                                        <span class='bab-stat-control-pause'><a
                                                title="<?php 
            _e('Pause this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=pause-variation'><?php 
            _e('Pause', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator pause-sep'>|</span>
                                        <span class='bab-stat-control-play'><a
                                                title="<?php 
            _e('Turn this variation on', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=play-variation'><?php 
            _e('Play', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator play-sep'>|</span>
                                        <span class='bab-stat-menu-edit'><a
                                                title="<?php 
            _e('Edit this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
'><?php 
            _e('Edit', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-menu-preview'><a
                                                title="<?php 
            _e('Preview this variation', 'landing-pages');
            ?>
"
                                                class='thickbox'
                                                href='<?php 
            echo $permalink;
            ?>
&iframe_window=on&post_id=<?php 
            echo $post->ID;
            ?>
&TB_iframe=true&width=1503&height=467'
                                                target='_blank'><?php 
            _e('Preview', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-menu-clone'><a
                                                title="<?php 
            _e('Clone this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&new-variation=1&clone=<?php 
            echo $vid;
            ?>
&new_meta_key=<?php 
            echo $howmany;
            ?>
'><?php 
            _e('Clone', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-control-delete'><a
                                                title="<?php 
            _e('Delete this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=delete-variation'><?php 
            _e('Delete', 'landing-pages');
            ?>
</a></span>
                                    </div>
                                </div>
                            </div>
                            <div class="bab-stat-row">

                                <div class='bab-stat-menu-container'>

                                    <?php 
            do_action('lp_ab_testing_stats_menu_post');
            ?>

                                </div>
                            </div>
                        </div>
                    <?php 
        }
        ?>
                </div>

            </div>
        </div>
    <?php 
    }
 /**
  * Show stats container on Landing Page lists page
  */
 public static function show_stats()
 {
     global $post;
     $permalink = get_permalink($post->ID);
     $variations = Landing_Pages_Variations::get_variations($post->ID);
     echo "<span class='show-stats button'> " . __('Show Variation Stats', 'landing-pages') . "</span>";
     echo "<ul class='lp-varation-stat-ul'>";
     $cr_array = array();
     $i = 0;
     $impressions = 0;
     $conversions = 0;
     foreach ($variations as $key => $vid) {
         $letter = Landing_Pages_Variations::vid_to_letter($post->ID, $key);
         /* convert to letter */
         $each_impression = get_post_meta($post->ID, 'lp-ab-variation-impressions-' . $vid, true);
         /* get impressions */
         /* get variation status */
         $v_status = Landing_Pages_Variations::get_variation_status($post->ID, $vid);
         /* Current status */
         /* Get variation notes */
         $each_notes = Landing_Pages_Variations::get_variation_notes($post->ID, $vid);
         $each_conversion = get_post_meta($post->ID, 'lp-ab-variation-conversions-' . $vid, true);
         $each_conversion === "" ? $final_conversion = 0 : ($final_conversion = $each_conversion);
         $impressions += get_post_meta($post->ID, 'lp-ab-variation-impressions-' . $vid, true);
         $conversions += get_post_meta($post->ID, 'lp-ab-variation-conversions-' . $vid, true);
         if ($each_impression != 0) {
             $conversion_rate = $final_conversion / $each_impression;
         } else {
             $conversion_rate = 0;
         }
         $conversion_rate = round($conversion_rate, 2) * 100;
         $cr_array[] = $conversion_rate;
         if ($v_status === "0") {
             $final_status = __("(Paused)", 'landing-pages');
         } else {
             $final_status = "";
         }
         /*if ($cr_array[$i] > $largest) {
           $largest = $cr_array[$i];
            }
           (($largest === $conversion_rate)) ? $winner_class = 'lp-current-winner' : $winner_class = ""; */
         $final_conversion === "1" ? $c_text = __('conversion', 'landing-pages') : ($c_text = __("conversions", 'landing-pages'));
         $each_impression === "1" ? $i_text = __('visit', 'landing-pages') : ($i_text = __("visits", 'landing-pages'));
         $each_notes === "" ? $each_notes = __('No notes', 'landing-pages') : ($each_notes = $each_notes);
         $data_letter = "data-letter=\"" . $letter . "\"";
         $edit_link = admin_url('post.php?post=' . $post->ID . '&lp-variation-id=' . $vid . '&action=edit');
         $popup = "data-notes=\"<span class='lp-pop-description'>" . $each_notes . "</span><span class='lp-pop-controls'><span class='lp-pop-edit button-primary'><a href='" . $edit_link . "'>Edit This variation</a></span><span class='lp-pop-preview button'><a title='Click to Preview this variation' class='thickbox' href='" . $permalink . "?lp-variation-id=" . $vid . "&iframe_window=on&post_id=" . $post->ID . "&TB_iframe=true&width=640&height=703' target='_blank'>Preview This variation</a></span><span class='lp-bottom-controls'><span class='lp-delete-var-stats' data-letter='" . $letter . "' data-vid='" . $vid . "' rel='" . $post->ID . "'>Clear These Stats</span></span></span>\"";
         echo "<li rel='" . $final_status . "' data-postid='" . $post->ID . "' data-letter='" . $letter . "' data-lp='' class='lp-stat-row-" . $vid . " " . $post->ID . '-' . $conversion_rate . " status-" . $v_status . "'><a " . $popup . " " . $data_letter . " class='lp-letter' title='click to edit this variation' href='" . $edit_link . "'>" . $letter . "</a><span class='lp-numbers'> <span class='lp-impress-num'>" . $each_impression . "</span><span class='visit-text'>" . $i_text . " with</span><span class='lp-con-num'>" . $final_conversion . "</span> " . $c_text . "</span><a " . $popup . " " . $data_letter . " class='cr-number cr-empty-" . $conversion_rate . "' href='" . $edit_link . "'>" . $conversion_rate . "%</a></li>";
         $i++;
     }
     echo "</ul>";
     $winning_cr = max($cr_array);
     /* best conversion rate */
     if ($winning_cr != 0) {
         echo "<span class='variation-winner-is'>" . $post->ID . "-" . $winning_cr . "</span>";
     }
     /*echo "Total Visits: " . $impressions; */
     /*echo "Total Conversions: " . $conversions; */
 }