<?php include "header.php";
if($login_type=='admin'){ 
$submit=$_POST['submit'];
if($submit=='Add Record'){
$course_name=$_POST['course_name'];
$ctype=$_POST['ctype'];
$college_id=$_POST['college_id'];

$query = "INSERT INTO `course_name` (`id`, `course_name`, `ctype`, `college_id`,`code`,`session`) VALUES ('$id', '$course_name', '$ctype', '$college_id','$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_course.php?active2=1&title=Courses";
            }
            
            document.write("<h1>You will be redirected to main page in 10 sec.</h1>");
            setTimeout('Redirect()', 1000);
         //-->
      </script>
<?php
}


if($submit=='Update'){
$id=$_POST['id'];
$course_name=$_POST['course_name'];
$ctype=$_POST['ctype'];
$college_id=$_POST['college_id'];
$query = "UPDATE course_name SET course_name='$course_name',ctype='$ctype',college_id='$college_id' WHERE id='$id' and code='$code' and session='$session'";
 $result = mysql_query( $query );
 if ( ! $result )
die ("Couldn't update: ".mysql_error());
print "<h1>Table Updated ". mysql_affected_rows() .
" row(s) updated</h1>";
?>
<script type="text/javascript">
         <!--
            function Redirect() {
               window.location="feed_course.php?active2=1&title=Courses";
            }
            
            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 course_name 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_course.php?active2=1&title=Courses";
            }
            
            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">
                  
   
    <style type="text/css">
<!--
.style1 {color: }
-->
</style>
<div class="card card-danger">
              <div class="card-header">
                <h3 class="card-title"><?php echo $_GET['title']; ?>?</h3>
              </div>

<table width="100%" border="0" cellspacing="2" cellpadding="2" background="images/co-surgeons.jpg">
  
  
  
  <tr>
    <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    
    <td width="50%" valign="top" align="center"><div align="center">
      <form name="myform" id="myform" method="post" action="feed_course.php?active2=1&title=Courses">
	  <table cellpadding=2 cellspacing=0 border=1 bordercolor=#FFFFCC bgcolor="" align=center class="table table-bordered table-striped">
				
		
		<tr>
		  <td width="116" class=color3> Course Name</td>
		  <td width="190" class=color2><input class="form-control" name="course_name" type="text" tabindex="1" required="required" /></td>
		  </tr>
        
        <tr>
          <td class=color3>College Type</td>
          <td class=color2>
          <select name="ctype" required="required" tabindex="2" class="form-control">
               <?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>          </td>
        </tr>
        <tr>
          <td class=color3>Select College</td>
          <td class=color2> <?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" class="form-control" required tabindex="3" > 

<option value="">Select</option>
      
                                  <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
                  <option
                 <?php 
				 $cn_id=$a_roww[2];
				 if($cn_id==$college){
				  ?>selected<?php } ?>
                  
                   value="<?php echo $a_roww[2];?>" >( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?></option>
                  <?php } ?>
                </select></td>
        </tr>
        <tr> 
			<td class=color3></td>
			<td class=color2><input name="submit" class="btn btn-primary" type="submit" value="Add Record" tabindex="3"/></td>
		</tr>
	</table>
</form></div></td>
  </tr>
</table></td>
    
  </tr>
</table>
</td>
  </tr>
  <tr>
    <td align="center"><?php
	 
$query = "SELECT * FROM course_name 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="" 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" >Course Name</td>
 
  <td align="center" valign="top"  class="style1" >College Type</td>
  <td align="center" valign="top"  class="style1" >College Code</td>
  <td align="center" valign="top"  class="border"><div align="center"><em><strong>Update</strong></em></div></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 ) )
 {?>
<form action="feed_course.php?active2=1&title=Courses" enctype="multipart/form-data" method="post">
<input  name="id" type="hidden" value="<?php echo $a_row[0];?>" />
 <tr>
 <td height="20" align="center" valign="top" ><div align="center" ><?php echo $counter;?></div></td>
 <td align="center" valign="top" ><input name="course_name" type="text" class="form-control"  value="<?php echo $a_row[1];?>"></td>
 
 <td align="center" valign="top" ><input class="form-control" name="ctype" type="text"  value="<?php echo $a_row[2];?>" /></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");
?>
<select name="college_id" class="form-control" required > 
<option value="">Select</option>
<?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
{?>
<option <?php $college=$a_row[3]; $cn_id=$a_roww[2]; if($cn_id==$college){ ?>selected<?php } ?>
                   value="<?php echo $a_roww[2];?>" >( <?php echo $a_roww[2];?> ) <?php echo $a_roww[1];?></option>
                  <?php } ?>
                </select>
 
 </td>
 <td align="center" valign="top" >

 <input class="btn btn-primary" type="submit"  name="submit" value="Update"  ></td>
 <td align="center" valign="top" >

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

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

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

<?php } include "footer.php"; ?>