<?php

include('functions.php');
include('db.inc.php');

if($round) {


	if(!$HTTP_POST_FILES["file_name"]["name"]==""){

		include('iu.inc.php');

		srand((double)microtime()*1000000); 
		$rnd_name=substr(md5(rand(0,32000)),0,12);


		$iu = new SDImageUploading();
		$ret=$iu->doUpload('/var/www/vhosts/konyvel.net/httpdocs/admin/upload/',$HTTP_POST_FILES["file_name"],$rnd_name);	


		if($ret==false){
			print_r($iu->error);
		} else {
			 $foto=$ret;
		}
	} // end foto if



	while (list($key, $val) = each($_POST)) {
		if ($key<>"id" && $key<>"Submit" && $key<>"round"){
			$insert_fields.=$key .", ";

            switch ($key) {
                case 'file_size':
                    $insert_values.= "'". $HTTP_POST_FILES["file_name"]["size"] . "', ";
                    break;
                case 'file_type':
                    $insert_values.= "'". $HTTP_POST_FILES["file_name"]["type"] . "', ";
                    break;
                case 'real_name':
                    $insert_values.= "'". $HTTP_POST_FILES["file_name"]["name"] . "', ";
                    break;
                default:
                    $insert_values.= "'". addslashes($val) . "', ";
                }

		}
	}


    $insert_fields.= 'file_name';
    $insert_values.= "'" . $foto . "'";

//	$insert_fields=substr($insert_fields,0, strlen($insert_fields)-2);
//	$insert_values=substr($insert_values,0, strlen($insert_values)-2);

	$stmt="INSERT INTO kk_upload($insert_fields) VALUES($insert_values)";
	$mydb = new db();
    $result=$mydb->query($stmt);

    
    header("Location:a_upload.php");

} else {

	$title="uj file";

	include('header.inc.php');

	printf("<B>Új file hozzáadása</B>");

	$mydb = new db();

	$link=$mydb->get_link();

	$result=mysql_list_fields("fordit", "kk_upload", $link );

	for($field_index=0; $field_index<mysql_num_fields($result); $field_index++){
		$field_name=mysql_field_name($result, $field_index);
		$data[$field_name]="";
	}


    $data["real_name"]="Automatikus, ne töltsd ki!";
    $data["file_size"]="Automatikus, ne töltsd ki!";
    $data["file_type"]="Automatikus, ne töltsd ki!";
    $data["letoltheto"]=1;
	generate_html_form('upload', $data, $PHP_SELF);

	include('footer.inc.php');

}
?>
