* Calculate weekly used time correctly (from Sunday 00:00:00)
* Allow for defining the ldap_filter used when searching for a user. The filter supports dynamic variables
like %u (username) and %U (username provided though http auth)
+* Add a configuration directive counter_monthly_calculate_usage to calculate the monthly usage time. Calculate
+ it in user_admin if monthly_limit != 'none' or if this directive is set.
+ Based on a report by "apellido jr., wilfredo p"
Ver 1.62:
* Remove one sql query from user_admin which was not needed.
* Instead of a query like "LIKE 'YYYY-MM-DD%'" use "AcctStopTime >= 'YYYY-MM-DD 00:00:00 AND AcctStopTime
$week_str = date("$config[sql_date_format]",$week);
$day = date('w');
$week_start = date($config[sql_date_format],$now - ($day)*86400);
+$month_start = date($config[sql_date_format],$now - date('j')*86400);
$today = $day;
$now_tmp = $now;
for ($i = $day; $i >-1; $i--){
}
else
echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
+ if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
+ $search = @da_sql_query($link,$config,
+ "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE UserName = '$login'
+ AND AcctStartTime >= '$month_start' AND AcctStartTime <= '$now_str';");
+ if ($search){
+ $row = @da_sql_fetch_array($search,$config);
+ $monthly_used = $row['sum(AcctSessionTime)'];
+ }
+ else
+ echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
+ }
$search = @da_sql_query($link,$config,
"SELECT COUNT(*) FROM $config[sql_accounting_table] WHERE UserName = '$login'
AND AcctStopTime >= '$week_str' AND AcctStopTime <= '$now_str'
if ($weekly_limit != 'none' && !$tmp)
$weekly_used = "<font color=red>$weekly_used</font>";
+ if ($monthly_limit != 'none'){
+ $tmp = $monthly_limit - $monthly_used;
+ if ($tmp <=0){
+ $tmp = 0;
+ $extra_msg .= '(Out of monthly quota)';
+ }
+ if (!is_numeric($remaining))
+ $remaining = $tmp;
+ if ($remaining > $tmp)
+ $remaining = $tmp;
+ $log_color = ($remaining) ? 'green' : 'red';
+ }
+ if ($config[counter_monthly_calculate_usage] == 'true'){
+ $monthly_used = time2str($monthly_used);
+ if ($monthly_limit != 'none' && !$tmp)
+ $monthly_used = "<font color=red>$monthly_used</font>";
+ }
+
$search = @da_sql_query($link,$config,
"SELECT * FROM $config[sql_accounting_table]
WHERE UserName = '$login' AND AcctStopTime IS NULL