<?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($_GET['form_id']) !='' )
{

	if(isset($_POST['insert']))
	{
	
	
		/*check whether custom fields with the same name exists in the database*/
			
		$select_custom_fields = "SELECT * FROM ".$tableprefix."custom_fields WHERE LOWER(vcustom_field_name) = ".GetSQLValueString(strtolower($_POST['txtfield_name']),"text");
		$result_custom_fields = mysql_query($select_custom_fields) or die(mysql_error());
		
		if(mysql_num_rows($result_custom_fields)>0)
		{
		
			$message = CUSFIELD_ALREADY_EXIST." !!";
		}
		else
		{	
	
			$insert_custom_fields = "INSERT INTO ".$tableprefix."custom_fields(vcustom_field_form_id,vcustom_field_name,
									  vcustom_field_type,vrequired_custom_field,vcustom_sort_order,vcustom_display_field,vcustom_delete_status)
									  VALUES(".$_GET['form_id'].","
									  .GetSQLValueString($_POST['txtfield_name'],"text").","
									  .GetSQLValueString($_POST['txtfield_type'],"text").","
									  .GetSQLValueString($_POST['txtfield_required'],"text").","
									  .GetSQLValueString($_POST['txtsort_order'],"text").","
									  .GetSQLValueString($_POST['txtfield_displayfield'],"text").
									  ",'N')";
			  
			mysql_query($insert_custom_fields) or die(mysql_error());
		
		header('Location:custom_fields.php?msg1='.CUST_FIELD_SUCCESS);
		
		}
		
	
	}

}
include "../includes/htmltop.php";
?>
<body topmargin="0">
<script>
function checkCustomFields()
{

  var form_name = new Array('txtfield_name','txtsort_order');		
  var display_name = new Array('<?php echo FIELD_NAME;?>','<?php echo SORT_ORDER;?>');
  var count = 2;	

  if(check_fields('frmAddCustomFields',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="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo ADD_USER_REGN;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">										
																							
					<form name="frmAddCustomFields" method="post" onSubmit="return checkCustomFields();">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
					
					
					<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
					<tr>
                                                    <td colspan="2"><?php echo TEXT_ENABLE_REG_FIELDS;?>.</td>
                                                </tr>
                                        <tr class="whitebg">
							<td width="12%" class="" valign="top"><?php echo FIELD_NAME;?>&nbsp;<span class="required">*</span></td>
							<td width="88%" valign="top"><input type="text" name="txtfield_name" class="textarea2"></td>
						</tr>
						<tr class="whitebg">
							<td width="12%" class="" valign="top"><?php echo FIELD_TYPE;?></td>
							<td width="88%" valign="top">
								<select name="txtfield_type" class="textarea2">
									<option value="text_box"><?php echo TEXTBOX;?></option>
									<option value="text_area"><?php echo TEXTAREA;?></option>
								</select>
							</td>
						</tr>
						<tr>
							<td width="12%" valign="top"><?php echo SORT_ORDER;?>&nbsp;<span class="required">*</span></td>
							<td width="88%" valign="top">
								<select name="txtsort_order" class="textarea2">
								
<?php
					
								for($i=1;$i<=100;$i++)
								{
								
?>			
									<option value="<?php echo $i?>"><?php echo $i?></option>
								
					
<?php			
								}
					
					
?>			
								
								
								</select>
							</td>
						</tr>	
						<tr>
							<td width="12%" valign="top"><?php echo ACTION;?></td>
							<td width="88%">
								<input type="checkbox" name="txtfield_required" value="Y">&nbsp;[ <?php echo ENABLE_CHKBOX;?> ]<br>
								<input type="checkbox" name="txtfield_displayfield" value="Y">&nbsp;[ <?php echo ENABLE_CHKBOX_CUSTMFLD;?> ]
							</td>
						</tr>
                                                
						<tr>
							<td align="center" colspan="6">
								
								<input type="button" name="back" class="button" value="&nbsp;<?php echo BACK;?>&nbsp;" onClick="history.go(-1)">
                                                                <input type="submit" class="button" name="insert" value="&nbsp;<?php echo ADD_TEXT;?>&nbsp">
							</td> 
						</tr>				
					</table>	
				</form>
								
				</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" 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();
?>