#!/usr/bin/perl #use CGI qw(:standard); # Set Variables $group = 'email'; ################################### #default variables do't change it $formfile = $group.'.form'; $indexfile = $group.'.index'; $datafile = $group.'.dat'; $deffile = $group.'.def'; ############################## $cgiurl = 'index.cgi'; $admincgiurl = 'admin.cgi'; $title = '預訂【諮商專業倫理通訊】電子報'; # Set Your Options: $perorder = 0; # 1 = first in first show ; 0 = in the other hand $use_time = 1; # 1 = YES; 0 = NO # Done ############################################################################## print "Content-type: text/html\n\n"; &ReadSIN(*data); &GetDef(*type,*value,*option); #%option = GetDef('option'); #%value = GetDef('value'); if($data{'submit'}){ local ($key,$temp,@temp); foreach $key (sort keys %type) { @temp=split(/\0/,$data{$key}); foreach $temp (@temp) { if (&CheckData(*temp,$key)) { $realdata{$key} .= "\0" if (defined($realdata{$key})); $realdata{$key} .= $temp; } } } local $count = &WriteData(); &PrintOK($count); exit; } elsif($data{'del'}){ if ($data{'E-mail信箱'}) { local(@datalines,$line,$f); open(D,$datafile)|| CgiErr('System can not open datafile !!'); @datalines = ; close(D); $f = 0; open(D,">$datafile"); foreach $line (@datalines) { if ($line =~/\&*$data{'E-mail信箱'}\&/) { $f = 2; } if ($line =~s/\&$data{'E-mail信箱'}\&/\&*$data{'E-mail信箱'}\&/) { $f= 1; } print D $line; } close(D); print "
★資料刪除★
\n"; if ($f != 0) { print "◎您的E-mail信箱已經刪除:
\n$data{'E-mail信箱'}\n"; } else{ print "◎系統找不到您的E-mail:
\n$data{'E-mail信箱'}\n"; print "請確定您曾經加入並新輸入您的E-mail信箱 !!"; } print "

回$title"; exit; } else{ CgiErr('你必須輸入-E-mail信箱- !!'); } } elsif($data{'option'} eq 'adminform'){ } else{ local (@datas,@temp,$update); open(DATA,$datafile); @datas = ; close(DATA); @temp = split(/&&/,$datas[$#datas]); $update = $temp[$#temp]; #get the least updata time !! local $c = $#datas + 1; #get how many numbers the data have print "$title\n\n"; print "

\n"; #print "

★$title★

\n"; print "
歡迎預訂 【諮商專業倫理通訊】電子報免費給您最好最新訊息
\n"; print "
請在此留下您的訂戶資料 您的資料我們將不會對外公開 趕快行動吧!
\n"; print "
【回首頁】【搜尋】【管理】
\n"; print "
目前有 $c 位訂戶,Update:$update

\n"; print "


\n"; print ""; local (@defs,@deflines,$head,$temp); foreach $k(@Keys) { if ($option{$k}=~/N/) { $head =$k.'(必填)'; } else{ $head =$k; } if ($type{$k} eq 'text') { print "\n"; print "
★$head\n"; } elsif($type{$k} eq 'textarea'){ print "
★$head
\n"; } elsif($type{$k} eq 'radio'){ print "
★$head\n"; local @datas = split(/\;/,$value{$k}); foreach $temp (@datas) { print "$temp \n"; } } elsif($type{$k} eq 'select'){ print "
★$head\n"; print "\n"; } if ($k eq 'E-mail信箱') { print ""; } } print "
       

\n"; print "
Back
"; #&PrintData($group); print "
"; exit; } exit; ################################################### sub ReadSIN { local (*in) = @_ if @_; local ($i, $key, $val); if ($ENV{'REQUEST_METHOD'} eq 'GET') { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); } @in = split(/[&;]/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; if($val =~/&/){ &CgiErr('請勿使用“&”作為輸入!!'); last; } $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; } if(&CgiErr() > 0){ &CgiErr('>>|'); } } ############################################################## sub CgiErr{ ## print error message !! @ErrMesg=(); local ($mesg) = $_[0] if @_; local ($i,$err_message,$k,$mesgdata,$l); if($mesg =~/^>>\|*(.*)/){ push(@ErrMesg,$1) if $1; if($#ErrMesg != -1){ print "
\n"; foreach $k(0..$#ErrMesg){ if($ErrMesg[$k]=~/System/i){ print "\n"; } else{ print "\n"; } } print "
資料有誤,請仔細察看下列項目!!
Warn !!$ErrMesg[$k]
Data Error
$ErrMesg[$k]
\n"; if($mesg =~/^>>\|(.*)/){ print "
\n"; print "\n"; print "
\n"; exit; } } return @ErrMesg ; } else{ push(@ErrMesg,$mesg) if ($mesg) ; return @ErrMesg ; } } ################################################## sub GetDef{ local (*type,*value,*option) = @_ if @_; local ($def,@deflines,$temp); $def = $group.'.def'; open(DEF,$def) || CgiErr('>>|Systen can\'t open defineS file !!'); @deflines = ; close(DEF); foreach $temp (@deflines) { if (($temp eq '')||( $temp=~/\s*#.*/g)) { next; } @temp = split(/\|/,$temp,4); push(@Keys,$temp[0]) ; $type{$temp[0]} = $temp[1]; $value{$temp[0]} = $temp[2]; $option{$temp[0]} = $temp[3]; } } ################################################## ############################################################## sub PrintData{ local ($in) = $_[0] if @_; local ($def,$data,@defs,@deflines,@datas,@datalines,@types,$i,@temp); open(DEF,$datafile) || return; @datalines = ; close(DEF); foreach $temp (@datalines) { print "
"; @datas = split(/&&/,$temp); splice(@datas,0,1); for($i=0;$i<=$#Keys;$i++ ){ if (($datas[$i] ne '')&&($option{$Keys[$i]} =~/S/)) { $datas[$i]=~s/\0/
/g; if ($type{$Keys[$i]} eq 'textarea') { print "
$Keys[$i]
$datas[$i]
\n"; } elsif($type{$Keys[$i]} eq 'other'){ } else{ print "
★$Keys[$i]$datas[$i]\n" } } else{ next; } } print "
★填寫日期:$datas[$#datas]\n"; print "
\n"; } } ############################################################## sub CheckData{ ##### # N: 一定要填寫 # E: email format # W: http format # A: 管理所要列出的項目 # S: 一般畫面所要顯示的資料 local (*in,$inkey) = @_ if @_ ; if($option{$inkey}=~/E/){ if ($in=~/.+\@.+\..+/){ if ($in=~/[;><&\*`\| ]/) { $in = ''; } } else{ $in = ''; } } if($option{$inkey}=~/W/){ unless ($in=~/http:\/\/.+\..+\..+/) { $in = ''; } } if($type{$inkey} eq 'textarea'){ $in =~s//>/g; $in =~s/"/"/g; $in =~s/\cM//g; $in =~s/\n\n/

/g; $in =~s/\n/
/g; } if(($type{$inkey} eq 'select')||($type{$inkey} eq 'radio')){ unless ($value{$inkey}=~/$in/g) { CgiErr('>>|CGI 參數傳遞錯誤!!'); } } if (($option{$inkey}=~/N/g)&&($in eq '')) { &CgiErr(">>|$inkey 欄位是一定要填寫的,請再檢查一次!!"); } if ($in ne '') { return 1; } else{ return 0; } } ############################################################## sub WriteData{ #mon/dd/yy-hh/mim/ss local ($e,$date,@e,$count); local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon++; if ($use_time == 1) { $date = "$mon/$mday/$year-$hour:$min:$sec"; } else{ $date = "$mon/$mday/$year";} chop($date) if ($date =~ /\n/); open(D,$datafile); @e = ; close(D); ($count,$_) = split(/&&/,$e[$#e]); $count++; open(DATA,">>$datafile"); print DATA "$count&&"; foreach $e (@Keys) { print DATA "$realdata{$e}&&"; } print DATA "$date\n"; close(DATA); return $count ; } ############################################################## sub PrintOK{ local ($c) = $_[0] if @_; local ($t,$e,@temp); print "Thank You!! ^_^\n"; print "

★謝謝您成為 【諮商專業倫理通訊】電子報 的訂戶貴賓!!★

\n"; print "

您的資料已加入訂戶貴賓名單上了,您是第 $c 位訂戶貴賓!!
\n"; print "您的資料如下:

\n"; print "

\n"; foreach $e (@Keys) { if ($realdata{$e} ne '') { print "
▲$e\n"; @temp = split(/\0/,$realdata{$e}); foreach $t (@temp) { print "$t
\n"; } } } print "

回$title\n"; } ############################################################ sub SetValueofKey{ local ($db,*in) = @_ if @_; local ($deffile,$datfile,@datalines); $datfile = $db.'.dat'; open(D,$datfile); @datalines = ; close(D); foreach $temp (@datalines) { @datas = split(/&&/,$temp); splice(@datas,0,1); for($i=0;$i<=$#Keys;$i++ ){ print""; } } }