PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/web/skins/mobile/views/events.php

https://github.com/schumi-chu/zm_nvr
PHP | 158 lines | 127 code | 12 blank | 19 comment | 14 complexity | 89d9b66d86efb45be1ea0b923817f3b0 MD5 | raw file
  1. <?php
  2. //
  3. // ZoneMinder web events view file, $Date: 2008-07-25 10:48:16 +0100 (Fri, 25 Jul 2008) $, $Revision: 2612 $
  4. // Copyright (C) 2001-2008 Philip Coombes
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public License
  8. // as published by the Free Software Foundation; either version 2
  9. // of the License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. if ( !canView( 'Events' ) )
  21. {
  22. $view = "error";
  23. return;
  24. }
  25. $sql = "select * from Monitors";
  26. foreach ( dbFetchAll( $sql ) as $row )
  27. {
  28. $monitors[$row['Id']] = $row;
  29. }
  30. if ( isset($_REQUEST['filterName']) )
  31. {
  32. $dbFilter = dbFetchOne( "select * from Filters where Name = '".dbEscape($_REQUEST['filterName'])."'" );
  33. $_REQUEST['filter'] = unserialize( $dbFilter['Query'] );
  34. $_REQUEST['filter'] = unserialize( $dbFilter['Query'] );
  35. $_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:"DateTime";
  36. $_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:"1";
  37. $_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:"";
  38. unset( $_REQUEST['filter']['sort_field'] );
  39. unset( $_REQUEST['filter']['sort_asc'] );
  40. unset( $_REQUEST['filter']['limit'] );
  41. }
  42. if ( empty($_REQUEST['sort_field']) )
  43. $_REQUEST['sort_field'] = "DateTime";
  44. if ( empty($_REQUEST['sort_asc']) )
  45. $_REQUEST['sort_asc'] = "1";
  46. $countSql = "select count(E.Id) as EventCount from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where";
  47. $eventsSql = "select E.Id,E.MonitorId,M.Name As MonitorName,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where";
  48. if ( $user['MonitorIds'] )
  49. {
  50. $countSql .= " M.Id in (".join( ",", preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) ).")";
  51. $eventsSql .= " M.Id in (".join( ",", preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) ).")";
  52. }
  53. else
  54. {
  55. $countSql .= " 1";
  56. $eventsSql .= " 1";
  57. }
  58. parseSort( true, '&amp;' );
  59. parseFilter( $_REQUEST['filter'], true, '&amp;' );
  60. $filterQuery = $_REQUEST['filter']['query'];
  61. if ( $_REQUEST['filter']['sql'] )
  62. {
  63. $countSql .= $_REQUEST['filter']['sql'];
  64. $eventsSql .= $_REQUEST['filter']['sql'];
  65. }
  66. $eventsSql .= " order by $sortColumn $sortOrder";
  67. $deviceLines = (isset($device)&&!empty($device['lines']))?$device['lines']:DEVICE_LINES;
  68. // Allow for headers etc
  69. $deviceLines -= 2;
  70. if ( !empty($_REQUEST['page']) )
  71. {
  72. $limitStart = (($_REQUEST['page']-1)*$deviceLines);
  73. if ( empty($_REQUEST['limit']) )
  74. {
  75. $limitAmount = $deviceLines;
  76. }
  77. else
  78. {
  79. $limitLeft = $_REQUEST['limit'] - $limitStart;
  80. $limitAmount = ($limitLeft>$deviceLines)?$deviceLines:$limitLeft;
  81. }
  82. $eventsSql .= " limit $limitStart, $limitAmount";
  83. }
  84. elseif ( !empty( $_REQUEST['limit'] ) )
  85. {
  86. $eventsSql .= " limit 0, ".$_REQUEST['limit'];
  87. }
  88. $nEvents = dbFetchOne( $countSql, 'EventCount' );
  89. if ( !empty($limit) && $nEvents > $_REQUEST['limit'] )
  90. {
  91. $nEvents = $_REQUEST['limit'];
  92. }
  93. $pages = (int)ceil($nEvents/$deviceLines);
  94. $maxShortcuts = 3;
  95. $pagination = getPagination( $pages, $_REQUEST['page'], $maxShortcuts, $filterQuery.$sortQuery.'&amp;limit='.$_REQUEST['limit'], '&amp;' );
  96. xhtmlHeaders( __FILE__, $SLANG['Events'] );
  97. ?>
  98. <body>
  99. <div id="page">
  100. <div id="header">
  101. <div id="headerButtons"><?= makeLink( "?view=filter", empty($_REQUEST['filterName'])?$SLANG['ChooseFilter']:$_REQUEST['filterName'], canView( 'Events' ) ) ?></div>
  102. <h2><?= sprintf( $CLANG['EventCount'], $nEvents, zmVlang( $VLANG['Event'], $nEvents ) ) ?></h2>
  103. </div>
  104. <div id="content">
  105. <?php
  106. if ( $pagination )
  107. {
  108. ?>
  109. <h3 class="pagination"><?= $pagination ?></h3>
  110. <?php
  111. }
  112. ?>
  113. <table id="contentTable" class="major">
  114. <?php
  115. $count = 0;
  116. foreach ( dbFetchAll( $eventsSql ) as $event )
  117. {
  118. if ( ($count++%$deviceLines) == 0 )
  119. {
  120. ?>
  121. <tr>
  122. <th class="colId"><a href="<?= sortHeader( 'Id', '&amp;' ) ?>"><?= substr( $SLANG['Id'], 0, 3 ) ?><?= sortTag( 'Id' ) ?></a></th>
  123. <th class="colTime"><a href="<?= sortHeader( 'StartTime', '&amp;' ) ?>"><?= substr( $SLANG['Time'], 0, 3 ) ?><?= sortTag( 'StartTime' ) ?></a></th>
  124. <th class="colDuration"><a href="<?= sortHeader( 'Length', '&amp;' ) ?>"><?= substr( $SLANG['Duration'], 0, 3 ) ?><?= sortTag( 'Length' ) ?></a></th>
  125. <th class="colFrames"><a href="<?= sortHeader( 'Frames', '&amp;' ) ?>"><?= substr( $SLANG['Frames'], 0, 3 ) ?><?= sortTag( 'Frames' ) ?></a></th>
  126. <th class="colScore"><a href="<?= sortHeader( 'TotScore', '&amp;' ) ?>"><?= substr( $SLANG['Score'], 0, 3 ) ?><?= sortTag( 'TotScore' ) ?></a></th>
  127. </tr>
  128. <?php
  129. }
  130. ?>
  131. <tr>
  132. <td class="colId"><a href="?view=eventdetails&amp;eid=<?= $event['Id'] ?>&amp;page=1"><?= $event['Id'] ?><?php if ( $event['Archived'] ) echo "*" ?></a></td>
  133. <td class="colTime"><?= strftime( "%d/%H:%M", strtotime($event['StartTime']) ) ?></td>
  134. <td class="colDuration"><?= sprintf( "%d", $event['Length'] ) ?></td>
  135. <td class="colFrames"><a href="?view=event&amp;eid=<?= $event['Id'] ?>&amp;page=1"><?= $event['AlarmFrames'] ?></a></td>
  136. <td class="colScore"><a href="?view=frame&amp;eid=<?= $event['Id'] ?>&amp;fid=0"><?= $event['MaxScore'] ?></a></td>
  137. </tr>
  138. <?php
  139. }
  140. ?>
  141. </table>
  142. <p><a href="?view=console"><?= $SLANG['Console'] ?></a></p>
  143. </div>
  144. </div>
  145. </body>
  146. </html>