<?php include ("../core/kfunctions.php");

role("overadmin");

?>

<html>

<head>

<?php kheader(); ?>

<?php 

require_once("../core/connect.php");



?>

<link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">

<script src="../js/sorttable.js"></script>

</head>

<body>





    <div id="wrapper">



        <!-- Navigation -->

        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">

            <!-- Brand and toggle get grouped for better mobile display -->

            <?php ktopbar(); ?>

            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->

            <?php kleftbar(); ?>

            <!-- /.navbar-collapse -->

        </nav>



        <div id="page-wrapper">



            <div class="container-fluid">



 <!-- Page Heading -->

                



                <div class="row">

                    <?php

if(isset($_POST["submit"])){

$schoolterm=$_POST["schoolterm"];

$schoolyear=$_POST["schoolyear"];

$setname=$_POST["setname"];

$selectedinput=$_POST["selectedinput"];

$yy=date("Y");

$fyy=substr($yy,2,2);

$mm=date("m");

$dd=date("d");

$hi=date("h");

$mi=date("i");

$sa=date("sa");

$fsa=substr($sa,0,2);   

$setid="set".$fyy.$mm.$dd.$hi.$mi.$fsa;



include("../core/connect.php");

$rolenumber=$_SESSION["rolenumber"];

if($setname!=""){

$insert_examset=$dbh->query("insert into examsets (ouruser,setid,setname,year,term,setclasses) values('$rolenumber','$setid','$setname','$schoolyear','$schoolterm','$selectedinput')");





//pick from scrap where primary or secondary

$result_scrap=$dbh->query("select * from scrap where  type='secclas' or type='priclas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



//if its greater than 0

if($count_scrap>0){

do{

if(isset($_POST["cla".$row_scrap->item.""])){

$schoolclass=$_POST["cla".$row_scrap->item.""];



$result_citadel=$dbh->query("select * from citadel where schoolyear='$schoolyear' and schoolclass='$schoolclass'");

$row_citadel=$result_citadel->fetchObject();

$count_citadel=$result_citadel->rowCount();



if($count_citadel>0){

do{

$insert_child=$dbh->query("insert into kingslanding (schoolyear,term,schoolclass,cid,setid,combination,sub44marks,sub45marks,sub46marks,sub47marks,sub48marks,sub49marks,sub50marks,sub51marks,sub52marks,sub53marks,sub54marks,sub55marks,sub56marks,sub57marks,sub58marks,sub59marks,sub60marks,sub61marks,sub62marks,sub63marks,sub64marks,sub65marks,sub66marks,sub67marks,sub68marks,sub69marks,sub70marks,sub71marks,sub72marks,sub73marks,sub74marks,sub75marks,sub76marks,sub77marks,sub78marks,sub79marks,sub80marks,sub81marks,sub82marks,sub83marks,sub84marks,sub85marks,sub86marks,sub87marks,sub88marks,sub89marks) values('$row_citadel->schoolyear','$schoolterm','$row_citadel->schoolclass','$row_citadel->cid','$setid','$row_citadel->combination','$row_citadel->sub44marks','$row_citadel->sub45marks','$row_citadel->sub46marks','$row_citadel->sub47marks','$row_citadel->sub48marks','$row_citadel->sub49marks','$row_citadel->sub50marks','$row_citadel->sub51marks','$row_citadel->sub52marks','$row_citadel->sub53marks','$row_citadel->sub54marks','$row_citadel->sub55marks','$row_citadel->sub56marks','$row_citadel->sub57marks','$row_citadel->sub58marks','$row_citadel->sub59marks','$row_citadel->sub60marks','$row_citadel->sub61marks','$row_citadel->sub62marks','$row_citadel->sub63marks','$row_citadel->sub64marks','$row_citadel->sub65marks','$row_citadel->sub66marks','$row_citadel->sub67marks','$row_citadel->sub68marks','$row_citadel->sub69marks','$row_citadel->sub70marks','$row_citadel->sub71marks','$row_citadel->sub72marks','$row_citadel->sub73marks','$row_citadel->sub74marks','$row_citadel->sub75marks','$row_citadel->sub76marks','$row_citadel->sub77marks','$row_citadel->sub78marks','$row_citadel->sub79marks','$row_citadel->sub80marks','$row_citadel->sub81marks','$row_citadel->sub82marks','$row_citadel->sub83marks','$row_citadel->sub84marks','$row_citadel->sub85marks','$row_citadel->sub86marks','$row_citadel->sub87marks','$row_citadel->sub88marks','$row_citadel->sub89marks')");

}while($row_citadel=$result_citadel->fetchObject());

}



}



}while($row_scrap=$result_scrap->fetchObject());

}

//if its greater than 0

//pick from scrap where primary or secondary

}

}

?>

                    <form method='post'>

<div class='col-lg-2'>

<select class="form-control" name="schoolyear">

<option value="<?php echo date("y"); ?>"><?php echo date("Y"); ?></option>

<?php

$result_scrap=$dbh->query("select * from scrap where  type='ya'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap){

    do{

echo "<option value='".$row_scrap->item."'>".$row_scrap->item2."</option>";

}while($row_scrap=$result_scrap->fetchObject());

}else{

    echo "<option value=''>Please contact your IT department. </option>";

}

?>

</select>

</div>

<div class='col-lg-2'>

<select class="form-control" name="schoolterm">

<?php

$cm=date("m");

if($cm>='1' and $cm<='4'){$oterm="Term 1"; $iterm="1";}

elseif($cm>='5' and $cm<='8'){$oterm="Term 2"; $iterm="2";}

elseif($cm>='9' and $cm<='12'){$oterm="Term 3"; $iterm="3";}

echo "

<option value='".$iterm."'>".$oterm."</option>";



$result_scrap=$dbh->query("select * from scrap where  type='ts'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap){

    do{

echo "<option value='".$row_scrap->item."'>Term ".$row_scrap->item2."</option>";

}while($row_scrap=$result_scrap->fetchObject());

}else{

    echo "<option value=''>Please contact your IT department. </option>";

}

?>

</select>

</div>

<div class='col-lg-4'>

<input type='text' class='form-control' name='setname' placeholder='Set name'>

</div>

<div class='col-lg-2'>

    <input type='submit' name='submit' class='btn btn-sm btn-primary' value='Submit'>

</div>

<?php

$result_scrap=$dbh->query("select * from scrap where  type='secclas' or type='clas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap>0){

do{

    echo "

<input type='hidden' name='cla".$row_scrap->item."' id='cla".$row_scrap->item."'>";

}while($row_scrap=$result_scrap->fetchObject());

}

?>





<div class='col-lg-12'><br></div>



                    <div class="col-lg-12">

                        <div class="panel panel-default">

                            <div class="panel-body">

                            

                           

<div class='panel panel-yellow'><!--Initiative-->

<div class='panel-heading'><h3 class='panel-title'>Select class to do the set</h3></div>

<div class='panel-body'>



<?php

include("../core/connect.php");

$result_scrap=$dbh->query("select * from scrap where type='priclas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap){

    do{



    echo "

<div class='col-lg-2'>"; ?>

<input type='checkbox' id='sub<?php echo $row_scrap->item; ?>' onclick="sender()" value='<?php echo $row_scrap->item2; ?>'> <?php echo $row_scrap->item2; ?>

<?php echo "</div>"; 

}while($row_scrap=$result_scrap->fetchObject());

}else{

    echo "Please contact your IT department. ";

}



echo "<div class='col-lg-12'><br></div>";



$result_scrap=$dbh->query("select * from scrap where  type='secclas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap){

    do{



    echo "

<div class='col-lg-2'>"; ?>

<input type='checkbox' id='sub<?php echo $row_scrap->item; ?>' onclick="sender()" value='<?php echo $row_scrap->item2; ?>'> <?php echo $row_scrap->item2; ?>

<?php echo "</div>";



}while($row_scrap=$result_scrap->fetchObject());

}else{

    echo "Please contact your IT department. ";

}





?>

</div></div>



</div>



</div>



<input type='text' class='form-control' name='selectedinput' id='selectedclass' placeholder='Selected class' readonly>



</form>



                            </div> </div>

                    </div>

                </div>

                <!-- /.row -->



               



            </div>

            <!-- /.container-fluid -->

<?php useractivity("on page", "56"); ?>

        </div>

        <!-- /#page-wrapper -->



    </div>

    <!-- /#wrapper -->



    <!-- jQuery -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>



<script>

function sender(){

 var selectedclass = document.getElementById("selectedclass");

var values = [];

<?php

$result_scrap=$dbh->query("select * from scrap where  type='secclas' or type='priclas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){

    do{

?>

if(document.getElementById("sub<?php echo $row_scrap->item; ?>").checked) {

 var sub = document.getElementById("sub<?php echo $row_scrap->item; ?>").value;

  values.push(sub);

  

}

<?php

}while($row_scrap=$result_scrap->fetchObject());

}

?>

selectedclass.value = values.join(", ");



setTimeout(auto_sender,500);

}



var auto_sender=function(){

<?php

include("../core/connect.php");

$result_scrap=$dbh->query("select * from scrap where  type='secclas' or type='clas'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){

    do{

?>

if(document.getElementById("sub<?php echo $row_scrap->item; ?>").checked) {

 document.getElementById("cla<?php echo $row_scrap->item; ?>").value="<?php echo $row_scrap->item; ?>";

}

<?php

}while($row_scrap=$result_scrap->fetchObject());

}

?>



}

</script>



    <!-- Bootstrap Core JavaScript -->

    <script src="../js/bootstrap.min.js"></script>

    <script type="text/javascript" src="../js/jquery-1.8.3.min.js" charset="UTF-8"></script>

</body>



</html>

