<?php require "commonincludefiles.php"; 
function getdistrictname($district_id)
{
	if($district_id==0)
	{
		$qry = "SELECT dist_id,dist_nameeng FROM sms_distmaster ORDER BY dist_nameeng ASC"; // where dist_id = $district_hidden
	}
	else
	{
	  $qry = "SELECT dist_id,dist_nameeng FROM sms_distmaster where dist_id = $district_id";
	}
	
 	 $disresult=dbQuery($qry);
	 return  $disresult;
}	 
function getdistschool($dist_id)
{
	$company_id="";
	 $qry = "SELECT sm.company_id 
			FROM sms_schoolmaster sm 
			WHERE sm.dist_id = $dist_id ";
	 $schresult = dbQuery($qry);
	 if(dbRows($schresult)>0){
		while($schrow= dbArray($schresult))
		{ 
			$company_id .= $schrow['company_id'].",";
		}
	}
	return   $company_id;
}	 
function getsection()
{
	 $query = "SELECT * FROM sms_section WHERE  1=1 "; 
	$out = dbQuery($query);
	return   $out;
}	 
function getstandard($secno)
{
	$query = "SELECT * FROM sms_standard WHERE  section_no='$secno' "; 
					$out1 = dbQuery($query);
	return   $out1;
}

function standardsum($company_id,$section_id,$standard_id)
{
	$noofdiv=0;
	
	$query=" SELECT sum(standard_noofdiv) as noofdiv
					FROM sms_standardmaster
					WHERE find_in_set(company_id,'$company_id') AND
					section_id  = $section_id AND
					standard_id = $standard_id AND
					standard_active ='1' ";
					
	$out2 = dbQuery($query);
	
	if(dbRows($out2)>0){ 
		while($nofdivrow=dbArray($out2)){ 
			$noofdiv = $nofdivrow['noofdiv'];
		}
	}
	if($noofdiv=="")
		$noofdiv=0;
		
	return $noofdiv;
}

function GetGenderTotal($company_id,$section_id,$standard_id,$gender,$condition = "")
{
	$total =0;
if($condition == "")
{
	$qry="SELECT student_gender, count( student_gender ) as COUNTTOTAL 
		FROM sms_studentmaster sm,sms_studentdetail sd
		WHERE 
		find_in_set(sm.company_id, '$company_id') AND
		sm.company_id  =  sd.company_id AND
		sm.student_active='Yes' AND
		sm.student_id = sd.student_id AND
		sm.section_id = $section_id AND
		sd.section_id  = $section_id AND
		sd.year_id='2' AND
		sd.student_curstd= $standard_id AND
		student_gender= '$gender'
		GROUP BY student_gender LIMIT 0,1";
}
if($condition != "")
{
	$qry="SELECT student_gender, count( student_gender ) as COUNTTOTAL 
		FROM sms_studentmaster sm,sms_studentdetail sd
		WHERE 
		find_in_set(sm.company_id, '$company_id') AND
		sm.company_id  =  sd.company_id AND
		sm.student_active='Yes' AND
		sm.student_id = sd.student_id AND
		sm.section_id = $section_id AND
		sd.section_id  = $section_id AND
		sd.year_id='2' AND
		sd.student_curstd= $standard_id AND
		student_gender= '$gender'
		$condition
		GROUP BY student_gender LIMIT 0,1";
}
		//echo $qry;	
	$out = dbQuery($qry);				

	if(dbRows($out) > 0){
		while($row=dbArray($out)){							
			$total = $row["COUNTTOTAL"];
		}
		dbFreeResult($out);
	}
	return $total;
}
		
function GetGenderTotalByCategory1($company_id,$section,$student_curstd,$gender,$category)
{
	$total =0;
	
	 $qry="SELECT student_gender, count(student_gender) AS COUNTTOTAL
		  FROM sms_studentmaster sm,sms_studentdetail sd
		  WHERE
		  find_in_set(sm.company_id, '$company_id') 
			AND sm.company_id  =  sd.company_id 
		    AND	sm.student_id=sd.student_id 
			AND sm.student_active='Yes' 
			AND sd.section_id = '$section'
			AND sm.section_id = '$section'
			AND student_curstd = '$student_curstd'
			AND student_category = '$category'
			AND student_gender= '$gender'
			GROUP BY student_gender LIMIT 0,1";
		
		//echo  $qry;	
		$out = dbQuery($qry);				
	
		if(dbRows($out) > 0){
			while($row=dbArray($out)){							
				$total = $row["COUNTTOTAL"];
			}
			dbFreeResult($out);
		}
		return $total;
}			