Advertisement
Guest User

hir

a guest
Mar 29th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require("../mainconfig.php");
  4.  
  5. if (isset($_SESSION['user'])) {
  6. $ses_username = $_SESSION['user']['username'];
  7. $check_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$ses_username' AND status = 'Active'");
  8. $data_user = mysqli_fetch_assoc($check_user);
  9. $data_username = $data_user['username'];
  10. if (mysqli_num_rows($check_user) == 0) {
  11. header("Location: ".$cfg_baseurl."logout.php");
  12. } else if ($data_user['level'] == "Member") {
  13. header("Location: ".$cfg_baseurl);
  14. } else if($data_user['level'] == "Reseller") {
  15. header("Location: ".$cfg_baseurl);
  16. die();
  17. } else {
  18. include("../lib/header.php");
  19. $msg_type = "nothing";
  20. if (isset($_POST['add'])) {
  21. $post_username = $_POST['username'];
  22. $post_password = $_POST['password'];
  23. $post_duration = $_POST['duration'];
  24. if ($data_user['level'] == "Developer") {
  25. $post_level = $_POST['level'];
  26. $pricel = 0;
  27. } else if ($data_user['level'] == "Admin") {
  28. $post_level = $_POST['level'];
  29. if ($post_level == "Reseller") {
  30. $pricel = $reseller_price;
  31. $post_balance = $reseller_bonus;
  32. } else {
  33. $pricel = 0;
  34. $post_balance = 0;
  35. }
  36. } else {
  37. $post_level = "Member";
  38. $pricel = 0;
  39. $post_balance = 0;
  40. }
  41.  
  42. $pcheck_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$post_username'");
  43. $pcheck_duration = mysqli_query($db, "SELECT * FROM price WHERE duration = '$post_duration'");
  44.  
  45. $pdata_duration = mysqli_fetch_assoc($pcheck_duration);
  46. $price = $pdata_duration['price']+$pricel;
  47.  
  48. if (empty($post_username) OR empty($post_password) OR empty($post_duration)) {
  49. $msg_type = "error";
  50. $msg_content = "<b>GAGAL:</b> Mohon melengkapi semua input.";
  51. } else if ($data_user['level'] == "Admin" AND $post_level !== "Reseller" AND $post_level !== "Member") {
  52. $msg_type = "error";
  53. $msg_content = "<b>GAGAL:</b> What are you doing dude? /.Mr.WebDev404 was here.";
  54. } else if (mysqli_num_rows($pcheck_user) > 0) {
  55. $msg_type = "error";
  56. $msg_content = "<b>GAGAL:</b> Username <i>$post_username</i> sudah terdaftar.";
  57. } else if (strlen($post_password) < 5) {
  58. $msg_type = "error";
  59. $msg_content = "<b>GAGAL:</b> Password minimal 5 karakter.";
  60. } else if (mysqli_num_rows($pcheck_duration) == 0) {
  61. $msg_type = "error";
  62. $msg_content = "<b>GAGAL:</b> Durasi tidak ditemukan.";
  63. } else if ($data_user['balance'] < $price) {
  64. $msg_type = "error";
  65. $msg_content = "<b>GAGAL:</b> Saldo Anda tidak cukup untuk melakukan pendaftaran member.";
  66. } else {
  67. $exp_date = sum_date($date, $post_duration);
  68. $update_user = mysqli_query($db, "UPDATE users SET balance = balance-$price WHERE username = '$data_username'");
  69. $post_passwords = password_hash($post_password, PASSWORD_DEFAULT);
  70. if ($update_user == true) {
  71. $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')");
  72. if ($insert_query == true) {
  73. $msg_type = "success";
  74. $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";
  75. } else {
  76. $msg_type = "error";
  77. $msg_content = "<b>GAGAL:</b> Kesalahan sistem. #2";
  78. }
  79. } else {
  80. $msg_type = "error";
  81. $msg_content = "<b>GAGAL:</b> Kesalahan sistem. #1";
  82. }
  83. }
  84. }
  85. $check_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$ses_username' AND status = 'Active'");
  86. $data_user = mysqli_fetch_assoc($check_user);
  87. ?>
  88. <div class="row">
  89. <div class="col-md-12">
  90. <div class="panel panel-primary">
  91. <div class="panel-heading">
  92. <i class="fa fa-plus fa-fw"></i> Tambah Pengguna (Sisa saldo: Rp <?php echo number_format($data_user['balance'],0,',','.'); ?>)
  93. </div>
  94. <!-- /.panel-heading -->
  95. <div class="panel-body">
  96. <div class="alert alert-info">
  97. Jumlah pemotongan saldo jika ingin mendaftarkan user<br />
  98. <?php
  99. $fcheck_duration = mysqli_query($db, "SELECT * FROM price ORDER BY duration ASC");
  100. while($fdata_duration = mysqli_fetch_assoc($fcheck_duration)) {
  101. ?>
  102. <?php echo $fdata_duration['duration']; ?> Hari : Rp <?php echo number_format($fdata_duration['price'],0,',','.'); ?> Saldo<br />
  103. <?php
  104. }
  105. ?>
  106. <?php
  107. if ($data_user['level'] == "Admin") {
  108. ?>
  109. <br />Jika mendaftarkan Reseller, maka potongan saldo Rp <?php echo number_format($reseller_price,0,',','.'); ?>
  110. <?php
  111. }
  112. ?>
  113. </div>
  114. <?php
  115. include "../lib/result_msg.php";
  116. ?>
  117. <form role="form" method="POST">
  118. <div class="form-group">
  119. <label>Username</label>
  120. <input class="form-control" type="text" name="username">
  121. <p class="help-block"></p>
  122. </div>
  123. <div class="form-group">
  124. <label>Password</label>
  125. <input class="form-control" type="text" name="password">
  126. <p class="help-block"></p>
  127. </div>
  128. <?php
  129. if ($data_user['level'] == "Developer") {
  130. ?>
  131. <div class="form-group">
  132. <label>Level</label>
  133. <select class="form-control" name="level">
  134. <option value="Member">Member</option>
  135. <option value="Reseller">Reseller</option>
  136. <option value="Admin">Admin</option>
  137. </select>
  138. <p class="help-block"></p>
  139. </div>
  140. <?php
  141. } else if ($data_user['level'] == "Admin") {
  142. ?>
  143. <div class="form-group">
  144. <label>Level</label>
  145. <select class="form-control" name="level">
  146. <option value="Member">Member</option>
  147. <option value="Reseller">Reseller</option>
  148. <option value="Admin">Admin</option>
  149. </select>
  150. <p class="help-block"></p>
  151. </div>
  152. <?php
  153. }
  154. ?>
  155. <div class="form-group">
  156. <label>Durasi</label>
  157. <select class="form-control" name="duration"> <?php
  158. $fcheck_duration = mysqli_query($db, "SELECT * FROM price ORDER BY duration ASC");
  159. while($fdata_duration = mysqli_fetch_assoc($fcheck_duration)) {
  160. ?>
  161. <option value="<?php echo $fdata_duration['duration']; ?>"><?php echo $fdata_duration['duration']; ?> Hari</option>
  162. <?php
  163. }
  164. ?>
  165. </select>
  166. <p class="help-block"></p>
  167. </div>
  168. <div class="pull-right">
  169. <button type="reset" class="btn btn-warning"><i class="fa fa-undo"></i> Ulangi</button>
  170. <button type="submit" class="btn btn-success" name="add"><i class="fa fa-check"></i> Tambah</button>
  171. </div>
  172. </form>
  173. </div>
  174. <!-- /.panel-body -->
  175. </div>
  176. <!-- /.panel -->
  177. </div>
  178. <!-- /.col -->
  179. </div>
  180. <!-- /.row -->
  181. <?php
  182. include("../lib/footer.php");
  183. }
  184. } else {
  185. header("Location: ".$cfg_baseurl);
  186. }
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement