Cod: Selectaţi tot
<?php
session_start();
$auth = "";
$access = "";
$password = "";
$flags = "";
$grad = "";
$id = 0;
$errors = array();
$succes = array();
$edit_state = false;
//$db = new mysqli("localhost", "root", "", "amx") or die("Unable to connect!");
include('conndb.php');
if (isset($_POST['save'])) {
$auth = $_POST['auth'];
$password = $_POST['password'];
$access = $_POST['access'];
$flags = $_POST['flags'];
$grad = $_POST['grad'];
if (empty($auth)) { array_push($errors, "Name is required"); }
if (empty($password)) { array_push($errors, "Password is required"); }
if (empty($access)) { array_push($errors, "Access is required"); }
if (empty($flags)) { array_push($errors, "Flags is required"); }
if (empty($grad)) { array_push($errors, "Grad is required"); }
if (count($errors) == 0) {
$query = "INSERT INTO admins (auth, password, access, flags, grad) VALUES ('$auth', '$password', '$access', '$flags', '$grad')";
mysqli_query($db, $query);
if (empty($_POST['save'])) { array_push($succes, "Admin adaugat cu succes!"); }
if (count($succes) == 0) {
header('location: admin.php');
}
}
}
if (isset($_POST['update'])) {
$id = $_POST['id'];
$auth = $_POST['auth'];
$access = $_POST['access'];
$password = $_POST['password'];
$flags = $_POST['flags'];
$grad = $_POST['grad'];
if (empty($auth)) { array_push($errors, "Name is required"); }
if (empty($password)) { array_push($errors, "Password is required"); }
if (empty($access)) { array_push($errors, "Access is required"); }
if (empty($flags)) { array_push($errors, "Flags is required"); }
if (empty($grad)) { array_push($errors, "Grad is required"); }
if (count($errors) == 0) {
mysqli_query($db, "UPDATE admins SET auth='$auth', access='$access', password='$password', flags='$flags', grad='$grad' WHERE id='$id'");
if (empty($_POST['update'])) { array_push($succes, "Admin editat cu succes!"); }
if (count($succes) == 0) {
header('location: admin.php');
}
}
}
if (isset($_GET['del'])) {
$id = $_GET['del'];
mysqli_query($db, "DELETE FROM admins WHERE id=$id");
if (empty($_POST['update'])) { array_push($succes, "Admin sters cu succes!"); }
if (count($succes) == 0) {
header('location: admin.php');
}
}
$results = mysqli_query($db, "SELECT * FROM admins");
//$sqlget = "SELECT * FROM `admin_kick`";
//$sqldata = mysqli_query($db, $sqlget) or die ('Eroare la extragere adminilor');
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$edit_state = true;
$rec = mysqli_query($db, "SELECT * FROM admins WHERE id=$id");
$record = mysqli_fetch_array($rec);
$auth = $record['auth'];
$access = $record['access'];
$password = $record['password'];
$flags = $record['flags'];
$id = $record['id'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>AmxModX cPanel admin</title>
<link rel="stylesheet" type="text/css" href="css/stylemenu.css">
<link rel="stylesheet" type="text/css" href="css/admini.css">
</head>
<body>
<div class="header">
<div class="logo"><span><a href="#">Staff page</a></span></div>
</div>
<ul>
<li><a href="home.php">HOME</a></li>
<li><a href="#">MENU</a>
<ul>
<li><a href="admin.php">ADMINS</a></li>
<li><a href="shop.php">SHOP</a></li>
<li><a href="rules.php">RULES</a></li>
</ul>
</li>
<li><a href="logout.php">LOGOUT</a></li>
<li><?php echo $_SESSION['auth']; echo '(<i>' . $grad . '</i>)'; ?></li>
</ul>
<br><br>
<table>
<thead>
<tr>
<th>Name</th>
<th>Acces</th>
<th colspan="2">Actiune</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($results, MYSQLI_ASSOC)) { ?>
<tr>
<td><?php echo $row['auth']; ?></td>
<td><?php echo $row['grad']; ?></td>
<td><a class="edit_btn" href="admin.php?edit=<?php echo $row['id']; ?>">Edit</a></td>
<td><a class="del_btn" href="admin.php?del=<?php echo $row['id']; ?>">Delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
$current_user_id = $id; // get it from the session if user is logged in
if ($current_user_id == 1):
?>
<form action="admin.php" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Name</label>
<input type="text" name="auth" value="<?php echo $auth; ?>">
</div>
<div class="input-group">
<label>Acces</label>
<input type="text" name="access" value="<?php echo $access; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password" value="<?php echo $password; ?>">
</div>
<div class="input-group">
<label>Flag type</label>
<input type="text" name="flags" value="<?php echo $flags; ?>">
</div>
<div class="input-group">
<label>Grad</label>
<div class="styled-select slate">
<select name="grad">
<option value="Creator">Creator</option>
<option value="Fondator">Fondator</option>
<option value="Administrator">Administrator</option>
<option value="Helper">Helper</option>
<option value="Slot">Slot</option>
</select>
</div>
</div>
<div class="input-group">
<?php if ($edit_state == false): ?>
<button type="submit" name="save" class="btn">SAVE</button>
<?php else: ?>
<button type="submit" name="update" class="btn">UPDATE</button>
<?php endif ?>
</div>
</form>
</body>
</html>
Daca se poate sa ma ajutati cu functia, am tot incercat diverse functii, dar am esuat de fiecare data ...