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


//CODE FOR DELETE RECORD
if(isset($_GET['action']) && $_GET['action'] == "delete")
{
	mysqli_query($connection,"DELETE FROM `pr_donation` WHERE `pID` = '".$_GET['pID']."'");
	
	$_SESSION['del_succ_msg'] = 'Record deleted successfully.';
	header("location: donation_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>Donation Collections 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="24%">Name & Phone No.</th>
								<th width="28%">Email Address</th>
								<th width="13%">Amount</th>
								<th width="25%">Action</th>
							</tr>
						</thead>
						<tbody>
						<?php
						$category_counter = 1;
						$sql_record = "SELECT * FROM `pr_donation` WHERE `paymentStatus` = 'SUCCESS' ORDER BY `pID` 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']);
								$email = stripslashes($fetch_record['email']);
								$phone = stripslashes($fetch_record['phone']);
								$amount = $fetch_record['toValue'];
							?>
							<tr>
								<td><?php echo $category_counter;?></td>
								<td><b>Name : </b><?php echo $name;?><br><b>Phone No : </b><?php echo $phone;?></td>
								<td><?php echo $email;?></td>
								<td>Rs. <?php echo $amount;?></td>
								<td><a href="donation_list.php?pID=<?php echo $fetch_record['pID']?>&action=delete" title="Delete" onclick="return confirm('Are you sure you want to delete this record?');" 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="cp" onclick='window.location.href="donation_details.php?pID=<?php echo $fetch_record['pID']?>"'>View Details</button></td>
							</tr>
							<?php
							$category_counter++;
							}
						}
						else
						{
						?>
						<tr>
							<td><font color="#FF0000">No record 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"); ?>