Upgrade monitor saving and viewing

pull/2725/head
Isaac Connor 2019-09-19 14:56:16 -04:00
parent 73a5a8c8c5
commit b9b52c964e
4 changed files with 217 additions and 239 deletions

View File

@ -28,17 +28,26 @@ if ( $action == 'monitor' ) {
$mid = 0;
if ( !empty($_REQUEST['mid']) ) {
$mid = validInt($_REQUEST['mid']);
#if ( ZM_OPT_X10 ) {
#$x10Monitor = dbFetchOne('SELECT * FROM TriggersX10 WHERE MonitorId=?', NULL, array($mid));
#if ( !$x10Monitor )
#$x10Monitor = array();
#}
#} else {
if ( ZM_OPT_X10 ) {
$x10Monitor = dbFetchOne('SELECT * FROM TriggersX10 WHERE MonitorId=?', NULL, array($mid));
if ( !$x10Monitor )
$x10Monitor = array();
}
if ( !canEdit('Monitors',$mid) ) {
ZM\Warning('You do not have permission to edit this monitor');
return;
}
} else {
#$monitor = array();
#if ( ZM_OPT_X10 ) {
#$x10Monitor = array();
#}
if ( ZM_OPT_X10 ) {
$x10Monitor = array();
}
if ( $user['MonitorIds'] ) {
ZM\Warning('You are restricted to certain monitors so cannot add a new one.');
return;
}
}
$monitor = new ZM\Monitor($mid);
// Define a field type for anything that's not simple text equivalent
@ -47,11 +56,12 @@ if ( $action == 'monitor' ) {
'Controllable' => 'toggle',
'TrackMotion' => 'toggle',
'Enabled' => 'toggle',
'DoNativeMotDet' => 'toggle',
'Exif' => 'toggle',
'RTSPDescribe' => 'toggle',
'RecordAudio' => 'toggle',
'Method' => 'raw',
'GroupIds' => 'array',
'LinkedMonitors' => 'set'
);
if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) {
@ -64,9 +74,8 @@ if ( $action == 'monitor' ) {
}
}
$changes = $monitor->changes($_REQUEST['newMonitor']);
ZM\Logger::Debug("Changes:". print_r($changes,true));
#ZM\Logger::Debug("newMonitor:". print_r($_REQUEST['newMonitor'],true));
$changes = $monitor->changes($_REQUEST['newMonitor'], $types);
$restart = false;
if ( count($changes) ) {
if ( $mid ) {
@ -76,73 +85,75 @@ ZM\Logger::Debug("Changes:". print_r($changes,true));
$monitor->zmaControl('stop');
$monitor->zmcControl('stop');
}
$monitor->save($changes);
if ( $monitor->save($changes) ) {
// Groups will be added below
if ( isset($changes['Name']) or isset($changes['StorageId']) ) {
// creating symlinks when symlink already exists reports errors, but is perfectly ok
error_reporting(0);
// Groups will be added below
if ( isset($changes['Name']) or isset($changes['StorageId']) ) {
// creating symlinks when symlink already exists reports errors, but is perfectly ok
error_reporting(0);
$OldStorage = $monitor->StorageId();
$saferOldName = basename($monitor->Name());
if ( file_exists($OldStorage->Path().'/'.$saferOldName) )
unlink($OldStorage->Path().'/'.$saferOldName);
$OldStorage = $monitor->StorageId();
$saferOldName = basename($monitor->Name());
if ( file_exists($OldStorage->Path().'/'.$saferOldName) )
unlink($OldStorage->Path().'/'.$saferOldName);
$NewStorage = new ZM\Storage($_REQUEST['newMonitor']['StorageId']);
if ( !file_exists($NewStorage->Path().'/'.$mid) ) {
if ( !mkdir($NewStorage->Path().'/'.$mid, 0755) ) {
ZM\Error('Unable to mkdir ' . $NewStorage->Path().'/'.$mid);
$NewStorage = new ZM\Storage($_REQUEST['newMonitor']['StorageId']);
if ( !file_exists($NewStorage->Path().'/'.$mid) ) {
if ( !mkdir($NewStorage->Path().'/'.$mid, 0755) ) {
ZM\Error('Unable to mkdir ' . $NewStorage->Path().'/'.$mid);
}
}
}
$saferNewName = basename($_REQUEST['newMonitor']['Name']);
$link_path = $NewStorage->Path().'/'.$saferNewName;
if ( !symlink($NewStorage->Path().'/'.$mid, $link_path) ) {
if ( ! ( file_exists($link_path) and is_link($link_path) ) ) {
ZM\Warning('Unable to symlink ' . $NewStorage->Path().'/'.$mid . ' to ' . $NewStorage->Path().'/'.$saferNewName);
}
}
}
if ( isset($changes['Width']) || isset($changes['Height']) ) {
$newW = $_REQUEST['newMonitor']['Width'];
$newH = $_REQUEST['newMonitor']['Height'];
$newA = $newW * $newH;
$oldW = $monitor['Width'];
$oldH = $monitor['Height'];
$oldA = $oldW * $oldH;
$zones = dbFetchAll('SELECT * FROM Zones WHERE MonitorId=?', NULL, array($mid));
foreach ( $zones as $zone ) {
$newZone = $zone;
$points = coordsToPoints($zone['Coords']);
for ( $i = 0; $i < count($points); $i++ ) {
$points[$i]['x'] = intval(($points[$i]['x']*($newW-1))/($oldW-1));
$points[$i]['y'] = intval(($points[$i]['y']*($newH-1))/($oldH-1));
$saferNewName = basename($_REQUEST['newMonitor']['Name']);
$link_path = $NewStorage->Path().'/'.$saferNewName;
if ( !symlink($NewStorage->Path().'/'.$mid, $link_path) ) {
if ( ! ( file_exists($link_path) and is_link($link_path) ) ) {
ZM\Warning('Unable to symlink ' . $NewStorage->Path().'/'.$mid . ' to ' . $NewStorage->Path().'/'.$saferNewName);
}
}
$newZone['Coords'] = pointsToCoords($points);
$newZone['Area'] = intval(round(($zone['Area']*$newA)/$oldA));
$newZone['MinAlarmPixels'] = intval(round(($newZone['MinAlarmPixels']*$newA)/$oldA));
$newZone['MaxAlarmPixels'] = intval(round(($newZone['MaxAlarmPixels']*$newA)/$oldA));
$newZone['MinFilterPixels'] = intval(round(($newZone['MinFilterPixels']*$newA)/$oldA));
$newZone['MaxFilterPixels'] = intval(round(($newZone['MaxFilterPixels']*$newA)/$oldA));
$newZone['MinBlobPixels'] = intval(round(($newZone['MinBlobPixels']*$newA)/$oldA));
$newZone['MaxBlobPixels'] = intval(round(($newZone['MaxBlobPixels']*$newA)/$oldA));
} // end if Name or Storage Area Change
$changes = getFormChanges($zone, $newZone, $types);
if ( isset($changes['Width']) || isset($changes['Height']) ) {
$newW = $_REQUEST['newMonitor']['Width'];
$newH = $_REQUEST['newMonitor']['Height'];
$newA = $newW * $newH;
$oldW = $monitor['Width'];
$oldH = $monitor['Height'];
$oldA = $oldW * $oldH;
if ( count($changes) ) {
dbQuery('UPDATE Zones SET '.implode(', ', $changes).' WHERE MonitorId=? AND Id=?',
array($mid, $zone['Id']));
}
} // end foreach zone
} // end if width and height
$zones = dbFetchAll('SELECT * FROM Zones WHERE MonitorId=?', NULL, array($mid));
foreach ( $zones as $zone ) {
$newZone = $zone;
$points = coordsToPoints($zone['Coords']);
for ( $i = 0; $i < count($points); $i++ ) {
$points[$i]['x'] = intval(($points[$i]['x']*($newW-1))/($oldW-1));
$points[$i]['y'] = intval(($points[$i]['y']*($newH-1))/($oldH-1));
}
$newZone['Coords'] = pointsToCoords($points);
$newZone['Area'] = intval(round(($zone['Area']*$newA)/$oldA));
$newZone['MinAlarmPixels'] = intval(round(($newZone['MinAlarmPixels']*$newA)/$oldA));
$newZone['MaxAlarmPixels'] = intval(round(($newZone['MaxAlarmPixels']*$newA)/$oldA));
$newZone['MinFilterPixels'] = intval(round(($newZone['MinFilterPixels']*$newA)/$oldA));
$newZone['MaxFilterPixels'] = intval(round(($newZone['MaxFilterPixels']*$newA)/$oldA));
$newZone['MinBlobPixels'] = intval(round(($newZone['MinBlobPixels']*$newA)/$oldA));
$newZone['MaxBlobPixels'] = intval(round(($newZone['MaxBlobPixels']*$newA)/$oldA));
$changes = getFormChanges($zone, $newZone, $types);
if ( count($changes) ) {
dbQuery('UPDATE Zones SET '.implode(', ', $changes).' WHERE MonitorId=? AND Id=?',
array($mid, $zone['Id']));
}
} // end foreach zone
} // end if width and height
} // end if successful save
$restart = true;
} else if ( ! $user['MonitorIds'] ) {
} else { // new monitor
// Can only create new monitors if we are not restricted to specific monitors
# FIXME This is actually a race condition. Should lock the table.
$maxSeq = dbFetchOne('SELECT MAX(Sequence) AS MaxSequence FROM Monitors', 'MaxSequence');
$changes['Sequence'] = $maxSeq+1;
if ( !$monitor->save($changes) ) {
if ( $monitor->save($changes) ) {
$mid = $monitor->Id();
$zoneArea = $_REQUEST['newMonitor']['Width'] * $_REQUEST['newMonitor']['Height'];
dbQuery("INSERT INTO Zones SET MonitorId = ?, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = ?, Area=?, AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels=?, MaxAlarmPixels=?, FilterX = 3, FilterY = 3, MinFilterPixels=?, MaxFilterPixels=?, MinBlobPixels=?, MinBlobs = 1", array( $mid, sprintf( "%d,%d %d,%d %d,%d %d,%d", 0, 0, $_REQUEST['newMonitor']['Width']-1, 0, $_REQUEST['newMonitor']['Width']-1, $_REQUEST['newMonitor']['Height']-1, 0, $_REQUEST['newMonitor']['Height']-1 ), $zoneArea, intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*2)/100) ) );
@ -157,9 +168,6 @@ ZM\Logger::Debug("Changes:". print_r($changes,true));
$error_message = dbError($sql);
return;
}
} else {
ZM\Error('Users with Monitors restrictions cannot create new monitors.');
return;
}
$restart = true;
@ -167,20 +175,15 @@ ZM\Logger::Debug("Changes:". print_r($changes,true));
ZM\Logger::Debug('No action due to no changes to Monitor');
} # end if count(changes)
if (
( !isset($_POST['newMonitor']['GroupIds']) )
or
( count($_POST['newMonitor']['GroupIds']) != count($monitor->GroupIds()) )
or
array_diff($_POST['newMonitor']['GroupIds'], $monitor->GroupIds())
) {
if ( $monitor->Id() )
dbQuery('DELETE FROM Groups_Monitors WHERE MonitorId=?', array($mid));
if ( !$mid ) {
ZM\Error("We should have a mid by now. Something went wrong.");
return;
}
if ( isset($_POST['newMonitor']['GroupIds']) ) {
foreach ( $_POST['newMonitor']['GroupIds'] as $group_id ) {
dbQuery('INSERT INTO Groups_Monitors (GroupId,MonitorId) VALUES (?,?)', array($group_id, $mid));
}
if ( isset($changes['GroupIds']) ) {
dbQuery('DELETE FROM Groups_Monitors WHERE MonitorId=?', array($mid));
foreach ( $changes['GroupIds'] as $group_id ) {
dbQuery('INSERT INTO Groups_Monitors (GroupId, MonitorId) VALUES (?,?)', array($group_id, $mid));
}
} // end if there has been a change of groups

View File

@ -127,6 +127,10 @@ function initPage() {
document.querySelectorAll('select[name="dimensions_select"]').forEach(function(el) {
el.onchange = window['updateMonitorDimensions'].bind(el, el);
});
document.querySelectorAll('select[name="newMonitor[ControlId]"]').forEach(function(el) {
el.onchange = window['loadLocations'].bind(el, el);
});
$j('.chosen').chosen();
} // end function initPage()

View File

@ -70,6 +70,11 @@ function validateForm( form ) {
errors[errors.length] = "<?php echo translate('BadPort') ?>";
//if ( !form.elements['newMonitor[Path]'].value )
//errors[errors.length] = "<?php echo translate('BadPath') ?>";
} else if ( form.elements['newMonitor[Type]'].value == 'Ffmpeg' ) {
if ( !form.elements['newMonitor[Path]'].value )
//|| !form.elements['newMonitor[Path]'].value.match( /^\d+$/ ) ) // valid url
errors[errors.length] = "<?php echo translate('BadPath') ?>";
} else if ( form.elements['newMonitor[Type]'].value == 'File' ) {
if ( !form.elements['newMonitor[Path]'].value )
errors[errors.length] = "<?php echo translate('BadPath') ?>";
@ -132,22 +137,13 @@ function validateForm( form ) {
}
if ( errors.length ) {
alert( errors.join( "\n" ) );
alert(errors.join("\n"));
return false;
}
return true;
}
function updateLinkedMonitors( element ) {
var form = element.form;
var monitorIds = new Array();
for ( var i = 0; i < element.options.length; i++ )
if ( element.options[i].selected )
monitorIds[monitorIds.length] = element.options[i].value;
form.elements['newMonitor[LinkedMonitors]'].value = monitorIds.join( ',' );
}
function updateMethods( element ) {
function updateMethods(element) {
var form = element.form;
var origMethod = form.elements['origMethod'];
@ -155,31 +151,27 @@ function updateMethods( element ) {
methodSelector.options.length = 0;
switch ( element.value ) {
case 'http' :
{
<?php
foreach( $httpMethods as $value=>$label ) {
?>
methodSelector.options[methodSelector.options.length] = new Option( "<?php echo htmlspecialchars($label) ?>", "<?php echo $value ?>" );
if ( origMethod.value == "<?php echo $value ?>" )
methodSelector.selectedIndex = methodSelector.options.length-1;
<?php
}
?>
<?php
foreach( $httpMethods as $value=>$label ) {
?>
methodSelector.options[methodSelector.options.length] = new Option("<?php echo htmlspecialchars($label) ?>", "<?php echo $value ?>");
if ( origMethod.value == "<?php echo $value ?>" )
methodSelector.selectedIndex = methodSelector.options.length-1;
<?php
}
?>
break;
}
case 'rtsp' :
{
<?php
foreach( $rtspMethods as $value=>$label ) {
?>
methodSelector.options[methodSelector.options.length] = new Option( "<?php echo htmlspecialchars($label) ?>", "<?php echo $value ?>" );
if ( origMethod.value == "<?php echo $value ?>" )
methodSelector.selectedIndex = form.elements['newMonitor[Method]'].options.length-1;
<?php
}
?>
break;
}
<?php
foreach( $rtspMethods as $value=>$label ) {
?>
methodSelector.options[methodSelector.options.length] = new Option( "<?php echo htmlspecialchars($label) ?>", "<?php echo $value ?>" );
if ( origMethod.value == "<?php echo $value ?>" )
methodSelector.selectedIndex = form.elements['newMonitor[Method]'].options.length-1;
<?php
}
?>
break;
}
return( true );
return true;
}

View File

@ -35,12 +35,12 @@ if ( !$Server ) {
}
$monitor = null;
if ( ! empty($_REQUEST['mid']) ) {
$monitor = new ZM\Monitor( $_REQUEST['mid'] );
if ( !empty($_REQUEST['mid']) ) {
$monitor = new ZM\Monitor($_REQUEST['mid']);
if ( $monitor and ZM_OPT_X10 )
$x10Monitor = dbFetchOne('SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['mid']));
}
if ( ! $monitor ) {
if ( !$monitor ) {
$nextId = getTableAutoInc('Monitors');
if ( isset($_REQUEST['dupId']) ) {
@ -49,86 +49,11 @@ if ( ! $monitor ) {
if ( ZM_OPT_X10 )
$x10Monitor = dbFetchOne('SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['dupId']));
$clonedName = $monitor->Name();
$monitor->Name(translate('Monitor').'-'.$nextId);
$monitor->Id(0);
} else {
$monitor = new ZM\Monitor();
$monitor->set( array(
'Id' => 0,
'Name' => translate('Monitor').'-'.$nextId,
'Function' => 'Mocord',
'Enabled' => true,
'LinkedMonitors' => '',
'Type' => 'Ffmpeg',
'Device' => '/dev/video0',
'Channel' => '0',
'Format' => 0x000000ff,
'Protocol' => '',
'Method' => '',
'Host' => '',
'Path' => '',
'Options' => '',
'Port' => '80',
'User' => '',
'Pass' => '',
'Colours' => 4,
'Palette' => 0,
'Width' => '',
'Height' => '',
'Orientation' => '0',
'Deinterlacing' => 0,
'RTSPDescribe' => 0,
'SaveJPEGs' => '0',
'VideoWriter' => '1',
'EncoderParameters' => "# Lines beginning with # are a comment \n# For changing quality, use the crf option\n# 1 is best, 51 is worst quality\n#crf=23\n",
'RecordAudio' => '0',
'LabelFormat' => '%N - %d/%m/%y %H:%M:%S',
'LabelX' => 0,
'LabelY' => 0,
'LabelSize' => 1,
'ImageBufferCount' => 20,
'WarmupCount' => 0,
'PreEventCount' => 0,
'PostEventCount' => 5,
'StreamReplayBuffer' => 0,
'AlarmFrameCount' => 1,
'Controllable' => 0,
'ControlId' => '',
'ControlType' => 0,
'ControlDevice' => '',
'ControlAddress' => '',
'AutoStopTimeout' => '',
'TrackMotion' => 0,
'TrackDelay' => '',
'ReturnLocation' => -1,
'ReturnDelay' => '',
'SectionLength' => 600,
'MinSectionLength' => 10,
'FrameSkip' => 0,
'MotionFrameSkip' => 0,
'EventPrefix' => 'Event-',
'AnalysisFPSLimit' => '',
'AnalysisUpdateDelay' => 0,
'MaxFPS' => null,
'AlarmMaxFPS' => null,
'FPSReportInterval' => 100,
'RefBlendPerc' => 6,
'AlarmRefBlendPerc' => 6,
'DefaultRate' => '100',
'DefaultScale' => '100',
'DefaultCodec' => 'auto',
'SignalCheckPoints' => '10',
'SignalCheckColour' => '#0000c0',
'WebColour' => 'red',
'Exif' => '0',
'Triggers' => '',
'V4LMultiBuffer' => '',
'V4LCapturesPerFrame' => 1,
'ServerId' => 'auto',
'StorageId' => '1',
'Refresh' => '',
) );
} # end if $_REQUEST['dupID']
} # end if $_REQUEST['dupID']
$monitor->Name(translate('Monitor').'-'.$nextId);
} # end if $_REQUEST['mid']
if ( ZM_OPT_X10 && empty($x10Monitor) ) {
@ -150,8 +75,6 @@ if ( isset($_REQUEST['newMonitor']) ) {
if ( ZM_OPT_X10 )
$newX10Monitor = $_REQUEST['newX10Monitor'];
} else {
# FIXME: Triggers in the db is a comma separated string. Needs to be an array.
#$monitor->Triggers()= explode( ',', isset($monitor->Triggers())?$monitor->Triggers:"" );
if ( ZM_OPT_X10 )
$newX10Monitor = $x10Monitor;
}
@ -168,8 +91,9 @@ if ( !empty($_REQUEST['preset']) ) {
$preset = dbFetchOne( 'SELECT Type, Device, Channel, Format, Protocol, Method, Host, Port, Path, Width, Height, Palette, MaxFPS, Controllable, ControlId, ControlDevice, ControlAddress, DefaultRate, DefaultScale FROM MonitorPresets WHERE Id = ?', NULL, array($_REQUEST['preset']) );
foreach ( $preset as $name=>$value ) {
# Does isset handle NULL's? I don't think this code is correct.
# Icon: It does, but this means we can't set a null value.
if ( isset($value) ) {
$monitor->$name = $value;
$monitor->$name($value);
}
}
} # end if preset
@ -530,7 +454,6 @@ foreach ( $tabs as $name=>$value ) {
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
<input type="hidden" name="action" value="monitor"/>
<input type="hidden" name="mid" value="<?php echo $monitor->Id()?>"/>
<input type="hidden" name="newMonitor[LinkedMonitors]" value="<?php echo (null !== $monitor->LinkedMonitors())?validHtmlStr($monitor->LinkedMonitors()):'' ?>"/>
<input type="hidden" name="origMethod" value="<?php echo ( null !== $monitor->Method())?validHtmlStr($monitor->Method()):'' ?>"/>
<?php
if ( $tab != 'general' ) {
@ -538,6 +461,7 @@ if ( $tab != 'general' ) {
<input type="hidden" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>"/>
<input type="hidden" name="newMonitor[ServerId]" value="<?php echo validHtmlStr($monitor->ServerId() ) ?>"/>
<input type="hidden" name="newMonitor[StorageId]" value="<?= validHtmlStr($monitor->StorageId() ) ?>"/>
<input type="hidden" name="newMonitor[LinkedMonitors]" value="<?php echo (null !== $monitor->LinkedMonitors())?validHtmlStr($monitor->LinkedMonitors()):'' ?>"/>
<?php
foreach ( $monitor->GroupIds() as $group_id ) {
echo '<input type="hidden" name="newMonitor[GroupIds][]" value="'.$group_id.'"/>';
@ -552,8 +476,8 @@ echo '<input type="hidden" name="newMonitor[GroupIds][]" value="'.$group_id.'"/>
<input type="hidden" name="newMonitor[MaxFPS]" value="<?php echo validHtmlStr($monitor->MaxFPS()) ?>"/>
<input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?php echo validHtmlStr($monitor->AlarmMaxFPS()) ?>"/>
<?php
if ( null !== $monitor->Triggers() ) {
foreach( explode(',', $monitor->Triggers()) as $newTrigger ) {
if ( '' !== $monitor->Triggers() ) {
foreach ( explode(',', $monitor->Triggers()) as $newTrigger ) {
?>
<input type="hidden" name="newMonitor[Triggers][]" value="<?php echo validHtmlStr($newTrigger) ?>"/>
<?php
@ -684,8 +608,12 @@ switch ( $tab ) {
case 'general' :
{
?>
<tr class="Name"><td><?php echo translate('Name') ?></td><td><input type="text" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>" /></td></tr>
<tr><td><?php echo translate('Server') ?></td><td>
<tr class="Name">
<td><?php echo translate('Name') ?></td>
<td><input type="text" name="newMonitor[Name]" value="<?php echo validHtmlStr($monitor->Name()) ?>"/></td>
</tr>
<tr>
<td><?php echo translate('Server') ?></td><td>
<?php
$servers = array(''=>'None','auto'=>'Auto');
foreach ( ZM\Server::find(NULL, array('order'=>'lower(Name)')) as $Server ) {
@ -693,40 +621,61 @@ switch ( $tab ) {
}
echo htmlSelect( 'newMonitor[ServerId]', $servers, $monitor->ServerId() );
?>
</td></tr>
<tr><td><?php echo translate('StorageArea') ?></td><td>
</td>
</tr>
<tr>
<td><?php echo translate('StorageArea') ?></td>
<td>
<?php
$storage_areas = array(0=>'Default');
foreach ( ZM\Storage::find( NULL, array('order'=>'lower(Name)') ) as $Storage ) {
foreach ( ZM\Storage::find(NULL, array('order'=>'lower(Name)')) as $Storage ) {
$storage_areas[$Storage->Id()] = $Storage->Name();
}
echo htmlSelect( 'newMonitor[StorageId]', $storage_areas, $monitor->StorageId() );
echo htmlSelect('newMonitor[StorageId]', $storage_areas, $monitor->StorageId());
?>
</td></tr>
<tr><td><?php echo translate('SourceType') ?></td><td><?php echo htmlSelect('newMonitor[Type]', $sourceTypes, $monitor->Type()); ?></td></tr>
<tr><td><?php echo translate('Function') ?></td><td><select name="newMonitor[Function]">
<?php
foreach ( getEnumValues('Monitors', 'Function') as $optFunction ) {
?>
<option value="<?php echo $optFunction ?>"<?php if ( $optFunction == $monitor->Function()) { ?> selected="selected"<?php } ?>><?php echo translate('Fn'.$optFunction) ?></option>
</td>
</tr>
<tr>
<td><?php echo translate('SourceType') ?></td>
<td><?php echo htmlSelect('newMonitor[Type]', $sourceTypes, $monitor->Type()); ?></td>
</tr>
<tr>
<td><?php echo translate('Function') ?></td>
<td>
<?php
$function_options = array();
foreach ( getEnumValues('Monitors', 'Function') as $f ) {
$function_options[$f] = translate("Fn$f");
}
ZM\Error("Type: " . $monitor->Type());
echo htmlSelect('newMonitor[Function]', $function_options, $monitor->Function());
?>
</select></td></tr>
<tr><td><?php echo translate('Enabled') ?></td><td><input type="checkbox" name="newMonitor[Enabled]" value="1"<?php if ( $monitor->Enabled() ) { ?> checked="checked"<?php } ?>/></td></tr>
</td>
</tr>
<tr>
<td><?php echo translate('Enabled') ?></td>
<td><input type="checkbox" name="newMonitor[Enabled]" value="1"<?php if ( $monitor->Enabled() ) { ?> checked="checked"<?php } ?>/></td>
</tr>
<?php
if ( $monitor->Type != 'WebSite' ) {
if ( $monitor->Type() != 'WebSite' ) {
?>
<tr>
<td><?php echo translate('LinkedMonitors') ?>&nbsp;(<?php echo makePopupLink('?view=optionhelp&amp;option=OPTIONS_LINKED_MONITORS', 'zmOptionHelp', 'optionhelp', '?' ) ?>)</td>
<td>
<select name="monitorIds" class="chosen" multiple="multiple" onchange="updateLinkedMonitors( this )">
<?php
$monitors = dbFetchAll( 'select Id,Name from Monitors order by Sequence asc' );
if ( $monitor->LinkedMonitors() )
$monitorIds = array_flip( explode( ',', $monitor->LinkedMonitors()) );
else
$monitorIds = array();
$monitors = dbFetchAll('SELECT Id, Name FROM Monitors ORDER BY Sequence ASC');
foreach ( $monitors as $linked_monitor ) {
$monitor_options[$linked_monitor['Id']] = $linked_monitor['Name'];
}
echo htmlSelect(
'newMonitor[LinkedMonitors]',
$monitor_options,
( $monitor->LinkedMonitors() ? explode(',', $monitor->LinkedMonitors()) : array() ),
array('class'=>'chosen','multiple'=>'multiple')
);
if ( 0 ) {
foreach ( $monitors as $linked_monitor ) {
if ( (!$monitor->Id() || ($monitor->Id()!= $linked_monitor['Id'])) && visibleMonitor( $linked_monitor['Id'] ) ) {
?>
@ -734,8 +683,8 @@ switch ( $tab ) {
<?php
}
}
}
?>
</select>
</td>
</tr>
<tr><td><?php echo translate('Groups'); ?></td><td><select name="newMonitor[GroupIds][]" multiple="multiple" class="chosen"><?php
@ -790,9 +739,9 @@ echo htmlOptions(ZM\Group::get_dropdown_options( ), $monitor->GroupIds() );
?>
<tr><td><?php echo translate('Triggers') ?></td><td>
<?php
$optTriggers = getSetValues( 'Monitors', 'Triggers' );
$optTriggers = getSetValues('Monitors', 'Triggers');
$breakCount = (int)(ceil(count($optTriggers)));
$breakCount = min( 3, $breakCount );
$breakCount = min(3, $breakCount);
$optCount = 0;
foreach( $optTriggers as $optTrigger ) {
if ( !ZM_OPT_X10 && $optTrigger == 'X10' )
@ -1027,22 +976,52 @@ if ( $monitor->Type() == 'Local' ) {
case 'control' :
{
?>
<tr><td><?php echo translate('Controllable') ?></td><td><input type="checkbox" name="newMonitor[Controllable]" value="1"<?php if ( $monitor->Controllable() ) { ?> checked="checked"<?php } ?>/></td></tr>
<tr><td><?php echo translate('ControlType') ?></td><td><?php echo buildSelect( "newMonitor[ControlId]", $controlTypes, 'loadLocations( this )' ); ?><?php if ( canEdit( 'Control' ) ) { ?>&nbsp;<?php echo makePopupLink('?view=controlcaps', 'zmControlCaps', 'controlcaps', translate('Edit')); ?></a><?php } ?></td></tr>
<tr><td><?php echo translate('ControlDevice') ?></td><td><input type="text" name="newMonitor[ControlDevice]" value="<?php echo validHtmlStr($monitor->ControlDevice()) ?>" size="32"/></td></tr>
<tr><td><?php echo translate('ControlAddress') ?></td><td><input type="text" name="newMonitor[ControlAddress]" value="<?php echo validHtmlStr($monitor->ControlAddress()) ?>" size="32"/></td></tr>
<tr><td><?php echo translate('AutoStopTimeout') ?></td><td><input type="text" name="newMonitor[AutoStopTimeout]" value="<?php echo validHtmlStr($monitor->AutoStopTimeout()) ?>" size="4"/></td></tr>
<tr><td><?php echo translate('TrackMotion') ?></td><td><input type="checkbox" name="newMonitor[TrackMotion]" value="1"<?php if ( $monitor->TrackMotion() ) { ?> checked="checked"<?php } ?>/></td></tr>
<tr>
<td><?php echo translate('Controllable') ?></td>
<td><input type="checkbox" name="newMonitor[Controllable]" value="1"<?php if ( $monitor->Controllable() ) { ?> checked="checked"<?php } ?>/></td></tr>
<tr>
<td><?php echo translate('ControlType') ?></td>
<td><?php echo htmlSelect('newMonitor[ControlId]', $controlTypes, $monitor->ControlId());
if ( canEdit('Control') ) {
echo '&nbsp;'.makePopupLink('?view=controlcaps', 'zmControlCaps', 'controlcaps', translate('Edit'));
}
?></td>
</tr>
<tr>
<td><?php echo translate('ControlDevice') ?></td>
<td><input type="text" name="newMonitor[ControlDevice]" value="<?php echo validHtmlStr($monitor->ControlDevice()) ?>"/></td>
</tr>
<tr>
<td><?php echo translate('ControlAddress') ?></td>
<td><input type="text" name="newMonitor[ControlAddress]" value="<?php echo validHtmlStr($monitor->ControlAddress()) ?>"/></td>
</tr>
<tr>
<td><?php echo translate('AutoStopTimeout') ?></td>
<td><input type="number" name="newMonitor[AutoStopTimeout]" value="<?php echo validHtmlStr($monitor->AutoStopTimeout()) ?>"/></td>
</tr>
<tr>
<td><?php echo translate('TrackMotion') ?></td>
<td><input type="checkbox" name="newMonitor[TrackMotion]" value="1"<?php if ( $monitor->TrackMotion() ) { ?> checked="checked"<?php } ?>/></td>
</tr>
<?php
$return_options = array(
'-1' => translate('None'),
'0' => translate('Home'),
'1' => translate('Preset')." 1",
'1' => translate('Preset').' 1',
);
?>
<tr><td><?php echo translate('TrackDelay') ?></td><td><input type="text" name="newMonitor[TrackDelay]" value="<?php echo validHtmlStr($monitor->TrackDelay()) ?>" size="4"/></td></tr>
<tr><td><?php echo translate('ReturnLocation') ?></td><td><?php echo buildSelect( "newMonitor[ReturnLocation]", $return_options ); ?></td></tr>
<tr><td><?php echo translate('ReturnDelay') ?></td><td><input type="text" name="newMonitor[ReturnDelay]" value="<?php echo validHtmlStr($monitor->ReturnDelay()) ?>" size="4"/></td></tr>
<tr>
<td><?php echo translate('TrackDelay') ?></td>
<td><input type="number" name="newMonitor[TrackDelay]" value="<?php echo validHtmlStr($monitor->TrackDelay()) ?>"/></td>
</tr>
<tr>
<td><?php echo translate('ReturnLocation') ?></td>
<td><?php echo htmlSelect('newMonitor[ReturnLocation]', $return_options, $monitor->ReturnLocation()); ?></td>
</tr>
<tr>
<td><?php echo translate('ReturnDelay') ?></td>
<td><input type="number" name="newMonitor[ReturnDelay]" value="<?php echo validHtmlStr($monitor->ReturnDelay()) ?>"/></td>
</tr>
<?php
break;
}