Location: PHPKode > projects > Zonomania > zonomania202/zones/functions/insert_zone.php
<?php
// Datum: 27.04.10
// Author: Chrigi
// Version: 2.01
// File: insert_zone.php
//
// LICENSE
//    Copyright (C) 2007-2010 Chrigi
//    This file is part of Zonomania.
//
//    Zonomania 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 3 of the License, or
//    (at your option) any later version.
//
//    Foobar 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 Zonomania.  If not, see <http://www.gnu.org/licenses/>.
//
// DESCRIPTION
//    Zonomania is a webbased application to document a SAN (Storage Area Network) environment.
//    It is powerful in the hand of a SAN Administrator to manage, engineer and plan a SAN.
// 
//    What before has been done with table sheets, can now be done with Zonomania.
//    Zonomania easily handles SAN servers, HBAs, zones, aliases, switches and LUNs. 
//    You always have an eye on firmware revisions, available switchports or fill levels of storage arrays.
//    With Zonomania you keep track of your configuration items manually and Zonomania verifies 
//    the documentation online with your SAN devices. It also draws performance graphs from EVAperf csv files. 
//
//    As for now Zonomania is designed for an HP EVA SAN environement.
//    Any enhancements, especially the integration of other storage systems, are welcome.
//
//
///////////////////////////////////////////////////////////////////////////////////////

include("../../var/config.php"); // configuration things
include("../../var/functions.php"); // function things

$zone_id = $_GET['zone_id'];		// zone_id abfangen falls bestehende zone modifiziert wird
if (!$zone_id) $zone_id = 0;		// falls keine bestehende zone modifiziert wird, id = 0 setzen

$name = $_POST["name"];
$description = $_POST["description"];
$zonetype = $_POST["zonetype"];
$fabric = $_POST["fabric"];
$error = 'ok';

// wenn es sich um eine switchmodifikation handelt alle felder löschen, falls ein feld falsch ist 
// (notwenig, da sonst zwei switche mit gleichen parameter eingefügt werden)
if ($zone_id != 0) {
	if (!$name) {
		$error = 'name_mod';
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
	elseif (exist_zone($name, $zone_id, $fabric)) {		// prüfen ob zone bereits existiert
		$error = 'name_exist_mod'; 
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
	elseif (!$zonetype) {
		$error = 'zonetype_mod';
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
	elseif (!$fabric) {
		$error = 'fabric_mod';
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
}
else {
	if (!$name) $error = 'name';
	elseif (exist_zone($name, $zone_id, $fabric)) $error = 'name_exist';		// prüfen ob zone bereits existiert
	elseif (!$fabric) $error = 'fabric';
	elseif (!$zonetype) $error = 'zonetype';
}

// unerlaubte zeichen entfernen
$name = remove_unallowed_chars($name);
$description = remove_unallowed_chars($description);

if ($error == 'ok') {
	if ($zone_id != 0) {		// bestehende zone wird modifiziert
		include("../../var/dbconnect.php"); // zur DB verbinden
		$statement = "UPDATE `zm_zones` SET `fabric` = '$fabric', `name` = '$name', `zonetype` = '$zonetype', `description` = '$description' WHERE `zm_zones`.`zones_id` = $zone_id";
		$doit = mysql_query($statement);
		if (!$doit) {
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL QUERY edit zone: $statement\n", 3, $DEV_LOG_FILE);
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL ERROR: ".mysql_error()."\n", 3, $DEV_LOG_FILE);
		}
		// logging
		if ($LOG_LEVEL > 1) createEvent('info', $name, 'zone edited', '');
		mysql_close($db_connection); // Verbindung zur DB schliessen
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
	else {						// neue zone kommt hinzu
		include("../../var/dbconnect.php"); // zur DB verbinden
		$statement = "INSERT INTO zm_zones (fabric, name, description, zonetype) VALUES ('$fabric', '$name', '$description', '$zonetype')";
		$doit = mysql_query($statement);
		if (!$doit) {
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL QUERY insert new zone: $statement\n", 3, $DEV_LOG_FILE);
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL ERROR: ".mysql_error()."\n", 3, $DEV_LOG_FILE);
		}
		// get zone_id
		$query_id = "SELECT @@IDENTITY";
		$output_id	= mysql_query($query_id);
		if (!$output_id) {
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL QUERY query_id: $query_id\n", 3, $DEV_LOG_FILE);
			error_log(date("M d H:i:s ")."### zones/functions/insert_zone.php FAILED SQL ERROR: ".mysql_error()."\n", 3, $DEV_LOG_FILE);
		}
		$zone_id_arr = mysql_fetch_row($output_id);
		$zone_id = $zone_id_arr[0];
		// logging
		if ($LOG_LEVEL > 0) createEvent('info', $name, 'zone created', 'zone initially created');
		mysql_close($db_connection); // Verbindung zur DB schliessen
		$name = ''; $description = ''; $zonetype = ''; $fabric = '';
	}
	header("Location: ../index.php?error_add=$error&error_del=&name=$name&description=$description&fabric=$fabric&zonetype=$zonetype&add=0&max=$zone_id#$zone_id");
}

else {
	if ($zone_id != 0) header("Location: ../index.php?error_add=$error&error_del=&name=$name&description=$description&fabric=$fabric&zonetype=$zonetype&add=0&max=$zone_id#$zone_id");
	else header("Location: ../index.php?error_add=$error&error_del=&name=$name&description=$description&fabric=$fabric&zonetype=$zonetype&add=1");
}
?>
Return current item: Zonomania