<?php
	include("inside/config.php");
	session_start();
	$user=$_SESSION['username'];
	if(empty($user))
	{
		echo "<script>window.location='login.php'</script>";
	}
		
	$currentpage = "teachersprofile";
	$id=$_REQUEST['id'];
	$sql=mysql_query("select * from `teacher_profile` where `tid`='$id'");
	$row=mysql_fetch_array($sql);
	if($_REQUEST['action']=="add"){	
    	$id = $_REQUEST['id'];
		$name = $_REQUEST['fname'];
		$designation = $_REQUEST['fdesig'];
		$qualification = $_REQUEST['fqualif'];
		$other = $_REQUEST['fother'];
	
		//Writes the information to the database
   		$insert = mysql_query("insert into `teacher_profile`(`Name`,`Designation`, `Qualification`,`other`)
		values('$name','$designation','$qualification','$other')");
		if(!$insert){
		die('Invalid query: ' . mysql_error());
		$type = "error";
		$msg = "Error Adding Detail";
		}
		else {
		
		$type = "ok";
		$msg = "Teacher Detail Added Successfully!";
			}
}	
if($_REQUEST['action']=="delete")
	{
		$id=$_REQUEST['id'];
		$sqlDel=mysql_query("delete from `teacher_profile` where `tid`='$id'");
		$type = "ok";
		$msg = "Deletion Successful! ";
	}
?>
<!DOCTYPE html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Admin Panel : Frontier Public High School</title>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<?php include('inside/jsfunctions.php'); ?>
</head>
<body>
<?php include('inside/header.php'); ?>
<!-- Container -->
<div id="container">
	<div class="shell">
		
		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a>
			<span>&gt;</span>
			Teachers Profile</div>
		<!-- End Small Nav -->
		
		<!-- Message OK -->		
		<?php if($type=="ok"){ ?>
        <div class="msg msg-ok" id="msgok">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onClick="removeOk()">close</a>
		</div>
		<!-- End Message OK -->		
		<?php } ?>
		<!-- Message Error -->
		<?php if($type=="error"){ ?>
		<div class="msg msg-error" id="error">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onClick="removeError()">close</a>
		</div>
        <?php } ?>
		<!-- End Message Error -->
		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>
			
			<!-- Content -->
		  <div id="content">
				
				<!-- Box -->
			<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">Teachers Detail</h2>
				</div>
					<!-- End Box Head -->	

					<!-- Table -->
					<div class="table">
					  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <th>S.No</th>
					      <th>Name</th>
					      <th>Designation</th>
					      <th>Qualification</th>
					      <th>Other</th>
					      <th width="110" class="ac">Action  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
				        </tr>
					   
<?php						$serial = 0;
					  		$sql2=mysql_query("select * from `teacher_profile` ");
					  		while($result_row=mysql_fetch_array($sql2))
					  		{
					  		?>                        <tr>
  <td class="odd"><h3><?php $serial++; echo $serial; ?></h3></td>
					      <td><?php echo $result_row['Name']; ?></td>
					      <td><?php echo $result_row['Designation']; ?></td>
					      <td><?php echo $result_row['Qualification']; ?></td>
		        <td><?php echo $result_row['Other']; ?></td>
		        <td><a  class="ico del" href="teachers-profile.php?action=delete&id=<?php echo $result_row['tid'];?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a> <a  class="ico edit" href="edit-teacher-detail.php?id=<?php echo $result_row['tid'];?>">Edit</a></td>
					      </tr>
                        <?php
					  		}
					  		?>
				      </table>
					 
						
			  </div>
					<!-- Table -->
					
			  </div>
			  <!-- End Box -->
				
			  <!-- Box -->
              <div class="box">
                  <!-- Box Head -->
                <div class="box-head">
                    <h2 class="left">Add New Teacher Detail
                </h2>
                </div>
                  <!-- End Box Head -->
                  <form action="teachers-profile.php?action=add" method="post" enctype="multipart/form-data">
 					<table width="99%" border="0">
 					  <tr>
 					    <td valign="middle">Name : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<label>
			        <input name="fname" type="text" id="fname" required />
			            </label></td>
 					    <td valign="middle">Designation : 
				        <input name="fdesig" type="text" id="fdesig" required /></td>
				      </tr>
 					  <tr>
 					    <td valign="middle">Qualification : 
				        <input name="fqualif" type="text" id="fqualif" required /></td>
 					    <td valign="middle">Other :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 					      <input name="fother" type="text" id="fother" required /></td>
				      </tr>
				    </table>
<!-- Form Buttons -->
                    <div class="buttons">
                      <input type="reset" class="button" value="reset" />
                      <input type="submit" class="button" value="submit" />
                    </div>
                    <!-- End Form Buttons -->
                </form>
            </div>
            <!-- End Box -->

			</div>
			<!-- End Content -->
			
			<!-- Sidebar -->
			<div id="sidebar">
				
				<!-- Box -->
				<div class="box">
					
					<!-- Box Head -->
					<div class="box-head">
						<h2>Management</h2>
					</div>
					<!-- End Box Head-->
					
					<div class="box-content">
						<a href="new-article.php" class="add-button"><span>Add new Article</span></a>
						<div class="cl">&nbsp;</div>

						<!-- Sort --><!-- End Sort -->
						
					</div>
				</div>
				<!-- End Box -->
			</div>
			<!-- End Sidebar -->
			
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->
<?php  include("inside/footer.php"); ?></body>
</html>