1#!/usr/local/bin/perl
2#
3# LightSquid Project (c) 2004-2005 Sergey Erokhin aka ESL
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version.
9#
10# detail see in gnugpl.txt
11
12print "Content-Type: text/html\n\n";
13
14use File::Basename;
15push (@INC,(fileparse($0))[1]);
16
17use CGI;
18require "/usr/local/etc/lightsquid/lightsquid.cfg";
19require "common.pl";
20
21
22$co=new CGI;
23
24$year =$co->param('year');
25$month=$co->param('month');
26$day  =$co->param('day');
27$user =$co->param('user');
28$mode =$co->param('mode');
29
30InitTPL("user_detail",$co->param('tpl'));
31
32if      ($mode eq "month") {
33  $workperiod="##MSG_WHOLE## ##MSG_MONTH## - $year $MonthName[$month]";
34  $mask = "$year$month";
35} elsif ($mode eq "year") {
36  $workperiod="##MSG_WHOLE## ##MSG_YEAR## - $year";
37  $mask = "$year";
38} else {
39  $workperiod="$day $MonthName[$month] $year";
40  $mask = "$year$month$day";
41  $mode = "day"
42}
43
44@datelist=sort glob "$reportpath/$mask*";
45
46$calculatedtotal=0;
47foreach $workday (sort @datelist) {
48  GetRealName($workday,"?");
49  GetGroup($workday);
50
51  open FF,"<$workday/$user" || MyDie("can't open $daypath/$user");
52  $totalsize=<FF>;chomp $totalsize;$totalsize=~s/total: //;
53
54  while (<FF>) {
55    ($site,$size,$hit)=split;
56    $h{$site}{hit} +=$hit;
57    $h{$site}{size}+=$size;
58    $calculatedtotal+=$size
59  }
60  close FF;
61}
62
63
64#---------
65# check - exist current user in .bigfiles
66# only in DAY mode
67if ($mode eq "day") {
68  open FF,"<$reportpath/$year$month$day/.bigfiles";
69
70  while (<FF>) {
71    ($buser,$btime,$bsize,$blink)=split;
72    $flagbigfiles=1 if ($buser eq $user);
73  }
74  close FF;
75}
76
77if ($flagbigfiles) {
78    $bigfiles_B="##MSG_BIG_FILES_USER##";
79    $bigfiles_L="bigfiles.cgi?year=$year&month=$month&day=$day&user=$user";
80}
81#---------
82
83
84$N=0;
85$total=0;
86foreach $site (sort {$h{$b}{size} <=> $h{$a}{size}} keys %h)  {
87  $N++;
88  $hit=$h{$site}{hit};
89  $size=$h{$site}{size};
90  $total+=$size;
91  $percent   =sprintf("%2.1f",int($size*1000/$calculatedtotal)/10);
92  $printhit  =FineDec($hit);
93  $printsize =FineDec($size);
94  $printtotal=FineDec($total);
95
96  $siteurl_L="http://$site";
97  $siteurl_B="$site";
98
99  $rowattr = ($N & 1)?$hTPLVARIABLE{oddattr}:$hTPLVARIABLE{evenattr};
100
101  $tmp=$hTPL{site};
102  $tmp=~s/##NUM##/$N/;
103  $tmp=~s/##SITEURL_L##/$siteurl_L/g;
104  $tmp=~s/##SITEURL_B##/$siteurl_B/g;
105  $tmp=~s/##SITECONNECT##/$printhit/;
106  $tmp=~s/##SITEBYTES##/$printsize/;
107  $tmp=~s/##SITETOTAL##/$printtotal/;
108  $tmp=~s/##SITEPERCENT##/$percent/;
109  $tmp=~s/##ROWATTR##/$rowattr/;
110  $tpl{site} .= $tmp;
111
112}
113
114$printtotalsize=FineDec($calculatedtotal);
115
116$printuser="$user";
117$printuser .= " (".GetRealName("?",$user).")" if ($userealname != 0);
118
119ReplaceTPL(USER,$printuser);
120ReplaceTPL(TOTAL,$printtotalsize);
121ReplaceTPL(WORKPERIOD,$workperiod);
122ReplaceTPL(GROUP,(defined $hGroup{$user})?"$hGroupName{$hGroup{$user}}":"?");
123
124
125ReplaceTPL_URL(TIMEURL,"user_time.cgi?year=$year&month=$month&day=$day&user=$user","##MSG_TIME_LINK##");
126ReplaceTPL_URL(BIGFILESURL,$bigfiles_L,$bigfiles_B);
127
128ApplyTPL();
129HideTPL("timereport") if (($timereport == 0) || ($mode ne "day"));
130HideTPL("group")      if ($showgrouplink == 0);
131PrintTPL();
132
133__END__
1342004-11-09 ADD : Total column, commulative total
1352004-12-18 ADD : ���������� ���� � ��� ������������ � �������
1362005-01-31 ADD : New Param (month=1) if, then show whole month user report, else only selected day
1372005-04-14 FIX : in CONNECT column displayed size column
1382005-04-17 ADD : TemplateEngine
1392005-04-25 ADD : mode=year
1402005-05-01 ADD : time report link
1412005-08-30 ADD : Color Flipper
1422005-09-08 ADD : if user exist in .bigfiles file, on top of report MESSAGE with link
1432005-10-02 ADD : _L,_B
1442005-11-01 ADD : Group name in header
1452006-06-28 ADD : die -> MyDie
1462006-06-28 ADD : &tpl= support
1472006-09-13 ADD : add &user= in bigfiles URL
1482006-11-20 ADD : /g for ##SITEURL_B## & ##SITEURL_L##, my need in some cases