<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#----------------------------------------------------------------------
	# $Id: postattach.php3,v 1.8 2000/12/14 19:13:54 shevett Exp $
	#----------------------------------------------------------------------
	
	#----------------------------------------------------------------------
	#		Post an uploaded attachment.
	#----------------------------------------------------------------------

	if (! is_dir("$sys_attachdir")) {
		report_error("postattach.php3","100","Cannot save file to directory '$sys_attachdir'.");
	} else {
		LogIt("DEBUG","postattach.php3", "$userfile"); /* $userfile - The temporary filename in which the uploaded file was stored on the server machine. */
		LogIt("DEBUG","postattach.php3", "$userfile_name"); /* The original name of the file on the sender's system. */
		LogIt("DEBUG","postattach.php3", "$userfile_size"); /* The size of the uploaded file in bytes.  */
		LogIt("DEBUG","postattach.php3", "$userfile_type"); /* The mime type of the file if the browser provided this information. */
		LogIt("DEBUG","postattach.php3", "Will move to $sys_attachdir");
		# Make sure we're trailing a /
		if (! ereg('/$',$dir)) {
			$sys_attachdir="$sys_attachdir" . "/";
			LogIt("DEBUG","postattach.php3", "Will move to $sys_attachdir");
		}
		# Copy the file out of the temp dir into the attachments dir
		$newfile = "$a_sid" . md5("$a_title") . ereg_replace('.*\.', ".", $userfile_name);

		LogIt("DEBUG","postattach.php3", "New filename is $newfile.");
		if (! copy("$userfile","$sys_attachdir" . "$newfile")) {
			report_error("postattach.php3","100","Error moving file into attachments directory : " . $php_errormsg);
		} else {
			# successful copy!  Delete the temp file...
			unlink("$userfile");
			# make an entry in the library for this file
			$clist = "li_fname, li_fsize, li_update, li_uptech, li_title, li_descrip, li_public, li_oname";
			$vlist = "'$newfile',$userfile_size,".time().",'$a_tech','$a_title','$a_descrip', $a_public, '$userfile_name'";
			$lq = db_query("insert into library ($clist) values ($vlist)");

			# now update the attachments listing
			$clist = "at_sid,at_fname,at_tech,at_date";
			$vlist = "$a_sid,'$newfile','$curruser',".time();
			LogIt("DEBUG","postattach.php3", "clist is $clist <br>");
			LogIt("DEBUG","postattach.php3", "vlist is $vlist <br>");
			$aq = db_query("insert into attachments ($clist) values ($vlist)");

			# done!
		}
	} 
		

?>
	
