#!C:\Perl64\bin\perl.exe -w
#************************************************************************
# Чтение файла истории ICQ v 0.1 (19.07.2010г.)
#
#************************************************************************
use strict;
#use CGI::Carp qw(fatalsToBrowser);
#use Data::Dump qw(dump);
use CGI ':standard';
use DBI;
my ($dbfile, $dbh, $sth, $sql, @text, @colors, $Users);
$dbfile = 'Messages.qdb'; # файл ICQ history
@colors = ('your', 'stra');
$dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","");
if (param('userId') =~ /^\d+$/) {
my $userId = param('userId');
my $tt = 2415018.5 + ($gmtl / 24); # хм... http://en.wikipedia.org/wiki/Julian_day
$sql = "SELECT strftime('%d.%m.%Y', m.date+$tt), strftime('%H:%M', m.date+$tt), m.fromUser, m.subject
FROM Messages m INNER JOIN Participants p ON m.participantsHash = p.participantsHash
WHERE m.fromUser = '$userId' OR p.userId = '$userId'";
$sth = $dbh->prepare(qq{ $sql });
$sth->execute();
my (%unic1, %unic2);
while (my ($date, $time, $fromUser, $subject) = $sth->fetchrow_array()) {
my $dates = my $times = ' ';
$dates = $date and $unic1{$date} = 1
and %unic2 = () unless exists $unic1{$date};
$times = $time and $unic2{$time} = 1
unless exists $unic2{$time};
my $color = ($fromUser) ? $colors[1] : $colors[0];
$subject =~ s/(?:\n|\r\n)/<br \/>/g;
push @text, td
([$dates, $times, span
({-class
=>$color}, $subject)]);
}
($Users) = $dbh->selectrow_array("SELECT name FROM Users WHERE userId = '$userId'");
$Users = " - $Users ($userId)";
} else {
$sql = "SELECT userId, name FROM Users";
$sth = $dbh->prepare(qq{ $sql });
$sth->execute();
while (my ($userId, $name) = $sth->fetchrow_array()) {
push @text, td
([a
({-href
=>"?userId=$userId"}, $userId), $name]);
}
}
$sth->finish();
$dbh->disconnect();
my $newStyle = <<END;
.your { color: green; }
.stra { color: blue; }
td { border-bottom: 1px solid #A52A2A; }
END
print header
(-charset
=> "UTF-8"),
start_html(-title=>"ICQ History", -style=>{-code=>$newStyle}),
h3(a({-href=>$ENV{'SCRIPT_NAME'}}, "ICQ History"), $Users),
table({-border=>0}, Tr([@text]) ),
end_html;