<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 11/12/2008	ELL
// Fixed bug with custom tags using "#" instead of ".".
// Revised: 7/30/2009	ELL
// Added field `subclass_sort_order` with a default of 500.  This will be used to arrange the classes when defining class/subclass relationships.
// Revised: 8/1/2009	ELL
// Added ability to operate using different class tables.  This was done to give the ability
// to style calendar grids and event grids without adding 14 more classes to the site style list.
// Renamed from add_tag.php to add_class.php.
// Added feed thru to show/hide custom styles.
// Revised: 1/27/2010	ELL
// Removed line that replaces spaces with underscores.  This had some purpose once upon a time, but no longer has a reason.
// Add trimming of white space on outside of class.
// Revised: 2/7/2012	ELL
// Added table prefix handling.
// 
// 
	include ("check_session.php");

	$style_sheet = $_REQUEST['style_sheet'];
	$class_table = $style_sheet . "_classes";

	$class = trim($_POST['class']);
	$search = array(".", "#", " ", ",");
	$replace = array("PERIOD", "POUND", "SPACE", "COMMA");
	$class_str = str_replace($search, $replace, $class);
	$_SESSION['last_class_edited'] = $class_str;
	$description = $_POST['description'];
	$sort_order = $_POST['sort_order'];
	
	//First check to see if user exists.
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . $class_table . "` WHERE `class` = '$class'";
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$tmp_class = $row["class"];
	if ($tmp_class)
	{
		echo "'$class' already exists in database.  Click <a href=\"classes.php?style_sheet=$style_sheet&show_class_editor=1\" title=\"here\">here</a> to add a different class.";
		exit;
	}
	
	
	// Add class to database.
	$query = "INSERT INTO `" . BWB_TABLE_PREFIX . $class_table . "` SET `class` = '$class', `description` = '$description', `sort_order` = $sort_order, `subclass_sort_order` = 500, `custom` = 1";
	$result = mysql_query($query, $bwb_link);
	
	header("Location: classes.php?style_sheet=$style_sheet&show_class_editor=1");
	
?>
