#!/usr/local/bin/perl
#################################################################################################################
# File Upload Script        Version 5.003
#¼öÁ¤ ¹öÁ¯ : Version 6.0 
# Modifier : Younsb         http://younsb.iri-c.ac.kr
#ÃÖ±Ù ¼öÁ¤ÀÏ   1998, 3,17 ÀÏ
#ÀÌ½ºÅ©¸³Æ®´Â ÀÌÀü ¹öÀü°ú´Â ¿ÏÀüÈ÷ »õ·Î¿î 
#ÀÚ·á½Ç¿ë ½ºÅ©¸³Æ®·Î ¾Æ·¡ÀÇ º¯¼ö¸¦ ÀÚ½ÅÀÇ ÄÄ¿¡ ¸Â°Ô ¼öÁ¤ÇÏ½Ã¿À
#»õ·Î¿î ±â´É
#ÀÚµ¿ ÆäÀÌÁö ±â´É 
#GCI.PM È­ÀÏ À§Ä¡¹®Á¦ ÇØ°á
# ---------------------------------------------------------------------
# Configurable Options Follow:
##################################################################################################################
#¿©±â¼­ ºÎÅÍ ¼öÁ¤
BEGIN {
push (@INC, "/perl/lib");           #GCI.PM È­ÀÏÀÇ À§Ä¡ Àý´ë°æ·Î

    $base_dir = "/internet/premech/public_html/member/cgi/thesis";        #upload ±âº» µð·¢Åä¸® Á¤´ë°æ·Î 
    $base_url = "http://www.keti.re.kr/~premech/member/cgi/thesis";       #upload ÀÇ ±âº» URL
                
    $cgi_url = "http://www.keti.re.kr/~premech/member/cgi/thesis/upload.cgi";              #ÀÌ cgiÈ­ÀÏÀÇ url

    $overwrite = 0;                                                 # ±âÁ¸È­ÀÏ µ¤¾î¾²±â Çã¿ë¿©ºÎ.

    $password = 'happy6104';                                      #°ü¸®ÀÚ ºñ¹Ð¹øÈ£ ¸Â°Ô ¼öÁ¤ÇÏ½Ã¿À

    
    #$file_type1 = "gif";                                          #¾÷·Îµå È­ÀÏ Çü½ÄÀ» ÁöÁ¤ÇÒ ¶§
    #$file_type2 = "jpg";                                         #¾÷·Îµå È­ÀÏ Çü½Ä

    $candown = "1";                                               #³»·Á¹Þ±â Çã¿ëÇÏ·Á¸é  1 ¾Æ´Ï¸é 0

    $max_byte ="12000000";                                     #ÃÖ´ë Çã¿ëÈ­ÀÏÅ©±â

    $Windows = 1;                                                 #OS°¡ MS Windows ÀÌ¸é 1 ¾Æ´Ï¸é 0
#####################################################################################################################
#¼öÁ¤ ³¡
    $path = "$base_dir/files";                                  #È­ÀÏÀúÀåÀ§Ä¡ÀÇ DIR(Àý´ë °æ·Î)
    $url = "$base_url/files";                                    #È­ÀÏ ÀúÀåÀ§Ä¡ÀÇ URL
    $upload_url = "$base_url/upload.html";            #upload.htmlÀÇ url 
    $up_file = "$base_dir/filelist.txt";                     #È­ÀÏ ³»¿ëÀ» ±â·ÏÇÏ´Â È­ÀÏ·Î ±×°ÍÀÇ À§Ä¡(Àý´ë°æ·Î)
    $rem_gif = "http://www.keti.re.kr/~premech/cgi-bin/board/icon/delete.gif";                   #»èÁ¦¶ó´Â µ¿ºÀµÈ ÀÌ¹ÌÁö upload µð·¢Åä¸®¿¡ µÎ½Ê½Ã¿À
    $page = '1';                                                      #½ÃÀÛ ÆäÀÌÁö
    $datafile = "data.txt";                                        #È­ÀÏ ÀúÀå µð·¢Åä¸®¿¡ data.txt ¸¦ ³õÀ¸½Ê½Ã¿À

    $exclusive_lock = 2;                                                              # ¼Õ´ëÁö ¸¶½Ã¿À '2'
    $unlock_lock = 8;                                                                   #¼Õ´ëÁö ¸¶½Ã¿À '8'
    $userid = 2301;            # --> This Number is the specific ID
    $groupid = 1000;          # --> This Number is the specific Group
    }
#####################################################################################################################
# ---------------------------------------------------------------------
# -->           ¼Õ´ëÁö ¸¶½Ã¿À   <-- #
#####################################################################################################################
$| = 1;
  
&GetInput;
if($action eq "remove") {
&remove; 
 }

if ($action eq "preview") {
&Redirect_User; }

if ($action eq "upload") {
   &Process_File;
&write_data;
if($temp_dir) {
&remove_temp; 
	}
}

if(param('f_name')) {
&hit;
&down;
}

if(($action eq search) && ($keyword ne "")) {
&search;
}

&Redirect_User;


##################################################################################

sub GetInput {

    use CGI qw(:standard);
    $CGI::OS = 'WINDOWS' if ($Windows);

    $query = new CGI;

    if ($query->param('save-as-filename') !~ /^[ \t]*$/) {
        $filename = $query->param('save-as-filename');
        $yourname = $query->param('yourname');
        $email_ne = $query->param('emailname');
        $comments = $query->param('comments');
        $content = $query->param('content'); 
        $action = $query->param('action');     
        $remove_file = $query->param('remove_file');
        $number = $query->param('number');     
        $passwd = $query->param('passwd');  
        $npage = param('pg');      
        $keyword = param('keyword');      
       } 
else {
        $filename = $query->param('upload-file');
        $yourname = $query->param('yourname');
        $emailname = $query->param('emailname');
        $comments = $query->param('comments');   
        $content = $query->param('content'); 
        $action = $query->param('action');     
        $remove_file = $query->param('remove_file'); 
        $number = $query->param('number');    
        $passwd = $query->param('passwd');   
        $npage = $query->param('pg');  
        $keyword = param('keyword');         
    }

    #
    #  END OF SUB
    #
}

# ######################################################################

sub Process_File {


    &Exit_Not_A_Netscape_User if ($ENV{'HTTP_USER_AGENT'} !~ /^Mozilla\/[432]/);
    if ($yourname eq ""){
    &get_error;
     }
     
    if ($filename =~ /\//) {
        @array = split(/\//, $filename);
        $real_name = pop(@array);
    } elsif ($filename =~ /\\/) {
        @array = split(/\\/, $filename);
        $real_name = pop(@array);
    } else {
        $real_name = "$filename";
    }

    $outfile = "$path" . "/" . "$real_name";

    $filename = $query->param('upload-file');
      @name_check = split(/\./, $filename);
#######È­ÀÏ Çü½Ä ÁöÁ¤
    if ($file_type1 NE '') {
    if (($name_check[1] ne '$file_type1') && ($name_check[1] ne '$file_type2')) {
     &Exit_Not_A_Gif; }
        }

     @TempCheck = split (/\\/, $filename);
        $ii = "$#TempCheck";

       $newname = "$TempCheck[$ii]";
       $outfile1 = "$path" . "/" . "$newname";
       
    &Exit_File_Exists if ((-e "$outfile1") && (!$overwrite));
    # &Exit_Size_Error  if ((stat $tmpfilename)[7] < 1);

    if (!open(OUTFILE, ">$outfile1")) {
        print "Content-type: text/plain\n\n";
        print "-------------------------\n";
        print "Error:\n";
        print "-------------------------\n";
        print "File: $outfile1\n";
        print "-------------------------\n";
        print "È­ÀÏ ¿­±â¿¡ ¹®Á¦°¡ ÀÖ½À´Ï´Ù.\n";
        print "$path\n";
        print "°æ·Î´Â ±ÇÇÑ ¼³Á¤À» '777'·Î ÇØÁÖ¾î¾ß ÇÕ´Ï´Ù.\n\n";
        print "¸¸¾à µ¤¾î¾²±â¸¦ Çã¿ëÇÏ·Á¸é\n";
        print "Áö±Ý Á¸ÀçÇÏ´Â È­ÀÏÀÇ ±ÇÇÑÀ» '666' À¸·Î ÇÏ½Ê½Ã¿À.\n\n";
        print "Error: $!\n";
        exit;
    }

    while ($bytesread = read($filename,$buffer,1024)) {
        $totalbytes += $bytesread;
        binmode OUTFILE;
        print OUTFILE $buffer;               
    }

    close($filename);
    close(OUTFILE);
    if ($totalbytes > $max_byte) {
        unlink $outfile1;
       &Exit_Size_Error;   }
    if ((stat $outfile1)[7] < 1) {
        unlink $outfile1;
        &Exit_Size_Error;
    }
    chmod (0644, "$outfile1")              if (!$Windows);
    chown ($userid, $groupid, "$outfile1") if (!$Windows);

    #
    #  END OF SUB
    #
}

###################################È­ÀÏ ¸Þ¼¼Áö ±â·Ï
sub write_data {
&get_Date;
&get_number;
$newnum = $numm;
&increment_num ;
open (UPFILE,">>$up_file") || die "Can't Open $up_file: $!\n";
print UPFILE "$newnum|$passwd|$newname|$yourname|$email_ne|$comments|$shortdate|$totalbytes|0|$content\n";
close(UPFILE);

}

#############################################
sub Redirect_User {

open (FILE,"$up_file") || die "Can't Open $up_file: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;
$totpge = $SIZE/15;
$totpga = int($totpge);
if ($totpge > $totpga) {
$totpg = $totpga+1; }
else {$totpg = $totpga; }

if ($npage ne "") {$page = $npage;}
$nextpg = $page+1;
$prepg = $page-1;
$start = ($page-1)*15+1;
$stop = ($page*15);
if ($stop > $SIZE) {$stop = $SIZE;}

           print "Content-type: text/html\n\n";
           print "<html><head><title>È­ÀÏ ¸®½ºÆ®</title></head>\n";
           print "<body bgcolor=ffffff><ul><table width=550 border=0><tr><td><img src=$base_url/pds.jpg border=0></td>
                   <td valign=bottom align=right><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=text size=20 name=keyword> <font size=2> <input type=submit value=³í¹®Ã£±â></form></td></tr></table><br>\n";

 if (($page == 1) && ($SIZE <= 15)) {
         print "<td><font size=-1>ÇöÀç ÆäÀÌÁö (1/1)</font></td></tr></table>"; }
if (($page > 1) && ($page eq  $totpg)) { 
         print "<td><form method=post action=$cgi_url><input type=hidden name=pg value=\"$prepg\"><input type=submit value=\"ÀÌÀüÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÇöÀç ÆäÀÌÁö ($page/$totpg)</font></td></tr></table>";
     }

if (($page ==1) && ($totpg > 1)){ 
         print "<td></td><td></form></td><td><form method=post action=$cgi_url><input type=hidden name=pg value=\"$nextpg\"><input type=submit value=\"´ÙÀ½ÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÇöÀç ÆäÀÌÁö ($page/$totpg)</font></td></tr></table>";
    }

if (($page >= 2) && ($totpg > $page)){ 
         print "<td><form method=post action=$cgi_url><input type=hidden name=pg value=\"$prepg\"><input type=submit value=\"ÀÌÀüÆäÀÌÁö\"></td><td></form></td><td><form method=post action=$cgi_url><input type=hidden name=pg value=\"$nextpg\"><input type=submit value=\"´ÙÀ½ÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÇöÀç ÆäÀÌÁö ($page/$totpg)</font></td></tr></table>";
    }


             
  for ($i=1;$i<=$SIZE;$i++) {
     if (($i >= $start) && ($i <= $stop))  {
     }
  else {next}

   $j = $SIZE-$i; 
   $_=$LINES[$j]; 
   ($newnum,$passwd,$newname,$yourname,$email_ne,$comments,$shortdate,$bite,$hit,$content) = split(/\|/, $_);
   
  if ($candown eq '0') {
  if ($email_ne eq "") {
      print "<tr bgcolor=#c1cdc1 ><td align=center><small>$newnum</small></td><td align=center><small>$newname</small></td><td align=center><small>$bite</a></td><td align=center><small>$yourname</a></td><td><small>$comments</small></td><td align=center><small>$shortdate</small></td><td align=center><small>$hit</small></td><td align=center><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0></small></td></tr></form>\n";
      }
  else{
     print "<tr bgcolor=#c1cdc1 ><td align=center><small>$newnum</small></td><td align=center><small>$newname</small></td><td align=center><small>$bite</a></td><td align=center><small><a href=\"mailto:$email_ne\">$yourname</a></small></td><td><small>$comments</small></td><td align=center><small>$shortdate</small></td><td align=center><small>$hit</small></td><td align=center><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0></small></td></tr></form>\n";
          }
        }
else {
  if ($email_ne eq "") {
      print "<table border=0 bgcolor=000000 width=550 cellpadding=0 cellspacing=0><tr><td>
              <table border=0 width=550 border=0  cellpadding=2 cellspacing=1><tr bgcolor=#c1cdc1 ><td align=center><small>no. $newnum</small></td><td align=center><small><a href=\"$cgi_url/$newname?f_name=$newname&number=$newnum\"><img src=http://www.keti.re.kr/~premech/member/cgi/thesis/down.gif border=0 ></a></small></td><td align=center><small>Å©±â: $bite</a></td><td align=center><small>Àü¼Û: $hit</small></td><td align=center><small>µî·ÏÀÚ: $yourname</a></td><td align=center><small>µî·ÏÀÏ: $shortdate</small></td></tr>
              <tr bgcolor=f0fff0><td height=30 ><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0 ></td><td colspan=5><small><font color=53868b><b> $comments</b></small></td></tr>
               <tr bgcolor=f0fff0 ><td ><small><pre> </pre></td><td colspan=5><small> <br>$content<br><br> </td></tr></table></td></tr></table></form>\n";

      }
 else {

  print "<table border=0 bgcolor=000000 width=550 cellpadding=0 cellspacing=0><tr><td>
             <table border=0 width=550 border=0 cellpadding=2 cellspacing=1><tr bgcolor=#c1cdc1 ><td align=center><small>no. $newnum</small></td><td align=center><small><a href=\"$cgi_url/$newname?f_name=$newname&number=$newnum\"><img src=http://www.keti.re.kr/~premech/member/cgi/thesis/down.gif border=0 ></a></small></td><td align=center><small>Å©±â: $bite</a></td><td align=center><small>Àü¼Û: $hit</small></td><td align=center><small>µî·ÏÀÚ: <a href=\"mailto:$email_ne\">$yourname</a></td><td align=center><small>µî·ÏÀÏ: $shortdate</small></td></tr>
              <tr bgcolor=f0fff0><td height=30><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0 align=right></td><td colspan=5><small><font color=53868b><b>$comments</b></small></td></tr>
               <tr bgcolor=f0fff0 ><td ><small><pre> </pre></td><td colspan=5><small> <br>$content<br><br> </td></tr></table></td></tr></table></form>\n";

    
       }
     
}

   }

exit;


}

#############################
sub Exit_Not_A_Netscape_User {

    print header;
    print start_html('Error!', '#FFFFFF');
    print h1(tt(b('Error! - Invalid Browser'))), br;
    print "ÁË¼ÛÇÕ´Ï´Ù. È­ÀÏ ¿Ã¸®±â´Â Netscape2.0 ÀÌ»ó¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù.<p>Sorry, but you must use Netscape 2.0+ to use this system. ";
    print "<br> Please return to the upload page with a different browser.<p><form> <input type=button value=´Ù½ÃÀÛ¼º(Back) onclick=\"history.go(-1)\"></form>\n";
    print end_html;
    exit 0;

}

########################################
sub Exit_Not_A_Gif {
    #

    print header;
    print start_html('Error!', '#FFFFFF');
    print h1(tt(b('Error! - ÀÌ¹ÌÁö È­ÀÏÀÌ ¾Æ´Õ´Ï´Ù'))), br;
    print "ÁË¼ÛÇÕ´Ï´Ù. È­ÀÏ ¿Ã¸®±â´Â È®ÀåÀÚ°¡ Gif ³ª Jpg ÀÎ ÀÌ¹ÌÁö È­ÀÏ¸¸ ÀÛµ¿ÇÕ´Ï´Ù.<br>È®ÀåÀÚ°¡ <font color=red><b>$name_check[1]</b></font>¿¡¼­´Â ÀÛµ¿ÇÏÁö ¾Ê½À´Ï´Ù<br>ÀÌ¹ÌÁö È­ÀÏÀÇ È®ÀåÀÚ¸¦ Gif ³ª Jpg·Î ¹Ù²Ù½Ê½Ã¿À<p>Sorry, but you must use Image file with Gif or Jpg Exp. <br><font color=red><b>$name_check[1]</b></font> file will not work under any circumstances.";
    print "<br> Please return to the upload page with a Gif or Jpg Image file.<p><form> <input type=button value=´Ù½ÃÀÛ¼º(Back) onclick=\"history.go(-1)\"></form>\n";
    print end_html;
    exit 0;

    #
    #  END OF SUB
    #
}

#######################################
sub Exit_File_Exists {

    print header;
    print start_html('Error!', '#FFFFFF');
    print h1(tt(b('Error! - È­ÀÏ¸í Áßº¹'))), br;
    print "ÁË¼ÛÇÕ´Ï´Ù. È­ÀÏ ÀÌ¸§À» ±â·ÏÇÏÁö ¾Ê¾Ò°Å³ª Áßº¹µÇ¾ú½À´Ï´Ù.<br>Back ¹öÆ°À» ´­·¯ È­ÀÏÀÌ¸§À» ´Ù¸¥ ÀÌ¸§À¸·Î ¿Ã¸®½Ê½Ã¿À.<p>The filename you have selected is";
    print " already in use in the directory file-uploads are allowed.<br>Please use the back button on your browser,";
    print " rename the file, and try again.<p><form> <input type=button value=´Ù½ÃÀÛ¼º(Back) onclick=\"history.go(-1)\"></form>\n";
    print end_html;
    exit 0;

    #
    #  END OF SUB
    #
}

####################################
sub Exit_Size_Error {

    print header;
    print start_html('Error!', '#FFFFFF');
    print h1(tt(b('Error! - Size Error'))), br;
    print "ÁË¼ÛÇÕ´Ï´Ù. È­ÀÏ »çÀÌÁî°¡ 1¹ÙÀÌÆ® ¹Ì¸¸ ÀÌ°Å³ª $max_byte ¹ÙÀÌÆ® ÀÌ»óÀÔ´Ï´Ù.<br>³Ê¹« ÀÛ°Å³ª $max_byte ¹ÙÀÌÆ® ÀÌ»óÀÌ¸é ¿Ã¸± ¼ö ¾øÀ¾´Ï´Ù.<br>";
    print "È­ÀÏ »çÀÌÁî¸¦ ÀÛ°ÔÇÏ¿© ´Ù½Ã ½ÃµµÇÏ½Ê½Ã¿À.<p>Sorry, but it seems that<br> the file you uploaded is less than 1 byte or over $max_byte bytes in size. <br>This means that there was an";
    print " error transfering the file from your computer to the server.  <br>Verify with the server administrator that";
    print " you are allowed to upload files,<br> and verify that the file you are attempting to upload exists on your system.<p><form> <input type=button value=´Ù½ÃÀÛ¼º(Back) onclick=\"history.go(-1)\"></form>\n";
    print end_html;
    exit 0;

    #
    #  END OF SUB
    #
}

###############
sub get_Date {
# Get the Date for Entry
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
   if ($sec < 10)  { $sec = "0$sec";   }
   if ($min < 10)  { $min = "0$min";   }
   if ($hour < 10) { $hour = "0$hour"; }
   if ($mday < 10) { $mday = "0$mday"; }
   if ($mon < 10)  { $mon = "0$mon";  }
   $month = ($mon + 1);
$date = "19$year³â $month¿ù $mdayÀÏ/ $hour½Ã\:$minºÐ\:$secÃÊ"; 
$shortdate = "19$year/$month/$mday";
$datenum = (($month*30)+$mday);
$remove_num = ($datenum-$remove_date);
   
}
#####################
sub get_number {
   open(NUMBER,"$path/$datafile");
   $numm = <NUMBER>;
   close(NUMBER);
   if ($numm == 9999)  {
      $numm = "1";
   }
   else {
      $numm++;
   }
}


sub increment_num {
   open(NUM,">$path/$datafile") || die $!;
   print NUM "$numm";
   close(NUM);
}
###########
sub get_error {

    print header;
    print start_html('Error!', '#FFFFFF');
    print h1(tt(b('Error! - No Name'))), br;
    print "±ÍÇÏÀÇ ÀÌ¸§À» ±â·ÏÇÏ½Ê½Ã¿À !<br>ÀÌ¸§À» ±â·ÏÇÏÁö ¾ÊÀ¸¸é ¿Ã¸± ¼ö ¾ø½À´Ï´Ù.<p>Sorry, If you want upload a file,<br>Go back and  input your name please !";
    print "<form> <input type=button value=´Ù½ÃÀÛ¼º(Back) onclick=\"history.go(-1)\"></form>";
    print " <br>\n";
    print end_html;
    exit 0;

    #
    #  END OF SUB
    #
}

###################################
sub remove_temp {

 opendir(TEMDIR,$temp_dir);
          @entries = readdir(TEMDIR);
 close (TEMDIR);
           foreach (@entries) {
            unlink("$temp_dir/$_");
           }
     }

#########################################
sub remove {

#if ($ENV{'REMOTE_HOST'} ne "$password") {
#         &error_notuser;  
#         exit; }

#  &get_Date;
  if ($passwd eq '') {
               print "Content-type: text/html\n\n";
           print qq!
           <HTML><HEAD><TITLE>ºñ¹Ð¹øÈ£ È®ÀÎ</TITLE></HEAD>
           <BODY BGCOLOR=ffffff>
           <center><h1>ºñ¹Ð¹øÈ£ È®ÀÎ</h1><h4>È­ÀÏÀ» »èÁ¦ÇÏ·Á¸é °ü¸®ÀÚ ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ½Ã¿À</h4>
          <form method=post action=$cgi_url>
          <input type=hidden name=action value=remove>
          <input type=hidden name=number value=$number>
          <input type=password name=passwd size=10>
          <input type=submit value="È­ÀÏ»èÁ¦">
          </form>
          </body></html>
!;
exit;         
    }

   if ($passwd eq $password) {
   open (FILE, "$up_file") || die "Can't Open: $!\n";
   @LINES = <FILE>;
   close (FILE);
   $SIZE=@LINES;
     
    open (NFILE,">$up_file") || die "Can't Open: $!\n";
    for ($i=0;$i<=$SIZE;$i++) {
     $line_=$LINES[$i];
    @data = split(/\|/,$line_);
     if ($data[0] eq $number) {
     unlink ("$path\/$data[2]");
      }
     else {
     print NFILE $line_;
           }
        }

     close (NFILE);
     &Redirect_User;
    }

   else {
   open (FILE, "$up_file") || die "Can't Open: $!\n";
   @LINES = <FILE>;
   close (FILE);
   $SIZE=@LINES;
     
    open (NFILE,">$up_file") || die "Can't Open: $!\n";
    for ($i=0;$i<=$SIZE;$i++) {
     $line_=$LINES[$i];
    @data = split(/\|/,$line_);
     if (($data[0] eq $number) && ($data[1] eq $passwd)){
     unlink ("$path\/$data[2]");
      }
     else {
     print NFILE $line_;
           }
        }

     close (NFILE);
     &Redirect_User;
      
        }
     }
  

###################################
sub hit {
 
   open (FILE, "$up_file");
   @LINES = <FILE>;
   close (FILE);
   $SIZE=@LINES;
     
    open (NFILE,">$up_file");
    for ($i=0;$i<=$SIZE;$i++) {
     $line_=$LINES[$i];
    @data = split(/\|/,$line_);
    if ($data[0] eq $number) {
     $data[8]++;
     print NFILE "$data[0]|$data[1]|$data[2]|$data[3]|$data[4]|$data[5]|$data[6]|$data[7]|$data[8]|$data[9]\n";
      }
     else { 
         print NFILE $line_;  }
        }

        close (NFILE);
      
  }

###################################
sub down {
$f_name = param('f_name');
	print "Content-type: application/binary\n\n";
  open (FILE, "$path/$f_name") ;
  binmode(FILE);
  binmode(STDOUT);
  binmode(STDERR);
  print <FILE>;
  close (FILE);
  exit;
}

###################################
sub search {
   open (FILE, "$up_file");
   @LINES = <FILE>;
   close (FILE);
   $SIZE=@LINES;

   $j = 0;
   for ($i=0;$i<=$SIZE;$i++) {
   $line_=$LINES[$i];
    if ($line_ =~ /$keyword/i) {
   $rem[$j] = $line_;
   $j++;
        }
   }


$totpge = $j/15;
$totpga = int($totpge);
if ($totpge > $totpga) {
$totpg = $totpga+1; }
else {$totpg = $totpga; }

if ($npage ne "") {$page = $npage;}
$nextpg = $page+1;
$prepg = $page-1;
$start = ($page-1)*15+1;
$stop = ($page*15);
if ($stop > $j) {$stop = $j;}

           print "Content-type: text/html\n\n";
           print "<html><head><title>È­ÀÏ ¸®½ºÆ®</title></head>\n";
                    print "<body bgcolor=ffffff><ul><table width=550 border=0><tr><td><img src=$base_url/pds.jpg border=0></td>
                   <td valign=bottom align=right><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=text size=20 name=keyword> <font size=2> <input type=submit value=³í¹®Ã£±â></form></td></tr></table><br>\n";



 if (($page == 1) && ($j <= 15)) {
         print "<td><font size=-1>ÃÑ $j °³ °Ë»ö(1/1)</font></td></tr></table>"; }
if (($page > 1) && ($page eq  $totpg)) { 
         print "<td><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=hidden name=keyword value=$keyword><input type=hidden name=pg value=\"$prepg\"><input type=submit value=\"ÀÌÀüÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÃÑ $j °³ °Ë»ö ($page/$totpg)</font></td></tr></table>";
     }

if (($page ==1) && ($totpg > 1)){ 
         print "<td></td><td></form></td><td><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=hidden name=keyword value=$keyword><input type=hidden name=pg value=\"$nextpg\"><input type=submit value=\"´ÙÀ½ÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÃÑ $j °³ °Ë»ö ($page/$totpg)</font></td></tr></table>";
    }

if (($page >= 2) && ($totpg > $page)){ 
         print "<td><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=hidden name=keyword value=$keyword><input type=hidden name=pg value=\"$prepg\"><input type=submit value=\"ÀÌÀüÆäÀÌÁö\"></td><td></form></td><td><form method=post action=$cgi_url><input type=hidden name=action value=search><input type=hidden name=keyword value=$keyword><input type=hidden name=pg value=\"$nextpg\"><input type=submit value=\"´ÙÀ½ÆäÀÌÁö\"></td><td></form></td><td><font size=-1>ÃÑ $j °³ °Ë»ö ($page/$totpg)</font></td></tr></table>";
    }
         print "<table border=0 width=550>\n";
             
  for ($k=1;$k<=$j;$k++) {
     if (($k >= $start) && ($k <= $stop))  {
     }
  else {next}

   $l = $j-$k; 
   $_=$rem[$l]; 
   ($newnum,$passwd,$newname,$yourname,$email_ne,$comments,$shortdate,$bite,$hit,$content) = split(/\|/, $_);
   
  if ($candown eq '0') {
  if ($email_ne eq "") {
      print "<tr bgcolor=#c1cdc1 ><td align=center><small>$newnum</small></td><td align=center><small>$newname</small></td><td align=center><small>$bite</a></td><td align=center><small>$yourname</a></td><td><small>$comments</small></td><td align=center><small>$shortdate</small></td><td align=center><small>$hit</small></td><td align=center><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0></small></td></tr></form>\n";
      }
  else{
     print "<tr bgcolor=#c1cdc1 ><td align=center><small>$newnum</small></td><td align=center><small>$newname</small></td><td align=center><small>$bite</a></td><td align=center><small><a href=\"mailto:$email_ne\">$yourname</a></small></td><td><small>$comments</small></td><td align=center><small>$shortdate</small></td><td align=center><small>$hit</small></td><td align=center><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0></small></td></tr></form>\n";
          }
        }
else {
  if ($email_ne eq "") {
      print "<table border=0 bgcolor=000000 width=550 cellpadding=0 cellspacing=0><tr><td>
              <table border=0 width=550 border=0  cellpadding=2 cellspacing=1><tr bgcolor=#c1cdc1 ><td align=center><small>no. $newnum</small></td><td align=center><small><a href=\"$cgi_url/$newname?f_name=$newname&number=$newnum\"><img src=http://www.keti.re.kr/~premech/member/cgi/thesis/down.gif border=0 ></a></small></td><td align=center><small>Å©±â: $bite</a></td><td align=center><small>Àü¼Û: $hit</small></td><td align=center><small>µî·ÏÀÚ: $yourname</a></td><td align=center><small>µî·ÏÀÏ: $shortdate</small></td></tr>
              <tr bgcolor=f0fff0><td height=30 ><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0 ></td><td colspan=5><small><font color=53868b><b> $comments</b></small></td></tr>
               <tr bgcolor=f0fff0 ><td ><small><pre> </pre></td><td colspan=5><small> <br>$content<br><br> </td></tr></table></td></tr></table></form>\n";

      }
 else {

  print "<table border=0 bgcolor=000000 width=550 cellpadding=0 cellspacing=0><tr><td>
             <table border=0 width=550 border=0 cellpadding=2 cellspacing=1><tr bgcolor=#c1cdc1 ><td align=center><small>no. $newnum</small></td><td align=center><small><a href=\"$cgi_url/$newname?f_name=$newname&number=$newnum\"><img src=http://www.keti.re.kr/~premech/member/cgi/thesis/down.gif border=0 ></a></small></td><td align=center><small>Å©±â: $bite</a></td><td align=center><small>Àü¼Û: $hit</small></td><td align=center><small>µî·ÏÀÚ: <a href=\"mailto:$email_ne\">$yourname</a></td><td align=center><small>µî·ÏÀÏ: $shortdate</small></td></tr>
              <tr bgcolor=f0fff0><td height=30><small><form method=post action=$cgi_url><input type=hidden name=action value=remove><input type=hidden name=number value=$newnum><input type=image name=submit src=$rem_gif border=0 align=right></td><td colspan=5><small><font color=53868b><b>$comments</b></small></td></tr>
               <tr bgcolor=f0fff0 ><td ><small><pre> </pre></td><td colspan=5><small> <br>$content<br><br> </td></tr></table></td></tr></table></form>\n";

    
       }
     }

   }


exit;
}
# EOF
