function gen_server_trafic(&$tpl, &$sql) { $query = <<<SQL_QUERY select straff_max,straff_warn from straff_settings SQL_QUERY; $rs = exec_query($sql, $query, array()); $straff_max = $rs->fields['straff_max'] * 1024 * 1024; $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(bytes_in) + sum(bytes_out)), 0) as traffic from server_traffic where traff_time > ? and traff_time < ? SQL_QUERY; $rs1 = exec_query($sql, $query, array($fdofmnth, $ldofmnth)); $traff = $rs1->fields['traffic']; $mtraff = sprintf("%.2f", $traff); if ($straff_max == 0) { $pr = 0; } else { $pr = $traff / $straff_max * 100; } $pr = sprintf("%.2f", $pr); if (($straff_max != 0 || $straff_max != '') && $mtraff > $straff_max) { $tpl->assign('TR_TRAFFIC_WARNING', tr('You are exceeding your traffic limit!')); } else { $tpl->assign('TRAFF_WARN', ''); } $bar_value = calc_bar_value($traff, $straff_max, 400); if ($straff_max == 0) { $show_straf_max = tr('unlimited'); } else { $show_straf_max = sizeit($straff_max); } $tpl->assign(array('TR_OF' => tr('of'), 'PERCENT' => $pr, 'VALUE' => sizeit($mtraff), 'MAX_VALUE' => $show_straf_max, 'BAR_VALUE' => $bar_value)); }
/** * @param EasySCP_TemplateEngine $tpl * @param int $user_id * @param int $row */ 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) = 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; $traff_show_percent = calc_bar_value($utraff_current, $utraff_max, 400); $disk_show_percent = calc_bar_value($udisk_current, $udisk_max, 400); if ($utraff_max > 0) { $traff_percent = $utraff_current / $utraff_max * 100 < 99.7 ? $utraff_current / $utraff_max * 100 : 99.7; } else { $traff_percent = 0; } if ($udisk_max > 0) { $disk_percent = $udisk_current / $udisk_max * 100 < 99.7 ? $udisk_current / $udisk_max * 100 : 99.7; } else { $disk_percent = 0; } $domain_name = decode_idna($domain_name); $tpl->append(array('DOMAIN_NAME' => tohtml($domain_name), 'MONTH' => $crnt_month, 'YEAR' => $crnt_year, 'DOMAIN_ID' => $domain_id, 'TRAFF_SHOW_PERCENT' => $traff_show_percent, 'TRAFF_PERCENT' => $traff_percent, 'TRAFF_MSG' => $utraff_max ? tr('%1$s <br/>of<br/> <strong>%2$s</strong>', sizeit($utraff_current), sizeit($utraff_max)) : tr('%s <br/>of<br/> <strong>unlimited</strong>', sizeit($utraff_current)), 'DISK_SHOW_PERCENT' => $disk_show_percent, 'DISK_PERCENT' => $disk_percent, 'DISK_MSG' => $udisk_max ? tr('%1$s <br/>of<br/> <strong>%2$s</strong>', sizeit($udisk_current), sizeit($udisk_max)) : tr('%s <br/>of<br/> <strong>unlimited</strong>', sizeit($udisk_current)), 'WEB' => sizeit($web), 'FTP' => sizeit($ftp), 'SMTP' => sizeit($smtp), 'POP3' => sizeit($pop3), 'SUB_MSG' => $usub_max ? $usub_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', sizeit($usub_current), $usub_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', sizeit($usub_current)), 'ALS_MSG' => $uals_max ? $uals_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', sizeit($uals_current), $uals_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', sizeit($uals_current)), 'MAIL_MSG' => $umail_max ? $umail_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', $umail_current, $umail_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', $umail_current), 'FTP_MSG' => $uftp_max ? $uftp_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', $uftp_current, $uftp_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', $uftp_current), 'SQL_DB_MSG' => $usql_db_max ? $usql_db_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', $usql_db_current, $usql_db_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', $usql_db_current), 'SQL_USER_MSG' => $usql_user_max ? $usql_user_max > 0 ? tr('%1$d <br/>of<br/> <strong>%2$d</strong>', $usql_user_current, $usql_user_max) : tr('<strong>disabled</strong>') : tr('%d <br/>of<br/> <strong>unlimited</strong>', $usql_user_current))); }
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'); }
/** * @param EasySCP_TemplateEngine $tpl * @return void */ function gen_server_trafic($tpl) { $sql_query = "\n\t\tSELECT\n\t\t\tstraff_max, straff_warn\n\t\tFROM\n\t\t\tstraff_settings;\n\t"; $row = DB::query($sql_query, true); $straff_max = $row['straff_max'] * 1024 * 1024; $straff_warn = $row['straff_warn'] * 1024 * 1024; $sql_param = array(':fdofmnth' => mktime(0, 0, 0, date("m"), 1, date("Y")), ':ldofmnth' => mktime(1, 0, 0, date("m") + 1, 0, date("Y"))); $query = "\n\t\tSELECT\n\t\t\tIFNULL((SUM(bytes_in) + SUM(bytes_out)), 0) AS traffic\n\t\tFROM\n\t\t\tserver_traffic\n\t\tWHERE\n\t\t\ttraff_time > :fdofmnth\n\t\tAND\n\t\t\ttraff_time < :ldofmnth;\n\t"; DB::prepare($sql_query); $row = DB::execute($sql_param, true); $traff = isset($row['traffic']) ? $row['traffic'] : 0; $mtraff = sprintf("%.2f", $traff); if ($straff_max == 0) { $pr = 0; } else { $pr = $traff / $straff_max * 100; } if (($straff_max != 0 || $straff_max != '') && $mtraff > $straff_max) { $tpl->assign(array('TR_TRAFFIC_WARNING' => tr('You are exceeding your traffic limit!'))); } else { if (($straff_warn != 0 || $straff_warn != '') && $mtraff > $straff_warn) { $tpl->assign(array('TR_TRAFFIC_WARNING' => tr('You traffic limit will be reached soon!'))); } else { $tpl->assign('TRAFF_WARN', ''); } } $bar_value = calc_bar_value($traff, $straff_max, 400); $percent = 0; if ($straff_max == 0) { $traff_msg = tr('%1$d%% [%2$s of unlimited]', $pr, sizeit($mtraff)); } else { $traff_msg = tr('%1$d%% [%2$s of %3$s]', $pr, sizeit($mtraff), sizeit($straff_max)); $percent = $traff / $straff_max * 100 < 99.7 ? $traff / $straff_max * 100 : 99.7; } $tpl->assign(array('TRAFFIC_WARNING' => $traff_msg, 'BAR_VALUE' => $bar_value, 'TRAFFIC_PERCENT' => $percent)); }
/** * @param EasySCP_TemplateEngine $tpl * @param int $reseller_id * @param string $reseller_name * @param int $row * @return void */ 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, , , $usub_current, , , $uals_current, , , $umail_current, , , $uftp_current, , , $usql_db_current, , , $usql_user_current, , , $utraff_current, , , $udisk_current, , ) = 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; $traff_show_percent = calc_bar_value($utraff_current, $rtraff_max, 400); $disk_show_percent = calc_bar_value($udisk_current, $rdisk_max, 400); if ($rtraff_max > 0) { $traff_percent = $utraff_current / $rtraff_max * 100 < 99.7 ? $utraff_current / $rtraff_max * 100 : 99.7; } else { $traff_percent = 0; } if ($rdisk_max > 0) { $disk_percent = $udisk_current / $rdisk_max * 100 < 99.7 ? $udisk_current / $rdisk_max * 100 : 99.7; } else { $disk_percent = 0; } $tpl->append(array('RESELLER_NAME' => tohtml($reseller_name), 'RESELLER_ID' => $reseller_id, 'MONTH' => $crnt_month, 'YEAR' => $crnt_year, 'TRAFF_SHOW_PERCENT' => $traff_show_percent, 'TRAFF_PERCENT' => $traff_percent, 'TRAFF_MSG' => $rtraff_max ? tr('%1$s / %2$s <br/>of<br/> <strong>%3$s</strong>', sizeit($utraff_current), sizeit($rtraff_current), sizeit($rtraff_max)) : tr('%1$s / %2$s <br/>of<br/> <strong>unlimited</strong>', sizeit($utraff_current), sizeit($rtraff_current)), 'DISK_SHOW_PERCENT' => $disk_show_percent, 'DISK_PERCENT' => $disk_percent, 'DISK_MSG' => $rdisk_max ? tr('%1$s / %2$s <br/>of<br/> <strong>%3$s</strong>', sizeit($udisk_current), sizeit($rdisk_current), sizeit($rdisk_max)) : tr('%1$s / %2$s <br/>of<br/> <strong>unlimited</strong>', sizeit($udisk_current), sizeit($rdisk_current)), 'DMN_MSG' => $rdmn_max ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $udmn_current, $rdmn_current, $rdmn_max) : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $udmn_current, $rdmn_current), 'SUB_MSG' => $rsub_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $usub_current, $rsub_current, $rsub_max) : ($rsub_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $usub_current, $rsub_current)), 'ALS_MSG' => $rals_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $uals_current, $rals_current, $rals_max) : ($rals_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $uals_current, $rals_current)), 'MAIL_MSG' => $rmail_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $umail_current, $rmail_current, $rmail_max) : ($rmail_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $umail_current, $rmail_current)), 'FTP_MSG' => $rftp_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $uftp_current, $rftp_current, $rftp_max) : ($rftp_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $uftp_current, $rftp_current)), 'SQL_DB_MSG' => $rsql_db_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $usql_db_current, $rsql_db_current, $rsql_db_max) : ($rsql_db_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $usql_db_current, $rsql_db_current)), 'SQL_USER_MSG' => $rsql_user_max > 0 ? tr('%1$d / %2$d <br/>of<br/> <strong>%3$d</strong>', $usql_user_current, $rsql_user_current, $rsql_user_max) : ($rsql_user_max === "-1" ? tr('<strong>disabled</strong>') : tr('%1$d / %2$d <br/>of<br/> <strong>unlimited</strong>', $usql_user_current, $rsql_user_current)))); }