#!/usr/bin/perl #-d #-w #-d:ptkdb ######################################################### # Manager custom message on web # main view ######################################################### my $currdir = &getcurrpath; require "$currdir/conf.pl"; use CGI; use HTML::Template; use Manager; use Page; require "$currdir/cookie.pl"; sub main{ my $hd = *STDOUT; my $cgi = new CGI; my @logdata = (); my $tmplfile = $g_cgiparam{tmpldir}."tempprod.html"; my $tpl = HTML::Template->new( filename => $tmplfile, loop_context_vars =>1, die_on_bad_params=>0); $tpl->param(index=>1); my $mg = Manager->new(\@logdata); my $sch_txt = $cgi->param('sch_txt'); my $sch_type = $cgi->param('sch_type'); my $pg = Page->new; my $pg_no = $cgi->param('pg_no'); if($pg_no eq ''){ $pg_no = 1; } $pg->setvalue({ pg_no=>$pg_no, pg_rc=>$g_cgiparam{pg_rc}, pg_sec=>$g_cgiparam{pg_sec} }); $mg->readcatefromtxt($g_cgiparam{datadir}."type.txt"); $mg->readprodfromtxt($g_cgiparam{datadir}."product.txt"); $mg->dealwithschprods($sch_txt,$sch_type,$pg); $mg->dealwithpageprods($pg,['viewno']); &blanktemplate($mg,$tpl,$cgi,$pg); print $hd "Content-type: text/html\n\n"; $tpl->output(print_to=>$hd); } ## blank template file sub blanktemplate{ my($mg,$tpl,$cgi,$pg) = @_; my ($count,$i); my $sch_txt = $cgi->param('sch_txt'); my $sch_type = $cgi->param('sch_type'); my $pcates = $mg->{cates}; my ($lineno); if ($pcates){ my $opt_str = $mg->getcates_opt_str($pcates,$sch_type); $tpl->param(cates_opt_str=>$opt_str); #my $typestr = $mg->getcates_line_str($pcates,$sch_type,"index.cgi","sch_type"); #$tpl->param(cates_line_str=>$typestr); } $tpl->param(sch_type=>$sch_type); $tpl->param(sch_txt=>$sch_txt); my $pviewprods = $mg->{viewprods}; my $comfunc = sub{ my ($parray,$i,$j) = @_; #my $t1 = $pviewprods->{$parray->[$i]}->{viewno}; #my $t2 = $pviewprods->{$parray->[$j]}->{viewno}; my $t1 = $pviewprods->{$parray->[$i]}->{lineno}; my $t2 = $pviewprods->{$parray->[$j]}->{lineno}; return ($t1-$t2); #return -1 if ($t1 lt $t2); #return 0 if ($t1 eq $t2); #return 1 if ($t1 gt $t2); }; if($pviewprods){ my @prod_loop = (); my @arryschkey = keys %$pviewprods; $mg->sortarray(\@arryschkey,$comfunc); my $pkeys = \@arryschkey; foreach $lineno(@$pkeys){ my %row =(); $row{lineno} = $pviewprods->{$lineno}->{lineno}; $row{cate} = $pviewprods->{$lineno}->{cate}; $row{pdname} = $pviewprods->{$lineno}->{pdname}; $row{pdcode} = $pviewprods->{$lineno}->{pdcode}; push(@prod_loop,\%row); } $tpl->param(prod_loop=>\@prod_loop); } if($pg->{pg_total} == 0){ $tpl->param(pg_no=>0); $tpl->param(pg_rc_first=>0); }else{ $tpl->param(pg_no=>$pg->{pg_no}); $tpl->param(pg_rc_first=>($pg->{pg_rc_first}+1)); } $tpl->param(count=>$pg->{rc_total}); $tpl->param(pg_rc=>$pg->{pg_rc}); $tpl->param(pg_total=>$pg->{pg_total}); $tpl->param(pg_rc_end=>($pg->{pg_rc_end}+1)); my $url_sch = ''; if ($sch_txt ne ''){ $url_sch = qq(sch_txt=$sch_txt); } if($sch_type ne ''){ if($url_sch ne ''){ $url_sch = $url_sch.qq(\&sch_type=$sch_type); }else{ $url_sch = qq(sch_type=$sch_type); } } if($pg->{ahead}){ $tpl->param(ahead => 1); my $url_ahead = ''; if($url_sch ne ''){ $url_ahead= qq($url_sch\&pg_no=$pg->{aheadno}); }else{ $url_ahead= qq(pg_no=$pg->{aheadno}); } $tpl->param(url_ahead=>$url_ahead); $tpl->param(pgsec=>$pg->{pg_sec}); } if($pg->{behind}){ $tpl->param(behind => 1); my $url_behind = ''; if($url_sch ne ''){ $url_behind= qq($url_sch\&pg_no=$pg->{behindno}); }else{ $url_behind= qq(pg_no=$pg->{behindno}); } $tpl->param(url_behind=>$url_behind); $tpl->param(pgsec=>$pg->{pg_sec}); } my $pg_no = $pg->{'pg_no'}; my $firstno = $pg->{'firstno'}; my $lastno = $pg->{'lastno'}; my @pgsec_loop = (); my $turl = ''; my $url_sec =''; for($i=$firstno;$i<=$lastno;$i++){ if($url_sch ne ''){ $url_sch =~ s/\s/\%20/g; $url_sec= qq($url_sch\&pg_no=$i); }else{ $url_sec= qq(pg_no=$i); } if ($i == $pg_no){ $turl = qq( $i ); }else{ $turl = qq( $i ); } my %pgsec = ( url_pgsec => $turl ); push(@pgsec_loop,\%pgsec); } $tpl->param(pgsec_loop=>\@pgsec_loop); } #get current path ,in order to get current include path sub getcurrpath{ my $path = __FILE__; my $mypath; if($path =~ /\\/){ $path =~ s/\\/\//g; } if ($path){ $mypath = substr($path,0,rindex($path,"/")); }else{ $mypath = substr($ENV{'PATH_TRANSLATED'},0,rindex($ENV{'PATH_TRANSLATED'},"\\")); $mypath =~ s/\\/\//g; } return $mypath; } main(@ARGV);