<?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);
    $canada_post = $row['enable_canadapost'];
    $canada_merchatId = $row['canada_merchantId'];
    $canada_sever = $row['canada_server'];
} // end result check 
//selecting settings for fedex shipping
$message = "";
if (isset($_POST['submit'])) {
    $canada_merchatId = addslashes($_POST['merchatId']);
    $canada_sever = addslashes($_POST['server']);
    (isset($_POST['enable_canadapost'])) ? $chkcanadapost = $_POST['enable_canadapost'] : $chkcanadapost = 'N';
    if (empty($canada_merchatId)) {
        $message = ENTER_MID;
    }
    if ($message == "") { // check no error
        $sql_update = "UPDATE " . $tableprefix . "settings 
	                SET  canada_merchantId ='" . $canada_merchatId . "',
				 canada_server='" . $canada_sever . "',enable_canadapost='" . $chkcanadapost . "' ";
        $result = mysql_query($sql_update);

        $message_succ = "Shipping Settings Updated Successfully !!";
    }
}
$message = (!empty($message)) ? $message : $message_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";
    $canada_shipping_block = "visible";
} else {
    $canadapost_checked = "";
    $canada_shipping_block = "none";
}
if ($chkaustraliapost == "Y") {
    $australiapost_checked = "checked";
} else {
    $australiapost_checked = '';
}

if ($txtusps == "Y") {
    $shipping_usps_checked = "checked";
} else {
    $shipping_usps_checked = "";
}
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";
}

$sql = "UPDATE " . $tableprefix . "settings 
           SET
					enable_shipping				=	" . GetSQLValueString($txtEnableShipping, "text") . ",
					enable_flatrate				=	" . GetSQLValueString($txtflatShipping, "text") . ",
					enable_fedexshipping 		=	" . GetSQLValueString($txtfedex, "text") . ",
					enable_uspsshipping			=	" . GetSQLValueString($txtusps, "text") . ",
					enable_canadapost			=	" . GetSQLValueString($chkcanadapost, "text") . ",
					enable_australiapost		=	" . GetSQLValueString($chkaustraliapost, "text");
//echo $sql;
mysql_query($sql) or die(mysql_error());
?>
<style type="text/css">
    <!--
    .style1 {color: #FF0000}
    -->
</style>
<script language="javascript">
    function checkCanadashipping()
    {
        if(document.canadapost.enable_canadapost.checked == true)
        {
            document.getElementById("canadaBlock").style.display = "";
        }
        else
        {
            document.getElementById("canadaBlock").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="canadapost" 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_CP;?></div>
                                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                                <div align="left">				  
                                    <table width="100%" border="0" cellpadding="5" cellspacing="5" class="manage_table">
                                        <tr>
                                            <td  height="40" colspan="2"><span class="style1">*</span><?php echo MSG_CP;?></td>
                                        </tr>
                                        <tr>
                                            <td  height="40"><?php echo SHIPPING_METHOD;?> </td>
                                            <td  align="left">&nbsp;<b><?php echo CP_SHIPPING;?></b></td>
                                        </tr>
                                        <tr>
                                            <td><?php echo ENABLE;?></td>
                                            <td  align="left"><input name="enable_canadapost" type="checkbox" id="enable_canadapost" value="Y" <?php echo $canadapost_checked; ?> onClick="checkCanadashipping();">
                                                <?php echo SEL_CP;?>. </td>
                                        </tr>
                                        <tr>
                                            <td align="left" colspan="2">
                                                <div id="canadaBlock" style="display:<?php echo $canada_shipping_block; ?>">
                                                    <table align="center" width="100%" border="0">
                                                        <tr>
                                                            <td><?php echo MER_ID;?> <span class="style1">*</span></td>
                                                            <td align="left"><input name="merchatId" type="text" class="textarea2" id="merchatId" value="<?php echo $canada_merchatId; ?>">
                                                                <?php echo TESTMER;?></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 ($canada_server == "test") {
                echo "checked";
            } ?> checked>
                                                                <?php echo TEST;?>
                                                                <input name="server" type="radio" value="production" <?php if ($canada_server == "production") {
                echo "checked";
            } ?> >
                                                                <?php echo PRODUCTION;?></td>
                                                        </tr>
                                                    </table>
                                                </div></td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td align="left">&nbsp;</td>
                                        </tr>
                                    </table>
                                </div>
                                <div align="center"><input type="submit" name="submit" value="<?php echo BTN_UPDATE; ?>" class="button"></div>

                                <!--content area end-->

                                <!--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.canadapost.merchatId.value=="")
                {
                    return confirm("<?php echo PLS_CP;?>")
                    document.canadapost.merchatId.focus();
                    return false;
                }
	
		
                return true;
	
            }	

        </script>
