<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


if(isset($_POST['update']))
{


	/*check whether option with the same name exists in the database*/
		
	$select_options = "SELECT * FROM ".$tableprefix."options 
							 WHERE LOWER(option_name) = ".GetSQLValueString(strtolower($_POST['txtoption_name']),"text").
							 " AND option_id != ".$_GET['edit_id'];
	$result_options = mysql_query($select_options) or die(mysql_error());
	
	if(mysql_num_rows($result_options)>0)
	{
	
		$message = OPTION_EXISTS;
	}
	else
	{	

		$update_options = "UPDATE ".$tableprefix."options
								 SET option_name = ".GetSQLValueString($_POST['txtoption_name'],"text")."WHERE option_id = ".$_GET['edit_id'];	 
							  	
		mysql_query($update_options) or die(mysql_error());
	
	header("Location:options.php?".$_GET['qstring']."&txtSearch=".$_GET['txtSearch']."&msg=S");
	}
	

}

include "../includes/htmltop.php";
?>
<script>
function checkOptions()
{

  var form_name = new Array('txtoption_name');		
  var display_name = new Array('<?php echo OPTION_NAME;?>');
  var count = 1;	

  if(check_fields('frmEditOptions',form_name,display_name,count))	
  {
  
  	
	 
   
  }
  else
  {
  
  		return false;
  
  }
   
}

</script>

		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="right" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="right" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo EDIT_OPTION;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="right">				
																				
					<form name="frmEditOptions" method="post" onSubmit="return checkOptions();">

					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						<tr><td colspan="3">&nbsp;</td></tr>
						<tr><td colspan="3" align="left"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
						<tr class="">
							
							<td width="50%" class="" align="right" valign="top"><?php echo OPTION_NAME;?>&nbsp;<span class="required">*</span></td>
							<td width="50%" valign="top" align="left"><input type="text" class="textarea2" name="txtoption_name" value="<?php echo $option_field_row['option_name']?>"></td>
		
<?php

							$select_options_edit = "SELECT * FROM ".$tableprefix."options WHERE option_id = ".$_GET['edit_id'];
							$result_options_edit = mysql_query($select_options_edit) or die(mysql_error());
							
							$option_field_row = mysql_fetch_assoc($result_options_edit);
																							
?>		
																									
						
					</tr>
					<tr>
						<td align="center" colspan="6">
							<input type="button" name="back" class="button" value="&nbsp;&nbsp;<?php echo BACK;?>&nbsp;&nbsp;" onClick="window.location='options.php'">
							<input type="submit" class="button" name="update" value="<?php echo UPDATE;?>">
						</td> 
					</tr>				
				</table>	
				</form>
			</div>
			</div>
			<div align="right" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--content area end-->
				</div>
					<div align="right" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
<?php
	include "../includes/footer.php";
	
	ob_end_flush();
?>