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 : 18.227.183.161


Current Path : /proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/src/uExamApplicationForm.php

<?php

function uShowExamApplicationForm($aobj_context){
    $regno = $aobj_context->mobj_data["regno"];
    $regno = strtoupper($regno);
    $category = $aobj_context->mobj_data["category"];
    $li = $aobj_context->mobj_data["li"];
    $FUNIVCODE = $aobj_context->mobj_data["univcode"];


    $query = "select * from candsum where fregno = '{$regno}'";
    $res = $aobj_context->pobj_db->GetRow($query);

    if($res['FFRESHEXAM'] == '')
		{
			$arr['data']='Freshexam Not Updated Contact Help Desk.';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"Failure");
			return;
        }
    
    $lquery="select FDEGREE,FCOLLCODE,FNAME,ifnull(fappblock,'') as fappblock from student 
	where FREGNO='{$regno}' 
	and ifnull(fexamappblk,'') <> 'T' and ifnull(fmp,'') <> 'T'";	
	$restemp = $aobj_context->pobj_db->GetRow($lquery);
    $college_code = $restemp['FCOLLCODE'];
	$degree = $restemp['FDEGREE'];
	$student_name = $restemp['FNAME'];
    $fappblock = $restemp['fappblock'];
    
    if(empty($college_code))
	{
			$arr['data']='No details found for the student';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"Failure");
			return false;
	}else if($fappblock == 'T')
	{
			$arr['data']='Last date is over for online exam application form';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"Failure");
			return false;
	}
	else
	{
		GenerateCandidateDetails($aobj_context,$FUNIVCODE,$college_code,$degree,$regno,$category);

	}

}




function GenerateCandidateDetails($aobj_context,$FUNIVCODE,$college_code,$degree,$regno,$category){

    $responseObj="";

    $exam_appear=array();
    $qry=" select * from collexam where fdegree = '{$degree}' and fcollcode = '{$college_code}' 
        and DATE_FORMAT(NOW(),'%Y-%m-%d') 
        BETWEEN DATE_FORMAT(fappfrom,'%Y-%m-%d') 
        AND DATE_FORMAT(fappto,'%Y-%m-%d')";
    $student_exam_details = $aobj_context->pobj_db->GetRow($qry); 

    if(count($student_exam_details) > 0)
    {
        $lquery = " select c.FDEGREE,c.FEXAMNO,c.FCOLLCODE,c.FREGNO,
			IF(IFNULL(c.FCATEGORY,'')='',if(ifnull(s.FCASTE,'') = '', 'GM', s.FCASTE) ,c.FCATEGORY) AS FCATEGORY,
			if(c.Fgender='',s.Fgender,c.Fgender) as Fgender,c.FAPPEARA,c.FEXAMFEEA,
			c.FAPPEARB,c.FEXAMFEEB,c.FAPPEARC,c.FEXAMFEEC,c.FAPPEARD,c.FEXAMFEED,c.FAPPEARE,
			c.FEXAMFEEE,c.FAPPEARF,c.FEXAMFEEF,c.FAPPEARG,c.FEXAMFEEG,c.FAPPEARH,c.FEXAMFEEH,
			c.FAPPEARI,c.FEXAMFEEI,c.FAPPEARJ,c.FEXAMFEEJ,round(c.FTOTALFEE,2) as FTOTALFEE,
			c.FYEAR,c.FEXAMTYPE,c.FDELETED,FRECPTNO,DATE_FORMAT(FRECPTDATE,'%d/%m/%Y') as FRECPTDATE
			,FREMARKS,c.FTOTSUBA,c.FTOTSUBB,c.FTOTSUBC,c.FTOTSUBD,c.FTOTSUBE,c.FTOTSUBF,c.FTOTSUBG,c.FTOTSUBH,
			c.FTOTSUBI,c.FTOTSUBJ,concat('*',c.FCONSTYPE) as FCONSTYPE,ifnull(c.FELIG,'0123456789') as FELIG,
			sum(if(t.fexamno = 'A',1,0)) as fcnta, sum(if(t.fexamno = 'B',1,0)) as fcntb,
			sum(if(t.fexamno = 'C',1,0)) as fcntc, sum(if(t.fexamno = 'D',1,0)) as fcntd,
			sum(if(t.fexamno = 'E',1,0)) as fcnte, sum(if(t.fexamno = 'F',1,0)) as fcntf,
			sum(if(t.fexamno = 'G',1,0)) as fcntg, sum(if(t.fexamno = 'H',1,0)) as fcnth,
			sum(if(t.fexamno = 'I',1,0)) as fcnti, sum(if(t.fexamno = 'J',1,0)) as fcntj,
			FRECPTNOA,DATE_FORMAT(FRECPTDATEA,'%d/%m/%Y') AS FRECPTDATEA,
			FRECPTNOB,DATE_FORMAT(FRECPTDATEB,'%d/%m/%Y') AS FRECPTDATEB,
			FRECPTNOC,DATE_FORMAT(FRECPTDATEC,'%d/%m/%Y') AS FRECPTDATEC ,
			FRECPTNOD,DATE_FORMAT(FRECPTDATED,'%d/%m/%Y') AS FRECPTDATED ,
			FRECPTNOE,DATE_FORMAT(FRECPTDATEE,'%d/%m/%Y') AS FRECPTDATEE ,
			FRECPTNOF,DATE_FORMAT(FRECPTDATEF,'%d/%m/%Y') AS FRECPTDATEF ,
			FRECPTNOG,DATE_FORMAT(FRECPTDATEG,'%d/%m/%Y') AS FRECPTDATEG ,
			FRECPTNOH,DATE_FORMAT(FRECPTDATEH,'%d/%m/%Y') AS FRECPTDATEH ,
			FRECPTNOI,DATE_FORMAT(FRECPTDATEI,'%d/%m/%Y') AS FRECPTDATEI ,
			FRECPTNOJ,DATE_FORMAT(FRECPTDATEJ,'%d/%m/%Y') AS FRECPTDATEJ ,
			FFRESHEXAM  
			from candsum c left join student s on s.FDEGREE=c.FDEGREE 
			and s.FREGNO=c.FREGNO
			left outer join canddet t
			on c.fdegree = t.fdegree and c.fregno = t.fregno
			where c.FDEGREE='{$degree}' 
			and c.FCOLLCODE='{$college_code}'
			and c.FREGNO='{$regno}' 
			and ifnull(s.fexamappblk,'') <> 'T' 
            and ifnull(s.fmp,'') <> 'T'";
            
        
			
            $student_exam_details = $aobj_context->pobj_db->GetRow($lquery);
            $exam_details_header="";
            
            
            $exam_det_blue_header=["Exam Details"];
            $exam_details_header->blueHeader=$exam_det_blue_header;
            $exam_details_table_data_header = ["A","B","C","D","E","F","G","H","I","J"];
            $exam_details_header->exam_details_table_data_header=$exam_details_table_data_header;

            $responseObj->exam_details_header = $exam_details_header;
            


    }
    else
    {
		$arr="Last date is over for online exam application form";
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"Failure");
		return;	
    }

        $fee_td="";
		$totsub = '';
		$FFRESHEXAM = $student_exam_details['FFRESHEXAM'];
		$CONSTYPE  = $student_exam_details['FCONSTYPE'];
		$FELIG  = $student_exam_details['FELIG'];

		$fcnta  = $student_exam_details['fcnta'];
		$fcntb  = $student_exam_details['fcntb'];
		$fcntc  = $student_exam_details['fcntc'];	
		$fcntd  = $student_exam_details['fcntd'];
		$fcnte  = $student_exam_details['fcnte'];
		$fcntf  = $student_exam_details['fcntf'];
		$fcntg  = $student_exam_details['fcntg'];
		$fcnti  = $student_exam_details['fcnti'];
		$fcntj  = $student_exam_details['fcntj'];




		$totsub.=$student_exam_details['FTOTSUBA'].",";
		$totsub.=$student_exam_details['FTOTSUBB'].",";
		$totsub.=$student_exam_details['FTOTSUBC'].",";
		$totsub.=$student_exam_details['FTOTSUBD'].",";
		$totsub.=$student_exam_details['FTOTSUBE'].",";
		$totsub.=$student_exam_details['FTOTSUBF'].",";
		$totsub.=$student_exam_details['FTOTSUBG'].",";
		$totsub.=$student_exam_details['FTOTSUBH'].",";
		$totsub.=$student_exam_details['FTOTSUBI'].",";
        $totsub.=$student_exam_details['FTOTSUBJ'].",";
		
		$exam_detail_radioButton_table_data =array();
        for($i=65;$i<75;$i++)
		{  
			$obj=""; 
			$html_id="candidate_list_exam_".chr($i)."_details";
			$exam_fee["{$html_id}"]=$student_exam_details['FEXAMFEE'.chr($i)];
			$exam_receipt_no["{$html_id}"]=$student_exam_details['FRECPTNO'.chr($i)];
			$exam_receipt_no_date["{$html_id}"]=is_null($student_exam_details['FRECPTDATE'.chr($i)])?date('d/m/Y'):($student_exam_details['FRECPTDATE'.chr($i)]);
			$border_left=($i==65)?" border-left:1px solid #ccc;":" border-left:0px solid #ccc;";
		
			$obj->id = chr($i);
			if($student_exam_details['FAPPEAR'.chr($i)]=='N')
			{						
				$obj->tableDataValue = "NE";
			}	
			else if($student_exam_details['FAPPEAR'.chr($i)]=='P')
			{
				$obj->tableDataValue = "PASS";

			}else if($FELIG == '0123456789')
			{
				$obj->tableDataValue = "Blocked";
			}
			else  if($student_exam_details['FAPPEAR'.chr($i)]=='A' && strpos('*'.$FELIG,chr($i)) > 0)
			{

				$obj->tableDataValue = "Radio";
				$chr = chr($i);
				array_push($exam_appear,$chr);
			}
			else  
			{
				
				$obj->tableDataValue = "Blocked";
			}
			

			array_push($exam_detail_radioButton_table_data,$obj);
			
        }
        
		$responseObj->exam_detail_radioButton_table_data = $exam_detail_radioButton_table_data;
		//var_dump(json_encode($responseObj));
	    
		
	
	$get_total_sub_for_degree="select * from degree where FDEGREE='{$degree}'";
	$lobj_get_total_sub_for_degree = $aobj_context->pobj_db->GetAll($get_total_sub_for_degree); 
	$totsub = explode(',',$totsub);	

	

	for($j=0;$j<count($lobj_get_total_sub_for_degree);$j++)
		{
			if($lobj_get_total_sub_for_degree[$j]['FEXAMNO'] == 'A')
			{

				//var_dump($fcnta.' - '.$lobj_get_total_sub_for_degree[$j]['FEXAMNAME']);
				if($totsub[$j] > 0)
					$exam_A_limit = $totsub[$j];
				else if($fcnta > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_A_limit = $fcnta;
				else
					$exam_A_limit = $lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['A'] = $lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='B')
			{ 
				if($totsub[$j] > 0)
					$exam_B_limit = $totsub[$j];
				else if($fcntb > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_B_limit = $fcntb;
				else
					$exam_B_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['B']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='C')
			{
				if($totsub[$j] > 0)
					$exam_C_limit = $totsub[$j];
				else if($fcntc > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_C_limit = $fcntc;
				else
					$exam_C_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['C']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='D')
			{
				if($totsub[$j] > 0)
					$exam_D_limit = $totsub[$j];
				else if($fcntd > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_D_limit = $fcntd;
				else
					$exam_D_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];

				$semister_names['D']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='E')
			{
				if($totsub[$j] > 0)
					$exam_E_limit = $totsub[$j];
				else if($fcnte > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_E_limit = $fcnte;
				else
					$exam_E_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['E']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='F')
			{
				if($totsub[$j] > 0)
					$exam_F_limit = $totsub[$j];
				else if($fcntf > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_F_limit = $fcntf;
				else
					$exam_F_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['F']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}	
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='G')
			{
				if($totsub[$j] > 0)
					$exam_G_limit = $totsub[$j];
				else if($fcntg > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_G_limit = $fcntg;
				else
					$exam_G_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['G']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='H')
			{
				if($totsub[$j] > 0)
					$exam_H_limit = $totsub[$j];
				else if($fcnth > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_H_limit = $fcnth;
				else
					$exam_H_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['H']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='I')
			{
				if($totsub[$j] > 0)
					$exam_I_limit = $totsub[$j];
				else if($fcnti > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_I_limit = $fcnti;
				else
					$exam_I_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['I']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
			else if($lobj_get_total_sub_for_degree[$j]['FEXAMNO']=='J')
			{
				if($totsub[$j] > 0)
					$exam_J_limit = $totsub[$j];
				else if($fcntj > $lobj_get_total_sub_for_degree[$j]['FTOTSUB'])
					$exam_J_limit = $fcntj;
				else
					$exam_J_limit=$lobj_get_total_sub_for_degree[$j]['FTOTSUB'];
				
				$semister_names['J']=$lobj_get_total_sub_for_degree[$j]['FEXAMNAME'];
			}
		}


		$semister = array(); 
		
		foreach($semister_names as $k=>$v)   // All semester names
		{
			$FEXAMNO = chr($v);
			foreach($exam_appear as $kk=>$vv ) // Semester in which student is going to appear
			{
				$rowObj = "";
			   if($k==$vv)
			   {
				 $rowObj->semsester_name = $v;
				 $rowObj->FEXAMNO = $k;
				 $FEXAMNO = $k;

			
		        // How many subjects are there in each semester (Count) = $max_limit
				$max_limit="\$exam_".$k."_limit";  
				eval("\$max_limit = \"$max_limit\";");
				
		
				 // subject table header 
				 $subject_table_header = ["Sub Code","QP Code","Description","Checkbox"];
				 $rowObj->subject_table_header = $subject_table_header;
				 


                 // subject table data
				 $lobj_rs = get_subject_details($aobj_context,$degree,$college_code,$FEXAMNO,$regno,$max_limit);

				 $sub_details = array(); // for one semester subjects only

				 foreach($lobj_rs as $sub_key=>$sub_value)
				 {
					  $Obj ="";
					  $FSUBCODE = $sub_value['FSUBCODE'];
					  $FTHPR =  $sub_value['fthpr'];
					  $Fcounttype='count(1)';

					$get_theroy_cnt ="SELECT {$Fcounttype} AS t_cnt FROM subject 
					WHERE FDEGREE='{$degree}' AND fexamno='{$FEXAMNO}'
					AND FSUBCODE='{$FSUBCODE}' AND IFNULL(ftheory,'') = 'T' 
					AND IFNULL(fintass,'') <> 'T' AND IFNULL(fretain,'') <> 'T'  ";

					$lobj_get_theroy_cnt = $aobj_context->pobj_db->GetRow($get_theroy_cnt);
					$th_cnt=$lobj_get_theroy_cnt['t_cnt'];

					$get_prc_cnt="SELECT {$Fcounttype} AS p_cnt FROM subject 
					WHERE FDEGREE='{$degree}' AND fexamno='{$FEXAMNO}'
					AND FSUBCODE='{$FSUBCODE}' AND IFNULL(ftheory,'') <> 'T' 
					AND IFNULL(fretain,'') <> 'T'";
					$lobj_get_prc_cnt = $aobj_context->pobj_db->GetRow($get_prc_cnt);
					
					$pr_cnt = $lobj_get_prc_cnt['p_cnt'];
					if($th_cnt>1) $th_cnt=max(2,$th_cnt);
					if($pr_cnt>1) $pr_cnt=max(2,$pr_cnt);
					$FSUBSHORT = $sub_value['FSUBSHORT']; 
					$FSUBNAME  = $sub_value['FSUBNAME'];

					if($FTHPR == 'T')
						$FSUBNAME = $FSUBNAME." (Practical only)";
					else if($FTHPR == 'F')
						$FSUBNAME = $FSUBNAME." (Theory only)";
					else
						$FSUBNAME = $FSUBNAME;
					if($sub_value['FPASSMTH']=='' or is_null($sub_value['FPASSMTH']))// to display pass M/Y based on the  value
					{
						$fpass_month = "CheckBox";
					}
					else  
					{
						$FPASSMTH=$sub_value['FPASSMTH'];	
						//$Obj->FPASSMTH = $FPASSMTH;	
						$fpass_month = 	$FPASSMTH;		
					}

					$id.="<tr>";
						$id.="<td align='center' style='  font-size:12px;   border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'><input {$code_pop_up_field} {$inp_class} type=text style='width:55px;{$sub_code_input_border}' {$read_only} {$sub_code_input_popup} name='{$sub_code_input_name}'   id='exam_{$char_name}_ce_sub_code_{$txt_id}' {$input_tab_indx} value='{$FSUBCODE}'></td>";
						$id.="<td align='center'  style='  font-size:12px;   border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'id='exam_{$char_name}_ce_short_name_{$txt_id}' > {$FSUBSHORT}</td>";
						$id.="<td align='left' id='exam_{$char_name}_ce_desc_{$txt_id}'  style='  font-size:12px;    border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>   {$FSUBNAME}</td>";
						$id.="<td style='  font-size:12px;    border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;' align='center'  {$FPASSMTH_TD} >{$FPASSMTH} </td>";
						$id.="</tr>";   
						$k++;

					//$rowObj->FSUBCODE = $FSUBCODE;
					$f_sub_code = $FSUBCODE;
					//$rowObj->QPCODE = $FSUBSHORT;
					$qp_code = $FSUBSHORT;
					//$rowObj->FSUBNAME = $FSUBNAME;
					$f_sub_name = $FSUBNAME;

					$Obj->f_sub_code = $f_sub_code;
					$Obj->qp_code = $qp_code;
					$Obj->f_sub_name = $f_sub_name;
					$Obj->fpass_month = $fpass_month;
					$Obj->th_cnt =  $th_cnt;
					$Obj->pr_cnt = $pr_cnt;
        
					array_push($sub_details,$Obj);


				 }  // subject details loop ends
				 
				 $rowObj->sub_details = $sub_details;
				
				 
				 $li = $li;
				 $fullfee = 'no';
				if($FUNIVCODE=='023')
				{	
					if($category == 'SC' ||$category == 'ST')
					{
						$category =  $category;
					}
					else
					{
						$category = 'IIA';
					}
				}
				else
				{
						$category = 'IIA';
				}
				
				if($FUNIVCODE=='041' || $FUNIVCODE=='042')	
					$cnt = "if('{$pr_cnt}' > 0,FMAXFEE,FFEE)";
				else
					$cnt = "FMAXFEE";
				

			     // get fees of the particular semister		
				$lobj_get_fee_data = get_fee_details($aobj_context,$fullfee,$FEXAMNO,$CONSTYPE,$FFRESHEXAM,$degree,$category,$regno,$college_code,$cnt);

				$fee_cnt = count($lobj_get_fee_data)+1;
				$li = $li;
				$flag = 'F';  


				$fees_table_header = ["Fee Details","Amount"];
                $rowObj->fees_table_header = $fees_table_header;
                $fees_table_data = array();

				foreach($lobj_get_fee_data as $ak=>$av)
				{		
					$Obj="";
						      
					$tr.=" <tr class='ui-state-default ui-jqgrid-hdiv'>";
					$h_code = substr($av['FHEADCODE'],0,2);	
					$tr.="<td align='left' style='border-top:1px solid #C5DBEC ;border-left:1px solid #C5DBEC; ' id='tfh_{$char_name}_{$h_code}'>{$av[FHEADCODE]}</td>";

					  
                      $Obj->FHEADCODE = $av[FHEADCODE];
					 

					$input_val=$av['FFEE'];	
					//var_dump($flag);
					if($flag == 'T' && $av['FHEADCODE'] == '02 Exam Fee')
					{
						if($FUNIVCODE == '011')
						{
							$TH_FFEE = $av['O_FFEE']*5;	
							$FPRFEE = $av['FPRFEE']*5;
							$max_fee = $av['FMAXFEE']*5;
							
						}else
						{
							$TH_FFEE = $av['O_FFEE']*4;	
							$FPRFEE = $av['FPRFEE']*4;
							$max_fee = $av['FMAXFEE']*4;
						}			
					}else
					{
						$TH_FFEE  = $av['O_FFEE'];
						$FPRFEE  = $av['FPRFEE']; 
						$max_fee = $av['FMAXFEE'];
					}
				
						$tr.="<td  align='center'  style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;' > <input  type=hidden value='{$O_FFEE}' id='o_fee_{$char_name}_{$h_code}' /> <input  type=hidden value='{$FPRFEE}' id='prfee_{$char_name}_{$h_code}' />  <input  type=hidden value='{$max_fee}' id='minnfee_{$char_name}_{$h_code}' /> <input readonly='true' onblur='CalculateNewwFeeTotals();' style='border:none;text-align:center;;'  type=text value='0' id='nfee_{$char_name}_{$h_code}'></td>";
						$tr.=" </tr>";

						$Obj->TH_FFEE = $TH_FFEE;
						$Obj->FPRFEE = $FPRFEE;
						$Obj->max_fee = $max_fee; 

					array_push($fees_table_data,$Obj);
				}

				// pushing fees data to result
				$rowObj->fees_table_data = $fees_table_data;


				// select payment type
				$get_data="SELECT payment_type,bank_name FROM acc_mas where ifnull(fsuspend ,'') <> 'T' 
				order by forder";
				$lobj_payment_type= $aobj_context->pobj_db->GetAll($get_data); 
				
				$rowObj->payment_type = $lobj_payment_type;
				// $rowObj->status ="success";
				// $rowObj->FRESHEXAM = $FFRESHEXAM;
		        // $rowObj->error_code = 0;
				

				array_push($semister,$rowObj);
			   } // main if ends
			   
			   

			}
		} // all semester loop ends

		// $rowObj->status ="success";
        // $rowObj->FRESHEXAM = $FFRESHEXAM;
		// $rowObj->error_code = 0;
		if(sizeof($semister)==0)
		{
             $rowObj->status ="Failure";
             $rowObj->error_code = -1;
			$rowObj->data = "No data found!";
			echo json_encode($rowObj);
			return;
		}
		$resp ="";
		$resp->data = $semister;
		$resp->status = "success";
		$resp->FRESHEXAM = $FFRESHEXAM;
		$resp->error_code = 0;
        echo json_encode($resp);
	    	


}


function get_subject_details($aobj_context,$degree,$college_code,$FEXAMNO,$regno,$max_limit)
{
	
	$lquery="select c.FSUBCODE,s.FSUBNAME,
				ifnull(c.FPASSMTH,'') as FPASSMTH,
				s.FQPCODE AS FSUBSHORT,c.FEXAMTYPE,
				ifnull(c.FPRESENT,'N') as FPRESENT,
				if(c.FINSERTED='','F',c.FINSERTED) as FINSERTED,
				ifnull(c.fthpr,'') as fthpr 
				from canddet c 
				inner join subject s on s.FDEGREE=c.FDEGREE
				and s.fexamno = c.fexamno and s.FSUBCODE=c.FSUBCODE 
				where c.FDEGREE='{$degree}' and c.FCOLLCODE='{$college_code}' and 
				c.FEXAMNO='{$FEXAMNO}'  and
				c.FREGNO='{$regno}' group by c.FSUBCODE order by c.fsubcode,
				s.fqpcode desc limit $max_limit ";

				
				$lobj_rs = $aobj_context->pobj_db->GetAll($lquery); 

				return $lobj_rs;
}

function get_fee_details($aobj_context,$fullfee,$char_name,$CONSTYPE,$FFRESHEXAM,$degree,$category,$regno,$college_code,$cnt)
{
	$get_fee_data="SELECT  FHEADCODE,FFEE, 
	if('{$fullfee}' = 'yes','Normal Fee',if(instr('{$CONSTYPE}','{$char_name}') >0,'Low Income','Normal Fee')) as feetype, 
	IF('{$FFRESHEXAM}'='{$char_name}',FFEE,FREPFEE) AS O_FFEE,
	IF('{$FFRESHEXAM}'='{$char_name}',FPRFEE,FREPPRFEE) AS FPRFEE ,
	if('{$FFRESHEXAM}'='{$char_name}',{$cnt},FMAXFEE) as FMAXFEE
	FROM admfeestr a
	WHERE FDEGREE='{$degree}'
	AND FEXAMNO='{$char_name}'
	AND FCOMBCODE='EXAM' 
	AND FCATCODE='{$category}'
	and FCONSTYPE = if('{$fullfee}' = 'yes','Normal Fee',if(instr('{$CONSTYPE}','{$char_name}') >0,'Low Income','Normal Fee'))
	and ifnull(FADMFEESDATE,'') <> '' and ifnull(FADMFEEEDATE,'') <> ''
	and DATE_FORMAT(NOW(),'%Y-%m-%d') 
	BETWEEN DATE_FORMAT(FADMFEESDATE,'%Y-%m-%d') 
	AND DATE_FORMAT(FADMFEEEDATE,'%Y-%m-%d')				
	and IF(IFNULL(FREGRANGE,'') = '', '1=1', 
	1=1 and (INSTR(FREGRANGE,(CONCAT(SUBSTR('{$regno}',1,2),'*'))) > 0 
	or INSTR(FREGRANGE,(CONCAT(SUBSTR('{$regno}',1,4),'*'))) > 0
	or INSTR(FREGRANGE,(CONCAT(SUBSTR('{$regno}',1,5),'*'))) > 0))
	and IF(IFNULL(FCOLLRANGE,'') = '', '1=1', 
	1=1 and INSTR(FCOLLRANGE,(CONCAT('{$college_code}','*'))) <= 0)
	order by FHEADCODE";

	//var_dump($get_fee_data);

   $lobj_get_fee_data = $aobj_context->pobj_db->GetAll($get_fee_data); 
   return $lobj_get_fee_data;
}

function usaveCandidateEntryDetails($aobj_context){
		$FUNIVCODE = $aobj_context->mobj_data["univcode"];
		$req = $aobj_context->req_body;
		$reg_no = $req["regno"];
		$category = $req["category"];
		$payment_type = $req["payment_type"];
		$prevPhotoStatus = $req["prevPhotoStatus"];
		$fpaymode=$payment_type;

		$lquery="select date_format(current_date,'%d/%m/%Y') as curr_date,
		FDEGREE,FCOLLCODE,FNAME,FEXAMNO
		from student where   FREGNO='{$reg_no}'";	 
		$lobj_get_name = $aobj_context->pobj_db->GetRow($lquery);
		$college_code = $lobj_get_name['FCOLLCODE'];
		$degree = $lobj_get_name['FDEGREE'];
		$student_name = $lobj_get_name['FNAME'];
		$curr_date = $lobj_get_name['curr_date'];
		$fexamno = $lobj_get_name['FEXAMNO'];
		$moi = '';

		$lquery="select FAPPTO as last_date
		from collexam where fdegree='{$degree}'";	 
		$lobj_get_date = $aobj_context->pobj_db->GetRow($lquery);
		$last_date = $lobj_get_date['last_date'];
        
		if(empty($college_code))
		{
			$arr['data']='No details found for the student';
			echo $aobj_context->pobj_output->ToJSONEnvelope($arr,-1,"Failure");
			return;
		}

		$insert_app_candsum = InsertEmptyAppCandSumm($aobj_context,$FUNIVCODE,$college_code,$payment_type,$degree,$reg_no);

		$app_number = $insert_app_candsum->app_number;
		$insert_status = $insert_app_candsum->status;
        //var_dump($insert_app_candsum);
		if(!$insert_status)
		{
			$arr['data']='Error While Inserting AppCandSum';
			echo $aobj_context->pobj_output->ToJSONEnvelope($arr,-1,"Failure");
			return;
		}

		$total_fee = $req["total_fee"];
		$candidate_list_remarks = trim($req["candidate_list_remarks"]);
		$candidate_list_date = date("Y-m-d");
		include_once($aobj_context->main_src."/json.php"); 
		$json = new Services_JSON();

		$check_admission_freeze ="select distinct c.FCCLSTATUS, d.fmeyear, d.fmeexamtyp 
		from colldeg c, degree d 
		where c.fdegree = d.fdegree and c.FCOLLCODE='{$college_code}' 
		and c.FDEGREE='{$degree}'";								
		$lobj_check_admission_freeze = $aobj_context->pobj_db->getRow($check_admission_freeze); 

		$sub_arr_data = $req["subDetails"];
		
        

		for($k=0;$k<count($sub_arr_data);$k++)
		{
			$fexamno = $sub_arr_data[$k]['examno'];
			$SubCode = $sub_arr_data[$k]['SubCode'];
			$Finserted = $sub_arr_data[$k]['Finserted'];
					
			$FRESENT=$sub_arr_data[$k]['Fpresent'];			
			$insert_canddet_records = "insert into appcanddet 
			(appno,fdegree,fexamno,fcollcode,fregno,fsubcode,finserted,fpresent, fyear, fexamtype) 
			select distinct '{$app_number}',FDEGREE,'{$fexamno}',FCOLLCODE,
			FREGNO,'{$SubCode}','{$Finserted}','{$FRESENT}',
			FYEAR,FEXAMTYPE from candsum 
			where FDEGREE = '{$degree}' and FREGNO = '{$reg_no}'";
					
			$lobj_insert_canddet_records = $aobj_context->pobj_db->Execute($insert_canddet_records);
					
		}
		
		$update_appcanddet = "update appcanddet a, canddet b
			set a.fthpr = b.fthpr
			where a.fdegree = b.fdegree
			and a.fexamno = b.fexamno 
			and a.fsubcode = b.fsubcode
			and a.fregno = b.fregno
			and b.fdegree = '{$degree}'
			and b.fregno = '{$reg_no}'
			and ifnull(b.fthpr,'') <> ''";
			//var_dump($update_appcanddet);
			$lobj_insert_update_appcanddet = $aobj_context->pobj_db->Execute($update_appcanddet);	
			//var_dump($lobj_insert_update_appcanddet);
			

			$examno = $sub_arr_data[0]['examno'];
			$update_records="update appcandsum set  
			FEXAMFEE{$examno}='{$total_fee}' 
			where  FDEGREE='{$degree}' and  FCOLLCODE='{$college_code}' 
			and FREGNO='{$reg_no}'
			and APPNO='{$app_number}'";  
			$lobj_update_records = $aobj_context->pobj_db->Execute($update_records);
			

			$update_total_fee = "update appcandsum set FTOTALFEE={$total_fee},
		    FCATEGORY='{$category}', 
		    FFEETYPE = 'Normal Fee',		
		    FLOGDATE=now(),
		    FAPPLASTDATE = '{$last_date}'
		    where  FDEGREE='{$degree}' and 
		    FCOLLCODE='{$college_code}' 
		    and FREGNO='{$reg_no}' 
		    and APPNO='{$app_number}'";
		
		   $lobj_update_total_fee = $aobj_context->pobj_db->Execute($update_total_fee);
		   
		   $FeesDetails = $req["feesDetails"];
		
		   insertStudFeeDetails($aobj_context,$FUNIVCODE,$FeesDetails,$app_number,$degree,$examno,$college_code,$reg_no);

		   $query ="select * from masbank where ifnull(fsuspend,'') <> 'T'";								
		   $resmasbank = $aobj_context->pobj_db->getAll($query);
		  
		   if($lobj_update_total_fee) 
		   {
			$query ="select * from control";								
			$rescontrol = $aobj_context->pobj_db->getRow($query);
			$funivcode = $rescontrol['FUNIVCODE'];
			$arr['funivcode'] = $funivcode;
			$arr['fpaymode'] = $fpaymode;
			$arr['fappno'] = $app_number;
			$arr['fpaymode'] = $fpaymode;

			if($fpaymode=="Other Banks")
			{
				$isRazorPay = $req['isRazorPay'];
				$razorpayResp = pay_with_razorPay($aobj_context,$app_number,$total_fee);
                $arr['razorPay'] = $razorpayResp;
			}

			
	
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
			return;
		   }
		   else
		   {
			$arr='Updation failed';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"success"); 
			return;
		   }

		
		
							 
		
}


function insertStudFeeDetails($aobj_context,$FUNIVCODE,$FeesDetails,$app_number,$degree,$examno,$college_code,$reg_no)
{

	 for($k=0;$k<count($FeesDetails);$k++)
	 {

		$FFEECODE  = $FeesDetails[$k]['feecode'];
		$FAMOUNT   = $FeesDetails[$k]['amount'];

		$insert_into_student_fee="insert into appstudfee
						(
						APPNO,FDEGREE,FEXAMNO,FCOLLCODE,FREGNO,FFEECODE,FAMOUNT,FLOGDATE
						) VALUES
						(
						'{$app_number}',
						'{$degree}',
						'{$examno}',
						'{$college_code}',
						'{$reg_no}',
						'{$FFEECODE}',
						'{$FAMOUNT}',
						NOW()
						)";
						$lobj_insert_into_student_fee = $aobj_context->pobj_db->Execute($insert_into_student_fee);  
		


	 }   
}



function InsertEmptyAppCandSumm($aobj_context,$FUNIVCODE,$college_code,$payment_type,$degree,$reg_no)
	{
		// session_start();
		// $FUNIVCODE=$_SESSION['FUNIVCODE'];
		$app_number=GetNextNumber($aobj_context,$college_code);
	
			$insert="INSERT INTO  appcandsum 
					(APPNO, FDATE,FPAYMENTYPE,
					FDEGREE,FEXAMNO, FCOLLCODE, FREGNO, 
					FCATEGORY, 	FSEX, FAPPEARA, FEXAMFEEA, 
					FRECPTNOA, 	FRECPTDATEA, FAPPEARB, 
					FEXAMFEEB, 	FRECPTNOB, 	FRECPTDATEB, 
					FAPPEARC, 	FEXAMFEEC, FRECPTNOC, 
					FRECPTDATEC, FAPPEARD, 	FEXAMFEED, 
					FRECPTNOD, 	FRECPTDATED,FAPPEARE, 
					FEXAMFEEE, 	FRECPTNOE, 	FRECPTDATEE, FAPPEARF, 
					FEXAMFEEF, 	FRECPTNOF, 	FRECPTDATEF, 	FAPPEARG, 
					FEXAMFEEG, 	FRECPTNOG, 	FRECPTDATEG, 	FAPPEARH, 
					FEXAMFEEH, 	FRECPTNOH, 	FRECPTDATEH, FAPPEARI, 
					FEXAMFEEI, 	FRECPTNOI,	FRECPTDATEI, 
					FAPPEARJ, FEXAMFEEJ, 	FRECPTNOJ, 
					FRECPTDATEJ, FRECPTNO, FRECPTDATE, 	FTOTALFEE, 
					FREMARKS, 	FYEAR, 	FEXAMTYPE, 	FAPPNO, FCNTRCODE, 	FGENDER,FFRESHEXAM
					)
					 SELECT '{$app_number}',current_date(),'{$payment_type}',
					FDEGREE,FEXAMNO, FCOLLCODE, FREGNO, 
					FCATEGORY, 	FSEX, FAPPEARA, FEXAMFEEA, 
					FRECPTNOA, 	FRECPTDATEA, FAPPEARB, 
					FEXAMFEEB, 	FRECPTNOB, 	FRECPTDATEB, 
					FAPPEARC, 	FEXAMFEEC, FRECPTNOC, 
					FRECPTDATEC, FAPPEARD, 	FEXAMFEED, 
					FRECPTNOD, 	FRECPTDATED,FAPPEARE, 
					FEXAMFEEE, 	FRECPTNOE, 	FRECPTDATEE, FAPPEARF, 
					FEXAMFEEF, 	FRECPTNOF, 	FRECPTDATEF, 	FAPPEARG, 
					FEXAMFEEG, 	FRECPTNOG, 	FRECPTDATEG, 	FAPPEARH, 
					FEXAMFEEH, 	FRECPTNOH, 	FRECPTDATEH, FAPPEARI, 
					FEXAMFEEI, 	FRECPTNOI,	FRECPTDATEI, 
					FAPPEARJ, FEXAMFEEJ, 	FRECPTNOJ, 
					FRECPTDATEJ, FRECPTNO, FRECPTDATE, 	FTOTALFEE, 
					FREMARKS, 	FYEAR, 	FEXAMTYPE, 	FAPPNO, FCNTRCODE, 	FGENDER,FFRESHEXAM
					FROM candsum 	
					where  FDEGREE='{$degree}'
					AND FCOLLCODE='{$college_code}'
					AND  FREGNO='{$reg_no}'
					 LIMIT 1";
		
		
		$lobj_insert = $aobj_context->pobj_db->Execute($insert); 
		
		$returnObj ="";
		$returnObj->app_number = $app_number;
		if($lobj_insert)
		{

			$returnObj->status=true;
			return $returnObj;
		}
		else
		{
			$returnObj->status=false;
			return $returnObj;
		}
	}


	function GetNextNumber($aobj_context,$college_code)
	{
		
		$get_prefix_running_number = "select last_number from res_reval_code_generator
		where college_code = '{$college_code}' and type='Candidate' ";		
		$lobj_get_prefix_running_number = $aobj_context->pobj_db->GetAll($get_prefix_running_number); 

		
		$query= " Select FEXAMPREFIX from control";
		$result = $aobj_context->pobj_db->GetRow($query);
    
		if(!empty($lobj_get_prefix_running_number[0]['last_number']))
		{			
			$next_number = $lobj_get_prefix_running_number[0]['last_number'];
			$last_number = str_pad($next_number,4, "0", STR_PAD_LEFT);
		}
		else
		{	
			$next_number=0001;			
			$insert_into="insert into res_reval_code_generator(college_code,last_number,type)
			values
			(
			'{$college_code}',
			{$next_number},'Candidate'
			)";
			$lobj_insert_into = $aobj_context->pobj_db->Execute($insert_into);
			$last_number = str_pad($next_number,4, "0", STR_PAD_LEFT);		
		}
		UpdateNextNumber($aobj_context,$college_code);
		return $result['FEXAMPREFIX'].$college_code.$last_number;	
	}


	function UpdateNextNumber($aobj_context,$college_code)
	{							 
		$update_code_generator = "update res_reval_code_generator set last_number = last_number+1
		where college_code = '{$college_code}' and type='Candidate' ";
		$lobj_update_code_generator = $aobj_context->pobj_db->Execute($update_code_generator);
	}


	require('razorPayConfig.php');
	include('../razorpay/razorpay-php/Razorpay.php');
	use Razorpay\Api\Api;

	function pay_with_razorPay($aobj_context,$app_number,$total_fee)
	{
	 $api = new Api('rzp_test_FZazLkXZLydpKS', 'fy1e9wzLm5cEuc14gL7GLdNf');
 
	  
	 $number = rand(10000001,99999999);
 
	 $orderData = [
		 'receipt'         => $number,
		 'amount'          => $total_fee * 100, // 2000 rupees in paise
		 'currency'        => 'INR',
		 'payment_capture' => 1 // auto capture
	 ];
	 
	 $razorpayOrder = $api->order->create($orderData);
	 $razorpayOrderId = $razorpayOrder['id'];
 
	 $displayAmount = $amount = $orderData['amount'];
 
	 $displayAmount = $displayAmount / 100;
 
	 $query = "update collfundtransfer set forderid = '{$razorpayOrderId}', fpaymenttype = 'razorpay' 
	 where fid = '{$app_number}'";
	 
	 $result1 = $aobj_context->pobj_db->Execute($query);
	 $razorpayResp = "";
	 $razorpayResp->key = 'rzp_test_FZazLkXZLydpKS';
	 $razorpayResp->order_id = $razorpayOrderId;
	 $razorpayResp->amount = $displayAmount;
 
	 return $razorpayResp;
 
	}

?>