// *** Функция balans - результат - баланс пользователя ***
// ********************************************************
function balans($id_user)
{
global $balans, $all_day, $date_temp;
$res = mysql_query("SELECT * FROM `cabinet_unlim` WHERE `id_user`='$id_user'");
while($arr = mysql_fetch_assoc($res))
{
$time = $arr[time];
$d = time() - $time;
if ($d > 2592000) {$d = 2592000;}
// 86400 $d
// ---------------------- = ----
// $_SESSION[const_money] x
$v = $v + $d * $_SESSION[const_money] / 86400;
}
$res_date = mysql_query("SELECT date_off, date_on FROM `cabinet_off` WHERE `id_user` = $id_user");
$res1 = mysql_query("SELECT sum(summa) FROM `cabinet_proplata` WHERE `id_user`= $id_user");
$res2 = mysql_query("SELECT * FROM `cabinet_users` WHERE `id_user` = $id_user");
if (!$res2) {$balans = "?"; return;}
$arr2 = mysql_fetch_assoc($res2);
$array_money = mysql_fetch_row($res1);
//mysql_free_result($res1); $array_date = $arr2[connect];
$status = $arr2[status];
if ($status == 1) {$status = 0;} else {$status = 1;}
mysql_free_result($res2);
$i = -1;
while ($array_assoc = mysql_fetch_assoc($res_date))
{
$i = $i + 1;
$date_off[$i] = $array_assoc[date_off];
$temp_date_off = explode("-", $date_off[$i]);
$date_off[$i] = mktime(0,0,0,$temp_date_off[1],$temp_date_off[2],$temp_date_off[0]);
$date_on[$i] = $array_assoc[date_on];
if ($date_on[$i]!=0)
{
$temp_date_on = explode("-", $date_on[$i]);
$date_on[$i] = mktime(0,0,0,$temp_date_on[1],$temp_date_on[2],$temp_date_on[0]);
}
else
{
$date_on[$i]=date("Y-m-d");
$temp_date_on = explode("-", $date_on[$i]);
$date_on[$i] = mktime(0,0,0,$temp_date_on[1],$temp_date_on[2],$temp_date_on[0]);
}
$raznica_days = $date_on[$i]-$date_off[$i];
$all_day = $all_day + $raznica_days;
}
$all_day = $all_day / (3600 * 24);
$date_elements = explode("-", $array_date);
$timeconnect = mktime(0,0,0,$date_elements[1],$date_elements[2],$date_elements[0]);
$raznica = ((time() - $timeconnect)/60/60/24);
$res = mysql_query("SELECT * FROM `cabinet_const`"); $arr = mysql_fetch_row($res); $_SESSION[const_money] = $arr[0];
$balans = $array_money[0] - ($raznica - $all_day) * $_SESSION[const_money] * $status + $v * $status;
$n = strpos($balans,'.');
if ($n > 0) {$balans = substr($balans,0,$n).substr($balans,$n,10);}
$array_date_proplata = localtime($balans / $_SESSION[const_money] * 24 * 3600 + time());
$day = $array_date_proplata[3]; if ($day < 10) {$day = '0'.$day;}
$month = $array_date_proplata[4] + 1; if ($month < 10) {$month = '0'.$month;}
$year = $array_date_proplata[5] + 1900;
$date_temp = $day.'.'.$month.'.'.$year;
return;
}
сама офигела