<?php
session_start();

if(!$_SESSION['isadmin'])
{
	header("Location: login.php?ref=edit.php?pageid=1");
	exit;
}

include_once("../functions.php");
$conn = dbconnect();
include "header.php";
include "leftbar.php";

$get_all_clubs = mysqli_query($conn,"SELECT * FROM club_registrations");

if($_POST['changepassword'])
{

	$current_password_matching = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM adminusers WHERE uname='".$_SESSION['loginname']."' AND upasswd='".md5($_POST['currentpassword'])."'"));
	
	if($current_password_matching)
	{
		if(mysqli_query($conn,"UPDATE adminusers SET upasswd = '".md5($_POST['newpassword'])."' WHERE id=".$_SESSION['userid']))
		$password_changed=1;
	}
	else
	{
		$current_password_does_not_match = 1;
	}
 
}

?>

    <div class="content">
        
        <div class="header">
            
            <h1 class="page-title">Golf Clubs</h1>
        </div>
        
                <ul class="breadcrumb">
            <li><a href="index.php">Home</a> <span class="divider">/</span></li>
            <li class="active">Golf Clubs</li>
        </ul>

<?php if($password_changed) {?>
<div style="padding: 0.1em; width:96%; margin-left:20px;" class="ui-state-highlight ui-corner-all">
   <p style="padding-top:10px;"><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span> Password changed successfully.</p>
</div>
<br />
<?php }?>

<?php if($current_password_does_not_match) {?>
<div class="ui-state-error ui-corner-all" style="padding: 0.1em; width:96%; margin-left:20px;">
   <p style="padding-top:10px;"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span> <strong>Alert: </strong> Current password do not match.</p>
</div>
<br />
<?php }?>
  

        <div class="container-fluid">
            <div class="row-fluid">
		
<div class="well">

<a href="add-a-club.php" style="text-decoration:underline"><h4>Add a club</h4></a>


<table style="width:100%">
<tr><th>Sr. No.</th><th>Golf club</th><th>Business Name</th><th>Contact Details</th><th>Registered on</th><th>Last Login</th><th>Assign Stickers</th><th>Assign Licensee</th></tr>
<?php 
$srno = 1;
while($golf_club = mysqli_fetch_array($get_all_clubs)){?>

<tr><td><?php echo $srno; ?></td><td><?php echo $golf_club['golfclub']?></td><td><?php echo $golf_club['businessname']?></td><td><?php echo $golf_club['contactname']."<br />".$golf_club['phone']."<br />".$golf_club['email']."<br /> Address: ".$golf_club['address']; ?></td><td><?php echo $golf_club['registeredon']?></td><td><?php echo $golf_club['lastlogin']?></td><td><a href="assign-stickers.php?cid=<?php echo $golf_club['id']?>">Assign Stickers</a></td><td><a href="assign-licensee.php?cid=<?php echo $golf_club['id']?>">Assign Licensee</a></td></tr>

<?php $srno++;}?>
</table>

</div>

<style>
table tr td { text-align:center; }
table tr { border-bottom:1px solid #000000 }
</style>
<?php include "footer.php";?>