<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============

$operation=$_POST['operation'];
$branch_id=$_SESSION['LOGIN_BRANCH'];
$time=addslashes(trim($_POST['time']));

if($operation=='insert_admission_master'){
	$session_for_admission=addslashes(trim($_POST['admission_session_input']));
	$admission_start_date=addslashes(trim($_POST['admission_start_date_input']));
	$admission_end_date=addslashes(trim($_POST['admission_end_date_input']));
	$admission_age_calculation_date=addslashes(trim($_POST['admission_age_calculation_date_input']));
	$circular_text_for_admission=addslashes(trim($_POST['admission_circular_text_input']));
	
	//$attachment_for_circular='asset/custom/upload/student/'.$session_for_admission.".jpg";

	
	$convert_to_date=strtotime($admission_start_date);
	$start_date_for_circular=date("Y:m:d h:i:s", $convert_to_date);
	$convert_to_date=strtotime($admission_end_date);
	$end_date_for_circular=date("Y:m:d h:i:s", $convert_to_date);
	$convert_to_date=strtotime($admission_age_calculation_date);
	$age_calculation_date_for_circular=date("Y:m:d h:i:s", $convert_to_date);
	
	$form_data1['_session']=$session_for_admission;
	$form_data1['_submission_start_date']=$start_date_for_circular;
	$form_data1['_submission_end_date']=$end_date_for_circular;
	$form_data1['_age_calculation_date']=$age_calculation_date_for_circular;
	$form_data1['_circular_text']=$circular_text_for_admission;
	//$form_data1['_circular_file']=$attachment_for_circular;
	$form_data1['_status']='A';
	$form_data1['_create_by']=$_SESSION['LOGIN_USERID'];
	$form_data1['_create_date']=date("Y:m:d h:i:s");
	
	$table_name='_student_admission_master';
	$entry1=$obj->Insert_Data_By_Cond($table_name, $form_data1,"_session=$session_for_admission");
	if($entry1!=NULL){
		echo "New admission circular has been added";
	}
	else{
		echo "Admission master settings already exists for selected session";
	}
}

if($operation=='update_admission_master_info'){
	$master_id_for_admission_edit = trim($_POST['edit_admission_id']);
	$session_for_admission_edit=addslashes(trim($_POST['edit_admission_session']));
	$start_date_for_admission_edit=addslashes(trim($_POST['edit_admission_start_date']));
	$end_date_for_admission_edit=addslashes(trim($_POST['edit_admission_end_date']));
	$age_calculation_for_admission_edit=addslashes(trim($_POST['edit_admission_age_calculation_date']));
	$circular_text_for_admission_edit=addslashes(trim($_POST['edit_admission_circular_text']));
	$status_for_admission_edit=addslashes(trim($_POST['edit_admission_master_status']));
	//$attachment_for_circular='asset/custom/upload/student/'.$session_for_admission.".jpg";

	
	$convert_to_start_date=strtotime($start_date_for_admission_edit);
	$start_date_for_circular=date("Y:m:d h:i:s", $convert_to_start_date);
	$convert_to_end_date=strtotime($end_date_for_admission_edit);
	$end_date_for_circular=date("Y:m:d h:i:s", $convert_to_end_date);
	$convert_to_end_date=strtotime($age_calculation_for_admission_edit);
	$age_calculation_date_for_circular=date("Y:m:d h:i:s", $convert_to_end_date);
	
	$form_data1['_session']=$session_for_admission_edit;
	$form_data1['_submission_start_date']=$start_date_for_circular;
	$form_data1['_submission_end_date']=$end_date_for_circular;
	$form_data1['_age_calculation_date']=$age_calculation_date_for_circular;
	$form_data1['_circular_text']=$circular_text_for_admission_edit;
	//$form_data1['_circular_file']=$attachment_for_circular;
	$form_data1['_status']=$status_for_admission_edit;
	$form_data1['_update_by']=$_SESSION['LOGIN_USERID'];
	
	
	$table_name='_student_admission_master';
	$where_clause="_id='".$master_id_for_admission_edit."'";
	$entry1=$obj->Update_Data($table_name, $form_data1, $where_clause);
	if($entry1!=NULL){
		echo "Admission master has been updated";
	}else{
		echo "error occured during updating information!!";
	}
	
}
if($operation=='delete_admission_master_info'){
	$delete_admission_master_id=trim($_POST['delete_admission_master_id']);
	

	$form_data1['_status']='D';
	$form_data1['_update_by']=$_SESSION['LOGIN_USERID'];
	//$form_data1['_last_update']=date("Y:m:d h:i:s");
	
	$table_name1='_student_admission_details';
	$where_clause1="_master_id='".$delete_admission_master_id."'";
	$table_name2='_student_admission_master';
	$where_clause2="_id='".$delete_admission_master_id."'";
	
	$entry1=$obj->Total_Count_By_Cond($table_name1,$where_clause1);
	if($entry1!=0){
		echo "Active admission master cannot be deleted";
	}
	else{
		$entry2=$obj->Update_Data($table_name2, $form_data1, $where_clause2);
		if($entry2!=NULL){
			echo "Admission master has been deleted";
		}else{
			echo "error occured during deleting information!!";
		}
	}
	
}
?>