<?php
include("../db.php");
$ch=$_REQUEST["type"];
if($ch=="exmtype"){
	$detail=$db->getRows("select DISTINCT type from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
	?>
    <select name="type" id="type">
    <option value="">Exam type</option><?php
	if(is_array($detail) && count($detail)>0){
		foreach($detail as $ds){
			?><option><?php echo $ds["type"] ?></option><?php	
		}
	}
	?></select><?php
}
elseif($ch=="NoOfExam"){
	$exam=$db->getVal("select id from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' limit 0,1");
	if($_REQUEST["utype"]=="edit" || $exam!=""){
		$examtype=$db->getRows("select distinct(type) from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
		?>
		<form method="post" action="">
			<input type="hidden" name="class" value="<?php echo $_REQUEST["class"] ?>" />
			<div class="row-fluid">
				<div class="span12">
					<div class="top-bar">
						<h3><i class="icon-cog"></i> Exam type detail</h3>
						<div>
								<button type="submit" name="fee" onclick="createExam()" class="btn btn-primary"> Save</button>
						</div>
					</div>
					<div class="well no-padding">
					<table class="table">
					<tr>
						<td></td>
						<?php 
						
						if(is_array($examtype) && count($examtype)>0){
							foreach($examtype as $eytpe){ //echo "<pre>";print_r($eytpe);echo "</pre>";?>
							<td><input required type="text" name="type[]" style="width:80px" class="total" value="<?php echo $eytpe[0] ?>" placeholder="Exam type" /></td>
						<?php }
						}?>
					</tr>
					<?php
					$detail=$db->getRows("select * from subject_mp where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
					foreach($detail as $d){
					?><tr>
							<td><?php echo $d["subject"] ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
							<?php 
							for($i=1; $i<=count($examtype);$i++){ ?>
							<td><input required type="text" style="width:80px" name="<?php echo $d["subject"];?>[]" class="total" value="<?php
							echo $db->getVal("select total from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and subject='".$d["subject"]."' and type='".$examtype[$i-1][0]."'")
							 ?>" placeholder="Total Maks" /><?php 
							 //print_r($examtype[$i-1][0]); echo $db->getLastQuery() ?></td>
							<?php } ?>
						</tr>
					<?php
					}
					?>
					</table>
				</div>
			</div>
			</div>
		</form>
		<?php
	}else{
		$detail=$db->getRows("select * from subject_mp where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' order by id");
		if(count($detail)==0){
			echo '<div class="alert alert-error">
				  <a class="close" data-dismiss="alert">×</a>
				  <i class="icon icon-warning-sign"></i> <b>Notice</b> Please create Subject for this class</i>
				</div>';
		}
		else{
			?><form method="post" action="">
			<input type="hidden" name="class" value="<?php echo $_REQUEST["class"] ?>" />
			<div class="row-fluid">
				<div class="span12">
					<div class="top-bar">
						<h3><i class="icon-cog"></i> Exam type detail</h3>
						<div>
								<button type="submit" name="fee" onclick="createExam()" class="btn btn-primary"> Save</button>
						</div>
					</div>
					<div class="well no-padding">
					<table class="table">
					<tr>
						<td></td>
						<?php for($i=1; $i<=(int)$_REQUEST["noexam"];$i++){ ?>
							<td><input required onkeyup="SpaceReplace(this)" type="text" name="type[]" style="width:80px" class="total" value="<?php if($i==1)echo "Monthly"; elseif($i==2)echo "Term1"; elseif($i==3)echo "Term2"; elseif($i==4)echo "Final"; else echo "";?>" placeholder="Exam type" /></td>
						<?php } ?>
					</tr>
					<?php
					foreach($detail as $d){
						$subj=str_replace(" ","_",str_replace("+","~",str_replace("&","and",$d["subject"])));
						?>
						<tr>
							<td><?php echo $d["subject"] ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
							<?php for($i=1; $i<=(int)$_REQUEST["noexam"];$i++){ ?>
							<td><input required type="text" style="width:80px" name="<?php echo $subj;?>[]" class="total onlyZero" value="0" placeholder="Total Maks" /></td>
							<?php } ?>
						</tr>
						<?php
					}
					?>
					</table>
				</div>
			</div>
			</div>
			</form>
		<?php
		}
	}
}
elseif($ch=="findSubject"){
	$str="";$arr=array();
	$subjects=$db->getRows("select * from subject_mp where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["cls"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	if(is_array($subjects) && count($subjects)>0){
		foreach($subjects as $d){
			$arr[]=$d["subject"];
		}
		$str=implode(",",$arr);
		echo trim($str);
	}
}

elseif($ch=="studentportal"){
    $idno = $_POST['idno'];
	$user = $db->getRow("select * from student where idno='$idno' ");
    if(is_array($user) && count($user)>0){
        $_SESSION["isadmin"] = "1";
        // $_SESSION["adminid"] = $_SESSION["admin"]["uid"];

        $_SESSION["first"]="yes";
        $_SESSION["admin"]["login"]="Yes";
        $_SESSION["admin"]["uid"] = $user["idno"];
        $_SESSION["admin"]["class"] = $user["class"];
        $_SESSION["admin"]["section"] = $user["section"];
        $_SESSION["admin"]["utype"] = 1;
        $_SESSION["admin"]["school_id"] = $user["school_id"];
        $_SESSION["admin"]["roll"] = 1;
        $_SESSION["admin"]["session"] = $user["session"];
	}
    // echo "./v3/?src=Academic&page_id=syllabus";
    echo "./v3/dashboard.php";
}

elseif($ch=="teacherportal"){
    $idno = $_POST['idno'];
	$user = $db->getRow("select * from staff where idno='$idno' ");
    if(is_array($user) && count($user)>0){
        $_SESSION["isadmin"] = "1";
        // $_SESSION["adminid"] = $_SESSION["admin"]["uid"];

        $_SESSION["first"]="yes";
        $_SESSION["admin"]["login"]="Yes";
        $_SESSION["admin"]["uid"]=$user["idno"];
        $_SESSION["admin"]["utype"]=$user["idno"];
        $_SESSION["admin"]["school_id"]=$user["school_id"]; 
        $_SESSION["admin"]["roll"]=$user["role_id"];
        $_SESSION["admin"]["session"]=$user["session"];
	}
    echo "./v2/dashboard.php";
    // echo "./v2/?src=Attandence&page_id=student_day_wise";
}

if($_REQUEST["type"]=="student_portal_data"){
	//echo $_REQUEST['class'];
	$where="";
	if(isset($_REQUEST["class"]))$where=" AND class='".$_REQUEST["class"]."'";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 order by name";
	$aryList=$db->getRows($sql_limit);
	$aryPgAct=array("src"=>"TC", "page_id"=>"tc","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['idno'];
			$i++;
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['class']).'",';
			$aryData.='"'.POST($iList['fincome']).'",';
			$aryData.='"'.POST($iList["admissionno"]).'",';
			$aryData.='"'.POST($iList['mobile']).'",';
			$aryData.='"';
		
            $aryData.="<button type='button' onclick='enterStudentPortal($iList[idno])' class='btn btn-info'>Enter</button>";

				// if($iList["issue_TC"]==0){ 	$aryPgAct=array("page_id"=>"cc","action"=>"print","id"=>$aryPgAct["id"]);
		  	   //$aryData.='<a href=\''.URL_ROOT.'print/'.getQueryString($aryPgAct).'\' ><button type=\'button\' class=\'btn btn-danger\'>Print CC</button></a>';

// 			}

			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
}

?>



