<?php

//echo $_GET['id'];
//exit;
require_once("../common/connect.php");

$contents="<b>S.No</b>, SID, Enrollment No, Student Name, Fathers Name, Mothers Name, Course, Course Type, Contact No, Email Id, Semester, Category, Religion, DOB, Gender, State, Nationality, Enrollment Date, Address, Parent Mobile No, Parent Email Id, City, State, District, Pincode, Country, Father Occupation, Father Annual Income, Mother Name, Mother Occupation, Mother Annual Income\n";

//Mysql query to get records from datanbase
//You can customize the query to filter from particular date and month etc...Which will depends your database structure.
$user_query= mysql_query("SELECT * FROM `student_registration` WHERE `step` = '11' AND  `sesion` ='$_GET[id]' ORDER BY `student_registration`.`student_name` ASC");
//mysql_num_rows($user_query);


$count=0;


//While loop to fetch the records
while($row = mysql_fetch_assoc($user_query))
{
	
		$GetContactDetails=mysql_query("SELECT * FROM  `step1_contact` WHERE  `sid` ='$row[sid]'");
		$GetContactDetails1=mysql_fetch_assoc($GetContactDetails);

	
		$GetCityName=mysql_query("SELECT * FROM  `city` WHERE  `city_id` ='$GetContactDetails1[city]'");
		$GetCityName1=mysql_fetch_assoc($GetCityName);
	
		$GetPersonal=mysql_query("SELECT * FROM `step1_perosonal` WHERE `sid` = '$row[sid]'");
		$GetPersonal1=mysql_fetch_assoc($GetPersonal);

		

$GetChkenroll=mysql_query("SELECT * FROM  `old_student_enrollment` WHERE  `sid` ='$row[sid]'");
$GetChkenroll1=mysql_num_rows($GetChkenroll);
$GetChkenroll2=mysql_fetch_assoc($GetChkenroll);
if($GetChkenroll1 > 0)
{
	$enroll=$GetChkenroll2['enrollment'];
}
else
{

 $GetEnroll=mysql_query("SELECT * FROM `sgvu_enrollment` WHERE `sid` ='$row[sid]'");
$GetEnroll1=mysql_fetch_assoc($GetEnroll);
$enroll=$GetEnroll1['enrollment_no'];
}



 //= $GetEnroll1['enrollment_no'];

$GetCourse=mysql_query("SELECT * FROM  `sgvu_courses` WHERE  `course_id` ='$GetPersonal1[program]'");
$GetCourse1=mysql_fetch_assoc($GetCourse);

$GetCourseType=mysql_query("SELECT * FROM  `sgvu_coursetype` WHERE  `id` ='$GetCourse1[course_type]'");
$GetCourseType1=mysql_fetch_assoc($GetCourseType);



		
$GetSem=mysql_query("SELECT * FROM  `sgvu_stu_sem_allocate` WHERE  `sid` ='$row[sid]'");
$GetSem1=mysql_fetch_assoc($GetSem);

		
if(is_numeric($GetContactDetails1['state']))
{
$GetState=mysql_query("SELECT * FROM  `state` WHERE  `ids` ='$GetContactDetails1[state]'");
$GetState1=mysql_fetch_assoc($GetState);
	
$state=$GetState1['state'];	
$Nationality='Indian';
}
else
{
$state='NA';	
$Nationality=str_replace(",", " ", $GetContactDetails1['state']);
}

$GetCat=mysql_query("SELECT * FROM  `category` WHERE  `id` ='$GetPersonal1[cat]'");
$GetCat1=mysql_fetch_assoc($GetCat);

$GetReligion=mysql_query("SELECT * FROM  `religion` WHERE  `id` ='$GetPersonal1[religion]'");
$GetReligion1=mysql_fetch_assoc($GetReligion);


$count+=1;
$t=$row['time'];

$dob=strtotime($GetPersonal1['dob']);
$dob1=date('d M Y', $dob);

$add1=str_replace(",", " ", $GetContactDetails1['add1']);
$add2=str_replace(",", " ", $GetContactDetails1['add2']);
$add3=$add1.$add2;

$contents.=$count.",";
$contents.=$row['sid'].",";
$contents.=$enroll.",";
$contents.=$GetPersonal1['firstname'].' '.$GetPersonal1['middlename'].' '.$GetPersonal1['lastname'].",";
$contents.=$GetPersonal1['father_name'].",";
$contents.=$GetPersonal1['mother_name'].",";
$contents.=$GetCourse1['coursename'].",";
$contents.=$GetCourseType1['coursetype'].","; // Course Type
$contents.=$row['mobile'].",";
$contents.=$row['email'].",";
$contents.=$GetSem1['sem'].",";
$contents.=$GetCat1['category'].",";
$contents.=$GetReligion1['religion'].",";
$contents.=$dob1.",";
$contents.=$GetPersonal1['sex'].",";
$contents.=$state.",";
$contents.=$Nationality.",";
$contents.=$GetEnroll1['date'].",";


$contents.=$add1.",";
$contents.=$GetContactDetails1['parent_mobile'].",";
$contents.=$GetContactDetails1['parent_email'].",";
$contents.=$GetContactDetails1['city1'].",";
$contents.=$state.",";
$contents.=$GetCityName1['cityname'].",";
$contents.=$GetContactDetails1['pincode'].",";
$contents.=$Nationality.",";

$contents.=$GetPersonal1['father_occupation'].",";
$contents.=$GetPersonal1['father_anuual_income'].",";
$contents.=$GetPersonal1['mother_name'].",";
$contents.=$GetPersonal1['mother_occupation'].",";
$contents.=$GetPersonal1['mother_income']."\n";



}

$contents = strip_tags($contents); 

header("Content-Disposition: attachment; filename=download_enroll_list.csv");
print $contents;

?>