File: timeperiodedit.php

package info (click to toggle)
nagat 1.0a2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 312 kB
  • ctags: 377
  • sloc: php: 2,604; sh: 78; makefile: 42
file content (169 lines) | stat: -rw-r--r-- 4,336 bytes parent folder | download
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
<?php
# $Id: timeperiodedit.php,v 1.6 2002/06/21 10:27:38 kemuri Exp $

/*
 * Copyright (c) 2002 Ypsilon.Net AG, Germany
 *
 * This file is part of Nagat.
 * 
 * Nagat is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * Nagat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Nagat; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

# Page variables
define("PAGE_ID","timeperiodedit");
define("PAGE_TITLE","Timeperiod object");
define("OBJECTTYPE","timeperiod");

require_once("local.inc");

$action = @strtolower($action);
$message = '';

# Actions before output is send
switch($action) {
	case 'save':
		$name = $saveobject['name'] ? 
			$saveobject['name'] : $saveobject[OBJECTTYPE.'_name'];

		# Check data and bailout when there are errors
#		if( $name != $timeperiodname &&
#			NagiosSearchObject(OBJECTTYPE, $nagios_objects, 
#				$name) != NULL ) {
#			$errmsg = "Timeperiod named '$name' already exists.";
#			$object = $saveobject;
#			break;
#		}

		$objectid = PluginSaveObject($objectid,$saveobject,OBJECTTYPE);
		header("Location: timeperiodedit.php?objectid=$objectid");
		exit();
		break;
	case 'delete':
		$objectid = PluginDeleteObject($objectid,OBJECTTYPE);
		header("Location: timeperiods.php");
		break;
}

include_once(NGT_LIB."head.inc");

if( is_array($object) == FALSE) {
	$object = PluginGetObject($objectid,OBJECTTYPE);
}

$timeperiodname = isset($object[OBJECTTYPE."_name"]) ? 
	$object[OBJECTTYPE."_name"] : $object['name']; 
if( !empty($object['name']) ) {
	$cntinh = NagiosCountInherited(OBJECTTYPE,$timeperiodname);
}

if( !empty($object['use']) ) {
	$inhobject = PluginGetObjectByName($object['use'],OBJECTTYPE);
	foreach($inhobject as $key => $value) {
		$object['++'.$key] = $value;
	}
}

# Get a default cfg file if object is new
if( $object['__cfgfile'] == "") {
  $objects = PluginGetObjects(OBJECTTYPE);
  $firstobject = reset($objects);
  $object['__cfgfile'] = $firstobject['__cfgfile'];
}
foreach( $confobjects[OBJECTTYPE] as $key => $propconf ) {

	$required = 'label';
	$value = $object[$key];
	$inhhtml = "";
	
	if( $inhvalue = $object["++".$key] ) {
	   $inhhtml = "  <td>$inhvalue</td>";
           $reqclass = 'requiredok';
	} else {
	   $reqclass = 'required';
	}
	
  	$show = NagiosObjPropEdit(OBJECTTYPE,$key,"saveobject[$key]",$value);

	if( $object['name'] == '' ) {
		$required = $propconf[2] == TRUE ? $reqclass : 'label';
	}

	$rows[$key] = <<<HTML
<tr>
  <td class="label">$key</td>
  <td class="$required" with="3">&nbsp;</td>
  <td class="value">
  $show
  </td>
  $inhhtml
</tr>
HTML;
}

?>
<form method="post">
<input type="hidden" name="timeperiodname" value="<?=$timeperiodname?>">
<input type="hidden" name="objectid" value="<?=$object['__objectid']?>">
<input type="hidden" name="saveobject[__cfgfile]" value="<?=$object['__cfgfile']?>">
<input type="hidden" name="saveobject[__type]" value="<?=$object['__type']?>">

<table cellpadding="3" border="0">
<tr>
  <td colspan="3" align="left">
  <?=ErrorMsg($errmsg)?>
  <b><?=$message?>&nbsp;</b>
  </td>
</tr>
<tr>
  <td colspan="3" align="right">
  <input type="submit" name="action" value="Save">
  <input type="submit" name="action" value="Delete">
  </td>
</tr>
<tr class="rowsep">
  <td colspan="3">Properties</td>
<?php
if( !empty($object['use']) ) {
	$parent = PluginGetObjectByName($object['use'],OBJECTTYPE);
	print <<<HTML
  <td>
  Inherits from 
  <a href="timeperiodedit.php?objectid={$parent['__objectid']}"><b>{$parent['name']}</b></a>
  </td>
HTML;
}
?>
</tr>
<?=implode("\n", $rows)?>
<?

if ( $cntinh > 0 ) {
	print ObjectInheritance($timeperiodname,OBJECTTYPE);
}

$userobjs = NagiosObjectUsage($timeperiodname,OBJECTTYPE);
if ( $userobjs != NULL ) {
	print ObjectUsage($timeperiodname,OBJECTTYPE,$userobjs);
}

?>

</table>
</form>

<?php
include_once(NGT_LIB."tail.inc");
?>