PageRenderTime 35ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/edit.php

https://github.com/whale2/users
PHP | 152 lines | 129 code | 20 blank | 3 comment | 14 complexity | 838fa95e90af8dcf348dca3e89184984 MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/config.php');
  3. require_once(dirname(__FILE__).'/User.php');
  4. $user = User::require_login();
  5. UserTools::preventCSRF();
  6. $errors = array();
  7. $module = UserConfig::$authentication_modules[0];
  8. if (array_key_exists('module', $_GET))
  9. {
  10. foreach (UserConfig::$authentication_modules as $module)
  11. {
  12. if ($module->getID() == $_GET['module']) {
  13. break;
  14. }
  15. }
  16. }
  17. if (is_null($module))
  18. {
  19. throw new Exception('Wrong module specified');
  20. }
  21. if (array_key_exists('save', $_POST))
  22. {
  23. try
  24. {
  25. if ($module->processEditUser($user, $_POST))
  26. {
  27. header('Location: '.UserConfig::$USERSROOTURL.'/edit.php?module='.$_GET['module']);
  28. }
  29. else
  30. {
  31. header('Location: '.UserConfig::$USERSROOTURL.'/edit.php?module='.$_GET['module'].'&error=failed');
  32. }
  33. exit;
  34. }
  35. catch(InputValidationException $ex)
  36. {
  37. $errors[$module->getID()] = $ex->getErrors();
  38. }
  39. catch(ExistingUserException $ex)
  40. {
  41. $user_exists = true;
  42. $errors[$module->getID()] = $ex->getErrors();
  43. }
  44. }
  45. require_once(UserConfig::$header);
  46. ?>
  47. <style>
  48. #userbase-edit-info {
  49. font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  50. background: white;
  51. padding: 0 1em;
  52. margin: 0;
  53. }
  54. #userbase-edit-info h2 {
  55. font-weight: bold;
  56. font-size: 2.5em;
  57. }
  58. #userbase-edit-info h3 {
  59. font-weight: bold;
  60. font-size: 1.5em;
  61. }
  62. .userbase-errorbox {
  63. background: #f7dfb9;
  64. padding: 0.4em 1em;
  65. margin: 1em 0;
  66. width: 515px;
  67. border: 4px solid #f77;
  68. border-radius: 7px;
  69. -moz-border-radius: 7px;
  70. -webkit-border-radius: 7px;
  71. font-size: 1.2em;
  72. color: #500;
  73. font-weight: bold;
  74. }
  75. </style>
  76. <div id="userbase-edit-info">
  77. <h2>Edit Your Information</h2>
  78. <div style="float: right; width: 400px">
  79. <div>
  80. <?php if (UserConfig::$useAccounts) { ?>
  81. <h2>Accounts:</h2>
  82. <?php
  83. $accounts = $user->getAccounts();
  84. foreach ($accounts as $user_account) {
  85. ?><div>
  86. <?php echo $user_account->getName() ?> (<?php echo $user_account->getPlan()->name ?>)<?php
  87. if ($user_account->getUserRole() == Account::ROLE_ADMIN) {
  88. ?> - <a href="<?php echo UserConfig::$USERSROOTURL.'/manage_account.php?account='.$user_account->getID(); ?>">manage</a><?php
  89. }
  90. ?></div><?php
  91. }
  92. }
  93. ?>
  94. </div>
  95. <?php if (!is_null(UserConfig::$maillist) && file_exists(UserConfig::$maillist))
  96. {
  97. ?>
  98. <?php include(UserConfig::$maillist); ?>
  99. <?php
  100. }
  101. ?></div>
  102. <div id="userbase-authlist">
  103. <?php
  104. foreach (UserConfig::$authentication_modules as $module)
  105. {
  106. $id = $module->getID();
  107. ?><div style="background: white; padding: 0 1em">
  108. <h3 name="<?php echo $id?>"><?php echo $module->getTitle()?></h3>
  109. <?php
  110. if (array_key_exists($id, $errors) && is_array($errors[$id]) && count($errors[$id]) > 0)
  111. {
  112. ?><div class="userbase-errorbox"><ul><?php
  113. foreach ($errors[$id] as $field => $errorset)
  114. {
  115. foreach ($errorset as $error)
  116. {
  117. ?><li><?php echo $error?></li><?php
  118. }
  119. }
  120. ?></ul></div><?php
  121. }
  122. $module->renderEditUserForm("?module=$id",
  123. array_key_exists($id, $errors) ? $errors[$id] : array(),
  124. $user,
  125. $_POST);
  126. ?></div><?php
  127. }
  128. ?>
  129. </div>
  130. </div>
  131. <?php
  132. require_once(UserConfig::$footer);