<?php

require_once("db.php");

//$link = mysqli_connect('localhost', 'ivtr_sudam', 'cidb@2018#', 'ivtr_cid');

if(isset($_POST['submit']))
{
	
    $last_name=$_POST['last_name'];
    $first_name=$_POST['first_name'];
    $middle_name=$_POST['middle_name'];
	$gender=$_POST['gender'];
	$bgroup=$_POST['bgroup'];
	$dob=$_POST['dob'];
	$lngkwn=$_POST['lngkwn'];
	$mobile=$_POST['mobile'];
	$mobile2=$_POST['mobile2'];
	$email=$_POST['email'];
	$email2=$_POST['email2'];
	$edu=$_POST['edu'];
	$profn=$_POST['profn'];
	$aadharn=$_POST['aadharn'];
	$pann=$_POST['pann'];
	$address1=$_POST['address1'];
	$address2=$_POST['address2'];
	$dist=$_POST['dist'];
	$state=$_POST['state'];
	$npstn=$_POST['npstn'];
	$activity=$_POST['activity'];
	$language=$_POST['language'];
	$category=$_POST['category'];
	$donation=$_POST['donation'];
	$pay_method=$_POST['pay_method'];
	$trdate=$_POST['trdate'];
	$bank=$_POST['bank'];
	$bankcity=$_POST['bankcity'];
	$ref1name=$_POST['ref1name'];
	$ref1add=$_POST['ref1add'];
	$ref1rel=$_POST['ref1rel'];
	$ref1con=$_POST['ref1con'];
	$ref1desi=$_POST['ref1desi'];


//	$no_rows = count($sxe);
//	$tid = $no_rows+1;



			$today=getdate();
			$pid=$today['mday']."".$today['mon']."".$today['year']."".$today['hours']."".$today['minutes']."".$today['seconds'];
			
			$vid='CR'.$pid;

$allowedExts = array("pdf", "jpg", "jpeg", "png");
	// PHOTO	
				
				$temp1 = explode(".", $_FILES["photo"]["name"]);
				$extension1 = end($temp1);
				
				if (($_FILES["photo"]["type"] == "application/pdf")
				|| ($_FILES["photo"]["type"] == "image/jpg")
				|| ($_FILES["photo"]["type"] == "image/jpeg")
				|| ($_FILES["photo"]["type"] == "image/png")
				&& ($_FILES["photo"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["photo"]["error"] > 0) {
					echo "Return Code: " . $_FILES["photo"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['photo']['name'];
					$tmpName  = $_FILES['photo']['tmp_name'];
					$fileSize = $_FILES['photo']['size'];
					$fileType = $_FILES['photo']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."photo.".$extension1; 
					}
					move_uploaded_file($_FILES["photo"]["tmp_name"],"reporters/" . $fileName);
			
					}
					} 
					$fpp1="reporters/".$vid."photo.".$extension1;
//  PHOTO END

	// SIGN
				$temp1 = explode(".", $_FILES["sign"]["name"]);
				$extension1 = end($temp1);

				if (($_FILES["sign"]["type"] == "application/pdf")
				|| ($_FILES["sign"]["type"] == "image/jpg")
				|| ($_FILES["sign"]["type"] == "image/jpeg")
				|| ($_FILES["sign"]["type"] == "image/png")
				&& ($_FILES["sign"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["sign"]["error"] > 0) {
					echo "Return Code: " . $_FILES["sign"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['sign']['name'];
					$tmpName  = $_FILES['sign']['tmp_name'];
					$fileSize = $_FILES['sign']['size'];
					$fileType = $_FILES['sign']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."sign.".$extension1; 
					}
					move_uploaded_file($_FILES["sign"]["tmp_name"],"reporters/" . $fileName);
			
					}
					} 
					$fpp2="reporters/".$vid."sign.".$extension1;	
	// SIGN END

	
	//AADHAR
	$temp1 = explode(".", $_FILES["aadhar"]["name"]);
				$extension1 = end($temp1);

				if (($_FILES["aadhar"]["type"] == "application/pdf")
				|| ($_FILES["aadhar"]["type"] == "image/jpg")
				|| ($_FILES["aadhar"]["type"] == "image/jpeg")
				|| ($_FILES["aadhar"]["type"] == "image/png")
				&& ($_FILES["aadhar"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["aadhar"]["error"] > 0) {
					echo "Return Code: " . $_FILES["aadhar"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['aadhar']['name'];
					$tmpName  = $_FILES['aadhar']['tmp_name'];
					$fileSize = $_FILES['aadhar']['size'];
					$fileType = $_FILES['aadhar']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."aadhar.".$extension1; 
					}
					move_uploaded_file($_FILES["aadhar"]["tmp_name"],"reporters/" . $fileName);
			
					}
					} 
					$fpp3="reporters/".$vid."aadhar.".$extension1;
	//AADHAR END

	
	//PAN
	$temp1 = explode(".", $_FILES["pan"]["name"]);
				$extension1 = end($temp1);

				if (($_FILES["pan"]["type"] == "application/pdf")
				|| ($_FILES["pan"]["type"] == "image/jpg")
				|| ($_FILES["pan"]["type"] == "image/jpeg")
				|| ($_FILES["pan"]["type"] == "image/png")
				&& ($_FILES["pan"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["pan"]["error"] > 0) {
					echo "Return Code: " . $_FILES["pan"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['pan']['name'];
					$tmpName  = $_FILES['pan']['tmp_name'];
					$fileSize = $_FILES['pan']['size'];
					$fileType = $_FILES['pan']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."pan.".$extension1; 
					}
					move_uploaded_file($_FILES["pan"]["tmp_name"],"reporters/".$fileName);
			
					}
					} 
					$fpp4="reporters/".$vid."pan.".$extension1;
	//PAN
	
	
	//AFFEDAVIT
					
$temp1 = explode(".", $_FILES["affidevit"]["name"]);
				$extension1 = end($temp1);

				if (($_FILES["affidevit"]["type"] == "application/pdf")
				|| ($_FILES["affidevit"]["type"] == "image/jpg")
				|| ($_FILES["affidevit"]["type"] == "image/jpeg")
				|| ($_FILES["affidevit"]["type"] == "image/png")
				&& ($_FILES["affidevit"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["affidevit"]["error"] > 0) {
					echo "Return Code: " . $_FILES["affidevit"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['affidevit']['name'];
					$tmpName  = $_FILES['affidevit']['tmp_name'];
					$fileSize = $_FILES['affidevit']['size'];
					$fileType = $_FILES['affidevit']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."affidevit.".$extension1; 
					}
					move_uploaded_file($_FILES["affidevit"]["tmp_name"],"reporters/" . $fileName);
			
					}
					} 
					$fpp5="reporters/".$vid."affidevit.".$extension1;
	//END AFFEDAVIT
	
		//BANK SLIP
					
$temp1 = explode(".", $_FILES["bankslip"]["name"]);
				$extension1 = end($temp1);

				if (($_FILES["bankslip"]["type"] == "application/pdf")
				|| ($_FILES["bankslip"]["type"] == "image/jpg")
				|| ($_FILES["bankslip"]["type"] == "image/jpeg")
				|| ($_FILES["bankslip"]["type"] == "image/png")
				&& ($_FILES["bankslip"]["size"] < 200000)
				&& in_array($extension1, $allowedExts)) {
				if ($_FILES["bankslip"]["error"] > 0) {
					echo "Return Code: " . $_FILES["bankslip"]["error"] . "<br>";
				  } else {
					$fileName = $_FILES['bankslip']['name'];
					$tmpName  = $_FILES['bankslip']['tmp_name'];
					$fileSize = $_FILES['bankslip']['size'];
					$fileType = $_FILES['bankslip']['type'];
					$fp      = fopen($tmpName, 'r');
					$content = fread($fp, filesize($tmpName));
					$content = addslashes($content);
					fclose($fp);

					if(!get_magic_quotes_gpc()) {
						$fileName = $vid."bankslip.".$extension1; 
					}
					move_uploaded_file($_FILES["bankslip"]["tmp_name"],"reporters/" . $fileName);

					}
					} 
					$fpp6="reporters/".$vid."bankslip.".$extension1;
		//END BANK SLIP
	
	//	print_r($last_name); exit;	
			$sql="INSERT INTO `cr_members` (`vid`,`last_name`,`first_name`,`middle_name`,`gender`,`bgroup`,`dob`,`lngkwn`,`mobile`,`mobile2`,`email`,`email2`,`edu`,`profn`,`aadharn`,
			`pann`,`address1`,`address2`,`dist`,`state`,`npstn`,`activity`,`language`,`category`,`donation`,`pay_method`,`trdate`,`bank`,`bankcity`,
			`ref1name`,`ref1add`,`ref1rel`,`ref1con`,`ref1desi`,
			`photo`,`sign`,`aadhar`,`pan`,`affidevit`,`bankslip`)
			VALUES ('$vid','$last_name','$first_name','$middle_name','$gender','$bgroup','$dob','$lngkwn','$mobile','$mobile2','$email','$email2','$edu','$profn','$aadharn','$pann','$address1','$address2','$dist','$state','$npstn','$activity','$language','$category',
			'$donation','$pay_method','$trdate','$bank','$bankcity',
			'$ref1name','$ref1add','$ref1rel','$ref1con','$ref1desi',
			'$fpp1','$fpp2','$fpp3','$fpp4','$fpp5','$fpp6');"; 
//			 echo $sql; exit;
				mysqli_query($link,$sql);
		        mysqli_close($link);

	header('Location:../j_success.php');
		
}

else{	
			echo"ERROR!";
		}

?>