Advertisement
Guest User

edit profile

a guest
Mar 27th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. <?php
  2. include_once('includes/no-session.inc.php');
  3. include_once ("classes/users.class.php");
  4. $showavatar = new Users();
  5. $showavatar->showAvatar();
  6. if(!empty($_POST)){
  7. if(isset($_POST['update'])){
  8. $editEmail = strip_tags($_POST['editEmail']);
  9. $editUsername = strip_tags($_POST['editUsername']);
  10. $editBio = strip_tags($_POST['editBio']);
  11. $_SESSION['bio'] = strip_tags($_POST['editBio']);
  12. $newPassword = strip_tags($_POST['newPassword']);
  13. $confirmNewPassword = strip_tags($_POST['confirmNewPassword']);
  14. if(strlen(trim($editEmail)) != 0 or strlen(trim($editUsername)) != 0 or strlen(trim($editBio)) != 0)
  15. {
  16. $updateProfile = new Users();
  17. $updateProfile->EditEmail = $editEmail;
  18. if(!empty($editUsername))
  19. {
  20. $updateProfile->EditUsername = $editUsername;
  21. }
  22. $updateProfile->EditBio = $editBio;
  23. $updateProfile->updateProfile();
  24. $messageUpdate = "Your information was successfully updated.";
  25. }
  26. else
  27. {
  28. $messageEmptySubmit = "We could not change your information. Try again!";
  29. }
  30. if(strlen(trim($newPassword)) != 0 and strlen(trim($confirmNewPassword)) != 0)
  31. {
  32. if(strcmp($newPassword, $confirmNewPassword) == 0){
  33. $updatePassword = new Users();
  34. $updatePassword->EditPassword = $confirmNewPassword;
  35. $updatePassword->updatePassword();
  36.  
  37. $passwordSucces = "Your password was successfully changed.";
  38. }
  39. else
  40. {
  41. $passwordError = "Woops, passwords do not match. Try again!";
  42. }
  43. }
  44. }
  45. if(isset($_POST['upload'])){
  46. if ($_FILES["file"]["error"] > 0)
  47. {
  48. //for error messages: see http://php.net/manual/en/features.fileupload.errors.php
  49. switch($_FILES["file"]["error"])
  50. {
  51. case 1:
  52. $errorImage = "We are sorry. Your file is too big(Max. 2mb)";
  53. break;
  54. default:
  55. $errorImage = "Woops, uploading failed.";
  56. }
  57. }
  58. else
  59. {
  60. $p = new Users();
  61. $p->moveAvatar();
  62. $p->saveAvatar();
  63. }
  64. }
  65. }
  66. // PRIVACY SETTINGS
  67. $privacySetting = "Public";
  68. $privacyUitleg = "This means that anyone can see your posts.";
  69. ?><!doctype html>
  70. <html lang="en">
  71. <head>
  72. <meta charset="UTF-8">
  73. <title>Imdstagram</title>
  74. <link rel="stylesheet" href="css/reset.css">
  75. <link rel="stylesheet" href="css/style.css">
  76. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  77. <script src="js/scripts.js"></script>
  78. <script type="text/javascript">
  79. $(document).ready(function()
  80. {
  81. $("#username").keyup(function()
  82. {
  83. var username = $(this).val();
  84. if(username.length > 2)
  85. {
  86. $("#availability").html('checking...');
  87. $.ajax({
  88. type : 'POST',
  89. url : 'includes/username-check.inc.php',
  90. data : $(this).serialize(),
  91. success : function(data)
  92. {
  93. $("#availability").html(data);
  94. }
  95. });
  96. return false;
  97. }
  98. else
  99. {
  100. $("#availability").html('');
  101. }
  102. });
  103. });
  104. </script>
  105. </head>
  106. <body>
  107. <?php include_once("includes/nav.inc.php"); ?>
  108.  
  109. <div class="editContainer">
  110. <div class="editDetails">
  111. <h1>Avatar uploaden</h1>
  112. <img class="avatar" src="<?php echo $_SESSION['avatar']; ?>" alt="avatar">
  113.  
  114. <form class="formUpload" action="" enctype="multipart/form-data" method="post">
  115. <label for="file">Avatar uploaden:</label>
  116. <input type="file" name="file" id="file">
  117. <?php
  118. if( isset($errorImage) ) {
  119. echo "<p class='messageUpdateError'>$errorImage</p>";
  120. }
  121. ?>
  122.  
  123. <input class="btnUpload" type="submit" name="upload" value="Upload">
  124. </form>
  125.  
  126. <h1>Profiel bewerken</h1>
  127.  
  128. <form class="formDetails formPassword" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  129.  
  130. <label for="email">E-mailadres:</label>
  131. <input type="email" name="editEmail"></br>
  132.  
  133. <label for="username">Gebruikersnaam:</label>
  134. <input id="username" type="text" name="editUsername"></br>
  135. <span id="availability"></span>
  136.  
  137. <label for="bio">Biografie:</label>
  138. <textarea name="editBio" maxlength="150" id="bio" cols="30" rows="5"></textarea></br>
  139.  
  140. <?php
  141. if( isset($messageUpdate) ) {
  142. echo "<p class='messageUpdate'>$messageUpdate</p>";
  143. }
  144. ?>
  145.  
  146. <h1>Wachtwoord wijzigen</h1>
  147.  
  148. <label for="newpassword">Nieuw wachtwoord:</label>
  149. <input type="password" name="newPassword"></br>
  150.  
  151. <label for="confirmnewpassword">Nieuw wachtwoord bevestigen:</label>
  152. <input type="password" name="confirmNewPassword"></br>
  153.  
  154. <?php
  155. if( isset($passwordSucces) )
  156. {
  157. echo "<p class='messageUpdate'>$passwordSucces</p>";
  158. }
  159. else if( isset($passwordError) )
  160. {
  161. echo "<p class='messageUpdateError'>$passwordError</p>";
  162. }
  163. else if( isset($messageEmptySubmit) )
  164. {
  165. echo "<p class='messageUpdateError'>$messageEmptySubmit</p>";
  166. }
  167. ?>
  168.  
  169. <input class="submitEdit" name="update" type="submit" value="Gegevens wijzigen">
  170. </form>
  171. <h1>Privacy</h1>
  172. <button class="<?php echo $privacySetting; ?>"><?php echo $privacySetting; ?></button>
  173. <p>Your profile is: <strong id="privacySetting"><?php echo $privacySetting; ?></strong>.</p>
  174.  
  175. <p id="privacyUitleg"> <?php echo $privacyUitleg; ?></p>
  176.  
  177.  
  178. </div>
  179. </div>
  180. </body>
  181. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement