0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.145.97.1


Current Path : /var/www/oasis/rrit/adm/src/
Upload File :
Current File : /var/www/oasis/rrit/adm/src/kusphdadm.php

<?php

require_once(_DIR_."/../../../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

function saveApplication($aobj_context)
{
	// $bucketName = 'logisys-uploads';
	
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$reg_no = $aobj_context->mobj_data["reg_no"];

	$s3 = S3Client::factory(
		array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		)
	);
	
	include_once($aobj_context->main_src."/json.php"); 
	$json = new Services_JSON();
	//recieve decode json string of personal info
	$lstr_param = stripslashes($aobj_context->mobj_data["personal_info"]);
	$per_arr_data = json_decode($lstr_param, true);	
	
	// $fappno = stripslashes($aobj_context->mobj_data["fappno"]);
	$final_submit = stripslashes($aobj_context->mobj_data["final"]);
	////recieve decode json string of subject info

	$strSubject = stripslashes($aobj_context->mobj_data["pRgSubjects"]);
	$sub_arr_data = json_decode($strSubject, true);	
	
	$aobj_context->main_src = realpath(__DIR__ . '/../..');

	$rgMultiMarks = stripslashes($aobj_context->mobj_data["rgMultiMarks"]);
	$MultiMarks_arr_data = json_decode($rgMultiMarks, true);	

	$strSubjects = implode("','", $sub_arr_data);
	//convert to Associative array
	$rgPerArray = array();
	for($i=0; $i<count($per_arr_data); $i++)
	{
		$rgPerArray[$per_arr_data[$i]['id']] = $per_arr_data[$i]['value'];
	}
	
	//For phd admissions assuming examno and college code

	$degree  = $rgPerArray['idDegree'];
	$college = $rgPerArray['idCollege'];
	
	if($degree == '' || $college == '')
	{
		$arr['message'] = '1. Error in saving admission details. Send query through I NEED HELP.';
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
		return;
	}

	$fappno = '';
	$query = "select FCONTACT_NO, fappno from studadm 
	where FCONTACT_NO = '{$rgPerArray['stuMobileno']}'";
	$studresult =  $aobj_context->mobj_db->GetRow($query); 

	$query = "select funivcode from control";
	$funiv =  $aobj_context->mobj_db->GetRow($query); 

	$FUNIVCODE = $funiv["funivcode"];
	if(count($studresult) >0)
		$fappno = $studresult['fappno']; 
	
	if($fappno == '')
	{		
		$get_last_no="select right(concat('0000',ifnull(max(FSLNO),0)+01),4) as app_no 
		from studadm
		WHERE FDEGREE='{$rgPerArray['idDegree']}' and FCOLLCODE = '{$rgPerArray['idCollege']}'";
		$obj =  $aobj_context->mobj_db->GetRow($get_last_no); 
		$sl_no = "0000".$obj['app_no']; 
		$sl_no = substr($sl_no, -4);

		$rgPerArray['cadd1'] = $rgPerArray['cadd1'];
		$rgPerArray['cadd2'] = $rgPerArray['cadd2'];
		$rgPerArray['cadd3'] = $rgPerArray['cadd3'];

		$rgPerArray['padd1'] = $rgPerArray['padd1'];
		$rgPerArray['padd2'] = $rgPerArray['padd2'];
		$rgPerArray['padd3'] = $rgPerArray['padd3'];

		// $query = "select FADMPREFIX from control";
		// $results = $aobj_context->mobj_db->GetRow($query);
		// $FADMPREFIX = $results['FADMPREFIX'];

		/*$query = "select internal_code+1 as FAUTOINCREMENT from studadm 
		order by internal_code desc limit 1";
		$results = $aobj_context->mobj_db->GetRow($query);
		$FAUTOINCREMENT = $results['FAUTOINCREMENT'];

		$appno = $FADMPREFIX.$FAUTOINCREMENT;
		$fappno = $appno;*/

		if($rgPerArray['idNationality'] != 'Indian' && $rgPerArray['idNationality'] != 'NRI'){
			$cond = ",fdomCountry,fdomstate,fpassportno,fppexpirydate,fvisaNo,
			fvisaExp,fefrroNo,fefrroexpdate";
			$cond2 = ",'{$rgPerArray['fdomCountry']}','{$rgPerArray['fdomstate']}','{$rgPerArray['fpassportno']}',
			date_format(STR_TO_DATE({$rgPerArray['fppexpirydate']},'%d/%m/%Y'),'%Y-%m-%d'),'{$rgPerArray['fvisaNo']}',
			date_format(STR_TO_DATE({$rgPerArray['fvisaExp']},'%d/%m/%Y'),'%Y-%m-%d'),
			'{$rgPerArray['fefrroNo']}',date_format(STR_TO_DATE({$rgPerArray['fefrroexpdate']},'%d/%m/%Y'),'%Y-%m-%d')";
		}
		
		$insert_qry="insert into studadm 
		(FSLNO,FDEGREE,fstudidno,FCOLLCODE,FNAME,FGENDER,FDOB,
		FEXAMNO,FFATNAME,FMOTNAME,FEMAIL,FCASTE,
		FCONTACT_NO,FNATIONAL,FCURRADD1,FCURRADD2,FCURRADD3,FPERMADD1,
		FPERMADD2,FPERMADD3,FRELIGION,FMOBILE_NO,
		FCATBIRTH,FINCOME,FAADHARNO,
		FUNIVNAME,FQUALEXREGNO, FSTUTYPE, FMEDIUM, FQUOTA,
		FAREA,FQMONTH,FQYEAR,FQSECMARKS,FQMAXMARKS,FQPERCENTAGE,FBLOOD_GROUP,
		FTYPEQUALEXAM,fcombcode,FPERDIST,FPERPINCODE,
		FPERSATE,FCOMDIST,FCOMPINCODE,FCOMSTATE,FFINSUB, FCREATEDATE, FCREATEUSER,fincomecert,fcastecert,fph,
		idFatOccup ,fFatAnInc,idMotOccup,fMotAnInc,ftenregno,ftenminmrk, ftenmaxmrk,ftenper,
		ftenbrd,ftenschname,ftenlocsch,ftwtregno, ftwtminmrk,ftwtmaxmrk,ftwtper,ftwtbrd,
		ftwtcollname,ftwtloccoll,fpcmaggt,fdipregno,fthredipmin,fthredipmax,fdipper,
		fdipbrd , fdipcollname ,fdiploccoll, fenttstnm,fentmax,fentper,frankobt,
		fentrritmrk,frrittestper,frankrritobt,fparexser,fpergovt,fstdncc,
		fFatMob,fMotMob,fentmin,fentrritmin $cond)
		values   
		('{$sl_no}','{$rgPerArray['idDegree']}','{$rgPerArray['fstudidno']}',
		'{$rgPerArray['idCollege']}','{$rgPerArray['idStudname']}',
		'{$rgPerArray['gender']}',date_format(STR_TO_DATE('{$rgPerArray['idDob']}','%d/%m/%Y'),'%Y-%m-%d'),
		'A','{$rgPerArray['idFatname']}',
		'{$rgPerArray['idMotname']}','{$rgPerArray['stuEmail']}',
		'{$rgPerArray['idCategory']}','{$rgPerArray['stuMobileno']}',
		'{$rgPerArray['idNationality']}','{$rgPerArray['cadd1']}','{$rgPerArray['cadd2']}',
		'{$rgPerArray['cadd3']}','{$rgPerArray['padd1']}','{$rgPerArray['padd2']}',
		'{$rgPerArray['padd3']}','{$rgPerArray['idReligion']}','{$rgPerArray['pmobileno']}',
		'{$rgPerArray['idCaste']}',
		'{$rgPerArray['income']}','{$rgPerArray['adhar']}',
		'{$rgPerArray['idUnvName']}','{$rgPerArray['idUnvRegno']}',
		'{$rgPerArray['sttype']}','{$rgPerArray['medium']}','{$rgPerArray['adquota']}',
		'{$rgPerArray['area']}',
		'{$rgPerArray['idUnvPassMth']}','{$rgPerArray['idUnvPassYear']}',
		'{$rgPerArray['idUnvSecMarks']}','{$rgPerArray['idUnvMaxMarks']}',
		'{$rgPerArray['idUnvPerc']}','{$rgPerArray['idBldgrp']}',
		'{$rgPerArray['idUnvExam']}',
		'{$rgPerArray['idDegComb']}','{$rgPerArray['pdistrict']}',
		'{$rgPerArray['ppincode']}','{$rgPerArray['pstate']}','{$rgPerArray['cdistrict']}',
		'{$rgPerArray['cpincode']}','{$rgPerArray['cstate']}','{$final_submit}', now(), 'student',
		'{$rgPerArray['fincomecert']}','{$rgPerArray['fcastecert']}','{$rgPerArray['fph']}',
		'{$rgPerArray['idFatOccup']}','{$rgPerArray['fFatAnInc']}','{$rgPerArray['idMotOccup']}',
		'{$rgPerArray['fMotAnInc']}','{$rgPerArray['ftenregno']}','{$rgPerArray['ftenminmrk']}',
		'{$rgPerArray['ftenmaxmrk']}','{$rgPerArray['ftenper']}','{$rgPerArray['ftenname']}',
		'{$rgPerArray['ftenschname']}','{$rgPerArray['ftenlocsch']}',
		'{$rgPerArray['ftwtregno']}','{$rgPerArray['ftwtminmrk']}' ,'{$rgPerArray['ftwtmaxmrk']}',
		'{$rgPerArray['ftwtper']}','{$rgPerArray['ftwtname']}','{$rgPerArray['ftwtcollname']}',
		'{$rgPerArray['ftwtloccoll']}','{$rgPerArray['fpcmaggt']}','{$rgPerArray['fdipregno']}',
		'{$rgPerArray['fthredipmin']}','{$rgPerArray['fthredipmax']}','{$rgPerArray['fdipper']}',
		'{$rgPerArray['fdipname']}','{$rgPerArray['fdipcollname']}','{$rgPerArray['fdiploccoll']}',
		'{$rgPerArray['fenttstnm']}','{$rgPerArray['fentmax']}','{$rgPerArray['fentper']}','{$rgPerArray['frankobt']}',
		'{$rgPerArray['fentrritmrk']}','{$rgPerArray['frrittestper']}','{$rgPerArray['frankrritobt']}',
		'{$rgPerArray['fparexser']}','{$rgPerArray['fpergovt']}','{$rgPerArray['fstdncc']}',
		'{$rgPerArray['fFatMob']}', '{$rgPerArray['fMotMob']}','{$rgPerArray['fentmin']}', '{$rgPerArray['fentrritmin']}' $cond2)";
		// var_dump($insert_qry);die();
		$results = $aobj_context->mobj_db->Execute($insert_qry);

		if($results)
		{
			$query = "select studadm.fappno, studadm.fdegree, studadm.fcollcode, 
			studadm.fslno, control.funivcode from studadm, control 
			where fcontact_no = '{$rgPerArray['stuMobileno']}'"; 
			$results2 = $aobj_context->mobj_db->GetRow($query);
			$fappno = $results2['fappno'];
			
			// if(count($results2) > 0)
			// {
			// 	$internal_code = $results2['internal_code'];
			// 	$degree = $results2['fdegree'];
			// 	$college = $results2['fcollcode'];
			// 	$sl_no = $results2['fslno'];
			// 	$funivcode = substr($results2['funivcode'],1,2);
				
				

			// 	$query = "update studadm set fappno = '{$fappno}' 
			// 	where fcontact_no = '{$rgPerArray['stuMobileno']}' 
			// 	and fappno = '{$rgPerArray['stuMobileno']}'";

			// 	$results3 = $aobj_context->mobj_db->Execute($query);
				
			// }
			// else
			// {
			// 	$arr['message'] = '2. Error in saving admission details. Send query through I NEED HELP.';
			// 	echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
			// 	return;
			// }
			if(count($sub_arr_data) > 0)
			{
				for($k=0;$k<count($sub_arr_data);$k++)
				{
					if($sub_arr_data[$k] != '')
					{
						$insSubs .= "('{$degree}', 'A', '{$college}', '{$sl_no}', '{$sub_arr_data[$k]}', 'F', '{$fappno}'),";
					}
				}
			
				$insSubs = rtrim($insSubs,',');

				$query = "insert into options(FDEGREE, FEXAMNO, FCOLLCODE,
				FSLNO, FSUBCODE, FDELETED, FAPPNO)
				values
				{$insSubs}";
				
				$optresults = $aobj_context->mobj_db->Execute($query);
			}

			if(substr(strtoupper($degree),0,1) == 'M' )
			{
				$mobj_jsondata = json_decode($rgMultiMarks,true);
					
				$sub_marks = array();
				for($i=0; $i<count($mobj_jsondata); $i++)
				{
					
					for($j=0;$j<count($mobj_jsondata[$i]);$j++)
					{
						$sub_marks[$i][$mobj_jsondata[$i][$j]['name']] = $mobj_jsondata[$i][$j]['value']; 	

					}	
				}
				$sql = array();
				$j=0;
				for($i=1; $i<=count($sub_marks);$i++)
				{
					$sql[] = "('{$fappno}' ,'{$rgPerArray['idCollege']}' ,'{$degree}',
					'{$sub_marks[$j]["subcode_$i"]}','{$sub_marks[$j]["subsem1_$i"]}', '{$sub_marks[$j]["subsem1mo_$i"]}',
					'{$sub_marks[$j]["subsem1mm_$i"]}' ,'{$sub_marks[$j]["subsem2mo_$i"]}' ,'{$sub_marks[$j]["subsem2mm_$i"]}',
					'{$sub_marks[$j]["subsem3mo_$i"]}', '{$sub_marks[$j]["subsem3mm_$i"]}', '{$sub_marks[$j]["subsem4mo_$i"]}',
					'{$sub_marks[$j]["subsem4mm_$i"]}', '{$sub_marks[$j]["subsem5mo_$i"]}', '{$sub_marks[$j]["subsem5mm_$i"]}', 
					'{$sub_marks[$j]["subsem6mo_$i"]}', '{$sub_marks[$j]["subsem6mm_$i"]}', '{$sub_marks[$j]["subtotalmo_$i"]}',
					'{$sub_marks[$j]["subtotalmm_$i"]}', '{$sub_marks[$j]["subpercentagemm_$i"]}')";
					$j++;
				}

				// $query = "delete from qualsubdet where fappno = '{$fappno}'";
				// $deloptresults = $aobj_context->mobj_db->Execute($query);
				if(count($sub_marks) > 0)
				{	
					$query = 'INSERT INTO qualsubdet(fappno,
					fcollcode, fdegree, fsubcode,
					fsubname, fsecmarksa, fmaxmarksa, 
					fsecmarksb, fmaxmarksb,
					fsecmarksc, fmaxmarksc,
					fsecmarksd, fmaxmarksd,
					fsecmarkse, fmaxmarkse,
					fsecmarksf, fmaxmarksf,
					ftotsecmarks, ftotmaxmarks,
					fsubpercent
					) VALUES '.implode(',', $sql);
					
					$resultqualdets = $aobj_context->mobj_db->Execute($query);
				}	
			}
			
			$cert_path = $aobj_context->main_src."/adm/upload/".$fappno;
			//is successfully inserted
			if(!file_exists($cert_path))
			{
				mkdir($cert_path);
			}
			
			// ------------- Document Strart -------------------//////

			$insert = "INSERT INTO studoc
			( 
			app_no, 
			login_cnt, 
			file_path, 
			created_date,fdegree,fcollcode,fdoctype
			)
			select '{$sl_no}', '{$fappno}', null, now(), '{$degree}', 
			'{$college}', ffilename from masdoc where fdegree = '{$degree}'";	
			$lobj_insert= $aobj_context->mobj_db->Execute($insert);
			//var_dump($insert);
			$doc_names = ['ADHAAR', 'CASTE', 'INCOME', 'SSLCMC', 'TCCERT', 'PUMC', 'GCCERT'];

			for($i=0;$i<count($doc_names);$i++)
			{
				$GCCERT = $rgPerArray['h_'.$doc_names[$i]];
				if($GCCERT == '')
					continue;

				$GCCERT_PATH = $aobj_context->main_src.'/adm/upload/'.$GCCERT;
				$filename = explode(".", $GCCERT_PATH);
				$ext = strtolower($filename[1]);

				$GCCERT_FILENAME = $doc_names[$i];
				
				$GCCERT_FILENAME = $GCCERT_FILENAME.".".$ext;

				$GCCERT_FILENAME_FILENAME = $cert_path."/".$GCCERT_FILENAME;
				$GCCERT = $FUNIVCODE."/certificates/{$fappno}/".$GCCERT_FILENAME;
				$GCCERT_upd = "certificates/{$fappno}/".$GCCERT_FILENAME;
				
				if(file_exists($GCCERT_PATH)) {
					try {
						$s3->putObject(['Bucket' => "admission-certificates", 'Key' => $GCCERT, 'SourceFile' => $GCCERT_PATH]);

						$update = "update studoc set file_path = '{$GCCERT_upd}' 
							where login_cnt = '{$fappno}' 
							and fdoctype = '{$doc_names[$i]}'";

							$lobj_insert= $aobj_context->mobj_db->Execute($update);
							unlink($GCCERT_PATH);
					}	catch(S3Exception $e){
						$arr['message'] = 'Unable to upload documents';
						echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
						return;
					}
				}
				// if($s3->putObject(['Bucket' => $this->bucket, 'Key' => $path, 'Body' => $data]))
				// {
				// 	$update = "";
				// 	$update = "update studoc set file_path = '{$GCCERT}' 
				// 	where login_cnt = '{$fappno}' 
				// 	and fdoctype = '{$doc_names[$i]}'";
				// 	$lobj_insert= $aobj_context->mobj_db->Execute($update);
				// 	unlink($GCCERT_PATH);
				// }
			}
			// -------------Document end -------------------//////
		}
	}
	else
	{
		if($rgPerArray['idNationality'] != 'Indian' && $rgPerArray['idNationality'] != 'NRI'){
			$cond = ",fdomCountry = '{$rgPerArray['fdomCountry']}',fdomstate = '{$rgPerArray['fdomstate']}',
			fpassportno = '{$rgPerArray['fpassportno']}',
			fppexpirydate = DATE_FORMAT(STR_TO_DATE('{$rgPerArray['fppexpirydate']}','%d/%m/%Y'),'%Y-%m-%d'),
			fvisaNo = '{$rgPerArray['fvisaNo']}',
			fvisaExp = DATE_FORMAT(STR_TO_DATE('{$rgPerArray['fvisaExp']}','%d/%m/%Y'),'%Y-%m-%d'),
			fefrroNo = '{$rgPerArray['fefrroNo']}',
			fefrroexpdate = DATE_FORMAT(STR_TO_DATE('{$rgPerArray['fefrroexpdate']}','%d/%m/%Y'),'%Y-%m-%d')";
		}
		$query = "update studadm set 
		fdegree = '{$rgPerArray['idDegree']}',
		FCOLLCODE = '{$rgPerArray['idCollege']}',
		FNAME = '{$rgPerArray['idStudname']}',
		FGENDER = '{$rgPerArray['gender']}',
		FSTUTYPE = '{$rgPerArray['sttype']}',
		FDOB = DATE_FORMAT(STR_TO_DATE('{$rgPerArray['idDob']}','%d/%m/%Y'),'%Y-%m-%d'),	
		FFATNAME = '{$rgPerArray['idFatname']}',
		FMOTNAME = '{$rgPerArray['idMotname']}',
		FEMAIL = '{$rgPerArray['stuEmail']}',
		FCASTE = '{$rgPerArray['idCategory']}',
		FCONTACT_NO = '{$rgPerArray['stuMobileno']}',
		FNATIONAL = '{$rgPerArray['idNationality']}',
		FMEDIUM = '{$rgPerArray['medium']}',
		FQUOTA = '{$rgPerArray['adquota']}',
		FCURRADD1 = '{$rgPerArray['cadd1']}',
		FCURRADD2 = '{$rgPerArray['cadd2']}',
		FCURRADD3 = '{$rgPerArray['cadd3']}',
		FCOMDIST = '{$rgPerArray['cdistrict']}',
		FCOMPINCODE = '{$rgPerArray['cpincode']}',
		FCOMSTATE = '{$rgPerArray['cstate']}',
		FPERMADD1 = '{$rgPerArray['padd1']}',
		FPERMADD2 = '{$rgPerArray['padd2']}',
		FPERMADD3 = '{$rgPerArray['padd3']}',
		FPERDIST = '{$rgPerArray['pdistrict']}',
		FPERPINCODE = '{$rgPerArray['ppincode']}',
		FPERSATE = '{$rgPerArray['pstate']}',
		FRELIGION = '{$rgPerArray['idReligion']}',
		FMOBILE_NO = '{$rgPerArray['pmobileno']}',
		FCATBIRTH = '{$rgPerArray['idCaste']}',
		FINCOME = '{$rgPerArray['income']}',
		FAADHARNO = '{$rgPerArray['adhar']}',
		FUNIVNAME = '{$rgPerArray['idUnvName']}',
		FQUALEXREGNO = '{$rgPerArray['idUnvRegno']}',
		FAREA = '{$rgPerArray['area']}',
		FQMONTH = '{$rgPerArray['idUnvPassMth']}',
		FQYEAR = '{$rgPerArray['idUnvPassYear']}',
		FQMAXMARKS = '{$rgPerArray['idUnvMaxMarks']}',
		FQSECMARKS = '{$rgPerArray['idUnvSecMarks']}',
		FQPERCENTAGE = '{$rgPerArray['idUnvPerc']}',
		FBLOOD_GROUP = '{$rgPerArray['idBldgrp']}',
		FTYPEQUALEXAM = '{$rgPerArray['idUnvExam']}',
		fcombcode = '{$rgPerArray['idDegComb']}',
		fincomecert = '{$rgPerArray['fincomecert']}',
		fcastecert = '{$rgPerArray['fcastecert']}',
		fph = '{$rgPerArray['fph']}',
		flogdate = now(),
		ffinsub = '{$final_submit}' ,
		idFatOccup = '{$rgPerArray['idFatOccup']}',
		fFatAnInc = '{$rgPerArray['fFatAnInc']}',
		idMotOccup = '{$rgPerArray['idMotOccup']}',
		fMotAnInc = '{$rgPerArray['fMotAnInc']}',
		ftenregno = '{$rgPerArray['ftenregno']}',
		ftenminmrk = '{$rgPerArray['ftenminmrk']}',
		ftenmaxmrk = '{$rgPerArray['ftenmaxmrk']}',
		ftenper = '{$rgPerArray['ftenper']}',
		ftenbrd = '{$rgPerArray['ftenbrd']}',
		ftenschname = '{$rgPerArray['ftenschname']}',
		ftenlocsch = '{$rgPerArray['ftenlocsch']}',
		ftwtregno = '{$rgPerArray['ftwtregno']}',
		ftwtminmrk = '{$rgPerArray['ftwtminmrk']}',
		ftwtmaxmrk = '{$rgPerArray['ftwtmaxmrk']}',
		ftwtper = '{$rgPerArray['ftwtper']}',
		ftwtbrd = '{$rgPerArray['ftwtbrd']}',
		ftwtcollname = '{$rgPerArray['ftwtcollname']}',
		ftwtloccoll = '{$rgPerArray['ftwtloccoll']}',
		fpcmaggt = '{$rgPerArray['fpcmaggt']}',
		fdipregno = '{$rgPerArray['fdipregno']}',
		fthredipmin = '{$rgPerArray['fthredipmin']}',
		fthredipmax = '{$rgPerArray['fthredipmax']}',
		fdipper = '{$rgPerArray['fdipper']}',
		fdipbrd = '{$rgPerArray['fdipbrd']}',
		fdipcollname = '{$rgPerArray['fdipcollname']}',
		fdiploccoll = '{$rgPerArray['fdiploccoll']}',
		fenttstnm = '{$rgPerArray['fenttstnm']}',
		fentmax = '{$rgPerArray['fentmax']}',
		fentper ='{$rgPerArray['fentper']}',
		frankobt = '{$rgPerArray['frankobt']}',
		fentrritmrk = '{$rgPerArray['fentrritmrk']}',
		frrittestper = '{$rgPerArray['frrittestper']}',
		frankrritobt = '{$rgPerArray['frankrritobt']}',
		fparexser = '{$rgPerArray['fparexser']}',
		fpergovt = '{$rgPerArray['fpergovt']}',
		fstdncc = '{$rgPerArray['fstdncc']}',
		fFatMob = '{$rgPerArray['fFatMob']}',
		fMotMob = '{$rgPerArray['fMotMob']}',
		fentmin = '{$rgPerArray['fentmin']}',
		fstudidno = '{$rgPerArray['fstudidno']}',
		fentrritmin = '{$rgPerArray['fentrritmin']}'
		$cond
		where fappno = '{$fappno}'";
		
		$results = $aobj_context->mobj_db->Execute($query);

		if($results)
		{
			$query = "select fslno from studadm where fappno = '{$fappno}'";
			$res =  $aobj_context->mobj_db->GetRow($query); 

			$sl_no = $res['fslno'];
			if(count($sub_arr_data) >0)
			{
				$query = "delete from options where fappno = '{$fappno}'";
				$deloptresults = $aobj_context->mobj_db->Execute($query);

				for($k=0;$k<count($sub_arr_data);$k++)
				{
					if($sub_arr_data[$k] != '')
					{
						$insSubs .= "('{$rgPerArray['idDegree']}', 'A', '{$rgPerArray['idCollege']}', '{$sl_no}', '{$sub_arr_data[$k]}', 'F', '{$fappno}'),";
					}
				}
				$insSubs = rtrim($insSubs,',');

				$query = "insert into options(FDEGREE,
				FEXAMNO,
				FCOLLCODE,
				FSLNO,
				FSUBCODE,
				FDELETED,fappno)
				values
				{$insSubs}";
				$optresults = $aobj_context->mobj_db->Execute($query);

			}

			if(substr(strtoupper($degree),0,1) == 'M' )
			{
				$mobj_jsondata = json_decode($rgMultiMarks,true);
				
				$sub_marks = array();
				for($i=0; $i<count($mobj_jsondata); $i++)
				{
					
					for($j=0;$j<count($mobj_jsondata[$i]);$j++)
					{
						$sub_marks[$i][$mobj_jsondata[$i][$j]['name']] = $mobj_jsondata[$i][$j]['value']; 	

					}	
				}
				$sql = array();
				$j=0;
				for($i=1; $i<=count($sub_marks);$i++)
				{
					$sql[] = "('{$fappno}' ,'{$rgPerArray['idCollege']}' ,'{$degree}',
					'{$sub_marks[$j]["subcode_$i"]}','{$sub_marks[$j]["subsem1_$i"]}', '{$sub_marks[$j]["subsem1mo_$i"]}',
					'{$sub_marks[$j]["subsem1mm_$i"]}' ,'{$sub_marks[$j]["subsem2mo_$i"]}' ,'{$sub_marks[$j]["subsem2mm_$i"]}',
					'{$sub_marks[$j]["subsem3mo_$i"]}', '{$sub_marks[$j]["subsem3mm_$i"]}', '{$sub_marks[$j]["subsem4mo_$i"]}',
					'{$sub_marks[$j]["subsem4mm_$i"]}', '{$sub_marks[$j]["subsem5mo_$i"]}', '{$sub_marks[$j]["subsem5mm_$i"]}', 
					'{$sub_marks[$j]["subsem6mo_$i"]}', '{$sub_marks[$j]["subsem6mm_$i"]}', '{$sub_marks[$j]["subtotalmo_$i"]}',
					'{$sub_marks[$j]["subtotalmm_$i"]}', '{$sub_marks[$j]["subpercentagemm_$i"]}')";
					$j++;
				}

				$query = "delete from qualsubdet where fappno = '{$fappno}'";
				$deloptresults = $aobj_context->mobj_db->Execute($query);

				$query = 'INSERT INTO qualsubdet(fappno,
				fcollcode, fdegree, fsubcode,
				fsubname, fsecmarksa, fmaxmarksa, 
				fsecmarksb, fmaxmarksb,
				fsecmarksc, fmaxmarksc,
				fsecmarksd, fmaxmarksd,
				fsecmarkse, fmaxmarkse,
				fsecmarksf, fmaxmarksf,
				ftotsecmarks, ftotmaxmarks,
				fsubpercent
				) VALUES '.implode(',', $sql);
				
				$resultqualdets = $aobj_context->mobj_db->Execute($query);
			}

			$cert_path = $aobj_context->main_src."/adm/upload/".$fappno;
			
			//is successfully inserted
			if(!file_exists($cert_path))
			{
				mkdir($cert_path);
			}

			// ------------- Document Strart -------------------//////

			$doc_names = ['ADHAAR', 'CASTE', 'INCOME', 'SSLCMC', 'TCCERT', 'PUMC', 'GCCERT'];
			
			for($i=0;$i<count($doc_names);$i++)
			{
				$GCCERT = $rgPerArray['h_'.$doc_names[$i]];
				if($GCCERT == '')
					continue;

				$GCCERT_PATH = $aobj_context->main_src.'/upload/'.$GCCERT;
				
				$filename = explode(".", $GCCERT_PATH);
				$ext = strtolower($filename[1]);
				
				$GCCERT_FILENAME = $doc_names[$i];
				
				$GCCERT_FILENAME = $GCCERT_FILENAME.".".$ext;

				$GCCERT_FILENAME_FILENAME = $cert_path."/".$GCCERT_FILENAME;
				$GCCERT = $FUNIVCODE."/certificates/{$fappno}/".$GCCERT_FILENAME;
				$GCCERT_upd = "certificates/{$fappno}/".$GCCERT_FILENAME;
				if(file_exists($GCCERT_PATH)) 
				{
					try{
						$s3->putObject(['Bucket' => "admission-certificates", 'Key' => $GCCERT, 'SourceFile' => $GCCERT_PATH]);
						$update = '';
						$update = "update studoc set file_path = '{$GCCERT_upd}' 
							where login_cnt = '{$fappno}' 
							and fdoctype = '{$doc_names[$i]}'";	
							
							$lobj_insert= $aobj_context->mobj_db->Execute($update);
							unlink($GCCERT_PATH);
					} catch(S3Exception $e){
						$arr['message'] = 'Unable to upload documents';
						echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
						return;
					}
				}
				// if(copy($GCCERT_PATH,$GCCERT_FILENAME_FILENAME))
				// {
				// 	$update = "update studoc set file_path = '{$GCCERT}' 
				// 	where login_cnt = '{$fappno}' 
				// 	and fdoctype = '{$doc_names[$i]}'";	
				
				// 	$lobj_insert= $aobj_context->mobj_db->Execute($update);

				// 	unlink($GCCERT_PATH);
				// }
			}
			// -------------Document end -------------------//////
		}
	}
		
	if($results) 
	{
		//update photo path
		$college_path=$aobj_context->main_src."/student_photos/{$college}";
		$degree_path=$aobj_context->main_src."/student_photos/{$college}/".$degree;
		$folder_path=$aobj_context->main_src."/student_photos/{$college}/".$degree;
		$sign_folder_path = $aobj_context->main_src."/student_photos/{$college}/".$degree."/sign";
		
		$photo_filename = $rgPerArray['photo_path'];

		if($photo_filename != '')
		{
			$image_path = $aobj_context->main_src."/adm/upload/{$photo_filename}";

			$filename = explode(".", $photo_filename);
			$ext = strtolower($filename[1]);
			$photo_filename = $college."_".$degree."_".$fappno;
			$photo_filename = $photo_filename.".".$ext;

			$full_file_path = $folder_path.'/'.$photo_filename;

			if(!file_exists($college_path))
			{
				mkdir($college_path);
			}

			if(!file_exists($degree_path))
			{
				mkdir($degree_path);
			}
			if(!file_exists($sign_folder_path))
			{
				mkdir($sign_folder_path);
			}

			$photo = $FUNIVCODE."/student_photos/{$college}/".$degree.'/'.$fappno.'/'.$photo_filename;

			$photo_upd = "student_photos/{$college}/".$degree.'/'.$fappno.'/'.$photo_filename;

			if(file_exists($image_path))
			{
				try{
					
					$s3->putObject(['Bucket' => "university-student-photos", 'Key' => $photo, 'SourceFile' => $image_path]);
					
					$update="update studadm set FPHOTOPATH='{$photo_upd}' 
							where FAPPNO=  '{$fappno}'";
					$up_obj=$aobj_context->mobj_db->Execute($update); 
					unlink($image_path);
				} catch(S3Exception $e){
					$arr['message'] = 'Unable to upload photo';
					echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
					return;
				}
			}
			// if(copy($image_path,$full_file_path))
			// {
			// 	$update="update studadm set FPHOTOPATH='{$photo}' 
			// 			where FAPPNO=  '{$fappno}'";
			// 	$up_obj=$aobj_context->mobj_db->Execute($update); 
			// 	unlink($image_path);
			// }
		}

			//update signature path
			
		$sign_filename = $rgPerArray['sign_path'];

		if($sign_filename != '')
		{
			$sign_path = $aobj_context->main_src."/upload/{$sign_filename}";

			$filename = explode(".", $sign_filename);
			$ext = strtolower($filename[1]);
			$sign_filename = $college."_".$degree."_".$fappno."_sign";
			$sign_filename = $sign_filename.".".$ext;

			$full_file_path_sign = $folder_path."/sign/".$sign_filename;

			$sign = $FUNIVCODE."/student_photos/{$college}/".$degree."/sign/".$sign_filename;

			$sign_upd = "student_photos/{$college}/".$degree."/sign/".$fappno.'/'.$sign_filename;
			if(file_exists($sign_path))
			{
				try{
					$s3->putObject(['Bucket' => "university-student-photos", 'Key' => $sign, 'SourceFile' => $sign_path]);
					$update="update studadm set FSIGNPATH='{$sign_upd}' 
							where FAPPNO='{$fappno}' ";
					$up_obj=$aobj_context->mobj_db->Execute($update); 
					unlink($sign_path);
				} catch(S3Exception $e){
					$arr['message'] = 'Unable to upload Signature';
					echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
					return;
				}
			}

			// if(copy($sign_path,$full_file_path_sign))
			// {
			// 	$update="update studadm set FSIGNPATH='{$sign_upd}' 
			// 			where FAPPNO='{$fappno}' ";
			// 	$up_obj=$aobj_context->mobj_db->Execute($update); 
			// 	unlink($sign_path);
			// }
		}

		$data='Your Application is submitted successfully.';
		$arr['message']= $data;
		$arr['app_no'] = $fappno;
		$arr['slno']  = $slnocnt;
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
		return;
	}	
	else
	{
		$arr['message'] = 'Error in submitting the application.';
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
		return;
	}

}


function rePrintApplication($aobj_context) 
{
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

	$query = "select ifnull(fappno,'') as fappno from studadm 
	where FCONTACT_NO = '{$_SESSION['MOBILE']}' and ffinsub = 'T'";

	$obj =  $aobj_context->mobj_db->GetRow($query); 
	
	$row['appno'] = $obj['fappno'];
	$row['error_code'] = '0';
	if($obj['fappno'] == '')
	{
		$row['error_code'] = '1';
	}
	echo json_encode($row);

}