Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require("../mainconfig.php");
- if (isset($_SESSION['user'])) {
- $ses_username = $_SESSION['user']['username'];
- $check_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$ses_username' AND status = 'Active'");
- $data_user = mysqli_fetch_assoc($check_user);
- $data_username = $data_user['username'];
- if (mysqli_num_rows($check_user) == 0) {
- header("Location: ".$cfg_baseurl."logout.php");
- } else if ($data_user['level'] == "Member") {
- header("Location: ".$cfg_baseurl);
- } else if($data_user['level'] == "Reseller") {
- header("Location: ".$cfg_baseurl);
- die();
- } else {
- include("../lib/header.php");
- $msg_type = "nothing";
- if (isset($_POST['add'])) {
- $post_username = $_POST['username'];
- $post_password = $_POST['password'];
- $post_duration = $_POST['duration'];
- if ($data_user['level'] == "Developer") {
- $post_level = $_POST['level'];
- $pricel = 0;
- } else if ($data_user['level'] == "Admin") {
- $post_level = $_POST['level'];
- if ($post_level == "Reseller") {
- $pricel = $reseller_price;
- $post_balance = $reseller_bonus;
- } else {
- $pricel = 0;
- $post_balance = 0;
- }
- } else {
- $post_level = "Member";
- $pricel = 0;
- $post_balance = 0;
- }
- $pcheck_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$post_username'");
- $pcheck_duration = mysqli_query($db, "SELECT * FROM price WHERE duration = '$post_duration'");
- $pdata_duration = mysqli_fetch_assoc($pcheck_duration);
- $price = $pdata_duration['price']+$pricel;
- if (empty($post_username) OR empty($post_password) OR empty($post_duration)) {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Mohon melengkapi semua input.";
- } else if ($data_user['level'] == "Admin" AND $post_level !== "Reseller" AND $post_level !== "Member") {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> What are you doing dude? /.Mr.WebDev404 was here.";
- } else if (mysqli_num_rows($pcheck_user) > 0) {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Username <i>$post_username</i> sudah terdaftar.";
- } else if (strlen($post_password) < 5) {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Password minimal 5 karakter.";
- } else if (mysqli_num_rows($pcheck_duration) == 0) {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Durasi tidak ditemukan.";
- } else if ($data_user['balance'] < $price) {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Saldo Anda tidak cukup untuk melakukan pendaftaran member.";
- } else {
- $exp_date = sum_date($date, $post_duration);
- $update_user = mysqli_query($db, "UPDATE users SET balance = balance-$price WHERE username = '$data_username'");
- $post_passwords = password_hash($post_password, PASSWORD_DEFAULT);
- if ($update_user == true) {
- $insert_query = mysqli_query($db, "INSERT INTO users (username, password, balance, level, join_date, exp_date, status, uplink) VALUES ('$post_username', '$post_passwords', '$post_balance', '$post_level', '$date', '$exp_date', 'Active', '$data_username')");
- if ($insert_query == true) {
- $msg_type = "success";
- $msg_content = "<b>Sukses -</b> $post_level berhasil ditambahkan.<br />Username: $post_username<br />Password: $post_password<br />Durasi: $post_duration hari<br />Expired: $exp_date";
- } else {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Kesalahan sistem. #2";
- }
- } else {
- $msg_type = "error";
- $msg_content = "<b>GAGAL:</b> Kesalahan sistem. #1";
- }
- }
- }
- $check_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$ses_username' AND status = 'Active'");
- $data_user = mysqli_fetch_assoc($check_user);
- ?>
- <div class="row">
- <div class="col-md-12">
- <div class="panel panel-primary">
- <div class="panel-heading">
- <i class="fa fa-plus fa-fw"></i> Tambah Pengguna (Sisa saldo: Rp <?php echo number_format($data_user['balance'],0,',','.'); ?>)
- </div>
- <!-- /.panel-heading -->
- <div class="panel-body">
- <div class="alert alert-info">
- Jumlah pemotongan saldo jika ingin mendaftarkan user<br />
- <?php
- $fcheck_duration = mysqli_query($db, "SELECT * FROM price ORDER BY duration ASC");
- while($fdata_duration = mysqli_fetch_assoc($fcheck_duration)) {
- ?>
- <?php echo $fdata_duration['duration']; ?> Hari : Rp <?php echo number_format($fdata_duration['price'],0,',','.'); ?> Saldo<br />
- <?php
- }
- ?>
- <?php
- if ($data_user['level'] == "Admin") {
- ?>
- <br />Jika mendaftarkan Reseller, maka potongan saldo Rp <?php echo number_format($reseller_price,0,',','.'); ?>
- <?php
- }
- ?>
- </div>
- <?php
- include "../lib/result_msg.php";
- ?>
- <form role="form" method="POST">
- <div class="form-group">
- <label>Username</label>
- <input class="form-control" type="text" name="username">
- <p class="help-block"></p>
- </div>
- <div class="form-group">
- <label>Password</label>
- <input class="form-control" type="text" name="password">
- <p class="help-block"></p>
- </div>
- <?php
- if ($data_user['level'] == "Developer") {
- ?>
- <div class="form-group">
- <label>Level</label>
- <select class="form-control" name="level">
- <option value="Member">Member</option>
- <option value="Reseller">Reseller</option>
- <option value="Admin">Admin</option>
- </select>
- <p class="help-block"></p>
- </div>
- <?php
- } else if ($data_user['level'] == "Admin") {
- ?>
- <div class="form-group">
- <label>Level</label>
- <select class="form-control" name="level">
- <option value="Member">Member</option>
- <option value="Reseller">Reseller</option>
- <option value="Admin">Admin</option>
- </select>
- <p class="help-block"></p>
- </div>
- <?php
- }
- ?>
- <div class="form-group">
- <label>Durasi</label>
- <select class="form-control" name="duration"> <?php
- $fcheck_duration = mysqli_query($db, "SELECT * FROM price ORDER BY duration ASC");
- while($fdata_duration = mysqli_fetch_assoc($fcheck_duration)) {
- ?>
- <option value="<?php echo $fdata_duration['duration']; ?>"><?php echo $fdata_duration['duration']; ?> Hari</option>
- <?php
- }
- ?>
- </select>
- <p class="help-block"></p>
- </div>
- <div class="pull-right">
- <button type="reset" class="btn btn-warning"><i class="fa fa-undo"></i> Ulangi</button>
- <button type="submit" class="btn btn-success" name="add"><i class="fa fa-check"></i> Tambah</button>
- </div>
- </form>
- </div>
- <!-- /.panel-body -->
- </div>
- <!-- /.panel -->
- </div>
- <!-- /.col -->
- </div>
- <!-- /.row -->
- <?php
- include("../lib/footer.php");
- }
- } else {
- header("Location: ".$cfg_baseurl);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement