#!/usr/bin/perl
#############################################################
##            ExchangeVisits    Version  3.00              ##
##            February 2003  Ust-Nera  Russia              ##
##            All rights  ScriptZaWM&RuScript              ##
##            Web  http://www.script.zawm.biz              ##
##            Support scripts script@zawm.biz              ##
#############################################################
require "config.pl";
if($ENV{'REQUEST_METHOD'} eq 'GET'){$query=$ENV{'QUERY_STRING'}}
elsif($ENV{'REQUEST_METHOD'} eq 'POST'){sysread(STDIN,$query,$ENV{'CONTENT_LENGTH'})}
@formfields=split(/&/,$query);
sub urldecode{local($val)=@_;
$val=~s/\+/ /g;$val=~s/%([0-9a-hA-H]{2})/pack('C',hex($1))/ge;
return $val;}
foreach (@formfields){chomp($_);
($f_n,$f_v)=split(/=/,$_);
$f_n=&urldecode($f_n);
$f_v=&urldecode($f_v);
if($f_n=~/^d/ && $f_v ne '1'){$f_v = 0}
if($f_n eq 'move'){push(@td,$f_v)}else{$in{$f_n}=$f_v}}
($Second, $Minute, $Hour, $DayOfMonth, $Month, $ShortYear, $Weekday,
$DayOfYear, $IsDST) = localtime(time);
$Year = $ShortYear + 1900;$Year=~s/^..//;
$Month++;
if($Month < 10) {$Month = "0" . $Month}
if($DayOfMonth < 10) {$DayOfMonth = "0" . $DayOfMonth}
$Date = "$DayOfMonth-$Month-$Year";
print "Content-Type: text/html; charset=windows-1251\n\n";
#### Записываем оплату счета ####
open(SCHET,">>payment.dat");
if ($flock eq "1")
{flock(SCHET, 2);}
print SCHET "$in{'user'}|$Date|$in{'LMI_PAYMENT_AMOUNT'}\n";
close(SCHET);
#### Записываем в статистику пользователя ####
open(PWD,"userdat.pl");
if ($flock eq "1")
{flock(PWD, 2);}
@users = <PWD>;
close(PWD);chomp(@users);
foreach (@users){($login,$pwd,$id,$status,$dr,$dc) = split(/\|/,$_);
if($in{'user'} eq $login){$userid=$id;}}
open(WMUSER,"./users/$userid/wm.user");
@wmuser = <WMUSER>;
close(WMUSER);chomp(@wmuser);
$wmuser[0]=$wmuser[0]+$in{'LMI_PAYMENT_AMOUNT'};
open(WMUSER,">./users/$userid/wm.user");
if ($flock eq "1")
{flock(WMUSER, 2);}
foreach (@wmuser){
print WMUSER "$_\n"}
close(WMUSER);

