<?php include "header.php"; 
if($login_type=='admin'){
$btnSave=$_POST['btnSave'];
$college_id=$_POST['college_id'];
$course_name=$_POST['course_name'];
$subject=$_POST['subject'];
$subject_type=$_POST['subject_type'];
$practical_fee=$_POST['practical_fee'];
$college_type=$_POST['college_type'];

if($btnSave=='Add Record'){
$query = "INSERT INTO `subject` (`id`, `subject`, `course_name`, `college_type`, `college_code`, `subject_type`, `practical_fee`,`code`,`session`) VALUES ('$id','$subject','$course_name','$college_type','$college_id','$subject_type','$practical_fee','$code','$session')";
  mysql_query( $query )
 or die ( "Couldn't add data to \"application\" table: " 
 .mysql_error() );
print "<div>Data Save [ ". mysql_affected_rows() .
" row(s) ] Successfully </div>";
?>
<script type="text/javascript">
         <!--
            function Redirect() {
               window.location="feed_subject.php";
            }
            
            document.write("<h1>You will be redirected to main page in 10 sec.</h1>");
            setTimeout('Redirect()', 1000);
         //-->
      </script>
<?PHP
}





$submit=$_GET['submit'];
if($submit=='Delete'){
$id=$_GET['id'];
$query = "DELETE FROM subject WHERE id=$id and code='$code' and session='$session'";
//$query = "UPDATE subject SET status='Reject' WHERE id='$id' and code='$code' and session='$session'";
$result = mysql_query( $query );
if ( ! $result )
die ("Couldn't deleted: ".mysql_error());
print "<h1>Table deleted ". mysql_affected_rows() .
" row(s) deleted</h1><p>";
?>
<script type="text/javascript">
         <!--
            function Redirect() {
               window.location="feed_subject.php";
            }
            
            document.write("<h1>You will be redirected to main page in 10 sec.</h1>");
            setTimeout('Redirect()', 1000);
         //-->
      </script>
<?PHP
}
?> <section class="content">
      <div class="container-fluid">
                <!-- Page Header -->
                <div class="col-lg-12">
                    
    
<script language='JavaScript'>

function validate()
{
	conf = confirm("Are you sure you want to delete?");
	if (conf)
		return true
	else
		return false;
}

</script><div class="card card-danger">
              <div class="card-header">
                <h3 class="card-title"><?php echo $_GET['title']; ?>?</h3>
              </div>
<div align="center">
    
      <form name="form1" action="feed_subject.php" method="post"  class="form-horizontal" role="form">
	  <?php
							
$queryy = "SELECT * FROM college_name where code='$code'";
$numresultsy=mysql_query($queryy);
$resulty= mysql_query($queryy) or die("Couldn't execute query");
?>
              <select name="college_id" id="college_id"  class="form-control"  required onchange='this.form.submit()' >
                <option value="">Select</option>
                <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
                <option
                 <?php 
				 $cn_id=$a_roww[2];
				 if($cn_id==$college_id){
				  ?>selected<?php } ?>
                  
                   value="<?php echo $a_roww[2];?>" >( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?></option>
                <?php } ?>
            </select><select name="college_type" class="form-control"  required="required" onchange='this.form.submit()'>
              <?php
$query = "SELECT * FROM ctype where session='$session' and code='$code' ORDER BY id";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
while ( $a_row = mysql_fetch_row( $result ) )

 {?>
          <option value="<?php echo $yiu=$a_row[1]; ?>" <?php if($college_type==$yiu){ ?> selected<?php } ?> ><?php echo $a_row[2]; ?></option>
<?php } ?>
            </select>          
          <select name="course_name" class="form-control"  required onchange='this.form.submit()' >
                                            
                                            <?php $queryy = "SELECT * FROM course_name where college_id='$college_id' && ctype='$college_type' and code='$code' and session='$session' Order by id";
$numresultsy=mysql_query($queryy);
$resulty= mysql_query($queryy) or die("Couldn't execute query");
 ?>
	<option value="">Select</option>
	 <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
                  <option 
                 <?php 
				 $Course_id=$a_roww[0];
				 if($Course_id==$course_name){
				  ?>selected<?php } ?> 
                  value="<?php echo $a_roww[0];?>" ><?php echo $a_roww[1];?></option>
                  <?php } ?>

</select>         
		 
		<div class="input-group mb-3">
                  <div class="input-group-prepend">
                    <span class="input-group-text">Subject Name</span>
                  </div>
                  
                  <input class="form-control" name="subject" type="text"  required="required" Placeholder='Subject Name' />
                </div>
          <select name="subject_type" class="form-control" >
              <option value="P">Practical</option>
              <option value="T">Theory</option>
            </select>          
         
         <input class="form-control" name="practical_fee" type="text" Placeholder='Practical Fee'   required="required" />
        <input class="btn btn-primary" type="submit" name="btnSave" value="Add Record"   >
</form></div>
  <?php
	 
$query = "SELECT * FROM subject where code='$code' and session='$session' ORDER BY course_name";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");


?>
<div style="overflow:auto; text-align:center">
<div class="card card-success">
              <div class="card-header">
                <h3 class="card-title"><?php echo $_GET['title']; ?>?</h3>
              </div>
<?php if($numrows!=""){?>
   <table  cellpadding="1" border="1" cellspacing="1" bgcolor="#FFFFFF" align="center" class="table table-bordered table-striped">
 <tr>
	
 <td align="center" valign="top"  class="border"><div align="center"   ><em><strong>S.</strong></em></div></td>
  <td align="center" valign="top"  class="style1" >College Name</td>
 
  <td align="center" valign="top"  class="style1" >College Type</td>
  <td align="center" valign="top"  class="style1" >Course Name</td>
  <td align="center" valign="top"  class="style1" >Subject Name</td>
  <td align="center" valign="top"  class="style1" >Subject Type</td>
  <td align="center" valign="top"  class="style1" >Practical Fees</td>

 <td align="center" valign="top"  class="border"><div align="center"    ><em><strong>Delete</strong></em></div></td>
 </tr>
<?php 
$counter = 1;?>
 <?php
while ( $a_row = mysql_fetch_row( $result ) )
 {?>
 
 

 <tr>
 <td height="20" align="center" valign="top" ><div align="center" ><?php echo $counter;?></div></td>
 <td align="center" valign="top" ><?php
							
$queryy = "SELECT * FROM college_name where code='$code'";
$numresultsy=mysql_query($queryy);
$resulty= mysql_query($queryy) or die("Couldn't execute query");
?>
              
               
                <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
                <?php 
				 
				$college_idi=$a_row[4];
				
				 $cn_id=$a_roww[2];
				 if($cn_id==$college_idi){
				  ?>( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?><?php } ?>
                <?php } ?>            </td>
 
 <td align="center" valign="top" >
             <?php 
			  
				$college_typei=$a_row[3];
				
				  ?>
               <?php
$queryh = "SELECT * FROM ctype where session='$session' and code='$code' ORDER BY id";
$numresults=mysql_query($queryh);
 $numrowsh=mysql_num_rows($numresultsh);
$resulth = mysql_query($queryh) or die("Couldn't execute query");
while ( $a_rowh = mysql_fetch_row( $resulth ) )

 {?>
         <?php $yiu=$a_rowh[1]; if($college_typei==$yiu){ ?> <?php echo $a_row[3]; ?><?php } ?>
<?php } ?>         </td>
 <td align="center" valign="top" >
 
  
                                            
                                            <?php 
											$queryy = "SELECT * FROM course_name where ctype='$college_typei' && code='$code' && session='$session' Order by id";
$numresultsy=mysql_query($queryy);
$resulty= mysql_query($queryy) or die("Couldn't execute query");
 ?>
	
	 <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
                  <?php 
				  
				 $course_namei=$a_row[2];
				
				
				 $Course_id=$a_roww[0];
				 if($Course_id==$course_namei){
				  ?> <?php echo $a_roww[0];?>-<?php echo $a_roww[1];?><?php } ?> 
                  <?php } ?> </td>
 <td bordercolor="#FFFFCC" class=color2><?php echo $a_row[1]; ?></td>
 <td bordercolor="#FFFFCC" class=color2>
     <?php 
				 $subject_typei=$a_row[5];
				 if($subject_typei=='P'){
				  ?>Practical<?php } ?>
     <?php 
				 $subject_typei=$a_row[5];
				 if($subject_typei=='T'){
				  ?>Theory<?php } ?>   </td>
 <td bordercolor="#FFFFCC" class=color2><?php echo $a_row[6]; ?></td>
 
 <td align="center" valign="top" >

 
<a href="feed_subject.php?id=<?php echo $a_row[0];?>&&submit=Delete" onclick='return validate();'><input type="reset" class="btn btn-danger" name="Delete" value="Delete" class="btn btn-danger" /></a></td>
 </tr>


   
  <?php $counter++;}?>
  </table>
</div>
   <?php }?>

<?php if($numrows==""){
  echo "<div  style='border:none; text-align:center'><h3 class='logo2'>No Record Found</h3></div>";
}?>
</div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
<?php }
include "footer.php"; ?>