<HTML>
<HEAD>
<TITLE>File Upload</TITLE>
</HEAD>
<BODY bgcolor="#99CCCC" background="../graphics/web3.jpg">
<center>
<h2>File Upload</h2>
<p><hr><p>
<font color=red>SECURITY WARNING!</font><br>
DO NOT leave your computer unattended with this page loaded.
<br>Shut down your browser when you are finished this session.
<p><hr><p>

<?
// last updated June 4, 2005

// configure variables for your particular instance of the MVD.
      $docpath = "/usr/local/www/data/mvd.stable/";
      $docpathstring = "/docs ";
      $grafxpath = "/usr/local/www/data/graphics/";
      $grafxpathstring = "/graphics ";
      $adminemail = "admin@global-dialog.org";
      $listfile = $uname.".dat";

// Change anything below this line at your own risk

      $ok = 0;
      $userlevel = 0;      
          
      if($uname != "" && $pword != ""){
        if(file_exists($listfile)){
          $pw = crypt($pword,$pword);
          $ustring = $uname.":".$pw."\n";
          $ulfile = fopen("ul.txt","r");
          
          if(!($ulfile)){
            print("Error: File 'ul.txt' could not be read.");
            exit; 
          }
          while(!feof($ulfile)){
            $uline = fgets($ulfile, 255);
            $userlevel++;
            //print("userlevel: $userlevel"); 
            if($uline == $ustring){
              $ok = 1;
              break; 
            }
          }
          fclose($ulfile); 
            
        }
        else{
          print("Can't find user file. Perhaps wrong username supplied.<p><HR><p>\n");
          exit;
        }
      }
      else{
        print("You need to supply your username and password<p><HR><p>\n");
        exit;
      }

      if(!($ok)){
        print("Invalid username or password<p><HR><p>\n");
        exit;
      }


   //check for file upload
   if(isset($UploadedFile) && $UploadedFile != "")
   {
  
      if($destname != ""){
        $filename = $destname;
      }
      else{
        $filename = $UploadedFile_name;
      }

      if($altpath != ""){ 
        $dest = $altpath.$filename;
      }
      else{
        $dest = $copyto.$filename;
      }

      if(file_exists($dest) && $ok){
        if(isset($overwrite)){
          $ok = $ok;
        }
        else{
        $ok = 0;
        print("A file named $dest already exists.<br>If you still want to upload this file either choose another name in the <i>Rename on U/L</i> field or delete the existing file.<p><HR><p>\n");
        }
      }
     
      if($ok){
      
        if(copy($UploadedFile, $dest )){
          print("<table border=0><td>");
          print("Uploaded file: $UploadedFile_name [$UploadedFile]<br>\n");
          print("Copied to: $dest<BR>\n");
          print("Size: $UploadedFile_size <BR>\n");
          #print("Type: $UploadedFile_type <BR>\n");
          mail($adminemail, "MVD file upload", "$UploadedFile_name [$UploadedFile] copied to $dest by $uname");
          if($copyto == $docpath && $altpath == "" && $nolistupdate != "on"){
            $FILE = fopen($listfile,"a");
            fputs($FILE, "$filename,Uploaded file\n");
            fclose($FILE); 
          }
        }
        else{
          print("$UploadedFile_name [$UploadedFile] could not be copied to $dest<BR>\n");
        }                
        unlink($UploadedFile);
        print("</td></table><p><HR><p>\n");
      }
      else {
        unlink($UploadedFile);
        print("$UploadedFile_name not uploaded<p>Possible reasons include an invalid username/password combo or a non-existent file.<p><HR><p>\n");        
      }
   }

if($ok){
  print ("<table border=2 cellpadding=8 bgcolor=\"#99CCCC\">\n
<td><center><br><b>Name of the local file you would like to upload<br></center></b>\n
<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"upl.php\" METHOD=\"post\">\n
<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"102400\">\n
<center><INPUT NAME=\"UploadedFile\" SIZE=30 TYPE=\"file\"></center><p>\n
Choose a location for this file:<br>\n");
  //print ("Userlevel = $userlevel<br>\n");
  print ("<input type=\"radio\" name=\"copyto\" value=$docpath> 
$docpathstring <font size=1> - Put html files here (will be added to 
your 
private file list)</font><br>\n
<input type=\"radio\" name=\"copyto\" value=$grafxpath CHECKED> $grafxpathstring 
<font size=1> - Put gifs, jpegs and other files here</font><br>\n");
  print ("<p>
<center><INPUT TYPE='text' name='destname' size=30> Rename on 
U/L<br><font size=2> (If you want to change the name it will have on the site)</font><p>\n");

  if($userlevel == 1){
    print("<center><INPUT TYPE='text' name='altpath' size=30> Other Directory<P> \n");
    print("<INPUT TYPE='checkbox' name='overwrite' value='on'> Overwrite if file already exists</center><P>\n");
    print("<INPUT TYPE='checkbox' name='nolistupdate' value='on'> Don't add to private file list</center><P>\n");

  }

  print ("<center><table><td>\n
<INPUT TYPE=TEXT SIZE=23 NAME=\"uname\"> username<br>\n
<INPUT TYPE=password SIZE=23 NAME=\"pword\"> password</td></table>\n
<p>
<INPUT TYPE=\"submit\" VALUE=\"Upload\"></center></FORM></td></table><p>
<hr size=2>\n");

  print("<A HREF=\"mvladmin.cgi?Action=Add/Edit%20Entry&private=true&uname=$uname&pword=$pword#Files\"> [ Private File Form ] </a>\n");

}
?>

<hr>
<br>
</center>
</BODY>
</HTML>
