forked from nconf/nconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_item.php
1287 lines (1083 loc) · 58.8 KB
/
handle_item.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once 'include/head.php';
set_page();
?>
<!-- jQuery part -->
<script type="text/javascript">
$(document).ready(function(){
$("#loading").hide();
$("#check_command_select").change(function() {
$("form").find('input[type=submit]').prepend('<input type="hidden" name="check_command_changed" value="true">');
$("form").find('input[type=submit]').click();
});
// mode for multimodify
$("input[name='replace_mode']").change(function() {
if ($("input[name='replace_mode']:checked").val() == 'replace'){
$("#info_box").hide("blind", "slow", function(){
$("#mode_add_title").hide();
$("#mode_add_title").prev().show();
$("#info_box").show("blind", "slow");
});
}else if ($("input[name='replace_mode']:checked").val() == 'add'){
$("#info_box").hide("blind", "slow", function(){
$("#mode_add_title").prev().hide();
$("#mode_add_title").show();
$("#info_box").show("blind", "slow");
});
}
});
/* resizable feature */
$('div.multipleSelectBoxControl.ui-nconf-content').each(function () {
$(this).resizable({
handles: "e",
minWidth: 530
});
});
});
</script>
<?php
// Autocomplete
if ( defined('AUTO_COMPLETE_PIKETT') AND AUTO_COMPLETE_PIKETT != "0" ){
//Get Pikett email and pager list
include('include/modules/sunrise/autocomplete/pikett_users.php');
// Create pikett / pager list for autocomplete
$prepare_status = js_Autocomplete_prepare('emaillist', $emaillist);
$prepare_status = js_Autocomplete_prepare('pagerlist', $pagerlist);
}
###
# Use Session cache only if back button was clicked
###
# otherwise delete cache:
if ( !isset($_POST["back"]) AND !isset($_SESSION["cache"]["use_cache"]) ){
if ( isset($_SESSION["cache"]["handle"]) ) unset($_SESSION["cache"]["handle"]);
if ( isset($_SERVER["HTTP_REFERER"]) ) $_SESSION["go_back_page_ok"] = $_SERVER["HTTP_REFERER"];
// remove use_cache
}
if ( isset($_SESSION["cache"]["use_cache"]) ){
unset($_SESSION["cache"]["use_cache"]);
}
###
# coming from modify item service
###
# Check for coming from "modify item service" (<edit>) and performing an "clone service"
# if true, we have to change the go back page ok (otherwise the session check will fail)
if ( !empty($_SESSION["go_back_page_ok"]) && (strpos($_SESSION["go_back_page_ok"], "cloneONhost") !== FALSE) ){
$hostID = db_templates("hostID_of_service", $_GET["id"]);
$_SESSION["go_back_page_ok"] = 'modify_item_service.php?item=service&id='.$hostID;
}
# The replace mode is only for multimodify so disable it generally
$replace_mode = 0;
###
# Handle add / modify / multimodify
###
if ( !empty($_GET["id"]) ){
# modify item
NConf_DEBUG::set("", 'DEBUG', "collected data of selected item", TRUE);
if(isset($_GET["xmode"])){
# Special mode to allow ordinary users to change on-call settings
# get id_item based on contact name
$query = 'SELECT fk_id_item FROM ConfigValues,ConfigAttrs,ConfigClasses
WHERE id_attr = fk_id_attr
AND naming_attr = "yes"
AND id_class = fk_id_class
AND config_class = "contact"
AND attr_value = "'.$_GET["xmode"].'"';
$qres = mysql_query($query);
$entry = mysql_fetch_assoc($qres);
$_GET["id"] = $entry["fk_id_item"];
$item_class = "contact";
}else{
# get $item_class
$item_class = db_templates("class_name", $_GET["id"]);
if (!$item_class){
NConf_DEBUG::set("This item does not exist", 'ERROR');
}
}
# get basic entries (ConfigValues) for passed id
$query = mysql_query('SELECT id_attr,attr_value
FROM ConfigAttrs,ConfigValues,ConfigItems
WHERE id_attr=fk_id_attr
AND id_item=fk_id_item
AND visible="yes"
AND id_item='.$_GET["id"].'
ORDER BY ordering');
$item_data = array();
while($entry = mysql_fetch_assoc($query)){
$item_data[$entry["id_attr"]] = $entry["attr_value"];
}
# get linked entries (ItemLinks) for passed id
$query2 = 'SELECT id_attr,attr_value,fk_item_linked2
FROM ConfigValues,ItemLinks,ConfigAttrs
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ItemLinks.fk_id_attr
AND ConfigAttrs.visible="yes"
AND (SELECT naming_attr FROM ConfigAttrs WHERE id_attr=ConfigValues.fk_id_attr)="yes"
AND ItemLinks.fk_id_item='.$_GET["id"].'
ORDER BY
ConfigAttrs.friendly_name DESC,
ItemLinks.cust_order
';
$result2 = db_handler($query2, "result", "linked entries");
$item_data2 = array();
while($entry2 = mysql_fetch_assoc($result2)){
$item_data2[$entry2["id_attr"]][$entry2["fk_item_linked2"]] = $entry2["attr_value"];
}
# get entries linked as child (ItemLinks) for passed id
$query3 = 'SELECT id_attr,attr_value,ItemLinks.fk_id_item
FROM ConfigValues,ItemLinks,ConfigAttrs
WHERE ItemLinks.fk_id_item=ConfigValues.fk_id_item
AND id_attr=ItemLinks.fk_id_attr
AND ConfigAttrs.visible="yes"
AND (SELECT naming_attr FROM ConfigAttrs WHERE id_attr=ConfigValues.fk_id_attr)="yes"
AND ItemLinks.fk_item_linked2='.$_GET["id"].'
ORDER BY ConfigAttrs.friendly_name DESC';
$result3 = db_handler($query3, "result", "Linked as child");
while($entry3 = mysql_fetch_assoc($result3)){
$item_data2[$entry3["id_attr"]][$entry3["fk_id_item"]] = $entry3["attr_value"];
}
if ($item_class == "service" OR $item_class == "advanced-service"){
# get id of attr check_command
$check_command_attr_id = db_templates("get_attr_id", $item_class, "check_command");
$host_name_attr_id = db_templates("get_attr_id", $item_class, "host_name");
}
# debug infos
NConf_DEBUG::set($item_data, 'DEBUG', "item_data");
NConf_DEBUG::set($item_data2, 'DEBUG', "item_data2");
NConf_DEBUG::close_group();
$handle_action = "modify";
$form_action = 'modify_item_write2db.php';
}elseif (isset($_GET["type"]) AND $_GET["type"] == "multimodify" ){
###
# multimodify
###
# handle configuration
$handle_action = "multimodify";
$form_action = 'multimodify_attr_write2db.php';
###
# some URL handling
###
# set overview page to goto after modification
$_SESSION["go_back_page_ok"] = $_SESSION["after_delete_page"];
$url = basename($_SERVER['REQUEST_URI']);
# url for select attribute
$form_action_attr_select = $url;
# check cache
if ( !empty($_SESSION["cache"]["handle"]) ){
if ( isset($_SESSION["cache"]["handle"]["HIDDEN_config_class"]) ){
$_POST["class"] = $_SESSION["cache"]["handle"]["HIDDEN_config_class"];
}
if ( isset($_SESSION["cache"]["handle"]["HIDDEN_config_class"]) ){
$_POST["ids"] = $_SESSION["cache"]["handle"]["HIDDEN_modify_ids"];
}
if ( isset($_SESSION["cache"]["handle"]["HIDDEN_selected_attr"]) ){
$_POST["attr"] = $_SESSION["cache"]["handle"]["HIDDEN_selected_attr"];
}
}
# check class
if ( empty($_POST["class"]) ){
NConf_DEBUG::set("No class set", 'ERROR');
}else{
$item_class = $_POST["class"];
}
# check ids
if ( empty($_POST["advanced_items"]) AND empty($_POST["ids"])) {
message($error, "No items selected to write to");
}
# replace mode
if ( isset($_SESSION["cache"]["handle"]["replace_mode"]) ){
if ($_SESSION["cache"]["handle"]["replace_mode"] == "add") {
$replace_mode = 2;
}elseif ($_SESSION["cache"]["handle"]["replace_mode"] == "replace") {
$replace_mode = 1;
}
}else{
$replace_mode = 2;
}
}else{
# add item
if( empty($_GET["item"]) ){
NConf_DEBUG::set("No config_class set", 'ERROR');
}
$handle_action = "add";
$form_action = 'add_item_step2.php';
$item_class = $_GET["item"];
$class_ID = db_templates('get_id_of_class', $item_class);
if (!$class_ID){
NConf_DEBUG::set("This class does not exist", 'ERROR');
}
# get id of attr check_command
$check_command_attr_id = db_templates("get_attr_id", $item_class, "check_command");
if ( !empty($_GET[$check_command_attr_id]) ){
$_SESSION["cache"]["handle"][$check_command_attr_id][0] = $_GET[$check_command_attr_id];
}
}
if ( empty($item_class) ) $item_class = '';
NConf_DEBUG::set($handle_action, 'DEBUG', 'Handle action: ');
NConf_DEBUG::set($item_class, 'DEBUG', 'Handle class: ');
#########################################################################
#########################################################################
###
# Title
###
#header blox
echo '<div class="ui-nconf-header ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix">';
echo '<div>';
echo '<h2>'.ucfirst($handle_action).' '.$item_class.'</h2>';
echo '</div>';
echo '</div>';
# content blox
echo '<div class="ui-nconf-content ui-widget-content ui-corner-bottom">';
// end / exit page if error
if ( NConf_DEBUG::status('ERROR') ) {
echo NConf_HTML::exit_error();
}
###
# Form header for multimodify (attribute selection)
###
if ($handle_action == "multimodify"){
# naming attr
if ($item_class != "service"){
message($info, "the naming attribute is not listed, because it's not allowed to have multiple identical naming attributes");
}
# output for select attribute
$result_array = db_templates("get_attributes_with_bidirectional", $item_class);
echo '<fieldset class="inline ui-widget-content">';
echo '<legend><b>Select the attribute which you want to modify </b></legend>';
echo '<form name="select_attr" action="'.$form_action_attr_select.'" method="post">';
# add selected items and class
echo '<input name="class" type="hidden" value="'.$item_class.'">';
if ( empty($_POST["ids"]) ){
$id_items = implode(",", $_POST["advanced_items"]);
}else{
$id_items = $_POST["ids"];
}
echo '<input name="ids" type="hidden" value="'.$id_items.'">';
echo '<div id=buttons>';
echo '<select name="attr" onchange="document.select_attr.submit()">';
foreach ($result_array AS $attr ){
# Naming attributes should not be the same on multiple items, so its not allowed to modify it on multiple items
if ($attr["naming_attr"] == "no" OR $item_class == "service" ){
echo '<option value="'.$attr["attr_name"].'"';
if (!empty($_POST["attr"]) AND $_POST["attr"] == $attr["attr_name"]) echo " SELECTED";
echo '>'.$attr["friendly_name"].'</option>';
}
}
echo '</select>';
echo ' <input type="Submit" value="next" name="send" align="middle">';
echo '</div>';
echo '</form>';
echo '</fieldset>';
}
if(
( (isset($item_class) AND !empty($item_class)) )
AND (
$handle_action != "multimodify" OR ( $handle_action == "multimodify" AND !empty($_POST["attr"]) )
)
){
echo '<div style="height: 20px;">
<div id="loading">
<img src="img/working_small.gif"> in progress...
</div>
</div>';
###
# Form start
###
echo '<form name="handle_item" action="'.$form_action.'" method="post" onsubmit="multipleSelectOnSubmit()">';
if ($handle_action == "add"){
# add
echo '<input name="config_class" type="hidden" value="'.$item_class.'">';
}else{
# modify / multimodify
echo '<input name="HIDDEN_config_class" type="hidden" value="'.$item_class.'">';
if ($handle_action == "modify") echo '<input name="HIDDEN_modify_id" type="hidden" value="'.$_GET["id"].'">';
if ($handle_action == "multimodify"){
echo '<input name="HIDDEN_modify_ids" type="hidden" value="'.$_POST["ids"].'">';
echo '<input name="HIDDEN_selected_attr" type="hidden" value="'.$_POST["attr"].'">';
}
}
//$notification_period_attribute_id = db_templates("get_attr_id", "host", "notification_period");
//$check_period_attribute_id = db_templates("get_attr_id", "host", "check_period");
$contact_groups_attribute_id = db_templates("get_attr_id", "host", "contact_groups");
$class_ID = db_templates('get_id_of_class', $item_class);
NConf_DEBUG::open_group("prepare data");
# bidirectional class check
if ($handle_action == "multimodify"){
$result_array = db_templates("get_attributes_with_bidirectional", $item_class, $_POST["attr"]);
# set special Fieldset
echo '<fieldset class="inline ui-widget-content">';
echo '<legend><b>New value to write</b></legend>';
}else{
$result_array = db_templates("get_attributes_with_bidirectional", $item_class);
}
NConf_DEBUG::close_group();
if ( count($result_array) == 0){
// warn if class contains no attrbibutes
NConf_DEBUG::set('There are no attributes defined for this class.', 'ERROR');
}
if ( NConf_DEBUG::status('ERROR') ) {
$content = NConf_HTML::show_error();
$content .= "<br><br>";
if (!empty($_SESSION["after_delete_page"]) ){
$link = $_SESSION["after_delete_page"];
}else{
$link = "index.php";
}
$content .= NConf_HTML::back_button($link);
echo NConf_HTML::limit_space($content);
mysql_close($dbh);
require_once 'include/foot.php';
exit;
}
// seems not really nice, disabled for new theme
//echo '<table border="0" style="table-layout:fixed; width:770px">';
echo '<table>';
# predefine col width
echo define_colgroup();
foreach ($result_array AS $entry ){
if( ($handle_action != "modify") AND !empty($entry["predef_value"]) ){
# add / multimodify
$item_data[$entry["id_attr"]] = $entry["predef_value"];
// debug must be redone with message:
NConf_DEBUG::set($entry["predef_value"], 'DEBUG', 'predefined value of '.$entry["attr_name"].' ('.$entry["id_attr"].')');
}
###
# check for bidirectional attribute
###
# if they are of "assign_one" types, they must be displayed as assign_many!
if( $class_ID != $entry["fk_id_class"] AND
( $entry["link_bidirectional"] == "yes" AND $entry["datatype"] == "assign_one" )
){
$entry["datatype"] = "assign_many";
message($debug, '<b>Bidirectional</b> Changed output of bidirectional item from assign_one to assign_many');
}
# assign_many needs special tr class for setting margin
if($entry["datatype"] == "assign_many"
OR $entry["datatype"] == "assign_cust_order" ){
//echo '<tr class="assign_many">'.$command_args;
echo '<tr class="assign_many">';
}else{
//echo '<tr>'.$command_args;
echo '<tr>';
}
# set special Fieldset for check_params
if ( ($item_class == "service" OR $item_class == "advanced-service") AND $entry["attr_name"] == "check_params"){
#do nothing here, print title later if really needed
}else{
echo '<td class="middle">'.$entry["friendly_name"].'</td>';
}
# check if items being displayed are "services"
if(isset($entry["fk_show_class_items"])){
$srvquery = mysql_query('SELECT config_class FROM ConfigClasses WHERE id_class='.$entry["fk_show_class_items"]);
$srv = mysql_fetch_assoc($srvquery);
}
### process "text" fields
if ($entry["datatype"] == "text"){
# check special case for check_params
if ( ($item_class == "service" OR $item_class == "advanced-service") AND $entry["attr_name"] == "check_params"){
# check_param stuff
NConf_DEBUG::open_group("params for check command (service parameters)");
# get id of check_command
if ($handle_action == "add"){
if ( !empty($_SESSION["cache"]["handle"][$check_command_attr_id][0]) ){
$check_command_id = $_SESSION["cache"]["handle"][$check_command_attr_id][0];
}elseif( !empty($check_command_first_id) ){
# When adding a new service, this will help displaying the correct command_param for the first check_command
# This is only needed for not changed check_command select field
$check_command_id = $check_command_first_id;
}
$command_param_count = db_templates("get_command_param_count_of_checkcommand", $check_command_id);
# Read default checkcommand params of selected check command and override predefined value (which makes more sense here)
$default_params = db_templates("get_default_checkcommand_params", $check_command_id);
$item_data[$entry["id_attr"]] = $default_params;
}elseif( $handle_action == "modify" AND !empty($_GET["id"]) ){
$check_command_id = db_templates("get_checkcommand_of_service", $_GET["id"]);
$command_param_count = db_templates("get_command_param_count_of_checkcommand", $check_command_id);
}elseif( $handle_action == "multimodify" AND !empty($_POST["ids"]) ){
# process multivalue fields
# special
# its riski to allow to multimodify the check_command of mutliple (perhaps different) services
# perhaps more checks are needed here
$service_items = explode(",", $id_items);
$command_param_count_array = array();
$most_counts = 0;
foreach ($service_items AS $service_item){
$temp_check_command_id = db_templates("get_checkcommand_of_service", $service_item);
$command_param_count = db_templates("get_command_param_count_of_checkcommand", $temp_check_command_id);
$command_param_count_array[] = $command_param_count;
if ($command_param_count > $most_counts){
$most_counts = $command_param_count;
$check_command_id = $temp_check_command_id;
}
}
NConf_DEBUG::set($command_param_count_array, "DEBUG", "Command param counters");
# check if count is different for selected services
$command_param_count_unique = array_unique($command_param_count_array);
if (count($command_param_count_unique) > 1){
$warning_check_command_arguments = TXT_MULTIMODIFY_PARAMS_OF_CHECK_COMMAND_DIFFER;
}
$command_param_count = $most_counts;
}
if ($command_param_count == "0"){
# no command syntax if param count == 0
# display no attribute but value of hidden attribute must be "!"
echo '
<td>
<input name="'.$entry["id_attr"].'" type="hidden" value="!">
</td>';
# continue with next attribute (normaly these are bidirectional ones, param count is the last of normal attributes)
# but this will ignore all the next text/select etc logic
echo '</tr>';
continue;
}elseif( $command_param_count > 0 ){
echo '<td class="middle">'.$entry["friendly_name"].'</td>';
echo '<td colspan=3>';
echo '<fieldset class="inline ui-widget-content">';
echo '<legend><b>service parameters</b></legend>';
if ( isset( $_SESSION["cache"]["handle"][$entry["id_attr"]] )
AND empty( $_SESSION["cache"]["handle"][$entry["id_attr"]]["check_command_changed"] )
){
$value = $_SESSION["cache"]["handle"][$entry["id_attr"]];
}elseif ( isset($item_data[$entry["id_attr"]]) ){
$value = $item_data[$entry["id_attr"]];
}else{
$value = "";
}
# command
$commands_split = explode("!", $value);
#
# Handle \! in commands
# Nagios allows to put \! in commands, so do not split that
# Put commands back together if a \! was split bevore
#
$commands_array = array();
$command = '';
foreach($commands_split as $command_part){
$command .= $command_part;
# if command ends with a backslash (\) the next command must be attached with a !
if ( preg_match("/\\\\$/", $command) ){
# if there is a backslash at the end, add the !
$command .= "!";
}else{
# command doesn't end with a backslash (\) so put it in array
$commands_array[] = $command;
$command = '';
}
}
# get syntax of arguments
# Get command syntax
$command_query = 'SELECT attr_value FROM ConfigValues,ConfigAttrs
WHERE id_attr=fk_id_attr
AND attr_name="command_syntax"
AND fk_id_item='.$check_command_id;
$cmd_syntax_string = db_handler($command_query, "getOne", "Get command syntax");
$cmd_syntax = explode(",", $cmd_syntax_string);
# generate html output
echo '<table class="ui-nconf-max-width">';
for ($i = 1; $i <= $command_param_count; $i++){
# If not set make empty because of php offset failure
if ( !isset($commands_array[$i]) ){
$commands_array[$i] = '';
}
if ( !isset($cmd_syntax[$i]) ){
$cmd_syntax[$i] = $i;
}
echo '<tr>';
echo '<td align=right>ARG'.$i.': </td>
<td colspan=2>
<input name="exploded['.$entry["id_attr"].'][]" type=text maxlength='.$entry["max_length"].' value="'.htmlspecialchars($commands_array[$i]).'">
</td>';
# remove ARG1 etc from description
$syntax_description = preg_replace('/ARG\d+\s*=\s*/i', '', $cmd_syntax[$i-1]);
echo '<td>'.$syntax_description.'</td>';
echo '</tr>';
}
echo '</table>';
# unset $command_param_count for next loop
unset($command_param_count);
NConf_DEBUG::close_group();
}
#close special td and fieldset
echo '</td></fieldset>';
}else{
###
# normal text case
###
if ( ( isset($_SESSION["cache"]["handle"][$entry["id_attr"]]) ) ){
$value = $_SESSION["cache"]["handle"][$entry["id_attr"]];
}elseif ( isset($item_data[$entry["id_attr"]]) ){
$value = $item_data[$entry["id_attr"]];
}else{
$value = "";
}
//special auto complete
//if ($entry["attr_name"] == "email" OR $entry["attr_name"] == "pager"){
if ( preg_match("/[email|pager]/", $entry["attr_name"]) ){
echo '<td>
<input id="'.$entry["attr_name"].'" name="'.$entry["id_attr"].'" type=text maxlength='.$entry["max_length"].' value="'.htmlspecialchars($value).'">
</td>';
}else{
echo '<td>
<input name="'.$entry["id_attr"].'" type=text maxlength='.$entry["max_length"].' value="'.htmlspecialchars($value).'">
</td>';
}
}
# process "password" fields
}elseif($entry["datatype"] == "password"){
if ( ( isset($_SESSION["cache"]["handle"][$entry["id_attr"]]) ) ){
$value = $_SESSION["cache"]["handle"][$entry["id_attr"]];
}elseif ( isset($item_data[$entry["id_attr"]]) ){
$value = $item_data[$entry["id_attr"]];
$value = show_password($value);
}else{
$value = "";
}
echo '<td>
<input name="'.$entry["id_attr"].'" type=password maxlength='.$entry["max_length"].' value="'.htmlspecialchars($value).'">
</td>';
# process "select" fields
}elseif($entry["datatype"] == "select"){
// ADMIN users only
if ( ($_SESSION["group"] != "admin") AND ( in_array($entry["attr_name"], $ADMIN_ONLY) ) ){
echo '<input name="'.$entry["id_attr"].'" type="HIDDEN" value="'.$entry["predef_value"].'">';
}
$dropdown = preg_split("/".SELECT_VALUE_SEPARATOR."/", $entry["poss_values"]);
echo '<td><select name="'.$entry["id_attr"].'" size="0"';
// ADMIN users only
if ( ($_SESSION["group"] != "admin") AND ( in_array($entry["attr_name"], $ADMIN_ONLY) ) ){
echo " DISABLED";
}
echo '>';
if ($entry["mandatory"] == "no"){
echo '<option value="">'.SELECT_EMPTY_FIELD.'</option>';
}
foreach ($dropdown as $menu){
echo "<option";
if ( isset($_SESSION["cache"]["handle"][$entry["id_attr"]]) ){
if ( $menu == $_SESSION["cache"]["handle"][$entry["id_attr"]] ){
echo " SELECTED";
}
}elseif ( ( isset($item_data[$entry["id_attr"]]) ) AND ($menu == $item_data[$entry["id_attr"]]) ){
echo " SELECTED";
}
echo ">$menu</option>";
}
echo "</select></td>";
# process "assign_one" fields
}elseif($entry["datatype"] == "assign_one"){
if ($srv["config_class"] == "service"){
$query2 = 'SELECT id_item,attr_value,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"';
if ($handle_action == "modify"){
$query2 .= ' AND id_item <> '.$_GET["id"];
}
$query2 .= ' AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
ORDER BY hostname,attr_value';
}else{
$query2 = 'SELECT id_item,attr_value
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"';
if ($handle_action == "modify"){
$query2 .= ' AND id_item <> '.$_GET["id"];
}
$query2 .= ' AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
ORDER BY attr_value';
}
$result2 = db_handler($query2, "result", "assign_one");
if ($handle_action == "add" AND ($item_class == "service" OR $item_class == "advanced-service") AND $entry["id_attr"] == $check_command_attr_id){
# special for check_command
$check_command_first_id = db_handler($query2.' LIMIT 1', "getOne", "get id of first checkcommand for check params / arguments");
echo '<td><select id="check_command_select" name="'.$entry["id_attr"].'[]">';
}elseif($handle_action == "modify" AND ($item_class == "service" OR $item_class == "advanced-service") AND ($entry["id_attr"] == $check_command_attr_id OR $entry["id_attr"] == $host_name_attr_id) ){
# modify service should have disabled check_command and hostname
echo '<td><select name="'.$entry["id_attr"].'[]" disabled=disabled>';
}else{
echo '<td><select name="'.$entry["id_attr"].'[]">';
}
if ($entry["mandatory"] == "no"){
echo '<option value="">'.SELECT_EMPTY_FIELD.'</option>';
}
while($menu2 = mysql_fetch_assoc($result2)){
//NConf_DEBUG::set($menu2["id_item"].'+++'.$menu2["attr_value"], 'DEBUG', "id attr ".$entry["id_attr"]." : value @ itemdata(idattr)".$item_data[$entry["id_attr"]]);
//NConf_DEBUG::set(NConf_HTML::swap_content($item_data, "hmmm"), 'DEBUG', "hmmm");
echo '<option value='.$menu2["id_item"];
if ( isset($_SESSION["cache"]["handle"][$entry["id_attr"]]) ) {
if ( $_SESSION["cache"]["handle"][$entry["id_attr"]][0] == $menu2["id_item"] ){
echo " SELECTED";
}
}else{
# not in cache, handle "add" and "modify" different
if ($handle_action != "modify"){
# add / multimodify
if ( is_array($entry["predef_value"]) ){
if ($menu2["id_item"] == $entry["predef_value"][0]) echo ' SELECTED';
}else{
if ($menu2["attr_value"] == $entry["predef_value"]) echo ' SELECTED';
}
}else{
# modify
if( isset($item_data2[$entry["id_attr"]][$menu2["id_item"]]) ) {
echo ' SELECTED';
}
}
}
if ($srv["config_class"] == "service"){
echo '>'.$menu2["hostname"].': '.$menu2["attr_value"].'</option>';
}else{
echo '>'.$menu2["attr_value"].'</option>';
}
}
echo '</select></td>';
# process "assign_many" fields
}elseif($entry["datatype"] == "assign_many"){
if ($srv["config_class"] == "service"){
if ($handle_action != "modify"){
# add / multimodify
$query2 = 'SELECT id_item,attr_value,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
ORDER BY hostname,attr_value';
}else{
# modify
$query2 = 'SELECT id_item,attr_value,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND id_item <> '.$_GET["id"].'
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
AND (SELECT fk_id_item FROM ItemLinks,ConfigAttrs,ConfigClasses
WHERE id_attr=fk_id_attr
AND id_class=fk_id_class
AND config_class="'.$item_class.'"
AND (attr_name="parents" OR attr_name="dependent_service_description")
AND fk_item_linked2="'.$_GET["id"].'"
AND fk_id_item=id_item) IS NULL
ORDER BY hostname,attr_value';
}
}else{
if ($handle_action != "modify"){
# add / multimodify
$query2 = 'SELECT id_item,attr_value
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
ORDER BY attr_value';
}else{
# modify
$query2 = 'SELECT id_item,attr_value
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND id_item <> '.$_GET["id"].'
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
AND (SELECT fk_id_item FROM ItemLinks,ConfigAttrs,ConfigClasses
WHERE id_attr=fk_id_attr
AND id_class=fk_id_class
AND config_class="'.$item_class.'"
AND (attr_name="parents" OR attr_name="dependent_service_description")
AND fk_item_linked2="'.$_GET["id"].'"
AND fk_id_item=id_item) IS NULL
ORDER BY attr_value';
}
}
$result2 = db_handler($query2, "result", "assign_many");
echo '<td colspan=3>
<div class="select-container">
<select id="fromBox_'.$entry["id_attr"].'" name="from_'.$entry["id_attr"].'[]" style="'.CSS_SELECT_MULTI.'" multiple ';
/*# Load ajax info for PRIO's
if ($entry["id_attr"] == $contact_groups_attribute_id){
echo ' onmouseover="attachInfo(this, \'contacts\')"';
}*/
echo '>';
# split predef value
$predef_value = preg_split("/".SELECT_VALUE_SEPARATOR."/", $entry["predef_value"]);
$selected_items = array();
while($menu2 = mysql_fetch_assoc($result2)){
// SELECTED
if ( isset($_SESSION["cache"]["handle"][$entry["id_attr"]]) ) {
if ( in_array($menu2["id_item"], $_SESSION["cache"]["handle"][$entry["id_attr"]]) ){
$selected_items[] = $menu2;
continue;
}
}else{
if ($handle_action != "modify"){
# add / multimodify
# select predefined values
if ( is_array($predef_value) ){
if ( in_array($menu2["attr_value"], $predef_value) ){
$selected_items[] = $menu2;
continue;
}
}
}else{
# modify
if ( isset($item_data2[$entry["id_attr"]]) AND is_array($item_data2[$entry["id_attr"]]) ){
if ( array_key_exists($menu2["id_item"], $item_data2[$entry["id_attr"]] ) ){
$selected_items[] = $menu2;
continue;
}
}
}
}
echo '<option value='.$menu2["id_item"];
if ($srv["config_class"] == "service"){
echo '>'.$menu2["hostname"].': '.$menu2["attr_value"].'</option>';
}else{
echo '>'.$menu2["attr_value"].'</option>';
}
}
echo '</select>';
# fill "selected items" with session or predefiend data
echo '<select multiple name="'.$entry["id_attr"].'[]" id="toBox_'.$entry["id_attr"].'"';
/*# Load ajax info for PRIO's
if ($entry["id_attr"] == $contact_groups_attribute_id){
echo ' onmouseover="attachInfo(this, \'contacts\')"';
}*/
echo '>';
foreach ($selected_items AS $selected_menu){
echo '<option value='.$selected_menu["id_item"];
/*# Load ajax info for PRIO's
if ($entry["id_attr"] == $contact_groups_attribute_id){
echo ' onmouseover="getText(this, \'contacts\')"';
}*/
// END of SELECTED
if ($srv["config_class"] == "service"){
echo '>'.$selected_menu["hostname"].': '.$selected_menu["attr_value"].'</option>';
}
else{
echo '>'.$selected_menu["attr_value"].'</option>';
}
}
echo '</select>';
echo '</div>';
# assign_cust_order handling
$assign_cust_order = ($entry["datatype"] == "assign_cust_order") ? 1 : 0;
echo '
<script type="text/javascript">
createMovableOptions("fromBox_'.$entry["id_attr"].'","toBox_'.$entry["id_attr"].'",530,145,"available items","selected items","livesearch",'.$assign_cust_order.','.$replace_mode.');
</script>
';
echo '</td>';
# process "assign_cust_order" fields
}elseif($entry["datatype"] == "assign_cust_order"){
if ($srv["config_class"] == "service"){
if ($handle_action != "modify"){
# add / multimodify
$query2 = 'SELECT id_item,attr_value,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
ORDER BY hostname,attr_value';
}else{
#modify
$query2 = 'SELECT id_item,attr_value,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND id_item <> '.$_GET["id"].'
AND ConfigItems.fk_id_class='.$entry["fk_show_class_items"].'
AND (SELECT fk_id_item FROM ItemLinks,ConfigAttrs,ConfigClasses
WHERE id_attr=fk_id_attr
AND id_class=fk_id_class
AND config_class="'.$item_class.'"
AND (attr_name="parents" OR attr_name="dependent_service_description")
AND fk_item_linked2="'.$_GET["id"].'"
AND fk_id_item=id_item) IS NULL
ORDER BY hostname,attr_value';
}
}else{
if ($handle_action != "modify"){
# add / multimodify
$query2 = 'SELECT id_item,attr_value
FROM ConfigItems,ConfigValues,ConfigAttrs
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"