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


include "../includes/htmltop.php";

$currency_name_flag = 0;
$currency_code_flag = 0;

$adminCurrency = GetAdminCurrency();

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


    /* check whether currency name and currency code with the same name exists in the database */

    $select_currency = "SELECT * FROM " . $tableprefix . "currency_master WHERE LOWER(vcurrency_name) = " . GetSQLValueString(strtolower($_POST['txtCurrencyName']), "text");
    $result_currency = mysql_query($select_currency) or die(mysql_error());

    $select_currency_code = "SELECT * FROM " . $tableprefix . "currency_master WHERE LOWER(vcurrency_code) = " . GetSQLValueString(strtolower($_POST['txtCurrencyCode']), "text");
    $result_currency_code = mysql_query($select_currency_code) or die(mysql_error());

    if (mysql_num_rows($result_currency) > 0) {

        $message = CURR_NAME_EXIST."!!<br>";
        $currency_name_flag = 1;
    }
    if (mysql_num_rows($result_currency_code) > 0) {

        $message .= CURR_CODE_EXIST."!!";
        $currency_code_flag = 1;
    }
    if ($currency_name_flag == 0 && $currency_code_flag == 0) {

        $insert_currency = "INSERT INTO " . $tableprefix . "currency_master(vcurrency_name,vcurrency_code,vcurrency_symbol,nexchange_price,usdollar_rate,vactive)
						  	VALUES(" . GetSQLValueString($_POST['txtCurrencyName'], "text") . ","
                . GetSQLValueString($_POST['txtCurrencyCode'], "text") . ","
                . GetSQLValueString($_POST['txtCurrencySymbol'], "text") . ","
                . GetSQLValueString($_POST['txtExchangePrice'], "text") . ", "
                . GetSQLValueString($_POST['txtUSDValue'], "text") . ",
						  	'Y')";
        mysql_query($insert_currency) or die(mysql_error());

        header('Location:currency.php?msg=add');
    }
}
?>
<script>
    function checkAddCurrencyForm()
    {

        var form_name = new Array('txtCurrencyName','txtCurrencyCode','txtCurrencySymbol','txtExchangePrice','txtUSDValue');		
        var display_name = new Array('Currency Name','Currency Code','Currency Symbol','Exchange Price','US Dollar Value');
        var count = 5;	

        if(check_fields('frmAddCurrency',form_name,display_name,count))	
        {
  
  	
            if(!check_numeric(trimSpaces(document.frmAddCurrency.txtExchangePrice.value)))
            {
	 
                return confirm("<?php echo PLS_NUMBER;?>");
                document.frmAddCurrency.txtExchangePrice.focus();
                return false;		 
	 
            }
            if(trimSpaces(document.frmAddCurrency.txtExchangePrice.value)==0)
            {
	 
                return confirm("<?php echo PLS_NUMBER;?>");
                document.frmAddCurrency.txtExchangePrice.focus();
                return false;		 
	 
            }
	 
	 
            if(!check_numeric(trimSpaces(document.frmAddCurrency.txtUSDValue.value)))
            {
	 
            	return confirm("<?php echo PLS_NUMBER;?>");
                document.frmAddCurrency.txtUSDValue.focus();
                return false;		 
	 
            }
	 
            if(trimSpaces(document.frmAddCurrency.txtUSDValue.value)==0)
            {
	 
            	return confirm("<?php echo PLS_NUMBER;?>");
                document.frmAddCurrency.txtUSDValue.focus();
                return false;		 
	 
            }
	 
	 
  	
	   
        }
        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 -->


                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr><td height="35"><?php include_once("../includes/currencymenu.php") ?></td>
                    </tr>
                    <tr>
                        <td>

                            <div align="left" class="page_title"><?php echo ADD_NEW_CURRENCY_RATES;?></div>
                            <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                            <br>

                            <div align="left">			

                                <form name="frmAddCurrency" action="#" method="POST" enctype="" onSubmit="return checkAddCurrencyForm();">

                                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                                        <tr>
                                            <td colspan="3"><span class="required">*</span> <?php echo EXCHANGE_RATES;?>. </td>
                                        </tr>
                                        <tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
                                        <tr><td width="60%" align="left" valign=top><?php echo CURR_NAME;?>&nbsp;<span class="required">*</span></td><td width="2%" >&nbsp;</td>
                                            <td width="40%" align="left" valign=top><input class="textbox" type="text" name="txtCurrencyName" value="" size="25" maxlength="50" onChange="changeExchangeCurrency(this.value)"></td>
                                        </tr>
                                        <tr>
                                            <td align="left" valign=top><?php echo CURR_CODE;?>&nbsp;<span class="required">*</span></td>
                                            <td>&nbsp;</td>
                                            <td valign=top align="left"><input class="textbox" type="text" name="txtCurrencyCode" value="" size="25" maxlength="10"></td>
                                        </tr>
                                        <tr>
                                            <td align="left" valign=top><?php echo CURR_SYMBOL;?>&nbsp;<span class="required">*</span></td>
                                            <td>&nbsp;</td>
                                            <td valign=top align="left"><input class="textbox" type="text" name="txtCurrencySymbol" value="" size="25" maxlength="10"></td>
                                        </tr>
                                        <tr>
                                            <td align="left" valign=top><?php echo EXC_RATE_ADMIN_CURR;?> (<?php echo $adminCurrency['currency_code']; ?>) <?php echo AGAINST_SEC_CURR;?> <span id="exCurr"><b><?php echo $currency_row['vcurrency_name'] ?> </b></span><span class="required">*</span></td>
                                            <td>&nbsp;</td>
                                            <td valign=top align="left"><strong>  ( 1 <?php echo $adminCurrency['currency_code'] ?> =   </strong><input class="textbox" type="text" name="txtExchangePrice" value="<?php echo $_POST['txtExchangePrice'] ?>" size="25"> <b> <span id="exCurr1"><?php echo $currency_row['vcurrency_name'] ?></span> ) </b></td>
                                        </tr>

                                        <!--<tr>
                                            <td align="right" valign=top><strong>  ( 1 <?php echo $adminCurrency['currency_code'] ?> =   </strong></td>
                                            <td>&nbsp;</td>
                                            <td valign=top align="left"><input class="textbox" type="text" name="txtExchangePrice" value="<?php echo $_POST['txtExchangePrice'] ?>" size="25"> <b> <span id="exCurr1"><?php echo $currency_row['vcurrency_name'] ?></span> </b></td>
                                        </tr>-->
                                        <tr>
                                            <td colspan="3" align="left"><?php echo SHPNG_RATE_TO_DOLLAR;?>: </td>
                                        </tr>
                                               
                                        <tr>
                                            <td align="left" valign=top><?php echo EXC_RATE_USD_DOLL;?> <b> <span id="exCurr2"> <?php echo $adminCurrency['currency_code'] ?></span> </b> <span class="required">*</span></td>
                                            <td>&nbsp;</td>
                                            <td valign=top align="left"><b>( 1  USD =  </span> </b><input class="textbox" type="text" name="txtUSDValue"  size="25" value="<?php echo $_POST['txtUSDValue'] ?>"> <b><span id="exCurr3"><?php echo $adminCurrency['currency_code'] ?></span>)</b></td>
                                        </tr>

                                        <!--<tr>
                                            <td align="right"> <b>( 1  <?php echo USD;?> =  </span> </b></td>
                                            <td>&nbsp;</td>
                                            <td><input class="textbox" type="text" name="txtUSDValue"  size="25" value="<?php echo $_POST['txtUSDValue'] ?>"> <b><span id="exCurr3"><?php echo $adminCurrency['currency_code'] ?></span></b></td>
                                        </tr>-->
                                        <tr>
                                            <td colspan="3" align="center">
                                                <input type="button" name="back" class="button" value="<?php echo BACKBTN;?>" onClick="window.location='currency.php'">
                                                <input type="submit" value="&nbsp;<?php echo ADD_TEXT;?>&nbsp;" name="add" class="button">
                                            </td>
                                        </tr>
                                        <tr><td colspan="3">&nbsp;</td></tr>
                                    </table>

                                </form>

                            </div>
                        </td></tr></table>				

                <!--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();
        ?>
        <script type="text/javascript">
            function changeExchangeCurrency(val)
            {
                document.getElementById("exCurr").innerHTML = val;
                document.getElementById("exCurr2").innerHTML = val;
                document.getElementById("exCurr1").innerHTML = val;
                document.getElementById("exCurr3").innerHTML = val;
            }
        </script>