<?php
	require "commonincludefiles.php";	
	$adm_yearId  = '';
	$received = 0;
		
	if($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])) 
	{
		if($_REQUEST['semester_hidden_right'] < $_REQUEST['semester_hidden_left'])
		{								
				$StudentDetailMgmt = new StudentDetailMgmt();
				$StudentDetailMgmt->student_id		= $_REQUEST['studentlist_left']; 
				$StudentDetailMgmt->DeleteStudentDetail();
				
				echo '{"success":"true"}';
		}
		else
		{	
					
			if(($_REQUEST['semester_hidden_right']=='3' or $_REQUEST['semester_hidden_right']=='5'))
			{
				
				$objYearMgmt = new YearMgmt();
				$objYearMgmt->year_name   = 	"'".(date("Y")) ."(Odd)','".(date("Y")) ."(Even)'";
				$out=$objYearMgmt ->getAllRecords();
				 
			 	if(dbRows($out)==0)
		 		{
					$objYearMgmt = new YearMgmt();
					$objYearMgmt ->edit(); 
					$objYearMgmt = new YearMgmt();
					$objYearMgmt->year_name            = 	date("Y") ."(Odd)";
					$objYearMgmt ->add(); 
					$objYearMgmt->year_name            = 	date("Y") ."(Even)";
					$objYearMgmt ->add(); 
				}
			}
			
	 		$std=explode(',',$_REQUEST['studentlist_left']);
	
			$objStudentDetailMgmt = new StudentDetailMgmt();
			$condition = " and student_id in (".$_REQUEST['studentlist_left'].")";
			$condition .= " and year_id = ".$_SESSION["VedantnrYearId"]." ";
			$result = $objStudentDetailMgmt ->getAllRecords1(0,0,$condition,"","");
			$studentids="";
	
			if(dbRows($result) > 0)
			{	
				while($record = dbArray($result))
				{										 
			      										
							$objStudentDetailMgmt = new StudentDetailMgmt();							

							$condition1= " and student_id in (".$record['student_id'].")";
							$condition1 .= " and year_id = ".($_SESSION["VedantnrYearId"])." ";
							$result1 = $objStudentDetailMgmt ->getAllRecords(0,0,$condition1,"","");
							
							if(dbRows($result1) > 0)
							{
																								
								$year_id1= $_SESSION['aYearId'] +1;
								
								$objStudentDetailMgmt->year_id		
								= 	$year_id1;
								
								$objStudentDetailMgmt->college_id   
								= 	$_SESSION["VedantnrCollegeId"] ;	
								
								$objStudentDetailMgmt->cur_branchid	
								=	$_REQUEST['branch_hidden_right'];																		
								$objStudentDetailMgmt->cur_semesterid	
								= 	$_REQUEST['semester_hidden_right'];
								
								$objStudentDetailMgmt->cur_divison		
								=	$_REQUEST['division_right'];
								
								$objStudentDetailMgmt->cur_shift		
								=	$record['cur_shift'];
								
								$objStudentDetailMgmt->current_active	=	'1';
								
								$objStudentDetailMgmt->student_id		
								=	$record['student_id'];
								
								$objStudentDetailMgmt->batch_id			
								=	$record['batch_id'];								
								
								$objStudentDetailMgmt->student_rollno	
								=	$record['student_rollno'];
								
								$objStudentDetailMgmt->msc_group		
								=	$record['msc_group'];
								
								$objStudentDetailMgmt->bsc_group		
								=	$record['bsc_group'];
								
								$objStudentDetailMgmt->ba_core			
								=	$record['ba_core'];
								
								$objStudentDetailMgmt->ba_el1			
								=	$record['ba_el1'];
								
								$objStudentDetailMgmt->ba_el2			
								=	$record['ba_el2'];
								
								$objStudentDetailMgmt ->add();
								
								$sql_update = "
								UPDATE cms_studentdetail SET current_active = 0
								WHERE student_id = ".$record['student_id']." AND year_id =".$_SESSION['aYearId']." AND current_active = 1 ";
															
								dbQuery($sql_update);	 
							}							
					//}					
				}
			}						
		}
		echo '{"success":"true"}';
 	}	 	 	 	 	 	 
	else
	{ 
	    echo '{"success":"false"}';
	}	
?>