/** * recalculates packets limits * * @param array $packets */ protected function recalcTrafficLimits() { $config = $this->BILL->GetCADBiSConfig(); $maximumMonthTraffic = $config['max_month_traffic']; $monthAccts = $this->BILL->GetMonthTotalAccts(); $this->usedMonthTraffic = $monthAccts['traffic'] ? $monthAccts['traffic'] : 0; $this->restDaysCount = date("t") - date("j") + 1; $this->restMonthTraffic = $maximumMonthTraffic - $this->usedMonthTraffic; $this->allowedDayTraffic = $this->restMonthTraffic / $this->restDaysCount; $SumOfRangs = 0; for ($i = 0; $i < count($this->packets); ++$i) { $SumOfRangs += $this->packets[$i]['rang'] * $this->packets[$i]['simuluse_sum']; } for ($i = 0; $i < count($this->packets); ++$i) { $this->packetsCoefs[$this->packets[$i]['gid']] = (double) $this->packets[$i]['rang'] * (double) $this->packets[$i]['simuluse_sum'] / (double) $SumOfRangs; } $this->onePointCost = round($this->allowedDayTraffic / (double) $SumOfRangs); for ($i = 0; $i < count($this->packets); ++$i) { $dayLimit = round($this->allowedDayTraffic * $this->packetsCoefs[$this->packets[$i]['gid']]); $restPacketMonthTraffic = $dayLimit * $this->restDaysCount; $this->monthTrafficLimits[$this->packets[$i]['gid']] = $restPacketMonthTraffic; if (($this->packets[$i]['exceed_times'] + 1) * $dayLimit <= $restPacketMonthTraffic) { $dayLimit *= $this->packets[$i]['exceed_times'] + 1; } else { $dayLimit = $restPacketMonthTraffic; } $this->dayTrafficLimits[$this->packets[$i]['gid']] = $dayLimit; } }
<?php error_reporting(E_PARSE); include "restore_confs.php"; $BILL = new CBilling($GV["dbhost"], $GV["dbname"], $GV["dblogin"], $GV["dbpassword"]); $cur = $BILL->GetMonthTotalAccts(); $mon = $BILL->GetMonthMaxAccts(); $imgnum = 20.0; $prc_tr = (double) $cur["traffic"] / (double) $mon["traffic"] * 100.0; $perimg = 100.0 / $imgnum; $year = date("Y"); $month = date("m"); $day = date("d"); $daycount = date("t"); $maxtraf = 0; $daynorm = $mon["traffic"] / $daycount; $rest = $mon["traffic"] - $cur["traffic"]; $dnrm = $rest / ($daycount - $day + 1); $k = $dnrm < 0 ? -90000 : 100; $prc_tr2 = (double) $daynorm / (double) $dnrm * 100.0 - $k; if ($prc_tr2 > 100) { $prc_tr2 = 100; } if ($prc_tr2 < 0) { $prc_tr2 = 0; } $imgnum = (int) ((double) $prc_tr2 / $perimg); $imgnum += 1; if ($imgnum > 20) { $imgnum = 20; }