PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/invitations.php

https://github.com/whale2/users
PHP | 174 lines | 152 code | 22 blank | 0 comment | 16 complexity | 13590a6909949c7aca1592a69b1c9fe8 MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/admin.php');
  3. $user = User::require_login();
  4. if (!$user->isAdmin()) {
  5. require_once(dirname(__FILE__).'/admin_access_only.php');
  6. exit;
  7. }
  8. require_once(dirname(dirname(__FILE__)).'/Invitation.php');
  9. if (array_key_exists('save', $_POST))
  10. {
  11. foreach ($_POST as $key => $value)
  12. {
  13. if (strpos($key, 'code_') === 0 && trim($value) != '')
  14. {
  15. $invitation = Invitation::getByCode(substr($key, 5));
  16. $invitation->setComment($value);
  17. $invitation->save();
  18. }
  19. }
  20. header("Location: #message=saved");
  21. exit;
  22. }
  23. if (array_key_exists('add', $_POST) && is_numeric($_POST['add']))
  24. {
  25. $howmany = (int)$_POST['add'];
  26. if ($howmany > 0)
  27. {
  28. Invitation::generate($howmany);
  29. }
  30. header("Location: #message=added");
  31. exit;
  32. }
  33. $_styles = array (
  34. 'http://yui.yahooapis.com/2.7.0/build/button/assets/skins/sam/button.css',
  35. 'http://yui.yahooapis.com/2.7.0/build/container/assets/skins/sam/container.css'
  36. );
  37. $_scripts = array (
  38. 'http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js',
  39. 'http://yui.yahooapis.com/2.7.0/build/animation/animation-min.js',
  40. 'http://yui.yahooapis.com/2.7.0/build/connection/connection-min.js',
  41. 'http://yui.yahooapis.com/2.7.0/build/element/element-min.js',
  42. 'http://yui.yahooapis.com/2.7.0/build/button/button-min.js',
  43. 'http://yui.yahooapis.com/2.7.0/build/dragdrop/dragdrop-min.js',
  44. 'http://yui.yahooapis.com/2.7.0/build/container/container-min.js'
  45. );
  46. require_once(UserConfig::$header);
  47. ?>
  48. <script>
  49. YAHOO.util.Event.onDOMReady(function() {
  50. showMessages({
  51. added: { 'class': 'success', 'text': 'Invitations added'},
  52. saved: { 'class': 'success', 'text': 'Invitation comments saved'},
  53. });
  54. });
  55. </script>
  56. <h2><a href="./">Users</a> | Invitations</h2><div style="background: white; padding: 1em">
  57. <h2>Unsent Invitations</h2>
  58. <?php
  59. $invitations = Invitation::getUnsent();
  60. if (count($invitations) == 0)
  61. {
  62. ?><div style="border: 1px dotted silver; text-align: center; padding: 2em">
  63. <form action="" method="POST">
  64. Generate <input name="add" size="4" value="5"> more <input type="submit" value="&gt;&gt;">
  65. <?php UserTools::renderCSRFNonce(); ?>
  66. </form>
  67. </div>
  68. <?php
  69. }
  70. else
  71. {
  72. ?>
  73. <form action="" method="POST">
  74. <table cellpadding="5" cellspacing="0" border="1" width="100%">
  75. <tr><th>Code</th><th>By</th><th>Sent To</th><?php if (!is_null(UserConfig::$onRenderUserInvitationAction)) {?><th>Actions</th><?php }?></tr>
  76. <?php
  77. foreach ($invitations as $invitation)
  78. {
  79. $code = $invitation->getCode();
  80. ?><tr>
  81. <td><?php echo UserTools::escape($code)?></td>
  82. <td><?php // echo UserTools::escape(User::getUser($invitation->getIssuer())->getUserName())?></td>
  83. <td><input name="code_<?php echo UserTools::escape($invitation->getCode())?>" value="" style="width: 100%"></td><?php
  84. if (!is_null(UserConfig::$onRenderUserInvitationAction))
  85. {
  86. ?><td><?php
  87. call_user_func_array(UserConfig::$onRenderUserInvitationAction, array($code));
  88. ?></td><?php
  89. }
  90. ?></tr><?php
  91. }
  92. ?>
  93. <tr><td colspan="2"></td>
  94. <td><input type="submit" name="save" value="save &gt;&gt;" style="float: right"></td>
  95. <td></td></tr>
  96. </table>
  97. <?php UserTools::renderCSRFNonce(); ?>
  98. </form>
  99. <?php
  100. }
  101. $invitations = Invitation::getSent();
  102. if (count($invitations) > 0)
  103. {
  104. ?>
  105. <h2>Sent Invitations</h2>
  106. <table cellpadding="5" cellspacing="0" border="1" width="100%">
  107. <tr><th>Code</th><th>By</th><th>Sent To</th><?php if (!is_null(UserConfig::$onRenderUserInvitationFollowUpAction)) {?><th>Actions</th><?php }?></tr>
  108. <?php
  109. foreach ($invitations as $invitation)
  110. {
  111. $code = $invitation->getCode();
  112. $comment = $invitation->getComment();
  113. ?><tr>
  114. <td><?php echo UserTools::escape($code)?></td>
  115. <td><?php // echo UserTools::escape(User::getUser($invitation->getIssuer())->getUserName())?></td>
  116. <td><?php echo UserTools::escape($comment)?></td><?php
  117. if (!is_null(UserConfig::$onRenderUserInvitationFollowUpAction))
  118. {
  119. ?><td><?php
  120. call_user_func_array(UserConfig::$onRenderUserInvitationFollowUpAction,
  121. array($code, $comment)
  122. );
  123. ?></td><?php
  124. }
  125. ?></tr><?php
  126. }
  127. }
  128. ?>
  129. </table>
  130. <?php
  131. $invitations = Invitation::getAccepted();
  132. if (count($invitations) > 0)
  133. {
  134. ?>
  135. <h2>Accepted Invitations</h2>
  136. <table cellpadding="5" cellspacing="0" border="1" width="100%">
  137. <tr><th>Code</th><th>By</th><th>Sent To</th><th>User</th></tr>
  138. <?php
  139. foreach ($invitations as $invitation)
  140. {
  141. ?><tr>
  142. <td><?php echo UserTools::escape($invitation->getCode())?></td>
  143. <td><?php // echo UserTools::escape(User::getUser($invitation->getIssuer())->getUserName())?></td>
  144. <td><?php echo UserTools::escape($invitation->getComment())?></td>
  145. <td><?php echo UserTools::escape($invitation->getUser()->getUserName())?></td>
  146. </tr><?php
  147. }
  148. }
  149. ?>
  150. </table>
  151. </div><?php
  152. require_once(UserConfig::$footer);