<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 11/12/2015
// Modified: 11/26/2019	ELL
// Added specification of columns to be returned to reduce query speed and improve reliability by avoiding dealing with page data.
	
	include ("check_session.php");
	
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	
	$query = "SELECT page_name, template, head_name, header_name, top_name, left_name, right_name, bottom_name, footer_name, active FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
	$result = $bwb_dbh->query($query);
	
	if ($result->rowCount() < 1)
	{
		echo "-no data-";
		exit;
	}
	
	$row_delim = "";
	while($row = $result->fetch(PDO::FETCH_ASSOC))
	{
		/////////////////////////////////////////
		//Test to see if file already exists.
		$page_name = $row["page_name"];
		if (BWB_BASE_DIR == '')
			$file_name = $document_root . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
		else
			$file_name = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
		
		if (file_exists($file_name))
			$row['file_exists'] == 1;
		else
			$row['file_exists'] == 0;
			
		$rows .= $row_delim . json_encode($row);
		$row_delim = "@@@@@";
	}
	
	echo $rows;
?>