<?php
/* 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";
include "../includes/arrays.inc.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;
}
$sql = "SELECT * FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);
    $upsps_shipping = $row['enable_uspsshipping'];
} // end result check 
//selecting settings for fedex shipping

$sql = "select * from " . $tableprefix . "usps_settings ";
$rs = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($rs) > 0) {
    $row = mysql_fetch_array($rs);
    $uspsid = $row['username'];
    $server = $row['server'];
}

if (isset($_POST['submit'])) {
    $uspsid = addslashes($_POST['uspsId']);
    $server = addslashes($_POST['server']);
    (isset($_POST['enable_uspsshipping'])) ? $txtusps = $_POST['enable_uspsshipping'] : $txtusps = 'N';
    $sql_update = "update " . $tableprefix . "usps_settings SET username='" . $uspsid . "',
				 server='" . $server . "'";
    $result = mysql_query($sql_update);

    mysql_query("UPDATE " . $tableprefix . "settings 
	                SET enable_uspsshipping = " . GetSQLValueString($txtusps, "text"));

    if (mysql_affected_rows() > 0) {
        $message = SHIPPING_SETTINGS_UPDATED_SUCC;
    }
}
include "../includes/htmltop.php";

$sql = "SELECT * FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);

    $txtEnableShipping = $row["enable_shipping"];
    $txtfedex = $row["enable_fedexshipping"];
    $txtusps = $row["enable_uspsshipping"];
    $chkcanadapost = $row["enable_canadapost"];
    $chkaustraliapost = $row["enable_australiapost"];

    $txtflatShipping = $row["enable_flatrate"];
    $default_flatrate = $row["default_flatrate"];
    $flatrate_additional = $row["additional_flatrate"];
    $flatrate_name = stripslashes($row["flatrate_displayname"]);
}

if ($txtEnableShipping == "Y") {
    $shipping_checked = "checked";
} else {
    $shipping_checked = "";
}
if ($txtMembership == "Y") {
    $Membership_checked = "checked";
}

if ($chkcanadapost == "Y") {
    $canadapost_checked = "checked";
} else {
    $canadapost_checked = "";
}
if ($chkaustraliapost == "Y") {
    $australiapost_checked = "checked";
} else {
    $australiapost_checked = '';
}

if ($txtusps == "Y") {
    $shipping_usps_checked = "checked";
    $usps_shipping_block = "visible";
} else {
    $shipping_usps_checked = "";
    $usps_shipping_block = "none";
}
if ($txtEnableYourPay == "Y") {
    $yourpay = "checked";
    $yourpay_block = "";
} else {
    $yourpay = "";
    $yourpay_block = "none";
}
if ($txtfedex != "N") {
    $fedex_checked = "checked";
    $fedex_shipping_block = "";
} else {
    $fedex_checked = "";
    $fedex_shipping_block = "none";
}


if ($txtflatShipping == "Y") {
    $flat_checked = "checked";
    $flatrate_block = "";
} else {
    $flat_checked = "";
    $flatrate_block = "none";
}
?>
<style type="text/css">
    <!--
    .style1 {color: #FF0000}
    -->
</style>
<script language="javascript">
    function checkUspsshipping()
    {
        if(document.uspsshipping.enable_uspsshipping.checked == true)
        {
            document.getElementById("uspsBlock").style.display = "";
        }
        else
        {
            document.getElementById("uspsBlock").style.display = "none";
        }
    }
</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")
            ?>

            <form action="" method="post" name="uspsshipping" onSubmit="return validateFedex();">

                <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/shippingmenu.php") ?></td>
                        </tr>
                        <tr>
                            <td>
                                <div align="left" class="page_title"><?php echo EDIT_USPSHPNG;?></div>
                                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                                <br>
                                <div align="left">

                                    <table width="100%" border="0" cellpadding="5" cellspacing="5" class="manage_table">
                                        <tr align="left">
                                            <td  height="40" colspan="2"><span class="style1">*</span><?php echo MSG_USPS;?></td>
                                        </tr>
                                        <tr>
                                            <td  height="40"><?php echo SHIPPING_METHOD;?> </td>
                                            <td  align="left">&nbsp;<b><?php echo USPS;?></b></td>
                                        </tr>
                                        <tr>
                                            <td  height="40"><?php echo ENABLE;?> </td>
                                            <td  align="left">&nbsp;<input name="enable_uspsshipping" type="checkbox" id="enable_uspsshipping" value="Y" <?php echo $shipping_usps_checked ?>  onClick="checkUspsshipping();"/>
                                                <?php echo ENABLE_USPS;?>.</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="center">
                                                <div id="uspsBlock" style="display:<?php echo $usps_shipping_block; ?>">
                                                    <table align="left" width="100%"  border="0" cellpadding="5" cellspacing="5" >
                                                        <tr>
                                                            <td width="28%"><?php echo USPS_WEBTOOL;?><span class="style1">*</span></td>
                                                            <td width="72%" align="left"><input name="uspsId" class="textarea" type="text" id="uspsId" value="<?php echo $uspsid; ?>"> 
                                                                <?php echo TEST_UID;?></td>
                                                        </tr>
                                                        <tr>
                                                            <td><?php echo WHICH_SERVER;?> <span class="style1">*</span></td>
                                                            <td align="left"><input name="server" type="radio" value="test" <?php
            if ($server == "test") {
                echo "checked";
            }
            ?> checked> 
                                                                <?php echo TEST;?>
                                                                <input name="server" type="radio" value="production" <?php
                                                                                    if ($server == "production") {
                                                                                        echo "checked";
                                                                                    }
            ?> > 
                                                                <?php echo PRODUCTION;?></td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>

                                </div>
                                <div align="center"><input type="submit" name="submit" value="<?php echo BTN_UPDATE; ?>" class="button"></div>



                                <!--content area end-->
                            </td></tr>

                    </table>	

                </div>

            </form>

            <div align="left" class="clear_float"><img src="../images/clear.gif" alt="" width="1" height="1" /></div>
            <!--main body end -->
        </div>


        <?php
        include "../includes/footer.php";
        ?>

        <script language="javascript">
            function validateFedex()
            {
                if(document.uspsshipping.uspsId.value=="")
                {
                    return confirm("<?php echo PLS_USERID;?>");
                    document.uspsshipping.uspsId.focus();
                    return false;
                }
	
	
                return true;
	
            }	


        </script>
