<?php
/////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Build string for site.css file /////
// Created: 3/31/2010	ELL
// 
// Revised: 9/30/2011	ELL
// Added building of download files for open-source customers who purchase templates.
// Mode will switch based on whether or not wizard is enabled in options_selected table.
// If wizard is enabled, setup_site.php copies files to perspective folders and runs
// SQL directly on tables just as originally designed.  If wizard is not enabled,
// setup_site.php creates SQL file from all of the SQL commands, copies all of the
// other necessary files to a temp location, zips these files into a single file, and
// initiates download of zip file to customer.  Open-source customers will then upload
// this zip file into their Breeze Website Builder which will then unpack the files and
// apply template to their site automatically by running the SQL commands in the SQL file
// and copying the perspective files to the correct locations.
// Revised: 12/27/2011	ELL
// Changed CKEDITOR.addStylesSet to CKEDITOR.stylesSet.add as former is depricated in CKEditor 3.6.
// Revised: 2/10/2012	ELL
// Added table prefix handling. (Local mode only)
// Revised: 3/4/2012	ELL
// Revised from using currently saved style sheet to using site styles and mail forms styles.  These styles MUST be used to create
// the styles.js file for the CKEditor, AND the other styles sheets SHOULD be left out of that file.  Note: The CKEditor uses
// the styles.js file to generate the styles dropdown list the users use to style their page.
// Revised: 8/10/2015	ELL
// Added checking for existence if mail_form_classes table before trying to add these classes.
//
//
	
	include ("../connect/db_connect.php");
	include ("db_connection.php");
	include_once ("../connect/config.php");
	
	$jason_string = "CKEDITOR.stylesSet.add( 'eb_styles',\n";
	$jason_string .= "[\n";
					   
	if ($wiz_mode == 1)
	{
		$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "site_classes INNER JOIN " . BWB_TABLE_PREFIX . "site_css ON " . BWB_TABLE_PREFIX . "site_classes.class = " . BWB_TABLE_PREFIX . "site_css.class WHERE (" . BWB_TABLE_PREFIX . "site_classes.custom = 1) AND (" . BWB_TABLE_PREFIX . "site_css.use_table_data = 1) AND ((" . BWB_TABLE_PREFIX . "site_css.style_sheet = 'site') OR (" . BWB_TABLE_PREFIX . "site_css.style_sheet = 'mail_form')) ORDER BY sort_order";
		$result = $bwb_dbh->query($query);
	}
	else
	{
		$query = "SELECT * FROM site_classes INNER JOIN site_css ON site_classes.class = site_css.class WHERE (site_classes.custom = 1) AND (site_css.use_table_data = 1) AND ((site_css.style_sheet = 'site') OR (site_css.style_sheet = 'mail_form') AND (site_classes.template_id=" . $template_id . ")) ORDER BY sort_order";
		$result = $bwb_wiz_dbh->query($query);
	}

	while ($row = $result->fetch(PDO::FETCH_ASSOC))
	{		
		$class = $row["class"];
		$description = addslashes($row["description"]);
		$class = str_replace(".", "", $class);
		$class = str_replace("#", "", $class);
		$class_type = substr($class, 0, 1);
		if ($class_type == "#")
			$jason_string .= "   { name : '" . $description . "', element : 'div', attributes : { 'class' : '" . $class . "' } },\n";
		else
			$jason_string .= "   { name : '" . $description . "', element : 'span', attributes : { 'class' : '" . $class . "' } },\n";
	}	// end while
	
	// Add in default styles
	$jason_string .=  "{name:'Blue Title',element:'h3',styles:{color:'Blue'}},{name:'Red Title',element:'h3',styles:{color:'Red'}},{name:'Marker: Yellow',element:'span',styles:{'background-color':'Yellow'}},{name:'Marker: Green',element:'span',styles:{'background-color':'Lime'}},{name:'Big',element:'big'},{name:'Small',element:'small'},{name:'Typewriter',element:'tt'},{name:'Computer Code',element:'code'},{name:'Keyboard Phrase',element:'kbd'},{name:'Sample Text',element:'samp'},{name:'Variable',element:'var'},{name:'Deleted Text',element:'del'},{name:'Inserted Text',element:'ins'},{name:'Cited Work',element:'cite'},{name:'Inline Quotation',element:'q'},{name:'Language: RTL',element:'span',attributes:{dir:'rtl'}},{name:'Language: LTR',element:'span',attributes:{dir:'ltr'}},{name:'Image on Left',element:'img',attributes:{style:'padding: 5px; margin-right: 5px',border:'2',align:'left'}},{name:'Image on Right',element:'img',attributes:{style:'padding: 5px; margin-left: 5px',border:'2',align:'right'}}";
	
	// Fininh JASON definition.
	$jason_string .= "\n]);";
?>