From 260ebe2476597e9d6572bb8897aa96ac1b723e3d Mon Sep 17 00:00:00 2001
From: Lucas Bickel <hairmare@rabe.ch>
Date: Sun, 12 Mar 2017 15:13:45 +0100
Subject: [PATCH] Fix listenerstat page

Deactivates the bandwidth limit stuff if none is configured.
---
 airtime_mvc/application/models/Preference.php         | 11 +----------
 .../views/scripts/listenerstat/index.phtml            |  6 ++++--
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php
index 7041d7df8..17f6d69be 100644
--- a/airtime_mvc/application/models/Preference.php
+++ b/airtime_mvc/application/models/Preference.php
@@ -1576,17 +1576,8 @@ class Application_Model_Preference
     /**
      * Accessors for station bandwidth limit.
      */
-
     public static function getBandwidthLimit() {
-        $val = self::getValue("bandwidth_limit");
-        if (empty($val)) {
-            // Set and return the plan defaults
-            // TODO: remove this once all existing customers have this pref set
-            $planType = self::GetPlanLevel();
-            $val = Billing::$PLAN_TYPE_DEFAULTS[$planType]["bandwidth_limit"];
-            self::setBandwidthLimit($val);
-        }
-        return $val;
+        return self::getValue("bandwidth_limit");
     }
 
     public static function setBandwidthLimit($value) {
diff --git a/airtime_mvc/application/views/scripts/listenerstat/index.phtml b/airtime_mvc/application/views/scripts/listenerstat/index.phtml
index f8d358794..b1f67d6ea 100644
--- a/airtime_mvc/application/views/scripts/listenerstat/index.phtml
+++ b/airtime_mvc/application/views/scripts/listenerstat/index.phtml
@@ -15,8 +15,9 @@
         </fieldset>
     </div>
     <div style="clear: both;"></div>
-    <?php $bandwidthUsage = Application_Model_Preference::getBandwidthLimitCounter(); ?>
     <?php $bandwidthLimit = Application_Model_Preference::getBandwidthLimit(); ?>
+    <?php if ($bandwidthLimit): ?>
+    <?php $bandwidthUsage = Application_Model_Preference::getBandwidthLimitCounter(); ?>
     <?php $percentInUse = sprintf("%01.1f%% ", $bandwidthUsage/$bandwidthLimit*100); ?>
     <div id="bandwidth_usage">
         <div style="padding-bottom: 2px;"><?php echo _("Monthly Listener Bandwidth Usage") ?></div>
@@ -26,4 +27,5 @@
 
         <div style="margin-top: 17px; font-size: 12px;"><?php echo sprintf("%01.1fGB of %01.1fGB", $bandwidthUsage/pow(2, 30), $bandwidthLimit/pow(2, 30)); ?></div>
     </div>
-</div>
\ No newline at end of file
+    <?php endif; ?>
+</div>