diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 8f702e748..765e15519 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -204,6 +204,7 @@ CREATE TABLE `Events` ( `Messaged` tinyint(3) unsigned NOT NULL default '0', `Executed` tinyint(3) unsigned NOT NULL default '0', `Notes` text, + `StateId` int(10) unsigned NOT NULL, PRIMARY KEY (`Id`,`MonitorId`), KEY `MonitorId` (`MonitorId`), KEY `StartTime` (`StartTime`), diff --git a/db/zm_update-1.31.1.sql b/db/zm_update-1.31.1.sql new file mode 100644 index 000000000..18d825091 --- /dev/null +++ b/db/zm_update-1.31.1.sql @@ -0,0 +1,20 @@ +-- +-- This updates a 1.30.0 database to 1.30.1 +-- +-- Add StateId Column to Events. +-- + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'Events' + AND table_schema = DATABASE() + AND column_name = 'StateId' + ) > 0, +"SELECT 'Column StateId exists in Events'", +"ALTER TABLE Events ADD `StateId` int(10) unsigned default NULL AFTER `Notes`" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; + diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 44d8cf30b..8118f236a 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -77,10 +77,14 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string gettimeofday( &start_time, 0 ); } - static char sql[ZM_SQL_MED_BUFSIZ]; + unsigned int state_id = 0; + if ( MYSQL_ROW dbrow = zmDbFetchOne( "SELECT Id FROM States WHERE IsActive=1" ) ) { + state_id = atoi(dbrow[0]); + } + static char sql[ZM_SQL_MED_BUFSIZ]; struct tm *stime = localtime( &start_time.tv_sec ); - snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes, Videoed ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', '%d' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), videoEvent ); + snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes, StateId, Videoed ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', '%d' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), state_id, videoEvent ); if ( mysql_query( &dbconn, sql ) ) { Error( "Can't insert event: %s. sql was (%s)", mysql_error( &dbconn ), sql ); exit( mysql_errno( &dbconn ) ); diff --git a/version b/version index 34aae156b..6bae54024 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.31.0 +1.31.1 diff --git a/web/includes/functions.php b/web/includes/functions.php index 8e0004ea9..b76cb5c55 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -1283,6 +1283,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) { case 'MaxScore': case 'Cause': case 'Notes': + case 'StateId': case 'Archived': $filter['sql'] .= 'E.'.$filter['terms'][$i]['attr']; break; diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index b07fa452b..17e141c60 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -125,6 +125,7 @@ $SLANG = array( 'AttrMaxScore' => 'Max. Score', 'AttrMonitorId' => 'Monitor Id', 'AttrMonitorName' => 'Monitor Name', + 'AttrStateId' => 'Run State', 'AttrServer' => 'Server', 'AttrName' => 'Name', 'AttrNotes' => 'Notes', diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 3057fad74..2713d11ba 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -92,6 +92,7 @@ $attrTypes = array( 'DiskPercent' => translate('AttrDiskPercent'), 'DiskBlocks' => translate('AttrDiskBlocks'), 'SystemLoad' => translate('AttrSystemLoad'), + 'StateId' => translate('AttrStateId'), 'ServerId' => translate('AttrServer'), ); $opTypes = array( @@ -209,6 +210,15 @@ for ( $i = 0; isset($_REQUEST['filter']) && $i < count($_REQUEST['filter']['term + +