Exemplo n.º 1
0
function gen_detaildom_page(&$tpl, $user_id, $domain_id)
{
    global $sql;
    // Get domain data
    $query = <<<SQL_QUERY
      select
          *,
          IFNULL(domain_disk_usage, 0) as domain_disk_usage
      from
          domain
      where
          domain_id = ?;
SQL_QUERY;
    $res = exec_query($sql, $query, array($domain_id));
    $data = $res->FetchRow();
    if ($res->RecordCount() <= 0) {
        header('Location: manage_users.php');
        die;
    }
    // Get admin data
    $query = "select admin_name from admin where admin_id = ?";
    $res1 = exec_query($sql, $query, array($data['domain_admin_id']));
    $data1 = $res1->FetchRow();
    if ($res1->RecordCount() <= 0) {
        header('Location: manage_users.php');
        die;
    }
    // Get IP-info
    $query = "select * from server_ips where ip_id = ?";
    $ipres = exec_query($sql, $query, array($data['domain_ip_id']));
    $ipdat = $ipres->FetchRow();
    // Get staus name
    $dstatus = $data['domain_status'];
    global $cfg;
    if ($dstatus == $cfg['ITEM_OK_STATUS'] || $dstatus == $cfg['ITEM_DISABLED_STATUS'] || $dstatus == $cfg['ITEM_DELETE_STATUS'] || $dstatus == $cfg['ITEM_ADD_STATUS'] || $dstatus == $cfg['ITEM_RESTORE_STATUS'] || $dstatus == $cfg['ITEM_CHANGE_STATUS'] || $dstatus == $cfg['ITEM_TOENABLE_STATUS'] || $dstatus == $cfg['ITEM_TODISABLED_STATUS']) {
        $dstatus = translate_dmn_status($data['domain_status']);
    } else {
        $dstatus = "<b><font size=3 color=red>" . $data['domain_status'] . "</font></b>";
    }
    if ($data['domain_php'] == 'yes') {
        $php_stat = 'Enabled';
    } else {
        $php_stat = 'disabled';
    }
    if ($data['domain_cgi'] == 'yes') {
        $cgi_stat = 'Enabled';
    } else {
        $cgi_stat = 'disabled';
    }
    if ($data['domain_sqld_limit'] >= 0) {
        $sql_stat = 'Enabled';
    } else {
        $sql_stat = 'disabled';
    }
    // Traffic diagram
    $fdofmnth = mktime(0, 0, 0, date("m"), 1, date("Y"));
    $ldofmnth = mktime(1, 0, 0, date("m") + 1, 0, date("Y"));
    $query = <<<SQL_QUERY
        select
            IFNULL(sum(dtraff_web),0) as dtraff_web,
            IFNULL(sum(dtraff_ftp), 0) as dtraff_ftp,
            IFNULL(sum(dtraff_mail), 0) as dtraff_mail,
            IFNULL(sum(dtraff_pop),0) as dtraff_pop
        from
            domain_traffic
        where
            domain_id = ?
          and
            dtraff_time > ?
          and
            dtraff_time < ?
SQL_QUERY;
    $res7 = exec_query($sql, $query, array($data['domain_id'], $fdofmnth, $ldofmnth));
    $dtraff = $res7->FetchRow();
    $sumtraff = $dtraff['dtraff_web'] + $dtraff['dtraff_ftp'] + $dtraff['dtraff_mail'] + $dtraff['dtraff_pop'];
    $dtraffmb = sprintf("%.1f", $sumtraff / 1024 / 1024);
    $month = date("m");
    $year = date("Y");
    $query = "select * from server_ips where ip_id=?";
    $res8 = exec_query($sql, $query, array($data['domain_ip_id']));
    $ipdat = $res8->FetchRow();
    $domain_traffic_limit = $data['domain_traffic_limit'];
    $domain_all_traffic = $sumtraff;
    //$dtraff['traffic'];
    $traff = $domain_all_traffic / 1024 / 1024;
    $mtraff = sprintf("%.2f", $traff);
    if ($domain_traffic_limit == 0) {
        $pr = 0;
    } else {
        $pr = $traff / $domain_traffic_limit * 100;
        $pr = sprintf("%.2f", $pr);
    }
    $indx = (int) $pr;
    list($traffic_percent, $indx, $a) = make_usage_vals($domain_all_traffic, $domain_traffic_limit * 1024 * 1024);
    // Get disk status
    $domdu = $data['domain_disk_usage'];
    $domdl = $data['domain_disk_limit'];
    $tmp = $domdu / 1024 / 1024;
    if ($domdu == 0) {
        $dpr = 0;
    } else {
        if ($domdl == 0) {
            $dpr = 0;
        } else {
            $dpr = $tmp / $domdl * 100;
            $dpr = sprintf("%.2f", $dpr);
        }
    }
    $dindx = (int) $dpr;
    $domduh = make_hr($domdu);
    list($disk_percent, $dindx, $b) = make_usage_vals($domdu, $domdl * 1024 * 1024);
    // Get current mail count
    $query = "select count(mail_id) as mcnt from mail_users where domain_id = ?";
    $res6 = exec_query($sql, $query, array($data['domain_id']));
    $dat3 = $res6->FetchRow();
    if ($data['domain_mailacc_limit'] == 0) {
        $mail_limit = tr('unlimited');
    } else {
        if ($data['domain_mailacc_limit'] == -1) {
            $mail_limit = tr('None');
        } else {
            $mail_limit = $data['domain_mailacc_limit'];
        }
    }
    // FTP stat
    $query = "select gid from ftp_group where groupname = ?";
    $res4 = exec_query($sql, $query, array($data['domain_name']));
    $ftp_gnum = $res4->RowCount();
    if ($ftp_gnum == 0) {
        $used_ftp_acc = 0;
    } else {
        $dat1 = $res4->FetchRow();
        $query = "select count(uid) as ftp_cnt from ftp_users where gid=?";
        $res5 = exec_query($sql, $query, array($dat1['gid']));
        $dat2 = $res5->FetchRow();
        $used_ftp_acc = $dat2['ftp_cnt'];
    }
    if ($data['domain_ftpacc_limit'] == 0) {
        $ftp_limit = tr('unlimited');
    } else {
        $ftp_limit = $data['domain_ftpacc_limit'];
    }
    // Get sql database count
    $query = "select count(sqld_id) as dnum from sql_database where domain_id=?";
    $res = exec_query($sql, $query, array($data['domain_id']));
    $dat5 = $res->FetchRow();
    if ($data['domain_sqld_limit'] == 0) {
        $sql_db = tr('unlimited');
    } else {
        if ($data['domain_sqld_limit'] == -1) {
            $sql_db = tr('None');
        } else {
            $sql_db = $data['domain_sqld_limit'];
        }
    }
    // Get sql users count
    $query = "select count(u.sqlu_id) as ucnt from sql_user u,sql_database d where u.sqld_id=d.sqld_id and d.domain_id=?";
    $res = exec_query($sql, $query, array($data['domain_id']));
    $dat6 = $res->FetchRow();
    if ($data['domain_sqlu_limit'] == 0) {
        $sql_users = tr('unlimited');
    } else {
        if ($data['domain_sqlu_limit'] == -1) {
            $sql_users = tr('None');
        } else {
            $sql_users = $data['domain_sqlu_limit'];
        }
    }
    // Get sub domain
    $query = "select count(subdomain_id) as sub_num from subdomain where domain_id=?";
    $res1 = exec_query($sql, $query, array($data['domain_id']));
    $sub_num_data = $res1->FetchRow();
    if ($data['domain_subd_limit'] == 0) {
        $sub_dom = tr('unlimited');
    } else {
        if ($data['domain_subd_limit'] == -1) {
            $sub_dom = tr('None');
        } else {
            $sub_dom = $data['domain_subd_limit'];
        }
    }
    //Get domain aliases
    $query = "select count(alias_id) as alias_num from domain_aliasses where domain_id=?";
    $res1 = exec_query($sql, $query, array($data['domain_id']));
    $alias_num_data = $res1->FetchRow();
    if ($data['domain_alias_limit'] == 0) {
        $dom_alias = tr('unlimited');
    } else {
        if ($data['domain_alias_limit'] == -1) {
            $dom_alias = tr('None');
        } else {
            $dom_alias = $data['domain_alias_limit'];
        }
    }
    // Fill in the fileds
    $tpl->assign(array('VL_DOMAIN_NAME' => $data['domain_name'], 'VL_DOMAIN_IP' => $ipdat['ip_number'] . ' (' . $ipdat['ip_alias'] . ')', 'VL_STATUS' => $dstatus, 'VL_PHP_SUPP' => tr($php_stat), 'VL_CGI_SUPP' => tr($cgi_stat), 'VL_MYSQL_SUPP' => tr($sql_stat), 'VL_TRAFFIC_PERCENT' => $traffic_percent, 'VL_TRAFFIC_USED' => make_hr($domain_all_traffic), 'VL_TRAFFIC_LIMIT' => make_hr($domain_traffic_limit * 1024 * 1024), 'VL_DISK_PERCENT' => $disk_percent, 'VL_DISK_USED' => $domduh, 'VL_DISK_LIMIT' => make_hr($data['domain_disk_limit'] * 1024 * 1024), 'VL_MAIL_ACCOUNTS_USED' => $dat3['mcnt'], 'VL_MAIL_ACCOUNTS_LIIT' => $mail_limit, 'VL_FTP_ACCOUNTS_USED' => $used_ftp_acc, 'VL_FTP_ACCOUNTS_LIIT' => $ftp_limit, 'VL_SQL_DB_ACCOUNTS_USED' => $dat5['dnum'], 'VL_SQL_DB_ACCOUNTS_LIIT' => $sql_db, 'VL_SQL_USER_ACCOUNTS_USED' => $dat6['ucnt'], 'VL_SQL_USER_ACCOUNTS_LIIT' => $sql_users, 'VL_SUBDOM_ACCOUNTS_USED' => $sub_num_data['sub_num'], 'VL_SUBDOM_ACCOUNTS_LIIT' => $sub_dom, 'VL_DOMALIAS_ACCOUNTS_USED' => $alias_num_data['alias_num'], 'VL_DOMALIAS_ACCOUNTS_LIIT' => $dom_alias));
}
function gen_mount_point(&$tpl)
{
    $mount_points = filesystems();
    while (list($number, $row) = each($mount_points)) {
        if (($number + 1) % 2 == 0) {
            $tpl->assign(array('ITEM_CLASS' => 'content'));
        } else {
            $tpl->assign(array('ITEM_CLASS' => 'content2'));
        }
        $tpl->assign(array('MOUNT' => $row['mount'], 'TYPE' => $row['fstype'], 'PARTITION' => $row['disk'], 'PERCENT' => $row['percent'], 'FREE' => make_hr($row['free'] * 1014), 'USED' => make_hr($row['used'] * 1024), 'SIZE' => make_hr($row['size'] * 1024)));
        $tpl->parse('DISK_LIST_ITEM', '.disk_list_item');
    }
    $tpl->parse('DISK_LIST', 'disk_list');
}
function generate_domain_entry(&$tpl, $user_id, $row)
{
    global $crnt_month, $crnt_year;
    list($domain_name, $domain_id, $web, $ftp, $smtp, $pop3, $utraff_current, $udisk_current, $i, $j) = generate_user_traffic($user_id);
    list($usub_current, $usub_max, $uals_current, $uals_max, $umail_current, $umail_max, $uftp_current, $uftp_max, $usql_db_current, $usql_db_max, $usql_user_current, $usql_user_max, $utraff_max, $udisk_max) = generate_user_props($user_id);
    $utraff_max = $utraff_max * 1024 * 1024;
    $udisk_max = $udisk_max * 1024 * 1024;
    list($traff_percent, $traff_red, $traff_green) = make_usage_vals($utraff_current, $utraff_max);
    list($disk_percent, $disk_red, $disk_green) = make_usage_vals($udisk_current, $udisk_max);
    $traff_show_percent = $traff_percent;
    $disk_show_percent = $disk_percent;
    if ($traff_percent > 100) {
        $traff_percent = 100;
    }
    if ($disk_percent > 100) {
        $disk_percent = 100;
    }
    if ($row % 2 == 0) {
        $tpl->assign(array('ITEM_CLASS' => 'content'));
    } else {
        $tpl->assign(array('ITEM_CLASS' => 'content2'));
    }
    $domain_name = decode_idna($domain_name);
    $tpl->assign(array('DOMAIN_NAME' => $domain_name, 'MONTH' => $crnt_month, 'YEAR' => $crnt_year, 'DOMAIN_ID' => $domain_id, 'TRAFF_SHOW_PERCENT' => $traff_show_percent, 'TRAFF_PERCENT' => $traff_percent, 'TRAFF_RED' => $traff_red, 'TRAFF_GREEN' => $traff_green, 'TRAFF_USED' => make_hr($utraff_current), 'TRAFF_MAX' => $utraff_max ? make_hr($utraff_max) : tr('unlimited'), 'DISK_SHOW_PERCENT' => $disk_show_percent, 'DISK_PERCENT' => $disk_percent, 'DISK_RED' => $disk_red, 'DISK_GREEN' => $disk_green, 'DISK_USED' => make_hr($udisk_current), 'DISK_MAX' => $udisk_max ? make_hr($udisk_max) : tr('unlimited'), 'WEB' => make_hr($web), 'FTP' => make_hr($ftp), 'SMTP' => make_hr($smtp), 'POP3' => make_hr($pop3), 'SUB_USED' => $usub_current, 'SUB_MAX' => $usub_max ? $usub_max > 0 ? $usub_max : tr('disabled') : tr('unlimited'), 'ALS_USED' => $uals_current, 'ALS_MAX' => $uals_max ? $uals_max > 0 ? $uals_max : tr('disabled') : tr('unlimited'), 'MAIL_USED' => $umail_current, 'MAIL_MAX' => $umail_max ? $umail_max : tr('unlimited'), 'FTP_USED' => $uftp_current, 'FTP_MAX' => $uftp_max ? $uftp_max : tr('unlimited'), 'SQL_DB_USED' => $usql_db_current, 'SQL_DB_MAX' => $usql_db_max ? $usql_db_max > 0 ? $usql_db_max : tr('disabled') : tr('unlimited'), 'SQL_USER_USED' => $usql_user_current, 'SQL_USER_MAX' => $usql_user_max ? $usql_user_max > 0 ? $usql_user_max : tr('disabled') : tr('unlimited')));
}
Exemplo n.º 4
0
function generate_page_data(&$tpl, $reseller_id, $reseller_name)
{
    global $sql, $crnt_month, $crnt_year;
    $crnt_month = date("m");
    $crnt_year = date("Y");
    //global
    $tmpArr = get_reseller_default_props($sql, $reseller_id);
    //$tmpArr = generate_reseller_props($reseller_id);
    if (NULL !== $tmpArr) {
        // there are data in db
        list($rdmn_current, $rdmn_max, $rsub_current, $rsub_max, $rals_current, $rals_max, $rmail_current, $rmail_max, $rftp_current, $rftp_max, $rsql_db_current, $rsql_db_max, $rsql_user_current, $rsql_user_max, $rtraff_current, $rtraff_max, $rdisk_current, $rdisk_max) = $tmpArr;
    } else {
        list($rdmn_current, $rdmn_max, $rsub_current, $rsub_max, $rals_current, $rals_max, $rmail_current, $rmail_max, $rftp_current, $rftp_max, $rsql_db_current, $rsql_db_max, $rsql_user_current, $rsql_user_max, $rtraff_current, $rtraff_max, $rdisk_current, $rdisk_max) = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }
    list($udmn_current, $udmn_max, $udmn_uf, $usub_current, $usub_max, $usub_uf, $uals_current, $uals_max, $uals_uf, $umail_current, $umail_max, $umail_uf, $uftp_current, $uftp_max, $uftp_uf, $usql_db_current, $usql_db_max, $usql_db_uf, $usql_user_current, $usql_user_max, $usql_user_uf, $utraff_current, $utraff_max, $utraff_uf, $udisk_current, $udisk_max, $udisk_uf) = generate_reseller_user_props($reseller_id);
    // Convert into MB values
    $rtraff_max = $rtraff_max * 1024 * 1024;
    $rtraff_current = $rtraff_current * 1024 * 1024;
    $rdisk_max = $rdisk_max * 1024 * 1024;
    $rdisk_current = $rdisk_current * 1024 * 1024;
    $utraff_max = $utraff_max * 1024 * 1024;
    $udisk_max = $udisk_max * 1024 * 1024;
    list($traff_percent, $traff_red, $traff_green) = make_usage_vals($utraff_current, $rtraff_max);
    list($disk_percent, $disk_red, $disk_green) = make_usage_vals($udisk_current, $rdisk_max);
    gen_traff_usage($tpl, $utraff_current, $rtraff_max, 400);
    gen_disk_usage($tpl, $udisk_current, $rdisk_max, 400);
    if ($rtraff_max > 0) {
        if ($utraff_current > $rtraff_max) {
            $tpl->assign('TR_TRAFFIC_WARNING', tr('You are exceeding your traffic limit!'));
        } else {
            $tpl->assign('TRAFF_WARN', '');
        }
    } else {
        if ($utraff_current > 1024 * 1024 * 1024 * 1024) {
            $tpl->assign('TR_TRAFFIC_WARNING', tr('You are exceeding your UNLIMITED traffic limit!'));
        } else {
            $tpl->assign('TRAFF_WARN', '');
        }
    }
    //warning HDD Usage
    if ($rdisk_max > 0) {
        if ($udisk_current > $rdisk_max) {
            $tpl->assign('TR_DISK_WARNING', tr('You are exceeding your disk limit!'));
        } else {
            $tpl->assign('DISK_WARN', '');
        }
    } else {
        if ($udisk_current > 1024 * 1024 * 1024 * 1024) {
            $tpl->assign('TR_DISK_WARNING', tr('You are exceeding your UNLIMITED disk limit!'));
        } else {
            $tpl->assign('DISK_WARN', '');
        }
    }
    $tpl->assign(array('ACCOUNT_NAME' => tr("Account name"), 'GENERAL_INFO' => tr("General information"), "DOMAINS" => tr("User accounts"), "SUBDOMAINS" => tr("Subdomains"), "ALIASES" => tr("Aliases"), "MAIL_ACCOUNTS" => tr("Mail account"), "TR_FTP_ACCOUNTS" => tr("FTP account"), "SQL_DATABASES" => tr("SQL databases"), "SQL_USERS" => tr("SQL users"), "TRAFFIC" => tr("Traffic"), "DISK" => tr("Disk"), "TR_EXTRAS" => tr("Extras")));
    $tpl->assign(array('RESELLER_NAME' => $reseller_name, 'TRAFF_RED' => $traff_red * 3, 'TRAFF_GREEN' => $traff_green * 3, 'TRAFF_PERCENT' => $traff_percent, 'TRAFF_USED' => make_hr($utraff_current), 'TRAFF_CURRENT' => make_hr($rtraff_current), 'TRAFF_MAX' => $rtraff_max ? make_hr($rtraff_max) : tr('unlimited'), 'DISK_USED' => make_hr($udisk_current), 'DISK_CURRENT' => make_hr($rdisk_current), 'DISK_MAX' => $rdisk_max ? make_hr($rdisk_max) : tr('unlimited'), 'DMN_USED' => $udmn_current, 'DMN_CURRENT' => $rdmn_current, 'DMN_MAX' => $rdmn_max ? $rdmn_max : tr('unlimited'), 'SUB_USED' => $usub_current, 'SUB_CURRENT' => $rsub_current, 'SUB_MAX' => $rsub_max ? $rsub_max : tr('unlimited'), 'ALS_USED' => $uals_current, 'ALS_CURRENT' => $rals_current, 'ALS_MAX' => $rals_max ? $rals_max : tr('unlimited'), 'MAIL_USED' => $umail_current, 'MAIL_CURRENT' => $rmail_current, 'MAIL_MAX' => $rmail_max ? $rmail_max : tr('unlimited'), 'FTP_USED' => $uftp_current, 'FTP_CURRENT' => $rftp_current, 'FTP_MAX' => $rftp_max ? $rftp_max : tr('unlimited'), 'SQL_DB_USED' => $usql_db_current, 'SQL_DB_CURRENT' => $rsql_db_current, 'SQL_DB_MAX' => $rsql_db_max ? $rsql_db_max : tr('unlimited'), 'SQL_USER_USED' => $usql_user_current, 'SQL_USER_CURRENT' => $rsql_user_current, 'SQL_USER_MAX' => $rsql_user_max ? $rsql_user_max : tr('unlimited'), 'EXTRAS' => ''));
}
function generate_reseller_entry(&$tpl, $reseller_id, $reseller_name, $row)
{
    global $crnt_month, $crnt_year;
    list($rdmn_current, $rdmn_max, $rsub_current, $rsub_max, $rals_current, $rals_max, $rmail_current, $rmail_max, $rftp_current, $rftp_max, $rsql_db_current, $rsql_db_max, $rsql_user_current, $rsql_user_max, $rtraff_current, $rtraff_max, $rdisk_current, $rdisk_max) = generate_reseller_props($reseller_id);
    list($udmn_current, $udmn_max, $udmn_uf, $usub_current, $usub_max, $usub_uf, $uals_current, $uals_max, $uals_uf, $umail_current, $umail_max, $umail_uf, $uftp_current, $uftp_max, $uftp_uf, $usql_db_current, $usql_db_max, $usql_db_uf, $usql_user_current, $usql_user_max, $usql_user_uf, $utraff_current, $utraff_max, $utraff_uf, $udisk_current, $udisk_max, $udisk_uf) = generate_reseller_users_props($reseller_id);
    $rtraff_max = $rtraff_max * 1024 * 1024;
    $rtraff_current = $rtraff_current * 1024 * 1024;
    $rdisk_max = $rdisk_max * 1024 * 1024;
    $rdisk_current = $rdisk_current * 1024 * 1024;
    $utraff_max = $utraff_max * 1024 * 1024;
    $udisk_max = $udisk_max * 1024 * 1024;
    $traff_percent = calc_bar_value($utraff_current, $rtraff_max, 400);
    list($traff_percent, $traff_red, $traff_green) = make_usage_vals($utraff_current, $rtraff_max);
    list($disk_percent, $disk_red, $disk_green) = make_usage_vals($udisk_current, $rdisk_max);
    $traff_show_percent = $traff_percent;
    $disk_show_percent = $disk_percent;
    if ($traff_percent > 100) {
        $traff_percent = 100;
    }
    if ($disk_percent > 100) {
        $disk_percent = 100;
    }
    if ($row % 2 == 0) {
        $tpl->assign(array('ITEM_CLASS' => 'content'));
    } else {
        $tpl->assign(array('ITEM_CLASS' => 'content2'));
    }
    $tpl->assign(array('RESELLER_NAME' => $reseller_name, 'RESELLER_ID' => $reseller_id, 'MONTH' => $crnt_month, 'YEAR' => $crnt_year, 'TRAFF_SHOW_PERCENT' => $traff_show_percent, 'TRAFF_PERCENT' => $traff_percent, 'TRAFF_USED' => make_hr($utraff_current), 'TRAFF_CURRENT' => make_hr($rtraff_current), 'TRAFF_MAX' => $rtraff_max ? make_hr($rtraff_max) : tr('unlimited'), 'DISK_SHOW_PERCENT' => $disk_show_percent, 'DISK_PERCENT' => $disk_percent, 'DISK_USED' => make_hr($udisk_current), 'DISK_CURRENT' => make_hr($rdisk_current), 'DISK_MAX' => $rdisk_max ? make_hr($rdisk_max) : tr('unlimited'), 'DMN_USED' => $udmn_current, 'DMN_CURRENT' => $rdmn_current, 'DMN_MAX' => $rdmn_max ? $rdmn_max : tr('unlimited'), 'SUB_USED' => $usub_current, 'SUB_CURRENT' => $rsub_current, 'SUB_MAX' => $rsub_max ? $rsub_max : tr('unlimited'), 'ALS_USED' => $uals_current, 'ALS_CURRENT' => $rals_current, 'ALS_MAX' => $rals_max ? $rals_max : tr('unlimited'), 'MAIL_USED' => $umail_current, 'MAIL_CURRENT' => $rmail_current, 'MAIL_MAX' => $rmail_max ? $rmail_max : tr('unlimited'), 'FTP_USED' => $uftp_current, 'FTP_CURRENT' => $rftp_current, 'FTP_MAX' => $rftp_max ? $rftp_max : tr('unlimited'), 'SQL_DB_USED' => $usql_db_current, 'SQL_DB_CURRENT' => $rsql_db_current, 'SQL_DB_MAX' => $rsql_db_max ? $rsql_db_max : tr('unlimited'), 'TR_OF' => tr('of'), 'SQL_USER_USED' => $usql_user_current, 'SQL_USER_CURRENT' => $rsql_user_current, 'SQL_USER_MAX' => $rsql_user_max ? $rsql_user_max : tr('unlimited')));
    $tpl->parse('RESELLER_ENTRY', '.reseller_entry');
}
function generate_page(&$tpl)
{
    global $sql, $month, $year;
    if ($month == date('m') && $year == date('Y')) {
        $curday = date('j');
    } else {
        $tmp = mktime(1, 0, 0, $month + 1, 0, $year);
        $curday = date('j', $tmp);
    }
    $curtimestamp = time();
    $firsttimestamp = mktime(0, 0, 0, $month, 1, $year);
    $all[0] = 0;
    $all[1] = 0;
    $all[2] = 0;
    $all[3] = 0;
    $all[4] = 0;
    $all[5] = 0;
    $all[6] = 0;
    $all[7] = 0;
    for ($i = 1; $i <= $curday; $i++) {
        $ftm = mktime(0, 0, 0, $month, $i, $year);
        $ltm = mktime(23, 59, 59, $month, $i, $year);
        $query = <<<SQL_QUERY
          select
              count(bytes_in) as cnt
          from
              server_traffic
          where
              traff_time > ? and traff_time < ?
SQL_QUERY;
        $rs = exec_query($sql, $query, array($ftm, $ltm));
        $has_data = false;
        // if ($rs -> fields['cnt'] > 0) {
        if ($rs->RecordCount() > 0) {
            list($web_in, $web_out, $mail_in, $mail_out, $pop_in, $pop_out, $other_in, $other_out, $all_in, $all_out) = get_server_trafic($ftm, $ltm);
            $has_data = true;
            if ($i % 2 == 0) {
                $tpl->assign('ITEM_CLASS', 'content');
            } else {
                $tpl->assign('ITEM_CLASS', 'content2');
            }
            $tpl->assign(array('DAY' => $i, 'YEAR' => $year, 'MONTH' => $month, 'WEB_IN' => make_hr($web_in), 'WEB_OUT' => make_hr($web_out), 'MAIL_IN' => make_hr($mail_in), 'MAIL_OUT' => make_hr($mail_out), 'POP_IN' => make_hr($pop_in), 'POP_OUT' => make_hr($pop_out), 'OTHER_IN' => make_hr($other_in), 'OTHER_OUT' => make_hr($other_out), 'ALL_IN' => make_hr($all_in), 'ALL_OUT' => make_hr($all_out), 'ALL' => make_hr($all_in + $all_out)));
            $all[0] = $all[0] + $web_in;
            $all[1] = $all[1] + $web_out;
            $all[2] = $all[2] + $mail_in;
            $all[3] = $all[3] + $mail_out;
            $all[4] = $all[4] + $pop_in;
            $all[5] = $all[5] + $pop_out;
            $all[6] = $all[6] + $all_in;
            $all[7] = $all[7] + $all_out;
            $tpl->parse('DAY_LIST', '.day_list');
        }
        // if count
    }
    //for
    if (!$has_data) {
        $tpl->assign('DAY_LIST', '');
    }
    $all_other_in = $all[6] - ($all[0] + $all[2] + $all[4]);
    $all_other_out = $all[7] - ($all[1] + $all[3] + $all[5]);
    $tpl->assign(array('WEB_IN_ALL' => make_hr($all[0]), 'WEB_OUT_ALL' => make_hr($all[1]), 'MAIL_IN_ALL' => make_hr($all[2]), 'MAIL_OUT_ALL' => make_hr($all[3]), 'POP_IN_ALL' => make_hr($all[4]), 'POP_OUT_ALL' => make_hr($all[5]), 'OTHER_IN_ALL' => make_hr($all_other_in), 'OTHER_OUT_ALL' => make_hr($all_other_out), 'ALL_IN_ALL' => make_hr($all[6]), 'ALL_OUT_ALL' => make_hr($all[7]), 'ALL_ALL' => make_hr($all[6] + $all[7])));
}
function generate_page(&$tpl)
{
    global $sql, $month, $year, $day;
    $all[0] = 0;
    $all[1] = 0;
    $all[2] = 0;
    $all[3] = 0;
    $all[4] = 0;
    $all[5] = 0;
    $all[6] = 0;
    $all[7] = 0;
    $all_other_in = 0;
    $all_other_out = 0;
    $row = 1;
    $ftm = mktime(0, 0, 0, $month, $day, $year);
    $ltm = mktime(23, 59, 59, $month, $day, $year);
    $query = <<<SQL_QUERY
        select
            count(bytes_in) as cnt
        from
            server_traffic
        where
            traff_time > ? and traff_time < ?
SQL_QUERY;
    $rs = exec_query($sql, $query, array($ftm, $ltm));
    $dnum = $rs->fields['cnt'];
    $query = <<<SQL_QUERY
        select
            traff_time as ttime,
            bytes_in as sbin,
            bytes_out as sbout,
            bytes_mail_in as smbin,
            bytes_mail_out as smbout,
            bytes_pop_in as spbin,
            bytes_pop_out as spbout,
            bytes_web_in as swbin,
            bytes_web_out as swbout
        from
            server_traffic
        where
            traff_time > ? and traff_time < ?

SQL_QUERY;
    $rs1 = exec_query($sql, $query, array($ftm, $ltm));
    $row = 1;
    if ($dnum != 0) {
        for ($i = 0; $i < $dnum; $i++) {
            /* make it in kb mb or bytes :) */
            $ttime = date('H:i', $rs1->fields['ttime']);
            /* make other traffic */
            $other_in = $rs1->fields['sbin'] - ($rs1->fields['swbin'] + $rs1->fields['smbin'] + $rs1->fields['spbin']);
            $other_out = $rs1->fields['sbout'] - ($rs1->fields['swbout'] + $rs1->fields['smbout'] + $rs1->fields['spbout']);
            if ($row++ % 2 == 0) {
                $tpl->assign(array('ITEM_CLASS' => 'content'));
            } else {
                $tpl->assign(array('ITEM_CLASS' => 'content2'));
            }
            $tpl->assign(array('HOUR' => $ttime, 'WEB_IN' => make_hr($rs1->fields['swbin']), 'WEB_OUT' => make_hr($rs1->fields['swbout']), 'MAIL_IN' => make_hr($rs1->fields['smbin']), 'MAIL_OUT' => make_hr($rs1->fields['smbout']), 'POP_IN' => make_hr($rs1->fields['spbin']), 'POP_OUT' => make_hr($rs1->fields['spbout']), 'OTHER_IN' => make_hr($other_in), 'OTHER_OUT' => make_hr($other_out), 'ALL_IN' => make_hr($rs1->fields['sbin']), 'ALL_OUT' => make_hr($rs1->fields['sbout']), 'ALL' => make_hr($rs1->fields['sbin'] + $rs1->fields['sbout'])));
            $all[0] = $all[0] + $rs1->fields['swbin'];
            $all[1] = $all[1] + $rs1->fields['swbout'];
            $all[2] = $all[2] + $rs1->fields['smbin'];
            $all[3] = $all[3] + $rs1->fields['smbout'];
            $all[4] = $all[4] + $rs1->fields['spbin'];
            $all[5] = $all[5] + $rs1->fields['spbout'];
            $all[6] = $all[6] + $rs1->fields['sbin'];
            $all[7] = $all[7] + $rs1->fields['sbout'];
            $tpl->parse('HOUR_LIST', '.hour_list');
            $rs1->MoveNext();
        }
        //for
        $all_other_in = $all[6] - ($all[0] + $all[2] + $all[4]);
        $all_other_out = $all[7] - ($all[1] + $all[3] + $all[5]);
    } else {
        $tpl->assign('HOUR_LIST', '');
    }
    $tpl->assign(array('WEB_IN_ALL' => make_hr($all[0]), 'WEB_OUT_ALL' => make_hr($all[1]), 'MAIL_IN_ALL' => make_hr($all[2]), 'MAIL_OUT_ALL' => make_hr($all[3]), 'POP_IN_ALL' => make_hr($all[4]), 'POP_OUT_ALL' => make_hr($all[5]), 'OTHER_IN_ALL' => make_hr($all_other_in), 'OTHER_OUT_ALL' => make_hr($all_other_out), 'ALL_IN_ALL' => make_hr($all[6]), 'ALL_OUT_ALL' => make_hr($all[7]), 'ALL_ALL' => make_hr($all[6] + $all[7])));
}