Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. <?php
  2. $notice = array();
  3. if (isset($_POST['submit'])){
  4. $username = $_POST['uname'];
  5. $email = $_POST['email'];
  6. $password = $_POST['pass'];
  7. $groups = $_POST['groups'];
  8. if($groups == "Main Admin"){
  9. $level = 1;
  10. }else if($groups == "Administrator"){
  11. $level = 2;
  12. }else if($groups == "Content Creator"){
  13. $level = 3;
  14. }else if($groups == "Social Media Manager"){
  15. $level = 4;
  16. }else{
  17. $level = 5;
  18. }
  19. if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  20. $notice['email'] = "The email that you have entered is not a valid one";
  21. }else{
  22. $registration = new Register();
  23. $registration->CheckUname($username,$email,$password,$groups,$level);
  24. }
  25. }
  26. ?>
  27. <div class="content-wrapper">
  28. <section class="content-header">
  29. <h1>
  30. Add New Admin
  31. <small>You can add new admin here</small>
  32. </h1>
  33. <ol class="breadcrumb">
  34. <li class="active">addnewadmin.php</li>
  35. </ol>
  36. </section>
  37. <?php
  38. if(isset($notice['validation_email'])) {
  39. echo "
  40. <div class='alert alert-danger'>
  41. <strong>Hey!</strong> ".$notice['validation_email'].".
  42. </div>
  43. ";
  44. }
  45. if(isset($notice['username_exists'])) {
  46. echo "
  47. <div class='alert alert-danger'>
  48. <strong>Hey!</strong> ".$notice['username_exists'].".
  49. </div>
  50. ";
  51. }
  52. if(isset($notice['email_exists'])) {
  53. echo "
  54. <div class='alert alert-danger'>
  55. <strong>Hey!</strong> ".$notice['email_exists'].".
  56. </div>
  57. ";
  58. }
  59. if(isset($notice['success_message'])) {
  60. echo "
  61. <div class='alert alert-danger'>
  62. <strong>Hey!</strong> ".$notice['success_message'].".
  63. </div>
  64. ";
  65. }
  66. ?>
  67. <section class="content">
  68. <div class="row">
  69. <div class="col-md-6">
  70. <div class="box box-primary">
  71. <div class="box-header with-border">
  72. <h3 class="box-title">Required Information</h3>
  73. </div>
  74. <form role="form" method="POST" action="">
  75. <div class="box-body">
  76. <div class="form-group">
  77. <label>User name</label>
  78. <input type="text" class="form-control" placeholder="Enter username" name="uname" required>
  79. </div>
  80. <div class="form-group">
  81. <label for="exampleInputEmail1">Email address</label>
  82. <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" name="email" required>
  83. </div>
  84. <div class="form-group">
  85. <label for="exampleInputPassword1">Temporary password</label>
  86. <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Enter password" name="pass" required>
  87. </div>
  88. <div class="form-group">
  89. <label>Group admin</label>
  90. <select class="form-control" name="groups">
  91. <option value="Main Admin">Main Admin</option>
  92. <option value="Administrator">Administrator</option>
  93. <option value="Content Creator">Content Creator</option>
  94. <option value="Social Media Manager">Social Media Manager</option>
  95. <option value="Analyst">Analyst</option>
  96. </select>
  97. </div>
  98. </div>
  99. <div class="box-footer">
  100. Visit <a href="https://zite.pouyavagefi.com/documentation/types.php">admin types</a> documentation to know the differences between each admin.
  101. </div>
  102. <div class="box-footer">
  103. <button name="submit" type="submit" class="btn btn-primary">Submit</button>
  104. </div>
  105. </form>
  106. </div>
  107. </div>
  108. </div>
  109. </section>
  110. </div>
  111.  
  112. <?php
  113. class Register
  114. {
  115. private $db;
  116. public function __construct()
  117. {
  118. $this->db = new Connection();
  119. $this->db = $this->db->dbConnect();
  120. }
  121. public function CheckUname($username,$email,$password,$groups,$level)
  122. {
  123. if(!empty($username)&&($email))
  124. {
  125. $chk1 = $this->db->prepare("SELECT username FROM admins WHERE user_name= ?");
  126. $chk1->bindParam(1,$username);
  127. $chk1->execute();
  128. if($chk1->rowCount() == 1)
  129. {
  130. $notice['username_exists'] = "Try different username";
  131. return $notice;
  132. }else{
  133. $chk2 = $this->db->prepare("SELECT email FROM admins WHERE email_address= ?");
  134. $chk2->bindParam(1,$email);
  135. $chk2->execute();
  136. if($chk2->rowCount() == 1)
  137. {
  138. $notice['email_exists'] = "The email address that you have entered is already exists in database";
  139. return $notice;
  140. }else{
  141. $this->NewAdmin($username,$email,$password,$groups,$level);
  142. $notice['success_message'] = "New admin was successfully added";
  143. return $notice;
  144. }
  145. }
  146. }
  147. }
  148. public function NewAdmin($username,$email,$password,$groups,$level)
  149. {
  150. if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
  151. {
  152. $reg = $this->db->prepare("INSERT INTO admins (user_name, email_address, password_hash, group_admin, date_joined, admin_level) VALUES ( ?, ?, ?, ?, NOW(), ?)");
  153. $reg->bindParam(1,$username);
  154. $reg->bindParam(2,$email);
  155. $reg->bindParam(3,$password);
  156. $reg->bindParam(4,$groups);
  157. $reg->bindParam(5,$level);
  158. $reg->execute();
  159. }
  160. }
  161. }
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement