Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. <?php
  2.  
  3. if( !preg_match( "/index.php/i", $_SERVER['PHP_SELF'] ) ) { die(); }
  4.  
  5. if( $_GET['id'] ) {
  6.  
  7. $id = $core->clean( $_GET['id'] );
  8.  
  9. $query = $db->query( "SELECT * FROM users WHERE id = '{$id}'" );
  10. $data = $db->assoc( $query );
  11.  
  12. $data['ugroups'] = explode( ",", $data['usergroups'] );
  13.  
  14. $editid = $data['id'];
  15.  
  16. }
  17.  
  18. ?>
  19. <form action="" method="post" id="addUser">
  20.  
  21. <div class="box">
  22.  
  23. <div class="square title">
  24. <strong>Add user</strong>
  25. </div>
  26.  
  27. <?php
  28.  
  29. if( $_POST['submit'] ) {
  30.  
  31. try {
  32.  
  33. $username = $core->clean( $_POST['username'] );
  34. $password = $core->clean( $_POST['password'] );
  35. $email = $core->clean( $_POST['email'] );
  36. $habbo = $core->clean( $_POST['habbo'] );
  37. $dgroup = $core->clean( $_POST['dgroup'] );
  38.  
  39. $query = $db->query( "SELECT * FROM usergroups" );
  40.  
  41. while( $array = $db->assoc( $query ) ) {
  42.  
  43. if( $_POST['ugroup-' . $array['id']] ) {
  44.  
  45. $ugroups .= $array['id'] . ",";
  46.  
  47. }
  48.  
  49. }
  50.  
  51. $password_enc = $core->encrypt( $password );
  52.  
  53. if( !$username or ( !$password and !$editid ) or !$dgroup or !$ugroups ) {
  54.  
  55. throw new Exception( "All fields are required." );
  56.  
  57. }
  58. else {
  59.  
  60. if( $editid ) {
  61.  
  62. if( $password ) {
  63.  
  64. $password = ", password = '{$password_enc}'";
  65.  
  66. }
  67. else {
  68.  
  69. unset( $password );
  70.  
  71. }
  72.  
  73. $db->query( "UPDATE users SET username = '{$username}'{$password}, email = '{$email}', habbo = '{$habbo}', displaygroup = '{$dgroup}', usergroups = '{$ugroups}' WHERE id = '{$editid}'" );
  74.  
  75. }
  76. else {
  77.  
  78. $db->query( "INSERT INTO users VALUES (NULL, '{$username}', '{$password_enc}', '{$email}', '{$habbo}', '{$dgroup}', '{$ugroups}');" );
  79.  
  80. }
  81.  
  82. echo "<div class=\"square good\">";
  83. echo "<strong>Success</strong>";
  84. echo "<br />";
  85. echo "User added!";
  86. echo "</div>";
  87.  
  88. }
  89.  
  90. }
  91. catch( Exception $e ) {
  92.  
  93. echo "<div class=\"square bad\">";
  94. echo "<strong>Error</strong>";
  95. echo "<br />";
  96. echo $e->getMessage();
  97. echo "</div>";
  98.  
  99. }
  100.  
  101. }
  102.  
  103. ?>
  104.  
  105. <table width="100%" cellpadding="3" cellspacing="0">
  106. <?php
  107.  
  108. // Here, we check if the user is part of management, but not an administrator!
  109. if( $user->hasGroup( '6' ) AND !$user->hasGroup( '7' ) ) {
  110.  
  111. // The user is a member of the management group, and as such, we get all usergroups apart from administrator
  112. $query = $db->query( "SELECT * FROM usergroups WHERE id != '7'" );
  113.  
  114. }
  115.  
  116. else {
  117.  
  118. // Otherwise, they can select them all ;)
  119. $query = $db->query( "SELECT * FROM usergroups" );
  120.  
  121. }
  122.  
  123. while( $array = $db->assoc( $query ) ) {
  124.  
  125. if( in_array( $array['id'], $data['ugroups'] ) ) {
  126.  
  127. $groups[$array['id'] . '_active'] = $array['name'];
  128.  
  129. }
  130. else {
  131.  
  132. $groups[$array['id']] = $array['name'];
  133.  
  134. }
  135.  
  136. if( $array['id'] == $data['displaygroup'] ) {
  137.  
  138. $dgroups[$array['id'] . '_active'] = $array['name'];
  139.  
  140. }
  141. else {
  142.  
  143. $dgroups[$array['id']] = $array['name'];
  144.  
  145. }
  146.  
  147. }
  148.  
  149. echo $core->buildField( "text",
  150. "required",
  151. "username",
  152. "Username",
  153. "The new username.",
  154. $data['username'] );
  155.  
  156. echo $core->buildField( "password",
  157. "<?php if( !$editid ) { ?>required<?php } ?>",
  158. "password",
  159. "Password",
  160. "The new password." );
  161.  
  162. echo $core->buildField( "text",
  163. "",
  164. "email",
  165. "Email",
  166. "The new email (optional).",
  167. $data['email'] );
  168.  
  169. echo $core->buildField( "text",
  170. "",
  171. "habbo",
  172. "Habbo name",
  173. "The new Habbo name (optional).",
  174. $data['habbo'] );
  175.  
  176. echo $core->buildField( "select",
  177. "required",
  178. "dgroup",
  179. "Display group",
  180. "The user's display group.",
  181. $dgroups );
  182.  
  183. echo $core->buildField( "checkbox",
  184. "required",
  185. "ugroup",
  186. "Active usergroups",
  187. "The user's active groups.",
  188. $groups );
  189.  
  190. ?>
  191. </table>
  192.  
  193. </div>
  194.  
  195. <div class="box" align="right">
  196.  
  197. <input class="button" type="submit" name="submit" value="Submit" />
  198.  
  199. </div>
  200.  
  201. </form>
  202.  
  203. <?php
  204. echo $core->buildFormJS('addUser');
  205.  
  206. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement