/admin/registrations.php

https://github.com/whale2/users · PHP · 180 lines · 158 code · 22 blank · 0 comment · 24 complexity · b7b987d679acc37cd597d8bce8b4376a MD5 · raw file

  1. <?php
  2. require_once(dirname(__FILE__).'/admin.php');
  3. $ADMIN_SECTION = 'registrations';
  4. require_once(dirname(__FILE__).'/header.php');
  5. $dailyregs = User::getDailyRegistrations();
  6. $total = 0;
  7. ?>
  8. <script type='text/javascript' src='swfobject/swfobject/swfobject.js'></script>
  9. <script type='text/javascript' src='http://www.google.com/jsapi'></script>
  10. <script type='text/javascript'>
  11. google.load('visualization', '1', {'packages':['annotatedtimeline', 'corechart']});
  12. google.setOnLoadCallback(function() {
  13. var data = new google.visualization.DataTable();
  14. data.addColumn('date', 'Date');
  15. data.addColumn('number', 'Total Users');
  16. data.addColumn('number', 'Daily Registrations');
  17. var daily = [<?php
  18. $first = true;
  19. foreach ($dailyregs as $day)
  20. {
  21. if (!$first) {
  22. ?>,
  23. <?php
  24. }
  25. else
  26. {
  27. $first = false;
  28. }
  29. $total += $day['regs'];
  30. ?> [new Date('<?php echo $day['regdate']?>'), <?php echo $total?>, <?php echo $day['regs']?>]<?php
  31. }
  32. ?>
  33. ];
  34. data.addRows(daily);
  35. if (swfobject.hasFlashPlayerVersion("5")) {
  36. var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
  37. chart.draw(data, {
  38. displayAnnotations: true,
  39. scaleColumns: [0, 1],
  40. scaleType: 'allmaximized'
  41. });
  42. } else {
  43. var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  44. chart.draw(data, {
  45. legend: 'top'
  46. });
  47. }
  48. });
  49. </script>
  50. <div id='chart_div' style='width: 100%; height: 240px; margin-bottom: 1em'></div>
  51. <table cellpadding="5" cellspacing="0" border="1" width="100%">
  52. <tr><th>ID</th><th>Reg</th><th>Credentials</th><th>Name</th><th>Email</th><th>Points</th></tr>
  53. <?php
  54. $perpage = 20;
  55. $pagenumber = 0;
  56. if (array_key_exists('page', $_GET)) {
  57. $pagenumber = $_GET['page'];
  58. }
  59. $search = null;
  60. if (array_key_exists('q', $_GET)) {
  61. $search = trim($_GET['q']);
  62. if ($search == '') {
  63. $search = null;
  64. }
  65. }
  66. if (array_key_exists('sort', $_GET) && $_GET['sort'] == 'activity') {
  67. $sortby = 'activity';
  68. } else {
  69. $sortby = 'registration';
  70. }
  71. if (is_null($search)) {
  72. $users = User::getUsers($pagenumber, $perpage, $sortby);
  73. } else {
  74. $users = User::searchUsers($search, $pagenumber, $perpage, $sortby);
  75. }
  76. ?>
  77. <tr><td colspan="7" valign="middle">
  78. <?php
  79. if (count($users) == $perpage) {
  80. ?><a style="float: right" href="?page=<?php echo $pagenumber+1; echo is_null($search) ? '' : '&q='.urlencode($search)?>">next &gt;&gt;&gt;</a><?php
  81. }
  82. else
  83. {
  84. ?><span style="color: silver; float: right">next &gt;&gt;&gt;</span><?php
  85. }
  86. if ($pagenumber > 0) {
  87. ?><a style="float: left" href="?page=<?php echo $pagenumber-1; echo is_null($search) ? '' : '&q='.urlencode($search) ?>">&lt;&lt;&lt;prev</a><?php
  88. }
  89. else
  90. {
  91. ?><span style="color: silver; float: left">&lt;&lt;&lt;prev</span><?php
  92. }
  93. ?>
  94. <span style="float: left; margin: 0 2em 0 1em;">Page <?php echo $pagenumber+1?></span>
  95. <form action="" id="search" name="search">
  96. <input type="text" id="q" name="q"<?php echo is_null($search) ? '' : ' value="'.htmlspecialchars($search).'"'?>/><input type="submit" value="search"/><input type="button" value="clear" onclick="document.getElementById('q').value=''; document.search.submit()"/>
  97. Sort by
  98. <select name="sort" onchange="document.search.submit();">
  99. <option value="registration"<?php echo $sortby == 'registration' ? ' selected="yes"' : '' ?>>Registration date</option>
  100. <option value="activity"<?php echo $sortby == 'activity' ? ' selected="yes"' : '' ?>>User activity</option>
  101. </select>
  102. </form>
  103. </td></tr>
  104. <?php
  105. $now = time();
  106. foreach ($users as $user)
  107. {
  108. $regtime = $user->getRegTime();
  109. $ago = intval(floor(($now - $regtime)/86400));
  110. $tz = date_default_timezone_get();
  111. ?><tr valign="top">
  112. <td><a href="user.php?id=<?php $userid = $user->getID(); echo $userid; ?>"><?php echo $userid; ?></a></td>
  113. <td align="right"><?php echo date('M j, h:iA', $regtime)?> (<?php if ($ago <= 5) {?><span style="color: #00<?php echo sprintf('%02s', dechex((4 - $ago) * 150 / 4 + 50))?>00; font-weight: bold"><?php }?><?php echo $ago?> day<?php echo $ago > 1 ? 's' : '' ?> ago<?php if ($ago <= 5) {?></span><?php }?>)</td>
  114. <td><?php
  115. foreach (UserConfig::$authentication_modules as $module)
  116. {
  117. $creds = $module->getUserCredentials($user);
  118. if (!is_null($creds)) {
  119. ?>
  120. <div><b><?php echo $module->getID() ?>: </b><?php echo $creds->getHTML() ?></div>
  121. <?php
  122. }
  123. }
  124. ?></td>
  125. <td><a href="user.php?id=<?php echo $userid ?>"><?php echo UserTools::escape($user->getName())?></a></td>
  126. <td><?php echo UserTools::escape($user->getEmail())?></td>
  127. <td><?php
  128. $points = $user->getPoints();
  129. if ($points > 0) {
  130. ?><a href="./activity.php?userid=<?php echo $userid ?>"><?php echo $points ?></a><?php
  131. }
  132. ?>
  133. </td>
  134. </tr><?php
  135. }
  136. ?>
  137. <tr><td colspan="7">
  138. <?php
  139. if (count($users) == $perpage) {
  140. ?><a style="float: right" href="?page=<?php echo $pagenumber+1; echo is_null($search) ? '' : '&q='.urlencode($search)?>">next &gt;&gt;&gt;</a><?php
  141. }
  142. else
  143. {
  144. ?><span style="color: silver; float: right">next &gt;&gt;&gt;</span><?php
  145. }
  146. if ($pagenumber > 0) {
  147. ?><a style="float: left" href="?page=<?php echo $pagenumber-1; echo is_null($search) ? '' : '&q='.urlencode($search)?>">&lt;&lt;&lt;prev</a><?php
  148. }
  149. else
  150. {
  151. ?><span style="color: silver; float: left">&lt;&lt;&lt;prev</span><?php
  152. }
  153. ?>
  154. <span style="float: left; margin-left: 2em">Page <?php echo $pagenumber+1?></span>
  155. </td></tr>
  156. </table>
  157. <?php
  158. require_once(dirname(__FILE__).'/footer.php');