Bug 34 - Moved mysql specific functions to more generic functions.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2196 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2007-09-06 12:59:19 +00:00
parent f93e109b8d
commit 315c4656fc
58 changed files with 239 additions and 774 deletions

View File

@ -157,11 +157,7 @@ if ( !empty($action) )
{
if ( $action == "control" )
{
$result = mysql_query( "select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id) where M.Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id) where M.Id = '$mid'" );
$ctrl_command = "zmcontrol.pl";
if ( !preg_match( '/^\//', $ctrl_command ) )
@ -825,21 +821,14 @@ if ( !empty($action) )
{
if ( canEdit( 'Control' ) )
{
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."' and Preset = '".$preset."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( "select * from ControlPresets where MonitorId = '".$monitor['Id']."' and Preset = '".$preset."'" );
if ( $new_label != $row['Label'] )
{
if ( $new_label )
$sql = "replace into ControlPresets ( MonitorId, Preset, Label ) values ( '".$monitor['Id']."', '".$preset."', '".addslashes($new_label)."' )";
else
$sql = "delete from ControlPresets where MonitorId = '".$monitor['Id']."' and Preset = '".$preset."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( $sql );
$refresh_parent = true;
}
}
@ -893,10 +882,7 @@ if ( !empty($action) )
$zmu_command = getZmuCommand( " -m $mid -B$new_brightness -C$new_contrast -H$new_hue -O$new_colour" );
$zmu_output = exec( escapeshellcmd( $zmu_command ) );
list( $brightness, $contrast, $hue, $colour ) = split( ' ', $zmu_output );
$sql = "update Monitors set Brightness = '$brightness', Contrast = '$contrast', Hue = '$hue', Colour = '$colour' where Id = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Monitors set Brightness = '$brightness', Contrast = '$contrast', Hue = '$hue', Colour = '$colour' where Id = '$mid'" );
}
}
@ -907,11 +893,7 @@ if ( !empty($action) )
{
if ( !empty($cid) )
{
$result = mysql_query( "select * from Controls where Id = '$cid'" );
if ( !$result )
die( mysql_error() );
$control = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$control = dbFetchOne( "select * from Controls where Id = '$cid'" );
}
else
{
@ -942,11 +924,8 @@ if ( !empty($action) )
}
else
{
$sql = "insert into Controls set ".implode( ", ", $changes );
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$cid = mysql_insert_id();
dbQuery( "insert into Controls set ".implode( ", ", $changes ) );
$cid = dbInsertId();
}
$refresh_parent = true;
}
@ -970,12 +949,7 @@ if ( !empty($action) )
{
if ( $action == "function" )
{
$sql = "select * from Monitors where Id = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
dbQuery( "select * from Monitors where Id = '$mid'" );
$old_function = $monitor['Function'];
$old_enabled = $monitor['Enabled'];
@ -997,19 +971,11 @@ if ( !empty($action) )
}
elseif ( $action == "zone" && isset( $zid ) )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select * from Monitors where Id = '$mid'" );
if ( $zid > 0 )
{
$result = mysql_query( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
if ( !$result )
die( mysql_error() );
$zone = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$zone = dbFetchOne( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
}
else
{
@ -1059,25 +1025,11 @@ if ( !empty($action) )
}
elseif ( $action == "sequence" && isset($smid) )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$result = mysql_query( "select * from Monitors where Id = '$smid'" );
if ( !$result )
die( mysql_error() );
$smonitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select * from Monitors where Id = '$mid'" );
$smonitor = dbFetchOne( "select * from Monitors where Id = '$smid'" );
$sql = "update Monitors set Sequence = '".$smonitor['Sequence']."' where Id = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$sql = "update Monitors set Sequence = '".$monitor['Sequence']."' where Id = '".$smonitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Monitors set Sequence = '".$smonitor['Sequence']."' where Id = '".$monitor['Id']."'" );
dbQuery( "update Monitors set Sequence = '".$monitor['Sequence']."' where Id = '".$smonitor['Id']."'" );
$refresh_parent = true;
fixSequences();
@ -1089,14 +1041,13 @@ if ( !empty($action) )
$deleted_zid = 0;
foreach( $mark_zids as $mark_zid )
{
$result = mysql_query( "delete from Zones where MonitorId = '$mid' && Id = '$mark_zid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Zones where MonitorId = '$mid' && Id = '$mark_zid'" );
$deleted_zid = 1;
}
if ( $deleted_zid )
{
if ( $cookies ) session_write_close();
if ( $cookies )
session_write_close();
if ( daemonCheck() )
{
zmaControl( $mid, "restart" );
@ -1114,22 +1065,13 @@ if ( !empty($action) )
{
if ( !empty($mid) )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select * from Monitors where Id = '$mid'" );
if ( ZM_OPT_X10 )
{
$result = mysql_query( "select * from TriggersX10 where MonitorId = '$mid'" );
if ( !$result )
die( mysql_error() );
if ( !($x10_monitor = mysql_fetch_assoc( $result )) )
{
$x10_monitor = dbFetchOne( "select * from TriggersX10 where MonitorId = '$mid'" );
if ( !$x10_monitor )
$x10_monitor = array();
}
mysql_free_result( $result );
}
}
else
@ -1169,15 +1111,7 @@ if ( !empty($action) )
$old_h = $monitor['Height'];
$old_a = $old_w * $old_h;
$result = mysql_query( "select * from Zones where MonitorId = '$mid'" );
if ( !$result )
die( mysql_error() );
$zones = array();
while ( $zone = mysql_fetch_assoc( $result ) )
{
$zones[] = $zone;
}
mysql_free_result( $result );
$zones = dbFetchAll( "select * from Zones where MonitorId = '$mid'" );
foreach ( $zones as $zone )
{
$new_zone = $zone;
@ -1200,33 +1134,20 @@ if ( !empty($action) )
if ( count( $changes ) )
{
$sql = "update Zones set ".implode( ", ", $changes )." where MonitorId = '$mid' and Id = '".$zone['Id']."'";
//echo "<html>$sql</html>";
dbQuery( $sql );
dbQuery( "update Zones set ".implode( ", ", $changes )." where MonitorId = '$mid' and Id = '".$zone['Id']."'" );
}
}
}
}
elseif ( !$user['MonitorIds'] )
{
$sql = "select max(Sequence) as MaxSequence from Monitors";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$changes[] = "Sequence = ".($row['MaxSequence']+1);
$max_seq = dbFetchOne( "select max(Sequence) as MaxSequence from Monitors", "MaxSequence" );
$changes[] = "Sequence = ".($max_seq+1);
$sql = "insert into Monitors set ".implode( ", ", $changes );
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$mid = mysql_insert_id();
dbQuery( "insert into Monitors set ".implode( ", ", $changes ) );
$mid = dbInsertId();
$zone_area = $new_monitor['Width'] * $new_monitor['Height'];
$sql = "insert into Zones set MonitorId = $mid, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = '".sprintf( "%d,%d %d,%d %d,%d %d,%d", 0, 0, $new_monitor['Width']-1, 0, $new_monitor['Width']-1, $new_monitor['Height']-1, 0, $new_monitor['Height']-1 )."', Area = ".$zone_area.", AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels = ".intval(($zone_area*3)/100).", MaxAlarmPixels = ".intval(($zone_area*75)/100).", FilterX = 3, FilterY = 3, MinFilterPixels = ".intval(($zone_area*3)/100).", MaxFilterPixels = ".intval(($zone_area*75)/100).", MinBlobPixels = ".intval(($zone_area*2)/100).", MinBlobs = 1";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "insert into Zones set MonitorId = $mid, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = '".sprintf( "%d,%d %d,%d %d,%d %d,%d", 0, 0, $new_monitor['Width']-1, 0, $new_monitor['Width']-1, $new_monitor['Height']-1, 0, $new_monitor['Height']-1 )."', Area = ".$zone_area.", AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels = ".intval(($zone_area*3)/100).", MaxAlarmPixels = ".intval(($zone_area*75)/100).", FilterX = 3, FilterY = 3, MinFilterPixels = ".intval(($zone_area*3)/100).", MaxFilterPixels = ".intval(($zone_area*75)/100).", MinBlobPixels = ".intval(($zone_area*2)/100).", MinBlobs = 1" );
//$view = 'none';
mkdir( ZM_DIR_EVENTS."/".$mid, 0755 );
chdir( ZM_DIR_EVENTS );
@ -1244,26 +1165,17 @@ if ( !empty($action) )
{
if ( $x10_monitor && $new_x10_monitor )
{
$sql = "update TriggersX10 set ".implode( ", ", $x10_changes )." where MonitorId = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update TriggersX10 set ".implode( ", ", $x10_changes )." where MonitorId = '$mid'" );
}
elseif ( !$user['MonitorIds'] )
{
if ( !$x10_monitor )
{
$sql = "insert into TriggersX10 set MonitorId = '$mid', ".implode( ", ", $x10_changes );
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "insert into TriggersX10 set MonitorId = '$mid', ".implode( ", ", $x10_changes ) );
}
else
{
$sql = "delete from TriggersX10 where MonitorId = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from TriggersX10 where MonitorId = '$mid'" );
}
}
$restart = true;
@ -1272,13 +1184,10 @@ if ( !empty($action) )
if ( $restart )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select * from Monitors where Id = '$mid'" );
fixDevices();
if ( $cookies ) session_write_close();
if ( $cookies )
session_write_close();
if ( daemonCheck() )
{
zmcControl( $monitor, "restart" );
@ -1301,26 +1210,13 @@ if ( !empty($action) )
zmcControl( $monitor, "stop" );
$sql = "select * from Monitors where Id = '$mark_mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
if ( !($monitor = mysql_fetch_assoc( $result )) )
if ( !($monitor = dbFetchOne( $sql )) )
{
continue;
}
mysql_free_result( $result );
$sql = "select Id from Events where MonitorId = '$mark_mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$mark_eids = array();
while( $row = mysql_fetch_assoc( $result ) )
{
$mark_eids[] = $row['Id'];
}
mysql_free_result( $result );
$mark_eids = dbFetchAll( $sql, 'Id' );
foreach( $mark_eids as $mark_eid )
{
deleteEvent( $mark_eid );
@ -1328,18 +1224,12 @@ if ( !empty($action) )
unlink( ZM_DIR_EVENTS."/".$monitor['Name'] );
system( "rm -rf ".ZM_DIR_EVENTS."/".$monitor['Id'] );
$result = mysql_query( "delete from Zones where MonitorId = '$mark_mid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Zones where MonitorId = '$mark_mid'" );
if ( ZM_OPT_X10 )
{
$result = mysql_query( "delete from TriggersX10 where MonitorId = '$mark_mid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from TriggersX10 where MonitorId = '$mark_mid'" );
}
$result = mysql_query( "delete from Monitors where Id = '$mark_mid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Monitors where Id = '$mark_mid'" );
fixSequences();
}
@ -1415,10 +1305,7 @@ if ( !empty($action) )
}
case 'ignore' :
{
$sql = "update Config set Value = '".ZM_DYN_LAST_VERSION."' where Name = 'ZM_DYN_CURR_VERSION'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '".ZM_DYN_LAST_VERSION."' where Name = 'ZM_DYN_CURR_VERSION'" );
break;
}
case 'hour' :
@ -1438,18 +1325,12 @@ if ( !empty($action) )
{
$next_reminder += 7*24*60*60;
}
$sql = "update Config set Value = '".$next_reminder."' where Name = 'ZM_DYN_NEXT_REMINDER'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '".$next_reminder."' where Name = 'ZM_DYN_NEXT_REMINDER'" );
break;
}
case 'never' :
{
$sql = "update Config set Value = '0' where Name = 'ZM_CHECK_FOR_UPDATES'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '0' where Name = 'ZM_CHECK_FOR_UPDATES'" );
break;
}
}
@ -1485,19 +1366,13 @@ if ( !empty($action) )
{
$next_reminder += 30*24*60*60;
}
$sql = "update Config set Value = '".$next_reminder."' where Name = 'ZM_DYN_DONATE_REMINDER_TIME'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '".$next_reminder."' where Name = 'ZM_DYN_DONATE_REMINDER_TIME'" );
break;
}
case 'never' :
case 'already' :
{
$sql = "update Config set Value = '0' where Name = 'ZM_DYN_SHOW_DONATE_REMINDER'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '0' where Name = 'ZM_DYN_SHOW_DONATE_REMINDER'" );
break;
}
}
@ -1518,11 +1393,7 @@ if ( !empty($action) )
}
if ( $value['Value'] != $new_config[$name] )
{
$sql = "update Config set Value = '".$new_config[$name]."' where Name = '".$name."'";
//echo $sql;
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( "update Config set Value = '".$new_config[$name]."' where Name = '".$name."'" );
$changed = true;
}
}
@ -1557,11 +1428,7 @@ if ( !empty($action) )
{
if ( !empty($uid) )
{
$result = mysql_query( "select * from Users where Id = '$uid'" );
if ( !$result )
die( mysql_error() );
$db_user = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$db_user = dbFetchOne( "select * from Users where Id = '$uid'" );
}
else
{
@ -1585,9 +1452,7 @@ if ( !empty($action) )
{
$sql = "insert into Users set ".implode( ", ", $changes );
}
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( $sql );
$refresh_parent = true;
if ( $db_user['Username'] == $user['Username'] )
{
@ -1610,16 +1475,11 @@ if ( !empty($action) )
if ( $run_state || $new_state )
{
$sql = "select Id,Function,Enabled from Monitors order by Id";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$definitions = array();
while( $monitor = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $monitor )
{
$definitions[] = $monitor['Id'].":".$monitor['Function'].":".$monitor['Enabled'];
}
mysql_free_result( $result );
$definition = join( ',', $definitions );
if ( $new_state )
$run_state = $new_state;
@ -1679,9 +1539,7 @@ if ( !empty($action) )
{
foreach( $mark_eids as $mark_eid )
{
$result = mysql_query( "update Events set LearnState = '$learn_state' where Id = '$mark_eid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "update Events set LearnState = '$learn_state' where Id = '$mark_eid'" );
}
}
}

View File

@ -429,15 +429,11 @@ function controlPreset( command )
<td align="center">
<?php
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$labels = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
$labels[$row['Preset']] = $row['Label'];
}
mysql_free_result( $result );
$preset_break = (int)(($monitor['NumPresets']+1)/((int)(($monitor['NumPresets']-1)/MAX_PRESETS)+1));
for ( $i = 1; $i <= $monitor['NumPresets']; $i++ )

View File

@ -306,15 +306,11 @@ function controlPresets( $monitor )
define( "MAX_PRESETS", "12" );
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$labels = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
$labels[$row['Preset']] = $row['Label'];
}
mysql_free_result( $result );
$preset_break = (int)(($monitor['NumPresets']+1)/((int)(($monitor['NumPresets']-1)/MAX_PRESETS)+1));

View File

@ -50,6 +50,14 @@ function dbError( $sql )
die( "An error has occurred and this operation cannot continue.<br>For full details check your web logs for the code '$err_ref'" );
}
function dbEscape( $string )
{
if ( version_compare( phpversion(), "4.3.0", "<") )
return( mysql_escape_string( $string ) );
else
return( mysql_real_escape_string( $string ) );
}
function dbQuery( $sql )
{
if ( dbDebug( $sql ) )
@ -91,6 +99,12 @@ function dbFetch( $sql, $col=false )
return( dbFetchAll( $sql, $col ) );
}
function dbFetchNext( $result, $col=false )
{
$db_row = mysql_fetch_assoc( $result );
return( $col?$db_row[$col]:$db_row );
}
function dbNumRows( $sql )
{
dbDebug( $sql );
@ -100,14 +114,15 @@ function dbNumRows( $sql )
return( mysql_num_rows( $result ) );
}
function dbInsertId()
{
return( mysql_insert_id() );
}
function getEnumValues( $table, $column )
{
$enum_values = array();
$result = mysql_query( "DESCRIBE $table $column" );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc($result);
mysql_free_result( $result );
$row = dbFetchOne( "DESCRIBE $table $column" );
preg_match_all( "/'([^']+)'/", $row['Type'], $enum_matches );
$enum_values = $enum_matches[1];
return( $enum_values );
@ -121,44 +136,39 @@ function getSetValues( $table, $column )
function getUniqueValues( $table, $column, $as_string=1 )
{
$values = array();
$result = mysql_query( "SELECT DISTINCT $column FROM $table WHERE (NOT ISNULL($column) AND $column != '') ORDER BY $column" );
if ( $result )
{
while ( $row = mysql_fetch_array($result) )
{
if ( $as_string )
$values[$row[0]] = $row[0];
else
$values = $row[0];
}
mysql_free_result( $result );
}
else
{
echo mysql_error();
}
$sql = "SELECT DISTINCT $column FROM $table WHERE (NOT ISNULL($column) AND $column != '') ORDER BY $column";
foreach( dbFetchAll( $sql ) as $row )
{
if ( $as_string )
$values[$row[0]] = $row[0];
else
$values = $row[0];
}
return( $values );
}
function getTableColumns( $table, $as_string=1 )
{
$columns = array();
$result = mysql_query( "DESCRIBE $table" );
if ( $result )
{
while( $row = mysql_fetch_assoc($result) )
{
if ( $as_string )
$columns[$row[Field]] = $row[Type];
else
$columns[] = $row[Type];
}
mysql_free_result( $result );
}
else
{
echo mysql_error();
}
$sql = "DESCRIBE $table";
foreach( dbFetchAll( $sql ) as $row )
{
if ( $as_string )
$columns[$row[Field]] = $row[Type];
else
$columns[] = $row[Type];
}
return( $columns );
}
function dbFetchMonitor( $mid )
{
return( dbFetchOne( "select * from Monitors where Id = '$mid'" ) );
}
function dbFetchGroup( $gid )
{
return( dbFetchOne( "select * from Groups where Id = '$gid'" ) );
}
?>

View File

@ -99,14 +99,7 @@ function exportEventFrames( $event )
global $zmSlangYes, $zmSlangNo, $zmSlangNoFramesRecorded;
$sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '".$event['Id']."' order by FrameId";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$frames[] = $row;
}
mysql_free_result( $result );
$frames = dbFetchAll( $sql );
ob_start();
exportHeader( $zmSlangFrames." ".$event['Id'] );
@ -188,10 +181,7 @@ function exportFileList( $eid )
if ( canView( 'Events' ) && $eid )
{
$sql = "select E.Id,E.MonitorId,M.Name As MonitorName,M.Width,M.Height,E.Name,E.Cause,E.Notes,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where E.Id = '$eid'";
if ( !($result = mysql_query( $sql )) )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
$event_path = getEventPath( $event );
$files = array();

View File

@ -37,28 +37,17 @@ function userLogin( $username, $password="" )
global $_SESSION, $_SERVER;
}
if ( version_compare( phpversion(), "4.3.0", "<") )
{
$mysql_username = mysql_escape_string($username);
$mysql_password = mysql_escape_string($password);
}
else
{
$mysql_username = mysql_real_escape_string($username);
$mysql_password = mysql_real_escape_string($password);
}
$db_username = dbEscape($username);
$db_password = dbEscape($password);
if ( ZM_AUTH_TYPE == "builtin" )
{
$sql = "select * from Users where Username = '$mysql_username' and Password = password('$mysql_password') and Enabled = 1";
$sql = "select * from Users where Username = '$db_username' and Password = password('$db_password') and Enabled = 1";
}
else
{
$sql = "select * from Users where Username = '$mysql_username' and Enabled = 1";
$sql = "select * from Users where Username = '$db_username' and Enabled = 1";
}
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$_SESSION['username'] = $username;
if ( ZM_AUTH_RELAY == "plain" )
{
@ -66,7 +55,7 @@ function userLogin( $username, $password="" )
$_SESSION['password'] = $password;
}
$_SESSION['remote_addr'] = $_SERVER['REMOTE_ADDR']; // To help prevent session hijacking
if ( $db_user = mysql_fetch_assoc( $result ) )
if ( $db_user = dbFetchOne( $sql ) )
{
$_SESSION['user'] = $user = $db_user;
if ( ZM_AUTH_TYPE == "builtin" )
@ -78,8 +67,8 @@ function userLogin( $username, $password="" )
{
unset( $user );
}
mysql_free_result( $result );
if ( $cookies ) session_write_close();
if ( $cookies )
session_write_close();
}
function userLogout()
@ -461,17 +450,11 @@ function deleteEvent( $eid, $mid=false )
$mid = '*';
if ( $user['Events'] == 'Edit' && $eid )
{
$result = mysql_query( "delete from Events where Id = '$eid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Events where Id = '$eid'" );
if ( !ZM_OPT_FAST_DELETE )
{
$result = mysql_query( "delete from Stats where EventId = '$eid'" );
if ( !$result )
die( mysql_error() );
$result = mysql_query( "delete from Frames where EventId = '$eid'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Stats where EventId = '$eid'" );
dbQuery( "delete from Frames where EventId = '$eid'" );
if ( ZM_USE_DEEP_STORAGE )
{
error_log( "Globbing ".ZM_DIR_EVENTS.'/'.$mid.'/*/*/*/.'.$eid );
@ -802,10 +785,7 @@ function zmcControl( $monitor, $mode=false )
$sql = "select count(if(Function!='None',1,NULL)) as ActiveCount from Monitors where Id = '".$monitor['Id']."'";
$zmc_args = "-m ".$monitor['Id'];
}
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$row = mysql_fetch_assoc( $result );
$row = dbFetchOne( $sql );
$active_count = $row['ActiveCount'];
if ( !$active_count )
@ -827,10 +807,7 @@ function zmaControl( $monitor, $mode=false )
if ( !is_array( $monitor ) )
{
$sql = "select Id,Function,Enabled from Monitors where Id = '$monitor'";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$monitor = mysql_fetch_assoc( $result );
$monitor = dbFetchOne( $sql );
}
switch ( $monitor['Function'] )
{
@ -1046,10 +1023,7 @@ function getImageSrc( $event, $frame, $scale, $capture_only=false, $overwrite=fa
function createListThumbnail( $event, $overwrite=false )
{
$sql = "select * from Frames where EventId = '".$event['Id']."' and Score = '".$event['MaxScore']."' order by FrameId limit 0,1";
if ( !($result = mysql_query( $sql )) )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( $frame );
$frame_id = $frame['FrameId'];
if ( ZM_WEB_LIST_THUMB_WIDTH )
@ -1110,9 +1084,7 @@ function executeFilter( $filter )
{
$command = ZM_PATH_BIN."/zmfilter.pl --filter ".$filter;
$result = exec( $command, $output, $status );
$result = mysql_query( "delete from Filters where Name like '_TempFilter%'" );
if ( !$result )
die( mysql_error() );
dbQuery( "delete from Filters where Name like '_TempFilter%'" );
return( $status );
}
@ -1437,22 +1409,16 @@ function verNum( $version )
function fixSequences()
{
$sql = "select * from Monitors order by Sequence asc, Id asc";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$sequence = 1;
while ( $monitor = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $monitors ) as $monitor )
{
if ( $monitor['Sequence'] != $sequence )
{
$sql2 = "update Monitors set Sequence = '".$sequence."' where Id = '".$monitor['Id']."'";
$result2 = mysql_query( $sql2 );
if ( !$result2 )
echo mysql_error();
dbQuery( $sql2 );
}
$sequence++;
}
mysql_free_result( $result );
}
function firstSet()
@ -1823,10 +1789,7 @@ function monitorIdsToNames( $ids )
if ( !$mITN_monitors )
{
$sql = "select Id, Name from Monitors";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
while ( $monitor = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $monitor )
{
$mITN_monitors[$monitor['Id']] = $monitor;
}

View File

@ -24,11 +24,7 @@ if ( !canView( 'Control' ) )
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select * from Monitors where Id = '$mid'" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

View File

@ -40,11 +40,7 @@ if ( !isset($tab) )
if ( !empty($cid) )
{
$result = mysql_query( "select * from Controls where Id = '$cid'" );
if ( !$result )
die( mysql_error() );
$control = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$control = dbFetchOne( "select * from Controls where Id = '$cid'" );
}
else
{

View File

@ -25,15 +25,7 @@ if ( !canView( 'Control' ) )
}
$sql = "select * from Controls order by Id";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$controls = array();
while( $row = mysql_fetch_assoc( $result ) )
{
$controls[] = $row;
}
mysql_free_result( $result );
$controls = dbFetchAll( $sql );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -27,19 +27,12 @@ if ( !canView( 'Control' ) )
if ( $group )
{
$sql = "select * from Groups where Id = '$group'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $sql );
$group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )";
}
$sql = "select * from Monitors where Function != 'None' and Controllable = 1 $group_sql order by Sequence";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$mids = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -47,7 +40,6 @@ while( $row = mysql_fetch_assoc( $result ) )
}
$mids[$row['Id']] = $row['Name'];
}
mysql_free_result( $result );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -27,11 +27,7 @@ if ( !canView( 'Control' ) )
require_once( 'zm_control_funcs.php' );
$sql = "select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( $sql );
$cmds = getControlCommands( $monitor );

View File

@ -24,22 +24,14 @@ if ( !canEdit( 'Monitors' ) )
return;
}
$result = mysql_query( "select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( "select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'" );
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$labels = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
$labels[$row['Preset']] = $row['Label'];
}
mysql_free_result( $result );
$presets = array();
for ( $i = 1; $i <= $monitor['NumPresets']; $i++ )

View File

@ -34,21 +34,14 @@ if ( empty($mode) )
if ( $group )
{
$sql = "select * from Groups where Id = '$group'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $sql );
$group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )";
}
$sql = "select * from Monitors where Function != 'None' $group_sql order by Sequence";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitors = array();
$mon_idx = 0;
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -60,7 +53,6 @@ while( $row = mysql_fetch_assoc( $result ) )
$row['ScaledHeight'] = reScale( $monitor['Height'], $row['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$monitors[] = $row;
}
mysql_free_result( $result );
$monitor = $monitors[$mon_idx];
$next_mid = $mon_idx==(count($monitors)-1)?$monitors[0]['Id']:$monitors[$mon_idx+1]['Id'];

View File

@ -26,11 +26,7 @@ if ( !canEdit( 'Devices' ) )
if ( $did )
{
$sql = "select * from Devices where Id = '$did'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$new_device = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$new_device = dbFetchOne( $sql );
}
else
{

View File

@ -25,16 +25,12 @@ if ( !canView( 'Devices' ) )
}
$sql = "select * from Devices where Type = 'X10' order by Name";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$devices = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
$row['Status'] = getDeviceStatusX10( $row['KeyString'] );
$devices[] = $row;
}
mysql_free_result( $result );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

View File

@ -41,42 +41,33 @@ else
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultRate,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
parseSort();
parseFilter( $filter );
$sql = "select E.* from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sort_column ".($sort_order=='asc'?'<=':'>=')." '".$event[preg_replace( '/^.*\./', '', $sort_column )]."'$filter_sql$mid_sql order by $sort_column ".($sort_order=='asc'?'desc':'asc');
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
$result = dbQuery( $sql );
foreach( dbFetchAll( $sql ) as $row )
while ( $row = dbFetchNext( $result ) )
{
if ( $row['Id'] == $eid )
{
$prev_event = mysql_fetch_assoc( $result );
$prev_event = dbFetchNext( $result );
break;
}
}
mysql_free_result( $result );
$sql = "select E.* from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sort_column ".($sort_order=='asc'?'>=':'<=')." '".$event[preg_replace( '/^.*\./', '', $sort_column )]."'$filter_sql$mid_sql order by $sort_column $sort_order";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
$result = dbQuery( $sql );
while ( $row = dbFetchNext( $result ) )
{
if ( $row['Id'] == $eid )
{
$next_event = mysql_fetch_assoc( $result );
$next_event = dbFetchNext( $result );
break;
}
}
mysql_free_result( $result );
if ( !isset( $rate ) )
$rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE );
@ -93,11 +84,7 @@ $paged = $event['Frames'] > $frames_per_page;
if ( $mode == "stream" )
{
$sql = "select max(Delta)-min(Delta) as Duration from Frames where EventId = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$frame_data = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame_data = dbFetchOne( $sql );
$frame_data['RealDuration'] = ($frame_data['Duration']*RATE_BASE)/$rate;
$panel_init_color = '#eeeeee';
@ -461,15 +448,11 @@ else
$sql .= " order by FrameId";
if ( $paged && !empty($page) )
$sql .= " limit $lo_frame_id, ".($hi_frame_id-$lo_frame_id);
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$frames = array();
while( $frame = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $frame )
{
$frames[$frame['FrameId']] = $frame;
}
mysql_free_result( $result );
?>
<tr><td><div style="text-align: center">
<?php

View File

@ -26,11 +26,7 @@ if ( !canEdit( 'Events' ) )
if ( $eid )
{
$sql = "select E.* from Events as E where E.Id = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$new_event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$new_event = dbFetchOne( $sql );
}
elseif ( $eids )
{
@ -42,10 +38,7 @@ elseif ( $eids )
}
unset( $eid );
$sql .= join( " or ", $sql_where );
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !isset($new_event) )
{
@ -59,7 +52,6 @@ elseif ( $eids )
$new_event['Notes'] = "";
}
}
mysql_free_result( $result );
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -24,30 +24,19 @@ if ( !canView( 'Events' ) )
return;
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
if ( $fid )
{
$result = mysql_query( "select * from Frames where EventId = '$eid' and FrameId = '$fid'" );
if ( !$result )
die( mysql_error() );
if ( !($frame = mysql_fetch_assoc( $result )) )
$sql = "select * from Frames where EventId = '$eid' and FrameId = '$fid'";
if ( !($frame = dbFetchOne( $sql )) )
{
$frame = array( 'FrameId'=>$fid, 'Type'=>'Normal', 'Score'=>0 );
}
mysql_free_result( $result );
}
else
{
$result = mysql_query( "select * from Frames where EventId = '$eid' and Score = '".$event['MaxScore']."'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( "select * from Frames where EventId = '$eid' and Score = '".$event['MaxScore']."'" );
$fid = $frame['FrameId'];
}

View File

@ -24,21 +24,10 @@ if ( !canView( 'Events' ) )
return;
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
$sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '$eid' order by FrameId";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$frames[] = $row;
}
mysql_free_result( $result );
$frames = dbFetchAll( $sql );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -23,11 +23,8 @@ if ( !canEdit( 'Monitors' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -25,12 +25,7 @@ if ( !canEdit( 'System' ) )
}
if ( $gid )
{
$sql = "select * from Groups where Id = '$gid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$new_group = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$new_group = dbFetchGroup( $gid );
}
else
{

View File

@ -24,12 +24,10 @@ if ( !canView( 'System' ) )
return;
}
$result = mysql_query( "select * from Groups order by Name" );
if ( !$result )
die( mysql_error() );
$sql = "select * from Groups order by Name";
$groups = array();
$selected = false;
while ( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( $row['Id'] == $cgroup )
{
@ -38,7 +36,7 @@ while ( $row = mysql_fetch_assoc( $result ) )
}
$groups[] = $row;
}
mysql_free_result( $result );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

View File

@ -44,18 +44,10 @@ if ( !isset($tab) )
if ( !empty($mid) )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
if ( ZM_OPT_X10 )
{
$result = mysql_query( "select * from TriggersX10 where MonitorId = '$mid'" );
if ( !$result )
die( mysql_error() );
$x10_monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$x10_monitor = dbFetchOne( "select * from TriggersX10 where MonitorId = '$mid'" );
}
}
else
@ -115,11 +107,7 @@ if ( !isset( $new_monitor ) )
}
if ( !empty($preset) )
{
$result = mysql_query( "select Type, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, MaxFPS, Controllable, ControlId, ControlDevice, ControlAddress, DefaultRate, DefaultScale from MonitorPresets where Id = '$preset'" );
if ( !$result )
die( mysql_error() );
$preset = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$preset = dbFetchOne( "select Type, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, MaxFPS, Controllable, ControlId, ControlDevice, ControlAddress, DefaultRate, DefaultScale from MonitorPresets where Id = '$preset'" );
foreach ( $preset as $name=>$value )
{
if ( isset($value) )
@ -318,11 +306,8 @@ function loadLocations( form )
var option_count = 1;
<?php
$sql = "select * from Controls where Type = '".$monitor['Type']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$control_types = array( ''=>$zmSlangNone );
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
$control_types[$row['Id']] = $row['Name'];
?>
@ -349,7 +334,6 @@ function loadLocations( form )
returnLocationSelect.options.length = option_count;
<?php
}
mysql_free_result( $result );
?>
}
else

View File

@ -23,16 +23,13 @@ if ( !canEdit( 'Monitors' ) )
$view = "error";
return;
}
$result = mysql_query( "select Id,Name from MonitorPresets" );
if ( !$result )
die( mysql_error() );
$sql( "select Id,Name from MonitorPresets" );
$presets = array();
$presets[0] = $zmSlangChoosePreset;
while ( $preset = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $preset )
{
$presets[$preset['Id']] = htmlentities( $preset['Name'] );
}
mysql_free_result( $result );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -24,15 +24,12 @@ if ( !canView( 'System' ) )
return;
}
$result = mysql_query( "select Id,Name from Monitors order by Sequence asc" );
if ( !$result )
die( mysql_error() );
$sql = "select Id,Name from Monitors order by Sequence asc";
$monitors = array();
while ( $monitor = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $monitor )
{
$monitors[] = $monitor;
}
mysql_free_result( $result );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

View File

@ -27,20 +27,13 @@ if ( !canView( 'Stream' ) )
if ( $group )
{
$sql = "select * from Groups where Id = '$group'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $sql );
$group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )";
}
$sql = "select * from Monitors where Function != 'None' $group_sql order by Sequence";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitors = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -48,7 +41,6 @@ while( $row = mysql_fetch_assoc( $result ) )
}
$monitors[] = $row;
}
mysql_free_result( $result );
$rows = intval(((count($monitors)-1)/ZM_WEB_MONTAGE_MAX_COLS)+1);
$cols = intval(ceil(count($monitors)/$rows));

View File

@ -40,11 +40,8 @@ else
{
$sql = "select * from Monitors where Id = '$mid'";
}
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( $sql );
$montage_width = ZM_WEB_MONTAGE_WIDTH?ZM_WEB_MONTAGE_WIDTH:reScale( $monitor['Width'], $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$montage_height = ZM_WEB_MONTAGE_HEIGHT?ZM_WEB_MONTAGE_HEIGHT:reScale( $monitor['Height'], $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );

View File

@ -33,30 +33,19 @@ if ( empty($mode) )
if ( $mid )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
}
elseif ( ZM_OPT_CONTROL )
{
if ( $group )
{
$sql = "select * from Groups where Id = '$group'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $sql );
$group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )";
}
$sql = "select * from Monitors where Function != 'None' and Controllable = 1 $group_sql order by Sequence";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$control_mid = 0;
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAl( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -67,7 +56,6 @@ elseif ( ZM_OPT_CONTROL )
$control_mid = $row['Id'];
}
}
mysql_free_result( $result );
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -176,10 +176,8 @@ if ( $tab == "users" )
<td align="left" class="smallhead"><?= $zmSlangMark ?></td>
</tr>
<?php
$result = mysql_query( "select * from Users" );
if ( !$result )
die( mysql_error() );
while( $row = mysql_fetch_assoc( $result ) )
$sql = "select * from Users";
foreach( dbFetchAll( $sql ) as $row )
{
?>
<tr onMouseOver="this.className='over'" onMouseOut="this.className='out'">
@ -198,7 +196,6 @@ if ( $tab == "users" )
</tr>
<?php
}
mysql_free_result( $result );
?>
<tr><td colspan="12" class="ruled">&nbsp;</td></tr>
<tr><td colspan="12" align="right"><input type="button" value="<?= $zmSlangAddNewUser ?>" class="form" onClick="javascript: newWindow( '<?= $PHP_SELF ?>?view=user&uid=-1', 'zmUser', <?= $jws['user']['w'] ?>, <?= $jws['user']['h'] ?> );"<?php if ( !canEdit( 'System' ) ) { ?> disabled<?php } ?>>&nbsp;<input type="submit" name="delete_btn" value="<?= $zmSlangDelete ?>" class="form" disabled>&nbsp;<input type="button" value="<?= $zmSlangCancel ?>" class="form" onClick="closeWindow();"></td></tr>

View File

@ -23,11 +23,7 @@ if ( !canView( 'Control' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
$zmu_command = getZmuCommand( " -m $mid -B -C -H -O" );
$zmu_output = exec( escapeshellcmd( $zmu_command ) );

View File

@ -25,15 +25,7 @@ if ( !canEdit( 'System' ) )
}
$running = daemonCheck();
$result = mysql_query( "select * from States" );
if ( !$result )
die( mysql_error() );
$states = array();
while( $state = mysql_fetch_assoc( $result ) )
{
$states[] = $state;
}
mysql_free_result( $result );
$states = dbFetchAll( "select * from States" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -23,14 +23,8 @@ if ( !canView( 'Events' ) )
$view = "error";
return;
}
$result = mysql_query( "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' and S.FrameId = '$fid' order by S.ZoneId" );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$stats[] = $row;
}
mysql_free_result( $result );
$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 = '$eid' and S.FrameId = '$fid' order by S.ZoneId";
$stats = dbFetchAll( $sql );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -131,10 +131,8 @@ $chart = array(
$monitors = array();
$monitors_sql = "select * from Monitors order by Sequence asc";
if ( !($result = mysql_query( $monitors_sql )) )
die( mysql_error() );
//srand( 97981 );
while ( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $monitors_sql ) as $row )
{
//if ( empty($row['WebColour']) )
//{
@ -142,7 +140,6 @@ while ( $row = mysql_fetch_assoc( $result ) )
//}
$monitors[$row['Id']] = $row;
}
mysql_free_result( $result );
$range_sql = "select min(E.StartTime) as MinTime, max(E.EndTime) as MaxTime from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(E.StartTime) and not isnull(E.EndTime)";
$events_sql = "select E.Id,E.Name,E.StartTime,E.EndTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId from Events as E inner join Monitors as M on (E.MonitorId = M.Id) where not isnull(StartTime)";
@ -232,10 +229,7 @@ else
if ( !isset($min_time) || !isset($max_time) )
{
// Dynamically determine range
if ( !($result = mysql_query( $range_sql )) )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $range_sql );
if ( !isset($min_time) )
$min_time = $row['MinTime'];
@ -328,10 +322,8 @@ $chart['data']['x']['density'] = $chart['data']['x']['range']/$chart['graph']['w
$mon_event_slots = array();
$mon_frame_slots = array();
if ( !($event_result = mysql_query( $events_sql )) )
die( mysql_error() );
$monitor_ids = array();
while( $event = mysql_fetch_assoc( $event_result ) )
foreach( dbFetchAll( $events_sql ) as $event )
{
if ( !isset($monitor_ids[$event['MonitorId']]) )
$monitor_ids[$event['MonitorId']] = true;
@ -406,9 +398,7 @@ while( $event = mysql_fetch_assoc( $event_result ) )
else
{
$frames_sql = "select F.FrameId,F.Delta,unix_timestamp(F.TimeStamp) as TimeT,F.Score from Frames as F where F.EventId = '".$event['Id']."' and F.Score > 0";
if ( !($frame_result = mysql_query( $frames_sql )) )
die( mysql_error() );
while( $frame = mysql_fetch_assoc( $frame_result ) )
foreach( dbFetchAll( $frames_sql ) as $frame )
{
$frame_time_t = $frame['TimeT'];
$frame_time_t = $start_time_t + $frame['Delta'];
@ -437,11 +427,9 @@ while( $event = mysql_fetch_assoc( $event_result ) )
$chart['data']['y']['hi'] = $frame['Score'];
}
}
mysql_free_result( $frame_result );
}
}
}
mysql_free_result( $event_result );
ksort($monitor_ids,SORT_NUMERIC);
ksort($mon_event_slots,SORT_NUMERIC);
@ -461,10 +449,7 @@ foreach( array_keys($mon_frame_slots) as $monitor_id )
{
$xcount++;
$frames_sql = "select F.FrameId,F.Score from Frames as F where F.EventId = '".$curr_frame_slots[$i]['event']['Id']."' and F.Score > 0 order by F.FrameId limit 0,1";
if ( !($frame_result = mysql_query( $frames_sql )) )
die( mysql_error() );
$curr_frame_slots[$i]['frame'] = mysql_fetch_assoc( $frame_result );
mysql_free_result( $frame_result );
$curr_frame_slots[$i]['frame'] = dbFetchOne( $frame_sql );
}
}
}

View File

@ -23,16 +23,13 @@ if ( !canEdit( 'System' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Users where Id = '$uid'" );
if ( !$result )
die( mysql_error() );
if ( !($db_user = mysql_fetch_assoc( $result )) )
$sql = "select * from Users where Id = '$uid'";
if ( !($db_user = dbFetchOne( $sql )) )
{
$db_user = array();
$db_user['Username'] = $zmSlangNewUser;
$db_user['Enabled'] = 1;
}
mysql_free_result( $result );
$new_user = $db_user;

View File

@ -33,11 +33,7 @@ else
$mid_sql = '';
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultRate,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
if ( !isset( $rate ) )
$rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE );

View File

@ -23,11 +23,8 @@ if ( !canView( 'Stream' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
if ( !isset($control) )
{

View File

@ -25,11 +25,7 @@ if ( !canView( 'Stream' ) )
}
$sql = "select C.*, M.* from Monitors as M left join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( $sql );
$showControls = ( ZM_OPT_CONTROL && $monitor['Controllable'] && canView( 'Control' ) );

View File

@ -38,11 +38,7 @@ if ( ZM_WEB_REFRESH_METHOD == "http" )
header("Refresh: ".ZM_WEB_REFRESH_EVENTS."; URL=$PHP_SELF?view=watchevents&mid=$mid&max_events=".MAX_EVENTS );
noCacheHeaders();
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
@ -117,12 +113,9 @@ window.setTimeout( "window.location.replace( '<?= "$PHP_SELF?view=watchevents&mi
$sql = "select E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.AvgScore,E.MaxScore from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Id = '$mid' and E.Archived = 0";
$sql .= " order by $sort_column $sort_order";
$sql .= " limit 0,$max_events";
$result = mysql_query( $sql );
if ( !$result )
{
die( mysql_error() );
}
$n_events = mysql_num_rows( $result );
$events = dbFetchAll( $sql );
$n_events = count( $events );
?>
<tr>
<td width="30%"align="left" class="text"><b><?= sprintf( $zmClangLastEvents, $n_events, strtolower( zmVlang( $zmVlangEvent, $n_events ) ) ) ?></b></td>
@ -141,7 +134,7 @@ $n_events = mysql_num_rows( $result );
<td class="text"><input type="checkbox" name="toggle_check" value="1" onClick="toggleCheck( this, 'mark_eids' );"<?php if ( !canEdit( 'Events' ) ) { ?> disabled<?php } ?>></td>
</tr>
<?php
while( $event = mysql_fetch_assoc( $result ) )
foreach ( $events as $event )
{
?>
<tr bgcolor="#FFFFFF">
@ -155,7 +148,6 @@ while( $event = mysql_fetch_assoc( $result ) )
</tr>
<?php
}
mysql_free_result( $result );
?>
</table></td></tr>
</table></td>

View File

@ -33,11 +33,7 @@ if ( empty($mode) )
}
$sql = "select M.*,C.CanMoveMap,C.CanMoveRel,C.CanMoveCon from Monitors as M left join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchOne( $sql );
if ( !isset( $scale ) )
$scale = reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );

View File

@ -32,11 +32,7 @@ if ( empty($mode) )
$mode = "still";
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
if ( !isset( $scale ) )
$scale = $monitor['DefaultScale'] * ZM_WEB_DEFAULT_SCALE;

View File

@ -30,11 +30,7 @@ if ( ZM_WEB_REFRESH_METHOD == "http" )
header("Refresh: ".ZM_POS_REFRESH."; URL=$PHP_SELF?view=watchpos&mid=$mid" );
noCacheHeaders();
$result = mysql_query( "select * from Events where MonitorId = '$mid' order by Id desc limit 1" );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( "select * from Events where MonitorId = '$mid' order by Id desc limit 1" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

@ -38,24 +38,17 @@ $marker = array(
"height"=>7,
);
$result = mysql_query( "select *, Units-1 as UnitsIndex, CheckMethod-1 as CheckMethodIndex from ZonePresets order by Id asc" );
if ( !$result )
die( mysql_error() );
$sql( "select *, Units-1 as UnitsIndex, CheckMethod-1 as CheckMethodIndex from ZonePresets order by Id asc" );
$presets = array();
$preset_names = array();
$preset_names[0] = $zmSlangChoosePreset;
while ( $preset = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $preset )
{
$preset_names[$preset['Id']] = $preset['Name'];
$presets[] = $preset;
}
mysql_free_result( $result );
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor ( $mid );
$min_x = 0;
$max_x = $monitor['Width']-1;
@ -66,11 +59,7 @@ if ( !isset($new_zone) )
{
if ( $zid > 0 )
{
$result = mysql_query( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
if ( !$result )
die( mysql_error() );
$zone = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$zone = dbFetchOne( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
}
else
{

View File

@ -27,17 +27,11 @@ chdir( ZM_DIR_IMAGES );
$status = exec( escapeshellcmd( getZmuCommand( " -m $mid -z" ) ) );
chdir( '..' );
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
$result = mysql_query( "select * from Zones where MonitorId = '$mid' order by Area desc" );
if ( !$result )
die( mysql_error() );
$sql = "select * from Zones where MonitorId = '$mid' order by Area desc";
$zones = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( $row['Points'] = coordsToPoints( $row['Coords'] ) )
{
@ -45,7 +39,6 @@ while( $row = mysql_fetch_assoc( $result ) )
$zones[] = $row;
}
}
mysql_free_result( $result );
$image = $monitor['Name']."-Zones.jpg";

View File

@ -955,20 +955,14 @@ else
if ( canEdit( 'Control' ) )
{
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."' and Preset = '".$preset."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$row = dbFetchOne( $sql );
if ( $new_label != $row['Label'] )
{
if ( $new_label )
$sql = "replace into ControlPresets ( MonitorId, Preset, Label ) values ( '".$monitor['Id']."', '".$preset."', '".addslashes($new_label)."' )";
else
$sql = "delete from ControlPresets where MonitorId = '".$monitor['Id']."' and Preset = '".$preset."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
dbQuery( $sql );
$refresh_parent = true;
}
}

View File

@ -19,13 +19,13 @@ $refresh_parent = false;
// Event scope actions, edit permissions required
if ( $_REQUEST['action'] == "rename" && $_REQUEST['id'] && $_REQUEST['eventName'] )
{
dbQuery( "update Events set Name = '".mysql_real_escape_string($_REQUEST['eventName'])."' where Id = '".mysql_real_escape_string($_REQUEST['id'])."'" );
dbQuery( "update Events set Name = '".dbEscape($_REQUEST['eventName'])."' where Id = '".dbEscape($_REQUEST['id'])."'" );
}
else if ( $_REQUEST['action'] == "eventdetail" )
{
if ( $_REQUEST['id'] )
{
dbQuery( "update Events set Cause = '".mysql_real_escape_string($_REQUEST['new_event']['Cause'])."', Notes = '".mysql_real_escape_string($_REQUEST['new_event']['Notes'])."' where Id = '".mysql_real_escape_string($_REQUEST['id'])."'" );
dbQuery( "update Events set Cause = '".dbEscape($_REQUEST['new_event']['Cause'])."', Notes = '".dbEscape($_REQUEST['new_event']['Notes'])."' where Id = '".dbEscape($_REQUEST['id'])."'" );
$refresh_parent = true;
}
}
@ -35,7 +35,7 @@ elseif ( $_REQUEST['action'] == "archive" || $_REQUEST['action'] == "unarchive"
if ( $_REQUEST['id'] )
{
dbQuery( "update Events set Archived = ".$archive_val." where Id = '".mysql_real_escape_string($_REQUEST['id'])."'" );
dbQuery( "update Events set Archived = ".$archive_val." where Id = '".dbEscape($_REQUEST['id'])."'" );
}
elseif ( $mark_eids || $mark_eid )
{

View File

@ -204,28 +204,21 @@ function collectData( $spec )
$limit = $_REQUEST['count'];
if ( !empty( $limit ) )
$sql .= " limit ".$limit;
$result = mysql_query( $sql );
if ( !$result )
{
error_log( $sql );
error_log( mysql_error() );
}
if ( isset($limit) && $limit == 1 )
{
$sql_data = mysql_fetch_assoc( $result );
$sql_data = dbFetchOne( $sql );
$data = array_merge( $data, $sql_data );
}
else
{
$count = 0;
while ( $sql_data = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $sql_data )
{
$data[] = $sql_data;
if ( ++$count >= $limit )
break;
}
}
mysql_free_result( $result );
}
#print_r( $data );
return( $data );

View File

@ -42,11 +42,7 @@ $event_counts = array(
$running = daemonCheck();
$status = $running?$zmSlangRunning:$zmSlangStopped;
$sql = "select * from Groups where Name = 'Mobile'";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
if ( $group = dbFetchOne( "select * from Groups where Id = '$cgroup'" ) )
if ( $group = dbFetchOne( "select * from Groups where Name = 'Mobile'" ) )
$group_ids = array_flip(split( ',', $group['MonitorIds'] ));
$db_now = strftime( STRF_FMT_DATETIME_DB );
@ -87,7 +83,6 @@ for ( $i = 0; $i < count($monitors); $i++ )
}
$monitors[$i] = array_merge( $monitors[$i], $counts );
}
mysql_free_result( $result );
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

View File

@ -19,16 +19,12 @@
//
$sql = "select * from Devices where Type = 'X10' order by Name";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$devices = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach ( dbFetchAll( $sql ) as $row )
{
$row['Status'] = getDeviceStatusX10( $row['KeyString'] );
$devices[] = $row;
}
mysql_free_result( $result );
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

View File

@ -39,27 +39,15 @@ else
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
if ( $fid )
{
$result = mysql_query( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
}
elseif ( isset( $fid ) )
{
$result = mysql_query( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
$fid = $frame['FrameId'];
}
@ -67,32 +55,26 @@ parseSort( true, '&amp;' );
parseFilter( true, '&amp;' );
$sql = "select E.* from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sort_column ".($sort_order=='asc'?'<=':'>=')." '".$event[$sort_field]."'$filter_sql$mid_sql order by $sort_column ".($sort_order=='asc'?'desc':'asc');
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
$result = dbQuery( $sql );
while ( $row = dbFetchNext( $result ) )
{
if ( $row[Id] == $eid )
{
$prev_event = mysql_fetch_assoc( $result );
$prev_event = dbFetchNext( $result );
break;
}
}
mysql_free_result( $result );
$sql = "select E.* from Events as E inner join Monitors as M on E.MonitorId = M.Id where $sort_column ".($sort_order=='asc'?'>=':'<=')." '".$event[$sort_field]."'$filter_sql$mid_sql order by $sort_column $sort_order";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
$result = dbQuery( $sql );
while ( $row = dbFetchNext( $result ) )
{
if ( $row[Id] == $eid )
{
$next_event = mysql_fetch_assoc( $result );
$next_event = dbFetchNext( $result );
break;
}
}
mysql_free_result( $result );
$frames_per_page = 15;
$frames_per_line = 3;
@ -222,18 +204,14 @@ $sql = "select * from Frames where EventID = '$eid'";
if ( $paged && !empty($page) )
$sql .= " and FrameId between $lo_frame_id and $hi_frame_id";
$sql .= " order by FrameId";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$alarm_frames = array();
while( $row = mysql_fetch_assoc( $result ) )
foreach ( dbFetchAll( $sql ) as $row )
{
if ( $row['Type'] == 'Alarm' )
{
$alarm_frames[$row['FrameId']] = $row;
}
}
mysql_free_result( $result );
?>
<table style="width: 100%">
<?php

View File

@ -23,17 +23,9 @@ if ( !canView( 'Events' ) )
$view = "error";
return;
}
$result = mysql_query( "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E, Monitors as M where E.Id = '$eid' and E.MonitorId = M.Id" );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E, Monitors as M where E.Id = '$eid' and E.MonitorId = M.Id" );
$frame = dbFetchOne( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
$result = mysql_query( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$fid = $frame['FrameId'];
$scale = getDeviceScale( $event['Width'], $event['Height'], 2 );

View File

@ -25,22 +25,14 @@ if ( !canView( 'Events' ) )
}
$sql = "select * from Monitors";
if ( !($result = mysql_query( $sql )) )
die( mysql_error() );
while( $row = mysql_fetch_assoc( $result ) )
foreach ( dbFetchAll( $sql ) as $row )
{
$monitors[$row[Id]] = $row;
}
mysql_free_result( $result );
if ( $filter_name )
{
$result = mysql_query( "select * from Filters where Name = '$filter_name'" );
if ( !$result )
die( mysql_error() );
$filter_data = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$filter_data = dbFetchOne( "select * from Filters where Name = '$filter_name'" );
if ( !empty($filter_data) )
{
foreach( split( '&', $filter_data['Query'] ) as $filter_parm )
@ -110,11 +102,7 @@ elseif ( !empty( $limit ) )
<title><?= ZM_WEB_TITLE_PREFIX ?> - <?= $zmSlangEvents ?></title>
<link rel="stylesheet" href="zm_xhtml_styles.css" type="text/css"/>
<?php
if ( !($result = mysql_query( $count_sql )) )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$n_events = $row['EventCount'];
$n_events = dbFetchOne( $count_sql, 'EventCount' );
if ( !empty($limit) && $n_events > $limit )
{
$n_events = $limit;
@ -228,9 +216,7 @@ if ( !empty($limit) && $n_events > $limit )
<?php
flush();
$count = 0;
if ( !($result = mysql_query( $events_sql )) )
die( mysql_error() );
while( $event = mysql_fetch_assoc( $result ) )
foreach ( dbFetchAll( $events_sql ) as $event )
{
if ( ($count++%$device_lines) == 0 )
{
@ -255,7 +241,6 @@ if ( !empty($limit) && $n_events > $limit )
</tr>
<?php
}
mysql_free_result( $result );
?>
</table>
<p align="center"><a href="<?= $PHP_SELF ?>?view=console"><?= $zmSlangConsole ?></a></p>

View File

@ -24,14 +24,11 @@ if ( !canView( 'Events' ) )
return;
}
$filter_names = array();
$result = mysql_query( "select * from Filters order by Name" );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
$sql = "select * from Filters order by Name";
foreach( dbFetchAll( $sql ) as $row )
{
$filter_names[$row['Name']] = $row['Name'];
}
mysql_free_result( $result );
?>
<html xmlns="http://www.w3.org/1999/xhtml">

View File

@ -24,27 +24,15 @@ if ( !canView( 'Events' ) )
return;
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultScale from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
if ( $fid )
{
$result = mysql_query( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
}
else
{
$result = mysql_query( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame = dbFetchOne( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
$fid = $frame['FrameId'];
}

View File

@ -23,11 +23,7 @@ if ( !canEdit( 'Monitors' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
?>
<html xmlns="http://www.w3.org/1999/xhtml">

View File

@ -21,17 +21,13 @@
$images_per_line = 2;
$sql = "select * from Groups where Name = 'Mobile'";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$group = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$group = dbFetchOne( $sql );
$result = mysql_query( "select * from Monitors where Function != 'None' order by Sequence" );
$sql = "select * from Monitors where Function != 'None' order by Sequence";
$monitors = array();
$max_width = 0;
$max_height = 0;
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -46,7 +42,6 @@ while( $row = mysql_fetch_assoc( $result ) )
if ( $max_height < $row['Height'] ) $max_height = $row['Height'];
$monitors[] = $row;
}
mysql_free_result( $result );
?>
<html xmlns="http://www.w3.org/1999/xhtml">

View File

@ -25,14 +25,7 @@ if ( !canEdit( 'System' ) )
}
$running = daemonCheck();
$result = mysql_query( "select * from States" );
if ( !$result )
die( mysql_error() );
while( $state = mysql_fetch_assoc( $result ) )
{
$states[] = $state;
}
mysql_free_result( $result );
$status = dbFetchAll( "select * from States" );
?>
<html xmlns="http://www.w3.org/1999/xhtml">

View File

@ -33,11 +33,7 @@ else
$mid_sql = '';
}
$sql = "select E.*,M.Name as MonitorName,M.Width,M.Height,M.DefaultRate from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event = dbFetchOne( $sql );
$device_width = (isset($device)&&!empty($device['width']))?$device['width']:DEVICE_WIDTH;
$device_height = (isset($device)&&!empty($device['height']))?$device['height']:DEVICE_HEIGHT;

View File

@ -23,11 +23,8 @@ if ( !canView( 'Stream' ) )
$view = "error";
return;
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$monitor = dbFetchMonitor( $mid );
$zmu_command = getZmuCommand( " -m $mid -s -f" );
$zmu_output = exec( escapeshellcmd( $zmu_command ) );
@ -61,12 +58,12 @@ $was_alarmed = ( $last_status == STATE_ALARM || $last_status == STATE_ALERT );
$new_alarm = ( $is_alarmed && !$was_alarmed );
$old_alarm = ( !$is_alarmed && $was_alarmed );
$result = mysql_query( "select * from Monitors where Function != 'None' order by Sequence" );
$sql = "select * from Monitors where Function != 'None' order by Sequence";
$monitors = array();
$mon_idx = 0;
$max_width = 0;
$max_height = 0;
while( $row = mysql_fetch_assoc( $result ) )
foreach( dbFetchAll( $sql ) as $row )
{
if ( !visibleMonitor( $row['Id'] ) )
{
@ -78,7 +75,6 @@ while( $row = mysql_fetch_assoc( $result ) )
if ( $max_height < $row['Height'] ) $max_height = $row['Height'];
$monitors[] = $row;
}
mysql_free_result( $result );
//$monitor = $monitors[$mon_idx];
$next_mid = $mon_idx==(count($monitors)-1)?$monitors[0]['Id']:$monitors[$mon_idx+1]['Id'];