/** * 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 if ((!check_auth() || $CURRENT_USER['level'] < 7) && $BILLEVEL != 2) { die("Access denied!"); } require_once dirname(__FILE__) . "/SMPHPToolkit/SMAjax.php"; require_once dirname(__FILE__) . "/CADBiS/PacketsTodayLimits.php"; CADBiSNew::instance()->script_src('js/ajax/buffer.js'); $ajaxbuf = new ajax_buffer("update_buffer"); $ajaxbuf->show_progress(true); $ajaxbuf->set_postback_url($_SERVER['REQUEST_URI']); $BILL = new CBilling($GV["dbhost"], $GV["dbname"], $GV["dblogin"], $GV["dbpassword"]); require_once dirname(__FILE__) . "/CADBiS/cadbis_statistic_backend.php"; $packets = $BILL->GetTarifs(); $config = $BILL->GetCADBiSConfig(); $packets_confs = array(); foreach ($packets as &$packet) { $accts = $BILL->GetTarifTodayAccts($packet['gid']); $packet['accts']['traffic'] = $accts['traffic']; $packet['accts']['time'] = $accts['time']; $packets_confs[$packet['gid']]['rang'] = new ajax_var('rng' . $packet['gid'], $packet['rang']); $packets_confs[$packet['gid']]['exceed_times'] = new ajax_var('et' . $packet['gid'], $packet['exceed_times']); $ajaxbuf->register_vars($packets_confs[$packet['gid']]); } $max_month_traffic = new ajax_var('max_month_traffic', $config['max_month_traffic'] / 1024 / 1024); $ajaxbuf->register_var($max_month_traffic); if ($ajaxbuf->is_post_back()) { foreach ($packets as &$packet) { $packet['rang'] = $packets_confs[$packet['gid']]['rang']->get_value(); $packet['exceed_times'] = $packets_confs[$packet['gid']]['exceed_times']->get_value(); $BILL->UpdateTarif($packet['gid'], $packet);