<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created:	3/26/2018	ELL
// Revised: 4/16/2018	ELL
// Added importing of font sources to display these types of fonts correctly.
// Modified: 5/29/2021	ELL
// Added ability to activate or de-activate fonts.
// 
	include ("check_session.php");
		
	$style_sheet = $_REQUEST['style_sheet'];
		
	if (BWB_BASE_DIR != "")	{
		$fonts_dir = "/" . BWB_BASE_DIR . "/" . BWB_FONTS_DIR . "/";
		$rel_fonts_dir = "../" . BWB_BASE_DIR . "/" . BWB_FONTS_DIR . "/";
		$css_path = BWB_BASE_DIR . "/" . BWB_CSS_DIR;
	}
	else	{
		$fonts_dir = "/" . BWB_FONTS_DIR . "/";
		$rel_fonts_dir = "../" . BWB_FONTS_DIR . "/";
		$css_path = BWB_CSS_DIR;
	}		
	
	$manage_image_dir = "/manage/theme/" . $theme . "/images/";
	$rel_manage_image_dir = "../theme/" . $theme . "/images/";
	
	 $host = $_SERVER['HTTP_HOST'];
	 
	 $doc_root = $_SERVER['DOCUMENT_ROOT'];
	 if (!file_exists($doc_root . $fonts_dir))
	 	mkdir($doc_root . $fonts_dir);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Manage Fonts | Breeze Website Builder</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/<?php echo $css_path; ?>/fonts.css" type="text/css">
<link rel="stylesheet" href="theme/<?php echo $theme; ?>/manager.css" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">

<style type="text/css">
#help_button	{	
	position:relative;
	display:block;
	top:-15px;
	left:215px;
	height:31px;
	width:31px;
	z-index:100;
}

.header_row	{
	padding-left:5px;
	padding-right:5px;
}

#btn_add_font	{
	width:130px;
}

.extra_long_txt_field	{	width:25vw;	}
.long_txt_field	{	width:17vw;	}
.med_txt_field	{	width:16vw;	}
.file_browse	{	width:180px;	}

.instructions	{
	text-align:left;
	width:41%;
	margin-right:2%;
	margin-left:auto;
	margin-top:-2%;
}
@media only screen and (max-width: 1120px) {
.instructions	{
	width:30%;
}
}

#progressNumber	{	display: none;	}
</style>

<script src="js/jquery.min.js"></script>
<script src="js/json2.js"></script>
<script src="js/trim.js"></script>
<script src="js/escape_url.js"></script>
<script src="js/browser_detect.js"></script>
<script src="js/mouse_position.js"></script>
<script src="js/popup_msg.js"></script>
<script src="js/manage_fonts.js"></script>

<script>
	var unsaved_new_item = false;
	var bgclr = "#eeeeee";
	var nCount = 0;

<?php
	echo "	var theme = '$theme';\n\n";
/////////////////////////////////////////	
	echo "	var FONT_WORD = \"" . FONT_WORD . "\";\n";
	echo "	var SOURCE_WORD = \"" . SOURCE_WORD . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_GET_FONTS_MSG = \"" . MANAGE_CUSTOM_FONTS_GET_FONTS_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_GET_FONTS_COMPLETE_MSG = \"" . MANAGE_CUSTOM_FONTS_GET_FONTS_COMPLETE_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_ADDING_FONT_MSG = \"" . MANAGE_CUSTOM_FONTS_ADDING_FONT_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_ADDING_FONT_COMPLETE_MSG = \"" . MANAGE_CUSTOM_FONTS_ADDING_FONT_COMPLETE_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_1_MSG = \"" . MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_1_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_2_MSG = \"" . MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_2_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_3_MSG = \"" . MANAGE_CUSTOM_FONTS_DELETE_FONT_CONFIRM_3_MSG . "\";\n";
	echo "	var YES_WORD = \"" . YES_WORD . "\";\n";
	echo "	var NO_WORD = \"" . NO_WORD . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_DELETE_FONT_COMPLETE_MSG = \"" . MANAGE_CUSTOM_FONTS_DELETE_FONT_COMPLETE_MSG . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_NO_FONTS = \"" . MANAGE_CUSTOM_FONTS_NO_FONTS . "\";\n";
	echo "	var _NOT_SELECTED_ = \"" . _NOT_SELECTED_ . "\";\n";
	echo "	var COPY_STYLE_TO_MOBILE_SOURCE_TYPE = \"" . COPY_STYLE_TO_MOBILE_SOURCE_TYPE . "\";\n";
	echo "	var EDIT_FAVICON_UPLOAD_BTN = \"" . EDIT_FAVICON_UPLOAD_BTN . "\";\n";
	echo "	var EDIT_MENU_ITEMS_URL = \"" . EDIT_MENU_ITEMS_URL . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_STRETCH = \"" . MANAGE_CUSTOM_FONTS_STRETCH . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_STYLE = \"" . MANAGE_CUSTOM_FONTS_STYLE . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_WEIGHT = \"" . MANAGE_CUSTOM_FONTS_WEIGHT . "\";\n";
	echo "	var NORMAL_WORD = \"" . NORMAL_WORD . "\";\n";
	echo "	var CONDENSED_WORD = \"" . CONDENSED_WORD . "\";\n";
	echo "	var ULTRA_CONDENSED_WORD = \"" . ULTRA_CONDENSED_WORD . "\";\n";
	echo "	var EXTRA_CONDENSED_WORD = \"" . EXTRA_CONDENSED_WORD . "\";\n";
	echo "	var SEMI_WORD = \"" . SEMI_WORD . "\";\n";
	echo "	var EXPANDED_WORD = \"" . EXPANDED_WORD . "\";\n";
	echo "	var SEMI_EXPANDED_WORD = \"" . SEMI_EXPANDED_WORD . "\";\n";
	echo "	var EXTRA_EXPANDED_WORD = \"" . EXTRA_EXPANDED_WORD . "\";\n";
	echo "	var ULTRA_EXPANDED_WORD = \"" . ULTRA_EXPANDED_WORD . "\";\n";
	echo "	var ITALIC_WORD = \"" . ITALIC_WORD . "\";\n";
	echo "	var OBLIQUE_WORD = \"" . OBLIQUE_WORD . "\";\n";
	echo "	var BOLD_WORD = \"" . BOLD_WORD . "\";\n";
	echo "	var MANAGE_CUSTOM_FONTS_ADDING_FONT_FILE_TYPE_ERR = \"" . MANAGE_CUSTOM_FONTS_ADDING_FONT_FILE_TYPE_ERR . "\";\n";
	echo "	var MANAGE_FONTS_FONT_SAVED_MSG = \"" . MANAGE_FONTS_FONT_SAVED_MSG . "\";\n";
	echo "	var MANAGE_FONTS_ERROR_SAVING_FONT_ERR = \"" . MANAGE_FONTS_ERROR_SAVING_FONT_ERR . "\";\n";
	echo "	var MANAGE_FONTS_ADD_BEFORE_SAVE_NEW_MSG = \"" . MANAGE_FONTS_ADD_BEFORE_SAVE_NEW_MSG . "\";\n";
	echo "	var MANAGE_FONTS_FONT_UPLOADED_MSG = \"" . MANAGE_FONTS_FONT_UPLOADED_MSG . "\";\n";
	echo "	var MANAGE_FONTS_FONT_UPLOAD_ERR = \"" . MANAGE_FONTS_FONT_UPLOAD_ERR . "\";\n";
	echo "	var MANAGE_FONTS_FONT_UPLOAD_CANCEL_MSG = \"" . MANAGE_FONTS_FONT_UPLOAD_CANCEL_MSG . "\";\n";
	echo "	var MANAGE_FONTS_NO_FONT_ERR = \"" . MANAGE_FONTS_NO_FONT_ERR . "\";\n";
	echo "	var MANAGE_FONTS_NO_UPLOAD_ERR = \"" . MANAGE_FONTS_NO_UPLOAD_ERR . "\";\n";
	echo "	var MANAGE_FONTS_NO_URL_ERR = \"" . MANAGE_FONTS_NO_URL_ERR . "\";\n";
	echo "	var ACTIVE_WORD = \"" . ACTIVE_WORD . "\";\n";	
/////////////////////////////////////////
	echo "\n	var fonts_dir = '" . $fonts_dir . "';\n";
	echo "	var rel_fonts_dir = '" . $rel_fonts_dir . "';\n";
	echo "	var manage_image_dir = '" . $manage_image_dir . "';\n";
	echo "	var rel_manage_image_dir = '" . $rel_manage_image_dir . "';\n";
	echo "	var host = '" . $host . "';\n";
	echo "	var http = '" . $http . "';\n\n";
	echo "	var upload_index;\n\n";
?>
</script>

<?php
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "fonts` WHERE `src` LIKE 'http%'";
	if ($result = $bwb_dbh->query($query))
	{
		while ($row = $result->fetch(PDO::FETCH_ASSOC))
		{
			echo "<link href=\"" . $row['src'] . "\" rel=\"stylesheet\">\n";
		}
	}
?>

</head>

<body onLoad="RetrieveFonts();" id="workspace_body">
<div align="center">

<table width="90%" align="center"><tr>
<td>
	<div class="button_heading_sub_level_1" id="edit_menus_heading"><div class="button_heading_text_sub_level_1"><?php echo MANAGE_CUSTOM_FONTS_HEADING; ?></div><div class="help_button" id="help_button" onClick="OpenHelpWindow();">&nbsp;</div></div>
</td>
<td align="right">
<div class='button_console_go_back' style="width:210px;" onClick="window.location.href='edit_css.php?style_sheet=<?php echo $style_sheet; ?>'"><span class='button_console_text_w_icon'><?php echo CLASSES_BACK_TO_EDIT_CSS; ?></span></div>
</td>
</tr></table>
   
	<div id="FontsTable" style="width:100%;">&nbsp;</div>
    
</div>

<div style="text-align:center; margin-left:auto; margin-right:auto; padding-left:45%; margin-top:10px;">
     <div id="btn_add_font" class='button_console_add' onClick="AddFont();"><span class='button_console_text_w_icon'><?php echo MANAGE_CUSTOM_FONTS_ADD_FONT; ?></span></div>
</div>
<div class="instructions medium_message">
    <?php echo MANAGE_FONTS_INSTRUCTIONS_1; ?> <img src="theme/<?php echo $theme; ?>/images/save.png" width="16" height="16" alt="Save" />.
    <?php echo MANAGE_FONTS_INSTRUCTIONS_2; ?> <img src="theme/<?php echo $theme; ?>/images/save.png" width="16" height="16" alt="Save" />
    <?php echo MANAGE_FONTS_INSTRUCTIONS_3; ?> <img src="theme/<?php echo $theme; ?>/images/delete.png" width="16" height="16" alt="Delete" />
    <?php echo MANAGE_FONTS_INSTRUCTIONS_4; ?>
</div>

<div id="progressNumber"></div>

<?php include("lib/popup_msg.html"); ?>

<script language='javascript' type='text/javascript'>
	popup_msg.HidePopupMsg();
</script>
</body>
</html>