<?php
include("../include/config.php");
include("../include/functions.php"); 
include("../include/simpleimage.php");
 validate_admin();
  $attribute_type= mysqli_real_escape_string($GLOBALS['conn'],$_POST['attribute_type']);
  $attribute=ucfirst(mysqli_real_escape_string($GLOBALS['conn'],$_POST['attribute']));
  if(count($_REQUEST['attribute_cat'])>0){
	$attribute_cat=implode(",",$_REQUEST['attribute_cat']);  
  }
  $enable_searching=mysqli_real_escape_string($GLOBALS['conn'],$_POST['enable_searching']);
  if($_REQUEST['submitForm']=='yes'){
	  
  if($_REQUEST['id']==''){
	  $obj->query("insert into $tbl_attribute set attribute='$attribute',attribute_type='$attribute_type',enable_searching='$enable_searching',status=1 ");
	  $_SESSION['sess_msg']='Attribute  added successfully';  
	   }else{ 	  
	  $sql=" update $tbl_attribute set attribute='$attribute',attribute_type='$attribute_type',enable_searching='$enable_searching' ";
	  $sql.=" where id='".$_REQUEST['id']."'";
	  $obj->query($sql);
	  $_SESSION['sess_msg']='Attribute updated successfully';   
        }
   header("location:attribute-list.php");
   exit();
  }      
	   
	   
if($_REQUEST['id']!=''){
$sql=$obj->query("select * from $tbl_attribute where id=".$_REQUEST['id']);
$result=$obj->fetchNextObject($sql);
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SITE_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function validate(obj)
{
	
	if(obj.attribute.value==''){
alert("Please enter attribute");
obj.attribute.focus();
return false;
}
if(obj.attribute_type.value==''){
alert("Please select  attribute type");
obj.attribute_type.focus();
return false;
}
}
</script>

</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<?php include("header.php") ?>

<tr>
	<td align="right" class="paddRtLt70" valign="top">
		<table width="99%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				
				<td align="right" valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td align="left" valign="middle" class="headingbg bodr text14">
					<em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Add  Attribute 
					<span  style="float:right; padding-right:10px;">
					<input type="button" name="add" value="View  Attributes"  class="button" onclick="location.href='attribute-list.php'" /></span></td>
						</tr>
						
						<tr>
							<td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr">
                            <form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)">
						<input type="hidden" name="submitForm" value="yes" />
						<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
							<table width="100%" cellpadding="0" cellspacing="0">
									<tr>
										<td align="center" colspan="2" class="paddRt14 paddBot11">
										<font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td>
									</tr>
                                   
                             
                                    
                                    	<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong> Attribute:</strong></td>
									  <td align="left" class="paddBot11"><input name="attribute" type="text" id="attribute" size="36" value="<?php echo stripslashes($result->attribute);?>" /></td>
							  </tr>
                             
                          <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong> Type:</strong></td>
									  <td align="left" class="paddBot11">
                                      <select name="attribute_type" style="width:240px;" >
                                      <option value="Textbox" <?php if($result->attribute_type=='Textbox'){ ?>selected<?php } ?>>Textbox</option>
                                      <option value="TextArea" <?php if($result->attribute_type=='TextArea'){ ?>selected<?php } ?>>TextArea</option>
                                      <option value="Date" <?php if($result->attribute_type=='Date'){ ?>selected<?php } ?>>Date</option>
                                      <option value="Yes/No" <?php if($result->attribute_type=='Yes/No'){ ?>selected<?php } ?>>Yes/No</option>
                                      <option value="Dropdown" <?php if($result->attribute_type=='Dropdown'){ ?>selected<?php } ?>>Dropdown</option>
                                      <option value="MultipleSelect" <?php if($result->attribute_type=='MultipleSelect'){ ?>selected<?php } ?>>MultipleSelect</option>
                                      
                                      </select></td>
							  </tr>
                             <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong> Enable Searching:</strong></td>
									  <td align="left" class="paddBot11">
                                      <input type="checkbox" name="enable_searching" value="1" <?php if($result->enable_searching==1){?>checked <?php } ?>/>
                                      </td>
							  </tr>
                             
									
                              
									<tr>
									  <td align="right" class="paddRt14 paddBot11">&nbsp;</td>
									  <td align="left" class="paddBot11">&nbsp;</td>
							  </tr>
									<tr>
										<td width="18%" align="right" class="paddRt14 paddBot11">&nbsp;</td>
										<td width="82%" align="left" class="paddBot11">
											<input type="submit" name="submit" value="Submit"  class="submit" border="0"/> 	                  		 &nbsp;&nbsp;
											<input name="Reset" type="reset" id="Reset" value="Reset" class="submit" border="0" />									  </td>
									</tr>
								</table></form>
							</td>
						</tr>
						
					</table>
				</td>
			</tr>
		</table>
	</td>
</tr>
<?php include('footer.php'); ?>
</table>
</body>
</html>


