PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/conference/admin/attendees.php

https://github.com/azeckoski/az-php-sandbox
PHP | 394 lines | 341 code | 30 blank | 23 comment | 42 complexity | 6e7ad407567ae16fd48f3742ddefa557 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * file: index.php
  4. * Created on Mar 23, 2006 10:39:51 PM by @author aaronz
  5. * Aaron Zeckoski (aaronz@vt.edu) - Virginia Tech (http://www.vt.edu/)
  6. */
  7. ?>
  8. <?php
  9. require_once '../include/tool_vars.php';
  10. $PAGE_NAME = "Attendee List";
  11. $ACTIVE_MENU="REGISTER"; //for managing active links on multiple menus
  12. $Message = "";
  13. // connect to database
  14. require $ACCOUNTS_PATH.'sql/mysqlconnect.php';
  15. // check authentication
  16. require $ACCOUNTS_PATH.'include/check_authentic.php';
  17. // login if not autheticated
  18. //require $ACCOUNTS_PATH.'include/auth_login_redirect.php';
  19. // Make sure user is authorized
  20. $allowed = 0; // assume user is NOT allowed unless otherwise shown
  21. if (!$User->checkPerm("admin_conference")) {
  22. $allowed = 0;
  23. $Message = "Only admins with <b>admin_conference</b> may view this page.<br/>" .
  24. "Try out this one instead: <a href='$TOOL_URL/'>$TOOL_NAME</a>";
  25. } else {
  26. $allowed = 1;
  27. }
  28. // handle activation/deactivation controls
  29. if ($allowed) {
  30. if ($_REQUEST['activate']) {
  31. $sql = "update conferences set activated='Y' where id='".$_REQUEST['activate']."'";
  32. $result = mysql_query($sql) or die("Update query failed ($sql): " . mysql_error());
  33. } else if ($_REQUEST['deactivate']) {
  34. $sql = "update conferences set activated='N' where id='".$_REQUEST['deactivate']."'";
  35. $result = mysql_query($sql) or die("Update query failed ($sql): " . mysql_error());
  36. }
  37. }
  38. // Roles Filter
  39. $filter_roles_default = "show all Roles";
  40. $filter_roles = "";
  41. if ($_REQUEST["filter_roles"] && (!$_REQUEST["clearall"]) ) { $filter_roles = $_REQUEST["filter_roles"]; }
  42. $filter_roles_sql = "";
  43. if ($filter_roles && ($filter_roles != $filter_roles_default)) {
  44. $filter_roles_sql = " and primaryRole='$filter_roles' ";
  45. } else {
  46. $filter_roles = $filter_roles_default;
  47. }
  48. // get the search
  49. $searchtext = "";
  50. if ($_REQUEST["searchtext"]) { $searchtext = $_REQUEST["searchtext"]; }
  51. $sqlsearch = "";
  52. if ($searchtext) {
  53. $sqlsearch = " and (U1.username like '%$searchtext%' or U1.firstname like '%$searchtext%' or " .
  54. "U1.lastname like '%$searchtext%' or U1.email like '%$searchtext%' or U1.institution like '%$searchtext%') ";
  55. }
  56. // sorting
  57. $sortorder = "date_created desc";
  58. if ($_REQUEST["sortorder"]) { $sortorder = $_REQUEST["sortorder"]; }
  59. $sqlsorting = " order by $sortorder ";
  60. // main SQL to fetch all items
  61. $from_sql = " from users U1 join conferences C1 on U1.pk=C1.users_pk where confID='$CONF_ID' " ;
  62. // counting number of items
  63. // **************** NOTE - APPLY THE FILTERS TO THE COUNT AS WELL
  64. $count_sql = "select count(*) " . $from_sql . $sqlsearch;
  65. $result = mysql_query($count_sql) or die('Count query failed: ' . mysql_error());
  66. $row = mysql_fetch_array($result);
  67. $total_items = $row[0];
  68. // pagination control
  69. $num_limit = 25;
  70. if ($_REQUEST["num_limit"] == "All") {
  71. $num_limit = $total_items;
  72. $total_pages = 1;
  73. }
  74. else {
  75. $num_limit = $_REQUEST["num_limit"];
  76. if ($num_limit <= 0) { $num_limit = 1; }
  77. $total_pages = ceil($total_items / $num_limit);
  78. }
  79. $page = 1;
  80. $PAGE = $_REQUEST["page"];
  81. if ($PAGE) { $page = $PAGE; }
  82. $PAGING = $_REQUEST["paging"];
  83. if ($PAGING) {
  84. if ($PAGING == 'first') { $page = 1; }
  85. else if ($PAGING == 'prev') { $page--; }
  86. else if ($PAGING == 'next') { $page++; }
  87. else if ($PAGING == 'last') { $page = $total_pages; }
  88. }
  89. if ($page > $total_pages) { $page = $total_pages; }
  90. if ($page <= 0) { $page = 1; }
  91. $limitvalue = $page * $num_limit - ($num_limit);
  92. // we only want to limit the number of rows if we're not doing an export
  93. if ($_REQUEST["export"]) { $mysql_limit = ""; }
  94. else { $mysql_limit = " LIMIT $limitvalue, $num_limit"; }
  95. $start_item = $limitvalue + 1;
  96. $end_item = $limitvalue + $num_limit;
  97. if ($end_item > $total_items) { $end_item = $total_items; }
  98. // the main fetching query
  99. $sql = "select U1.username, U1.firstname, U1.lastname, U1.email, " .
  100. "U1.primaryRole, U1.institution, U1.institution_pk, U1.address, U1.city, U1.state, U1.zipcode, U1.country, U1.phone, C1.* " .
  101. $from_sql . $sqlsearch . $filter_roles_sql . $sqlsorting . $mysql_limit;
  102. //print "SQL=$sql<br/>";
  103. $result = mysql_query($sql) or die("Fetch query failed ($sql): " . mysql_error());
  104. $items_displayed = mysql_num_rows($result);
  105. // custom CSS file
  106. $CSS_FILE = $ACCOUNTS_URL."/include/accounts.css";
  107. $DATE_FORMAT = "M d, Y h:i a";
  108. // Do the export as requested by the user
  109. if ($_REQUEST["export"] && $allowed) {
  110. $date = date("Ymd-Hi",time());
  111. $filename = "conf_attendees-" . $date . ".csv";
  112. header("Content-type: text/x-csv");
  113. header("Content-disposition: attachment; filename=$filename\n\n");
  114. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  115. header("Expires: 0");
  116. $line = 0;
  117. while ($item = mysql_fetch_assoc($result)) {
  118. $line++;
  119. if ($line == 1) {
  120. echo "\"Conference Attendees Export:\",,\"$CONF_NAME\",\"$CONF_ID\"\n";
  121. print join(',', array_keys($item)) . "\n"; // add header line
  122. }
  123. foreach ($item as $name=>$value) {
  124. $value = str_replace("\"", "\"\"", $value); // fix for double quotes
  125. $item[$name] = '"' . trim($value) . '"'; // put quotes around each item
  126. }
  127. echo join(',', $item) . "\n";
  128. }
  129. echo "\n\"Exported on:\",\"" . date($DATE_FORMAT,time()) . "\"\n";
  130. exit;
  131. } // END EXPORT
  132. // set header links
  133. $EXTRA_LINKS =
  134. "<span class='extralinks'>" .
  135. "<a class='active' href='$CONFADMIN_URL/admin/attendees.php'>Attendee List</a>" .
  136. "<a href='$CONFADMIN_URL/admin/payment_info.php'>Payments</a>" .
  137. "<a href='$CONFADMIN_URL/admin/check_in.php'>Onsite Check-in</a>" .
  138. "</span>";
  139. ?>
  140. <?php // INCLUDE THE HTML HEAD
  141. require $ACCOUNTS_PATH.'include/top_header.php'; ?>
  142. <script type="text/javascript">
  143. <!--
  144. function orderBy(newOrder) {
  145. if (document.adminform.sortorder.value == newOrder) {
  146. document.adminform.sortorder.value = newOrder + " desc";
  147. } else {
  148. document.adminform.sortorder.value = newOrder;
  149. }
  150. document.adminform.submit();
  151. return false;
  152. }
  153. function doConfirm(item, type, action) {
  154. var response = window.confirm("Are you sure you want to "+action+" this "+type+" ("+item+")?");
  155. if (response) {
  156. return true;
  157. }
  158. return false;
  159. }
  160. // -->
  161. </script>
  162. <?php include $ACCOUNTS_PATH.'include/header.php' ?>
  163. <div id="maindata">
  164. <?= $Message ?>
  165. <?php
  166. // Put in footer and stop the rest of the page from loading if not allowed -AZ
  167. if (!$allowed) {
  168. include $ACCOUNTS_PATH.'include/footer.php';
  169. exit;
  170. }
  171. ?>
  172. <form name="adminform" method="post" action="<?= $_SERVER['PHP_SELF'] ?>" style="margin:0px;">
  173. <input type="hidden" name="sortorder" value="<?= $sortorder ?>"/>
  174. <div class="filterarea">
  175. <table border=0 cellspacing=0 cellpadding=0 width="100%">
  176. <tr>
  177. <td>
  178. <strong>Filter:</strong>
  179. </td>
  180. <td>
  181. <select style="font-size:.9em;"name="filter_roles" title="Filter the items by role">
  182. <option value="<?= $filter_roles ?>" selected><?= $filter_roles ?></option>
  183. <option value="Developer/Programmer">Developer/Programmer</option>
  184. <option value="Faculty">Faculty</option>
  185. <option value="Faculty Development">Faculty Development</option>
  186. <option value="Implementor">Implementor</option>
  187. <option value="Instructional Designer">Instructional Designer</option>
  188. <option value="Instructional Technologist">Instructional Technologist</option>
  189. <option value="Librarian">Librarian</option>
  190. <option value="Manager">Manager</option>
  191. <option value="System Administrator">System Administrator</option>
  192. <option value="UI/Interaction Designer">UI/Interaction Designer</option>
  193. <option value="University Administration">University Administration</option>
  194. <option value="User Support">User Support</option>
  195. <option value="show all Roles">show all Roles</option>
  196. </select>
  197. <input class="filter" type="submit" name="filter" value="Filter" title="Apply the current filter settings to the page" />
  198. &nbsp;&nbsp;
  199. </td> <td align="right">
  200. <?php
  201. $count_sql = "SELECT count(*) FROM conferences where activated = 'Y' and confId = '$CONF_ID'";
  202. $count_result = mysql_query($count_sql) or die("Count failed ($count_sql): " . mysql_error());
  203. $row = mysql_fetch_array($count_result);
  204. $total_activated = $row[0];
  205. $count_sql = "SELECT count(*) FROM conferences where date_created > curdate()-INTERVAL 7 DAY and confId = '$CONF_ID'";
  206. $count_result = mysql_query($count_sql) or die("Count failed ($count_sql): " . mysql_error());
  207. $row = mysql_fetch_array($count_result);
  208. $total_week = $row[0];
  209. $count_sql = "SELECT count(*) from conferences C1 join users U1 on U1.pk = C1.users_pk " .
  210. "and institution_pk = '1' where confId = '$CONF_ID'";
  211. $count_result = mysql_query($count_sql) or die("Count failed ($count_sql): " . mysql_error());
  212. $row = mysql_fetch_array($count_result);
  213. $non_members = $row[0];
  214. ?>
  215. <strong>Attendees:</strong>
  216. <label title="number of active registrations\n(i.e. signed up and paid)"><?= $total_activated ?></label>
  217. <span style="font-size:.9em;">
  218. (<label title="total number of registrations\n(including those who have not paid yet)"><?= $total_items ?> total</label>
  219. {<label style="color:red;" title="non-members that have not paid yet"><?= $total_items - $total_activated ?> inactive</label>},
  220. <label title="registrations in the past 7 days"><?= $total_week ?> recent</label>,
  221. <label title="members of Sakai partner institutions"><?= $total_items - $non_members ?> members</label> /
  222. <label style="color:#990099;" title="not members of Sakai partner institutions"><?= $non_members ?> non-members</label>)
  223. </span>
  224. </td>
  225. </tr>
  226. <tr>
  227. <td nowrap="y" style="padding-top:8px;" ><strong >Paging:</strong></td>
  228. <td nowrap="y" style="padding-top:8px;">
  229. <?php if ($_REQUEST["num_limit"] == "All") { ?>
  230. <input type="hidden" name="num_limit" value="All"/>
  231. <span class="keytext">
  232. Displaying all <?= $total_items ?> items
  233. </span>&nbsp;&nbsp;
  234. <strong>Show </strong> <input class="filter" type="submit" name="num_limit" value="25" /> per page
  235. <?php } else { ?>
  236. <input type="hidden" name="page" value="<?= $page ?>" />
  237. <input class="filter" type="submit" name="paging" value="first" title="Go to the first page" />
  238. <input class="filter" type="submit" name="paging" value="prev" title="Go to the previous page" />
  239. <span class="keytext">Page <?= $page ?> of <?= $total_pages ?></span>
  240. <input class="filter" type="submit" name="paging" value="next" title="Go to the next page" />
  241. <input class="filter" type="submit" name="paging" value="last" title="Go to the last page" />
  242. <span class="keytext">&nbsp;-&nbsp;
  243. Displaying <?= $start_item ?> - <?= $end_item ?> of <?= $total_items ?> items (<?= $items_displayed ?> shown)
  244. </span>&nbsp;&nbsp;
  245. <strong>Show </strong> <input class="filter" type="submit" name="num_limit" value="All" />
  246. <?php } ?>
  247. </td>
  248. <td nowrap="y" align="right" style="padding-top:8px;">
  249. <input class="filter" type="submit" name="clearall" value="Clear" title="Reset display to defaults" />
  250. <input class="filter" type="submit" name="export" value="Export" title="Export results based on current filters" />
  251. <input class="filter" type="text" name="searchtext" value="<?= $searchtext ?>"
  252. size="20" title="Enter search text here" />
  253. <script type="text/javascript">document.adminform.searchtext.focus();</script>
  254. <input class="filter" type="submit" name="search" value="Search" title="Search the requirements" />
  255. </td>
  256. </tr>
  257. </table>
  258. </div>
  259. <table border="0" cellspacing="0" width="100%">
  260. <tr class='tableheader'>
  261. <td>&nbsp;&nbsp;&nbsp;</td>
  262. <td><a href="javascript:orderBy('lastname');">Name</a></td>
  263. <td><a href="javascript:orderBy('email');">Email</a></td>
  264. <td><a href="javascript:orderBy('primaryRole');">Primary Role</a></td>
  265. <td><a href="javascript:orderBy('institution');">Institution</a></td>
  266. <td align="center"><a href="javascript:orderBy('date_created');">Date</a></td>
  267. <td align="center">#</td>
  268. </tr>
  269. <?php
  270. //TO DO calculations for members vs non members
  271. //TO DO report on the number of registrations each day (for Joseph's projections')
  272. $line = 0;
  273. $row_num=$total_items;
  274. while($row=mysql_fetch_assoc($result)) {
  275. $line++;
  276. //echo "<pre>",print_r($row),"</pre>";
  277. if (strlen($row["institution"]) > 33) {
  278. $row["institution"] = substr($row["institution"],0,35) . "...";
  279. }
  280. $rowstyle = "";
  281. if ($row["activated"] == 'N') {
  282. $rowstyle = " style = 'color:red;' ";
  283. } else if ($row["institution_pk"] == "1") {
  284. $rowstyle = " style = 'color:#990099;' ";
  285. }
  286. $linestyle = "oddrow";
  287. if ($line % 2 == 0) {
  288. $linestyle = "evenrow";
  289. } else {
  290. $linestyle = "oddrow";
  291. }
  292. ?>
  293. <tr class="<?= $linestyle ?>" <?= $rowstyle ?> >
  294. <td>
  295. <?php if ($row['activated'] == 'Y') { ?>
  296. <a title="Deactivate this user"
  297. onClick="return confirm('Are you sure you want to deactivate this user (<?= $row['username'] ?>)')"
  298. href="<?= $_SERVER['PHP_SELF'] ?>?deactivate=<?= $row['id'] ?>">x</a>
  299. <?php } else { ?>
  300. <a title="Activate this user"
  301. onClick="return confirm('Are you sure you want to activate this user (<?= $row['username'] ?>)')"
  302. href="<?= $_SERVER['PHP_SELF'] ?>?activate=<?= $row['id'] ?>">+</a>
  303. <?php } ?>
  304. </td>
  305. <td class="line"><?= $row["firstname"] ?> <?= $row["lastname"] ?></td>
  306. <td class="line"><?= $row["email"] ?></td>
  307. <td class="line"><?= $row['primaryRole'] ?> </td>
  308. <td class="line"><?= $row["institution"] ?></td>
  309. <td class="line" align="center" nowrap="y" ><?= date($DATE_FORMAT,strtotime($row["date_created"])) ?></td>
  310. <td class="line"><?= $row_num ?></td>
  311. </tr>
  312. <?php
  313. $row_num--;
  314. } ?>
  315. </table>
  316. </form>
  317. <div class="padding50"></div>
  318. <br/>
  319. <div class="definitions">
  320. <div class="defheader">How to use attendees page</div>
  321. <div style="padding:3px;">
  322. The attendees page is primarily for viewing a report of attendees.<br/>
  323. Use the export button to generate a spreadsheet of all attendees.<br/>
  324. <span style="color:red;">Non-member users</span> are color coded and indicate
  325. anyone is not part of a Sakai partner institution.<br/>
  326. <span style="color:#990099;">Inactive users</span> are color coded
  327. and represent anyone who has not paid the registration fee yet.<br/>
  328. To activate a user even if they have not paid, use the <strong>+</strong> link to the left of their name.<br/>
  329. To deactivate a user (basically disables their registration), use the <strong>x</strong> link to the left of their name.<br/>
  330. </div>
  331. </div>
  332. </div>
  333. <?php require $ACCOUNTS_PATH.'include/footer.php'; ?>