forked from nconf/nconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_class_write2db.php
153 lines (126 loc) · 5.28 KB
/
modify_class_write2db.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
<?php
require_once 'include/head.php';
// delay normaly short (given from config)
// but if there is a special message, the message should be read, so put the delay few seconds higher
$redirecting_delay = REDIRECTING_DELAY;
// read mandatory values
$class_id = $_POST['class_id'];
$config_class = $_POST['config_class'];
$friendly_name = $_POST['friendly_name'];
$nav_visible = $_POST['nav_visible'];
$ordering = $_POST['ordering'];
$out_file = $_POST['out_file'];
$nagios_object = $_POST['nagios_object'];
// process non-mandatory values
if(isset($_POST['new_group'])){
$new_group = $_POST['new_group'];
}else{
$new_group = "";
}
// New group or selected user/admin Group
if(isset($_POST['nav_privs'])){
$nav_privs = $_POST['nav_privs'];
if ( $new_group != "" ){
$grouping = $new_group;
}else{
if ($nav_privs == "user"){
if(isset($_POST['selectusergroup'])){
$grouping = $_POST['selectusergroup'];
}else{
$grouping = "";
}
}elseif ($nav_privs == "admin"){
if(isset($_POST['selectadmingroup'])){
$grouping = $_POST['selectadmingroup'];
}else{
$grouping = "";
}
}
}
}else{
// Should never come in this part...
$nav_privs = "";
$grouping = "";
}
if(isset($_POST['nav_links'])){
$nav_links = $_POST['nav_links'];
}else{
$nav_links = "";
}
if( ( $_POST['old_nav_privs'] != $nav_privs OR $_POST['old_group'] != $grouping ) OR ($class_id == "new") ){
$query = "SELECT MAX(ordering)+1 FROM ConfigClasses WHERE grouping = '$grouping' AND nav_privs = '$nav_privs'";
$ordering = db_handler($query, "getOne", "Get MAX ordering of coresponding group");
if ($ordering == NULL){
$ordering = 0;
}
}
// if class type select is disabled, no value will come, so get the one which is already set.
// this happens only on modifying
if(isset($_POST['class_type'])){
$class_type = $_POST['class_type'];
}else{
$class_type = db_templates("lookup_ConfigClasses", "class_type", $class_id);
}
# Check mandatory fields
$mandatory = array("config_class" => "Class name", "friendly_name" => "Friendly Name");
$write2db = check_mandatory($mandatory,$_POST);
if ($write2db == "yes"){
if ($class_id == "new"){
$title = "Add class";
// Generate navigation link string
$nav_links = 'Show::overview.php?class='.$config_class.';;Add::handle_item.php?item='.$config_class;
// Make insert (adding class)
$query = "INSERT INTO ConfigClasses (config_class, friendly_name, nav_visible, grouping, nav_links, nav_privs, class_type, ordering, out_file, nagios_object)
VALUES ('$config_class', '$friendly_name', '$nav_visible', '$grouping', '$nav_links', '$nav_privs', '$class_type', '$ordering', '$out_file', '$nagios_object')";
$action = "created";
}else{
$title = "Modify class";
// UPDATE ConfigAttrs
$action = "modified";
$query = "UPDATE ConfigClasses
SET
config_class = '$config_class',
friendly_name = '$friendly_name',
nav_visible = '$nav_visible',
grouping = '$grouping',
nav_links = '$nav_links',
nav_privs = '$nav_privs',
class_type = '$class_type',
ordering = '$ordering',
out_file = '$out_file',
nagios_object = '$nagios_object'
WHERE
id_class = $class_id
";
}
$result = db_handler($query, "result", "$action Entry");
if($result){
echo "<h2>$title</h2>Successfully $action class "$config_class"";
history_add($action, "Class", $config_class);
// Go to next page without pressing the button
echo '<meta http-equiv="refresh" content="'.$redirecting_delay.'; url='.$_SESSION["go_back_page_ok"].'">';
NConf_DEBUG::set('<a href="'.$_SESSION["go_back_page_ok"].'"> [ this page ] </a>', 'INFO', "<br>redirecting to");
}else{
echo "<h2>Failed to $action attribute "$config_class"</h2>";
}
}else{
if ( isset($_SESSION["cache"]["modify_class"]) ) unset($_SESSION["cache"]["modify_class"]);
if ( NConf_DEBUG::status('ERROR') ) {
echo NConf_DEBUG::show_debug('ERROR', TRUE, $_SESSION["go_back_page"]);
// Cache
foreach ($_POST as $key => $value) {
if ($key == "selectusergroup"){
$_SESSION["cache"]["modify_class"][$class_id]["grouping"] = $value;
}elseif ($key == "selectadmingroup"){
$_SESSION["cache"]["modify_class"][$class_id]["grouping"] = $value;
}else{
$_SESSION["cache"]["modify_class"][$class_id][$key] = $value;
}
}
}else{
echo NConf_DEBUG::show_debug('INFO', TRUE);
}
}
mysql_close($dbh);
require_once 'include/foot.php';
?>