Пример #1
0
    private static function stats_page()
    {
        ?>
        <style>
          .paypal_graph_container{clear:both; padding-left:5px; min-width:789px; margin-right:50px;}
        .paypal_message_container{clear: both; padding-left:5px; text-align:center; padding-top:120px; border: 1px solid #CCC; background-color: #FFF; width:100%; height:160px;}
        .paypal_summary_container {margin:30px 60px; text-align: center; min-width:740px; margin-left:50px;}
        .paypal_summary_item {width:160px; background-color: #FFF; border: 1px solid #CCC; padding:14px 8px; margin:6px 3px 6px 0; display: -moz-inline-stack; display: inline-block; zoom: 1; *display: inline; text-align:center;}
        .paypal_summary_value {font-size:20px; margin:5px 0; font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif}
        .paypal_summary_title {}
        #paypal_graph_tooltip {border:4px solid #b9b9b9; padding:11px 0 0 0; background-color: #f4f4f4; text-align:center; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; -khtml-border-radius: 4px;}
        #paypal_graph_tooltip .tooltip_tip {width:14px; height:14px; background-image:url(<?php 
        echo self::get_base_url();
        ?>
/images/tooltip_tip.png); background-repeat: no-repeat; position: absolute; bottom:-14px; left:68px;}

        .paypal_tooltip_date {line-height:130%; font-weight:bold; font-size:13px; color:#21759B;}
        .paypal_tooltip_sales {line-height:130%;}
        .paypal_tooltip_revenue {line-height:130%;}
            .paypal_tooltip_revenue .paypal_tooltip_heading {}
            .paypal_tooltip_revenue .paypal_tooltip_value {}
            .paypal_trial_disclaimer {clear:both; padding-top:20px; font-size:10px;}
        </style>
        <script type="text/javascript" src="<?php 
        echo self::get_base_url();
        ?>
/flot/jquery.flot.min.js"></script>
        <script type="text/javascript" src="<?php 
        echo self::get_base_url();
        ?>
/js/currency.js"></script>

        <div class="wrap">
            <img alt="<?php 
        _e("PayPal", "gravityformspaypal");
        ?>
" style="margin: 15px 7px 0pt 0pt; float: left;" src="<?php 
        echo self::get_base_url();
        ?>
/images/paypal_wordpress_icon_32.png"/>
            <h2><?php 
        _e("PayPal Stats", "gravityformspaypal");
        ?>
</h2>

            <form method="post" action="">
                <ul class="subsubsub">
                    <li><a class="<?php 
        echo !RGForms::get("tab") || RGForms::get("tab") == "daily" ? "current" : "";
        ?>
" href="?page=gf_paypal&view=stats&id=<?php 
        echo $_GET["id"];
        ?>
"><?php 
        _e("Daily", "gravityforms");
        ?>
</a> | </li>
                    <li><a class="<?php 
        echo RGForms::get("tab") == "weekly" ? "current" : "";
        ?>
" href="?page=gf_paypal&view=stats&id=<?php 
        echo $_GET["id"];
        ?>
&tab=weekly"><?php 
        _e("Weekly", "gravityforms");
        ?>
</a> | </li>
                    <li><a class="<?php 
        echo RGForms::get("tab") == "monthly" ? "current" : "";
        ?>
" href="?page=gf_paypal&view=stats&id=<?php 
        echo $_GET["id"];
        ?>
&tab=monthly"><?php 
        _e("Monthly", "gravityforms");
        ?>
</a></li>
                </ul>
                <?php 
        $config = GFPayPalData::get_feed(RGForms::get("id"));
        switch (RGForms::get("tab")) {
            case "monthly":
                $chart_info = self::monthly_chart_info($config);
                break;
            case "weekly":
                $chart_info = self::weekly_chart_info($config);
                break;
            default:
                $chart_info = self::daily_chart_info($config);
                break;
        }
        if (!$chart_info["series"]) {
            ?>
                    <div class="paypal_message_container"><?php 
            _e("No payments have been made yet.", "gravityformspaypal");
            ?>
 <?php 
            echo $config["meta"]["trial_period_enabled"] && empty($config["meta"]["trial_amount"]) ? " **" : "";
            ?>
</div>
                    <?php 
        } else {
            ?>
                    <div class="paypal_graph_container">
                        <div id="graph_placeholder" style="width:100%;height:300px;"></div>
                    </div>

                    <script type="text/javascript">
                        var paypal_graph_tooltips = <?php 
            echo $chart_info["tooltips"];
            ?>
;

                        jQuery.plot(jQuery("#graph_placeholder"), <?php 
            echo $chart_info["series"];
            ?>
, <?php 
            echo $chart_info["options"];
            ?>
);
                        jQuery(window).resize(function(){
                            jQuery.plot(jQuery("#graph_placeholder"), <?php 
            echo $chart_info["series"];
            ?>
, <?php 
            echo $chart_info["options"];
            ?>
);
                        });

                        var previousPoint = null;
                        jQuery("#graph_placeholder").bind("plothover", function (event, pos, item) {
                            startShowTooltip(item);
                        });

                        jQuery("#graph_placeholder").bind("plotclick", function (event, pos, item) {
                            startShowTooltip(item);
                        });

                        function startShowTooltip(item){
                            if (item) {
                                if (!previousPoint || previousPoint[0] != item.datapoint[0]) {
                                    previousPoint = item.datapoint;

                                    jQuery("#paypal_graph_tooltip").remove();
                                    var x = item.datapoint[0].toFixed(2),
                                        y = item.datapoint[1].toFixed(2);

                                    showTooltip(item.pageX, item.pageY, paypal_graph_tooltips[item.dataIndex]);
                                }
                            }
                            else {
                                jQuery("#paypal_graph_tooltip").remove();
                                previousPoint = null;
                            }
                        }

                        function showTooltip(x, y, contents) {
                            jQuery('<div id="paypal_graph_tooltip">' + contents + '<div class="tooltip_tip"></div></div>').css( {
                                position: 'absolute',
                                display: 'none',
                                opacity: 0.90,
                                width:'150px',
                                height:'<?php 
            echo $config["meta"]["type"] == "subscription" ? "75px" : "60px";
            ?>
',
                                top: y - <?php 
            echo $config["meta"]["type"] == "subscription" ? "100" : "89";
            ?>
,
                                left: x - 79
                            }).appendTo("body").fadeIn(200);
                        }


                        function convertToMoney(number){
                            var currency = getCurrentCurrency();
                            return currency.toMoney(number);
                        }
                        function formatWeeks(number){
                            number = number + "";
                            return "<?php 
            _e("Week ", "gravityformspaypal");
            ?>
" + number.substring(number.length-2);
                        }

                        function getCurrentCurrency(){
                            <?php 
            if (!class_exists("RGCurrency")) {
                require_once ABSPATH . "/" . PLUGINDIR . "/gravityforms/currency.php";
            }
            $current_currency = RGCurrency::get_currency(GFCommon::get_currency());
            ?>
                            var currency = new Currency(<?php 
            echo GFCommon::json_encode($current_currency);
            ?>
);
                            return currency;
                        }
                    </script>
                <?php 
        }
        $payment_totals = RGFormsModel::get_form_payment_totals($config["form_id"]);
        $transaction_totals = GFPayPalData::get_transaction_totals($config["form_id"]);
        switch ($config["meta"]["type"]) {
            case "product":
                $total_sales = $payment_totals["orders"];
                $sales_label = __("Total Orders", "gravityformspaypal");
                break;
            case "donation":
                $total_sales = $payment_totals["orders"];
                $sales_label = __("Total Donations", "gravityformspaypal");
                break;
            case "subscription":
                $total_sales = $payment_totals["active"];
                $sales_label = __("Active Subscriptions", "gravityformspaypal");
                break;
        }
        $total_revenue = empty($transaction_totals["payment"]["revenue"]) ? 0 : $transaction_totals["payment"]["revenue"];
        ?>
                <div class="paypal_summary_container">
                    <div class="paypal_summary_item">
                        <div class="paypal_summary_title"><?php 
        _e("Total Revenue", "gravityformspaypal");
        ?>
</div>
                        <div class="paypal_summary_value"><?php 
        echo GFCommon::to_money($total_revenue);
        ?>
</div>
                    </div>
                    <div class="paypal_summary_item">
                        <div class="paypal_summary_title"><?php 
        echo $chart_info["revenue_label"];
        ?>
</div>
                        <div class="paypal_summary_value"><?php 
        echo $chart_info["revenue"];
        ?>
</div>
                    </div>
                    <div class="paypal_summary_item">
                        <div class="paypal_summary_title"><?php 
        echo $sales_label;
        ?>
</div>
                        <div class="paypal_summary_value"><?php 
        echo $total_sales;
        ?>
</div>
                    </div>
                    <div class="paypal_summary_item">
                        <div class="paypal_summary_title"><?php 
        echo $chart_info["sales_label"];
        ?>
</div>
                        <div class="paypal_summary_value"><?php 
        echo $chart_info["sales"];
        ?>
</div>
                    </div>
                </div>
                <?php 
        if (!$chart_info["series"] && $config["meta"]["trial_period_enabled"] && empty($config["meta"]["trial_amount"])) {
            ?>
                    <div class="paypal_trial_disclaimer"><?php 
            _e("** Free trial transactions will only be reflected in the graph after the first payment is made (i.e. after trial period ends)", "gravityformspaypal");
            ?>
</div>
                    <?php 
        }
        ?>
            </form>
        </div>
        <?php 
    }