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

View File

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

View File

@ -306,15 +306,11 @@ function controlPresets( $monitor )
define( "MAX_PRESETS", "12" ); define( "MAX_PRESETS", "12" );
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'"; $sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$labels = array(); $labels = array();
while( $row = mysql_fetch_assoc( $result ) ) foreach( dbFetchAll( $sql ) as $row )
{ {
$labels[$row['Preset']] = $row['Label']; $labels[$row['Preset']] = $row['Label'];
} }
mysql_free_result( $result );
$preset_break = (int)(($monitor['NumPresets']+1)/((int)(($monitor['NumPresets']-1)/MAX_PRESETS)+1)); $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'" ); 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 ) function dbQuery( $sql )
{ {
if ( dbDebug( $sql ) ) if ( dbDebug( $sql ) )
@ -91,6 +99,12 @@ function dbFetch( $sql, $col=false )
return( dbFetchAll( $sql, $col ) ); 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 ) function dbNumRows( $sql )
{ {
dbDebug( $sql ); dbDebug( $sql );
@ -100,14 +114,15 @@ function dbNumRows( $sql )
return( mysql_num_rows( $result ) ); return( mysql_num_rows( $result ) );
} }
function dbInsertId()
{
return( mysql_insert_id() );
}
function getEnumValues( $table, $column ) function getEnumValues( $table, $column )
{ {
$enum_values = array(); $enum_values = array();
$result = mysql_query( "DESCRIBE $table $column" ); $row = dbFetchOne( "DESCRIBE $table $column" );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc($result);
mysql_free_result( $result );
preg_match_all( "/'([^']+)'/", $row['Type'], $enum_matches ); preg_match_all( "/'([^']+)'/", $row['Type'], $enum_matches );
$enum_values = $enum_matches[1]; $enum_values = $enum_matches[1];
return( $enum_values ); return( $enum_values );
@ -121,44 +136,39 @@ function getSetValues( $table, $column )
function getUniqueValues( $table, $column, $as_string=1 ) function getUniqueValues( $table, $column, $as_string=1 )
{ {
$values = array(); $values = array();
$result = mysql_query( "SELECT DISTINCT $column FROM $table WHERE (NOT ISNULL($column) AND $column != '') ORDER BY $column" ); $sql = "SELECT DISTINCT $column FROM $table WHERE (NOT ISNULL($column) AND $column != '') ORDER BY $column";
if ( $result ) foreach( dbFetchAll( $sql ) as $row )
{
while ( $row = mysql_fetch_array($result) )
{ {
if ( $as_string ) if ( $as_string )
$values[$row[0]] = $row[0]; $values[$row[0]] = $row[0];
else else
$values = $row[0]; $values = $row[0];
} }
mysql_free_result( $result );
}
else
{
echo mysql_error();
}
return( $values ); return( $values );
} }
function getTableColumns( $table, $as_string=1 ) function getTableColumns( $table, $as_string=1 )
{ {
$columns = array(); $columns = array();
$result = mysql_query( "DESCRIBE $table" ); $sql = "DESCRIBE $table";
if ( $result ) foreach( dbFetchAll( $sql ) as $row )
{
while( $row = mysql_fetch_assoc($result) )
{ {
if ( $as_string ) if ( $as_string )
$columns[$row[Field]] = $row[Type]; $columns[$row[Field]] = $row[Type];
else else
$columns[] = $row[Type]; $columns[] = $row[Type];
} }
mysql_free_result( $result );
}
else
{
echo mysql_error();
}
return( $columns ); 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; global $zmSlangYes, $zmSlangNo, $zmSlangNoFramesRecorded;
$sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '".$event['Id']."' order by FrameId"; $sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '".$event['Id']."' order by FrameId";
$result = mysql_query( $sql ); $frames = dbFetchAll( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$frames[] = $row;
}
mysql_free_result( $result );
ob_start(); ob_start();
exportHeader( $zmSlangFrames." ".$event['Id'] ); exportHeader( $zmSlangFrames." ".$event['Id'] );
@ -188,10 +181,7 @@ function exportFileList( $eid )
if ( canView( 'Events' ) && $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'"; $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 )) ) $event = dbFetchOne( $sql );
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$event_path = getEventPath( $event ); $event_path = getEventPath( $event );
$files = array(); $files = array();

View File

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

View File

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

View File

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

View File

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

View File

@ -24,22 +24,14 @@ if ( !canEdit( 'Monitors' ) )
return; 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'" ); $monitor = dbFetchOne( "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 );
$sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'"; $sql = "select * from ControlPresets where MonitorId = '".$monitor['Id']."'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$labels = array(); $labels = array();
while( $row = mysql_fetch_assoc( $result ) ) foreach( dbFetchAll( $sql ) as $row )
{ {
$labels[$row['Preset']] = $row['Label']; $labels[$row['Preset']] = $row['Label'];
} }
mysql_free_result( $result );
$presets = array(); $presets = array();
for ( $i = 1; $i <= $monitor['NumPresets']; $i++ ) for ( $i = 1; $i <= $monitor['NumPresets']; $i++ )

View File

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

View File

@ -25,16 +25,12 @@ if ( !canView( 'Devices' ) )
} }
$sql = "select * from Devices where Type = 'X10' order by Name"; $sql = "select * from Devices where Type = 'X10' order by Name";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$devices = array(); $devices = array();
while( $row = mysql_fetch_assoc( $result ) ) foreach( dbFetchAll( $sql ) as $row )
{ {
$row['Status'] = getDeviceStatusX10( $row['KeyString'] ); $row['Status'] = getDeviceStatusX10( $row['KeyString'] );
$devices[] = $row; $devices[] = $row;
} }
mysql_free_result( $result );
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <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"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
parseSort(); parseSort();
parseFilter( $filter ); 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'); $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 ); $result = dbQuery( $sql );
if ( !$result ) foreach( dbFetchAll( $sql ) as $row )
die( mysql_error() ); while ( $row = dbFetchNext( $result ) )
while ( $row = mysql_fetch_assoc( $result ) )
{ {
if ( $row['Id'] == $eid ) if ( $row['Id'] == $eid )
{ {
$prev_event = mysql_fetch_assoc( $result ); $prev_event = dbFetchNext( $result );
break; 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"; $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 ); $result = dbQuery( $sql );
if ( !$result ) while ( $row = dbFetchNext( $result ) )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{ {
if ( $row['Id'] == $eid ) if ( $row['Id'] == $eid )
{ {
$next_event = mysql_fetch_assoc( $result ); $next_event = dbFetchNext( $result );
break; break;
} }
} }
mysql_free_result( $result );
if ( !isset( $rate ) ) if ( !isset( $rate ) )
$rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE ); $rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE );
@ -93,11 +84,7 @@ $paged = $event['Frames'] > $frames_per_page;
if ( $mode == "stream" ) if ( $mode == "stream" )
{ {
$sql = "select max(Delta)-min(Delta) as Duration from Frames where EventId = '$eid'"; $sql = "select max(Delta)-min(Delta) as Duration from Frames where EventId = '$eid'";
$result = mysql_query( $sql ); $frame_data = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$frame_data = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$frame_data['RealDuration'] = ($frame_data['Duration']*RATE_BASE)/$rate; $frame_data['RealDuration'] = ($frame_data['Duration']*RATE_BASE)/$rate;
$panel_init_color = '#eeeeee'; $panel_init_color = '#eeeeee';
@ -461,15 +448,11 @@ else
$sql .= " order by FrameId"; $sql .= " order by FrameId";
if ( $paged && !empty($page) ) if ( $paged && !empty($page) )
$sql .= " limit $lo_frame_id, ".($hi_frame_id-$lo_frame_id); $sql .= " limit $lo_frame_id, ".($hi_frame_id-$lo_frame_id);
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$frames = array(); $frames = array();
while( $frame = mysql_fetch_assoc( $result ) ) foreach( dbFetchAll( $sql ) as $frame )
{ {
$frames[$frame['FrameId']] = $frame; $frames[$frame['FrameId']] = $frame;
} }
mysql_free_result( $result );
?> ?>
<tr><td><div style="text-align: center"> <tr><td><div style="text-align: center">
<?php <?php

View File

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

View File

@ -24,30 +24,19 @@ if ( !canView( 'Events' ) )
return; 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'"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( $fid ) if ( $fid )
{ {
$result = mysql_query( "select * from Frames where EventId = '$eid' and FrameId = '$fid'" ); $sql = "select * from Frames where EventId = '$eid' and FrameId = '$fid'";
if ( !$result ) if ( !($frame = dbFetchOne( $sql )) )
die( mysql_error() );
if ( !($frame = mysql_fetch_assoc( $result )) )
{ {
$frame = array( 'FrameId'=>$fid, 'Type'=>'Normal', 'Score'=>0 ); $frame = array( 'FrameId'=>$fid, 'Type'=>'Normal', 'Score'=>0 );
} }
mysql_free_result( $result );
} }
else else
{ {
$result = mysql_query( "select * from Frames where EventId = '$eid' and Score = '".$event['MaxScore']."'" ); $frame = dbFetchOne( "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']; $fid = $frame['FrameId'];
} }

View File

@ -24,21 +24,10 @@ if ( !canView( 'Events' ) )
return; 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'"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '$eid' order by FrameId"; $sql = "select *, unix_timestamp( TimeStamp ) as UnixTimeStamp from Frames where EventID = '$eid' order by FrameId";
$result = mysql_query( $sql ); $frames = dbFetchAll( $sql );
if ( !$result )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{
$frames[] = $row;
}
mysql_free_result( $result );
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,11 +40,8 @@ else
{ {
$sql = "select * from Monitors where Id = '$mid'"; $sql = "select * from Monitors where Id = '$mid'";
} }
$result = mysql_query( $sql );
if ( !$result ) $monitor = dbFetchOne( $sql );
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$montage_width = ZM_WEB_MONTAGE_WIDTH?ZM_WEB_MONTAGE_WIDTH:reScale( $monitor['Width'], $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ); $montage_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 ); $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 ) if ( $mid )
{ {
$result = mysql_query( "select * from Monitors where Id = '$mid'" ); $monitor = dbFetchMonitor( $mid );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
} }
elseif ( ZM_OPT_CONTROL ) elseif ( ZM_OPT_CONTROL )
{ {
if ( $group ) if ( $group )
{ {
$sql = "select * from Groups where Id = '$group'"; $sql = "select * from Groups where Id = '$group'";
$result = mysql_query( $sql ); $row = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )"; $group_sql = "and find_in_set( Id, '".$row['MonitorIds']."' )";
} }
$sql = "select * from Monitors where Function != 'None' and Controllable = 1 $group_sql order by Sequence"; $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; $control_mid = 0;
while( $row = mysql_fetch_assoc( $result ) ) foreach( dbFetchAl( $sql ) as $row )
{ {
if ( !visibleMonitor( $row['Id'] ) ) if ( !visibleMonitor( $row['Id'] ) )
{ {
@ -67,7 +56,6 @@ elseif ( ZM_OPT_CONTROL )
$control_mid = $row['Id']; $control_mid = $row['Id'];
} }
} }
mysql_free_result( $result );
} }
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!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> <td align="left" class="smallhead"><?= $zmSlangMark ?></td>
</tr> </tr>
<?php <?php
$result = mysql_query( "select * from Users" ); $sql = "select * from Users";
if ( !$result ) foreach( dbFetchAll( $sql ) as $row )
die( mysql_error() );
while( $row = mysql_fetch_assoc( $result ) )
{ {
?> ?>
<tr onMouseOver="this.className='over'" onMouseOut="this.className='out'"> <tr onMouseOver="this.className='over'" onMouseOut="this.className='out'">
@ -198,7 +196,6 @@ if ( $tab == "users" )
</tr> </tr>
<?php <?php
} }
mysql_free_result( $result );
?> ?>
<tr><td colspan="12" class="ruled">&nbsp;</td></tr> <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> <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"; $view = "error";
return; return;
} }
$result = mysql_query( "select * from Monitors where Id = '$mid'" ); $monitor = dbFetchMonitor( $mid );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$zmu_command = getZmuCommand( " -m $mid -B -C -H -O" ); $zmu_command = getZmuCommand( " -m $mid -B -C -H -O" );
$zmu_output = exec( escapeshellcmd( $zmu_command ) ); $zmu_output = exec( escapeshellcmd( $zmu_command ) );

View File

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

View File

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

View File

@ -131,10 +131,8 @@ $chart = array(
$monitors = array(); $monitors = array();
$monitors_sql = "select * from Monitors order by Sequence asc"; $monitors_sql = "select * from Monitors order by Sequence asc";
if ( !($result = mysql_query( $monitors_sql )) )
die( mysql_error() );
//srand( 97981 ); //srand( 97981 );
while ( $row = mysql_fetch_assoc( $result ) ) foreach( dbFetchAll( $monitors_sql ) as $row )
{ {
//if ( empty($row['WebColour']) ) //if ( empty($row['WebColour']) )
//{ //{
@ -142,7 +140,6 @@ while ( $row = mysql_fetch_assoc( $result ) )
//} //}
$monitors[$row['Id']] = $row; $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)"; $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)"; $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) ) if ( !isset($min_time) || !isset($max_time) )
{ {
// Dynamically determine range // Dynamically determine range
if ( !($result = mysql_query( $range_sql )) ) $row = dbFetchOne( $range_sql );
die( mysql_error() );
$row = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( !isset($min_time) ) if ( !isset($min_time) )
$min_time = $row['MinTime']; $min_time = $row['MinTime'];
@ -328,10 +322,8 @@ $chart['data']['x']['density'] = $chart['data']['x']['range']/$chart['graph']['w
$mon_event_slots = array(); $mon_event_slots = array();
$mon_frame_slots = array(); $mon_frame_slots = array();
if ( !($event_result = mysql_query( $events_sql )) )
die( mysql_error() );
$monitor_ids = array(); $monitor_ids = array();
while( $event = mysql_fetch_assoc( $event_result ) ) foreach( dbFetchAll( $events_sql ) as $event )
{ {
if ( !isset($monitor_ids[$event['MonitorId']]) ) if ( !isset($monitor_ids[$event['MonitorId']]) )
$monitor_ids[$event['MonitorId']] = true; $monitor_ids[$event['MonitorId']] = true;
@ -406,9 +398,7 @@ while( $event = mysql_fetch_assoc( $event_result ) )
else 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"; $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 )) ) foreach( dbFetchAll( $frames_sql ) as $frame )
die( mysql_error() );
while( $frame = mysql_fetch_assoc( $frame_result ) )
{ {
$frame_time_t = $frame['TimeT']; $frame_time_t = $frame['TimeT'];
$frame_time_t = $start_time_t + $frame['Delta']; $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']; $chart['data']['y']['hi'] = $frame['Score'];
} }
} }
mysql_free_result( $frame_result );
} }
} }
} }
mysql_free_result( $event_result );
ksort($monitor_ids,SORT_NUMERIC); ksort($monitor_ids,SORT_NUMERIC);
ksort($mon_event_slots,SORT_NUMERIC); ksort($mon_event_slots,SORT_NUMERIC);
@ -461,10 +449,7 @@ foreach( array_keys($mon_frame_slots) as $monitor_id )
{ {
$xcount++; $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"; $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 )) ) $curr_frame_slots[$i]['frame'] = dbFetchOne( $frame_sql );
die( mysql_error() );
$curr_frame_slots[$i]['frame'] = mysql_fetch_assoc( $frame_result );
mysql_free_result( $frame_result );
} }
} }
} }

View File

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

View File

@ -33,11 +33,7 @@ else
$mid_sql = ''; $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"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( !isset( $rate ) ) if ( !isset( $rate ) )
$rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE ); $rate = reScale( RATE_BASE, $event['DefaultRate'], ZM_WEB_DEFAULT_RATE );

View File

@ -23,11 +23,8 @@ if ( !canView( 'Stream' ) )
$view = "error"; $view = "error";
return; return;
} }
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result ) $monitor = dbFetchMonitor( $mid );
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( !isset($control) ) 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'"; $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 ); $monitor = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$showControls = ( ZM_OPT_CONTROL && $monitor['Controllable'] && canView( 'Control' ) ); $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 ); header("Refresh: ".ZM_WEB_REFRESH_EVENTS."; URL=$PHP_SELF?view=watchevents&mid=$mid&max_events=".MAX_EVENTS );
noCacheHeaders(); noCacheHeaders();
$result = mysql_query( "select * from Monitors where Id = '$mid'" ); $monitor = dbFetchMonitor( $mid );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!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 = "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 .= " order by $sort_column $sort_order";
$sql .= " limit 0,$max_events"; $sql .= " limit 0,$max_events";
$result = mysql_query( $sql );
if ( !$result ) $events = dbFetchAll( $sql );
{ $n_events = count( $events );
die( mysql_error() );
}
$n_events = mysql_num_rows( $result );
?> ?>
<tr> <tr>
<td width="30%"align="left" class="text"><b><?= sprintf( $zmClangLastEvents, $n_events, strtolower( zmVlang( $zmVlangEvent, $n_events ) ) ) ?></b></td> <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> <td class="text"><input type="checkbox" name="toggle_check" value="1" onClick="toggleCheck( this, 'mark_eids' );"<?php if ( !canEdit( 'Events' ) ) { ?> disabled<?php } ?>></td>
</tr> </tr>
<?php <?php
while( $event = mysql_fetch_assoc( $result ) ) foreach ( $events as $event )
{ {
?> ?>
<tr bgcolor="#FFFFFF"> <tr bgcolor="#FFFFFF">
@ -155,7 +148,6 @@ while( $event = mysql_fetch_assoc( $result ) )
</tr> </tr>
<?php <?php
} }
mysql_free_result( $result );
?> ?>
</table></td></tr> </table></td></tr>
</table></td> </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'"; $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 ); $monitor = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( !isset( $scale ) ) if ( !isset( $scale ) )
$scale = reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ); $scale = reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE );

View File

@ -32,11 +32,7 @@ if ( empty($mode) )
$mode = "still"; $mode = "still";
} }
$result = mysql_query( "select * from Monitors where Id = '$mid'" ); $monitor = dbFetchMonitor( $mid );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( !isset( $scale ) ) if ( !isset( $scale ) )
$scale = $monitor['DefaultScale'] * ZM_WEB_DEFAULT_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" ); header("Refresh: ".ZM_POS_REFRESH."; URL=$PHP_SELF?view=watchpos&mid=$mid" );
noCacheHeaders(); noCacheHeaders();
$result = mysql_query( "select * from Events where MonitorId = '$mid' order by Id desc limit 1" ); $event = dbFetchOne( "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 );
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

View File

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

View File

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

View File

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

View File

@ -19,13 +19,13 @@ $refresh_parent = false;
// Event scope actions, edit permissions required // Event scope actions, edit permissions required
if ( $_REQUEST['action'] == "rename" && $_REQUEST['id'] && $_REQUEST['eventName'] ) 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" ) else if ( $_REQUEST['action'] == "eventdetail" )
{ {
if ( $_REQUEST['id'] ) 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; $refresh_parent = true;
} }
} }
@ -35,7 +35,7 @@ elseif ( $_REQUEST['action'] == "archive" || $_REQUEST['action'] == "unarchive"
if ( $_REQUEST['id'] ) 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 ) elseif ( $mark_eids || $mark_eid )
{ {

View File

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

View File

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

View File

@ -19,16 +19,12 @@
// //
$sql = "select * from Devices where Type = 'X10' order by Name"; $sql = "select * from Devices where Type = 'X10' order by Name";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$devices = array(); $devices = array();
while( $row = mysql_fetch_assoc( $result ) ) foreach ( dbFetchAll( $sql ) as $row )
{ {
$row['Status'] = getDeviceStatusX10( $row['KeyString'] ); $row['Status'] = getDeviceStatusX10( $row['KeyString'] );
$devices[] = $row; $devices[] = $row;
} }
mysql_free_result( $result );
?> ?>
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <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"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( $fid ) if ( $fid )
{ {
$result = mysql_query( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" ); $frame = dbFetchOne( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
} }
elseif ( isset( $fid ) ) elseif ( isset( $fid ) )
{ {
$result = mysql_query( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" ); $frame = dbFetchOne( "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']; $fid = $frame['FrameId'];
} }
@ -67,32 +55,26 @@ parseSort( true, '&amp;' );
parseFilter( 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'); $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 ); $result = dbQuery( $sql );
if ( !$result ) while ( $row = dbFetchNext( $result ) )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{ {
if ( $row[Id] == $eid ) if ( $row[Id] == $eid )
{ {
$prev_event = mysql_fetch_assoc( $result ); $prev_event = dbFetchNext( $result );
break; 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"; $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 ); $result = dbQuery( $sql );
if ( !$result ) while ( $row = dbFetchNext( $result ) )
die( mysql_error() );
while ( $row = mysql_fetch_assoc( $result ) )
{ {
if ( $row[Id] == $eid ) if ( $row[Id] == $eid )
{ {
$next_event = mysql_fetch_assoc( $result ); $next_event = dbFetchNext( $result );
break; break;
} }
} }
mysql_free_result( $result );
$frames_per_page = 15; $frames_per_page = 15;
$frames_per_line = 3; $frames_per_line = 3;
@ -222,18 +204,14 @@ $sql = "select * from Frames where EventID = '$eid'";
if ( $paged && !empty($page) ) if ( $paged && !empty($page) )
$sql .= " and FrameId between $lo_frame_id and $hi_frame_id"; $sql .= " and FrameId between $lo_frame_id and $hi_frame_id";
$sql .= " order by FrameId"; $sql .= " order by FrameId";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$alarm_frames = array(); $alarm_frames = array();
while( $row = mysql_fetch_assoc( $result ) ) foreach ( dbFetchAll( $sql ) as $row )
{ {
if ( $row['Type'] == 'Alarm' ) if ( $row['Type'] == 'Alarm' )
{ {
$alarm_frames[$row['FrameId']] = $row; $alarm_frames[$row['FrameId']] = $row;
} }
} }
mysql_free_result( $result );
?> ?>
<table style="width: 100%"> <table style="width: 100%">
<?php <?php

View File

@ -23,17 +23,9 @@ if ( !canView( 'Events' ) )
$view = "error"; $view = "error";
return; 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" ); $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" );
if ( !$result ) $frame = dbFetchOne( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" );
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$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']; $fid = $frame['FrameId'];
$scale = getDeviceScale( $event['Width'], $event['Height'], 2 ); $scale = getDeviceScale( $event['Width'], $event['Height'], 2 );

View File

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

View File

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

View File

@ -24,27 +24,15 @@ if ( !canView( 'Events' ) )
return; 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'"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
if ( $fid ) if ( $fid )
{ {
$result = mysql_query( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" ); $frame = dbFetchOne( "select * from Frames where EventID = '$eid' and FrameId = '$fid'" );
if ( !$result )
die( mysql_error() );
$frame = mysql_fetch_assoc( $result );
mysql_free_result( $result );
} }
else else
{ {
$result = mysql_query( "select * from Frames where EventID = '$eid' and Score = '".$event['MaxScore']."'" ); $frame = dbFetchOne( "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']; $fid = $frame['FrameId'];
} }

View File

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

View File

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

View File

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

View File

@ -33,11 +33,7 @@ else
$mid_sql = ''; $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"; $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 ); $event = dbFetchOne( $sql );
if ( !$result )
die( mysql_error() );
$event = mysql_fetch_assoc( $result );
mysql_free_result( $result );
$device_width = (isset($device)&&!empty($device['width']))?$device['width']:DEVICE_WIDTH; $device_width = (isset($device)&&!empty($device['width']))?$device['width']:DEVICE_WIDTH;
$device_height = (isset($device)&&!empty($device['height']))?$device['height']:DEVICE_HEIGHT; $device_height = (isset($device)&&!empty($device['height']))?$device['height']:DEVICE_HEIGHT;

View File

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