-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodify_attr.php
380 lines (359 loc) · 17.3 KB
/
modify_attr.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
require_once 'config/main.php';
require_once 'include/head.php';
set_page();
# go to show attribute page, when modify was ok
$HTTP_referer = 'show_attr.php';
$_SESSION["go_back_page_ok"] = $HTTP_referer;
message($debug, "set go_back_page_ok : ".$_SESSION["go_back_page_ok"]);
# Choose title
if(isset($_GET['id'])){
$id = $_GET['id'];
$title = "Modify attribute";
}else{
$id = "new";
$title = "Add attribute";
}
if ($id != "new"){
# get entries
$query = 'SELECT * FROM ConfigAttrs WHERE id_attr="'.$id.'"';
$attr_entry = db_handler($query, "assoc", "get entries");
}else{
# new entry does not have predefined values like the modify part
$attr_entry = array("attr_name" => "",
"friendly_name" => "",
"description" => "",
"datatype" => "text",
"max_length" => "1024",
"poss_values" => "",
"predef_value" => "",
"mandatory" => "",
"ordering" => "",
"visible" => "",
"write_to_conf" => "",
"naming_attr" => "",
"link_as_child" => "no",
"fk_show_class_items" => "",
"fk_id_class" => "");
}
# Check cache
if ( isset($_SESSION["cache"]["modify_attr"][$id]) ){
# Cache
foreach ($_SESSION["cache"]["modify_attr"][$id] as $key => $value) {
$attr_entry[$key] = $value;
}
}
?>
<h2><?php echo $title;?></h2><br>
<form name="form1" action="modify_attr_write2db.php" method="post">
<!--<form name="form1" action="modify_attr_write2db.php" method="post" onclick="check_input()" onkeydown="check_input()" onreset="check_input()">-->
<input type=hidden name=attr_id value="<?php echo $id; ?>">
<table width=410>
<tr><td width=200>Nagios-specific attribute name</td>
<td width=20></td>
<td><input type=text name=attr_name maxlength=60 value="<?php echo htmlspecialchars($attr_entry["attr_name"]); ?>"></td>
<td class="attention">*</td>
</tr>
<tr><td>friendly name (will be shown in GUI)</td>
<td width=20></td>
<td><input type=text name=friendly_name maxlength=80 value="<?php echo htmlspecialchars($attr_entry["friendly_name"]); ?>"></td>
<td class="attention">*</td>
</tr>
<tr><td>description, example or help-text</td>
<td width=20></td>
<td><input type=text name=description maxlength=250 value="<?php echo htmlspecialchars($attr_entry["description"]); ?>"></td>
<td class="attention"></td>
</tr>
<tr><td>attribute belongs to class</td>
<td width=20></td>
<td><select name="fk_id_class"
<?php if ($id != "new") echo "disabled"; ?>
>
<?php
$query = mysql_query("SELECT id_class,config_class FROM ConfigClasses ORDER BY config_class");
while($entry = mysql_fetch_row($query)){
echo '<option value='.$entry[0];
if ( $entry[0] == $attr_entry["fk_id_class"] ) echo " selected";
echo " >$entry[1]</option>";
}
?>
</select></td>
<td class="attention">*</td>
</tr>
</table>
<br>
<table width=410>
<tr><td colspan=4>
<table border=0 frame=box rules=none cellspacing=2 cellpadding=3>
<tr class="box_content"><td colspan=3 class="bg_header"><strong>Info: datatype</strong></td></tr>
<tr class="box_content"><td width=10% valign=top class="box_content"><i>text</i></td>
<td width=3%></td><td width=87%>This datatype is used for a simple text attribute. A maximum length may be specified.</td></tr>
<tr class="box_content"><td width=10% valign=top><i>password</i></td>
<td width=3%></td><td width=87%>This datatype is used for a password attribute. An encryption may be specified. Passwords will not be displayed</td></tr>
<tr class="box_content"><td valign=top><i>select</i></td>
<td></td><td>This datatype creates a drop-down menu. A comma-separated list of possible values must be specified.</td></tr>
<tr class="box_content"><td valign=top><i>assign_one</i></td>
<td></td><td>This datatype creates a drop-down menu that allows an item of any class to be assigned to another one (selected item will be linked as "parent" by default).</td></tr>
<tr class="box_content"><td valign=top><i>assign_many</i></td>
<td></td><td>This datatype creates a menu that allows an item of any class to be assigned to one or more other items (selected items will be linked as "parents" by default).</td></tr>
<tr class="box_content"><td valign=top><i>assign_cust_order</i></td>
<td></td><td>This datatype is identic to "assign_many" but can additionally handle the order of items</td></tr>
</table><br>
</td></tr>
<tr><td width=200>choose attribute datatype</td>
<td width=20></td>
<td><select name="datatype" onChange="check_input(document.form1.datatype.value)"
<?php if ($id != "new") echo "disabled"; ?>
>
<option value="text" <?php if($attr_entry["datatype"] == "text") echo " selected"; ?> >text</option>
<option value="password" <?php if($attr_entry["datatype"] == "password") echo " selected"; ?> >password</option>
<option value="select" <?php if($attr_entry["datatype"] == "select") echo " selected"; ?> >select</option>
<option value="assign_one" <?php if($attr_entry["datatype"] == "assign_one") echo " selected"; ?> >assign_one</option>
<option value="assign_many" <?php if($attr_entry["datatype"] == "assign_many") echo " selected"; ?> >assign_many</option>
<option value="assign_cust_order" <?php if($attr_entry["datatype"] == "assign_cust_order") echo " selected"; ?> >assign_cust_order</option>
</select></td>
<td class="attention">*</td>
</tr>
<tr><td>items of class to be assigned</td>
<td width=20></td>
<td><select name="fk_show_class_items" disabled>
<?php
$query = mysql_query("SELECT id_class,config_class FROM ConfigClasses ORDER BY config_class");
while($entry = mysql_fetch_row($query)){
//echo "<option value=$entry[0]>$entry[1]</option>";
echo '<option value='.$entry[0];
if ( $entry[0] == $attr_entry["fk_show_class_items"] ) echo " selected";
echo " >$entry[1]</option>";
}
?>
</select></td>
<td class="attention">*</td>
</tr>
<tr><td>list of possible values (separated by "<?php echo SELECT_VALUE_SEPARATOR; ?>")</td>
<td width=20></td>
<td><input type=text name=poss_values value="<?php echo htmlspecialchars($attr_entry["poss_values"]); ?>"></td>
<td class="attention">*</td>
</tr>
<tr><td>pre-defined value</td>
<td width=20></td>
<td><input type=text name=predef_value maxlength=1024 value="<?php echo htmlspecialchars($attr_entry["predef_value"]); ?>"></td>
<td class="attention"></td>
</tr>
<tr><td>max. text-field length (chars)</td>
<td width=20></td>
<td><input type=text name=max_length maxlength=4 style="width:60px" value="<?php echo $attr_entry["max_length"]; ?>"></td>
<td class="attention"></td>
</tr>
<tr><td>link selected item(s) as children?</td>
<td width=20></td>
<td>
<select name="link_as_child" style="width:60px" disabled>
<option <?php if($attr_entry["link_as_child"] == "no") echo " selected"; ?> >no</option>
<option <?php if($attr_entry["link_as_child"] == "yes") echo " selected"; ?> >yes</option>
</select>
</td>
<td class="attention"></td>
</tr>
</table>
<br>
<table width=240>
<tr><td>attribute is mandatory?</td>
<td width=20></td>
<td>
<select name=mandatory style="width:60px">
<option <?php if($attr_entry["mandatory"] == "no") echo " selected"; ?> >no</option>
<option <?php if($attr_entry["mandatory"] == "yes") echo " selected"; ?> >yes</option>
</select>
<input type="hidden" name="HIDDEN_mandatory" value="<?php echo $attr_entry["mandatory"]; ?>">
</td>
<td class="attention">*</td>
</tr>
<tr><td>attribute is visible?</td>
<td width=20></td>
<td>
<select name=visible style="width:60px">
<option <?php if($attr_entry["visible"] == "yes") echo " selected"; ?> >yes</option>
<option <?php if($attr_entry["visible"] == "no") echo " selected"; ?> >no</option>
</select>
</td>
<td class="attention">*</td>
</tr>
<tr><td>write attribute to configuration?</td>
<td width=20></td>
<td>
<select name=conf style="width:60px">
<option <?php if($attr_entry["write_to_conf"] == "yes") echo " selected"; ?> >yes</option>
<option <?php if($attr_entry["write_to_conf"] == "no") echo " selected"; ?> >no</option>
</select>
</td>
<td class="attention">*</td>
</tr>
<tr><td>ordering</td>
<td width=20></td>
<td><input type=text name=ordering maxlength=2 style="width:60px" value="<?php echo $attr_entry["ordering"]; ?>"></td>
<td class="attention"></td>
</tr>
<tr><td>naming attribute?</td>
<td width=20></td>
<td>
<select name=naming_attr style="width:60px" onChange="check_naming_attr()"
<?php if ($id != "new") echo "disabled"; ?>
>
<option <?php if($attr_entry["naming_attr"] == "no") echo " selected"; ?> >no</option>
<option <?php if($attr_entry["naming_attr"] == "yes") echo " selected"; ?> >yes</option>
</select>
</td>
<td class="attention">*</td>
</tr>
<tr><td colspan=4><br>
<table border=0 frame=void rules=none style="border-collapse:collapse" cellspacing=2 cellpadding=3>
<tr class="bg_header"><td><strong>Info: ordering / naming_attr</strong></td></tr>
<tr class="box_content"><td><i>ordering</i>: enter specific ranking number or leave blank for the next free one.
<br><br><i>naming_attr</i>: defines the naming attribute of a class and is displayed in assignments. There is only one naming_attr per class!</td></tr>
</table>
</td></tr>
</table>
<table>
<tr><td>
<div id=buttons>
<input type="Submit" value="Submit" name="submit" align="middle">
<?php
echo '<input type="Reset" value="Reset" onclick=\'check_input("'.$attr_entry["datatype"].'")\'>';
?>
</div>
</td></tr>
</table>
</form>
<?php
# Script part for modify attribute
if ($id != "new"){
?>
<script type="text/javascript">
<!--
// execute once on load
//check_input();
<?php
echo 'check_input("'.$attr_entry["datatype"].'");';
?>
// also check the naming_attr
check_naming_attr();
function check_input(datatype){
if (!datatype){
datatype = "text";
}
//var datatype = "<?php echo $attr_entry["datatype"] ?>";
switch (datatype) {
//switch (document.form1.datatype.value) {
case "text":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = false;
break;
case "password":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = true;
document.form1.max_length.disabled = false;
document.form1.conf.value = "no";
break;
case "select":
document.form1.poss_values.disabled = false;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
case "assign_one":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
case "assign_many":
case "assign_cust_order":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
}
}
function check_naming_attr(){
if (document.form1.naming_attr.value == "yes"){
document.form1.mandatory.value = "yes";
document.form1.mandatory.disabled = true;
}else{
document.form1.mandatory.disabled = false;
}
}
//-->
</script>
<?php
# Script part for add attribute
}else{
?>
<script type="text/javascript">
<!--
// execute once on load
//check_input();
<?php
echo 'check_input("'.$attr_entry["datatype"].'");';
?>
// also check the naming_attr
check_naming_attr();
function check_input(datatype){
if (!datatype){
datatype = "text";
}
//var datatype = "<?php echo $attr_entry["datatype"] ?>";
switch (datatype) {
//switch (document.form1.datatype.value) {
case "text":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = false;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
break;
case "password":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = true;
document.form1.max_length.disabled = false;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
document.form1.conf.value = "no";
break;
case "select":
document.form1.poss_values.disabled = false;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
break;
case "assign_one":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = false;
document.form1.link_as_child.disabled = false;
break;
case "assign_many":
case "assign_cust_order":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = false;
document.form1.link_as_child.disabled = false;
break;
}
}
function check_naming_attr(){
if (document.form1.naming_attr.value == "yes"){
document.form1.mandatory.value = "yes";
document.form1.mandatory.disabled = true;
}else{
document.form1.mandatory.disabled = false;
}
}
//-->
</script>
<?php
} // end of add or modify script path
mysql_close($dbh);
require_once 'include/foot.php';
?>