<?php
 	session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
include("mylibrary.php");
	
	//$cmname=$_POST['cmname'];
	$cmname= checkvalidstring($_POST['cmname']);
	
	
	
	$collegecode=checkvalidstring ($_POST['collegecode']);
	
	
	$collegetypemid=$_POST['collegetypemid'];
	$ctotalcampus=checkvalidstring($_POST['ctotalcampus']);
	$ctotalprograms=$_POST['ctotalprograms'];
	$ctotalstudents=$_POST['ctotalstudents'];
	$ctotalinternationstudent=$_POST['ctotalinternationstudent'];
	$ccurrency=checkvalidstring($_POST['ccurrency']);
	$cyearoffoundation=$_POST['cyearoffoundation'];
	$cdlinumber=checkvalidstring($_POST['cdlinumber']);
	$cwebsite=checkvalidstring($_POST['cwebsite']);
	$capplicationurl=checkvalidstring($_POST['capplicationurl']);
	$cvideoprofile=checkvalidstring($_POST['cvideoprofile']);
	$cranking=checkvalidstring($_POST['cranking']);
	$capplyvia=checkvalidstring($_POST['capplyvia']);
	 $indirecttieupcmpmid =$_POST['indirecttieupcmpmid'];
	
	
	
	$csectiondesc=checkvalidstring($_POST['csectiondesc']);
	
	
	$contactname=checkvalidstring($_POST['contactname']);
	
	
	$cmiddlename=checkvalidstring($_POST['cmiddlename']);
	
	
	$csurname=checkvalidstring($_POST['csurname']);
	
		$contactnumber=checkvalidstring($_POST['contactnumber']);
	
	$mobilecode=$_POST['mobilecode'];
	$contactnumber=$mobilecode."".$contactnumber;
	$cmobilenumber=checkvalidstring($_POST['cmobilenumber']);
	
	$homemobilecode=$_POST['homemobilecode'];
	$cmobilenumber=$homemobilecode."".$cmobilenumber;
	$contactemail=checkvalidstring($_POST['contactemail']);
	
	$caltenateemail=checkvalidstring($_POST['caltenateemail']);
	
	$contactdepartmnet='Head';
	
	$cposition='Head';
	
	//$cremarks=checkvalidstring($_POST['cremarks']);
	
	
	$caddress1=checkvalidstring($_POST['caddress1']);

	
	$caddress2=checkvalidstring($_POST['caddress2']);
	
	
	$ccountry=checkvalidstring($_POST['ccountry']);
	
	$cpostalcode=checkvalidstring($_POST['cpostalcode']);
	
	
	$cmsgappname=checkvalidstring($_POST['cmsgappname']);
	
	
	$csubcategory='Direct';
	
	
	$cmsgappid=$_POST['cmsgappid'];
	
	
	$cvideoappname=checkvalidstring($_POST['cvideoappname']);
	
	
	$cvideoappid=$_POST['cvideoappid'];
	
	
	
	
	$cstate=$_POST['cstate'];
	
	
	$cfaxnumber=checkvalidstring($_POST['cfaxnumber']);
	
	
	$cbankname=checkvalidstring($_POST['cbankname']);
	
	
	$cbankbranch=checkvalidstring($_POST['cbankbranch']);
	
	
	$caccountname=checkvalidstring($_POST['caccountname']);
	
	
	$cifsccode=checkvalidstring($_POST['cifsccode']);
	
	
	$cmicrcode=checkvalidstring($_POST['cmicrcode']);
	
	
	$cbankdetails=checkvalidstring($_POST['cbankdetails']);
	
	
	$caccountnumber=checkvalidstring($_POST['caccountnumber']);
	
	
	$ctotaldomesticstudents=checkvalidstring($_POST['ctotaldomesticstudents']);
	;
	
	$ccity=$_POST['ccity'];
	
	
	
	
	 $eve = "select collegecode from res_college_master where collegecode='$collegecode'";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "college code Already Inserted.";
		header('Location: college.php');
	}
	else
	{	
	
		 $eve2 = "INSERT INTO res_college_master (cmname,collegecode,ctotalcampus,collegetypemid,ctotalprograms,ctotalinternationstudent,csectiondesc,cbankname,cbankbranch,caccountnumber,caccountname,cifsccode,cmicrcode,cbankdetails,cfaxnumber,ctotalstudents,countrymid,ctotaldomesticstudents,ccurrency,cdlinumber,cwebsite,capplicationurl,cvideoprofile,cranking,capplyvia,indirecttieupcmpmid,cyearoffoundation) VALUES('$cmname','$collegecode','$ctotalcampus','$collegetypemid','$ctotalprograms','$ctotalinternationstudent','$csectiondesc','$cbankname','$cbankbranch','$caccountnumber','$caccountname','$cifsccode','$cmicrcode','$cbankdetails','$cfaxnumber','$ctotalstudents','$ccountry','$ctotaldomesticstudents','$ccurrency','$cdlinumber','$cwebsite','$capplicationurl','$cvideoprofile','$cranking','$capplyvia','$indirecttieupcmpmid','$cyearoffoundation')";
		if ($conn->query($eve2) === TRUE)

	{	
	$last_id = $conn->insert_id;
		 $eve1 = "INSERT INTO res_contact_master (contactname, contactemail,contactnumber,cmobilenumber,contactdepartmnet,cposition,caltenateemail,caddress1,caddress2,ccountry,cstate,ccity,cpostalcode,cmiddlename,csurname,cmsgappname,cmsgappid,cvideoappname,cvideoappid,ccompanyname,csubcategory,clinktype,clinkid) VALUES('$contactname','$contactemail','$contactnumber','$cmobilenumber','$contactdepartmnet','$cposition','$caltenateemail','$caddress1','$caddress2','$ccountry','$cstate','$ccity','$cpostalcode','$cmiddlename','$csurname','$cmsgappname','$cmsgappid','$cvideoappname','$cvideoappid','$cmname','$csubcategory','College','$last_id')";
		
		$re1 = mysqli_query($conn, $eve1);
		
		 $delete_checkbox_array = $_POST['cdocstype'];
		$n=0;
			foreach ($delete_checkbox_array as $one_by_one_sid) 
			{
				$cdocsname="";
	 if(empty($_FILES['cdocsname']['name'][$n]) == false  )
	 {
		 
		  // Get Image Dimension
		$fileinfo = @getimagesize($_FILES['cdocsname']['tmp_name'][$n]);
		$width = $fileinfo[0];
		$height = $fileinfo[1];
	
		$simplephoto11=$_FILES['cdocsname']['name'][$n];
		 $ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
		
		$fileexplode1 = explode(".",$simplephoto11);
		$fileend1 = end($fileexplode1);

		$cdocsname= date("YmdHis").rand(100,999).".".$fileend1;
		$cdocsname= checkvalidstring($cdocsname);
		$path = "images";
		
		  move_uploaded_file( $_FILES['cdocsname']['tmp_name'][$n], $path ."/". $cdocsname);
		  $flag=1;
		  
		  
				$n = $n + 1;
		  
		  $eve2="insert into res_collegedocs_detail (collegemid,cdocstype,cdocsname) values($last_id,'$one_by_one_sid','$cdocsname')";
					$re2 = mysqli_query($conn, $eve2);
		
		
	}
					
				
			}
			
		$_SESSION['msg'] = "Record Saved successfully";
	}else{
		$_SESSION['msg1'] = "Error";
	}
	}
		header('Location: college.php');
			
	
?>