Example #1
0
function outputlivestream($monitor, $inwidth = 0, $inheight = 0)
{
    $scale = isset($_REQUEST['scale']) ? validInt($_REQUEST['scale']) : reScale(SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE);
    $connkey = $monitor['connKey'];
    // Minor hack
    //$connKey = generateConnKey();
    if (ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT) {
        $streamMode = "mpeg";
        $streamSrc = getStreamSrc(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale, "bitrate=" . ZM_WEB_VIDEO_BITRATE, "maxfps=" . ZM_WEB_VIDEO_MAXFPS, "format=" . ZM_MPEG_LIVE_FORMAT, "buffer=" . $monitor['StreamReplayBuffer']));
    } elseif (canStream()) {
        $streamMode = "jpeg";
        $streamSrc = getStreamSrc(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale, "maxfps=" . ZM_WEB_VIDEO_MAXFPS, "buffer=" . $monitor['StreamReplayBuffer']));
    } else {
        $streamMode = "single";
        $streamSrc = getStreamSrc(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale));
    }
    $width = !empty($inwidth) ? $inwidth : 150;
    $height = empty($inheight) ? $width * $monitor['Height'] / $monitor['Width'] : $inheight;
    $width = (int) $width;
    $height = (int) $height;
    if ($streamMode === "mpeg") {
        outputVideoStream('liveStream' . $monitor['Id'], $streamSrc, reScale($width, $scale), reScale($height, $scale), ZM_MPEG_LIVE_FORMAT, $monitor['Name']);
    } elseif ($streamMode == "jpeg") {
        if (canStreamNative()) {
            outputImageStream('liveStream' . $monitor['Id'], $streamSrc, reScale($width, $scale), reScale($height, $scale), $monitor['Name']);
        } elseif (canStreamApplet()) {
            outputHelperStream('liveStream' . $monitor['Id'], $streamSrc, reScale($width, $scale), reScale($height, $scale), $monitor['Name']);
        }
    } else {
        outputImageStill('liveStream' . $monitor['Id'], $streamSrc, reScale($width, $scale), reScale($height, $scale), $monitor['Name']);
    }
}
Example #2
0
function getAffectedIds($name)
{
    $names = $name . "s";
    $ids = array();
    if (isset($_REQUEST[$names]) || isset($_REQUEST[$name])) {
        if (isset($_REQUEST[$names])) {
            $ids = validInt($_REQUEST[$names]);
        } else {
            if (isset($_REQUEST[$name])) {
                $ids[] = validInt($_REQUEST[$name]);
            }
        }
    }
    return $ids;
}
Example #3
0
function outputLiveStreamSrcModern($monitor, $inwidth = 0, $inheight = 0)
{
    $scale = isset($_REQUEST['scale']) ? validInt($_REQUEST['scale']) : reScale(SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE);
    $connKey = generateAuthHashModern(false);
    //$connkey = $monitor['connKey']; // Minor hack
    if (ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT) {
        $streamMode = "mpeg";
        $streamSrc = getStreamSrcModern(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale, "bitrate=" . ZM_WEB_VIDEO_BITRATE, "maxfps=" . ZM_WEB_VIDEO_MAXFPS, "format=" . ZM_MPEG_LIVE_FORMAT, "buffer=" . $monitor['StreamReplayBuffer']));
    } elseif (canStream()) {
        $streamMode = "jpeg";
        $streamSrc = getStreamSrcModern(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale, "maxfps=" . ZM_WEB_VIDEO_MAXFPS, "buffer=" . $monitor['StreamReplayBuffer']));
    } else {
        $streamMode = "single";
        $streamSrc = getStreamSrcModern(array("mode=" . $streamMode, "monitor=" . $monitor['Id'], "scale=" . $scale));
    }
    return $streamSrc;
}
Example #4
0
    $view = "error";
    return;
}
if (empty($_REQUEST['mode'])) {
    if (canStream()) {
        $mode = "stream";
    } else {
        $mode = "still";
    }
} else {
    $mode = validHtmlStr($_REQUEST['mode']);
}
$group = '';
$groupSql = '';
if (!empty($_REQUEST['group'])) {
    $group = validInt($_REQUEST['group']);
    $row = dbFetchOne('SELECT * FROM Groups WHERE Id = ?', NULL, array($group));
    $groupSql = " and find_in_set( Id, '" . $row['MonitorIds'] . "' )";
}
$sql = "SELECT * FROM Monitors WHERE Function != 'None'{$groupSql} ORDER BY Sequence";
$monitors = array();
$monIdx = 0;
foreach (dbFetchAll($sql) as $row) {
    if (!visibleMonitor($row['Id'])) {
        continue;
    }
    if (isset($_REQUEST['mid']) && $row['Id'] == $_REQUEST['mid']) {
        $monIdx = count($monitors);
    }
    $row['ScaledWidth'] = reScale($row['Width'], $row['DefaultScale'], ZM_WEB_DEFAULT_SCALE);
    $row['ScaledHeight'] = reScale($row['Height'], $row['DefaultScale'], ZM_WEB_DEFAULT_SCALE);
Example #5
0
        <table id="sortTable" class="filterTable" cellspacing="0">
          <tbody>
            <tr>
              <td><label for="sort_field"><?php 
echo translate('SortBy');
?>
</label><?php 
echo buildSelect("sort_field", $sort_fields);
echo buildSelect("sort_asc", $sort_dirns);
?>
</td>
              <td><label for="limit"><?php 
echo translate('LimitResultsPre');
?>
</label><input type="text" size="6" id="limit" name="limit" value="<?php 
echo isset($_REQUEST['limit']) ? validInt($_REQUEST['limit']) : "";
?>
"/><?php 
echo translate('LimitResultsPost');
?>
</td>
            </tr>
          </tbody>
        </table>
        <hr/>
        <table id="actionsTable" class="filterTable" cellspacing="0">
          <tbody>
            <tr>
              <td><?php 
echo translate('FilterArchiveEvents');
?>
Example #6
0
// 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('Control')) {
    $view = "error";
    return;
}
$groupSql = "";
if (!empty($_REQUEST['group'])) {
    $row = dbFetchOne('SELECT * FROM Groups WHERE Id = ?', NULL, array($_REQUEST['group']));
    $groupSql = " and find_in_set( Id, '" . $row['MonitorIds'] . "' )";
}
$mid = validInt($_REQUEST['mid']);
$sql = "SELECT * FROM Monitors WHERE Function != 'None' AND Controllable = 1{$groupSql} ORDER BY Sequence";
$mids = array();
foreach (dbFetchAll($sql) as $row) {
    if (!visibleMonitor($row['Id'])) {
        continue;
    }
    if (empty($mid)) {
        $mid = $row['Id'];
    }
    $mids[$row['Id']] = $row['Name'];
}
foreach (getSkinIncludes('includes/control_functions.php') as $includeFile) {
    require_once $includeFile;
}
$sql = 'SELECT C.*,M.* FROM Monitors AS M INNER JOIN Controls AS C ON (M.ControlId = C.Id ) WHERE M.Id = ?';
Example #7
0
<?php

define("MSG_TIMEOUT", 2.0);
define("MSG_DATA_SIZE", 4 + 256);
if (canEdit('Monitors')) {
    $zmuCommand = getZmuCommand(" -m " . validInt($_REQUEST['id']));
    switch (validJsStr($_REQUEST['command'])) {
        case "disableAlarms":
            $zmuCommand .= " -n";
            break;
        case "enableAlarms":
            $zmuCommand .= " -c";
            break;
        case "forceAlarm":
            $zmuCommand .= " -a";
            break;
        case "cancelForcedAlarm":
            $zmuCommand .= " -c";
            break;
        default:
            ajaxError("Unexpected command '" . validJsStr($_REQUEST['command']) . "'");
    }
    ajaxResponse(exec(escapeshellcmd($zmuCommand)));
}
ajaxError('Unrecognised action or insufficient permissions');
Example #8
0
         $monitor_str .= make_tag("name", $monitor['Name']);
         $monitor_str .= make_tag("method", $monitor['Function']);
         $monitor_str .= make_tag("enabled", $monitor['Enabled']);
         $monitor_str .= make_tag("width", $monitor['Width']);
         $monitor_str .= make_tag("height", $monitor['Height']);
         print make_tag("monitor", $monitor_str);
     }
 } else {
     if ($_REQUEST['action'] == "get_connkey") {
         print make_tag("connkey", generateConnKey());
     } else {
         if ($_REQUEST['action'] == "event_stats") {
             if (!canView("Events")) {
                 ajaxError('Unrecognised action or insufficient permissions');
             }
             $eid = validInt($_REQUEST['eid']);
             $stats = dbFetchAll("select S.*,E.*,Z.Name as ZoneName,Z.Units,Z.Area,M.Name as MonitorName,M.Width,M.Height from Stats as S left join Events as E on S.EventId = E.Id left join Zones as Z on S.ZoneId = Z.Id left join Monitors as M on E.MonitorId = M.Id where S.EventId = '" . $eid . "' order by S.FrameId, S.ZoneId");
             for ($i = 0; $i < count($stats); $i++) {
                 $stat = $stats[$i];
                 $stat_str = "";
                 $stat_str .= make_tag("FrameId", $stat["FrameId"]);
                 $stat_str .= make_tag("PixelDiff", $stat["PixelDiff"]);
                 $stat_str .= make_tag("AlarmPixels", $stat["AlarmPixels"]);
                 $stat_str .= make_tag("FilterPixels", $stat["FilterPixels"]);
                 $stat_str .= make_tag("BlobPixels", $stat["BlobPixels"]);
                 $stat_str .= make_tag("Blobs", $stat["Blobs"]);
                 $stat_str .= make_tag("ZoneName", $stat["ZoneName"]);
                 $stat_str .= make_tag("Score", $stat["Score"]);
                 print make_tag("stat", $stat_str);
             }
         }
Example #9
0
function outputVideoStream($id, $src, $width, $height, $format, $title = "")
{
    if (file_exists($src)) {
        $mimeType = getMimeType($src);
    } else {
        switch ($format) {
            case 'asf':
                $mimeType = "video/x-ms-asf";
                break;
            case 'avi':
            case 'wmv':
                $mimeType = "video/x-msvideo";
                break;
            case 'mov':
                $mimeType = "video/quicktime";
                break;
            case 'mpg':
            case 'mpeg':
                $mimeType = "video/mpeg";
                break;
            case 'swf':
                $mimeType = "application/x-shockwave-flash";
                break;
            case '3gp':
                $mimeType = "video/3gpp";
                break;
            default:
                $mimeType = "video/{$format}";
                break;
        }
    }
    if (!$mimeType || $mimeType == 'application/octet-stream') {
        $mimeType = 'video/' . $format;
    }
    $objectTag = false;
    if (ZM_WEB_USE_OBJECT_TAGS) {
        switch ($mimeType) {
            case "video/x-ms-asf":
            case "video/x-msvideo":
            case "video/mp4":
                if (isWindows()) {
                    ?>
<object id="<?php 
                    echo $id;
                    ?>
" width="<?php 
                    echo validNum($width);
                    ?>
" height="<?php 
                    echo validNum($height);
                    ?>
"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"
standby="Loading Microsoft Windows Media Player components..."
type="<?php 
                    echo $mimeType;
                    ?>
">
<param name="FileName" value="<?php 
                    echo $src;
                    ?>
"/>
<param name="autoStart" value="1"/>
<param name="showControls" value="0"/>
<embed type="<?php 
                    echo $mimeType;
                    ?>
"
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src="<?php 
                    echo $src;
                    ?>
"
name="<?php 
                    echo validHtmlStr($title);
                    ?>
"
width="<?php 
                    echo validNum($width);
                    ?>
"
height="<?php 
                    echo validInt($height);
                    ?>
"
autostart="1"
showcontrols="0">
</embed>
</object>
<?php 
                    $objectTag = true;
                }
                break;
            case "video/quicktime":
                ?>
<object id="<?php 
                echo $id;
                ?>
" width="<?php 
                echo $width;
                ?>
" height="<?php 
                echo $height;
                ?>
"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
type="<?php 
                echo $mimeType;
                ?>
">
<param name="src" value="<?php 
                echo $src;
                ?>
"/>
<param name="autoplay" VALUE="true"/>
<param name="controller" VALUE="false"/>
<embed type="<?php 
                echo $mimeType;
                ?>
"
src="<?php 
                echo $src;
                ?>
"
pluginspage="http://www.apple.com/quicktime/download/"
name="<?php 
                echo validHtmlStr($title);
                ?>
"
width="<?php 
                echo validInt($width);
                ?>
"
height="<?php 
                echo validInt($height);
                ?>
"
autoplay="true"
controller="true">
</embed>
</object>
<?php 
                $objectTag = true;
                break;
            case "application/x-shockwave-flash":
                ?>
<object id="<?php 
                echo $id;
                ?>
" width="<?php 
                echo $width;
                ?>
" height="<?php 
                echo $height;
                ?>
"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
type="<?php 
                echo $mimeType;
                ?>
">
<param name="movie" value="<?php 
                echo $src;
                ?>
"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#ffffff"/>
<embed type="<?php 
                echo $mimeType;
                ?>
"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="<?php 
                echo $src;
                ?>
"
name="<?php 
                echo validHtmlStr($title);
                ?>
"
width="<?php 
                echo validInt($width);
                ?>
"
height="<?php 
                echo validInt($height);
                ?>
"
quality="high"
bgcolor="#ffffff">
</embed>
</object>
<?php 
                $objectTag = true;
                break;
        }
    }
    if (!$objectTag) {
        ?>
<embed<?php 
        echo isset($mimeType) ? ' type="' . $mimeType . '"' : "";
        ?>
 
src="<?php 
        echo $src;
        ?>
"
name="<?php 
        echo validHtmlStr($title);
        ?>
"
width="<?php 
        echo validInt($width);
        ?>
"
height="<?php 
        echo validInt($height);
        ?>
"
autostart="1"
autoplay="1"
showcontrols="0"
controller="0">
</embed>
<?php 
    }
}
Example #10
0
//
// 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('Events')) {
    $view = "error";
    return;
}
$eid = validInt($_REQUEST['eid']);
$fid = validInt($_REQUEST['fid']);
$sql = 'SELECT S.*,E.*,Z.Name AS ZoneName,Z.Units,Z.Area,M.Name AS MonitorName,M.Width,M.Height FROM Stats AS S LEFT JOIN Events AS E ON S.EventId = E.Id LEFT JOIN Zones AS Z ON S.ZoneId = Z.Id LEFT JOIN Monitors AS M ON E.MonitorId = M.Id WHERE S.EventId = ? AND S.FrameId = ? ORDER BY S.ZoneId';
$stats = dbFetchAll($sql, NULL, array($eid, $fid));
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Stats') . " - " . $eid . " - " . $fid);
?>
<body>
  <div id="page">
    <div id="header">
      <div id="headerButtons">
        <a href="#" onclick="closeWindow(); return( false );"><?php 
echo translate('Close');
?>
</a>
      </div>
      <h2><?php 
Example #11
0
</h2>
    </div>
    <div id="content">
<?php 
if (isset($_REQUEST['showIndex'])) {
    $showIndex = validInt($_REQUEST['showIndex']);
    preg_match('/([^\\/]+)\\.([^.]+)$/', $videoFiles[$showIndex], $matches);
    $name = $matches[1];
    $videoFormat = $matches[2];
    ?>
      <h3 id="videoFile"><?php 
    echo substr($videoFiles[$showIndex], strlen(ZM_DIR_EVENTS) + 1);
    ?>
</h3>
      <div id="imageFeed"><?php 
    outputVideoStream('videoStream', $videoFiles[$showIndex], validInt($_REQUEST['width']), validInt($_REQUEST['height']), $videoFormat, $name);
    ?>
</div>
<?php 
} else {
    ?>
      <form name="contentForm" id="contentForm" method="post" action="<?php 
    echo $_SERVER['PHP_SELF'];
    ?>
">
        <input type="hidden" name="id" value="<?php 
    echo $event['Id'];
    ?>
"/>
        <table id="contentTable" class="minor" cellspacing="0">
          <tbody>
Example #12
0
echo $_SERVER['PHP_SELF'];
?>
">
<?php 
if (!empty($_REQUEST['eid'])) {
    ?>
        <input type="hidden" name="id" value="<?php 
    echo validInt($_REQUEST['eid']);
    ?>
"/>
<?php 
} elseif (!empty($_REQUEST['eids'])) {
    foreach ($_REQUEST['eids'] as $eid) {
        ?>
        <input type="hidden" name="eids[]" value="<?php 
        echo validInt($eid);
        ?>
"/>
<?php 
    }
    unset($eid);
}
?>
        <table id="contentTable" class="minor" cellspacing="0">
          <tbody>
            <tr>
              <th scope="row"><?php 
echo $SLANG['ExportDetails'];
?>
</th>
              <td><input type="checkbox" name="exportDetail" value="1"<?php 
Example #13
0
if (isset($_REQUEST['eids'])) {
    $eidParms = array();
    foreach ($_REQUEST['eids'] as $eid) {
        $eidParms[] = "eids[]=" . validInt($eid);
    }
    ?>
var eidParm = '<?php 
    echo join('&', $eidParms);
    ?>
';
<?php 
} else {
    ?>
var eidParm = 'eid=<?php 
    echo validInt($_REQUEST['eid']);
    ?>
';
<?php 
}
?>

var exportReady = <?php 
echo !empty($_REQUEST['generated']) ? 'true' : 'false';
?>
;
var exportFile = '<?php 
echo !empty($_REQUEST['exportFile']) ? validJsStr($_REQUEST['exportFile']) : '';
?>
';
function buildControlCommand($monitor)
{
    $ctrlCommand = ZM_PATH_BIN . "/zmcontrol.pl";
    if (isset($_REQUEST['xge']) || isset($_REQUEST['yge'])) {
        $slow = 0.9;
        // Threshold for slow speed/timeouts
        $turbo = 0.9;
        // Threshold for turbo speed
        if (preg_match('/^([a-z]+)([A-Z][a-z]+)([A-Z][a-z]+)+$/', $_REQUEST['control'], $matches)) {
            $command = $matches[1];
            $mode = $matches[2];
            $dirn = $matches[3];
            switch ($command) {
                case 'focus':
                    $factor = $_REQUEST['yge'] / 100;
                    if ($monitor['HasFocusSpeed']) {
                        $speed = intval(round($monitor['MinFocusSpeed'] + ($monitor['MaxFocusSpeed'] - $monitor['MinFocusSpeed']) * $factor));
                        $ctrlCommand .= " --speed=" . $speed;
                    }
                    switch ($mode) {
                        case 'Abs':
                        case 'Rel':
                            $step = intval(round($monitor['MinFocusStep'] + ($monitor['MaxFocusStep'] - $monitor['MinFocusStep']) * $factor));
                            $ctrlCommand .= " --step=" . $step;
                            break;
                        case 'Con':
                            if ($monitor['AutoStopTimeout']) {
                                $slowSpeed = intval(round($monitor['MinFocusSpeed'] + ($monitor['MaxFocusSpeed'] - $monitor['MinFocusSpeed']) * $slow));
                                if ($speed < $slowSpeed) {
                                    $ctrlCommand .= " --autostop";
                                }
                            }
                            break;
                    }
                    break;
                case 'zoom':
                    $factor = $_REQUEST['yge'] / 100;
                    if ($monitor['HasZoomSpeed']) {
                        $speed = intval(round($monitor['MinZoomSpeed'] + ($monitor['MaxZoomSpeed'] - $monitor['MinZoomSpeed']) * $factor));
                        $ctrlCommand .= " --speed=" . $speed;
                    }
                    switch ($mode) {
                        case 'Abs':
                        case 'Rel':
                            $step = intval(round($monitor['MinZoomStep'] + ($monitor['MaxZoomStep'] - $monitor['MinZoomStep']) * $factor));
                            $ctrlCommand .= " --step=" . $step;
                            break;
                        case 'Con':
                            if ($monitor['AutoStopTimeout']) {
                                $slowSpeed = intval(round($monitor['MinZoomSpeed'] + ($monitor['MaxZoomSpeed'] - $monitor['MinZoomSpeed']) * $slow));
                                if ($speed < $slowSpeed) {
                                    $ctrlCommand .= " --autostop";
                                }
                            }
                            break;
                    }
                    break;
                case 'iris':
                    $factor = $_REQUEST['yge'] / 100;
                    if ($monitor['HasIrisSpeed']) {
                        $speed = intval(round($monitor['MinIrisSpeed'] + ($monitor['MaxIrisSpeed'] - $monitor['MinIrisSpeed']) * $factor));
                        $ctrlCommand .= " --speed=" . $speed;
                    }
                    switch ($mode) {
                        case 'Abs':
                        case 'Rel':
                            $step = intval(round($monitor['MinIrisStep'] + ($monitor['MaxIrisStep'] - $monitor['MinIrisStep']) * $factor));
                            $ctrlCommand .= " --step=" . $step;
                            break;
                    }
                    break;
                case 'white':
                    $factor = $_REQUEST['yge'] / 100;
                    if ($monitor['HasWhiteSpeed']) {
                        $speed = intval(round($monitor['MinWhiteSpeed'] + ($monitor['MaxWhiteSpeed'] - $monitor['MinWhiteSpeed']) * $factor));
                        $ctrlCommand .= " --speed=" . $speed;
                    }
                    switch ($mode) {
                        case 'Abs':
                        case 'Rel':
                            $step = intval(round($monitor['MinWhiteStep'] + ($monitor['MaxWhiteStep'] - $monitor['MinWhiteStep']) * $factor));
                            $ctrlCommand .= " --step=" . $step;
                            break;
                    }
                    break;
                case 'gain':
                    $factor = $_REQUEST['yge'] / 100;
                    if ($monitor['HasGainSpeed']) {
                        $speed = intval(round($monitor['MinGainSpeed'] + ($monitor['MaxGainSpeed'] - $monitor['MinGainSpeed']) * $factor));
                        $ctrlCommand .= " --speed=" . $speed;
                    }
                    switch ($mode) {
                        case 'Abs':
                        case 'Rel':
                            $step = intval(round($monitor['MinGainStep'] + ($monitor['MaxGainStep'] - $monitor['MinGainStep']) * $factor));
                            $ctrlCommand .= " --step=" . $step;
                            break;
                    }
                    break;
                case 'move':
                    $xFactor = empty($_REQUEST['xge']) ? 0 : $_REQUEST['xge'] / 100;
                    $yFactor = empty($_REQUEST['yge']) ? 0 : $_REQUEST['yge'] / 100;
                    if ($monitor['Orientation'] != '0') {
                        $conversions = array('90' => array('Up' => 'Left', 'Down' => 'Right', 'Left' => 'Down', 'Right' => 'Up', 'UpLeft' => 'DownLeft', 'UpRight' => 'UpLeft', 'DownLeft' => 'DownRight', 'DownRight' => 'UpRight'), '180' => array('Up' => 'Down', 'Down' => 'Up', 'Left' => 'Right', 'Right' => 'Left', 'UpLeft' => 'DownRight', 'UpRight' => 'DownLeft', 'DownLeft' => 'UpRight', 'DownRight' => 'UpLeft'), '270' => array('Up' => 'Right', 'Down' => 'Left', 'Left' => 'Up', 'Right' => 'Down', 'UpLeft' => 'UpRight', 'UpRight' => 'DownRight', 'DownLeft' => 'UpLeft', 'DownRight' => 'DownLeft'), 'hori' => array('Up' => 'Up', 'Down' => 'Down', 'Left' => 'Right', 'Right' => 'Left', 'UpLeft' => 'UpRight', 'UpRight' => 'UpLeft', 'DownLeft' => 'DownRight', 'DownRight' => 'DownLeft'), 'vert' => array('Up' => 'Down', 'Down' => 'Up', 'Left' => 'Left', 'Right' => 'Right', 'UpLeft' => 'DownLeft', 'UpRight' => 'DownRight', 'DownLeft' => 'UpLeft', 'DownRight' => 'UpRight'));
                        $new_dirn = $conversions[$monitor['Orientation']][$dirn];
                        $_REQUEST['control'] = preg_replace("/_{$dirn}\$/", "_{$new_dirn}", $_REQUEST['control']);
                        $dirn = $new_dirn;
                    }
                    if ($monitor['HasPanSpeed'] && $xFactor) {
                        if ($monitor['HasTurboPan']) {
                            if ($xFactor >= $turbo) {
                                $panSpeed = $monitor['TurboPanSpeed'];
                            } else {
                                $xFactor = $xFactor / $turbo;
                                $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                            }
                        } else {
                            $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                        }
                        $ctrlCommand .= " --panspeed=" . $panSpeed;
                    }
                    if ($monitor['HasTiltSpeed'] && $yFactor) {
                        if ($monitor['HasTurboTilt']) {
                            if ($yFactor >= $turbo) {
                                $tiltSpeed = $monitor['TurboTiltSpeed'];
                            } else {
                                $yFactor = $yFactor / $turbo;
                                $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                            }
                        } else {
                            $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                        }
                        $ctrlCommand .= " --tiltspeed=" . $tiltSpeed;
                    }
                    switch ($mode) {
                        case 'Rel':
                        case 'Abs':
                            if (preg_match('/(Left|Right)$/', $dirn)) {
                                $panStep = intval(round($monitor['MinPanStep'] + ($monitor['MaxPanStep'] - $monitor['MinPanStep']) * $xFactor));
                                $ctrlCommand .= " --panstep=" . $panStep;
                            }
                            if (preg_match('/^(Up|Down)/', $dirn)) {
                                $tiltStep = intval(round($monitor['MinTiltStep'] + ($monitor['MaxTiltStep'] - $monitor['MinTiltStep']) * $yFactor));
                                $ctrlCommand .= " --tiltstep=" . $tiltStep;
                            }
                            break;
                        case 'Con':
                            if ($monitor['AutoStopTimeout']) {
                                $slowPanSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $slow));
                                $slowTiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $slow));
                                if ((!isset($panSpeed) || $panSpeed < $slowPanSpeed) && (!isset($tiltSpeed) || $tiltSpeed < $slowTiltSpeed)) {
                                    $ctrlCommand .= " --autostop";
                                }
                            }
                            break;
                    }
            }
        }
    } elseif (isset($_REQUEST['x']) && isset($_REQUEST['y'])) {
        if ($_REQUEST['control'] == "moveMap") {
            $x = deScale($_REQUEST['x'], $_REQUEST['scale']);
            $y = deScale($_REQUEST['y'], $_REQUEST['scale']);
            switch ($monitor['Orientation']) {
                case '0':
                case '180':
                case 'hori':
                case 'vert':
                    $width = $monitor['Width'];
                    $height = $monitor['Height'];
                    break;
                case '90':
                case '270':
                    $width = $monitor['Height'];
                    $height = $monitor['Width'];
                    break;
            }
            switch ($monitor['Orientation']) {
                case '90':
                    $tempY = $y;
                    $y = $height - $x;
                    $x = $tempY;
                    break;
                case '180':
                    $x = $width - $x;
                    $y = $height - $y;
                    break;
                case '270':
                    $tempX = $x;
                    $x = $width - $y;
                    $y = $tempX;
                    break;
                case 'hori':
                    $x = $width - $x;
                    break;
                case 'vert':
                    $y = $height - $y;
                    break;
            }
            //$ctrlCommand .= " --xcoord=$x --ycoord=$y --width=$width --height=$height";
            $ctrlCommand .= " --xcoord={$x} --ycoord={$y}";
        } elseif ($_REQUEST['control'] == "movePseudoMap") {
            $x = deScale($_REQUEST['x'], $_REQUEST['scale']);
            $y = deScale($_REQUEST['y'], $_REQUEST['scale']);
            $halfWidth = $monitor['Width'] / 2;
            $halfHeight = $monitor['Height'] / 2;
            $xFactor = ($x - $halfWidth) / $halfWidth;
            $yFactor = ($y - $halfHeight) / $halfHeight;
            switch ($monitor['Orientation']) {
                case '90':
                    $tempYFactor = $y;
                    $yFactor = -$xFactor;
                    $xFactor = $tempYFactor;
                    break;
                case '180':
                    $xFactor = -$xFactor;
                    $yFactor = -$yFactor;
                    break;
                case '270':
                    $tempXFactor = $x;
                    $xFactor = -$yFactor;
                    $yFactor = $tempXFactor;
                    break;
                case 'hori':
                    $xFactor = -$xFactor;
                    break;
                case 'vert':
                    $yFactor = -$yFactor;
                    break;
            }
            $turbo = 0.9;
            // Threshold for turbo speed
            $blind = 0.1;
            // Threshold for blind spot
            $panControl = '';
            $tiltControl = '';
            if ($xFactor > $blind) {
                $panControl = 'Right';
            } elseif ($xFactor < -$blind) {
                $panControl = 'Left';
            }
            if ($yFactor > $blind) {
                $tiltControl = 'Down';
            } elseif ($yFactor < -$blind) {
                $tiltControl = 'Up';
            }
            $dirn = $tiltControl . $panControl;
            if (!$dirn) {
                // No command, probably in blind spot in middle
                $_REQUEST['control'] = 'null';
                return false;
            } else {
                $_REQUEST['control'] = 'moveRel' . $dirn;
                $xFactor = abs($xFactor);
                $yFactor = abs($yFactor);
                if ($monitor['HasPanSpeed'] && $xFactor) {
                    if ($monitor['HasTurboPan']) {
                        if ($xFactor >= $turbo) {
                            $panSpeed = $monitor['TurboPanSpeed'];
                        } else {
                            $xFactor = $xFactor / $turbo;
                            $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                        }
                    } else {
                        $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                    }
                }
                if ($monitor['HasTiltSpeed'] && $yFactor) {
                    if ($monitor['HasTurboTilt']) {
                        if ($yFactor >= $turbo) {
                            $tiltSpeed = $monitor['TurboTiltSpeed'];
                        } else {
                            $yFactor = $yFactor / $turbo;
                            $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                        }
                    } else {
                        $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                    }
                }
                if (preg_match('/(Left|Right)$/', $dirn)) {
                    $panStep = intval(round($monitor['MinPanStep'] + ($monitor['MaxPanStep'] - $monitor['MinPanStep']) * $xFactor));
                    $ctrlCommand .= " --panstep=" . $panStep . " --panspeed=" . $panSpeed;
                }
                if (preg_match('/^(Up|Down)/', $dirn)) {
                    $tiltStep = intval(round($monitor['MinTiltStep'] + ($monitor['MaxTiltStep'] - $monitor['MinTiltStep']) * $yFactor));
                    $ctrlCommand .= " --tiltstep=" . $tiltStep . " --tiltspeed=" . $tiltSpeed;
                }
            }
        } elseif ($_REQUEST['control'] == "moveConMap") {
            $x = deScale($_REQUEST['x'], $_REQUEST['scale']);
            $y = deScale($_REQUEST['y'], $_REQUEST['scale']);
            $halfWidth = $monitor['Width'] / 2;
            $halfHeight = $monitor['Height'] / 2;
            $xFactor = ($x - $halfWidth) / $halfWidth;
            $yFactor = ($y - $halfHeight) / $halfHeight;
            switch ($monitor['Orientation']) {
                case '90':
                    $tempYFactor = $y;
                    $yFactor = -$xFactor;
                    $xFactor = $tempYFactor;
                    break;
                case '180':
                    $xFactor = -$xFactor;
                    $yFactor = -$yFactor;
                    break;
                case '270':
                    $tempXFactor = $x;
                    $xFactor = -$yFactor;
                    $yFactor = $tempXFactor;
                    break;
                case 'hori':
                    $xFactor = -$xFactor;
                    break;
                case 'vert':
                    $yFactor = -$yFactor;
                    break;
            }
            $slow = 0.9;
            // Threshold for slow speed/timeouts
            $turbo = 0.9;
            // Threshold for turbo speed
            $blind = 0.1;
            // Threshold for blind spot
            $panControl = '';
            $tiltControl = '';
            if ($xFactor > $blind) {
                $panControl = 'Right';
            } elseif ($xFactor < -$blind) {
                $panControl = 'Left';
            }
            if ($yFactor > $blind) {
                $tiltControl = 'Down';
            } elseif ($yFactor < -$blind) {
                $tiltControl = 'Up';
            }
            $dirn = $tiltControl . $panControl;
            if (!$dirn) {
                // No command, probably in blind spot in middle
                $_REQUEST['control'] = 'moveStop';
            } else {
                $_REQUEST['control'] = 'moveCon' . $dirn;
                $xFactor = abs($xFactor);
                $yFactor = abs($yFactor);
                if ($monitor['HasPanSpeed'] && $xFactor) {
                    if ($monitor['HasTurboPan']) {
                        if ($xFactor >= $turbo) {
                            $panSpeed = $monitor['TurboPanSpeed'];
                        } else {
                            $xFactor = $xFactor / $turbo;
                            $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                        }
                    } else {
                        $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                    }
                }
                if ($monitor['HasTiltSpeed'] && $yFactor) {
                    if ($monitor['HasTurboTilt']) {
                        if ($yFactor >= $turbo) {
                            $tiltSpeed = $monitor['TurboTiltSpeed'];
                        } else {
                            $yFactor = $yFactor / $turbo;
                            $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                        }
                    } else {
                        $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                    }
                }
                if (preg_match('/(Left|Right)$/', $dirn)) {
                    $ctrlCommand .= " --panspeed=" . $panSpeed;
                }
                if (preg_match('/^(Up|Down)/', $dirn)) {
                    $ctrlCommand .= " --tiltspeed=" . $tiltSpeed;
                }
                if ($monitor['AutoStopTimeout']) {
                    $slowPanSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $slow));
                    $slowTiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $slow));
                    if ((!isset($panSpeed) || $panSpeed < $slowPanSpeed) && (!isset($tiltSpeed) || $tiltSpeed < $slowTiltSpeed)) {
                        $ctrlCommand .= " --autostop";
                    }
                }
            }
        } else {
            $slow = 0.9;
            // Threshold for slow speed/timeouts
            $turbo = 0.9;
            // Threshold for turbo speed
            $long_y = 48;
            $short_x = 32;
            $short_y = 32;
            if (preg_match('/^([a-z]+)([A-Z][a-z]+)([A-Z][a-z]+)$/', $_REQUEST['control'], $matches)) {
                $command = $matches[1];
                $mode = $matches[2];
                $dirn = $matches[3];
                switch ($command) {
                    case 'focus':
                        switch ($dirn) {
                            case 'Near':
                                $factor = ($long_y - ($y + 1)) / $long_y;
                                break;
                            case 'Far':
                                $factor = ($y + 1) / $long_y;
                                break;
                        }
                        if ($monitor['HasFocusSpeed']) {
                            $speed = intval(round($monitor['MinFocusSpeed'] + ($monitor['MaxFocusSpeed'] - $monitor['MinFocusSpeed']) * $factor));
                            $ctrlCommand .= " --speed=" . $speed;
                        }
                        switch ($mode) {
                            case 'Abs':
                            case 'Rel':
                                $step = intval(round($monitor['MinFocusStep'] + ($monitor['MaxFocusStep'] - $monitor['MinFocusStep']) * $factor));
                                $ctrlCommand .= " --step=" . $step;
                                break;
                            case 'Con':
                                if ($monitor['AutoStopTimeout']) {
                                    $slowSpeed = intval(round($monitor['MinFocusSpeed'] + ($monitor['MaxFocusSpeed'] - $monitor['MinFocusSpeed']) * $slow));
                                    if ($speed < $slowSpeed) {
                                        $ctrlCommand .= " --autostop";
                                    }
                                }
                                break;
                        }
                        break;
                    case 'zoom':
                        switch ($dirn) {
                            case 'Tele':
                                $factor = ($long_y - ($y + 1)) / $long_y;
                                break;
                            case 'Wide':
                                $factor = ($y + 1) / $long_y;
                                break;
                        }
                        if ($monitor['HasZoomSpeed']) {
                            $speed = intval(round($monitor['MinZoomSpeed'] + ($monitor['MaxZoomSpeed'] - $monitor['MinZoomSpeed']) * $factor));
                            $ctrlCommand .= " --speed=" . $speed;
                        }
                        switch ($mode) {
                            case 'Abs':
                            case 'Rel':
                                $step = intval(round($monitor['MinZoomStep'] + ($monitor['MaxZoomStep'] - $monitor['MinZoomStep']) * $factor));
                                $ctrlCommand .= " --step=" . $step;
                                break;
                            case 'Con':
                                if ($monitor['AutoStopTimeout']) {
                                    $slowSpeed = intval(round($monitor['MinZoomSpeed'] + ($monitor['MaxZoomSpeed'] - $monitor['MinZoomSpeed']) * $slow));
                                    if ($speed < $slowSpeed) {
                                        $ctrlCommand .= " --autostop";
                                    }
                                }
                                break;
                        }
                        break;
                    case 'iris':
                        switch ($dirn) {
                            case 'Open':
                                $factor = ($long_y - ($y + 1)) / $long_y;
                                break;
                            case 'Close':
                                $factor = ($y + 1) / $long_y;
                                break;
                        }
                        if ($monitor['HasIrisSpeed']) {
                            $speed = intval(round($monitor['MinIrisSpeed'] + ($monitor['MaxIrisSpeed'] - $monitor['MinIrisSpeed']) * $factor));
                            $ctrlCommand .= " --speed=" . $speed;
                        }
                        switch ($mode) {
                            case 'Abs':
                            case 'Rel':
                                $step = intval(round($monitor['MinIrisStep'] + ($monitor['MaxIrisStep'] - $monitor['MinIrisStep']) * $factor));
                                $ctrlCommand .= " --step=" . $step;
                                break;
                        }
                        break;
                    case 'white':
                        switch ($dirn) {
                            case 'In':
                                $factor = ($long_y - ($y + 1)) / $long_y;
                                break;
                            case 'Out':
                                $factor = ($y + 1) / $long_y;
                                break;
                        }
                        if ($monitor['HasWhiteSpeed']) {
                            $speed = intval(round($monitor['MinWhiteSpeed'] + ($monitor['MaxWhiteSpeed'] - $monitor['MinWhiteSpeed']) * $factor));
                            $ctrlCommand .= " --speed=" . $speed;
                        }
                        switch ($mode) {
                            case 'Abs':
                            case 'Rel':
                                $step = intval(round($monitor['MinWhiteStep'] + ($monitor['MaxWhiteStep'] - $monitor['MinWhiteStep']) * $factor));
                                $ctrlCommand .= " --step=" . $step;
                                break;
                        }
                        break;
                    case 'gain':
                        switch ($dirn) {
                            case 'Up':
                                $factor = ($long_y - ($y + 1)) / $long_y;
                                break;
                            case 'Down':
                                $factor = ($y + 1) / $long_y;
                                break;
                        }
                        if ($monitor['HasGainSpeed']) {
                            $speed = intval(round($monitor['MinGainSpeed'] + ($monitor['MaxGainSpeed'] - $monitor['MinGainSpeed']) * $factor));
                            $ctrlCommand .= " --speed=" . $speed;
                        }
                        switch ($mode) {
                            case 'Abs':
                            case 'Rel':
                                $step = intval(round($monitor['MinGainStep'] + ($monitor['MaxGainStep'] - $monitor['MinGainStep']) * $factor));
                                $ctrlCommand .= " --step=" . $step;
                                break;
                        }
                        break;
                    case 'move':
                        $xFactor = 0;
                        $yFactor = 0;
                        if (preg_match('/^Up/', $dirn)) {
                            $yFactor = ($short_y - ($y + 1)) / $short_y;
                        } elseif (preg_match('/^Down/', $dirn)) {
                            $yFactor = ($y + 1) / $short_y;
                        }
                        if (preg_match('/Left$/', $dirn)) {
                            $xFactor = ($short_x - ($x + 1)) / $short_x;
                        } elseif (preg_match('/Right$/', $dirn)) {
                            $xFactor = ($x + 1) / $short_x;
                        }
                        if ($monitor['Orientation'] != '0') {
                            $conversions = array('90' => array('Up' => 'Left', 'Down' => 'Right', 'Left' => 'Down', 'Right' => 'Up', 'UpLeft' => 'DownLeft', 'UpRight' => 'UpLeft', 'DownLeft' => 'DownRight', 'DownRight' => 'UpRight'), '180' => array('Up' => 'Down', 'Down' => 'Up', 'Left' => 'Right', 'Right' => 'Left', 'UpLeft' => 'DownRight', 'UpRight' => 'DownLeft', 'DownLeft' => 'UpRight', 'DownRight' => 'UpLeft'), '270' => array('Up' => 'Right', 'Down' => 'Left', 'Left' => 'Up', 'Right' => 'Down', 'UpLeft' => 'UpRight', 'UpRight' => 'DownRight', 'DownLeft' => 'UpLeft', 'DownRight' => 'DownLeft'), 'hori' => array('Up' => 'Up', 'Down' => 'Down', 'Left' => 'Right', 'Right' => 'Left', 'UpLeft' => 'UpRight', 'UpRight' => 'UpLeft', 'DownLeft' => 'DownRight', 'DownRight' => 'DownLeft'), 'vert' => array('Up' => 'Down', 'Down' => 'Up', 'Left' => 'Left', 'Right' => 'Right', 'UpLeft' => 'DownLeft', 'UpRight' => 'DownRight', 'DownLeft' => 'UpLeft', 'DownRight' => 'UpRight'));
                            $new_dirn = $conversions[$monitor['Orientation']][$dirn];
                            $_REQUEST['control'] = preg_replace("/_{$dirn}\$/", "_{$new_dirn}", $_REQUEST['control']);
                            $dirn = $new_dirn;
                        }
                        if ($monitor['HasPanSpeed'] && $xFactor) {
                            if ($monitor['HasTurboPan']) {
                                if ($xFactor >= $turbo) {
                                    $panSpeed = $monitor['TurboPanSpeed'];
                                } else {
                                    $xFactor = $xFactor / $turbo;
                                    $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                                }
                            } else {
                                $panSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $xFactor));
                            }
                            $ctrlCommand .= " --panspeed=" . $panSpeed;
                        }
                        if ($monitor['HasTiltSpeed'] && $yFactor) {
                            if ($monitor['HasTurboTilt']) {
                                if ($yFactor >= $turbo) {
                                    $tiltSpeed = $monitor['TurboTiltSpeed'];
                                } else {
                                    $yFactor = $yFactor / $turbo;
                                    $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                                }
                            } else {
                                $tiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $yFactor));
                            }
                            $ctrlCommand .= " --tiltspeed=" . $tiltSpeed;
                        }
                        switch ($mode) {
                            case 'Rel':
                            case 'Abs':
                                if (preg_match('/(Left|Right)$/', $dirn)) {
                                    $panStep = intval(round($monitor['MinPanStep'] + ($monitor['MaxPanStep'] - $monitor['MinPanStep']) * $xFactor));
                                    $ctrlCommand .= " --panstep=" . $panStep;
                                }
                                if (preg_match('/^(Up|Down)/', $dirn)) {
                                    $tiltStep = intval(round($monitor['MinTiltStep'] + ($monitor['MaxTiltStep'] - $monitor['MinTiltStep']) * $yFactor));
                                    $ctrlCommand .= " --tiltstep=" . $tiltStep;
                                }
                                break;
                            case 'Con':
                                if ($monitor['AutoStopTimeout']) {
                                    $slowPanSpeed = intval(round($monitor['MinPanSpeed'] + ($monitor['MaxPanSpeed'] - $monitor['MinPanSpeed']) * $slow));
                                    $slowTiltSpeed = intval(round($monitor['MinTiltSpeed'] + ($monitor['MaxTiltSpeed'] - $monitor['MinTiltSpeed']) * $slow));
                                    if ((!isset($panSpeed) || $panSpeed < $slowPanSpeed) && (!isset($tiltSpeed) || $tiltSpeed < $slowTiltSpeed)) {
                                        $ctrlCommand .= " --autostop";
                                    }
                                }
                                break;
                        }
                }
            }
        }
    } else {
        if (preg_match('/^presetGoto(\\d+)$/', $_REQUEST['control'], $matches)) {
            $_REQUEST['control'] = 'presetGoto';
            $ctrlCommand .= " --preset=" . $matches[1];
        } elseif ($_REQUEST['control'] == "presetGoto" && !empty($_REQUEST['preset'])) {
            $ctrlCommand .= " --preset=" . $_REQUEST['preset'];
        } elseif ($_REQUEST['control'] == "presetSet") {
            if (canEdit('Control')) {
                $preset = validInt($_REQUEST['preset']);
                $newLabel = validJsStr($_REQUEST['newLabel']);
                $row = dbFetchOne('SELECT * FROM ControlPresets WHERE MonitorId = ? AND Preset = ?', NULL, array($monitor['Id'], $preset));
                if ($newLabel != $row['Label']) {
                    if ($newLabel) {
                        dbQuery('REPLACE INTO ControlPresets ( MonitorId, Preset, Label ) VALUES ( ?, ?, ? )', array($monitor['Id'], $preset, $newLabel));
                    } else {
                        dbQuery('DELETE FROM ControlPresets WHERE MonitorId = ? AND Preset = ?', array($monitor['Id'], $preset));
                    }
                }
                $ctrlCommand .= " --preset=" . $preset;
            }
            $ctrlCommand .= " --preset=" . $preset;
        } elseif ($_REQUEST['control'] == "moveMap") {
            $ctrlCommand .= " --xcoord={$x} --ycoord={$y}";
        }
    }
    $ctrlCommand .= " --command=" . $_REQUEST['control'];
    return $ctrlCommand;
}
Example #15
0
$unarchived = false;
foreach (dbFetchAll($sql) as $sqlData) {
    $eventdata[$sqlData['Id']] = $sqlData;
    if ($sqlData['Archived']) {
        $archived = true;
    } else {
        $unarchived = true;
    }
}
$eventlist = implode(',', array_keys($eventdata));
if (isset($_POST['eid']) && isset($eventdata[$_POST['eid']])) {
    $currentevent = $eventdata[$_POST['eid']];
}
$event = !empty($currentevent) ? $currentevent : current($eventdata);
$rate = isset($_POST['rate']) ? validInt($_POST['rate']) : reScale(RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE);
$scale = isset($_POST['scale']) ? validInt($_POST['scale']) : reScale(SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE);
/*
$replayModes = array(
    'single' => $SLANG['ReplaySingle'],
    'all' => $SLANG['ReplayAll'],
    'gapless' => $SLANG['ReplayGapless'],
);
$replayMode = isset( $_POST['replayMode']) ? validHtmlStr($_POST['replayMode']) : array_shift( array_keys( $replayModes ) );
*/
$replayMode = !empty($currentevent) ? 'single' : 'gapless';
$streamMode = isset($_POST['streamMode']) ? validHtmlStr($_POST['streamMode']) : (canStream() ? 'stream' : 'stills');
$panelSections = 40;
$panelSectionWidth = (int) ceil(reScale($event['Width'], $scale) / $panelSections);
$panelWidth = $panelSections * $panelSectionWidth - 1;
$connkey = generateConnKey();
?>
Example #16
0
function collectData()
{
    global $statusData;
    if (isset($_REQUEST['MainFrameID']) && $_REQUEST['MainFrameID'] == "1") {
        $statusData["event"]["elements"]["MainFrameID"] = array("sql" => "(select FrameID from Frames where EventId=Events.id order by Score desc,FrameId limit 1)");
        $statusData["events"]["elements"]["MainFrameID"] = array("sql" => "(select FrameID from Frames where EventId=Events.id order by Score desc,FrameId limit 1)");
    }
    $entitySpec =& $statusData[strtolower(validJsStr($_REQUEST['entity']))];
    #print_r( $entitySpec );
    if (!canView($entitySpec['permission'])) {
        ajaxError('Unrecognised action or insufficient permissions');
    }
    if (!empty($entitySpec['func'])) {
        $data = eval("return( " . $entitySpec['func'] . " );");
    } else {
        $data = array();
        $postFuncs = array();
        $fieldSql = array();
        $joinSql = array();
        $groupSql = array();
        $elements =& $entitySpec['elements'];
        $lc_elements = array_change_key_case($elements);
        $id = false;
        if (isset($_REQUEST['id'])) {
            if (!is_array($_REQUEST['id'])) {
                $id = array(validJsStr($_REQUEST['id']));
            } else {
                $id = array_values($_REQUEST['id']);
            }
        }
        if (!isset($_REQUEST['element'])) {
            $_REQUEST['element'] = array_keys($elements);
        } else {
            if (!is_array($_REQUEST['element'])) {
                $_REQUEST['element'] = array(validJsStr($_REQUEST['element']));
            }
        }
        if (isset($entitySpec['selector'])) {
            if (!is_array($entitySpec['selector'])) {
                $entitySpec['selector'] = array($entitySpec['selector']);
            }
            foreach ($entitySpec['selector'] as $selector) {
                if (is_array($selector) && isset($selector['table']) && isset($selector['join'])) {
                    $joinSql[] = "left join " . $selector['table'] . " on " . $selector['join'];
                }
            }
        }
        foreach ($_REQUEST['element'] as $element) {
            if (!($elementData = $lc_elements[strtolower($element)])) {
                ajaxError("Bad " . validJsStr($_REQUEST['entity']) . " element " . $element);
            }
            if (isset($elementData['func'])) {
                $data[$element] = eval("return( " . $elementData['func'] . " );");
            } else {
                if (isset($elementData['postFunc'])) {
                    $postFuncs[$element] = $elementData['postFunc'];
                } else {
                    if (isset($elementData['zmu'])) {
                        $data[$element] = exec(escapeshellcmd(getZmuCommand(" " . $elementData['zmu'])));
                    } else {
                        if (isset($elementData['sql'])) {
                            $fieldSql[] = $elementData['sql'] . " as " . $element;
                        } else {
                            $fieldSql[] = $element;
                        }
                        if (isset($elementData['table']) && isset($elementData['join'])) {
                            $joinSql[] = "left join " . $elementData['table'] . " on " . $elementData['join'];
                        }
                        if (isset($elementData['group'])) {
                            $groupSql[] = $elementData['group'];
                        }
                    }
                }
            }
        }
        if (count($fieldSql)) {
            $sql = "select " . join(", ", $fieldSql) . " from " . $entitySpec['table'];
            if ($joinSql) {
                $sql .= " " . join(" ", array_unique($joinSql));
            }
            if ($id && !empty($entitySpec['selector'])) {
                $index = 0;
                $where = array();
                $values = array();
                foreach ($entitySpec['selector'] as $selector) {
                    if (is_array($selector)) {
                        $where[] = $selector['selector'] . ' = ?';
                        $values[] = validInt($id[$index]);
                    } else {
                        $where[] = $selector . ' = ?';
                        $values[] = validInt($id[$index]);
                    }
                    $index++;
                }
                $sql .= " where " . join(" and ", $where);
            }
            if ($groupSql) {
                $sql .= " group by " . join(",", array_unique($groupSql));
            }
            if (!empty($_REQUEST['sort'])) {
                $arr = explode(' ', $_REQUEST['sort']);
                $col = validCol($arr[0]);
                $dir = "";
                if (count($arr) == 2) {
                    if ($arr[1] == "desc") {
                        $dir = $arr[1];
                    }
                }
                $sql .= " order by {$col} {$dir}";
            }
            if (!empty($entitySpec['limit'])) {
                $limit = $entitySpec['limit'];
            } elseif (!empty($_REQUEST['count'])) {
                $limit = validInt($_REQUEST['count']);
            }
            $limit_offset = "";
            if (!empty($_REQUEST['offset'])) {
                $limit_offset = validInt($_REQUEST['offset']) . ", ";
            }
            if (!empty($limit)) {
                $sql .= " limit " . $limit_offset . $limit;
            }
            if (isset($limit) && $limit == 1) {
                if ($sqlData = dbFetchOne($sql, NULL, $values)) {
                    foreach ($postFuncs as $element => $func) {
                        $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );');
                    }
                    $data = array_merge($data, $sqlData);
                }
            } else {
                $count = 0;
                foreach (dbFetchAll($sql, NULL, $values) as $sqlData) {
                    foreach ($postFuncs as $element => $func) {
                        $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );');
                    }
                    $data[] = $sqlData;
                    if (isset($limi) && ++$count >= $limit) {
                        break;
                    }
                }
            }
        }
    }
    #print_r( $data );
    return $data;
}
Example #17
0
if (!empty($fid)) {
    $sql = 'SELECT * FROM Frames WHERE EventId = ? AND FrameId = ?';
    if (!($frame = dbFetchOne($sql, NULL, array($eid, $fid)))) {
        $frame = array('FrameId' => $fid, 'Type' => 'Normal', 'Score' => 0);
    }
} else {
    $frame = dbFetchOne('SELECT * FROM Frames WHERE EventId = ? AND Score = ?', NULL, array($eid, $event['MaxScore']));
}
$maxFid = $event['Frames'];
$firstFid = 1;
$prevFid = $frame['FrameId'] - 1;
$nextFid = $frame['FrameId'] + 1;
$lastFid = $maxFid;
$alarmFrame = $frame['Type'] == 'Alarm';
if (isset($_REQUEST['scale'])) {
    $scale = validInt($_REQUEST['scale']);
} else {
    $scale = max(reScale(SCALE_BASE, $event['DefaultScale'], ZM_WEB_DEFAULT_SCALE), SCALE_BASE);
}
$imageData = getImageSrc($event, $frame, $scale, isset($_REQUEST['show']) && $_REQUEST['show'] == "capt");
$imagePath = $imageData['thumbPath'];
$eventPath = $imageData['eventPath'];
$dImagePath = sprintf("%s/%0" . ZM_EVENT_IMAGE_DIGITS . "d-diag-d.jpg", $eventPath, $frame['FrameId']);
$rImagePath = sprintf("%s/%0" . ZM_EVENT_IMAGE_DIGITS . "d-diag-r.jpg", $eventPath, $frame['FrameId']);
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Frame') . " - " . $event['Id'] . " - " . $frame['FrameId']);
?>
<body>
  <div id="page">
    <div id="header">
      <div id="headerButtons">
var labels = new Array();
<?php 
foreach ($labels as $index => $label) {
    ?>
labels[<?php 
    echo validInt($index);
    ?>
] = "<?php 
    echo validJsStr($label);
    ?>
";
<?php 
}
Example #19
0
}
parseSort();
parseFilter($_REQUEST['filter']);
$filterQuery = $_REQUEST['filter']['query'];
if ($_REQUEST['filter']['sql']) {
    $countSql .= $_REQUEST['filter']['sql'];
    $eventsSql .= $_REQUEST['filter']['sql'];
}
$eventsSql .= " ORDER BY {$sortColumn} {$sortOrder}";
if (isset($_REQUEST['page'])) {
    $page = validInt($_REQUEST['page']);
} else {
    $page = 0;
}
if (isset($_REQUEST['limit'])) {
    $limit = validInt($_REQUEST['limit']);
} else {
    $limit = 0;
}
$nEvents = dbFetchOne($countSql, 'EventCount');
if (!empty($limit) && $nEvents > $limit) {
    $nEvents = $limit;
}
$pages = (int) ceil($nEvents / ZM_WEB_EVENTS_PER_PAGE);
if ($pages > 1) {
    if (!empty($page)) {
        if ($page < 0) {
            $page = 1;
        }
        if ($page > $pages) {
            $page = $pages;
Example #20
0
//
// 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('Monitors')) {
    $view = "error";
    return;
}
$mid = validInt($_REQUEST['mid']);
$zid = !empty($_REQUEST['zid']) ? validInt($_REQUEST['zid']) : 0;
if ($zid > 0) {
    $newZone = dbFetchOne('SELECT * FROM Zones WHERE MonitorId = ? AND Id = ?', NULL, array($mid, $zid));
} else {
    $view = "error";
    return;
}
$monitor = dbFetchMonitor($mid);
$plugin = $_REQUEST['pl'];
$plugin_path = dirname(ZM_PLUGINS_CONFIG_PATH) . "/" . $plugin;
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Plugin'));
$pluginOptions = array('Enabled' => array('Type' => 'select', 'Name' => 'Enabled', 'Choices' => 'yes,no', 'Value' => 'no'));
$optionNames = array();
if (file_exists($plugin_path . "/config.php")) {
    include_once $plugin_path . "/config.php";