<?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;

}
</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">

<h1>Additional Locations</h1>

 <?php
//Code to add additional location 
if(isset($_POST['add_new_submit'])){

	$query = 'INSERT INTO `additional_locations` 
			  (address1,address2,city,state,zip,phone,fax,hours1,mapURL)
			  values("'.$_POST[address1].'","'.$_POST[address2].'","'.$_POST[city].'",
				  	 "'.$_POST[state].'","'.$_POST[zip].'","'.$_POST[phone].'",
				  	 "'.$_POST[fax].'","'.$_POST[hours1].'","'.$_POST[mapURL].'")';
	$result = mysql_query($query);
	$_GET["a"] = 'list_location';
}

//Code to update additional location 
if(isset($_POST['update_submit'])){

			 $query = 'UPDATE `additional_locations` 
						set address1="'.$_POST[address1].'",
						address2="'.$_POST[address2].'",
						city="'.$_POST[city].'",
						state="'.$_POST[state].'",
						zip="'.$_POST[zip].'",
						phone="'.$_POST[phone].'",
						fax="'.$_POST[fax].'",
						hours1="'.$_POST[hours1].'",
						mapURL="'.$_POST[mapURL].'"
						where recordkey="'.$_POST[recordkey].'"
		  		';
	$result = mysql_query($query);
	$_GET["a"] = 'list_location';
}

//Code for Edit, Remove and set as primary functionality
if(isset($_GET['action'])){

	if($_GET['action']=='edit_loc'){

		$query ='SELECT * from `additional_locations` where recordkey = '.$_GET['recordKey'].' ';
		$result = mysql_query($query);
		$row = mysql_fetch_array($result);
		echo '<form action="editprefsiframe.php" method="POST">
					<table>
						<tr>
						   <td>Enter Address1</td>
						   <td><input type="text" name="address1" value="'.$row[address1].'"></td>
						</tr>
						<tr>
						   <td>Enter Address2</td>
						   <td><input type="text" name="address2" value="'.$row[address2].'"></td>
						</tr>
						<tr>
						   <td>Enter city</td>
						   <td><input type="text" name="city" value="'.$row[city].'"></td>
						</tr>
						<tr>
						   <td>Enter state</td>
						   <td><input type="text" name="state" value="'.$row[state].'"></td>
						</tr>
						<tr>
						   <td>Enter zip</td>
						   <td><input type="text" name="zip" value="'.$row[zip].'"></td>
						</tr>
						<tr>
						   <td>Enter phone</td>
						   <td><input type="text" name="phone" value="'.$row[phone].'"></td>
						</tr>
						<tr>
						   <td>Enter fax</td>
						   <td><input type="text" name="fax" value="'.$row[fax].'"></td>
						</tr>
						<tr>
						   <td>Enter hours1</td>
						   <td><input type="text" name="hours1" value="'.$row[hours1].'"></td>
						</tr>
						<tr>
						   <td>Enter mapURL</td>
						   <td><input type="text" name="mapURL" value="'.$row[mapURL].'"></td>
						   <td><input type="hidden" name="recordkey" value="'.$row[recordkey].'"></td>
						</tr>
						<tr>
						   <td><input type="submit" value="UPDATE" name="update_submit" class="add_new_submit"></td>
						</tr>

					</table>	
				</form>';
	
	}elseif ($_GET['action']=='remove_loc') {

		$query = 'DELETE from `additional_locations` where recordkey = '.$_GET['recordKey'].' ';
		$result = mysql_query($query);
		$_GET["a"] = 'list_location';
		
	}elseif ($_GET['action']=='set_as_primary') {

//update set as primary flag
		$query_update_all = 'UPDATE `additional_locations` set set_as_primary = 0 WHERE 1=1';
		mysql_query($query_update_all);	

		$query_update = 'UPDATE `additional_locations` set set_as_primary = 1 
						 WHERE recordkey = '.$_GET['recordKey'].' ';
		mysql_query($query_update);

//fetch data for set as primary		
		$query_1 ='SELECT * from `additional_locations` where recordkey = '.$_GET['recordKey'].' ';
		$result_1 = mysql_query($query_1);
		$row = mysql_fetch_array($result_1);
		$query = 'UPDATE `storePrefs` 
						set address1="'.$row[address1].'",
						address2="'.$row[address2].'",
						city="'.$row[city].'",
						state="'.$row[state].'",
						zip="'.$row[zip].'",
						phone="'.$row[phone].'",
						fax="'.$row[fax].'",
						hours1="'.$row[hours1].'",
						mapURL="'.$row[mapURL].'"
		  		';
		if(mysql_query($query)){

			echo '<script type="text/javascript">window.parent.location.href="http://www.tastedev.com/cmsadmin/editprefs.php";</script>';
			die;
		}
	}
}

 	$action = $_GET["a"];
 	if($action == "list_location"){
 		$query = "SELECT * from `additional_locations` ";
		$result = mysql_query($query);
		echo '<button id="add_new_btn">Add New</button>';
		echo '<div id="location_list">
				<table width="70%" cellspacing="0" cellpadding="5" border=1 id="location_list_table">
					<tr>
						<th>ADDRESS</th>
						<th>STATE</th>
						<th>ZIP</th>
						<th>PHONE</th>
						<th>FAX</th>
						<th>HOURS</th>
						<th>MAP-URL</th>
						<th colspan=3>ACTION</th>
					</tr>';
					while($row = mysql_fetch_array($result)){
						$dclass='';
						if($row[set_as_primary] == 1){
							 $dclass = 'disableClick';
						}
					echo ' 
					<tr>
						<td>'.$row[address1].' '.$row[address2].' '.$row[city].'</td>
						<td>'.$row[state].'</td>
						<td>'.$row[zip].'</td>
						<td>'.$row[phone].'</td>
						<td>'.$row[fax].'</td>
						<td>'.$row[hours1].'</td>
						<td>'.$row[mapURL].'</td>
						<td><a href="editprefsiframe.php?action=edit_loc&recordKey='.$row[recordkey].'"  ><button id="edit_btn" >Edit</button></a></td>
						<td><a href="editprefsiframe.php?action=remove_loc&recordKey='.$row[recordkey].'" class='.$dclass.'><button id="remove_btn">Remove</button></a></td>
						<td><a href="editprefsiframe.php?action=set_as_primary&recordKey='.$row[recordkey].'" class='.$dclass.'><button id="primary_btn">Set as Primary</button></a></td>
					</tr>';
					}
					
			echo '</tr>
				</table>	
			 </div>
		';

		echo '<div id="add_new_form" style="display:none;">
				<form action="editprefsiframe.php" method="POST">
					<table>
						<tr>
						   <td>Enter Address1</td>
						   <td><input type="text" name="address1" ></td>
						</tr>
						<tr>
						   <td>Enter Address2</td>
						   <td><input type="text" name="address2" ></td>
						</tr>
						<tr>
						   <td>Enter city</td>
						   <td><input type="text" name="city" ></td>
						</tr>
						<tr>
						   <td>Enter state</td>
						   <td><input type="text" name="state" ></td>
						</tr>
						<tr>
						   <td>Enter zip</td>
						   <td><input type="text" name="zip" ></td>
						</tr>
						<tr>
						   <td>Enter phone</td>
						   <td><input type="text" name="phone" ></td>
						</tr>
						<tr>
						   <td>Enter fax</td>
						   <td><input type="text" name="fax" ></td>
						</tr>
						<tr>
						   <td>Enter hours1</td>
						   <td><input type="text" name="hours1" ></td>
						</tr>
						<tr>
						   <td>Enter mapURL</td>
						   <td><input type="text" name="mapURL" ></td>
						</tr>
						<tr>
						   <td><input type="submit" value="SAVE" name="add_new_submit" class="add_new_submit"></td>
						   <td><input type="button" value="CANCEL" name="btnCancel" class="add_new_submit cancel_btn"></td>
						</tr>

					</table>	
				</form>
			 </div>';
 	}

 ?>  

<script type="text/javascript">
$('#add_new_btn').click(function() {
	$('#location_list').toggle();
	$('#add_new_form').toggle();
	
});
$('.cancel_btn').click(function() {
	$('#add_new_form').toggle();
	$('#location_list').toggle();
});


</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>
