<?php
class index
{
	function slider($type="BANNER")
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from slider where  status=1  and type='".$type."'");
		if(is_array($contentDetail) && count($contentDetail)>0){$i=0;
			foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				$conDetail[$i]["no"]=$i;
				$galleryDetail=$db->getRows("select content from slider_content where sliderid='".$cdetail["id"]."' ");$j=0;
				if(is_array($galleryDetail) && count($galleryDetail)>0){$k=62;$start=2000;
					foreach($galleryDetail as $gDetail){$j++;
						$conDetail[$i]["detailInfo"][$j]=$gDetail;
						//$conDetail[$i]["detailInfo"][$j]["detail"]=nl2br($gDetail["detail"]);
						$k=$k+32;$start=$start+200;
						$conDetail[$i]["detailInfo"][$j]["start"]=$start;
						$conDetail[$i]["detailInfo"][$j]["k"]=$k;
					}
				}
			}
		}
		return $conDetail;
	}
	
	function extra_content($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from content where type='".$type."' and status=1 order by id DESC");
		if(is_array($contentDetail) && count($contentDetail)>0){$i=0;
			foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				if($i%2==0)$conDetail[$i]["slide"]="slide-left";else $conDetail[$i]["slide"]="slide-right";
				$conDetail[$i]["nonhtml"]=trim(strip_tags(unPOST($cdetail["content"])));
				$conDetail[$i]["no"]=$i;
				$conDetail[$i]["type"]=$db->getVal("select linkname from ".CONTENT_HEAD." where heading='".$type."' and status=1"); 
				$conDetail[$i]["content"]=ucfirst(unPOST($cdetail["content"]));
				$conDetail[$i]["Name"]=unPOST($cdetail["Name"]);
				$conDetail[$i]["url"]=href("newupdates.php","id=".$cdetail["id"]."&type=".$cdetail["type"]);
				
				$conDetail[$i]["photourl"]=href("photogallery.php","id=".$cdetail["id"]."&type=".$cdetail["type"]);
					$conDetail[$i]["TYPE"]=unPOST($cdetail["type"]);

				//$conDetail[$i]["url"]="newupdates.php?id=".$cdetail["id"]."-".$cdetail["type"];
				$conDetail[$i]["social"]=json_decode($cdetail["extra"],true);
			}
		}
		return $conDetail;
	}
	
	function solo_extra_content($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from content where type='".$type."' and status=1 order by id DESC");
		if(is_array($contentDetail) && count($contentDetail)>0){$i++;
					//return $contentDetail;
					$conDetail=$contentDetail;
					$conDetail["photourl"]=href("photogallery.php","id=".$contentDetail["id"]."&type=".$contentDetail["type"]);
					
				  }
		//return $db->getErMsg()."||".$db->getLastQuery();
		return $conDetail;
	}
	
	
	
	function allphotos($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from content where type='".$type."' and status=1 order by id DESC");
		if(is_array($contentDetail) && count($contentDetail)>0){$i++;
					//return $contentDetail;
				foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				
				}
					
					
				  }
		//return $db->getErMsg()."||".$db->getLastQuery();
		return $conDetail;
	}
	
	
	
	function review($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from ".REVIEWS." where  status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){$i=0;
			foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				if($i%2==0)$conDetail[$i]["slide"]="slide-left";else $conDetail[$i]["slide"]="slide-right";
				$conDetail[$i]["nonhtml"]=strip_tags(unPOST($cdetail["content"]));
				$conDetail[$i]["no"]=$i;
				$conDetail[$i]["content"]=unPOST($cdetail["content"]);
				$conDetail[$i]["social"]=json_decode($cdetail["extra"],true);
			}
		}
		return $conDetail;
	}
	
	function new_updates($type)
	{
		global $db;
		$conDetail=array();
		$cdetail = $db->getRow("select * from ".CONTENT." where  id='".$type."' and status=1");
		if(is_array($cdetail) && count($cdetail)>0){
			$conDetail=$cdetail;
			$conDetail["nonhtml"]=strip_tags(unPOST($cdetail["content"]));
			//$conDetail["content"]=unPOST($cdetail["content"]);
			$conDetail["content"]=ucfirst(strtolower(unPOST($cdetail["content"])));
			$conDetail["Name"]=ucfirst(strtolower($cdetail["Name"]));
			$conDetail["social"]=json_decode($cdetail["extra"],true);
		}
		return $conDetail;
	}
	
	function new_jobs($type)
	{
		global $db;
		$conDetail=array();
		$cdetail = $db->getRow("select * from ".CONTENT." where  id='".$type."' and status=1");
		if(is_array($cdetail) && count($cdetail)>0){
			$conDetail=$cdetail;
			$conDetail["nonhtml"]=strip_tags(unPOST($cdetail["content"]));
			$conDetail["content"]=unPOST($cdetail["content"]);
			$conDetail["social"]=json_decode($cdetail["extra"],true);
		}
		return $conDetail;
	}
	
	function new_forms($type)
	{
		global $db;
		$conDetail=array();
		$cdetail = $db->getRow("select * from ".CONTENT." where  id='".$type."' and status=1");
		if(is_array($cdetail) && count($cdetail)>0){
			$conDetail=$cdetail;
			$conDetail["nonhtml"]=strip_tags(unPOST($cdetail["content"]));
			$conDetail["content"]=unPOST($cdetail["content"]);
			$conDetail["social"]=json_decode($cdetail["extra"],true);
		}
		return $conDetail;
	}
	
	function student_response($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from ".CONTENT." where  id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){$i=0;
			foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				if($i%2==0)$conDetail[$i]["slide"]="slide-left";else $conDetail[$i]["slide"]="slide-right";
				$conDetail[$i]["nonhtml"]=strip_tags(unPOST($cdetail["content"]));
				$conDetail[$i]["no"]=$i;
				$conDetail[$i]["content"]=unPOST($cdetail["content"]);
				$conDetail[$i]["social"]=json_decode($cdetail["extra"],true);
			}
		}
		return $conDetail;
	}
	
	function myDetail($id)
	{
		global $db;
		$conDetail=array();
		
		$cdetail = $db->getRow("select * from student where idno='".$id."' ");
		
		if(is_array($cdetail) && count($cdetail)>0){
			$conDetail=$cdetail;
			$conDetail["no"]=$i;
			$class_name=$cdetail['class'];
			
			
			
			//$conDetail["added_byid"]=$added_by;
			$conDetail["class_name"]=$class_name;
		

		}
	
		return $conDetail;
	}
	
	function profile($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from student where idno='".$type."' and status=1");
		
		if(is_array($contentDetail) && count($contentDetail)>0)
		{
		   return $contentDetail;
		}
		else{
			return $db->getErMsg()."||".$db->getLastQuery();
		}
	
	}
	
	function stu_notice($type)
	{
		global $db;
		$conDetail=array();
if(trim($type)=="")
{
$type=$_SESSION['user']['uid'];
}		
//		$class=$db->getVal("select class from ".STUDENT." where idno=".$type );

		$class=$db->getRow("select * from student where idno=".$type );
		

		$contentDetail =$db->getRows("select * from student_notice where (class='".$class['class']."' or class='')  and status=1 order by date DESC ");


		if(is_array($contentDetail) && count($contentDetail)>0)
		{
			foreach($contentDetail as $cDetail)
			{
//echo"<pre>";print_r($cDetail);exit;		
$notice_type=$db->getVal("select notice_type from  notice where id=".$cDetail['notice_type']);
	$cDetail['notice_type_name']=$notice_type;
//	$cDetail['notice_type_name']=$db->getLastQuery();

				$studentid=explode(",",$cDetail["student_id"]);
				if(!in_array($type,$studentid))
				{
				
				 $conDetail[]=$cDetail;
				}
			}
		}
		//echo $db->getLastQuery()."<pre>";print_r($contentDetail);exit;
		return $conDetail;
	}
	
	function assignment($type)
	{
		global $db;
		$conDetail=array();
//		$class=$db->getVal("select class from ".STUDENT." where idno=".$type );

		$stu_detail=$db->getRow("select * from student where idno=".$type );

	
		$contentDetail = $db->getRows("select * from assignment where class='".$stu_detail['class']."' " );

		
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				//$conDetail=$contentDetail;
				foreach($contentDetail as $cdtl )
				{
								$eary=explode(',',$cdtl['student_id']);
						if(!in_array($type,$eary))
						{
						$conDetail[]=$cdtl;
						}
				}
		}
		return $conDetail;
	}

	function viewassignment($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from assignment where id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				//$conDetail=$contentDetail;
				$conDetail=$contentDetail;
						
		}
		return $conDetail;
	}
	
	function viewnotice($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from ".STUDENT_NOTICE." where id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				//$conDetail=$contentDetail;
				$conDetail=$contentDetail;
						
		}
		return $conDetail;
	}
	
	function viewcomplain($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from complain where id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				//$conDetail=$contentDetail;
				$conDetail=$contentDetail;
						
		}
		return $conDetail;
	}
	
	function viewvacancies($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from ".CONTENT." where id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				//$conDetail=$contentDetail;
				$conDetail=$contentDetail;
				$conDetail["content"]=unPOST($contentDetail["content"]);		
		}
		return $conDetail;
	}
	
	function viewapproch($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from ".CONTENT." where id='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){
			//$conDetail=$contentDetail;
			$conDetail=$contentDetail;
			$conDetail["content"]=unPOST($contentDetail["content"]);
						
		}
		return $conDetail;
	}
	
	function student_profile($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRows("select * from ".STUDENT." where idno='".$type."' and status=1");
		if(is_array($contentDetail) && count($contentDetail)>0){$i=0;
			foreach($contentDetail as $cdetail){$i++;
				$conDetail[$i]=$cdetail;
				$conDetail[$i]["no"]=$i;
				$class_name=$db->getVal("select class_name from ".CCLASS." where id='".$cdetail["class"]."' and status='1'");
				$subject_name=$db->getVal("select subject_name from ".SUBJECT." where id='".$cdetail["subject"]."' and status='1'");
				
				$conDetail[$i]["class"]=$class_name;
				$conDetail[$i]["subject"]=$subject_name;
			}
		}
		return $conDetail;
	}
	
		
	function get_papers($class)
	{
		global $db;
		//echo "$class $subject";exit;
		if($uid==0)
		{
			$uid=$_SESSION['user']['uid'];	
		}
		$conDetail=array();
		
		$conDetail= $db->getRows(" select * from papers where class='".$class."'  and status=1  order by lorder ASC");

		//return $conDetail;
		
		if(is_array($conDetail) && count($conDetail)>0){
			foreach($conDetail as $cd)
			{
				$no_approve=$db->getVal("select id from disallocate where paper_id=".$cd["id"]." and student_id=".$uid);


			  if($no_approve==""){
					
				$checkattnd=$db->getRow("select * from result where paper_id=".$cd['id']." and student_id=".$uid  );

					
				  if(!empty($checkattnd) )
				   {
						if($checkattnd['status']==1)
						{
							$reattempt=$db->getVal(" select count(*) from reattempt where status='1' and pid=".$checkattnd['pid']." and student_id=".$uid." ");		
							if($reattempt>0)
							{
								$cd['attempted']=3;	
							}else{
								$cd['attempted']=1;	
							}
						
						}else{
							
							$diff=$this->timediff($checkattnd['exp_date']);
							$cd['attempted']=1;
							if($diff=='false')
							{
								$this->updtppr($checkattnd['pid'],$checkattnd['user_id']);
							}else { 
								$cd['attempted']=0;
							}
						} 
				   }else{
						$cd['attempted']=0;
				   }
					$cdtl[]=$cd;
				}
			}
		}
							
		return $cdtl ;
	}
	
	function updtppr($pid,$uid)
	{  global $db;
	
	$arry=array('status'=>1);
	$update=$db->updateAry(EXAMDETAILS,$arry," where pid=$pid and user_id=$uid");
	
		if($update>0)
		{
			$all_q=$db->getRows("select * from ".EXAMDETAILS." where pid=$pid and user_id=$uid and status=1");
	
	$ttl=0;
$c=array();	
			if($all_q>0)
				{	
					foreach($all_q as $qs)
						{
							$rs=checkans($qs['qid'],$qs['answer']);
							if($rs>0)
							{
								$c[]=$qs['qid'];
							}else{
								$w[]=$qs['qid'];
							}
							
						 $ttl++;	
						}
					
					$uc['ans_status']=1;
					for($ca=0;$ca<count($c);$ca++)
					{
					  $updt=$db->updateAry(EXAMDETAILS,$uc," where pid=$pid and user_id=$uid and qid=".$c[$ca]);
						
					}
								
					$uw['ans_status']=0;
					for($wa=0;$wa<count($w);$wa++)
					{
						$updt=$db->updateAry(EXAMDETAILS,$uw," where pid=$pid and user_id=$uid and qid=".$w[$wa]);
						
					}
					$status['status']=1	;
					$updt=$db->updateAry(RESULT,$status," where pid=$pid and user_id=$uid " );
					if($updt>0)
					{	
						//redirect("result_view.php?pid=".$pid."&uid=".$uid);	 
					}else{
						echo "<hr>error sss".$db->getLastQuery().$db->getErMsg();exit;
					 }
				
				}
			//else{echo "<hr>error hhh".$db->getLastQuery().$db->getLastQuery();}
				
		}else{
		$count_ed=$db->getVal("select count(*) from ".EXAMDETAILS." where pid=$pid and user_id=$uid");			
		if($count_ed==0)
			{
				$update=$db->updateAry(RESULT,$arry," where pid=$pid and user_id=$uid");
			}	
	    }
	//else{echo "error ".$db->getLastQuery().$db->getErMsg();}
	 }
	function timediff($e)
	{
	global $db;
		$odt=strtotime($e)-strtotime(date('Y-m-d H:i:s'));
		if($odt>0){$odt="true";}else{$odt="false";}
	 return $odt;	
	}
	
	function total_fee($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail = $db->getRow("select * from ".FEE_COLLECT." where student_id='".$type."' and status=1 ");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				$conDetail=$contentDetail;
						
		}
		return $conDetail;
	}
	
	function all_transation($type)
	{
		global $db;
		$conDetail=array();
		$fees_Form=$db->getRows("SELECT * FROM ".FEE_DETAIL." WHERE student_id='".$type."'");
  		$conDetail=$fees_Form;
		return $conDetail;
	}
	
	function complain($type)
	{
		global $db;
		$conDetail=array();
		$contentDetail=$db->getRows("SELECT * FROM complain where student_id='".$type."' ORDER BY udate DESC" );
		//echo $db->getLastQuery();die('done');
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				$conDetail=$contentDetail;
$i=0;
				foreach($contentDetail as $cDetail){

					//$conDetail[$i]['complain_date']=ago($cDetail['udate']);
					//$conDetail[$i]['reply_date']=ago($cDetail['reply_date']);
					$conDetail[$i]['complain_date']=$cDetail['udate'];
					$conDetail[$i]['reply_date']=$cDetail['reply_date'];
$i++;					
					}

		}
		//print_r($conDetail);die('tp');
		return $conDetail;
	}
	
	function content($type)
	{
		//echo "error==>";echo"<pre>";print_r($type['type']);exit;
		global $db;
		$conDetail=array();
		if($type['type']=='complain'){
		$contentDetail = $db->getRow("select * from ".COMPLAIN." where id='".$type['id']."' and status=1 ");
		if(is_array($contentDetail) && count($contentDetail)>0){
			
				$conDetail=$contentDetail;
						
			}
		}
		return $conDetail;
	}
	
	function get_paper_detail($id)
	{
		global $db;
		
		$conDetail=array();
		$contentDetail = $db->getRow(" select * from papers where id=".$id);
		if(is_array($contentDetail) && count($contentDetail)>0){
		$conDetail=$contentDetail;
		
		
		}else{
		$conDetail=$db->getLastQuery();
		}
		return $conDetail ;
		
		
	}
	
	function get_class_name($id)
	{
		global $db;
		$class_name=$db->getVal("select class_name from ".CCLASS." where id='".$id."' and status='1'");
		
	   return $class_name;		
	}

	function get_exam_name($id)
	{
		global $db;
		$exam_name=$db->getVal(" select name from ".PAPER." where id='".$id."' and status='1'");
		
		return $exam_name;
	}

	function get_ques($pid)
	{	
		global $db;
		$conDetail=array();
		$contentDetail = $db->getVal(" select questions from papers where id=".$pid);
		
		$qlist="";
		$questionList=json_decode($contentDetail,true);
    
	//return $questionList;

		if(is_array($questionList) && count($questionList)>0){
			$i=0;
			foreach($questionList as $q){$i++;
				
				$qDetail=$db->getRow("select * from question where id=".$q['question']);
				$qlist[$i]["marks"]=$q["marks"];
				$qlist[$i]["qid"]=$q['question'];
				$quesdcds=json_decode($qDetail['question'],true);
		
				$qlist[$i]["question"]=$quesdcds['question'];		
				$qlist[$i]["type"]=$quesdcds['type'];
		
 				$alloptions=json_decode($qDetail['options'],true);
				$options=array();
				foreach($alloptions as $opt)
				{
					$options[]=$opt['answer'];
				}
				$qlist[$i]["options"]=$options;
				$qlist[$i]['answer']=$qDetail['answer'];
				$mysn=$db->getVal("select answer from examdetails where qid='".$q['question']."' and student_id='".$_SESSION["user"]["uid"]."' and paper_id='".$pid."'");
				
					
				if($mysn=="A")
					$qlist[$i]['myanswer']=$options[0];
				elseif($mysn=="B")
					$qlist[$i]['myanswer']=$options[1];
				elseif($mysn=="C")
					$qlist[$i]['myanswer']=$options[2];
				elseif($mysn=="D")
					$qlist[$i]['myanswer']=$options[3];
				//$qlist[$i]["quesstion"]=$q["marks"];
				//$qlist[$i]["options"]=$q["marks"];
			}
		}
		
		return $qlist	;
    }
	
	function cname()
	{
		global $db;
		$clas_name=$db->getRows("select * from ".CCLASS." where  status='1'");
		
		return $clas_name;
	}
	
	function get_sub_name($id)
	{
		global $db;
		$subject_name=$db->getVal("select subject_name from ".SUBJECT." where id='".$id."' and status='1'");
		
		return $subject_name;
	}

	function getname($uid){
		
		global $db;
		 if($uid==0 || $uid==1){
				 $names="SuperAdmin";
				 }else {
	$names=$db->getVal(" select fullname from ".SITE_USER." where id=".$_SESSION['admin']['uid']);
				 if($names=="") $names="SubAdmin";
				 	}
					
	return $names;	
		}
		
	function getrole($id)
	{
	 global $db;
	 $role=$db->getRow("select * from ".ROLL." where id=".$id);
		
	return $role['name'];	
	}
	
	function studentName($id)
	{
	 global $db;
	 $stu_name=$db->getVal("select student_name from ".STUDENT." where idno=".$id);
		
	return  $stu_name;	
	}

	function getAdmin($id)
	{
	 global $db;

	 	 $admin_id=$db->getVal("select added_by from ".STUDENT." where idno=".$id);
//	 	 return  $admin_id;	


		 if($admin_id==0 || $admin_id==1)
		 {
			$admin_name="SuperAdmin";
		 }else{
			$admin_name=$db->getVal("select fullname from ".SITE_USER." where id=".$admin_id);
		 }	 	 
	 return  $admin_name;	
	}

}
?>