From 52cdb8a05a31410aab9882c8b9b52caa4bb67bb4 Mon Sep 17 00:00:00 2001
From: Isaac Connor <iconnor@pseudo.connortechnology.com>
Date: Thu, 17 Sep 2015 15:29:36 -0400
Subject: [PATCH] add Monitor class

---
 web/includes/Makefile.am |  1 +
 web/includes/Monitor.php | 61 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 web/includes/Monitor.php

diff --git a/web/includes/Makefile.am b/web/includes/Makefile.am
index 7943e32d1..d4a1ece9b 100644
--- a/web/includes/Makefile.am
+++ b/web/includes/Makefile.am
@@ -6,6 +6,7 @@ web_DATA = \
 	config.php
 
 dist_web_DATA = \
+	Monitor.php \
 	Server.php \
 	actions.php \
 	database.php \
diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php
new file mode 100644
index 000000000..a3d3ebebb
--- /dev/null
+++ b/web/includes/Monitor.php
@@ -0,0 +1,61 @@
+<?php
+require_once( 'database.php' );
+require_once( 'Server.php' );
+
+class Monitor {
+	public function __construct( $id ) {
+		if ( $id ) {
+		$s = dbFetchOne( 'SELECT * FROM Monitors WHERE Id=?', NULL, array( $id ) );
+		if ( $s ) {
+			foreach ($s as $k => $v) {
+				$this->{$k} = $v;
+			}
+		} else {
+			Error("Unable to load Monitor record for Id=" . $id );
+		}
+		} else {
+			
+		}
+	} // end function __construct
+	public function __call( $fn, array $args){
+        if(isset($this->{$fn})){
+			return $fn;
+            #array_unshift($args, $this);
+            #call_user_func_array( $this->{$fn}, $args);
+        }
+    }
+	public function getStreamSrc( $args, $querySep='&amp;' ) {
+		if ( isset($this->{'ServerId'}) and $this->{'ServerId'} ) {
+			$Server = new Server( $this->{'ServerId'} );
+			$streamSrc = ZM_BASE_PROTOCOL.'://'.$Server->Hostname.ZM_PATH_ZMS;
+		} else {
+			$streamSrc = ZM_BASE_URL.ZM_PATH_ZMS;
+		}
+
+		$args[] = "monitor=".$this->{'Id'};
+
+		if ( ZM_OPT_USE_AUTH ) {
+			if ( ZM_AUTH_RELAY == "hashed" ) {
+				$args[] = "auth=".generateAuthHash( ZM_AUTH_HASH_IPS );
+			} elseif ( ZM_AUTH_RELAY == "plain" ) {
+				$args[] = "user=".$_SESSION['username'];
+				$args[] = "pass=".$_SESSION['password'];
+			} elseif ( ZM_AUTH_RELAY == "none" ) {
+				$args[] = "user=".$_SESSION['username'];
+			}
+		}
+		if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) {
+			$args[] = "connkey=".$GLOBALS['connkey'];
+		}
+		if ( ZM_RAND_STREAM ) {
+			$args[] = "rand=".time();
+		}
+
+		if ( count($args) ) {
+			$streamSrc .= "?".join( $querySep, $args );
+		}
+
+		return( $streamSrc );
+	} // end function etStreamSrc
+}
+?>