Beispiel #1
0
function catv_UserStatsDrawPayments($userid, $year)
{
    $catvconf = catv_LoadConfig();
    $alluserpayments = catv_PaymentsGetAllByUser($userid);
    $yearactivity = catv_ActivityGetAllByUserAndYear($userid, $year);
    $targetyearpayments = array();
    $userdata = catv_UserGetData($userid);
    $usertariff = $userdata['tariff'];
    $tariffdata = catv_TariffGetData($usertariff);
    $tariffprice = $tariffdata['price'];
    $montharray = months_array();
    $montharray_wz = months_array_wz();
    $actlog = array();
    $payments_table = wf_tag('h2') . __('Previous payments') . wf_tag('h2', true);
    $payments_table .= catv_UserShowAllpayments($userid);
    if (!empty($alluserpayments)) {
        //select only payments for needed year
        foreach ($alluserpayments as $ia => $eachpayment) {
            if ($eachpayment['from_year'] == $year) {
                $targetyearpayments[] = $eachpayment;
            }
        }
        //coloring year online and filling activity report
        $onlinecolorizer = '';
        $onlinewriter = '';
        if (!empty($yearactivity)) {
            foreach ($yearactivity as $ic => $eachactivity) {
                $datemonth = date("m", strtotime($eachactivity['date']));
                if ($eachactivity['state'] == 0) {
                    $onlinecolorizer .= catv_CalendarSetOffline($datemonth);
                    $onlinewriter .= catv_CalendarWriteActivity($datemonth, __('Disconnected'));
                    $actlog[$datemonth] = 'disconnected';
                }
                if ($eachactivity['state'] == 1) {
                    $onlinecolorizer .= catv_CalendarSetOnline($datemonth);
                    $onlinewriter .= catv_CalendarWriteActivity($datemonth, __('Connected'));
                }
            }
        }
        //print target payments to calendar
        if (!empty($targetyearpayments)) {
            $printpays = '';
            $colorizer = '';
            foreach ($targetyearpayments as $io => $eachpayment) {
                //calculate calendar offset for payments
                if ($eachpayment['from_month'] < 10) {
                    $offset = '0';
                } else {
                    $offset = '';
                }
                //insert payment to needed month
                $printpays .= catv_CalendarWrite($offset . $eachpayment['from_month'], $eachpayment['date'] . '<br><br>' . $eachpayment['summ'] . ' ' . $catvconf['CURRENCY']);
                //set payment month as good
                $colorizer .= catv_CalendarSetGood($offset . $eachpayment['from_month']);
                //maybe user payed for few months?
                if ($eachpayment['summ'] > $tariffprice) {
                    $additional_month = intval($eachpayment['summ'] / $tariffprice);
                    for ($coloroffset = 1; $coloroffset < $additional_month; $coloroffset++) {
                        //mb user was disabled?
                        if (isset($actlog[$offset . ($eachpayment['from_month'] + $coloroffset)])) {
                            $coloroffset = $coloroffset + 1;
                        }
                        $colorizer .= catv_CalendarSetGoodLong($offset . ($eachpayment['from_month'] + $coloroffset));
                    }
                }
            }
            //draw payments and colors to calendar
            show_window('', $printpays . $colorizer . $onlinewriter . $onlinecolorizer . $payments_table);
        }
    }
}
Beispiel #2
0
/**
 * Generates user's traffic statistic module content
 * 
 * @param   str     $login  User's login, for whitch generate module content
 * @return  str             Module content
 */
function web_UserTraffStats($login)
{
    $login = vf($login);
    $dirs = zb_DirectionsGetAll();
    // Current month traffic stats:
    $cells = wf_TableCell(__('Traffic classes'));
    $cells .= wf_TableCell(__('Downloaded'));
    $cells .= wf_TableCell(__('Uploaded'));
    $cells .= wf_TableCell(__('Total'));
    $rows = wf_TableRow($cells, 'row1');
    if (!empty($dirs)) {
        foreach ($dirs as $dir) {
            $query_downup = "SELECT `D" . $dir['rulenumber'] . "`,`U" . $dir['rulenumber'] . "` FROM `users` WHERE `login` = '" . $login . "'";
            $downup = simple_query($query_downup);
            $cells = wf_TableCell($dir['rulename']);
            $cells .= wf_TableCell(stg_convert_size($downup['D' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . $downup['D' . $dir['rulenumber']] . '"');
            $cells .= wf_TableCell(stg_convert_size($downup['U' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . $downup['U' . $dir['rulenumber']] . '"');
            $cells .= wf_TableCell(stg_convert_size($downup['U' . $dir['rulenumber']] + $downup['D' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . ($downup['U' . $dir['rulenumber']] + $downup['D' . $dir['rulenumber']]) . '"');
            $rows .= wf_TableRow($cells, 'row3');
        }
    }
    $result = wf_tag('h3') . __('Current month traffic stats') . wf_tag('h3', true);
    $result .= wf_TableBody($rows, '100%', '0', 'sortable');
    // End of current month traffic stats
    // Per-user graphs buttons:
    $ip = zb_UserGetIP($login);
    $bandwidthd = zb_BandwidthdGetUrl($ip);
    if (!empty($bandwidthd)) {
        $bwd = zb_BandwidthdGenLinks($ip);
        // Dayly graph button:
        $daybw = wf_img($bwd['dayr'], __('Downloaded'));
        if (!empty($bwd['days'])) {
            $daybw .= wf_delimiter() . wf_img($bwd['days'], __('Uploaded'));
        }
        // Weekly graph button:
        $weekbw = wf_img($bwd['weekr'], __('Downloaded'));
        if (!empty($bwd['weeks'])) {
            $weekbw .= wf_delimiter() . wf_img($bwd['weeks'], __('Uploaded'));
        }
        // Monthly graph button:
        $monthbw = wf_img($bwd['monthr'], __('Downloaded'));
        if (!empty($bwd['months'])) {
            $monthbw .= wf_delimiter() . wf_img($bwd['months'], __('Uploaded'));
        }
        // Yearly graph button:
        $yearbw = wf_img($bwd['yearr'], __('Downloaded'));
        if (!empty($bwd['years'])) {
            $yearbw .= wf_delimiter() . wf_img($bwd['years'], __('Uploaded'));
        }
        // Modal window sizes:
        if (!empty($bwd['days'])) {
            //bandwidthd
            $width = 920;
            $heidht = 640;
            $graphLegend = wf_tag('br') . wf_img('skins/bwdlegend.gif');
        } else {
            //mikrotik
            $width = 530;
            $heidht = 230;
            $graphLegend = '';
        }
        $result .= wf_delimiter();
        $result .= wf_tag('h3') . __('Graphs') . wf_tag('h3', true);
        $bwcells = wf_TableCell(wf_modal(__('Graph by day'), __('Graph by day'), $daybw . $graphLegend, 'ubButton', $width, $heidht));
        $bwcells .= wf_TableCell(wf_modal(__('Graph by week'), __('Graph by week'), $weekbw . $graphLegend, 'ubButton', $width, $heidht));
        $bwcells .= wf_TableCell(wf_modal(__('Graph by month'), __('Graph by month'), $monthbw . $graphLegend, 'ubButton', $width, $heidht));
        $bwcells .= wf_TableCell(wf_modal(__('Graph by year'), __('Graph by year'), $yearbw . $graphLegend, 'ubButton', $width, $heidht));
        $bwrows = wf_TableRow($bwcells);
        // Adding graphs buttons to result:
        $result .= wf_TableBody($bwrows, '', '0', '');
        $result .= wf_delimiter();
    } else {
        $result .= __('No user graphs because no NAS with bandwidthd for his network');
    }
    // End of per-user graphs buttons
    // Traffic statistic by previous months:
    $monthNames = months_array_wz();
    $result .= wf_tag('h3') . __('Previous month traffic stats') . wf_tag('h3', true);
    $cells = wf_TableCell(__('Year'));
    $cells .= wf_TableCell(__('Month'));
    $cells .= wf_TableCell(__('Traffic classes'));
    $cells .= wf_TableCell(__('Downloaded'));
    $cells .= wf_TableCell(__('Uploaded'));
    $cells .= wf_TableCell(__('Total'));
    $cells .= wf_TableCell(__('Cash'));
    $rows = wf_TableRow($cells, 'row1');
    if (!empty($dirs)) {
        foreach ($dirs as $dir) {
            $query_prev = "SELECT `D" . $dir['rulenumber'] . "`, `U" . $dir['rulenumber'] . "`, `month`, `year`, `cash` FROM `stat` WHERE `login` = '" . $login . "' ORDER BY `year`, `month`";
            $prevmonths = simple_queryall($query_prev);
            if (!empty($prevmonths)) {
                foreach ($prevmonths as $prevmonth) {
                    $cells = wf_TableCell($prevmonth['year']);
                    $cells .= wf_TableCell(rcms_date_localise($monthNames[$prevmonth['month']]));
                    $cells .= wf_TableCell($dir['rulename']);
                    $cells .= wf_TableCell(stg_convert_size($prevmonth['D' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . $prevmonth['D' . $dir['rulenumber']] . '"');
                    $cells .= wf_TableCell(stg_convert_size($prevmonth['U' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . $prevmonth['U' . $dir['rulenumber']] . '"');
                    $cells .= wf_TableCell(stg_convert_size($prevmonth['U' . $dir['rulenumber']] + $prevmonth['D' . $dir['rulenumber']]), '', '', 'sorttable_customkey="' . ($prevmonth['U' . $dir['rulenumber']] + $prevmonth['D' . $dir['rulenumber']]) . '"');
                    $cells .= wf_TableCell(round($prevmonth['cash'], 2));
                    $rows .= wf_TableRow($cells, 'row3');
                }
            }
        }
    }
    // End of traffic statistic by previous months
    // Generate table:
    $result .= wf_TableBody($rows, '100%', '0', 'sortable');
    // Return result:
    return $result;
}