<?php
include('config.php');
include('common.class.php');
include('specific.class.php');

$web = new web();

	
 
if($_POST)
{
	
	extract($_POST);
	if(!$gallery_title)
	{
		$web->alert('Please enter your fan club title',true,true);
	}
	elseif(!$history)
	{
		$web->alert('Please enter your fan\'s club brief history',true,true);
	}
	elseif(!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url))
	{
		$web->alert('Sorry invalid website address. Your website address should have a prefix of www or http:// ',true,true);
	}
	elseif(!$members)
	{
		$web->alert('Please enter your fan club\'s number of members',true,true);
	}
	elseif(!$url)
	{
		$web->alert('Please enter your fan club\'s URL',true,true);
	}
	elseif(!$keywords)
	{
		$web->alert('Please enter search keywords',true,true);
	}
	elseif(!$agree)
	{
		$web->alert('Please read PEP\'S Terms of Use',true,true);
	}
	elseif(!$_FILES[image][name])
	{
		$web->alert('Please select file to upload',true,true);
	}
	elseif(!preg_match('/(jpg|gif|jpeg|pjpg|flv|wmv|mp4|mpg)$/i',$_FILES[image][name]) and $_FILES[image][name])
		$web->alert("Invalid file type! ",true,true);
	elseif ($_FILES[image][type] != "image/jpeg" and $_FILES[image][type] != "image/gif" and $_FILES[image][type] != "image/pjpeg")
	{
		$web->alert("Invalid file type! ",true,true);
	}
	else
	{
		
		$username = $author_;
		$_POST[author] = $username;
		if(!file_exists('media/'.$username.'/'))
		{
			mkdir('media/'.$username.'/',0777);
			mkdir('media/thumbs/'.$username.'/',0777);
		}
		$destination = "media/".$username."/";
		$destination2 = "media/original_videos/";
		$destination_thumb = "media/thumbs/".$username."/";
		$_POST['destination'] = $username."/";
		$_POST['destination2'] = $username."/";
		
		if ($_FILES[image][type] == "image/gif") $short_type = ".gif";
		elseif ($_FILES[image][type] == "image/jpeg") $short_type = ".jpg";
		elseif ($_FILES[image][type] == "image/pjpeg") $short_type = ".jpg";
		
		$filename = 'peparazzi_'.substr(md5(uniqid(rand(),1)),0,12);
		$filename.=$short_type;
		
		$_POST['filename'] = $filename;
		copy($_FILES[image][tmp_name], $destination.$filename);
		$x = 105; $y = 75;
		$src = $username . '/' . $filename;
		$dest = $username . '/' . $filename;
		include('thumb.php');
		//$web->debug($_FILES);
		$web->connect_rw();
		$gid=$web->saveFanClub($_POST,$_FILES,$destination,$filename);
		
		if($gid)
			header("Location: " . DOCUMENT_ROOT . "update_fanclub.php?id=$gid");					// Redirect to notification
	}
}

$smarty->assign('page_name','peparazzi_default');
$smarty->display('writefanclub.html');
?>
