-
Notifications
You must be signed in to change notification settings - Fork 208
/
custom_search.php
224 lines (208 loc) · 6.78 KB
/
custom_search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
require_once('db.inc.php');
require_once('facilities.inc.php');
// Uncomment these if you need/want to set a title in the header
// $header=__("");
$subheader=__("Data Center Operations Custom Search");
$model = new Device();
$availFieldList = get_object_vars( $model );
// Append the list of DeviceCustomAttributes
$attrList=DeviceCustomAttribute::GetDeviceCustomAttributeList();
foreach( $attrList as $ca ) {
$availFieldList[$ca->Label] = true;
}
// Remove the Rights and CustomValues fields since they are not directly relatable
unset($availFieldList["Rights"]);
unset($availFieldList["CustomValues"]);
ksort($availFieldList);
if ( isset( $_POST["devicefield"]) && count( $_POST["devicefield"]>0 )) {
$searchString = "";
foreach( $_POST["devicefield"] as $key=>$val ) {
if ( $_POST["devicefield"][$key]!="" && $_POST["criteria"][$key]!="" ) {
// If not the first variable, add an ampersand to indicate an additional parameter
if ( $searchString != "" ) {
$searchString .= "&";
}
$searchString .= $_POST["devicefield"][$key] . "=" . $_POST["criteria"][$key];
}
}
if ( $searchString !="" ) {
header('Location: search.php?key=dev&loose&'.$searchString);
exit;
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>openDCIM Custom Search Builder</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" />
<![endif]-->
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('select[name=searchoptions]').on('change',function(e){
if(e.currentTarget.value != 0){
AddRow($('select[name=searchoptions] > option:selected'));
}
});
$('#customsearch').on('click',function(e){
var searchstring='search.php?key=dev&loose';
$('#searchfields > div > div > :input').each(function(){
if(this.value){
searchstring+="&"+this.name+"="+this.value;
}
});
newtab(searchstring);
});
function BuildSelect(data,name){
select=$('<select />').attr('name',name);
for(var i in data){
select.append($('<option />').text(data[i].Location).val(data[i].CabinetID));
}
return select;
}
function SortSelect(){
var sel = $('select[name=searchoptions]');
sel.html(sel.find('option').sort(function(x, y) {
return $(x).text() > $(y).text() ? 1 : -1;
}));
sel.prepend(sel.find('option[value=0]'));
sel.val(0);
}
function AddRow(option){
var row=$('<div />');
var addrem=$('<div />').data('original',option).html('<img src="images/del.gif">').click(
function(e) {
$('select[name=searchoptions]').append($(e.currentTarget).data('original'));
$(this).parent().remove();
$('select[name=searchoptions]').val(0);
SortSelect();
}
);
var label=$('<div />').html(option.val());
var searchfield=$('<div />');
switch(option.val()) {
case "BackSide":
select=$('<select />').attr('name','BackSide');
select.append($('<option />').text("False").val("0"));
select.append($('<option />').text("True").val("1"));
searchfield.append(select);
break;
case "Cabinet":
$.get('api/v1/cabinet').done(function(data){
var selectlist=BuildSelect(data.cabinet,option.val());
searchfield.append(selectlist);
});
break;
case "DeviceType":
var devTypes = Array( 'Server','Appliance','Storage Array','Switch','Chassis','Patch Panel','Physical Infrastructure','CDU','Sensor' );
select=$('<select />').attr('name','DeviceType');
for(var i in devTypes){
select.append($('<option />').text(devTypes[i]).val(devTypes[i]));
}
searchfield.append(select);
break;
case "HalfDepth":
select=$('<select />').attr('name','HalfDepth');
select.append($('<option />').text("False").val("0"));
select.append($('<option />').text("True").val("1"));
searchfield.append(select);
break;
case "Hypervisor":
var hypTypes = Array( 'ESX', 'ProxMox', 'None' );
select=$('<select />').attr('name','Hypervisor');
for(var i in hypTypes){
select.append($('<option />').text(hypTypes[i]).val(hypTypes[i]));
}
searchfield.append(select);
break;
case "Owner":
$.get('api/v1/department').done(function(data){
select=$('<select />').attr('name','Owner');
for(var i in data.department){
select.append($('<option />').text(data.department[i].Name).val(data.department[i].DeptID));
}
searchfield.append(select);
});
break;
case "PrimaryContact":
$.get('api/v1/people').done(function(data){
select=$('<select />').attr('name','PrimaryContact');
for(var i in data.people){
select.append($('<option />').text(data.people[i].LastName+', '+data.people[i].FirstName).val(data.people[i].PersonID));
}
searchfield.append(select);
});
break;
case "Status":
$.get('api/v1/devicestatus').done(function(data){
select=$('<select />').attr('name','Status');
for(var i in data.devicestatus){
select.append($('<option />').text(data.devicestatus[i].Status).val(data.devicestatus[i].Status));
}
searchfield.append(select);
});
break;
default:
searchfield.append($('<input>').attr('name',option.val()));
}
row.append(addrem).append(label).append(searchfield);
row.insertBefore($('select[name=searchoptions]').parent('div').parent('div'));
option.remove();
}
function newtab(searchlink){
var poopup=window.open(searchlink);
poopup.focus();
}
});
</script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page index">
<?php
include( 'sidebar.inc.php' );
?>
<div class="main">
<div class="center"><div>
<h3>Device Criteria</h3>
<?php
echo '<form action="',$_SERVER["SCRIPT_NAME"].$formpatch,'" method="POST">
<div class="table" id="searchfields">
<div>
<div></div>
<div>',__("Search Field"),'</div>
<div>',__("Contains"),'</div>
</div>';
echo ' <div>
<div></div>
<div><select name="searchoptions"><option value="0" selected>',__("Select search field"),'</option>';
foreach($availFieldList as $tmpField=>$val){
print "\t\t\t<option value=\"$tmpField\">$tmpField</option>\n";
}
echo ' </select></div>
<div></div>
</div>
<div>
<div></div>
<div></div>
</div>
<div class="caption">
<button type="button" id="customsearch">',__("Search"),'</button>
</div>
</div><!-- END div.table --> '
?>
</form>
<!-- CONTENT GOES HERE -->
</div></div>
</div><!-- END div.main -->
</div><!-- END div.page -->
</body>
</html>