#!/usr/bin/perl use lib 'adm'; $| = 1; use Connect; use Dbase; use Params; use Tpl; $, =", "; $params = Params -> new(); $sid = $params -> cookie('sid'); $sid = undef unless($sid); Connect -> db_connect($sid); $sid = $session->id; print "Set-Cookie: sid=$sid; expires=".gmtime(time+ 2592000).";path=/;\n"; print "Content-type: text/html; charset=windows-1251\n\n"; &rate; $_ = $params -> param; if($params -> param('tpl')){ $tpl = Tpl -> new($params -> param('tpl').'.htm'); Dbase -> top($tpl); print $tpl -> gettpl; exit; } $cat = ($params -> param('cat') || $params -> param('rub') || $params -> param('pid') || $cat); if($cat eq ''){$cat = $session -> param('cat')} else{$session -> param('cat', $cat)} if($params -> param('load') eq 'basket'){&basket} elsif($params -> param('load') eq 'about'){&about} else{ my $tpl = Tpl -> new('rubric.htm'); if(!($params -> param('rub'))){ Dbase -> rubric($tpl, $params -> param('cat')); # по-старому... #ублюдочный cat откуда-то прискакал.. }else{ Dbase -> rubric($tpl, $params -> param('rub')); # по-новому.. } } #if($_ == 0){ # $tpl = Tpl -> new('start.htm'); # print $tpl -> gettpl; # exit; #} if(($params -> param('cat'))||($params -> param('rub'))){ my $tpl = Tpl -> new('test.htm'); if($params -> param('search')){ } else{ } $pid = Dbase -> news(undef, $params -> param('news'), undef, $tpl); Dbase -> news(undef, undef, ($params -> param('cat') || $params -> param('rub') || $params -> param('pid') || $pid), $tpl); print $tpl -> gettpl(); } if($params -> param('load') eq 'news'){ require Vote; my $tpl = Tpl -> new('news.htm'); $pid = Dbase -> news(undef, $params -> param('news'), undef, $tpl); {my $tpl = Tpl -> new('right.htm'); &lbasket($tpl); Vote -> result($tpl); Dbase -> news(undef, undef, ($params -> param('cat') || $params -> param('rub') || $params -> param('pid') || $pid), $tpl) } print $tpl -> gettpl(); } elsif($params -> param('load') eq 'lbasket'){ if($params->param('id')){&savebasket()} $tpl = Tpl -> new('lbasket.htm'); $id = $params -> param('id'); &lbasket($tpl); print $tpl -> gettpl(); # print ""; } elsif($params -> param('load') eq 'auto'){ my ($email, $password) = $params -> param qw(email password); $tpl = Tpl -> new('auto.htm'); Dbase -> auto($email, $password, $tpl, $params); print $tpl -> gettpl(); } else{ ($id, $rub, $view) = $params -> param qw(id rub view); if($params -> param('search')){ # print "starts here"; require Search; $tpl = Tpl -> new('search.htm'); Search -> search($params -> param('search'), "${DB_preffix}_tovar", $tpl); Search -> oldsearch($tpl); print $tpl -> gettpl; # print "ends here"; exit; } require Vote; if($id){&savebasket()} my $tpl = Tpl -> new('right.htm'); &lbasket($tpl); Dbase -> news(undef, undef, ($params -> param('rub') || $params -> param('pid') || $cat), $tpl); if($params -> param('question')){ Vote -> vote; } Vote -> result($tpl); #search? if($view ne ''){$session -> param('view', $view)} if($cat ne ''){&cat()} else{ my $tpl = Tpl -> new('news.htm'); Dbase -> news(undef, $params -> param('news'), undef, $tpl); print $tpl -> gettpl(); } } sub cat{ my $sth = $dbh -> prepare("SELECT * FROM ${DB_preffix}_exchange"); $sth -> execute(); my $tpl = Tpl -> new('cat.htm'); $tpl -> add('cat', $cat, 'page', $params -> param('page')); Dbase -> tovar($cat, $tpl, $params -> param('page')); my $curr; while ( $curr = $sth->fetchrow_hashref() ) { my $rate = $curr->{'rate'}; $rate = $rate ? 1/$rate : 0; $tpl->add( $curr->{'currency'} ); } $pid = Dbase -> news(undef, $params -> param('news'), undef, $tpl); Dbase -> news(undef, undef, ($params -> param('cat') || $params -> param('rub') || $params -> param('pid') || $pid), $tpl); print $tpl -> gettpl(); } sub about{ my $tpl = Tpl -> new('about.htm'); # print "Content-type: text/html; charset=windows-1251\n\n"; # Dbase -> gettovar($id, $tpl, $params -> param('page', 'edit')); # Dbase -> gettovar($id, $tpl, $params -> param('page', 'edit')); Dbase -> about($tpl, $params -> param('id')); # $tpl -> add('id', $id); print $tpl -> gettpl; exit; # my $tpl = Tpl -> new('about.htm'); # Dbase -> about($tpl, $params -> param('id')); # print $tpl -> gettpl; # exit } sub basket{ require Basket; my $tpl; if($params -> param('pay')){ require Pay; if($params -> param('id')){Basket -> basket(undef, $params)} $tpl = Tpl -> new('pay.htm'); Pay -> pay($tpl, $params); } else{ $tpl = Tpl -> new('basket.htm'); if($params -> param('id')){Basket -> basket($tpl, $params)} else{Basket -> basket($tpl);} } print $tpl -> gettpl(); exit; } sub savebasket{ require Basket; $basket = $session -> param('basket'); %tovar = split /\s/, $basket; $tovar{$params -> param('id')} += $params -> param('number'); $session -> param('basket', join(" ", %tovar)); Basket -> basket; } sub lbasket{ my $tpl = shift; $number = $session -> param('number'); $price = $session -> param('price'); if($number){ $tpl -> addtpl('basket', 'number', $number, 'price', $price); } else{$tpl -> addtpl('empty')} } sub rate() { my $sth = $dbh -> prepare("SELECT * FROM ${DB_preffix}_exchange"); $sth -> execute(); my $tpl = Tpl -> new('rate.html'); my $curr; while ( $curr = $sth->fetchrow_hashref() ) { my $rate = $curr->{'rate'}; $rate = $rate ? 1/$rate : 0; $tpl->add( $curr->{'currencyid'}, sprintf("%.2f", $rate) ); } $tpl -> add('ue', 1); }