<?php
$members="1";
 include('header.php'); ?>

<div class="grid_full page_wrap">

<?php
	if(is_numeric($_GET['del'])){
		if($_GET['del'] =="1"){
			echo "<div class=\"alert alert-error\">You can`t delete admin !</div>";
		}else{
			@mysql_query("DELETE FROM `members` WHERE `id`='".$_GET['del']."'");
			echo "<div class=\"alert alert-error\">Delete Succesfully</div>";
		}
	}
	if(is_numeric($_GET['edit'])){
		$idedit= $_GET['edit'];
		$fetch=@mysql_fetch_array(mysql_query("SELECT * FROM `members` WHERE `id`='$idedit'"));
		
		if($_POST['submit']){
			$name=$_POST['name'];
			$email=$_POST['email'];
			$paypalemail=$_POST['paypalemail'];
			$cpass=$_POST['cpass'];
			if($cpass){
			$cpassmd5=md5($cpass);
			@mysql_query("UPDATE `members` SET `name`='$name',`email`='$email',`paypalemail`='$paypalemail',`password`='$cpassmd5' WHERE `id`='$idedit'");
			}else{
			@mysql_query("UPDATE `members` SET `name`='$name',`email`='$email',`paypalemail`='$paypalemail' WHERE `id`='$idedit'");
			}
			echo "<div class=\"alert alert-success\">Update Succesfully!</div>";
		}else{
	?>
<legend><strong>Edit:</strong> numele utilizatorului</legend>
<form action="" method="post" class="form-horizontal" style="width: 450px; margin: 0 auto;">
	<div class="control-group">
		<label class="control-label" for="inputProductName">Username: </label>
		<div class="controls">
			<input type="text"  readonly value="<?=$fetch[username];?>"> <!-- Sa nu poata fi schimbat -->
		</div>
	</div>	
	<div class="control-group">
		<label class="control-label" for="inputProductName">Name: </label>
		<div class="controls">
			<input type="text" name="name" id="inputProductName" value="<?=$fetch[name];?>"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="inputProductName">Email: </label>
		<div class="controls">
			<input type="text" name="email" id="inputProductName" value="<?=$fetch[email];?>"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="inputProductName">Paypal Email: </label>
		<div class="controls">
			<input type="text" name="paypalemail" id="inputProductName" value="<?=$fetch[paypalemail];?>"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label" id="PasswordChange" for="inputPasswordChange">Change password: </label>
		<div class="controls">
			<div class="change_password_tips"><-- Click on the text to change password</div>
			<input type="text" name="cpass" id="inputPasswordChange" class="hide" />
		</div>
	</div>
			<?php
				$querypro=@mysql_query("SELECT * FROM `products` WHERE `idu`='$fetch[id]'");
				if(mysql_num_rows($querypro) > 0){
			?>
	<div class="control-group">
		<label class="control-label" for="inputProductName">Products list: </label>
		<div class="controls">
			<ul style="list-style: none;margin: 0;padding: 0;">
			<?php
					while($rowpro=@mysql_fetch_array($querypro)){
					echo "
						<li class=\"well well-small\">
							<strong>$rowpro[name]</strong> | <a href=\"list.php?edit=$rowpro[edit]\"><i class=\"icon-pencil\"></i> EDIT</a>
						</li>
						";
					}
				
			?>
			</ul>
		</div>
	</div>
			<?php
				}
			?>
	<div style="text-align: center;"><input type="submit" name="submit" class="btn btn-primary btn-large" style="width: 300px;" /></div>


</form>


<hr />

<?php
		}
	}
		$query=@mysql_query("SELECT * FROM `members` ORDER BY id DESC");
			if(mysql_num_rows($query) > 0){
?>
<table class="table table-bordered">
	<thead>
		<tr>
			<th width="10">Id:</th>
			<th>Username:</th>
			<th>Email:</th>
			<th>Products have to sell:</th>
			<th width="170">Action:</th>
		</tr>
	</thead>
	<tbody>
		<?php
			while($row=@mysql_Fetch_array($query)){
			$products=@mysql_num_rows(mysql_query("SELECT `id` FROM `products` WHERE `idu`='$row[id]'"));
				echo "<tr>
							<td>$row[id]</td>
							<td>$row[username]</td>
							<td>$row[email]</td>
							<td>$products</td>
							<td><a href=\"?edit=$row[id]\" class=\"btn btn-info\"><i class=\"icon-pencil icon-white\"></i> Edit</a> <a href=\"?del=$row[id]\" class=\"btn btn-danger\"><i class=\"icon-remove icon-white\"></i> Delete</a></td>
						</tr>";
			
			
			}
			
	?>
	</tbody>
</table>
<?php
}else{
?>
<div class="alert alert-error">
    Not Found
    </div>
<?php
}
?>
</div>

<?php include('footer.php'); ?>