PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/ZoneMinder-1.25.0/web/skins/classic/views/console.php

#
PHP | 342 lines | 313 code | 11 blank | 18 comment | 50 complexity | 52567dd4fe650db8fad1832752df2f99 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // ZoneMinder web console file, $Date: 2011-06-21 10:19:10 +0100 (Tue, 21 Jun 2011) $, $Revision: 3459 $
  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. $eventCounts = array(
  21. array(
  22. "title" => $SLANG['Events'],
  23. "filter" => array(
  24. "terms" => array(
  25. )
  26. ),
  27. ),
  28. array(
  29. "title" => $SLANG['Hour'],
  30. "filter" => array(
  31. "terms" => array(
  32. array( "attr" => "DateTime", "op" => ">=", "val" => "-1 hour" ),
  33. )
  34. ),
  35. ),
  36. array(
  37. "title" => $SLANG['Day'],
  38. "filter" => array(
  39. "terms" => array(
  40. array( "attr" => "DateTime", "op" => ">=", "val" => "-1 day" ),
  41. )
  42. ),
  43. ),
  44. array(
  45. "title" => $SLANG['Week'],
  46. "filter" => array(
  47. "terms" => array(
  48. array( "attr" => "DateTime", "op" => ">=", "val" => "-7 day" ),
  49. )
  50. ),
  51. ),
  52. array(
  53. "title" => $SLANG['Month'],
  54. "filter" => array(
  55. "terms" => array(
  56. array( "attr" => "DateTime", "op" => ">=", "val" => "-1 month" ),
  57. )
  58. ),
  59. ),
  60. array(
  61. "title" => $SLANG['Archived'],
  62. "filter" => array(
  63. "terms" => array(
  64. array( "attr" => "Archived", "op" => "=", "val" => "1" ),
  65. )
  66. ),
  67. ),
  68. );
  69. $running = daemonCheck();
  70. $status = $running?$SLANG['Running']:$SLANG['Stopped'];
  71. if ( $group = dbFetchOne( "select * from Groups where Id = '".(empty($_COOKIE['zmGroup'])?0:dbEscape($_COOKIE['zmGroup']))."'" ) )
  72. $groupIds = array_flip(explode( ',', $group['MonitorIds'] ));
  73. noCacheHeaders();
  74. $maxWidth = 0;
  75. $maxHeight = 0;
  76. $cycleCount = 0;
  77. $minSequence = 0;
  78. $maxSequence = 1;
  79. $seqIdList = array();
  80. $monitors = dbFetchAll( "select * from Monitors order by Sequence asc" );
  81. $displayMonitors = array();
  82. for ( $i = 0; $i < count($monitors); $i++ )
  83. {
  84. if ( !visibleMonitor( $monitors[$i]['Id'] ) )
  85. {
  86. continue;
  87. }
  88. if ( $group && !empty($groupIds) && !array_key_exists( $monitors[$i]['Id'], $groupIds ) )
  89. {
  90. continue;
  91. }
  92. $monitors[$i]['Show'] = true;
  93. if ( empty($minSequence) || ($monitors[$i]['Sequence'] < $minSequence) )
  94. {
  95. $minSequence = $monitors[$i]['Sequence'];
  96. }
  97. if ( $monitors[$i]['Sequence'] > $maxSequence )
  98. {
  99. $maxSequence = $monitors[$i]['Sequence'];
  100. }
  101. $monitors[$i]['zmc'] = zmcStatus( $monitors[$i] );
  102. $monitors[$i]['zma'] = zmaStatus( $monitors[$i] );
  103. $monitors[$i]['ZoneCount'] = dbFetchOne( "select count(Id) as ZoneCount from Zones where MonitorId = '".$monitors[$i]['Id']."'", "ZoneCount" );
  104. $counts = array();
  105. for ( $j = 0; $j < count($eventCounts); $j++ )
  106. {
  107. $filter = addFilterTerm( $eventCounts[$j]['filter'], count($eventCounts[$j]['filter']['terms']), array( "cnj" => "and", "attr" => "MonitorId", "op" => "=", "val" => $monitors[$i]['Id'] ) );
  108. parseFilter( $filter );
  109. $counts[] = "count(if(1".$filter['sql'].",1,NULL)) as EventCount$j";
  110. $monitors[$i]['eventCounts'][$j]['filter'] = $filter;
  111. }
  112. $sql = "select ".join($counts,", ")." from Events as E where MonitorId = '".$monitors[$i]['Id']."'";
  113. $counts = dbFetchOne( $sql );
  114. if ( $monitors[$i]['Function'] != 'None' )
  115. {
  116. $cycleCount++;
  117. $scaleWidth = reScale( $monitors[$i]['Width'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
  118. $scaleHeight = reScale( $monitors[$i]['Height'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
  119. if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth;
  120. if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight;
  121. }
  122. $monitors[$i] = array_merge( $monitors[$i], $counts );
  123. $seqIdList[] = $monitors[$i]['Id'];
  124. $displayMonitors[] = $monitors[$i];
  125. }
  126. $lastId = 0;
  127. $seqIdUpList = array();
  128. foreach ( $seqIdList as $seqId )
  129. {
  130. if ( !empty($lastId) )
  131. $seqIdUpList[$seqId] = $lastId;
  132. else
  133. $seqIdUpList[$seqId] = $seqId;
  134. $lastId = $seqId;
  135. }
  136. $lastId = 0;
  137. $seqIdDownList = array();
  138. foreach ( array_reverse($seqIdList) as $seqId )
  139. {
  140. if ( !empty($lastId) )
  141. $seqIdDownList[$seqId] = $lastId;
  142. else
  143. $seqIdDownList[$seqId] = $seqId;
  144. $lastId = $seqId;
  145. }
  146. $cycleWidth = $maxWidth;
  147. $cycleHeight = $maxHeight;
  148. $eventsView = ZM_WEB_EVENTS_VIEW;
  149. $eventsWindow = 'zm'.ucfirst(ZM_WEB_EVENTS_VIEW);
  150. $eventCount = 0;
  151. for ( $i = 0; $i < count($eventCounts); $i++ )
  152. {
  153. $eventCounts[$i]['total'] = 0;
  154. }
  155. $zoneCount = 0;
  156. foreach( $displayMonitors as $monitor )
  157. {
  158. for ( $i = 0; $i < count($eventCounts); $i++ )
  159. {
  160. $eventCounts[$i]['total'] += $monitor['EventCount'.$i];
  161. }
  162. $zoneCount += $monitor['ZoneCount'];
  163. }
  164. $seqUpFile = getSkinFile( 'graphics/seq-u.gif' );
  165. $seqDownFile = getSkinFile( 'graphics/seq-d.gif' );
  166. $versionClass = (ZM_DYN_DB_VERSION&&(ZM_DYN_DB_VERSION!=ZM_VERSION))?'errorText':'';
  167. xhtmlHeaders( __FILE__, $SLANG['Console'] );
  168. ?>
  169. <body>
  170. <div id="page">
  171. <form name="monitorForm" method="get" action="<?= $_SERVER['PHP_SELF'] ?>">
  172. <input type="hidden" name="view" value="<?= $view ?>"/>
  173. <input type="hidden" name="action" value=""/>
  174. <div id="header">
  175. <h3 id="systemTime"><?= preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG ) ?></h3>
  176. <h3 id="systemStats"><?= $SLANG['Load'] ?>: <?= getLoad() ?> / <?= $SLANG['Disk'] ?>: <?= getDiskPercent() ?>%</h3>
  177. <h2 id="title"><a href="http://www.zoneminder.com" target="ZoneMinder">ZoneMinder</a> <?= $SLANG['Console'] ?> - <?= makePopupLink( '?view=state', 'zmState', 'state', $status, canEdit( 'System' ) ) ?> - <?= makePopupLink( '?view=version', 'zmVersion', 'version', '<span class="'.$versionClass.'">v'.ZM_VERSION.'</span>', canEdit( 'System' ) ) ?></h2>
  178. <div class="clear"></div>
  179. <div id="monitorSummary"><?= makePopupLink( '?view=groups', 'zmGroups', 'groups', sprintf( $CLANG['MonitorCount'], count($displayMonitors), zmVlang( $VLANG['Monitor'], count($displayMonitors) ) ).($group?' ('.$group['Name'].')':''), canView( 'System' ) ); ?></div>
  180. <?php
  181. if ( ZM_OPT_X10 && canView( 'Devices' ) )
  182. {
  183. ?>
  184. <div id="devices"><?= makePopupLink( '?view=devices', 'zmDevices', 'devices', $SLANG['Devices'] ) ?></div>
  185. <?php
  186. }
  187. if ( canView( 'System' ) )
  188. {
  189. ?>
  190. <div id="options"><?= makePopupLink( '?view=options', 'zmOptions', 'options', $SLANG['Options'] ) ?><?php if ( logToDatabase() > Logger::NOLOG ) { ?> / <?= makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.$SLANG['Log'].'</span>' ) ?><?php } ?></div>
  191. <?php
  192. }
  193. if ( canView( 'Stream' ) && $cycleCount > 1 )
  194. {
  195. $cycleGroup = isset($_COOKIE['zmGroup'])?$_COOKIE['zmGroup']:0;
  196. ?>
  197. <div id="cycleMontage"><?= makePopupLink( '?view=cycle&amp;group='.$cycleGroup, 'zmCycle'.$cycleGroup, array( 'cycle', $cycleWidth, $cycleHeight ), $SLANG['Cycle'], $running ) ?>&nbsp;/&nbsp;<?= makePopupLink( '?view=montage&amp;group='.$cycleGroup, 'zmMontage'.$cycleGroup, 'montage', $SLANG['Montage'], $running ) ?></div>
  198. <?php
  199. }
  200. else
  201. {
  202. ?>
  203. <?php
  204. }
  205. ?>
  206. <h3 id="loginBandwidth"><?php
  207. if ( ZM_OPT_USE_AUTH )
  208. {
  209. ?><?= $SLANG['LoggedInAs'] ?> <?= makePopupLink( '?view=logout', 'zmLogout', 'logout', $user['Username'], (ZM_AUTH_TYPE == "builtin") ) ?>, <?= strtolower( $SLANG['ConfiguredFor'] ) ?><?php
  210. }
  211. else
  212. {
  213. ?><?= $SLANG['ConfiguredFor'] ?><?php
  214. }
  215. ?>&nbsp;<?= makePopupLink( '?view=bandwidth', 'zmBandwidth', 'bandwidth', $bwArray[$_COOKIE['zmBandwidth']], ($user && $user['MaxBandwidth'] != 'low' ) ) ?> <?= $SLANG['Bandwidth'] ?></h3>
  216. </div>
  217. <div id="content">
  218. <table id="consoleTable" cellspacing="0">
  219. <thead>
  220. <tr>
  221. <th class="colName"><?= $SLANG['Name'] ?></th>
  222. <th class="colFunction"><?= $SLANG['Function'] ?></th>
  223. <th class="colSource"><?= $SLANG['Source'] ?></th>
  224. <?php
  225. for ( $i = 0; $i < count($eventCounts); $i++ )
  226. {
  227. ?>
  228. <th class="colEvents"><?= $eventCounts[$i]['title'] ?></th>
  229. <?php
  230. }
  231. ?>
  232. <th class="colZones"><?= $SLANG['Zones'] ?></th>
  233. <?php
  234. if ( canEdit('Monitors') )
  235. {
  236. ?>
  237. <th class="colOrder"><?= $SLANG['Order'] ?></th>
  238. <?php
  239. }
  240. ?>
  241. <th class="colMark"><?= $SLANG['Mark'] ?></th>
  242. </tr>
  243. </thead>
  244. <tfoot>
  245. <tr>
  246. <td class="colLeftButtons" colspan="3">
  247. <input type="button" value="<?= $SLANG['Refresh'] ?>" onclick="location.reload(true);"/>
  248. <?= makePopupButton( '?view=monitor', 'zmMonitor0', 'monitor', $SLANG['AddNewMonitor'], (canEdit( 'Monitors' ) && !$user['MonitorIds']) ) ?>
  249. <?= makePopupButton( '?view=filter&amp;filter[terms][0][attr]=DateTime&amp;filter[terms][0][op]=%3c&amp;filter[terms][0][val]=now', 'zmFilter', 'filter', $SLANG['Filters'], canView( 'Events' ) ) ?>
  250. </td>
  251. <?php
  252. for ( $i = 0; $i < count($eventCounts); $i++ )
  253. {
  254. parseFilter( $eventCounts[$i]['filter'] );
  255. ?>
  256. <td class="colEvents"><?= makePopupLink( '?view='.$eventsView.'&amp;page=1'.$eventCounts[$i]['filter']['query'], $eventsWindow, $eventsView, $eventCounts[$i]['total'], canView( 'Events' ) ) ?></td>
  257. <?php
  258. }
  259. ?>
  260. <td class="colZones"><?= $zoneCount ?></td>
  261. <td class="colRightButtons" colspan="<?= canEdit('Monitors')?2:1 ?>"><input type="button" name="editBtn" value="<?= $SLANG['Edit'] ?>" onclick="editMonitor( this )" disabled="disabled"/><input type="button" name="deleteBtn" value="<?= $SLANG['Delete'] ?>" onclick="deleteMonitor( this )" disabled="disabled"/></td>
  262. </tr>
  263. </tfoot>
  264. <tbody>
  265. <?php
  266. foreach( $displayMonitors as $monitor )
  267. {
  268. ?>
  269. <tr>
  270. <?php
  271. if ( !$monitor['zmc'] )
  272. $dclass = "errorText";
  273. else
  274. {
  275. if ( !$monitor['zma'] )
  276. $dclass = "warnText";
  277. else
  278. $dclass = "infoText";
  279. }
  280. if ( $monitor['Function'] == 'None' )
  281. $fclass = "errorText";
  282. elseif ( $monitor['Function'] == 'Monitor' )
  283. $fclass = "warnText";
  284. else
  285. $fclass = "infoText";
  286. if ( !$monitor['Enabled'] )
  287. $fclass .= " disabledText";
  288. $scale = max( reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE );
  289. ?>
  290. <td class="colName"><?= makePopupLink( '?view=watch&amp;mid='.$monitor['Id'], 'zmWatch'.$monitor['Id'], array( 'watch', reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ) ), $monitor['Name'], $running && ($monitor['Function'] != 'None') && canView( 'Stream' ) ) ?></td>
  291. <td class="colFunction"><?= makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.$monitor['Function'].'</span>', canEdit( 'Monitors' ) ) ?></td>
  292. <?php if ( $monitor['Type'] == "Local" ) { ?>
  293. <td class="colSource"><?= makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.$monitor['Device'].' ('.$monitor['Channel'].')</span>', canEdit( 'Monitors' ) ) ?></td>
  294. <?php } elseif ( $monitor['Type'] == "Remote" ) { ?>
  295. <td class="colSource"><?= makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.preg_replace( '/^.*@/', '', $monitor['Host'] ).'</span>', canEdit( 'Monitors' ) ) ?></td>
  296. <?php } elseif ( $monitor['Type'] == "File" ) { ?>
  297. <td class="colSource"><?= makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.preg_replace( '/^.*\//', '', $monitor['Path'] ).'</span>', canEdit( 'Monitors' ) ) ?></td>
  298. <?php } elseif ( $monitor['Type'] == "Ffmpeg" ) { ?>
  299. <td class="colSource"><?= makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.preg_replace( '/^.*\//', '', $monitor['Path'] ).'</span>', canEdit( 'Monitors' ) ) ?></td>
  300. <?php } else { ?>
  301. <td class="colSource">&nbsp;</td>
  302. <?php } ?>
  303. <?php
  304. for ( $i = 0; $i < count($eventCounts); $i++ )
  305. {
  306. ?>
  307. <td class="colEvents"><?= makePopupLink( '?view='.$eventsView.'&amp;page=1'.$monitor['eventCounts'][$i]['filter']['query'], $eventsWindow, $eventsView, $monitor['EventCount'.$i], canView( 'Events' ) ) ?></td>
  308. <?php
  309. }
  310. ?>
  311. <td class="colZones"><?= makePopupLink( '?view=zones&amp;mid='.$monitor['Id'], 'zmZones', array( 'zones', $monitor['Width'], $monitor['Height'] ), $monitor['ZoneCount'], canView( 'Monitors' ) ) ?></td>
  312. <?php
  313. if ( canEdit('Monitors') )
  314. {
  315. ?>
  316. <td class="colOrder"><?= makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdUpList[$monitor['Id']], '<img src="'.$seqUpFile.'" alt="Up"/>', $monitor['Sequence']>$minSequence ) ?><?= makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdDownList[$monitor['Id']], '<img src="'.$seqDownFile.'" alt="Down"/>', $monitor['Sequence']<$maxSequence ) ?></td>
  317. <?php
  318. }
  319. ?>
  320. <td class="colMark"><input type="checkbox" name="markMids[]" value="<?= $monitor['Id'] ?>" onclick="setButtonStates( this )"<?php if ( !canEdit( 'Monitors' ) ) { ?> disabled="disabled"<?php } ?>/></td>
  321. </tr>
  322. <?php
  323. }
  324. ?>
  325. </tbody>
  326. </table>
  327. </div>
  328. </form>
  329. </div>
  330. </body>
  331. </html>