<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 3/29/2017	ELL
// 
	include ("check_session.php");
	
	$file_browse_name = $_POST['file_browse_name'];

	if (!defined("BWB_FONTS_DIR"))
		define('BWB_FONTS_DIR', 'fonts');
	
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	if (BWB_BASE_DIR == "")
		$font_dir = $document_root . "/" . BWB_FONTS_DIR;
	else
		$font_dir = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_FONTS_DIR;
	if (!file_exists($font_dir))
		mkdir($font_dir);
	
	$target_file = $font_dir . "/" . basename($_FILES[$file_browse_name]["name"]);
	$fontFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

	// Check if file already exists
	if (file_exists($target_file)) {
		echo ERROR_CAPS_WORD . ": " . MANAGE_CUSTOM_FONTS_ADDING_FONT_UPLOAD_ERR . " '$target_file' " . MANAGE_CUSTOM_FONTS_ADDING_FONT_2_ERR;
		exit;
	}		
	// Check file types
	if (($fontFileType != "ttf") && ($fontFileType != "otf") && ($fontFileType != "woff") && ($fontFileType != "woff2") && ($fontFileType != "svg")  && ($fontFileType != "eot")) {
		echo MANAGE_CUSTOM_FONTS_ADDING_FONT_FILE_TYPE_ERR;
		exit;
	}
	else {
		if (!move_uploaded_file($_FILES[$file_browse_name]["tmp_name"], $target_file))	{
			echo ERROR_CAPS_WORD . ": " . MANAGE_CUSTOM_FONTS_ADDING_FONT_UPLOAD_ERR;
			exit;
		}
	}
?>
