<?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");
	
	$cmdesc=checkvalidstring($_POST['cmdesc']);
	
	

	//$countryname=$_POST['countryname'];
	
	$collegemid=$_POST['collegemid'];

	$campusmid=$_POST['campusmid'];
	
	 $cnmid=$_POST['cnmid'];
	
	
	$losmid=$_POST['losmid'];
	
	
	$cprocessingtime=checkvalidstring($_POST['cprocessingtime']);
	
	
	
	
	$countrymid=str_replace ("'","\'",$_POST['countrymid']);
	//$countrymid=str_replace ('"','\"',$countrymid);
	
	
	$feesin=checkvalidstring($_POST['feesin']);
	
	
	
	$cregifees=checkvalidstring($_POST['cregifees']);
	
	
	$capplicationfee=checkvalidstring($_POST['capplicationfee']);
	
	
	$ctutionfees=checkvalidstring($_POST['ctutionfees']);
	
	
	$cscholorship=checkvalidstring($_POST['cscholorship']);
	
	
	$cgrossfees=checkvalidstring($_POST['cgrossfees']);
	
	
	$cprogramcode=checkvalidstring($_POST['cprogramcode']);
	
	
	$cinternalcode=checkvalidstring($_POST['cinternalcode']);
	
	
	$cprogramcategory=checkvalidstring($_POST['cprogramcategory']);
	
	
	$cprogramlength=checkvalidstring($_POST['cprogramlength']);
	
	
	$cprogramtype=checkvalidstring($_POST['cprogramtype']);
	
	$cprogramavailibilty=checkvalidstring($_POST['cprogramavailibilty']);
	
	
	
	
	
	
	
	$csubmissiondeadline=checkvalidstring($_POST['csubmissiondeadline']);
	
	
	$cprogramdelivery=checkvalidstring($_POST['cprogramdelivery']);
	
	
	$cpercentage=checkvalidstring($_POST['cpercentage']);
	
	
	$cbacklogaccepted=$_POST['cbacklogaccepted'];
	
	
	$cedugapaccepted=$_POST['cedugapaccepted'];
	
	
	$chighlycompetitive=checkvalidstring($_POST['chighlycompetitive']);
	
	
	
	$ctutionfeesin=checkvalidstring($_POST['ctutionfeesin']);
	
	
	$programurl=checkvalidstring($_POST['programurl']);
	
	
	 $costofliving=checkvalidstring($_POST['costofliving']);
	
	
	$cjobprospect=checkvalidstring($_POST['cjobprospect']);
	
	
	$cavgannualsalary=checkvalidstring($_POST['cavgannualsalary']);
	 
	
	$cappurllink=checkvalidstring($_POST['cappurllink']);
	 
	
	$cconditionalacceptence=checkvalidstring($_POST['cconditionalacceptence']);
	
	
	$cprogramlanguage=checkvalidstring($_POST['cprogramlanguage']);
	 
	
	$cregifees1=checkvalidstring($_POST['cregifees1']);
	$programsem=checkvalidstring($_POST['programsem']);
	 
	
	
	$cmpbroucher = "";
	$cobroucher = "";
	if(empty($_FILES['file']['name']) == false  )
	{
		$cmpbroucher = date("YmdHis").$_FILES['file']['name'];
		$path = "docs/";
		move_uploaded_file( $_FILES['file']['tmp_name'], $path ."/". $cmpbroucher );
	
	}
	
	
	
		$eve = "select cprogramcode from res_course_master where cinternalcode='$cinternalcode' ";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "Internal Code Already Inserted";
	header('Location: course.php');
	}
	else
	{	
		
		 $eve1 = "INSERT INTO res_course_master (cnmid,cmdesc,collegemid,levelofstudy, cmpbroucher , feesin,cregifees ,capplicationfee,ctutionfees,cscholorship,cgrossfees,cprogramcode,cprogramcategory,cprogramlength,cprogramtype,csubmissiondeadline,cprogramdelivery,cpercentage,cbacklogaccepted,cedugapaccepted,chighlycompetitive,ctutionfeesin,programurl,countrymid,costofliving,cjobprospect,cavgannualsalary,cappurllink,cconditionalacceptence,cprogramlanguage,campusmid,cprocessingtime,cregifees1,cinternalcode,cprogramavailibilty,programsem) VALUES('$cnmid','$cmdesc','$collegemid','$losmid','$cmpbroucher','$feesin','$cregifees','$capplicationfee','$ctutionfees','$cscholorship','$cgrossfees','$cprogramcode','$cprogramcategory','$cprogramlength','$cprogramtype','$csubmissiondeadline','$cprogramdelivery','$cpercentage','$cbacklogaccepted','$cedugapaccepted','$chighlycompetitive','$ctutionfeesin','$programurl','$countrymid','$costofliving','$cjobprospect','$cavgannualsalary','$cappurllink','$cconditionalacceptence','$cprogramlanguage','$campusmid','$cprocessingtime','$cregifees1','$cinternalcode','$cprogramavailibilty','$programsem')";
		
		
		if($conn->query($eve1) === TRUE)
	{
			$last_id = $conn->insert_id;
		$delete_checkbox_array = $_POST['ctermmonth'];
		$n=0;
			foreach ($delete_checkbox_array as $one_by_one_sid) 
			{
				$ctermmonth=$one_by_one_sid;
					
				$ctermyear=$_POST['ctermyear'][$n];
				$n = $n + 1;
			
				
				if($ctermmonth=='')
				{
				}
				else
				{	
					$eve2="insert into res_courseintaketerm_detail (coursemid,ctermmonth,ctermyear) values($last_id,'$ctermmonth','$ctermyear')";
					$re2 = mysqli_query($conn, $eve2);
				}	
				
			}
			$delete_checkbox_array1 = $_POST['clangeligibility'];
		$m=0;
			foreach ($delete_checkbox_array1 as $one_by_one_sid) 
			{
				$clangeligibility=$one_by_one_sid;
					
				$clangscore=$_POST['clangscore'][$m];
				$clangminscore=$_POST['clangminscore'][$m];
				$m = $m + 1;
			
				
				if($clangeligibility==0)
				{
				}
				else
				{	
					$eve2="insert into res_courselanguage_detail (coursemid,clangeligibility,clangscore,clangminscore,clangtype) values($last_id,'$clangeligibility','$clangscore','$clangminscore','Language')";
					$re2 = mysqli_query($conn, $eve2);
				}	
				
			}
			
			$delete_checkbox_array2 = $_POST['clangeligibility1'];
		$p=0;
			foreach ($delete_checkbox_array2 as $one_by_one_sid) 
			{
				$clangeligibility=$one_by_one_sid;
					
				$clangscore=$_POST['clangscore1'][$p];
				$clangminscore=$_POST['clangminscore1'][$p];
				$m = $m + 1;
			
				
				if($clangeligibility==0)
				{
				}
				else
				{	
					$eve2="insert into res_courselanguage_detail (coursemid,clangeligibility,clangscore,clangminscore,clangtype) values($last_id,'$clangeligibility','$clangscore','$clangminscore','Aptitude')";
					$re2 = mysqli_query($conn, $eve2);
				}	
				
			}
	}
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: course.php');
	}
	
?>