PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/web/skins/classic/includes/export_functions.php

https://github.com/ZoneMinder/branch
PHP | 985 lines | 767 code | 134 blank | 84 comment | 123 complexity | cc3eb88b165acdb7e8b9bd996a665bef MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // ZoneMinder web export function library, $Date$, $Revision$
  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. function exportHeader( $title )
  21. {
  22. ?>
  23. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <title><?= $title ?></title>
  27. <style type="text/css">
  28. <!--
  29. <?php include( ZM_SKIN_PATH.'/css/export.css' ); ?>
  30. ul.tabs {
  31. margin: 0;
  32. margin-bottom: -1px;
  33. padding: 0;
  34. float: left;
  35. list-style: none;
  36. height: 32px;
  37. border-bottom: 1px solid #7f7fb2;
  38. border-left: 1px solid #7f7fb2;
  39. width: 100%;
  40. }
  41. ul.tabs li {
  42. float: left;
  43. margin: 0;
  44. padding: 0;
  45. height: 31px;
  46. line-height: 31px;
  47. border: 1px solid #7f7fb2;
  48. border-left: none;
  49. margin-bottom: -1px;
  50. background: #fff;
  51. overflow: hidden;
  52. position: relative;
  53. }
  54. ul.tabs li a {
  55. text-decoration: none;
  56. color: #000;
  57. display: block;
  58. font-size: 1.2em;
  59. padding: 0 20px;
  60. outline: none;
  61. }
  62. ul.tabs li a:hover {
  63. background: #ccc;
  64. }
  65. html ul.tabs li.active, html ul.tabs li.active a:hover {
  66. background: #dddddd;
  67. border-bottom: 1px solid #e0e0e0;
  68. }
  69. -->
  70. </style>
  71. <script type="text/javascript" src="<?php echo ZM_SKIN_PATH; ?>/js/jquery-1.4.2.min.js"></script>
  72. <script type="text/javascript" language="javascript" charset="utf-8">
  73. /*==========[tab code]==========*/
  74. $(document).ready(function() {
  75. //When page loads...
  76. $(".tab_content").hide(); //Hide all content
  77. $("ul.tabs li:first").addClass("active").show(); //Activate first tab
  78. $(".tab_content:first").show(); //Show first tab content
  79. //On Click Event
  80. $("ul.tabs li").click(function() {
  81. $("ul.tabs li").removeClass("active"); //Remove any "active" class
  82. $(this).addClass("active"); //Add "active" class to selected tab
  83. $(".tab_content").hide(); //Hide all tab content
  84. var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
  85. $(activeTab).fadeIn(); //Fade in the active ID content
  86. return false;
  87. });
  88. });
  89. // ]]>
  90. </script>
  91. </head>
  92. <?php
  93. }
  94. function exportEventDetail( $event, $exportFrames, $exportImages )
  95. {
  96. global $SLANG;
  97. ob_start();
  98. exportHeader( $SLANG['Event']." ".$event['Id'] );
  99. $otherlinks = '';
  100. if( $exportFrames ) $otherlinks .= '<a href="zmEventFrames.html">'.$SLANG['Frames'].'</a>,';
  101. if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.$SLANG['Images'].'</a>,';
  102. $otherlinks = substr($otherlinks,0,-1);
  103. ?>
  104. <body>
  105. <div id="page">
  106. <div id="content">
  107. <h2><?= $SLANG['Event'] ?>: <?= validHtmlStr($event['Name']) ?><?php if(!empty($otherlinks)) { ?> (<?=$otherlinks?>) <?php } ?></h2>
  108. <table id="eventDetail">
  109. <tr><th scope="row"><?= $SLANG['Id'] ?></th><td><?= $event['Id'] ?></td></tr>
  110. <tr><th scope="row"><?= $SLANG['Name'] ?></th><td><?= validHtmlStr($event['Name']) ?></td></tr>
  111. <tr><th scope="row"><?= $SLANG['Monitor'] ?></th><td><?= validHtmlStr($event['MonitorName']) ?> (<?= $event['MonitorId'] ?>)</td></tr>
  112. <tr><th scope="row"><?= $SLANG['Cause'] ?></th><td><?= validHtmlStr($event['Cause']) ?></td></tr>
  113. <tr><th scope="row"><?= $SLANG['Notes'] ?></th><td><?= validHtmlStr($event['Notes']) ?></td></tr>
  114. <tr><th scope="row"><?= $SLANG['Time'] ?></th><td><?= strftime( STRF_FMT_DATETIME_SHORTER, strtotime($event['StartTime']) ) ?></td></tr>
  115. <tr><th scope="row"><?= $SLANG['Duration'] ?></th><td><?= $event['Length'] ?></td></tr>
  116. <tr><th scope="row"><?= $SLANG['Frames'] ?></th><td><?= $event['Frames'] ?></td></tr>
  117. <tr><th scope="row"><?= $SLANG['AttrAlarmFrames'] ?></th><td><?= $event['AlarmFrames'] ?></td></tr>
  118. <tr><th scope="row"><?= $SLANG['AttrTotalScore'] ?></th><td><?= $event['TotScore'] ?></td></tr>
  119. <tr><th scope="row"><?= $SLANG['AttrAvgScore'] ?></th><td><?= $event['AvgScore'] ?></td></tr>
  120. <tr><th scope="row"><?= $SLANG['AttrMaxScore'] ?></th><td><?= $event['MaxScore'] ?></td></tr>
  121. <tr><th scope="row"><?= $SLANG['Archived'] ?></th><td><?= $event['Archived']?$SLANG['Yes']:$SLANG['No'] ?></td></tr>
  122. </table>
  123. </div>
  124. </div>
  125. </body>
  126. </html>
  127. <?php
  128. return( ob_get_clean() );
  129. }
  130. function exportEventFrames( $event, $exportDetail, $exportImages )
  131. {
  132. global $SLANG;
  133. $sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '".dbEscape($event['Id'])."' order by FrameId";
  134. $frames = dbFetchAll( $sql );
  135. ob_start();
  136. exportHeader( $SLANG['Frames']." ".$event['Id'] );
  137. $otherlinks = '';
  138. if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.$SLANG['Event'].'</a>,';
  139. if( $exportImages ) $otherlinks .= '<a href="zmEventImages.html">'.$SLANG['Images'].'</a>,';
  140. $otherlinks = substr($otherlinks,0,-1);
  141. ?>
  142. <body>
  143. <div id="page">
  144. <div id="content">
  145. <h2><?= $SLANG['Frames'] ?>: <?= validHtmlStr($event['Name']) ?><?php if(!empty($otherlinks)) { ?> (<?=$otherlinks?>) <?php } ?></h2>
  146. <table id="eventFrames">
  147. <tr>
  148. <th><?= $SLANG['FrameId'] ?></th>
  149. <th><?= $SLANG['Type'] ?></th>
  150. <th><?= $SLANG['TimeStamp'] ?></th>
  151. <th><?= $SLANG['TimeDelta'] ?></th>
  152. <th><?= $SLANG['Score'] ?></th>
  153. <?php
  154. if ( $exportImages )
  155. {
  156. ?>
  157. <th><?= $SLANG['Image'] ?></th>
  158. <?php
  159. }
  160. ?>
  161. </tr>
  162. <?php
  163. if ( count($frames) )
  164. {
  165. $eventPath = mygetEventPath( $event );
  166. foreach ( $frames as $frame )
  167. {
  168. $imageFile = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $frame['FrameId'] );
  169. $imagePath = $eventPath."/".$imageFile;
  170. $analImage = preg_replace( "/capture/", "analyse", $imagePath );
  171. if ( file_exists( $analImage ) )
  172. {
  173. $imageFile = preg_replace( "/capture/", "analyse", $imageFile );
  174. }
  175. $class = strtolower($frame['Type']);
  176. ?>
  177. <tr class="<?= $class ?>">
  178. <td><?= $frame['FrameId'] ?></td>
  179. <td><?= $frame['Type'] ?></td>
  180. <td><?= strftime( STRF_FMT_TIME, $frame['UnixTimeStamp'] ) ?></td>
  181. <td><?= number_format( $frame['Delta'], 2 ) ?></td>
  182. <td><?= $frame['Score'] ?></td>
  183. <?php
  184. if ( $exportImages )
  185. {
  186. ?>
  187. <td><a href="<?= $imageFile ?>" target="zmExportImage"><img src="<?= $imageFile ?>" border="0" class="thumb" alt="Frame <?= $frame['FrameId'] ?>"/></a></td>
  188. <?php
  189. }
  190. ?>
  191. </tr>
  192. <?php
  193. }
  194. }
  195. else
  196. {
  197. ?>
  198. <tr>
  199. <td class="monoRow" colspan="<?= $exportImages?6:5 ?>"><?= $SLANG['NoFramesRecorded'] ?></td>
  200. </tr>
  201. <?php
  202. }
  203. ?>
  204. </table>
  205. </div>
  206. </div>
  207. </body>
  208. </html>
  209. <?php
  210. return( ob_get_clean() );
  211. }
  212. function exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist )
  213. {
  214. global $SLANG;
  215. ob_start();
  216. exportHeader( $SLANG['Images']." ".$event['Id'] );
  217. $otherlinks = '';
  218. if( $exportDetail ) $otherlinks .= '<a href="zmEventDetail.html">'.$SLANG['Event'].'</a>,';
  219. if( $exportFrames ) $otherlinks .= '<a href="zmEventFrames.html">'.$SLANG['Frames'].'</a>,';
  220. $otherlinks = substr($otherlinks,0,-1);
  221. $filelist = array_keys($myfilelist);
  222. sort($filelist,SORT_NUMERIC);
  223. $slides = '"'.implode('","',$filelist).'"';
  224. $listcount = count($filelist);
  225. ?>
  226. <body>
  227. <style>
  228. *.horizontal_track {background-color: #bbb;width: <?=$event['Width']?>px;line-height: 0px;font-size: 0px;text-align: left;padding: 4px;border: 1px solid;border-color: #ddd #999 #999 #ddd;}
  229. *.horizontal_slider {background-color: #666;width: 16px;height: 8px;position: relative;z-index: 2;line-height: 0;margin: 0;border: 2px solid;border-color: #999 #333 #333 #999;}
  230. *.horizontal_slit {background-color: #333;width: <?=($event['Width']-10)?>px;height: 2px;margin: 4px 4px 2px 4px;line-height: 0;position: absolute;z-index: 1;border: 1px solid;border-color: #999 #ddd #ddd #999;}
  231. *.vertical_track {background-color: #bbb;padding: 3px 5px 15px 5px;border: 1px solid;border-color: #ddd #999 #999 #ddd;}
  232. *.vertical_slider {background-color: #666;width: 18px;height: 8px;font: 0px;text-align: left;line-height: 0px;position: relative;z-index: 1;border: 2px solid;border-color: #999 #333 #333 #999;}
  233. *.vertical_slit {background-color: #000;width: 2px;height: 100px;position: absolute;margin: 4px 10px 4px 10px;padding: 4px 0 1px 0;line-height: 0;font-size: 0;border: 1px solid;border-color: #666 #ccc #ccc #666;}
  234. *.display_holder {background-color: #bbb;color: #fff;width: 34px;height: 20px;text-align: right;padding: 0;border: 1px solid;border-color: #ddd #999 #999 #ddd;}
  235. .value_display {background-color: #bbb;color: #333;width: 30px;margin: 0 2px;text-align: right;font-size: 8pt;font-face: verdana, arial, helvetica, sans-serif;font-weight: bold;line-height: 12px;border: 0;cursor: default;}
  236. </style>
  237. <h2><?= $SLANG['Images'] ?>: <?= validHtmlStr($event['Name']) ?><?php if(!empty($otherlinks)) { ?> (<?=$otherlinks?>) <?php } ?></h2>
  238. <ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide>
  239. <layer id="slidenssub" width=&{slidewidth}; left=auto top=auto></layer>
  240. </ilayer>
  241. <div id="imagevideo" align="center"></div>
  242. <br>
  243. <div align="center">
  244. <button onclick="stepbackward()">< Step</button><button
  245. id="btnrwd" onclick="rewind()" >Rwd</button><button
  246. id="btnplay" onclick="playstop()">Stop</button><button
  247. onclick="stepforward()">Step ></button><button
  248. id="btnspeedup" onclick="speedup()">speedup</button><button
  249. id="btnspeeddown" onclick="speeddown()">slowdown</button>
  250. </div>
  251. <div align="center"><div class="horizontal_track" >
  252. <div class="horizontal_slit" >&nbsp;</div>
  253. <div class="horizontal_slider" id="imageslider_id" style="left: 0px;"
  254. onmousedown="slide(event,'horizontal', <?=($event['Width']-20)?>, 1, <?=$listcount?>, <?=$listcount?>,0, 'imageslider_display_id');" >&nbsp;</div>
  255. </div></div>
  256. <div align="center"><div class="display_holder" ><input id="imageslider_display_id" class="value_display" type="text" value="0" onfocus="blur(this);" /></div></div>
  257. <script language="JavaScript1.2">
  258. /***********************************************
  259. * Flexi Slideshow- © Dynamic Drive (www.dynamicdrive.com)
  260. * This notice must stay intact for use
  261. * Visit http://www.dynamicdrive.com/ for full source code
  262. ***********************************************/
  263. var eventWidth = <?=$event['Width']?>;
  264. var eventHeight = <?=$event['Height']?>;
  265. var variableslide=[<?=$slides?>];
  266. //configure the below 3 variables to set the dimension/background color of the slideshow
  267. var slidewidth=eventWidth+'px' //set to width of LARGEST image in your slideshow
  268. var slideheight=eventHeight+'px' //set to height of LARGEST iamge in your slideshow, plus any text description
  269. var slidebgcolor='#ffffff'
  270. //configure the below variable to determine the delay between image rotations (in miliseconds)
  271. var origslidedelay=100;
  272. var slidedelay=origslidedelay;
  273. ////Do not edit pass this line////////////////
  274. var ie=document.all;
  275. var dom=document.getElementById;
  276. for (i=0;i<variableslide.length;i++){
  277. var cacheimage=new Image()
  278. cacheimage.src=variableslide[i]
  279. }
  280. var currentslide=-1
  281. var mytimer = null;
  282. //if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+'px;height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>');
  283. if (ie||dom) document.getElementById('imagevideo').innerHTML = '<div id="slidedom" style="width:'+slidewidth+'px;height:'+slideheight+'; background-color:'+slidebgcolor+'"><img src="" name="imageslideframe"></div>';
  284. function rotateimages(){
  285. if (currentslide==variableslide.length-1) currentslide=0;
  286. else currentslide++;
  287. changeimage();
  288. mytimer = setTimeout("rotateimages()",slidedelay);
  289. }
  290. function changeimage() {
  291. contentcontainer='<center><img src="'+variableslide[currentslide]+'" border="0" vspace="3"></center>';
  292. if (document.layers){
  293. crossrotateobj.document.write(contentcontainer);
  294. crossrotateobj.document.close();
  295. }
  296. else if (ie||dom) document.imageslideframe.src = variableslide[currentslide];
  297. slideManual(currentslide+1,eventWidth-20, 1, variableslide.length);
  298. }
  299. function start_slider(){
  300. crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub;
  301. if (document.layers) document.slidensmain.visibility="show";
  302. rotateimages();
  303. }
  304. // seyi_code
  305. function rotateimagesrewind(){
  306. if (currentslide==0) currentslide=variableslide.length-1;
  307. else currentslide--;
  308. changeimage();
  309. mytimer = setTimeout("rotateimagesrewind()",slidedelay);
  310. }
  311. function stepforward() {
  312. clearTimeout(mytimer);
  313. // document.getElementById('btnrwd').style.borderTop='2px solid #ffffff';
  314. // document.getElementById('btnrwd').style.borderBottom='2px solid #848284';
  315. // document.getElementById('btnrwd').style.borderRight='2px solid #848284';
  316. // document.getElementById('btnrwd').style.borderLeft='1px solid #ffffff';
  317. document.getElementById('btnplay').disabled = false;
  318. document.getElementById('btnplay').innerHTML = 'Play';
  319. document.getElementById('btnspeedup').disabled = true;
  320. document.getElementById('btnspeeddown').disabled = true;
  321. if (currentslide==variableslide.length-1) currentslide=0;
  322. else currentslide++;
  323. changeimage();
  324. }
  325. function stepbackward() {
  326. clearTimeout(mytimer);
  327. // document.getElementById('btnrwd').style.borderTop='2px solid #ffffff';
  328. // document.getElementById('btnrwd').style.borderBottom='2px solid #848284';
  329. // document.getElementById('btnrwd').style.borderRight='2px solid #848284';
  330. // document.getElementById('btnrwd').style.borderLeft='1px solid #ffffff';
  331. document.getElementById('btnplay').disabled = false;
  332. document.getElementById('btnplay').innerHTML = 'Play';
  333. document.getElementById('btnspeedup').disabled = true;
  334. document.getElementById('btnspeeddown').disabled = true;
  335. if (currentslide==0) currentslide=variableslide.length-1;
  336. else currentslide--;
  337. changeimage();
  338. }
  339. function speedup() { slidedelay = slidedelay/2; }
  340. function speeddown() { slidedelay = slidedelay*2; }
  341. function playstop() {
  342. if(document.getElementById('btnplay').innerHTML == 'Play') {
  343. slidedelay = origslidedelay;
  344. mytimer = setTimeout("rotateimages()",slidedelay);
  345. document.getElementById('btnplay').innerHTML = 'Stop';
  346. document.getElementById('btnspeedup').disabled = false;
  347. document.getElementById('btnspeeddown').disabled = false;
  348. } else if(document.getElementById('btnplay').innerHTML == 'Stop') {
  349. clearTimeout(mytimer);
  350. document.getElementById('btnplay').innerHTML = 'Play';
  351. document.getElementById('btnrwd').disabled = false;
  352. document.getElementById('btnspeedup').disabled = true;
  353. document.getElementById('btnspeeddown').disabled = true;
  354. }
  355. }
  356. function rewind() {
  357. clearTimeout(mytimer);
  358. if(!document.getElementById('btnplay').disabled) {
  359. slidedelay = origslidedelay;
  360. mytimer = setTimeout("rotateimagesrewind()",slidedelay);
  361. // document.getElementById('btnrwd').style.borderTop = '2px solid #414241';
  362. // document.getElementById('btnrwd').style.borderBottom = '1px solid #ffffff';
  363. // document.getElementById('btnrwd').style.borderLeft = '2px solid #414241';
  364. // document.getElementById('btnrwd').style.borderRight = '1px solid #ffffff';
  365. document.getElementById('btnplay').disabled = true;
  366. document.getElementById('btnspeedup').disabled = false;
  367. document.getElementById('btnspeeddown').disabled = false;
  368. } else {
  369. // document.getElementById('btnrwd').style.borderTop='2px solid #ffffff';
  370. // document.getElementById('btnrwd').style.borderBottom='2px solid #848284';
  371. // document.getElementById('btnrwd').style.borderRight='2px solid #848284';
  372. // document.getElementById('btnrwd').style.borderLeft='1px solid #ffffff';
  373. document.getElementById('btnplay').disabled = false;
  374. document.getElementById('btnspeedup').disabled = true;
  375. document.getElementById('btnspeeddown').disabled = true;
  376. }
  377. }
  378. //---------------------------------+
  379. // CARPE S l i d e r 1.3 |
  380. // 2005 - 12 - 10 |
  381. // By Tom Hermansson Snickars |
  382. // Copyright CARPE Design |
  383. // http://carpe.ambiprospect.com/ |
  384. //---------------------------------+
  385. // carpeGetElementByID: Cross-browser version of "document.getElementById()"
  386. function carpeGetElementById(element) {
  387. if (document.getElementById) element = document.getElementById(element);
  388. else if (document.all) element = document.all[element];
  389. else element = null;
  390. return element;
  391. }
  392. // carpeLeft: Cross-browser version of "element.style.left"
  393. function carpeLeft(elmnt, pos) {
  394. if (!(elmnt = carpeGetElementById(elmnt))) return 0;
  395. if (elmnt.style && (typeof(elmnt.style.left) == 'string')) {
  396. if (typeof(pos) == 'number') elmnt.style.left = pos + 'px';
  397. else {
  398. pos = parseInt(elmnt.style.left);
  399. if (isNaN(pos)) pos = 0;
  400. }
  401. }
  402. else if (elmnt.style && elmnt.style.pixelLeft) {
  403. if (typeof(pos) == 'number') elmnt.style.pixelLeft = pos;
  404. else pos = elmnt.style.pixelLeft;
  405. }
  406. return pos;
  407. }
  408. // carpeTop: Cross-browser version of "element.style.top"
  409. function carpeTop(elmnt, pos) {
  410. if (!(elmnt = carpeGetElementById(elmnt))) return 0;
  411. if (elmnt.style && (typeof(elmnt.style.top) == 'string')) {
  412. if (typeof(pos) == 'number') elmnt.style.top = pos + 'px';
  413. else {
  414. pos = parseInt(elmnt.style.top);
  415. if (isNaN(pos)) pos = 0;
  416. }
  417. }
  418. else if (elmnt.style && elmnt.style.pixelTop) {
  419. if (typeof(pos) == 'number') elmnt.style.pixelTop = pos;
  420. else pos = elmnt.style.pixelTop;
  421. }
  422. return pos;
  423. }
  424. // moveSlider: Handles slider and display while dragging
  425. function moveSlider(evnt) {
  426. var evnt = (!evnt) ? window.event : evnt; // The mousemove event
  427. if (mouseover) { // Only if slider is dragged
  428. x = pxLeft + evnt.screenX - xCoord // Horizontal mouse position relative to allowed slider positions
  429. y = pxTop + evnt.screenY - yCoord // Horizontal mouse position relative to allowed slider positions
  430. if (x > xMax) x = xMax // Limit horizontal movement
  431. if (x < 0) x = 0 // Limit horizontal movement
  432. if (y > yMax) y = yMax // Limit vertical movement
  433. if (y < 0) y = 0 // Limit vertical movement
  434. carpeLeft(sliderObj.id, x) // move slider to new horizontal position
  435. carpeTop(sliderObj.id, y) // move slider to new vertical position
  436. sliderVal = x + y // pixel value of slider regardless of orientation
  437. sliderPos = (sliderObj.pxLen / sliderObj.valCount) * Math.round(sliderObj.valCount * sliderVal / sliderObj.pxLen)
  438. v = Math.round((sliderPos * sliderObj.scale + sliderObj.fromVal) * // calculate display value
  439. Math.pow(10, displayObj.dec)) / Math.pow(10, displayObj.dec)
  440. displayObj.value = v // put the new value in the slider display element
  441. // seyi_code
  442. currentslide = v-1;
  443. changeimage();
  444. return false
  445. }
  446. return
  447. }
  448. // moveSlider: Handles the start of a slider move.
  449. function slide(evnt, orientation, length, from, to, count, decimals, display) {
  450. if (!evnt) evnt = window.event;
  451. sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
  452. sliderObj.pxLen = length // The allowed slider movement in pixels.
  453. sliderObj.valCount = count ? count - 1 : length // Allowed number of values in the interval.
  454. displayObj = carpeGetElementById(display) // Get the associated display element.\
  455. displayObj.dec = decimals // Number of decimals to be displayed.
  456. sliderObj.scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
  457. if (orientation == 'horizontal') { // Set limits for horizontal sliders.
  458. sliderObj.fromVal = from
  459. xMax = length
  460. yMax = 0
  461. }
  462. if (orientation == 'vertical') { // Set limits and scale for vertical sliders.
  463. sliderObj.fromVal = to
  464. xMax = 0
  465. yMax = length
  466. sliderObj.scale = -sliderObj.scale // Invert scale for vertical sliders. "Higher is more."
  467. }
  468. pxLeft = carpeLeft(sliderObj.id) // Sliders horizontal position at start of slide.
  469. pxTop = carpeTop(sliderObj.id) // Sliders vertical position at start of slide.
  470. xCoord = evnt.screenX // Horizontal mouse position at start of slide.
  471. yCoord = evnt.screenY // Vertical mouse position at start of slide.
  472. mouseover = true
  473. document.onmousemove = moveSlider // Start the action if the mouse is dragged.
  474. document.onmouseup = sliderMouseUp // Stop sliding.
  475. }
  476. // sliderMouseup: Handles the mouseup event after moving a slider.
  477. // Snaps the slider position to allowed/displayed value.
  478. function sliderMouseUp() {
  479. mouseover = false // Stop the sliding.
  480. v = (displayObj.value) ? displayObj.value : 0 // Find last display value.
  481. pos = (v - sliderObj.fromVal)/(sliderObj.scale) // Calculate slider position (regardless of orientation).
  482. if (yMax == 0) carpeLeft(sliderObj.id, pos) // Snap horizontal slider to corresponding display position.
  483. if (xMax == 0) carpeTop(sliderObj.id, pos) // Snap vertical slider to corresponding display position.
  484. if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
  485. document.removeEventListener('mousemove', moveSlider)
  486. document.removeEventListener('mouseup', sliderMouseUp)
  487. }
  488. else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
  489. document.detachEvent('onmousemove', moveSlider)
  490. document.detachEvent('onmouseup', sliderMouseUp)
  491. }
  492. }
  493. //seyi_code
  494. //slide(event,'horizontal', 300, 1, 22, 22,0, 'imageslider_display_id');
  495. //slide(evnt, orientation, length, from, to, count, decimals, display) {
  496. function slideManual(val,length,from,to) {
  497. scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
  498. fromVal = from
  499. xMax = length
  500. yMax = 0
  501. sliderid = 'imageslider_id';
  502. v = (val) ? val : 0 // Find last display value.
  503. displayobject = carpeGetElementById('imageslider_display_id') // Get the associated display element.\
  504. displayobject.value = val;
  505. pos = (v - fromVal)/(scale) // Calculate slider position (regardless of orientation).
  506. if (yMax == 0) carpeLeft(sliderid, pos) // Snap horizontal slider to corresponding display position.
  507. }
  508. if (ie||dom) start_slider();
  509. else if (document.layers) window.onload=start_slider;
  510. </script>
  511. </body>
  512. </html>
  513. <?php
  514. return( ob_get_clean() );
  515. }
  516. function exportEventImagesMaster( $eids )
  517. {
  518. global $SLANG;
  519. ob_start();
  520. exportHeader( $SLANG['Images'].' Master' );
  521. ?>
  522. <body>
  523. <h2><?= $SLANG['Images'] ?> Master</h2>
  524. <?php
  525. foreach ($eids as $eid) {
  526. //get monitor id and event id
  527. $sql = "select E.MonitorId from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where E.Id = '".dbEscape($eid)."'";
  528. $event = dbFetchOne( $sql );
  529. $eventMonitorId[$eid] = $event['MonitorId'];
  530. }
  531. $monitors = array_values(array_flip(array_flip($eventMonitorId))); //unique monitors and reindex the array
  532. $monitorNames = array();
  533. //*
  534. if(!empty($monitors)) {
  535. $tmp = dbFetchAll("SELECT Id,Name FROM Monitors WHERE Id IN (".implode(',', $monitors).") ");
  536. foreach ( $tmp as $row ) { $monitorNames[$row['Id']] = $row['Name']; }
  537. }
  538. //*/
  539. //trigger_error(print_r($monitorNames,1));
  540. ?>
  541. <div id= 'tabs'>
  542. <ul class= 'tabs'>
  543. <li class = 'active' ><a href='#all' > All </a></li>
  544. <?php
  545. foreach ($monitors as $monitor) {
  546. # code...
  547. echo "<li><a href='#tab$monitor'>" . $monitorNames[$monitor] . "</a></li>";
  548. }
  549. ?>
  550. </ul>
  551. </div>
  552. <table width="100%" height="100%" ><tr>
  553. <td valign="top" bgcolor="#dddddd" style="padding:10px;">
  554. <div class='tab_content' id='all'>
  555. <h2> All </h2>
  556. <?php
  557. if (!is_array($eids))
  558. {
  559. echo "<div><a href=\"javascript:switchevent('$eids/zm/EventImages.html');\"> $eids </div>";
  560. }
  561. ?>
  562. <?php foreach($eids as $eid)
  563. {
  564. ?>
  565. <div><a href="javascript:switchevent('<?php echo $eventMonitorId[$eid].'/' . $eid; ?>/zmEventImages.html');"><?=$eid?></a></div>
  566. <?php
  567. }
  568. ?>
  569. </div>
  570. <?php
  571. foreach ($monitors as $monitor)
  572. {
  573. echo "<div class='tab_content' id='tab$monitor'>";
  574. echo "<h2>Monitor: " . $monitorNames[$monitor] . " </h2>";
  575. foreach ($eids as $eid)
  576. {
  577. if ($eventMonitorId[$eid] == $monitor)
  578. {
  579. ?>
  580. <div><a href="javascript:switchevent('<?php echo $eventMonitorId[$eid].'/' . $eid; ?>/zmEventImages.html');"><?=$eid?></a></div>
  581. <?php
  582. }
  583. }
  584. echo'</div>';
  585. }
  586. ?>
  587. </td><td>
  588. <iframe id="myframe" onload="resizeCaller();" name="myframe" src="#"
  589. scrolling="no" marginwidth="0" marginheight="0" frameborder="0"
  590. vspace="0" hspace="0" style="overflow:visible; width:100%; display:none">
  591. </iframe>
  592. </td>
  593. </tr></table>
  594. <script type="text/javascript">
  595. function switchevent(src) {
  596. if(document.all) document.all.myframe.src = src;
  597. else window.frames['myframe'].location.href = src;
  598. }
  599. /***********************************************
  600. * IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
  601. * Visit DynamicDrive.com for hundreds of original DHTML scripts
  602. * This notice must stay intact for legal use
  603. ***********************************************/
  604. //Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
  605. //Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
  606. var iframeids=["myframe"]
  607. //Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
  608. var iframehide="yes"
  609. var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
  610. var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
  611. function resizeCaller() {
  612. var dyniframe=new Array()
  613. for (i=0; i<iframeids.length; i++){
  614. if (document.getElementById) resizeIframe(iframeids[i]);
  615. //reveal iframe for lower end browsers? (see var above):
  616. if ((document.all || document.getElementById) && iframehide=="no"){
  617. var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
  618. tempobj.style.display="block"
  619. }
  620. }
  621. }
  622. function resizeIframe(frameid){
  623. var currentfr=document.getElementById(frameid)
  624. if (currentfr && !window.opera){
  625. currentfr.style.display="block"
  626. if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
  627. currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
  628. else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
  629. currentfr.height = currentfr.Document.body.scrollHeight;
  630. if (currentfr.addEventListener) currentfr.addEventListener("load", readjustIframe, false);
  631. else if (currentfr.attachEvent){
  632. currentfr.detachEvent("onload", readjustIframe) // Bug fix line
  633. currentfr.attachEvent("onload", readjustIframe)
  634. }
  635. }
  636. }
  637. function readjustIframe(loadevt) {
  638. var crossevt=(window.event)? event : loadevt;
  639. var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
  640. if (iframeroot) resizeIframe(iframeroot.id);
  641. }
  642. function loadintoIframe(iframeid, url){
  643. if (document.getElementById) document.getElementById(iframeid).src=url;
  644. }
  645. //if (window.addEventListener) window.addEventListener("load", resizeCaller, false)
  646. //else if (window.attachEvent) window.attachEvent("onload", resizeCaller)
  647. //else window.onload=resizeCaller
  648. </script>
  649. </body>
  650. </html>
  651. <?php
  652. return( ob_get_clean() );
  653. }
  654. function exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc )
  655. {
  656. if ( canView( 'Events' ) && $eid )
  657. {
  658. $sql = "select E.Id,E.MonitorId,M.Name As MonitorName,M.Width,M.Height,E.Name,E.Cause,E.Notes,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 E.Id = '".dbEscape($eid)."'";
  659. $event = dbFetchOne( $sql );
  660. $eventPath = mygetEventPath( $event );
  661. $files = array();
  662. if ( $dir = opendir( $eventPath ) )
  663. {
  664. while ( ($file = readdir( $dir )) !== false )
  665. {
  666. if ( is_file( $eventPath."/".$file ) )
  667. {
  668. $files[$file] = $file;
  669. }
  670. }
  671. closedir( $dir );
  672. }
  673. $exportFileList = array();
  674. if ( $exportDetail )
  675. {
  676. $file = "zmEventDetail.html";
  677. if ( !($fp = fopen( $eventPath."/".$file, "w" )) )
  678. {
  679. Fatal( "Can't open event detail export file '$file'" );
  680. }
  681. fwrite( $fp, exportEventDetail( $event, $exportFrames, $exportImages ) );
  682. fclose( $fp );
  683. $exportFileList[$file] = $eventPath."/".$file;
  684. }
  685. if ( $exportFrames )
  686. {
  687. $file = "zmEventFrames.html";
  688. if ( !($fp = fopen( $eventPath."/".$file, "w" )) )
  689. {
  690. Fatal( "Can't open event frames export file '$file'" );
  691. }
  692. fwrite( $fp, exportEventFrames( $event, $exportDetail, $exportImages ) );
  693. fclose( $fp );
  694. $exportFileList[$file] = $eventPath."/".$file;
  695. }
  696. if ( $exportImages )
  697. {
  698. $filesLeft = array();
  699. $myfilelist = array();
  700. foreach ( $files as $file )
  701. {
  702. if ( preg_match( "/-(?:capture|analyse).jpg$/", $file ) )
  703. {
  704. $exportFileList[$file] = $eventPath."/".$file;
  705. $myfilelist[$file] = $eventPath."/".$file;
  706. }
  707. else
  708. {
  709. $filesLeft[$file] = $file;
  710. }
  711. }
  712. $files = $filesLeft;
  713. // create an image slider
  714. if(!empty($myfilelist)) {
  715. $file = "zmEventImages.html";
  716. if ( !($fp = fopen( $eventPath."/".$file, "w" )) ) Fatal( "Can't open event images export file '$file'" );
  717. fwrite( $fp, exportEventImages( $event, $exportDetail, $exportFrames, $myfilelist ) );
  718. fclose( $fp );
  719. $exportFileList[$file] = $eventPath."/".$file;
  720. }
  721. }
  722. if ( $exportVideo )
  723. {
  724. $filesLeft = array();
  725. foreach ( $files as $file )
  726. {
  727. if ( preg_match( "/\.(?:mpg|mpeg|avi|asf|3gp)$/", $file ) )
  728. {
  729. $exportFileList[$file] = $eventPath."/".$file;
  730. }
  731. else
  732. {
  733. $filesLeft[$file] = $file;
  734. }
  735. }
  736. $files = $filesLeft;
  737. }
  738. if ( $exportMisc )
  739. {
  740. foreach ( $files as $file )
  741. {
  742. $exportFileList[$file] = $eventPath."/".$file;
  743. }
  744. $files = array();
  745. }
  746. }
  747. return( array_values( $exportFileList ) );
  748. }
  749. function exportEvents( $eids, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc, $exportFormat )
  750. {
  751. if ( canView( 'Events' ) && !empty($eids) )
  752. {
  753. $export_root = "zmExport";
  754. $export_listFile = "zmFileList.txt";
  755. $exportFileList = array();
  756. $html_eventMaster = '';
  757. if ( is_array( $eids ) )
  758. {
  759. foreach ( $eids as $eid )
  760. {
  761. $exportFileList = array_merge( $exportFileList, exportFileList( $eid , $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc ) );
  762. }
  763. }
  764. else
  765. {
  766. $eid = $eids;
  767. $exportFileList = exportFileList( $eid, $exportDetail, $exportFrames, $exportImages, $exportVideo, $exportMisc );
  768. }
  769. // create an master image slider
  770. if($exportImages)
  771. {
  772. if ( !is_array($eids) )
  773. {
  774. $eids = array($eids);
  775. }
  776. $monitorPath = 'events/';
  777. $html_eventMaster = 'zmEventImagesMaster_'.date('Ymd_His'). '.html';
  778. if ( !($fp = fopen( $monitorPath."/".$html_eventMaster, "w" )) ) Fatal( "Can't open event images export file '$html_eventMaster'" );
  779. fwrite( $fp, exportEventImagesMaster( $eids ) );
  780. fclose( $fp );
  781. $exportFileList[] = $monitorPath."/".$html_eventMaster;
  782. }
  783. $listFile = "temp/".$export_listFile;
  784. if ( !($fp = fopen( $listFile, "w" )) )
  785. {
  786. Fatal( "Can't open event export list file '$listFile'" );
  787. }
  788. foreach ( $exportFileList as $exportFile )
  789. {
  790. fwrite( $fp, "$exportFile\n" );
  791. }
  792. fclose( $fp );
  793. $archive = "";
  794. if ( $exportFormat == "tar" )
  795. {
  796. $archive = "temp/".$export_root.".tar.gz";
  797. @unlink( $archive );
  798. $command = "tar --create --gzip --file=$archive --files-from=$listFile";
  799. exec( escapeshellcmd( $command ), $output, $status );
  800. if ( $status )
  801. {
  802. Error( "Command '$command' returned with status $status" );
  803. if ( $output[0] )
  804. Error( "First line of output is '".$output[0]."'" );
  805. return( false );
  806. }
  807. }
  808. elseif ( $exportFormat == "zip" )
  809. {
  810. $archive = "temp/zm_export.zip";
  811. $archive = "temp/".$export_root.".zip";
  812. @unlink( $archive );
  813. $command = "cat ".escapeshellarg($listFile)." | zip -q ".escapeshellarg($archive)." -@";
  814. //cat zmFileList.txt | zip -q zm_export.zip -@
  815. //-bash: zip: command not found
  816. exec( $command, $output, $status );
  817. if ( $status )
  818. {
  819. Error( "Command '$command' returned with status $status" );
  820. if ( $output[0] )
  821. Error( "First line of output is '".$output[0]."'" );
  822. return( false );
  823. }
  824. }
  825. //clean up temporary files
  826. if(!empty($html_eventMaster)) {
  827. unlink($monitorPath.'/'.$html_eventMaster);
  828. }
  829. }
  830. return( $archive );
  831. }
  832. function mygetEventPath( $event )
  833. {
  834. if ( ZM_USE_DEEP_STORAGE )
  835. $eventPath = ZM_DIR_EVENTS.'/'.$event['MonitorId'].'/'.strftime( "%y/%m/%d/%H/%M/%S", strtotime($event['StartTime']) );
  836. else
  837. $eventPath = ZM_DIR_EVENTS.'/'.$event['MonitorId'].'/'.$event['Id'];
  838. return( $eventPath );
  839. }