Open monitors from montage view

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Open monitors from montage view

Post by unclerichy »

I've made a quick patch to zm_html_view_montagefeed.php to enable a user to open up the full camera watch window by clicking on one of the montage images.

I have my montage set to 1/2 regular image size so when something happens that looks interesting in the montage view I can click on the image and have the full view pop up as if I'd launched it from the console.

NB: This only works in browsers that use the native jpeg streaming method, such as Firefox.

Diff -> http://www.hunter13.com/zm_montagefeed.diff.txt
Complete file -> http://www.hunter13.com/zm_html_view_mo ... ed.php.txt
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

Thanks I will have a play with this sounds nice
Good idea and good work!

James
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

I tried this great contribution from unclerichy and found that when I put the php file into my Ubuntu 7.10 package install of 1.22, it messed up my montage scaling from the options panel (basically, my montage views no longer scaled properly; even though the image sizes on screen were the correct dimensions, the images themselves weren't scaled). Assuming this was because the montage scaling system may have changed since this patch was written in 2005, I modified it a bit and it seems to work for me now.

I left unclerichy's javascript:newWindow function alone at the top, and just added a little "echo" statement in the lower part that creates the link. This is a bit of a hack job (it doesn't even properly close the "<a>" tag), but so far it's working for me.

Allows clicking the montage image for a detail view of the monitor. You have to close your own windows; it's not smart enough to re-use the same pop-up window if you click another montage image.

If I haven't provided proper credit or if I've done something (other than poor coding) incorrectly, please let me know and give me a chance to correct it. I have never made a code contribution to anything before and I wanted to give something back (besides $) to the ZM community.

My edits to the stock 1.22 file - zm_html_view_montagefeed.php - below are surrounded by "//Haus Quick Edit" and "//Haus END Quick Edit"; the rest of the file is unchanged.

Code: Select all

<?php
//
// ZoneMinder web montage feed view file, $Date: 2006/03/27 22:01:33 $, $Revision: 1.40 $
// Copyright (C) 2003, 2004, 2005, 2006  Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

if ( !canView( 'Stream' ) )
{
	$view = "error";
	return;
}

if ( empty($mode) )
{
	if ( ZM_WEB_USE_STREAMS && canStream() )
		$mode = "stream";
	else
		$mode = "still";
}

if ( ZM_OPT_CONTROL )
{
	$sql = "select M.*,C.CanMoveMap,C.CanMoveRel from Monitors as M left join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'";
}
else
{
	$sql = "select * from Monitors where Id = '$mid'";
}
$result = mysql_query( $sql );
if ( !$result )
	die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );

$montage_width = ZM_WEB_MONTAGE_WIDTH?ZM_WEB_MONTAGE_WIDTH:reScale( $monitor['Width'], $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$montage_height = ZM_WEB_MONTAGE_HEIGHT?ZM_WEB_MONTAGE_HEIGHT:reScale( $monitor['Height'], $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$width_scale = ($montage_width*SCALE_BASE)/$monitor['Width'];
$height_scale = ($montage_height*SCALE_BASE)/$monitor['Height'];
$scale = (int)(($width_scale<$height_scale)?$width_scale:$height_scale);

if ( $mode != "stream" )
{
	// Prompt an image to be generated
	if ( ZM_WEB_REFRESH_METHOD == "http" )
		header("Refresh: ".ZM_WEB_REFRESH_IMAGE."; URL=$PHP_SELF?view=montagefeed&mid=$mid&mode=still&scale=$scale" );
}
noCacheHeaders();

$image_src = getStreamSrc( array( "mode=single", "monitor=".$monitor['Id'], "scale=".$scale ) );

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?= ZM_WEB_TITLE_PREFIX ?> - <?= $monitor['Name'] ?> - <?= $zmSlangFeed ?></title>
<link rel="stylesheet" href="zm_html_styles.css" type="text/css">
<script type="text/javascript">
//Haus Quick Edit: This was contributed by unclerichy of the Zoneminder Forums
function newWindow(Url,Name,Width,Height)
{
	var Name = window.open(Url,Name,"resizable,width="+Width+",height="+Height);
}
//Haus END Quick Edit: The above was contributed by unclerichy of the Zoneminder Forums

<?php
if ( $mode != "stream" && ZM_WEB_REFRESH_METHOD == "javascript" )
{
	if ( ZM_WEB_DOUBLE_BUFFER )
	{
?>
function fetchImage()
{
	var now = new Date();
	var zm_image = new Image();
	zm_image.src = '<?= $image_src ?>'+'&'+now.getTime();

	document['zmImage'].src = zm_image.src;
}

window.setInterval( "fetchImage()", <?= ZM_WEB_REFRESH_IMAGE*1000 ?> );
<?php
	}
	else
	{
?>
window.setTimeout( "window.location.reload(true)", <?= ZM_WEB_REFRESH_IMAGE*1000 ?> );
<?php
	}
}
?>
</script>
</head>
<body>
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center">
<?php
if ( $mode == "stream" )
{
//Haus Quick Edit
	echo('<a href="javascript:newWindow(\''.$PHP_SELF.'?view=watch&mid='.$monitor['Id'].'\',\'\')">');
//Haus End Quick Edit
	if ( ZM_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT )
	{
		$stream_src = getStreamSrc( array( "mode=mpeg", "monitor=".$monitor['Id'], "scale=".$scale, "bitrate=".ZM_WEB_VIDEO_BITRATE, "maxfps=".ZM_WEB_VIDEO_MAXFPS, "format=".ZM_MPEG_LIVE_FORMAT ) );
		outputVideoStream( $stream_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ), $monitor['Name'], ZM_MPEG_LIVE_FORMAT );
	}
	else
	{
		$stream_src = getStreamSrc( array( "mode=jpeg", "monitor=".$mid, "scale=".$scale, "maxfps=".ZM_WEB_VIDEO_MAXFPS ) );
		if ( canStreamNative() )
		{
			if ( $control && ($monitor['CanMoveMap'] || $monitor['CanMoveRel'] || $monitor['CanMoveCon']) )
			{
				outputControlStream( $stream_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ), $monitor, $scale, "MontageSink".$mid );
			}
			else
			{
				outputImageStream( $stream_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ), $monitor['Name'] );
			}
		}
		else
		{
			outputHelperStream( $stream_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ) );
		}
	}
}
else
{
	if ( $control && ($monitor['CanMoveMap'] || $monitor['CanMoveRel'] || $monitor['CanMoveCon']) )
	{
		outputControlStill( $image_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ), $monitor, $scale, "MontageSink".$mid );
	}
	else
	{
		outputImageStill( $image_src, reScale( $monitor['Width'], $scale ), reScale( $monitor['Height'], $scale ), $monitor['Name'] );
	}
}
?>
</td></tr>
</table>
</body>
</html>
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

What version did you do this patch on?

As an aside, this is a wonderful patch. I have many customers ask for this. Why is it not folded into the mainstream?
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Actualy this function is in ZM but only when you stream jpeg is it functional, Never really sat down to look at it.
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Lee, I'm using 1.22.3-8.deb or 1.22.3-9.deb (Peter Howard's fine work) on Ubuntu 7.04 server; I'm not sure which, though I'm pretty sure there's no change in the montage view between those two releases as I don't recall anything in the changelogs about it.

Cordel, I have "jpeg" selected under Options -> Images -> ZM_STREAM_METHOD. But until I edited the file above, I wasn't able to click the montage images. Am I missing a setting? If so, I feel sort of silly for changing the php file if the functionality is already there, but I'm not seeing it.
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Well unless I patched it to do so n my package, it already does so. I'll have to go back and look :roll:
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

Well, none of the unpatched systems I have can do it, and I have many people beating me over the head for it. I will be playing with this patch soon!
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

LOL don't let them beat you over the head! :)

I'm really enjoying this functionality now. I've got my montage thumbnails down to 160x120, so I can fit 9 monitors in a pretty small window, and then when Something Interesting Happens I can click and bring up the 320x240 pic and get a better view.
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

haus wrote:LOL don't let them beat you over the head! :)
It's OK. I have it on camera... ;)
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

Has anyone played with this in Peters new deb yet?
coke
Posts: 518
Joined: Wed Jan 30, 2008 5:53 pm
Location: St. Louis, MO, USA

Post by coke »

Zoneminder 1.23.2, Ubuntu 7.10, Firefox 2.0.0.12, doesn't appear to work.
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

I've never used 1.23, so I can't say what might be different in the zm_html_view_montagefeed.php file. If I upgrade to 1.23 I'll re-work the patch, but with a functioning 1.22 system I'm not sure there's enough new stuff in 1.23 to make me go through all the hassle of install/setup again...(sorry) - I'm a "don't mess with success" kind of guy.

If someone wants to run a diff between my zm_html_view_montagefeed.php file (as posted above) and that of a stock 1.23, it should become clear if there are massive changes between the two versions that would indicate how hard it would be to make this work under 1.23.
User avatar
ammaross
Posts: 61
Joined: Mon Mar 12, 2007 8:34 pm
Location: Utah, USA

Post by ammaross »

I had released a mod for montage view to view monitors by clicking on the image. It can be found here: http://www.zoneminder.com/forums/viewto ... highlight=

It doesn't have any scaling issues that I'm aware of.
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Ammaross,

Sorry - didn't mean to steal focus or not give credit to your earlier solution - I didn't know about your post/contribution. When I did a forum search, I only came up with unclerichy's thread, or I saw it and pounced on it without spending enough time reviewing all the info.

Nonetheless, echoing Lee's earlier comment, it would be great to see some of this stuff baked into ZM, rather than requiring patches. This has got to be one of the more useful changes for anyone who doesn't do full-size montage views.
Post Reply