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.156.17


Current Path : /var/www/oasis/custom_src_old/
Upload File :
Current File : /var/www/oasis/custom_src_old/evaluation.php

<?php
class valuation
{
	public $internal_code;
	
		function __construct($aobj_context)
		{
			session_start();
			$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
			$this->aobj_context=$aobj_context;
			 include_once("/JSON.php"); 
			 $this->json = new Services_JSON();
			$this->user_id = $_SESSION['user_id'];		
			$this->user_type = $_SESSION['user_type'];	
			$this->collcode = $_SESSION['collcode'];
			$this->qp_packet_no = $aobj_context->mobj_data["qp_packet_no"]; 
			$this->qp_packet_no=str_pad($this->qp_packet_no, 4, "0", STR_PAD_LEFT);
			$this->qp_code = $aobj_context->mobj_data["qp_code"]; 			
			$this->val_no = $aobj_context->mobj_data["val_no"]; 
			$this->max_mark = $aobj_context->mobj_data["max_mark"]; 		 
			$this->teacher_id = $aobj_context->mobj_data["teacher_id"]; 		 
			
		}
		
       	function ValidatePacketNoDetails()
		{
			$get_packet_no="select count(*) as cnt from valqp
							where FCOLLCODE='{$this->collcode}' 
							and FQPCODE='{$this->qp_code}'
							and '{$this->qp_packet_no}' between lpad(FFRPAKCET,4,0) and lpad(FTOPACKET,4,0)
							";
		       //echo $get_packet_no; die();		
		  $lobj_get_packet_no = $this->aobj_context->mobj_db->GetRow($get_packet_no);
		  $cnt=$lobj_get_packet_no['cnt'];
		  
         	if($cnt>0)	
			{
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  	
			}
			else
			{
				$err_data="No Data"; 	 	
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($err_data,-1,"Failure");				
			}
				 
		}	
       	function insertDeviationSlNoInTabHeadDeatils()
		{
			$get_tab_head_cnt="select count(*) as dup_cnt from 
								tabhead 
								where FCOLLCODE='{$this->collcode}'
								and FQPCODE='{$this->qp_code}'
								and lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								and FVALNO='{$this->val_no}'";
			 $lobj_get_tab_head_cnt = $this->aobj_context->mobj_db->GetRow($get_tab_head_cnt);
			$dup_cnt=$lobj_get_tab_head_cnt[dup_cnt];
			if($dup_cnt==0)
			{
				$insert_qry=" insert into  tabhead  
							(FCOLLCODE, FQPCODE, FPACKET, FVALNO,FFREEZE)
							values
							(
							'{$this->collcode}',
							'{$this->qp_code}',
							'{$this->qp_packet_no}',
							'{$this->val_no}','F')";
				$lobj_insert_qry = $this->aobj_context->mobj_db->Execute($insert_qry);
				 
				if($lobj_insert_qry)
				{
					$insert_details=" insert into tabdetl
								(FCOLLCODE, FQPCODE, FPACKET, FVALNO, FSLNO)
								select '{$this->collcode}',FQPCODE,FPACKET,'{$this->val_no}',FSLNO
								from tabsummary	where FQPCODE='{$this->qp_code}'
								and lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								group by FSLNO";
					$lobj_insert_qry = $this->aobj_context->mobj_db->Execute($insert_details);	
 			
				}
			}
			echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
		}
		function ValidateValNoDetails()
		{
			if($this->val_no== 3 or $this->val_no==5) // Check Devtaion Flag is True in tab_Summary
			{
				$get_flag="select FDEVIATION from tabsummary
							where FQPCODE='{$this->qp_code}'
							and lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
							and  FDEVIATION='T'";
				 $lobj_get_val_no = $this->aobj_context->mobj_db->GetRow($get_flag);
				 //echo $get_flag;
				$dev_flag= $lobj_get_val_no['FDEVIATION'];
				if(empty($dev_flag))
				{
					$err_data="No Deviation Found for the selected combination"; 	 	
					echo $this->aobj_context->mobj_output->ToJSONEnvelope($err_data,-1,"Failure");
					return	;
				}
				else
				{
					return $this->insertDeviationSlNoInTabHeadDeatils();
				}	
			}
			$get_val_no="select count(*) as cnt from valqp
							where FCOLLCODE='{$this->collcode}' 
							and FQPCODE='{$this->qp_code}'							
							and FVALNO='{$this->val_no}'
                            and '{$this->qp_packet_no}' 
							between lpad(FFRPAKCET,4,0) and lpad(FTOPACKET,4,0) 							
							";	
           $lobj_get_val_no = $this->aobj_context->mobj_db->GetRow($get_val_no);		  
		   $cnt=$lobj_get_val_no['cnt'];
			 //echo $get_val_no;
			if($cnt>0)	
			{
				$check_freezed="select  count(*) as cnt from tabhead
								where  FCOLLCODE='{$this->collcode}' 
							and FQPCODE='{$this->qp_code}'							
							and FVALNO='{$this->val_no}'
							and lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
							and FFREEZE='T'";
				$lobj_check_freezed = $this->aobj_context->mobj_db->GetRow($check_freezed);	
				$cnt=$lobj_check_freezed['cnt'];
				if($cnt>=1)
				{
				$err_data="Its Allready Freezed"; 	 	
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($err_data,-1,"Failure");	
				}
				else
				{
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  	
				}
			}
			else
			{
			    $err_data="No Data"; 	 	
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($err_data,-1,"Failure");	
			}
		   
		}	
		
		function GetTeacherName()
		{
			$get_teacher_name="select FTEACHNAME from masteach 
									  where FTEACHCODE='{$this->teacher_id}'";	
           							
		   $lobj_get_teacher_name = $this->aobj_context->mobj_db->GetRow($get_teacher_name);		
			
			if($lobj_get_teacher_name)	
			{
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($lobj_get_teacher_name,0,"success");  	
			}
			else
			{
			    $err_data="Invalid Teacher Id"; 	 	
				echo $this->aobj_context->mobj_output->ToJSONEnvelope($err_data,-1,"Failure");	
			}
		   
		}		
		 
		function GetPacketDetails()
		{
            $get_packet="select lpad(FSLNO,2,'0') as FSLNO ,
						case when FTOTMARKS  is null 
						then '' 
						when FTOTMARKS=0
						then '0' 
						when FTOTMARKS =-1
						then ''
						when FTOTMARKS =-3
						then 'MP'
						else 
						round(FTOTMARKS)
						end as FTOTMARKS,
						concat(ifnull(FQ01,''),',',ifnull(FQ02,''),',',ifnull(FQ03,''),',',ifnull(FQ04,''),',',
						ifnull(FQ05,''),',',ifnull(FQ06,''),',',ifnull(FQ07,''),',',ifnull(FQ08,''),',',
						ifnull(FQ09,''),',',ifnull(FQ10,''),',',ifnull(FQ11,''),',',ifnull(FQ12,''),',',
						ifnull(FQ13,''),',',ifnull(FQ14,''),',',ifnull(FQ15,''),',',ifnull(FQ16,''),',',
						ifnull(FQ17,''),',',ifnull(FQ18,''),',',ifnull(FQ19,''),',',ifnull(FQ20,''),',',
						ifnull(FQ21,''),',',ifnull(FQ22,''),',',ifnull(FQ23,''),',',ifnull(FQ24,''),',',
						ifnull(FQ25,''),',',ifnull(FQ26,''),',',ifnull(FQ27,''),',',ifnull(FQ28,''),',',
						ifnull(FQ29,''),',',ifnull(FQ30,'')) as MARKS,FTEACHCODE							
						from tabhead th
						inner join tabdetl td on td.FCOLLCODE=th.FCOLLCODE						
						and
						td.FQPCODE=th.FQPCODE
						and 
						td.FPACKET=th.FPACKET and td.FVALNO=th.FVALNO
						and th.FCOLLCODE=td.FCOLLCODE
						and lpad(th.FPACKET,4,'0')='{$this->qp_packet_no}'
						and th.FQPCODE='{$this->qp_code}'
						and th.FVALNO='{$this->val_no}'	
						order by lpad(FSLNO,2,'0')							
						";		    			
			$lobj_get_packet = $this->aobj_context->mobj_db->GetAll($get_packet);	
 //echo $get_packet;			
 			
			$teach_code=$lobj_get_packet[0]['FTEACHCODE'];
			$get_teach_data="select FTEACHCODE,FTEACHNAME from masteach where FTEACHCODE={$teach_code}";
			$lobj_get_teach_data = $this->aobj_context->mobj_db->GetRow($get_teach_data);
			$packet_html.="<table border='0' cellpadding='0' class='packet_table' cellspacing='0' width='100%'>";
			$packet_html.="<th colspan='2' class='th_class'>PACKET DETAILS</th>";
			$packet_html.="<tr class='tr_bg_color'>";
			$packet_html.="<td>Sl.No.</td>";
			$packet_html.="<td class='td_border'>Marks</td></tr>";

			
			$cnt=1;
			$onfocus="";
			foreach($lobj_get_packet as $k=>$v)
			{
			  
			  $FSLNO= ($v[FSLNO]);
			  $FSLNO=str_pad($FSLNO, 2, "0", STR_PAD_LEFT);
			  $FTOTMARKS=$v[FTOTMARKS];			  
			  $MARKS=$v[MARKS];
			  $onfocus="";
			 
			  $tab_indx=" tabindex=-1 ";
			  $tab_indx="   ";
               if($cnt==1)
                {
				 $onfocus="onfocus=\"ChangeCellColorAssignIdOnClick('{$FSLNO}')\"";  
				 $tab_indx="";				 
				}
			
				
				$cnt++;	
						
  
			   $packet_html.="<tr class='tr_height'>";
			   $packet_html.="<td style='border-left:1px solid #a0140d;'><input type='hidden' id='txt_hidden_$FSLNO' value='{$MARKS}'>{$FSLNO}</td>";
			   $packet_html.="<td style='border-right:1px solid #a0140d; cursor:pointer;' id='td_mark_$FSLNO'><input type='text' onkeydown=\"ChangeCellColorAssignIdOnKeyPress('{$FSLNO}');\" onclick=\"ChangeCellColorAssignIdOnClick('{$FSLNO}')\"  ondblclick=\"OnDbClickSlNo('{$FSLNO}');\" {$onfocus} onblur='checkMaxValMarks(this);' id='i_mark_$FSLNO' style='cursor:pointer; font-weight:700; text-align:right;' {$tab_indx} onkeypress='return AcceptNumbersOnly(event);'  maxlength='3' value='{$FTOTMARKS}'/></td>";
			   $packet_html.="</tr>";				   		   
			}            		
			 $final_html=$packet_html."</table><br>".$buttom_html;
			 
			$arr['html']= $packet_html;
			$arr['packet']= $lobj_get_packet;
			$arr['teacher_data']= $lobj_get_teach_data;
			echo $this->aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");  			
					
		}
		
		function SaveEvaluation()
		{				
			 $lstr_param = stripslashes($this->aobj_context->mobj_data["valuation_packet_details"]);
			 $teach_id =  ($this->aobj_context->mobj_data["evaluation_teacher_id"]);
			 $this->mobj_jsondata = $this->json->decode($lstr_param);
			 $this->larr_output_details = get_object_vars($this->mobj_jsondata);
		 
		 	for( $i = 0; $i < count($this->larr_output_details); $i++ )
			{		
				$update_header=" update  tabhead set 
								FTEACHCODE='{$teach_id}',FFREEZE='F' 
								, FENTDATE=now()
								 where FCOLLCODE='{$this->collcode}'
								 and
				                 FQPCODE='{$this->qp_code}'
								 and
				                 lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								 and
				                 FVALNO='{$this->val_no}'";
				$lobj_update_header= $this->aobj_context->mobj_db->Execute($update_header);		
			 	
			   	$f_marks_arr=explode(",",$this->larr_output_details[$i]->f_marks);		   
				
                $update_packets="update tabdetl set 							 
								 FQ01='{$f_marks_arr[0]}',FQ02='{$f_marks_arr[1]}',
								 FQ03='{$f_marks_arr[2]}', FQ04='{$f_marks_arr[3]}',
								 FQ05='{$f_marks_arr[4]}', FQ06='{$f_marks_arr[5]}',
								 FQ07='{$f_marks_arr[6]}', FQ08='{$f_marks_arr[7]}',
								 FQ09='{$f_marks_arr[8]}', FQ10='{$f_marks_arr[9]}',
								 FQ11='{$f_marks_arr[10]}', FQ12='{$f_marks_arr[11]}',
								 FQ13='{$f_marks_arr[12]}', FQ14='{$f_marks_arr[13]}',
								 FQ15='{$f_marks_arr[14]}', FQ16='{$f_marks_arr[15]}',
								 FQ17='{$f_marks_arr[16]}', FQ18='{$f_marks_arr[17]}',
								 FQ19='{$f_marks_arr[18]}', FQ20='{$f_marks_arr[19]}',
								 FQ21='{$f_marks_arr[20]}', FQ22='{$f_marks_arr[21]}',
								 FQ23='{$f_marks_arr[22]}', FQ24='{$f_marks_arr[23]}',
								 FQ25='{$f_marks_arr[24]}', FQ26='{$f_marks_arr[25]}',
								 FQ27='{$f_marks_arr[26]}', FQ28='{$f_marks_arr[27]}',
								 FQ29='{$f_marks_arr[28]}', FQ30='{$f_marks_arr[29]}',								  
								 FTOTMARKS='{$this->larr_output_details[$i]->packet_total}'								 
								 
                                 where FCOLLCODE='{$this->collcode}'
								 and
				                 FQPCODE='{$this->qp_code}'
								 and
				                 lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								 and
				                 FVALNO='{$this->val_no}'	
								 and								 
								 lpad(FSLNO,2,'0')='{$this->larr_output_details[$i]->sl_no_val}'									 
								 ";	 		 
				
				$lobj_update_packets = $this->aobj_context->mobj_db->Execute($update_packets);	
					
				 $get_check_no=$this->GetCheckSumNo();
				
				$update_check_sum=" update  tabhead set 
								 FFREEZE='F',FCHKNO={$get_check_no}
								 where FCOLLCODE='{$this->collcode}'
								 and
				                 FQPCODE='{$this->qp_code}'
								 and
				                 lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								 and
				                 FVALNO='{$this->val_no}'";
				$lobj_update_update_check_sum= $this->aobj_context->mobj_db->Execute($update_check_sum);
				
			}			
			$this->updateSummaryTable();	
			if($lobj_update_packets)
				    {
				        $rdata = "Inserted Successfully.";
				        print_r($this->aobj_context->mobj_output->ToJSONEnvelope($rdata,0,"success"));				      
				     }
				    else
				    {
				        $rdata = "There was a problem while inserting.Please Check it Once Again ";
				        print_r($this->aobj_context->mobj_output->ToJSONEnvelope($rdata,-1,"Failure"));  
					}			
				    
		}
		function updateSummaryTable()
		{
			$get_devaition_marks="select ifnull(FDEVMARK,0) as  FDEVMARK,FNOVAL from masqp where FQPCODE='{$this->qp_code}'";
			$lobj_get_devaition_marks= $this->aobj_context->mobj_db->GetRow($get_devaition_marks);
			$devaition_marks=$lobj_get_devaition_marks[FDEVMARK];
			$FNOVAL=$lobj_get_devaition_marks[FNOVAL];
			$select_saved_data="select FQPCODE,FPACKET,FVALNO,FTOTMARKS,
								lpad(FSLNO,2,'0') as FSLNO from tabdetl								 
								 where FCOLLCODE='{$this->collcode}'
								 and  FQPCODE='{$this->qp_code}'
								 and  lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								 and  FVALNO='{$this->val_no}'";
			$lobj_select_saved_data= $this->aobj_context->mobj_db->GetAll($select_saved_data);	
			foreach($lobj_select_saved_data as $k=>$v)
			{
				$FQPCODE=$v[FQPCODE];
				$FPACKET=$v[FPACKET];
				$FVALNO=$v[FVALNO];
				$val_field="v{$FVALNO}";
				$FSLNO=$v[FSLNO];
				$FTOTMARKS=$v[FTOTMARKS];
				$get_cnt="select count(*) as insert_cnt from tabsummary
								where FQPCODE='{$FQPCODE}'
								 and  lpad(FPACKET,4,'0')='{$FPACKET}'
								 and  lpad(FSLNO,2,'0')='{$FSLNO}'";
				$lobj_get_cnt= $this->aobj_context->mobj_db->GetRow($get_cnt);
				if($lobj_get_cnt[insert_cnt]==0)
				{				
					$insert="insert into tabsummary
							(FQPCODE, FPACKET, FSLNO, {$val_field},FDEVIATION)
							values('{$FQPCODE}','{$FPACKET}','{$FSLNO}',{$FTOTMARKS},'F')";
					$lobj_get_cnt= $this->aobj_context->mobj_db->Execute($insert);		
				}
				else
				{
					$update="update tabsummary set {$val_field}={$FTOTMARKS},FDEVIATION='F'
								where FQPCODE='{$FQPCODE}'
								 and  lpad(FPACKET,4,'0')='{$FPACKET}'
								 and  lpad(FSLNO,2,'0')='{$FSLNO}'";
					$lobj_get_cnt= $this->aobj_context->mobj_db->Execute($update);
					 	
				}	
			}
			if($FVALNO>1)
			{	
				$diff="";
				$cond="";
				if($FNOVAL==2)
				{
					$diff="  greatest(ifnull(v1,0),ifnull(v2,0)) - least(ifnull(v1,0),ifnull(v2,0))  ";
					$cond=" and v1 is not null and v2 is not null";
				}
				else if($FNOVAL==3)
				{
					$diff="  greatest(ifnull(v1,0),ifnull(v2,0),ifnull(v3,0)) - least(ifnull(v1,0),ifnull(v2,0),ifnull(v3,0))  ";
					$cond=" and v1 is not null and v2 is not null and v3 is not null";
				}else if($FNOVAL==4)
				{
					$diff="  greatest(ifnull(v1,0),ifnull(v2,0),ifnull(v3,0),ifnull(v4,0)) - least(ifnull(v1,0),ifnull(v2,0),ifnull(v3,0),ifnull(v4,0))  ";
					$cond=" and v1 is not null and v2 is not null and v3 is not null and v4 is not null";
				}
			$update_flag="update tabsummary set 
							FDEVIATION=if(abs({$diff})>={$devaition_marks},'T','F')
							where FQPCODE='{$FQPCODE}'
							 and lpad(FPACKET,4,'0')='{$FPACKET}'
							 {$cond}";	
							  
			$lobj_get_cnt= $this->aobj_context->mobj_db->Execute($update_flag);					
			}
		}
		function GetCheckSumNo()
		{
			$get_sum_of_marks="select sum(FTOTMARKS) as total_sum from tabdetl  
								where FCOLLCODE='{$this->collcode}'
								 and
				                 FQPCODE='{$this->qp_code}'
								 and
				                 lpad(FPACKET,4,'0')='{$this->qp_packet_no}'
								 and  FVALNO='{$this->val_no}'";
			
			$random_no=rand(1,5);
			return $random_no;
		}
 }	 
	
function GetPacketDetails($aobj_context)
{
	$valu_obj=new valuation($aobj_context);
	$valu_obj->GetPacketDetails();		
}

function ValidatePacketNoDetails($aobj_context)
{
	$valu_obj=new valuation($aobj_context);
	$valu_obj->ValidatePacketNoDetails();		
}
function ValidateValNoDetails($aobj_context)
{
	$valu_obj=new valuation($aobj_context);
	$valu_obj->ValidateValNoDetails();		
}

function SaveEvaluation($aobj_context)
{
	$valu_obj=new valuation($aobj_context);
	$valu_obj->SaveEvaluation();		
}
function GetTeacherName($aobj_context)
{
	$valu_obj=new valuation($aobj_context);
	$valu_obj->GetTeacherName();		
} 
?>