1<?php
2
3// Pandora FMS - http://pandorafms.com
4// ==================================================
5// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
6// Please see http://pandorafms.org for full contribution list
7
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation for version 2.
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// Load global vars
17global $config;
18
19check_login ();
20
21if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
22	db_pandora_audit("ACL Violation", "Trying to access Setup Management");
23	require ("general/noaccess.php");
24	return;
25}
26
27$action = get_parameter('action', 'new');
28$idOS = get_parameter('id_os', 0);
29$tab = get_parameter('tab', 'list');
30
31if ($idOS) {
32	$os = db_get_row_filter('tconfig_os', array('id_os' => $idOS));
33	$name = $os['name'];
34	$description = $os['description'];
35	$icon = $os['icon_name'];
36}
37else {
38	$name = get_parameter('name', '');
39	$description = get_parameter('description', '');
40	$icon = get_parameter('icon',0);
41}
42
43$message = '';
44
45switch ($action) {
46	default:
47	case 'new':
48		$actionHidden = 'save';
49		$textButton = __('Create');
50		$classButton = 'class="sub next"';
51		break;
52	case 'edit':
53		$actionHidden = 'update';
54		$textButton = __('Update');
55		$classButton = 'class="sub upd"';
56		break;
57	case 'save':
58		$values = array();
59		$values['name'] = $name;
60		$values['description'] = $description;
61
62		if (($icon !== 0) && ($icon != '')) {
63			$values['icon_name'] = $icon;
64		}
65		$resultOrId = false;
66		if ($name != '')
67			$resultOrId = db_process_sql_insert('tconfig_os', $values);
68
69		if ($resultOrId === false) {
70			$message = ui_print_error_message(__('Fail creating OS'), '', true);
71			$tab = 'builder';
72			$actionHidden = 'save';
73			$textButton = __('Create');
74			$classButton = 'class="sub next"';
75		}
76		else {
77			$message = ui_print_success_message(__('Success creating OS'), '', true);
78			$tab = 'list';
79		}
80		break;
81	case 'update':
82		$name = get_parameter('name', '');
83		$description = get_parameter('description', '');
84		$icon = get_parameter('icon',0);
85
86		$values = array();
87		$values['name'] = $name;
88		$values['description'] = $description;
89
90		if (($icon !== 0) && ($icon != '')) {
91			$values['icon_name'] = $icon;
92		}
93		$result = false;
94		if ($name != '')
95			$result = db_process_sql_update('tconfig_os', $values, array('id_os' => $idOS));
96
97		$message = ui_print_result_message($result, __('Success updatng OS'), __('Error updating OS'), '', true);
98		if ($result !== false) {
99			$tab = 'list';
100		}
101		else {
102			$tab = 'builder';
103			$os = db_get_row_filter('tconfig_os', array('id_os' => $idOS));
104			$name = $os['name'];
105		}
106		$actionHidden = 'update';
107		$textButton = __('Update');
108		$classButton = 'class="sub upd"';
109		break;
110	case 'delete':
111		$sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = ' . $idOS;
112		$count = db_get_all_rows_sql($sql);
113		$count = $count[0]['count'];
114
115		if ($count > 0) {
116			$message = ui_print_error_message(__('There are agents with this OS.'), '', true);
117		}
118		else {
119			$result = (bool)db_process_sql_delete('tconfig_os', array('id_os' => $idOS));
120
121			$message = ui_print_result_message($result, __('Success deleting'), __('Error deleting'), '', true);
122		}
123		break;
124}
125
126$buttons = array(
127	'list' => array(
128		'active' => false,
129		'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/os&tab=list">' .
130			html_print_image ("images/list.png", true, array ("title" => __('List OS'))) .'</a>'),
131	'builder' => array(
132		'active' => false,
133		'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/os&tab=builder">' .
134			html_print_image ("images/builder.png", true, array ("title" => __('Builder OS'))) .'</a>'));
135
136$buttons[$tab]['active'] = true;
137
138// Header
139ui_print_page_header(__('Edit OS'), "", false, "", true, $buttons);
140
141echo $message;
142
143switch ($tab) {
144	case 'list':
145		require_once('godmode/setup/os.list.php');
146		return;
147		break;
148	case 'builder':
149		require_once('godmode/setup/os.builder.php');
150		return;
151		break;
152}
153?>
154