18
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
//
20
20
21
- require_once ('includes/Monitor.php ' );
22
-
23
- zm_session_start ();
24
- foreach (array ('GroupId ' ,'Capturing ' ,'Analysing ' ,'Recording ' ,'ServerId ' ,'StorageId ' ,'Status ' ,'MonitorId ' ,'MonitorName ' ,'Source ' ) as $ var ) {
25
- if (isset ($ _REQUEST [$ var ])) {
26
- if ($ _REQUEST [$ var ] != '' ) {
27
- $ _SESSION [$ var ] = $ _REQUEST [$ var ];
28
- } else {
21
+ function addFilterSelect ($ name , $ options ) {
22
+ $ html = '<span class="term ' .$ name .'Filter"><label> ' .translate ($ name ).'</label> ' ;
23
+ $ html .= '<span class="term-value-wrapper"> ' ;
24
+ $ html .= htmlSelect ($ name .'[] ' , $ options ,
25
+ (isset ($ _SESSION [$ name ])?$ _SESSION [$ name ]:'' ),
26
+ array (
27
+ 'data-on-change ' =>'submitThisForm ' ,
28
+ 'class ' =>'chosen ' ,
29
+ 'multiple ' =>'multiple ' ,
30
+ 'data-placeholder ' =>'All ' ,
31
+ )
32
+ );
33
+ $ html .= '</span> ' ;
34
+ $ html .= '</span> ' .PHP_EOL ;
35
+ return $ html ;
36
+ }
37
+
38
+ function buildMonitorsFilters () {
39
+ global $ user , $ Servers ;
40
+ require_once ('includes/Monitor.php ' );
41
+
42
+ zm_session_start ();
43
+ foreach (array ('GroupId ' ,'Capturing ' ,'Analysing ' ,'Recording ' ,'ServerId ' ,'StorageId ' ,'Status ' ,'MonitorId ' ,'MonitorName ' ,'Source ' ) as $ var ) {
44
+ if (isset ($ _REQUEST [$ var ])) {
45
+ if ($ _REQUEST [$ var ] != '' ) {
46
+ $ _SESSION [$ var ] = $ _REQUEST [$ var ];
47
+ } else {
48
+ unset($ _SESSION [$ var ]);
49
+ }
50
+ } else if (isset ($ _REQUEST ['filtering ' ])) {
29
51
unset($ _SESSION [$ var ]);
30
52
}
31
- } else if (isset ($ _REQUEST ['filtering ' ])) {
32
- unset($ _SESSION [$ var ]);
33
53
}
34
- }
35
- session_write_close ();
54
+ session_write_close ();
36
55
37
- $ storage_areas = ZM \Storage::find ();
38
- $ StorageById = array ();
39
- foreach ($ storage_areas as $ S ) {
40
- $ StorageById [$ S ->Id ()] = $ S ;
41
- }
56
+ $ storage_areas = ZM \Storage::find ();
57
+ $ StorageById = array ();
58
+ foreach ($ storage_areas as $ S ) {
59
+ $ StorageById [$ S ->Id ()] = $ S ;
60
+ }
42
61
43
- $ ServersById = array ();
44
- foreach ($ Servers as $ s ) {
45
- $ ServersById [$ s ->Id ()] = $ s ;
46
- }
62
+ $ ServersById = array ();
63
+ foreach ($ Servers as $ s ) {
64
+ $ ServersById [$ s ->Id ()] = $ s ;
65
+ }
47
66
48
- $ html =
67
+ $ html =
49
68
'
50
69
<div class="controlHeader">
51
70
52
71
<!-- Used to submit the form with the enter key -->
53
72
<input type="submit" class="d-none"/>
54
73
<input type="hidden" name="filtering" value=""/>
55
74
' ;
56
- $ groupSql = '' ;
57
- if (canView ('Groups ' )) {
58
- $ GroupsById = array ();
59
- foreach (ZM \Group::find () as $ G ) {
60
- $ GroupsById [$ G ->Id ()] = $ G ;
75
+ $ groupSql = '' ;
76
+ if (canView ('Groups ' )) {
77
+ $ GroupsById = array ();
78
+ foreach (ZM \Group::find () as $ G ) {
79
+ $ GroupsById [$ G ->Id ()] = $ G ;
80
+ }
81
+
82
+ if (count ($ GroupsById )) {
83
+ $ html .= '<span class="term" id="groupControl"><label> ' . translate ('Group ' ) .'</label> ' ;
84
+ $ html .= '<span class="term-value-wrapper"> ' ;
85
+ # This will end up with the group_id of the deepest selection
86
+ $ group_id = isset ($ _SESSION ['GroupId ' ]) ? $ _SESSION ['GroupId ' ] : null ;
87
+ $ html .= ZM \Group::get_group_dropdown ();
88
+ $ groupSql = ZM \Group::get_group_sql ($ group_id );
89
+ $ html .= '</span> ' ;
90
+ $ html .= '</span> ' ;
91
+ }
61
92
}
62
93
63
- if (count ($ GroupsById )) {
64
- $ html .= '<span class="term" id="groupControl"><label> ' . translate ('Group ' ) .'</label> ' ;
65
- $ html .= '<span class="term-value-wrapper"> ' ;
66
- # This will end up with the group_id of the deepest selection
67
- $ group_id = isset ($ _SESSION ['GroupId ' ]) ? $ _SESSION ['GroupId ' ] : null ;
68
- $ html .= ZM \Group::get_group_dropdown ();
69
- $ groupSql = ZM \Group::get_group_sql ($ group_id );
70
- $ html .= '</span> ' ;
71
- $ html .= '</span> ' ;
94
+ $ selected_monitor_ids = isset ($ _SESSION ['MonitorId ' ]) ? $ _SESSION ['MonitorId ' ] : array ();
95
+ if ( !is_array ($ selected_monitor_ids ) ) {
96
+ $ selected_monitor_ids = array ($ selected_monitor_ids );
72
97
}
73
- }
74
98
75
- $ selected_monitor_ids = isset ($ _SESSION ['MonitorId ' ]) ? $ _SESSION ['MonitorId ' ] : array ();
76
- if ( !is_array ($ selected_monitor_ids ) ) {
77
- $ selected_monitor_ids = array ($ selected_monitor_ids );
78
- }
99
+ $ conditions = array ();
100
+ $ values = array ();
79
101
80
- $ conditions = array ();
81
- $ values = array ();
82
-
83
- if ( $ groupSql )
84
- $ conditions [] = $ groupSql ;
85
- foreach ( array ('ServerId ' ,'StorageId ' ,'Status ' ,'Capturing ' ,'Analysing ' ,'Recording ' ) as $ filter ) {
86
- if ( isset ($ _SESSION [$ filter ]) ) {
87
- if ( is_array ($ _SESSION [$ filter ]) ) {
88
- $ conditions [] = '` ' .$ filter . '` IN ( ' .implode (', ' , array_map (function (){return '? ' ;}, $ _SESSION [$ filter ])). ') ' ;
89
- $ values = array_merge ($ values , $ _SESSION [$ filter ]);
90
- } else {
91
- $ conditions [] = '` ' .$ filter . '`=? ' ;
92
- $ values [] = $ _SESSION [$ filter ];
102
+ if ( $ groupSql )
103
+ $ conditions [] = $ groupSql ;
104
+ foreach ( array ('ServerId ' ,'StorageId ' ,'Status ' ,'Capturing ' ,'Analysing ' ,'Recording ' ) as $ filter ) {
105
+ if ( isset ($ _SESSION [$ filter ]) ) {
106
+ if ( is_array ($ _SESSION [$ filter ]) ) {
107
+ $ conditions [] = '` ' .$ filter . '` IN ( ' .implode (', ' , array_map (function (){return '? ' ;}, $ _SESSION [$ filter ])). ') ' ;
108
+ $ values = array_merge ($ values , $ _SESSION [$ filter ]);
109
+ } else {
110
+ $ conditions [] = '` ' .$ filter . '`=? ' ;
111
+ $ values [] = $ _SESSION [$ filter ];
112
+ }
93
113
}
114
+ } # end foreach filter
115
+
116
+ if (count ($ user ->unviewableMonitorIds ()) ) {
117
+ $ ids = $ user ->viewableMonitorIds ();
118
+ $ conditions [] = 'M.Id IN ( ' .implode (', ' ,array_map (function (){return '? ' ;}, $ ids )).') ' ;
119
+ $ values = array_merge ($ values , $ ids );
94
120
}
95
- } # end foreach filter
96
121
97
- if (count ($ user ->unviewableMonitorIds ()) ) {
98
- $ ids = $ user ->viewableMonitorIds ();
99
- $ conditions [] = 'M.Id IN ( ' .implode (', ' ,array_map (function (){return '? ' ;}, $ ids )).') ' ;
100
- $ values = array_merge ($ values , $ ids );
101
- }
122
+ $ html .= '<span class="term MonitorNameFilter"><label> ' .translate ('Name ' ).'</label> ' ;
123
+ $ html .= '<span class="term-value-wrapper"> ' ;
124
+ $ html .= '<input type="text" name="MonitorName" value=" ' .(isset ($ _SESSION ['MonitorName ' ])?validHtmlStr ($ _SESSION ['MonitorName ' ]):'' ).'" placeholder="text or regular expression"/></span> ' ;
125
+ $ html .= '</span> ' .PHP_EOL ;
102
126
103
- $ html .= '<span class="term MonitorNameFilter"><label> ' .translate ('Name ' ).'</label> ' ;
104
- $ html .= '<span class="term-value-wrapper"> ' ;
105
- $ html .= '<input type="text" name="MonitorName" value=" ' .(isset ($ _SESSION ['MonitorName ' ])?validHtmlStr ($ _SESSION ['MonitorName ' ]):'' ).'" placeholder="text or regular expression"/></span> ' ;
106
- $ html .= '</span> ' .PHP_EOL ;
127
+ $ html .= addFilterSelect ('Capturing ' , array ('None ' =>translate ('None ' ), 'Always ' =>translate ('Always ' ), 'OnDemand ' =>translate ('On Demand ' )));
128
+ $ html .= addFilterSelect ('Analysing ' , array ('None ' =>translate ('None ' ), 'Always ' =>translate ('Always ' )));
129
+ $ html .= addFilterSelect ('Recording ' , array ('None ' =>translate ('None ' ), 'OnMotion ' =>translate ('On Motion ' ),'Always ' =>translate ('Always ' )));
107
130
108
- function addFilterSelect ( $ name , $ options ) {
109
- $ html = '<span class="term ' . $ name . ' Filter "><label> ' .translate ($ name ).'</label> ' ;
110
- $ html .= '<span class="term-value-wrapper"> ' ;
111
- $ html .= htmlSelect ($ name . ' [] ' , $ options ,
112
- (isset ($ _SESSION [$ name ])?$ _SESSION [$ name ]:'' ),
131
+ if ( count ( $ ServersById ) > 1 ) {
132
+ $ html . = '<span class="term ServerFilter "><label> ' . translate (' Server ' ).'</label> ' ;
133
+ $ html .= '<span class="term-value-wrapper"> ' ;
134
+ $ html .= htmlSelect (' ServerId [] ' , $ ServersById ,
135
+ (isset ($ _SESSION [' ServerId ' ])?$ _SESSION [' ServerId ' ]:'' ),
113
136
array (
114
137
'data-on-change ' =>'submitThisForm ' ,
115
138
'class ' =>'chosen ' ,
116
139
'multiple ' =>'multiple ' ,
117
140
'data-placeholder ' =>'All ' ,
118
141
)
119
142
);
120
- $ html .= '</span> ' ;
121
- $ html .= '</span> ' .PHP_EOL ;
122
- return $ html ;
123
- }
124
-
125
- $ html .= addFilterSelect ('Capturing ' , array ('None ' =>translate ('None ' ), 'Always ' =>translate ('Always ' ), 'OnDemand ' =>translate ('On Demand ' )));
126
- $ html .= addFilterSelect ('Analysing ' , array ('None ' =>translate ('None ' ), 'Always ' =>translate ('Always ' )));
127
- $ html .= addFilterSelect ('Recording ' , array ('None ' =>translate ('None ' ), 'OnMotion ' =>translate ('On Motion ' ),'Always ' =>translate ('Always ' )));
143
+ $ html .= '</span> ' ;
144
+ $ html .= '</span> ' ;
145
+ } # end if have Servers
128
146
129
- if ( count ($ ServersById ) > 1 ) {
130
- $ html .= '<span class="term ServerFilter"><label> ' . translate ('Server ' ).'</label> ' ;
131
- $ html .= '<span class="term-value-wrapper"> ' ;
132
- $ html .= htmlSelect ('ServerId[] ' , $ ServersById ,
133
- (isset ($ _SESSION ['ServerId ' ])?$ _SESSION ['ServerId ' ]:'' ),
134
- array (
135
- 'data-on-change ' =>'submitThisForm ' ,
136
- 'class ' =>'chosen ' ,
137
- 'multiple ' =>'multiple ' ,
138
- 'data-placeholder ' =>'All ' ,
139
- )
140
- );
141
- $ html .= '</span> ' ;
142
- $ html .= '</span> ' ;
143
- } # end if have Servers
147
+ if ( count ($ StorageById ) > 1 ) {
148
+ $ html .= '<span class="term StorageFilter"><label> ' .translate ('Storage ' ).'</label> ' ;
149
+ $ html .= '<span class="term-value-wrapper"> ' ;
150
+ $ html .= htmlSelect ('StorageId[] ' , $ StorageById ,
151
+ (isset ($ _SESSION ['StorageId ' ])?$ _SESSION ['StorageId ' ]:'' ),
152
+ array (
153
+ 'data-on-change ' =>'submitThisForm ' ,
154
+ 'class ' =>'chosen ' ,
155
+ 'multiple ' =>'multiple ' ,
156
+ 'data-placeholder ' =>'All ' ,
157
+ ) );
158
+ $ html .= '</span> ' ;
159
+ $ html .= '</span> ' ;
160
+ } # end if have Storage Areas
144
161
145
- if ( count ($ StorageById ) > 1 ) {
146
- $ html .= '<span class="term StorageFilter"><label> ' .translate ('Storage ' ).'</label> ' ;
162
+ $ html .= '<span class="term StatusFilter"><label> ' .translate ('Status ' ).'</label> ' ;
163
+ $ status_options = array (
164
+ 'Unknown ' => translate ('StatusUnknown ' ),
165
+ 'NotRunning ' => translate ('StatusNotRunning ' ),
166
+ 'Running ' => translate ('StatusRunning ' ),
167
+ 'Connected ' => translate ('StatusConnected ' ),
168
+ );
147
169
$ html .= '<span class="term-value-wrapper"> ' ;
148
- $ html .= htmlSelect (' StorageId [] ' , $ StorageById ,
149
- (isset ($ _SESSION ['StorageId ' ])? $ _SESSION ['StorageId ' ]: '' ),
170
+ $ html .= htmlSelect ( ' Status [] ' , $ status_options ,
171
+ ( isset ($ _SESSION ['Status ' ]) ? $ _SESSION ['Status ' ] : '' ),
150
172
array (
151
173
'data-on-change ' =>'submitThisForm ' ,
152
174
'class ' =>'chosen ' ,
153
175
'multiple ' =>'multiple ' ,
154
- 'data-placeholder ' =>'All ' ,
176
+ 'data-placeholder ' =>'All '
155
177
) );
156
178
$ html .= '</span> ' ;
157
179
$ html .= '</span> ' ;
158
- } # end if have Storage Areas
159
-
160
- $ html .= '<span class="term StatusFilter"><label> ' .translate ('Status ' ).'</label> ' ;
161
- $ status_options = array (
162
- 'Unknown ' => translate ('StatusUnknown ' ),
163
- 'NotRunning ' => translate ('StatusNotRunning ' ),
164
- 'Running ' => translate ('StatusRunning ' ),
165
- 'Connected ' => translate ('StatusConnected ' ),
166
- );
167
- $ html .= '<span class="term-value-wrapper"> ' ;
168
- $ html .= htmlSelect ( 'Status[] ' , $ status_options ,
169
- ( isset ($ _SESSION ['Status ' ]) ? $ _SESSION ['Status ' ] : '' ),
170
- array (
171
- 'data-on-change ' =>'submitThisForm ' ,
172
- 'class ' =>'chosen ' ,
173
- 'multiple ' =>'multiple ' ,
174
- 'data-placeholder ' =>'All '
175
- ) );
176
- $ html .= '</span> ' ;
177
- $ html .= '</span> ' ;
178
180
179
181
$ html .= '<span class="term SourceFilter"><label> ' .translate ('Source ' ).'</label> ' ;
180
182
$ html .= '<span class="term-value-wrapper"> ' ;
@@ -183,10 +185,10 @@ function addFilterSelect($name, $options) {
183
185
$ html .= '</span> ' ;
184
186
185
187
$ sqlAll = 'SELECT M.*, S.*, E.*
186
- FROM Monitors AS M
187
- LEFT JOIN Monitor_Status AS S ON S.MonitorId=M.Id
188
- LEFT JOIN Event_Summaries AS E ON E.MonitorId=M.Id
189
- WHERE M.`Deleted`=false ' ;
188
+ FROM Monitors AS M
189
+ LEFT JOIN Monitor_Status AS S ON S.MonitorId=M.Id
190
+ LEFT JOIN Event_Summaries AS E ON E.MonitorId=M.Id
191
+ WHERE M.`Deleted`=false ' ;
190
192
$ sqlSelected = $ sqlAll . ( count ($ conditions ) ? ' AND ' . implode (' AND ' , $ conditions ) : '' ).' ORDER BY Sequence ASC ' ;
191
193
$ monitors = dbFetchAll ($ sqlSelected , null , $ values );
192
194
@@ -195,7 +197,7 @@ function addFilterSelect($name, $options) {
195
197
if ( visibleMonitor ($ row ['Id ' ]) ) { #We count only available monitors.
196
198
++$ colAllAvailableMonitors ;
197
199
}
198
- }
200
+ }
199
201
200
202
$ displayMonitors = array ();
201
203
$ monitors_dropdown = array ();
@@ -283,6 +285,14 @@ function addFilterSelect($name, $options) {
283
285
$ display_monitor_ids = array_map (function ($ monitor_row ){return $ monitor_row ['Id ' ];}, $ displayMonitors );
284
286
$ html .= '</span> ' ;
285
287
$ html .= '</span> ' ;
286
- echo $ html ;
288
+ $ html .= '</div> ' ;
289
+
290
+ return [
291
+ "filterBar " => $ html ,
292
+ "displayMonitors " => $ displayMonitors ,
293
+ "storage_areas " => $ storage_areas ,
294
+ "StorageById " => $ StorageById ,
295
+ "selected_monitor_ids " => $ selected_monitor_ids
296
+ ];
297
+ }
287
298
?>
288
- </div>
0 commit comments