PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/viewlogs.php

https://github.com/adamfranco/segue-1.x
PHP | 412 lines | 336 code | 63 blank | 13 comment | 68 complexity | dddf42fefc397711a7df51aa9d22fed0 MD5 | raw file
  1. <? /* $Id$ */
  2. require("objects/objects.inc.php");
  3. $content = '';
  4. ob_start();
  5. session_start();
  6. // include all necessary files
  7. include("includes.inc.php");
  8. //if ($_SESSION['ltype'] != 'admin') exit;
  9. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  10. // Clean the old entries from the logs if we have not done so yet
  11. if ($cfg[logexpiration] && !$_SESSION['__logs_cleaned']) {
  12. $removalTStamp = strtotime($cfg[logexpiration].' days ago');
  13. $date = date('Ymd000000', $removalTStamp);
  14. if ($removalTStamp && $date) {
  15. // print "Removing logs with timestamp less than $date";
  16. $query =
  17. "DELETE FROM
  18. log
  19. WHERE
  20. log_tstamp < '".addslashes($date)."'
  21. ";
  22. db_query($query);
  23. $_SESSION['__logs_cleaned'] = TRUE;
  24. }
  25. }
  26. //if ($_REQUEST[order]) $order = $_REQUEST[order];
  27. $order = $_REQUEST[order];
  28. $enddate = $_REQUEST[enddate];
  29. $startdate = $_REQUEST[startdate];
  30. $type = $_REQUEST[type];
  31. $site = $_REQUEST[site];
  32. $user = $_REQUEST[user];
  33. $_auser = $_REQUEST[_auser];
  34. $_luser = $_REQUEST[_luser];
  35. if ($_REQUEST[clear]) {
  36. $type = "";
  37. $user = "";
  38. $site = "";
  39. $_auser = "";
  40. $_luser = "";
  41. $enddate = "";
  42. $startdate = "";
  43. $order = "";
  44. }
  45. $w = array();
  46. if ($_REQUEST[type]) $w[]="log_type='".addslashes($type)."'";
  47. if ($_REQUEST[user]) $w[]="log_desc like '%".addslashes($user)."%'";
  48. if ($_REQUEST[_luser]) $w[]="FK_luser='".addslashes($_luser)."'";
  49. if ($_REQUEST[_auser]) $w[]="FK_auser='".addslashes($_auser)."'";
  50. if ($_SESSION[ltype] != 'admin') {
  51. $w[]="slot_name LIKE '%".addslashes($site)."%'";
  52. } else {
  53. if ($_REQUEST[site] != "") $w[]="slot_name LIKE '%$site%'";
  54. if ($startdate) {
  55. $w[]="log_tstamp > $startdate";
  56. $order = "log_tstamp ASC";
  57. }
  58. if ($enddate) {
  59. $w[]="log_tstamp < $enddate";
  60. if (!$_REQUEST[startdate]) $order = "log_tstamp DESC";
  61. }
  62. }
  63. //if (!$order) $order = "log_tstamp DESC";
  64. if (!isset($order)
  65. || !preg_match('/^[a-z0-9_.]+( (ASC|DESC))?$/i', $order))
  66. $order = "log_tstamp DESC";
  67. $orderby = " ORDER BY $order";
  68. if ($_REQUEST[hideadmin]) $w[]="log_type NOT LIKE 'change_auser'";
  69. if (count($w)) $where = " WHERE ".implode(" AND ",$w);
  70. $query = "
  71. SELECT
  72. COUNT(*) AS log_count
  73. FROM
  74. log
  75. LEFT JOIN
  76. slot
  77. ON
  78. log.FK_slot = slot.slot_id
  79. LEFT JOIN
  80. user AS user1
  81. ON
  82. log.FK_luser = user1.user_id
  83. LEFT JOIN
  84. user AS user2
  85. ON
  86. log.FK_auser = user2.user_id
  87. $where";
  88. // print "<pre>".print_r($query)."</pre>";
  89. $r=db_query($query);
  90. $a = db_fetch_assoc($r);
  91. $numlogs = $a[log_count];
  92. if (isset($_REQUEST['lowerlimit']))
  93. $lowerlimit = intval($_REQUEST['lowerlimit']);
  94. else
  95. $lowerlimit = 0;
  96. if ($lowerlimit < 0)
  97. $lowerlimit = 0;
  98. $limit = " LIMIT $lowerlimit,30";
  99. $query = "
  100. SELECT
  101. log_type,
  102. log_tstamp,
  103. log_desc,
  104. FK_siteunit AS siteunit,
  105. log_siteunit_type AS siteunit_type,
  106. user1.user_uname AS luser,
  107. log.FK_luser AS luser_id,
  108. user2.user_uname AS auser,
  109. log.FK_auser AS auser_id,
  110. slot_name,
  111. FK_site AS site_id
  112. FROM
  113. log
  114. LEFT JOIN
  115. slot
  116. ON
  117. log.FK_slot = slot.slot_id
  118. LEFT JOIN
  119. user AS user1
  120. ON
  121. log.FK_luser = user1.user_id
  122. LEFT JOIN
  123. user AS user2
  124. ON
  125. log.FK_auser = user2.user_id
  126. $where
  127. $orderby
  128. $limit";
  129. //printpre($query);
  130. $r = db_query($query);
  131. ?>
  132. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  133. <html>
  134. <head>
  135. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  136. <title>View Logs</title>
  137. <? include("themes/common/logs_css.inc.php"); ?>
  138. <script type="text/JavaScript">
  139. // <![CDATA[
  140. function selectAUser(user) {
  141. f = document.searchform;
  142. f._auser.value=user;
  143. f._luser.value="";
  144. f.submit();
  145. }
  146. function selectLUser(user) {
  147. f = document.searchform;
  148. f._luser.value=user;
  149. f._auser.value="";
  150. f.submit();
  151. }
  152. function changeOrder(order) {
  153. f = document.searchform;
  154. f.order.value=order;
  155. f.submit();
  156. }
  157. // ]]>
  158. </script>
  159. </head>
  160. <body>
  161. <div align='right' class='bg'>
  162. <?
  163. /******************************************************************************
  164. * Get site id for links to participation section
  165. ******************************************************************************/
  166. $siteObj =&new site($site);
  167. $siteid = $siteObj->id;
  168. if ($_SESSION['ltype']=='admin') {
  169. print "<table width='100%' class='bg'><tr><td class='bg'>
  170. Logs: <a href='viewsites.php?$sid&amp;site=$site'>sites</a>
  171. | users
  172. </td><td align='right' class='bg'>
  173. <a href='users.php?$sid&amp;site=$site'>add/edit users</a> |
  174. <a href='classes.php?$sid&amp;site=$site'>add/edit classes</a> |
  175. <a href='add_slot.php?$sid&amp;site=$site'>add/edit slots</a> |
  176. <a href='update.php?$sid&amp;site=$site'>segue updates</a>
  177. </td></tr></table>";
  178. }
  179. if ($site) {
  180. if (isclass($site)) print "<a href='add_students.php?$sid&amp;name=$site&amp;scope=".$_REQUEST['scope']."&amp;storyid=".$_REQUEST['storyid']."'>Roster</a> |";
  181. print " <a href='email.php?$sid&amp;siteid=$siteid&amp;site=$site&amp;action=list&amp;order=user_fname&amp;scope=".$_REQUEST['scope']."&amp;storyid=".$_REQUEST['storyid']."'>Participation</a>";
  182. print " | Logs";
  183. }
  184. ?>
  185. </div>
  186. <div class='bg'>
  187. <? print $content; ?>
  188. </div>
  189. <table cellspacing='1' width='100%' id='maintable' style='margin-top: 5px;'>
  190. <tr>
  191. <td colspan='6'>
  192. <table width='100%'>
  193. <tr>
  194. <td>
  195. <form action='<?echo "$PHP_SELF?$sid"?>/' method='post' name='searchform'>
  196. <?
  197. if ($_SESSION['ltype'] != 'admin') {
  198. print "\n\t\t\t\t\t\t\t\t<input type='hidden' name='site' value='$site' />";
  199. print "\n\t\t\t\t\t\t\t\tLogs of $site <br />";
  200. }
  201. print "\n\t\t\t\t\t\t\t\t<input type='hidden' name='scope' value='".$_REQUEST['scope']."' />";
  202. print "\n\t\t\t\t\t\t\t\t<input type='hidden' name='storyid' value='".$_REQUEST['storyid']."' />";
  203. $r1 = db_query("SELECT DISTINCT log_type FROM log ORDER BY log_type asc");
  204. ?>
  205. type:
  206. <select name='type'>
  207. <option value=''>all</option>
  208. <?
  209. while ($a=db_fetch_assoc($r1))
  210. print "\n\t\t\t\t\t\t\t\t\t<option".(($type==$a[log_type])?" selected":"").">$a[log_type]</option>";
  211. ?>
  212. </select>
  213. <?
  214. if ($_SESSION['ltype'] == 'admin') {
  215. ?>
  216. user: <input type='text' name='user' size='15' value='<?echo $user?>' />
  217. site: <input type='text' name='site' size='15' value='<?echo $site?>' />
  218. <? print "\n\t\t\t\t\t\t\t\thide admin: <input type='checkbox' name='hideadmin' value='1'".(($hideadmin)?" checked='checked'":"")." />"; ?>
  219. <br />
  220. start date (yyyymmdd): <input type='text' name='startdate' size='10' value='<?echo $startdate?>' />
  221. end date (yyyymmdd): <input type='text' name='enddate' size='10' value='<?echo $enddate?>' />
  222. <? } ?>
  223. <input type='submit' value='go' />
  224. <input type='submit' name='clear' value='clear' />
  225. <input type='hidden' name='order' value='<? echo $order ?>' />
  226. <input type='hidden' name='_auser' value='<? echo $_auser ?>' />
  227. <input type='hidden' name='_luser' value='<? echo $_luser ?>' />
  228. <? print "\n\t\t\t\t\t\t\t\t<br />Total log entries:".$numlogs; ?>
  229. </form>
  230. </td>
  231. <td align='right'>
  232. <?
  233. $tpages = ceil($numlogs/30);
  234. $curr = ceil(($lowerlimit+30)/30);
  235. $prev = $lowerlimit-30;
  236. if ($prev < 0) $prev = 0;
  237. $next = $lowerlimit+30;
  238. if ($next >= $numlogs) $next = $numlogs-30;
  239. if ($next < 0) $next = 0;
  240. print "\n\t\t\t\t\t\t\t\t$curr of $tpages ";
  241. if ($prev != $lowerlimit)
  242. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&lt;&lt;' onclick='window.location=\"$PHP_SELF?$sid&amp;enddate=$enddate&amp;startdate=$startdate&amp;lowerlimit=$prev&amp;type=$type&amp;user=$user&amp;hideadmin=$hideadmin&amp;site=$site&amp;order=$order&amp;_auser=$_auser&amp;_luser=$_luser\"' />";
  243. if ($next != $lowerlimit && $next > $lowerlimit)
  244. print "\n\t\t\t\t\t\t\t\t<input type='button' value='&gt;&gt;' onclick='window.location=\"$PHP_SELF?$sid&amp;enddate=$enddate&amp;startdate=$startdate&amp;lowerlimit=$next&amp;type=$type&amp;user=$user&amp;hideadmin=$hideadmin&amp;site=$site&amp;order=$order&amp;_auser=$_auser&amp;_luser=$_luser\"' />";
  245. ?>
  246. </td>
  247. </tr>
  248. </table>
  249. </td>
  250. </tr>
  251. <tr>
  252. <?
  253. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  254. if ($order =='log_tstamp asc') print "log_tstamp desc";
  255. else print "log_tstamp asc";
  256. print "')\" style='color: #000'>Time";
  257. if ($order =='log_tstamp asc') print " &or;";
  258. if ($order =='log_tstamp desc') print " &and;";
  259. print "</a></th>";
  260. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  261. if ($order =='log_type asc') print "log_type desc";
  262. else print "log_type asc";
  263. print "')\" style='color: #000'>Type";
  264. if ($order =='log_type asc') print " &or;";
  265. if ($order =='log_type desc') print " &and;";
  266. print "</a></th>";
  267. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  268. if ($order =='luser asc') print "luser desc";
  269. else print "luser asc";
  270. print "')\" style='color: #000'>luser";
  271. if ($order =='luser asc') print " &or;";
  272. if ($order =='luser desc') print " &and;";
  273. print "</a></th>";
  274. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  275. if ($order =='auser asc') print "auser desc";
  276. else print "auser asc";
  277. print "')\" style='color: #000'>auser";
  278. if ($order =='auser asc') print " &or;";
  279. if ($order =='auser desc') print " &and;";
  280. print "</a></th>";
  281. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  282. if ($order =='slot_name asc') print "slot_name desc";
  283. else print "slot_name asc";
  284. print "')\" style='color: #000'>Site";
  285. if ($order =='slot_name asc') print " &or;";
  286. if ($order =='slot_name desc') print " &and;";
  287. print "</a></th>";
  288. print "\n\t\t\t<th><a href='#' onclick=\"changeOrder('";
  289. if ($order =='log_desc asc') print "log_desc desc";
  290. else print "log_desc asc";
  291. print "')\" style='color: #000'>Text";
  292. if ($order =='log_desc asc') print " &or;";
  293. if ($order =='log_desc desc') print " &and;";
  294. print "</a></th>";
  295. ?>
  296. </tr>
  297. <?
  298. $color = 0;
  299. $today = date(Ymd);
  300. $yesterday = date(Ymd)-1;
  301. if (db_num_rows($r)) {
  302. while ($a=db_fetch_assoc($r)) {
  303. print "\n\t\t<tr>";
  304. print "\n\t\t\t<td class='td$color' style='white-space: nowrap; color: #";
  305. if (strstr("add_site, delete_site, classgroups",$a[log_type]))
  306. print "F90";
  307. else if (strstr("login, change_auser",$a[log_type]))
  308. print "000";
  309. else
  310. print "00C";
  311. print "'>";
  312. if (strncmp($today, $a[log_tstamp], 8) == 0 || strncmp($yesterday, $a[log_tstamp], 8) == 0) print "<b>";
  313. print timestamp2usdate($a[log_tstamp],1);
  314. if (strncmp($today, $a[log_tstamp], 8) == 0 || strncmp($yesterday, $a[log_tstamp], 8) == 0) print "</b>";
  315. print "</td>";
  316. print "\n\t\t\t<td class='td$color' style='color: #";
  317. if (strstr("add_site, delete_site, classgroups",$a[log_type]))
  318. print "F90";
  319. else if (strstr("login, change_auser",$a[log_type]))
  320. print "000";
  321. else
  322. print "00C";
  323. print "'>$a[log_type]</td>";
  324. print "\n\t\t\t<td class='td$color'><a href='#' onclick=\"selectLUser('".$a[luser]."')\" style='color: #000;'>".(($a[luser])?$a[luser]:$a[luser_id])."</a></td>";
  325. print "\n\t\t\t<td class='td$color'><a href='#' onclick=\"selectAUser('".$a[auser]."')\" style='color: #000;'>".(($a[auser])?$a[auser]:$a[auser_id])."</a></td>";
  326. print "\n\t\t\t<td class='td$color'>";
  327. if ($a[site_id]) print "<a href='#' onclick='opener.window.location=\"index.php?$sid&amp;action=site&amp;site=$a[slot_name]\"'>";
  328. print stripslashes($a[slot_name]);
  329. if ($a[site_id]) print "</a>";
  330. print "</td>";
  331. print "\n\t\t\t<td class='td$color'>";
  332. if ($a[siteunit_type] == "section") print "<a href='#' onclick='opener.window.location=\"index.php?$sid&amp;action=site&amp;site=$a[slot_name]&amp;section=$a[siteunit]\"'>";
  333. print "$a[log_desc]";
  334. if ($a[siteunit_type] == "section") print "</a>";
  335. print "</td>";
  336. print "\n\t\t</tr>";
  337. $color = 1-$color;
  338. }
  339. } else {
  340. print "\n\t\t<tr>\n\t\t\t<td colspan='6'>No log entries.</td>\n\t\t</tr>";
  341. }
  342. ?>
  343. </table>
  344. <br />
  345. <div align='right'>
  346. <input type='button' value='Close Window' onclick='window.close()' />
  347. </div>
  348. </body>
  349. </html>