File : boardreply.pl. ID : 0808
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Frame
#!/usr/bin/perl
require 'parse.pl';
&parse_form;
print "Content-type:text/html\n\n";
&checklength;
if (!$v{'idstart'}) { &breakerror('ข้อมูลผิดพลาด โปรดกลับไปตรวจสอบ'); }
$filename = "."; 
opendir(flist,"$filename");
@allf = readdir flist;	
closedir(flist);   
$max = 0;
for $i (0 .. @allf) {		  
  if (substr($v{'idstart'},0,10) eq substr($allf[$i],0,10) && 
      substr($allf[$i],10,3) ne "999") {  
    $getseq = substr($allf[$i],10,3);
    if ($getseq > $max) { $max = $getseq; }
  }
}
$max++;
if ($max < 10) { $max = join '','00',$max; } else {
if ($max < 100) { $max = join '','0',$max; } }
$filename = join '',substr($v{'idstart'},0,10),$max,'.txt';
$number = substr($filename,0,13);
if ($v{'email'} =~ /.*\@.*\..*/) { 
  if (!$v{'subj'}) { &breakerror('ไม่ได้กรอกหัวเรื่อง'); }
} else {
  &breakerror('ไม่ได้กรอก E-Mail หรือผิดพลาด');
}
$title = join ':',$number,$v{'subj'},$v{'email'},$v{'icq'},$v{'answer'},$ENV{REMOTE_ADDR};
$filename = join '.',$number,'txt';
open(myfile,">$filename");
print myfile "$title\n";  
print myfile "$v{'message'}";  
close(myfile);
print "$title<br>กะทู้ถูกส่งให้ท่านทาง e-mail และจัดเก็บเข้าแฟ้ม .. เรียบร้อย";
# mail process
$filename = join '',substr($v{'idstart'},0,10),"999.txt";
open(myfile,"$filename");
@ar = <myfile>;
close(myfile);
@ars = split(/:/,$ar[0]);
$mailprog = '/var/qmail/bin/qmail-inject';
open (MAIL, "|$mailprog") || die "Can't open $mailprog!\n";  
print MAIL "To: $v{'email'}";
if ($ars[4] eq "on") { print ",$ars[2]"; }
print MAIL "\nFrom: perlphpasp\@thaiabc.com \n";  
print MAIL "Subject: Reply from board \n\n";
print MAIL "Automatically from http://perlphpaspbook.hypermart.net\n";
print MAIL "$v{'message'}\n";
close (MAIL);