<?php if (!isset($_SESSION['FirstName'])) {
	session_start();
}
    include ('includes/db1config.php');
    include ('../includes/mysql_connect.php');
	include ('includes/admin-config.php');	//get site options
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php 
include('title.php'); 
echo'<link href="css/'.$stylesheet.'" rel="stylesheet" type="text/css" media="screen" />';	
echo'<link href="css/print_style.css" rel="stylesheet" type="text/css" media="print" />';
?>

<link rel="stylesheet" type="text/css" href="css/cssverticalmenu.css" />
<link rel="stylesheet" href="includes/tinyaccordion/style.css" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>


<script type="text/javascript" src="../js/ddaccordion.js"></script>

<!-- for popup windows -->
<link href="css/popup-style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/script.js"></script>
 <!-- end popup script-->

<style type="text/css">

.mainForm{
width: 700px;
margin: auto;
}
.leftForm {
float: left;
width: 300px;
}
.rightForm{
float: left;
width: 300px;
}
.saveButton{
margin: auto;
}
#save-button{
margin-right: 115px;
width: 150px;
}

.arrowlistmenu{
	width: 100%; /*width of accordion menu*/
	}

	.arrowlistmenu .menuheader{ /*CSS class for menu headers in general (expanding or not!)*/
	font:12px Verdana,Arial;width:95%; border:1px solid #467182; padding:7px; 
		font-weight:bold; margin-top:5px; cursor:pointer; 
	    -webkit-border-radius: 7px;
	    -moz-border-radius: 7px;
	    border-radius: 7px;
	    border: solid 1px #e8e8e8;
	    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
	    -webkit-transition-duration: 0.2s;
	    -moz-transition-duration: 0.2s;
	    transition-duration: 0.2s;
	    -webkit-user-select:none;
	    -moz-user-select:none;
	    -ms-user-select:none;
	    user-select:none;
		color:#fff;
		background-color:#2077a1;
		padding-left:.5em;padding-right:.5em;
	}

	.arrowlistmenu .openheader{ /*CSS class to apply to expandable header when it's expanded*/
	background-image: url(titlebar-active.png);
	}

	.arrowlistmenu ul{ /*CSS for UL of each sub menu*/
	list-style-type: none;
	margin: 0;
	padding: 0;
	margin-bottom: 0px; /*bottom spacing between each UL and rest of content*/
	background: none;
	}

	.arrowlistmenu ul li{
	padding-bottom: 0px; /*bottom spacing between menu items*/
	}

	.arrowlistmenu ul li .opensubheader{ /*Open state CSS for sub menu header*/
	background: lightblue !important;
	}

	.arrowlistmenu ul li .closedsubheader{ /*Closed state CSS for sub menu header*/
	background: lightgreen !important;
	}

	.arrowlistmenu ul li a{
	color: #81BEF7;
	background: url(arrowbullet.png) no-repeat center left; /*custom bullet list image*/
	display: block;
	padding: 0px 0;
	padding-left: 19px; /*link text is indented 19px*/
	text-decoration: none;
	font-weight: bold;
	border-bottom: 1px solid #dadada;
	font-size: 90%;
	}

	.arrowlistmenu ul li a:visited{
	color: #81BEF7;
	}

	.arrowlistmenu ul li a:hover{ /*hover state CSS*/
	color: #FA5858;
	background-color: #FA5858;
	}

	.arrowlistmenu ul li a.subexpandable:hover{ /*hover state CSS for sub menu header*/
	background: lightblue;
	}
	html {
	    overflow-y: scroll;
	}
	

</style>

<script type="text/javascript">
ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

ddaccordion.init({ //2nd level headers initialization
	headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
	contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<style type="text/css">
	body#pop-up-window {
		background:none;
		margin-top:5px;
	}
	
body#pop-up-window #content,
body#pop-up-window #main-content {
margin:0px;
padding:0px;
width:100%;
background:none;
	}
	
body#pop-up-window #content {
	}
	
	#wrapper.custom {
		-webkit-border-radius: none;
		-moz-border-radius: none;
	    border-radius: 0;
		border: none;
		background: none;
		width: 750px;
		padding:0px;
		margin:0px;
		margin:16px;
	}
#add_new_btn{
	color: white;
	text-align: center;
	background-color: #2077A1;
	float: right;
	padding-left: 5px;
	padding-right: 5px;
	font-family: Arial,Times,serif;
	cursor: pointer;
	margin-bottom: 10px;
    margin-right: 10px;
}

#location_list th {
    padding: 8px;
    text-align: center;
}	
#location_list td {
    padding: 6px;
    text-align: center;

}
#edit_btn{
	color:white;
	background-color: #2077A1;
    cursor: pointer;
    text-align: center;
}
#remove_btn{
	color:white;
	background-color: #2077A1;
    cursor: pointer;
    text-align: center;
}	
#remove_btn > a {
    color: white;
}
#edit_btn > a {
    color: white;
}
#primary_btn > a {
    color: white;
}
#primary_btn{
	color:white;
	background-color: #2077A1;
    cursor: pointer;
    text-align: center;
}	
.entry a {
    color: #000;
    text-decoration: none;
}
.add_new_submit{
	color:white;
	background-color: #2077A1;
	cursor: pointer;
}
.disableClick{
    pointer-events: none;
    opacity: 0.6;
}
.cancel_btn{
	width: 60px;
}
.btnClass{
    
    background: #2077a1;
    color: white;
    cursor: pointer;
    border: 1px solid #cccfd2;
    border-radius: 4px;
    padding: 4px 5px;
}
</style>

</head>
<body id="pop-up-window">

<div id="wrapper" class="custom">



<!-- start page -->



<!-- start content -->
<div id="content">
<div id="main-content">
   
		<div class="post">
		  <div class="entry">



<?php

//Code to save data into database
if(isset($_POST['text_submit'])){

	if ($_POST['text_key'] !='undefined' ){
		$update_query = 'UPDATE `widget_fields` set content = "'.$_POST['text_input'].'" where recordkey= "'.$_POST['text_key'].'" ';
		mysql_query($update_query);
		echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editwidgets.php";</script>';
		die;
	}


}elseif (isset($_POST['title_submit'])) {

	if ($_POST['title_key'] !='undefined' ){
		$update_query = 'UPDATE `widget_fields` set content = "'.$_POST['title_input'].'" where recordkey= "'.$_POST['title_key'].'" ';
		mysql_query($update_query);
		echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editwidgets.php";</script>';
		die;
	}
	
}elseif (isset($_POST['subtitle_submit'])) {

	if ($_POST['subtitle_key'] !='undefined' ){
		$update_query = 'UPDATE `widget_fields` set content = "'.$_POST['subtitle_input'].'" where recordkey= "'.$_POST['subtitle_key'].'" ';
		mysql_query($update_query);
		echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editwidgets.php";</script>';
		die;
	}
}elseif (isset($_POST['textarea_submit'])) {

	if ( $_POST['textarea_key'] !='undefined' ) {
		$update_query = 'UPDATE `widget_fields` set content = "'.$_POST['textarea_input'].'" where recordkey= "'.$_POST['textarea_key'].'" ';
		mysql_query($update_query);
		echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editwidgets.php";</script>';
		die;
	}

}elseif (isset($_POST['image_submit'])) {

    if(isset($_FILES['image_name']) && !empty($_FILES['image_name']["name"])){
	    //Upload File
	    
	    $uploadok=0;
	    $check = getimagesize($_FILES["image_name"]["tmp_name"]);
    	if($check !== false) {
    		$target_dir = $_SERVER['DOCUMENT_ROOT']."/custom/images/";
    		$filename = strtotime("now").'_'.basename($_FILES["image_name"]["name"]);
			$target_file = $target_dir.$filename;
			$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
			if($imageFileType == "jpg" || $imageFileType ==  "png" || $imageFileType == "jpeg" || $imageFileType == "gif" ){
				$uploadedfile = $_FILES['image_name']['tmp_name'];
				if($imageFileType=="jpg" || $imageFileType=="jpeg" )
				{
					$src = imagecreatefromjpeg($uploadedfile);
				}else if($imageFileType=="png"){
					$src = imagecreatefrompng($uploadedfile);
				}else{
					$src = imagecreatefromgif($uploadedfile);
				}
 
				list($width,$height)=getimagesize($uploadedfile);

				$newwidth=400;
				$newheight=($height/$width)*$newwidth;
				$tmp=imagecreatetruecolor($newwidth,$newheight);

				imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

				imagejpeg($tmp,$target_file,100);

				imagedestroy($tmp);
			// if (move_uploaded_file($_FILES["image_name"]["tmp_name"], $target_file)) {
			//    } else {
			//        $uploadok=1;
			//        echo "<font color=red>Image not moved to server!!.</font><br/>";
			//    }
			}else{
				$uploadok=1;
				echo "<font color=red>uploaded file is not an image.</font><br/>";
			}		
    	}else{
				$uploadok=1;
				echo "<font color=red>Image size is zero.</font><br/>";
		}
		$uploadok; 
    	if($uploadok==0){				
	    	$query = 'UPDATE `widget_fields` set content = "'.$filename.'" where recordkey= "'.$_POST['image_key'].'" ';
	    	mysql_query($query);
	    	echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editwidgets.php";</script>';
		die;
	    }else{
	    	echo "<font color=red>Image is not Uploaded.</font><br/>";
	    }
	}
}

//Code to show form on the basisi of field-type

if(isset($_GET['action'])){

	
echo '<h1>Add/Edit/Upload Content here </h1>';
	$action = $_GET['action'];
	$type = $_GET['type'];

	if($type == 'text' || $type == 'Text'){
		$content = '';
		$key = '';
		$widgetId = '';
		if($_GET['content'] != 'undefined'){
		$content = $_GET['content'];
		}
		if(isset($_GET['key'])){
			$key = $_GET['key'];
		}
		if($_GET['widgetId'] != 'undefined'){
			$widgetId = $_GET['widgetId'];
		}
		echo '<form method="post" action="editwidgetsiframe.php">
				<table>
				<tr>
					<td>Enter Text here:</td>
					<td><input type="text" name="text_input" value="'.$content.'" required="required"></td>
					<td><input type="hidden" name="text_key" value="'.$key.'"></td>
				</tr>
				<tr>
					<td><input type="submit" name="text_submit" value="SAVE" class="btnClass"></td>
				</tr>
				</table>
				
			 </form>
			';
	}elseif($type == 'title' || $type == 'Title'){

		$content = '';
		$key = '';
		$widgetId = '';
		if($_GET['content'] != 'undefined'){
		   $content = $_GET['content'];
		}
		if(isset($_GET['key'])){
			$key = $_GET['key'];
		}
		if($_GET['widgetId'] != 'undefined'){
			$widgetId = $_GET['widgetId'];
		}
		echo '<form method="post" action="editwidgetsiframe.php">
				<table>
				<tr>
					<td>Enter Title here:</td>
					<td><input type="text" name="title_input" value="'.$content.'" required="required"></td>
					<td><input type="hidden" name="title_key" value="'.$key.'"></td>
				</tr>
				<tr>
					<td><input type="submit" name="title_submit" value="SAVE" class="btnClass"></td>
				</tr>
				</table>
				
			 </form>
			';
	}elseif($type == 'subtitle' || $type == 'Subtitle') {
			$content = '';
			$key = '';
			$widgetId = '';
			if($_GET['content'] != 'undefined'){
			$content = $_GET['content'];
			}
			if(isset($_GET['key'])){
				$key = $_GET['key'];
			}
			if($_GET['widgetId'] != 'undefined'){
				$widgetId = $_GET['widgetId'];
			}
			echo '<form method="post" action="editwidgetsiframe.php">
				<table>
				<tr>
					<td>Enter Sub-Title here:</td>
					<td><input type="text" name="subtitle_input" value="'.$content.'" required="required"></td>
					<td><input type="hidden" name="subtitle_key" value="'.$key.'"></td>
				</tr>
				<tr>
					<td><input type="submit" name="subtitle_submit" value="SAVE" class="btnClass"></td>
				</tr>
				</table>
				
			 </form>
			';
	}elseif ($type == 'textblock' || $type == 'Text block') {
		$content = '';
		$key = '';
		$widgetId = '';
		if($_GET['content'] != 'undefined'){
		$content = $_GET['content'];
		}
		if(isset($_GET['key'])){
			$key = $_GET['key'];
		}
		if($_GET['widgetId'] != 'undefined'){
			$widgetId = $_GET['widgetId'];
		}
		echo '<form method="post" action="editwidgetsiframe.php">
					<table>
					<tr>
						<td><textarea rows="4" cols="50" name="textarea_input" required="required">'.$content.'</textarea></td>
						<td><input type="hidden" name="textarea_key" value="'.$key.'"></td>
					</tr>
					<tr>
						<td><input type="submit" name="textarea_submit" value="SAVE" class="btnClass"></td>
					</tr>
					</table>
					
				 </form>
				';
	}elseif ($type == 'image' || $type == 'Image') {
		$content = '';
		$key = '';
		$widgetId = '';
		if($_GET['content'] != 'undefined'){
		$content = $_GET['content'];
		}
		if(isset($_GET['key'])){
			$key = $_GET['key'];
		}
		if($_GET['widgetId'] != 'undefined'){
			$widgetId = $_GET['widgetId'];
		}
			echo '<img src="/custom/images/'.$content.'" alt="No image available"></img>';
			echo '<form method="post" enctype="multipart/form-data" action="editwidgetsiframe.php">
				<table>
				<tr>
					<td><input type="file" name="image_name" required="required"></td>
					<td><input type="hidden" name="image_key" value="'.$key.'"></td>
				</tr>
				<tr>
					<td><input type="submit" name="image_submit" value="UPLOAD" class="btnClass"></td>
				</tr>
				</table>
				
			 </form>
			';
	}
}

?>



</script>

<?php 
// if($_SESSION['adminkey']=="security"){
// include "customersub.php"; 
// } else {
// 	echo '<font color="red"><div align="center">You are not authorized to view this page. <br>Please <a href="index.php"><font color="blue">login here</font></a>.</div></font>';
// }
?>
            
 <br />

</div><!-- end entry-->

<br />

</div><!-- end post-->

</div><!-- end main-content-->

</div><!-- end content -->


<div style="clear: both;">&nbsp;</div>
<div id="page-bg-btm">
</div><!-- end page-bg-btm div -->





</div><!-- end wrapper div-->

<!-- end page -->


<!--footer-->



</body>
</html>
