<?php 
require_once("header.php");
require_once("session_check.php");

//CODE FOR CHANGE STATUS TO APPROVE
if(isset($_GET['action']) && $_GET['action'] == "approve")
{
	$sql_update = "UPDATE `usertable_stu` SET `status` = 'approved' WHERE `id` = '".$_GET['id']."'";
	$exe_update = mysqli_query($connection,$sql_update);
	
	$_SESSION['change_succ_msg'] = 'Student volunteer approved successfully.';
	header("location: student_list.php");
	exit;
}

//CODE FOR DELETE STUDENT VOLUNTEER
if(isset($_GET['action']) && $_GET['action'] == "delete")
{
	mysqli_query($connection,"DELETE FROM `usertable_stu` WHERE `id` = '".$_GET['id']."'");
	
	$_SESSION['del_succ_msg'] = 'Student volunteer deleted successfully.';
	header("location: student_list.php");
	exit;
}
?>

<?php require_once("left_panel.php");?>
<div class="content">
	<div class="workplace">
		<?php if(isset($_SESSION['add_succ_msg'])) { ?>
			<div class="alert alert-success">                
			<b><?php echo $_SESSION['add_succ_msg'];?></b>
			</div> 
		<?php
		unset($_SESSION['add_succ_msg']);
		}
		?>
		
		<?php if(isset($_SESSION['edit_succ_msg'])) { ?>
			<div class="alert alert-success">                
			<b><?php echo $_SESSION['edit_succ_msg'];?></b>
			</div> 
		<?php
		unset($_SESSION['edit_succ_msg']);
		}
		?>
		
		<?php if(isset($_SESSION['del_succ_msg'])) { ?>
			<div class="alert alert-success">                
			<b><?php echo $_SESSION['del_succ_msg'];?></b>
			</div> 
		<?php
		unset($_SESSION['del_succ_msg']);
		}
		?>
		
		<?php if(isset($_SESSION['change_succ_msg'])) { ?>
			<div class="alert alert-success">                
			<b><?php echo $_SESSION['change_succ_msg'];?></b>
			</div> 
		<?php
		unset($_SESSION['change_succ_msg']);
		}
		?>
		<div class="row-fluid">
			<div class="span12">
				<div class="head clearfix">
					<div class="isw-grid"></div>
					<h1>Student Volunteers List</h1>                               
				</div>
				<div class="block-fluid table-sorting clearfix">
					<table cellpadding="0" cellspacing="0" width="100%" class="table" id="tSortable">
						<thead>
							<tr>
								<th width="10%">Serial No.</th>
								<th width="25%">Name & User ID & Password</th>
								<th width="25%">Email Address</th>
								<th width="20%">Status</th>
								<th width="20%">Action</th>
							</tr>
						</thead>
						<tbody>						
						<?php
						$product_counter = 1;
						$sql_record = "SELECT * FROM `usertable_stu` ORDER BY `id` DESC";
						$exe_record = mysqli_query($connection,$sql_record);
						$num_record = mysqli_num_rows($exe_record);
						if($num_record>0)
						{
							while($fetch_record = mysqli_fetch_array($exe_record))
							{
								$name = stripslashes($fetch_record['name']);
								$userid = $fetch_record['userid'];
								$email = $fetch_record['email'];
								$status = $fetch_record['status'];
								$cp_ori = $fetch_record['cp_ori'];
							?>
							<tr>
								<td><?php echo $product_counter;?></td>
								<td><b>Name : </b><?php echo $name;?><br><b>User ID : </b><?php echo $userid;?><br><b>Password : </b><?php echo $cp_ori;?></td>
								<td><?php echo $email;?></td>
								<td><?php if($status == 'notverified') { ?><a href="student_list.php?id=<?php echo $fetch_record['id']?>&action=approve" title="Click to approve" onclick="return confirm('Are you sure you want to approve this student volunteer?');">Approve</a> || <a href="student_reject_cause.php?id=<?php echo $fetch_record['id']?>" title="Click to approve" onclick="return confirm('Are you sure you want to reject this student volunteer?');">Reject</a><?php } ?><?php if($status == 'approved') { ?><font color="#009900;">Approved</font><?php } ?><?php if($status == 'rejected') { ?><font color="#ff0000;">Rejected</font><?php } ?></td>
								<td><a href="student_list.php?id=<?php echo $fetch_record['id']?>&action=delete" title="Delete" onclick="return confirm('Are you sure you want to delete this student volunteer?');" style="float:left; display:block; margin:0 5px 0 0;"><ul class="the-icons clearfix"><i class="isb-delete"></i></ul></a><button class="btn" type="button" name="back" onclick='window.location.href="student_details.php?id=<?php echo $fetch_record['id']?>"'>View Details</button></td>
							</tr>							
							<?php
							$product_counter++;
							}
						}
						else
						{
						?>
						<tr>
							<td><font color="#FF0000">No student volunteer found</font></td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
						<?php
						}
						?>						
						</tbody>
					</table>
				</div>
			</div>                                
		</div>
	 </div>
</div>

<?php require_once("footer.php"); ?>