<?php
	include("inside/config.php");
	session_start();
	$user=$_SESSION['username'];
	if(empty($user))
	{
		echo "<script>window.location='login.php'</script>";
	}
		
	$currentpage = "result";
	$id=$_REQUEST['rid'];
	$sql=mysql_query("select * from `result` where `rid`='$id'");
	$row=mysql_fetch_array($sql);
	if($_REQUEST['action']=="add"){	
		$name = $_REQUEST['name'];
		$roll = $_REQUEST['roll_no'];
		$class = $_REQUEST['class'];
		$obtained_marks = $_REQUEST['omarks'];
		$total_marks = $_REQUEST['tmarks'];
	
		//Writes the information to the database
   		$insert = mysql_query("insert into `result`(`name`,`roll_no`, `class`,`obtained_marks`,`total_marks`)
		values('$name','$roll','$class','$obtained_marks','$total_marks')");
		if(!$insert){
		die('Invalid query: ' . mysql_error());
		$type = "error";
		$msg = "Error Adding result info";
		}
		else {
		
		$type = "ok";
		$msg = "Record Addition Successful!";
			}
}

	
if($_REQUEST['action']=="delete")
	{
		$id=$_REQUEST['id'];
		$sqlDel=mysql_query("delete from `result` where `rid`='$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" />
    <script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
 <script src='../js/jquery-1.7.2.min.js' type='text/javascript'></script>
<script src='../js/sfm_validatorv7.js' type='text/javascript'></script>

<?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>
			Result Management</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">Current Records</h2>
				</div>
					<!-- End Box Head -->	

					<!-- Table -->
					<div class="table">
					  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <th width="118">Name</th>
					      <th width="95">Roll No</th>
					      <th width="88">Class</th>
					      <th width="148">Obtained Marks</th>
					      <th width="169">Total Marks</th>
					      <th width="130" class="ac">Action  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
				        </tr>
					   
						<?php
					  		$sql2=mysql_query("select * from `result`");
					  		while($result_row=mysql_fetch_array($sql2))
					  		{
					  		?>                        <tr>
  <td><?php echo $result_row['name']; ?></td>
					      <td><?php echo $result_row['roll_no']; ?></td>
					      <td><?php echo $result_row['class']; ?></td>
		        <td><?php echo $result_row['obtained_marks']; ?></td>
		        <td><?php echo $result_row['total_marks']; ?></td>
		        <td><a  class="ico del" href="result.php?action=delete&id=<?php echo $result_row['rid'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</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 Record
                </h2>
                </div>
                  <!-- End Box Head -->
                  <form action="result.php?action=add"  id="stdudent" method="post" enctype="multipart/form-data">
 					<table width="99%" border="0">
 					  <tr>
 					    <td width="34%" valign="middle"><label>
			        <input name="name" type="text" id="name" placeholder="Name" required />
			            </label></td>
 					    <td width="34%" valign="middle"><input name="roll_no" placeholder="Roll No" type="text" id="roll_no" required /></td>
 					    <td width="32%" valign="middle"><select name="class" class="size3" id="class">
 					      <option value="Select Class">Select Class</option>
 					      <option value="Play Group">Play Group</option>
 					      <option value="Nursery">Nursery</option>
 					      <option value="Prep">Prep</option>
 					      <option value="1st">1st</option>
 					      <option value="2nd">2nd</option>
 					      <option value="3rd">3rd</option>
 					      <option value="4th ">4th</option>
 					      <option value="5th ">5th </option>
 					      <option value="6th">6th </option>
 					      <option value="7th">7th</option>
 					      <option value="8th">8th</option>
 					      <option value="9th">9th</option>
 					      <option value="10th">10th</option>
				        </select></td>
				      </tr>
 					  <tr>
 					    <td valign="middle"><input name="omarks" placeholder="Obtained Marks" type="text" id="omarks" required /></td>
 					    <td valign="middle"><input name="tmarks" type="text" placeholder="Total Marks" id="tmarks" required /></td>
 					    <td valign="middle">&nbsp;</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><script type='text/javascript'>
// <![CDATA[
var stdudentValidator = new Validator("stdudent",{enable_smart_live_validation:false, message_style:'messagebox'});
stdudentValidator.addValidation("name",{required:true,message:"Name Required"} );
stdudentValidator.addValidation("roll_no",{required:true,message:"Name Required"} );
stdudentValidator.addValidation("omarks",{required:true,message:"Name Required"} );
stdudentValidator.addValidation("tmarks",{required:true,message:"Name Required"} );
stdudentValidator.addValidation("name",{alpha_s:true,message:"Name must be alphabatic only"} );
stdudentValidator.addValidation("roll_no",{numeric:true,message:"The input for Roll No should be a valid numeric value"} );
stdudentValidator.addValidation("omarks",{numeric:true,message:"The input for Obtained Marks should be a valid numeric value"} );
stdudentValidator.addValidation("tmarks",{numeric:true,message:"The input for Total Marks should be a valid numeric value"} );
stdudentValidator.addValidation("class",{dontselect:"Select Class",message:"Please select an option for Class"} );

// ]]>
</script>

            </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>