<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 8/5/2019	ELL

	include ("check_session.php");
		
	$style_sheet = $_REQUEST['style_sheet'];
	$class_sort_method = $_SESSION['class_sort_method'];
	
	$classes = array();
	$search = array(".", "#", " ", ",", ">", "&gt;", "+", "~");
	$replace = array("PERIOD", "POUND", "SPACE", "COMMA", "GREATERTHAN", "GREATERTHAN", "PLUS", "TILDA");

	if ($class_sort_method == 1)
		$query = "SELECT `class`, `description` FROM `" . BWB_TABLE_PREFIX . "site_classes` WHERE `style_sheet` = '$style_sheet' ORDER BY `class`";
	else
		$query = "SELECT `class`, `description` FROM `" . BWB_TABLE_PREFIX . "site_classes` WHERE `style_sheet` = '$style_sheet' ORDER BY `sort_order`";
	$result = $bwb_dbh->query($query);

	if ($result->rowCount() > 0)
	{
		while ($row = $result->fetch(PDO::FETCH_ASSOC))
		{
			$class = $row["class"];
			$description = $row["description"];
			$query = "SELECT `use_table_data` FROM `" . BWB_TABLE_PREFIX . "site_css` WHERE `style_sheet` = '$style_sheet' AND `class` = '$class'";
			$result2 = $bwb_dbh->query($query);
			if ($result2->rowCount() > 0)	{
				$row2 = $result2->fetch(PDO::FETCH_ASSOC);
				$classes[] = array('class' => str_replace($search, $replace, $class), 'description' => $description, 'use_table_data' => $row2['use_table_data']);
			}
			else
				$classes[] = array('class' => str_replace($search, $replace, $class), 'description' => $description, 'use_table_data' => 0);
		}
	}
	else
	{
		echo "-no data-";
		exit;
	}
	
	if (count($classes) > 0)
		echo json_encode($classes);
	else
		echo "-no data-";
?>