-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmetadata.php
355 lines (327 loc) · 13 KB
/
metadata.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
session_start();
$selectedPage="configure";
include "class/db.class.php";
$categories = new attrcategories;
if (isset($_GET['mode']))
{
if($_GET['mode'] == 'createCategory' && isset($_POST['name']))
{
$category = new attrcategory;
$category->name = $_POST['name'];
$categories->insert($category);
header("Location: metadata.php");
}
if($_GET['mode'] == 'deleteMetadata' && isset($_GET['id']))
{
$names = new attrnames;
$names->delete($_GET['id']);
header("Location: metadata.php?category=" . $_GET['category']);
}
if($_GET['mode'] == 'deleteCategory' && isset($_GET['id']))
{
$categories->delete($_GET['id']);
header("Location: metadata.php");
}
if ($_GET['mode'] == 'createMetadata')
{
$names = new attrnames;
$name = new attrname;
$name->name = $_POST['name'];
$name->parentid = $_POST['category'];
$name->parenttype = "attrcategory";
$name->type = $_POST['type'];
$name->default = $_POST['default'];
$name->units = $_POST['units'];
$name->desc = $_POST['desc'];
$id = $names->insert($name);
$options = new attroptions;
$option = new attroption;
if ($_POST['options'] == "")
{
$optionList = explode(",",$_POST['options']);
$option->attrnameid = $id;
foreach ($optionList as $opt)
{
$option->name = $opt;
$options->insert($option);
}
}
header("Location: metadata.php?category=" . $_POST['category']);
}
if($_GET['mode'] == 'saveCategoryOrder' && isset($_POST['data']))
{
$attrcategories = new attrcategories;
echo $attrcategories->update_sort($_POST['data']);
exit();
}
if($_GET['mode'] == 'saveNameOrder' && isset($_POST['data']))
{
$attrnames = new attrnames;;
echo $attrnames->update_sort($_POST['data']);
exit();
}
}
$globalTopic = "Device data & Attributes"; // page title
include "theme/" . $theme . "/top.php";
?>
<script>
function getData()
{
var data = "action=attrnames&attrcategory=" + $("[name=attrcategory]").val();
$.post("handler.php",data,function(data)
{
// Clear the table of search results
$("#attrnames table tbody").html("");
var count=0;
// loop over each returned cable
$.each(data, function(item,name)
{
var item = "<tr id=rowItem"+name['attrnameid']+"'><td>" + name['name'] +
"</td><td>" + name['type'] + "</td><td>" + name['default'] +
"</td><td>" + name['units'] + "</td><td>"+name['desc']+"</td><td >";
if(name['static']!=1)
item+= "<a href='#' >Edit</a> :: <a href='?category=" + $("[name=attrcategory]").val() + "&mode=deleteMetadata&id=" + name['attrnameid'] + "'>Delete</a>";
item+="</td><td align='center'><span class='handle' ><img src='images/icons/drag_list.gif' alt='Sort' /></span></td>" +
"</tr>";
$("#attrnames table tbody").append(item);
count++;
});
if(count==0)
{
$("#attrnames table tbody").append("<tr><td colspan='7'><em>This trait currently has no attributes</em></td></tr>");
}
},"json");
}
$(document).ready(function() {
<?php
if(isset($_GET['category']) && is_numeric($_GET['category']))
echo "getData();";
?>
$('[name=attrcategory]').change(function() {
$("#addNewOptionBtn").show();
getData();
});
//getData();
$("#traitsTable tbody").sortable({
items: "tr",
handle: "span.handle",
update : function ()
{
var sequence = $(this).sortable('toArray');
$.ajax
({
type: "POST",
url: "metadata.php?mode=saveCategoryOrder",
data: "data="+sequence,
async: false,
success: function(responce)
{
if(responce==0)
alert("Error: Unable to save list order");
}
})
}
});
$("#attrnames table tbody").sortable({
items: "tr",
handle: "span.handle",
update : function ()
{
var sequence = $(this).sortable('toArray');
$.ajax
({
type: "POST",
url: "metadata.php?mode=saveNameOrder",
data: "data="+sequence,
async: false,
success: function(responce)
{
if(responce==0)
alert("Error: Unable to save list order");
}
})
}
});
});
</script>
<div id="main">
<div id="left">
<div class="module" id="createCategory" style="display:none;">
<strong>Traits</strong>
<a href="#" class="closeDOMWindow"><img src="images/icons/close_module.gif" border="0" alt="Close" /></a>
<div class="form" align="center">
<table class="formTable" id="traitsTable">
<colgroup align="left" class="tblfirstRow"></colgroup>
<thead>
<tr>
<th scope="col" width="450px">Name</th>
<th align="center" width="110px"></th>
</tr>
</thead>
<tbody>
<tr class="creationRow">
<td><form method="post" action="?mode=createCategory" ><input name="name" type="text" id="name" value="" size="60"/></td>
<td><input type="submit" name="btnSubmit" value="Create" /></form></td>
</tr>
<?php
foreach ($categories->getAll() as $row)
{
?>
<tr id="rowItem<?php echo $row->attrcategoryid;?>">
<td width="450px"><?php echo $row->name; ?></td>
<td width="110px" align="right">
<?php if ($row->static != 1) { ?><a href="?mode=deleteCategory&id=<?php echo $row->attrcategoryid; ?>">Delete</a> - <?php } ?>
<span class="handle" ><img src="images/icons/drag_list.gif" alt="Sort" /></span></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="module" id="createMetadata" style="display:none">
<script>
$('[name=type]').change(function() {
$("#unitList").hide();
switch($(this).val())
{
case 'Number':
$("#unitList").show();
case 'Textbox':
case 'Date':
case 'Text Area':
case 'Image':
case 'File':
case 'Checkbox':
$("#optionsList").hide();
break;
default:
$("#optionsList").show();
}
});
</script>
<strong>New Metadata</strong>
<a href="#" class="closeDOMWindow"><img src="images/icons/close_module.gif" border="0" alt="Close" /></a>
<div class="form" align="center">
<form method="post" action="?mode=createMetadata" >
<table width="80%" class="formTable">
<colgroup align="left" class="tblfirstRow"></colgroup>
<tr>
<td>Category:</td><td id="createCategoryName"></td>
</tr>
<tr>
<td align="left" width="100"><label for="name" >Name:</label></td>
<td align="left"><input name="name" type="text" id="name" value="" /><input type="hidden" name="category" /></td>
</tr>
<tr>
<td align="left"><label for="type" >Type:</label></td>
<td align="left"><select name="type">
<option>Textbox</option>
<option>Number</option>
<option>Date</option>
<option>Text Area</option>
<option>Checkbox</option>
<option>Radio Buttons</option>
<option>Checkbox List</option>
<option>Dropdown List</option>
<option>File</option>
<option>Image</option>
</select></td>
</tr>
<tr id="optionsList" style="display:none;">
<td align="left"><label for="options">Options</label></td>
<td align="left"><input name="options" /> enter comma separated values</td>
</tr>
<tr>
<td width="100" align="left"><label for="default">Default Value:</label></td>
<td align="left"><input name="default" /> (optional)</td>
</tr>
<tr id="unitList" style="display:none;">
<td align="left"><label for="units">Units:</label></td>
<td align="left"><input name="units" /> (optional)</td>
</tr>
<tr>
<td align="left"><label for="desc">Description:</label></td>
<td align="left"><input name="desc" size="70"/> (optional)</td>
</tr>
<tr>
<td></td><td align="left"><input type="submit" name="btnSubmit" value="Create" /></td>
</tr>
<tr>
</tr>
</table>
</form>
</div>
</div>
<div class="module" id="manageMetaData">
<strong>Meta Data</strong>
<p>
Devices within RackSmith can store a wide range of information, here we define the defaults which are applied to the default categories within RackSmith.</p>
<p>
Each device can have a collection of the following traits, the values within each of them are then associated by default.
</p>
Trait: <select name="attrcategory">
<option value='0' disabled>-- Select Trait --</option>
<?php
foreach ($categories->getAll() as $row)
{
?>
<option <?php if (isset($_GET['category']) && $_GET['category'] == $row->attrcategoryid) { echo "selected=selected"; } ?> value="<?php echo $row->attrcategoryid; ?>"><?php echo $row->name; ?></option>
<?php
}
?>
</select> <a href="#" onclick="$.openDOMWindow({ width:'580',height: '450',overlayOpacity: '30', windowSourceID: '#createCategory'});">[Add & Edit]</a> <br /><br />
<input type="button" value="Add New Option" style="display:none;" id="addNewOptionBtn" onclick="$.openDOMWindow({ width:'580',height: '220',overlayOpacity: '30', windowSourceID: '#createMetadata'});$('[name=category]').val($('[name=attrcategory]').val());$('#createCategoryName').html($('[name=attrcategory] option:selected').text());">
<div id="attrnames">
<table class="dataTable">
<colgroup align="left" class="tblfirstRow"></colgroup>
<thead>
<tr>
<th scope="col" width="15%">Name</th>
<th scope="col" width="10%">Type</th>
<th scope="col" width="5%">Default</th>
<th scope="col" width="4%">Units</th>
<th scope="col" width="55%">Description</th>
<th scope="col" width="10%" align="center">Options</th>
<th scope="col" width="1%" align="center">Sort</th>
</tr>
</thead>
<tbody>
<tr><td colspan="7" ><em>Please select a trait above to start configuring</em></td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="right">
<div class="module sideMenu">
<strong>Devices & Templates</strong>
<p>
<ul>
<li><a href="manageTemplates.php">Create a new Template</a></li>
<li><a href="templates.php">Templates List</a></li>
<li><a href="templateMover.php">Import/Export Templates</a></li>
<li><a href="metadata.php" >Device Information</a></li>
</ul>
</p>
</div>
<div class="module sideMenu">
<strong>System</strong>
<p>
<ul>
<li><a href="cables.php" >Cable Types</a></li>
<li><a href="owners.php" >Equipment Owners</a></li>
<li><a href="management.php?action=accounts" >User Accounts</a></li>
<li><a href="system.php" >System</a></li>
<li><a href="logs.php" >Logs</a></li>
<li><a href="templateMover.php" >Import / Export Templates</a></li>
</ul>
</p>
</div>
</div>
</div>
<?php
include "theme/" . $theme . "/base.php";
?>