<?php
	//require_once('../system/Physis.php');

	require_once('Database.php');
	
	require_once('Ultraviolet.php');
	
	require_once('AdminFunctions.php');

	$database =& DatabaseConnect::getInstance();

	$database->query("SET CHARACTER SET utf8");
	
	
	require_once('FileUpload.php');

	require_once('SimpleImage.php');
	
	if($_FILES['directorbio']['name'] != ''):



	$file = new uploader('en');

					$file->max_filesize(return_bytes(ini_get('post_max_size')));



					$acceptable_file_types = "";

					$default_extension = "";

					$mode = 2;

					$file_name = 'directorbio';

					$path = '../docs';



					if($file->upload($file_name, $acceptable_file_types, $default_extension)):

						$file->save_file($path, $mode);

					endif;



					if($file->error):

						$file_content = $file->error;

						$fh = fopen('error.txt', 'w');

						fwrite($fh, $file_content);

						fclose($fh);

					else:

						chmod($path.'/'.$file->file['name'], 0777);		
						
						endif;
						
						$directorbio_filename = $file->file['name'];
						
						endif;
	
	
	if($_FILES['directorphoto']['name'] != ''):
$file = new uploader('en');

					$file->max_filesize(return_bytes(ini_get('post_max_size')));



					$acceptable_file_types = "";

					$default_extension = "";

					$mode = 2;

					$file_name = 'directorphoto';

					$path = '../docs';



					if($file->upload($file_name, $acceptable_file_types, $default_extension)):

						$file->save_file($path, $mode);

					endif;



					if($file->error):

						$file_content = $file->error;

						$fh = fopen('error.txt', 'w');

						fwrite($fh, $file_content);

						fclose($fh);

					else:

						chmod($path.'/'.$file->file['name'], 0777);		
						
						endif;
						
						$directorphoto_filename = $file->file['name'];
						
						endif;
	if($_FILES['sinopsis']['name'] != ''):
$file = new uploader('en');

					$file->max_filesize(return_bytes(ini_get('post_max_size')));



					$acceptable_file_types = "";

					$default_extension = "";

					$mode = 2;

					$file_name = 'sinopsis';

					$path = '../docs';



					if($file->upload($file_name, $acceptable_file_types, $default_extension)):

						$file->save_file($path, $mode);

					endif;



					if($file->error):

						$file_content = $file->error;

						$fh = fopen('error.txt', 'w');

						fwrite($fh, $file_content);

						fclose($fh);

					else:

						chmod($path.'/'.$file->file['name'], 0777);		
						
						endif;
						
						$sinopsis_filename = $file->file['name'];
						
						endif;
	if($_FILES['directorstat']['name'] != ''):
$file = new uploader('en');

					$file->max_filesize(return_bytes(ini_get('post_max_size')));



					$acceptable_file_types = "";

					$default_extension = "";

					$mode = 2;

					$file_name = 'directorstat';

					$path = '../docs';



					if($file->upload($file_name, $acceptable_file_types, $default_extension)):

						$file->save_file($path, $mode);

					endif;



					if($file->error):

						$file_content = $file->error;

						$fh = fopen('error.txt', 'w');

						fwrite($fh, $file_content);

						fclose($fh);

					else:

						chmod($path.'/'.$file->file['name'], 0777);		
						
						endif;
						
						$directorstat_filename = $file->file['name'];
						
						endif;
	

	$originaltitle = $_POST["original_title"];
	$englishtitle = $_POST["english_title"];
	$country = $_POST["country"];
	$year = $_POST["year"];
	$production = $_POST["production"];
	$director = $_POST["director"];
	$duration = $_POST["duration"];
	$language = $_POST["language"];
	$subtitle = $_POST["subtitle"];
	$source = $_POST["source"];
	$format = $_POST["format"];
	$demo = $_POST["demo"];
	$dialogue = $_POST["dialogue"];
	$presskit = $_POST["presskit"];
	$poster = $_POST["poster"];
	$agreement = $_POST["agreement"];
	$awards = $_POST["awards"];
	$youtube = $_POST["youtube"];
	
	
	

	
	$database->query("INSERT INTO beldocs_raw(originaltitle, englishtitle, country, year, production, director, duration, language, subtitle, source, format, demo, dialogue, presskit, poster, agreement, directorbio_filename, directorphoto_filename, sinopsis_filename, directorstat_filename, awards, youtube) VALUES('$originaltitle', '$englishtitle', '$country', '$year', '$production', '$director', '$duration', '$language', '$subtitle', '$source', '$format', '$demo', '$dialogue', '$presskit', '$poster', '$agreement', '$directorbio_filename', '$directorphoto_filename', '$sinopsis_filename', '$directorstat_filename', '$awards', '$youtube')");
	

	# -=-=-=- MIME BOUNDARY

	$mime_boundary = "ENTRY FORM".md5(time());
	
	# -=-=-=- MAIL HEADERS
	
	$to = "office@beldocs.rs";
	

	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
	$subject = "BELDOCS entry form";
	# -=-=-=- HTML EMAIL PART
	 
	$mailmessage .= "--$mime_boundary\n";
	$mailmessage .= "Content-Type: text/html; charset=utf-8\n";
	$mailmessage .= "Content-Transfer-Encoding: 8bit\n\n";
	$mailmessage .= "<html>\n";
	$mailmessage .= "<body style=\"font-family:Trebuchet MS, sans-serif; font-size:12px; color:#000;\">\n";
	$mailmessage .= "New entry form:<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Original title</b><br/>\n";
	$mailmessage .= "$originaltitle<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>English title</b><br/>\n";
	$mailmessage .= "$englishtitle<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Country of origin </b><br/>\n";
	$mailmessage .= "$country<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>The year of production</b><br/>\n";
	$mailmessage .= "$year<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>The name of the production company</b><br/>\n";
	$mailmessage .= "$production<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>The name of the director(s)</b><br/>\n";
	$mailmessage .= "$director<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Awards</b><br/>\n";
	$mailmessage .= "$awards<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Duration time </b><br/>\n";
	$mailmessage .= "$duration<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Original language</b><br/>\n";
	$mailmessage .= "$language<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Subtitles in English or/and any other (yes/no)</b><br/>\n";
	$mailmessage .= "$subtitle<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>DVD, Beta, HD cam, DV cam, 35mm, other, color / black & white</b><br/>\n";
	$mailmessage .= "$source<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Format (4:3, 16:9) </b><br/>\n";
	$mailmessage .= "$format<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Demo (yes/no)</b><br/>\n";
	$mailmessage .= "$demo<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Demo youtube link</b><br/>\n";
	$mailmessage .= "$youtube<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Dialogue list (yes/no)</b><br/>\n";
	$mailmessage .= "$dialogue<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Press kit and few photos (yes/no)</b><br/>\n";
	$mailmessage .= "$presskit<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Director's biography filename</b><br/>\n";
	$mailmessage .= "$directorbio_filename<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Director photo filename</b><br/>\n";
	$mailmessage .= "$directorphoto_filename<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Sinopsis filename</b><br/>\n";
	$mailmessage .= "$sinopsis_filename<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Director's statment filename</b><br/>\n";
	$mailmessage .= "$directorstat_filename<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Film poster (yes/no)</b><br/>\n";
	$mailmessage .= "$poster<br/>\n";
	$mailmessage .= "<br/>\n";
	$mailmessage .= "<b>Agree to terms?</b> <br/>\n";
	$mailmessage .= "$agreement<br/>\n";
	$mailmessage .= "<br/>\n";
	
	if(mail($to, $subject, $mailmessage, $headers))
		header('location:../entry.php?mail=sent');

	else
		header('location:../entry.php?mail=error');


	
	// Functions *************************************************************************************************

	function return_bytes($val){

	    $val = trim($val);

	    $last = strtolower($val{strlen($val)-1});

	    switch($last) {

	        // The 'G' modifier is available since PHP 5.1.0

	        case 'g':

	            $val *= 1024;

	        case 'm':

	            $val *= 1024;

	        case 'k':

	            $val *= 1024;

	    }



	    return $val;

	}

	// **********************************************************************************************************

	
	


?>