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

    $fedexmode = $row['enable_fedexshipping'];

    switch ($fedexmode) {
        case "FDXE":
            $fedexShipping = FEDEX_EXPRESS;
            $fedexServiceArray = $fedexService;

            break;
        case "FDXG":
            $fedexShipping = FEDEX_GROUND;
            $fedexServiceArray = $fedexGroundService;
            break;
        case "N":
            $fedexShipping = FEDEX_INACTIVE;
            break;
    }// end if 	
} // end result check 
//selecting settings for fedex shipping


$message = "";
$success_message ="";
if (isset($_POST['submit'])) {
    $fedexaccno = addslashes($_POST['fedexaccno']);
    $fedexmeterno = addslashes($_POST['fedexmeterno']);
    $weight = addslashes($_POST['weight']);
    $server = addslashes($_POST['server']);
    $dropoff = addslashes($_POST['dropoff']);
    $packagesTypes = addslashes($_POST['packageType']);
    $fedexpassword = addslashes($_POST['fedexpassword']);
    $fedexkey = addslashes($_POST['fedexkey']);
    (isset($_POST['enable_fedexshipping'])) ? $txtfedexShipping = $_POST['enable_fedexshipping'] : $txtfedexShipping = 'N';
    if ($txtfedexShipping == "Y") {
        $txtfedex = $_POST['fedex'];
    } else {
        $txtfedex = "N";
    }
    mysql_query("UPDATE " . $tableprefix . "settings SET enable_fedexshipping = " . GetSQLValueString($txtfedex, "text"));
    $currency = 'USD';
    //print_r($_POST['fedexservice']);
    if (empty($fedexaccno)) {
        $message =FEDEX_AC. "<br>";
    }
    if (empty($fedexmeterno)) {
        $message.=FEDEX_MNO;
    }
    if (empty($fedexpassword)) {
    	$message =PLS_FPASSWORD. "<br>";
    }
    if (empty($fedexkey)) {
    	$message.=PLS_FKEY;
    }
    if (is_array($_POST['fedexservice'])) { // check if it is an array or not
        $service_Name = join(",", $_POST['fedexservice']);
    } // array checking end 
    if (empty($message)) {
        $sql_update = "update " . $tableprefix . "fedexsettings SET FedexAccno='" . $fedexaccno . "',
				FedexMeterno='" . $fedexmeterno . "',FedexWeight='" . $weight . "',
				FedexServer='" . $server . "',FedexDropOff='" . $dropoff . "',
				FedexPackage='" . $packagesTypes . "',
                                FedexPassword='".$fedexpassword. "',
                                FedexKey='" .$fedexkey. "',
				FedexCurrency='" . $currency . "' ";
        $result = mysql_query($sql_update);

        $success_message = MSG_SETTINGS;
    }
}
$message = ($message != '') ? $message : $message_succ;
$sql = "select * from " . $tableprefix . "fedexsettings ";
$rs = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($rs) > 0) {
    $row = mysql_fetch_array($rs);
    $fedexaccno = $row['FedexAccno'];
    $fedexmeterno = $row['FedexMeterno'];
    $weight = $row['FedexWeight'];
    $server = $row['FedexServer'];
    $dropoff = $row['FedexDropOff'];
    $packagingTypes = $row['FedexPackage'];
    $serviceName = $row['FedexService'];
    $serviceName = $row['FedexService'];
    $Fedexservice = $row['FedexService'];
     $fedexpassword = $row['FedexPassword'];
    $fedexkey = $row['FedexKey'];
}

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

    $txtfedex = $row["enable_fedexshipping"];


    switch ($txtfedex) {
        case "FDXE":
            $fedexShipping = FEDEX_EXPRESS;
            $fedexServiceArray = $fedexService;

            break;
        case "FDXG":
            $fedexShipping = FEDEX_GROUND;
            $fedexServiceArray = $fedexGroundService;
            break;
        case "N":
            $fedexShipping = FEDEX_INACTIVE;
            break;
    }// end if 	
}

if ($txtfedex != "N") {
    $fedex_checked = "checked";
    $fedex_shipping_block = "";
} else {
    $fedex_checked = "";
    $fedex_shipping_block = "none";
}

$fedexShipping = FEDEX_GROUND;

include "../includes/htmltop.php";
?>
<style type="text/css">
    <!--
    .style1 {color: #FF0000}
    -->
</style>
<script language="javascript">
    function checkFedexshipping()
    {
        if(document.fedexShipping.enable_fedexshipping.checked == true)
        {
            document.getElementById("FedexBlock").style.display = "";
        }
        else
        {
            document.getElementById("FedexBlock").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="fedexShipping" 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_FED;?></div>
                                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                                <div align="center" class="text_information_success grey_tr">
                                                     <?php echo $success_message; ?>
                                </div>
                                <br>

                                <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_FED;?></td>
                                        </tr>
                                        <tr>
                                            <td  height="40"><?php echo SHIPPING_METHOD;?> </td>
                                            <td  align="left">&nbsp;<b><?php echo $fedexShipping; ?></b>
                                            
                                            <input name="fedex"  value="FDXG" type="hidden">
                                            </td>
                                        </tr>
                                        
                                        <!--tr><td colspan="2" class="text_information"> <?php echo FEDEX_SOAP_EXTENSION_MESSAGE ;?></td></tr-->
                                        
                                        <tr>
                                            <td align="left" valign="top"><?php echo FEDEX_ENABLE;?></td>
                                            <td  align="left" valign="middle"><input type="checkbox" name="enable_fedexshipping" value="Y" <?php echo $fedex_checked ?> >
                                                                                     <?php echo SELFED;?>
                                                                                     
                                        </tr>                                       
                                       
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td align="left">&nbsp;</td>
                                                        </tr>
                                                        <tr>
                                                            <td><?php echo FEDACNO;?><span class="style1">*</span></td>
                                                            <td align="left"><input name="fedexaccno" type="text" id="fedexaccno" value="<?php echo $fedexaccno; ?>" maxlength="50" class="textarea"> 
                                                                <?php echo TESTACNO;?></td>
                                                        </tr>
                                                        <tr>
                                                            <td><?php echo FEDMETER;?><span class="style1">*</span></td>
                                                            <td align="left"><input name="fedexmeterno" type="text" id="fedexmeterno" value="<?php echo $fedexmeterno; ?>" maxlength="50" class="textarea">
                                                                <?php echo TESTMNO;?></td>
                                                        </tr>
                                                        
                                                         <tr>
                                                            <td><?php echo FEDEX_PASSWORD;?><span class="style1">*</span></td>
                                                            <td align="left"><input name="fedexpassword" type="text" id="fedexpassword" value="<?php echo $fedexpassword; ?>" maxlength="50" class="textarea">
                                                                <?php echo FEDEX_TEST_PASSWORD;?> : 5ltFUnC8DD34ZYzAt1DEHOcBH</td>
                                                        </tr>
                                                        
                                                        <tr>
                                                            <td><?php echo FEDEX_KEY;?><span class="style1">*</span></td>
                                                            <td align="left"><input name="fedexkey" type="text" id="fedexkey" value="<?php echo $fedexkey; ?>" maxlength="50" class="textarea">
                                                                <?php echo FEDEX_TEST_KEY;?> : 93MUTAoVptiVrLWf</td>
                                                        </tr>
                                                        <tr>
                                                            <td><?php echo WU;?> <span class="style1">*</span></td>
                                                            <td align="left"><input name="weight" type="radio" value="LBS" <?php
                                                                                   if ($weight == "LBS") {
                                                                                       echo "checked";
                                                                                   }
            ?>  checked>
                                                                <?php echo LBS;?>							        </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>
                                                        <!--<tr>
                                                            <td valign="top"><?php echo DROPOFF;?><span class="style1">*</span><br>							      </td>
                                                            <td align="left">
                                                                <?php
                                                                foreach ($dropOfftype as $dropoffs => $type) { // display dropoff from array
                                                                    ?>
                                                                    <input name="dropoff" type="radio" value="<?php echo $dropoffs; ?>" <?php
                                                                if ($dropoffs == $dropoff) {
                                                                    echo "checked";
                                                                } if ($dropoff == '' && $dropoffs == "REGULAR_PICKUP") {
                                                                    echo "checked";
                                                                }
                                                                    ?>><?php echo $type; ?>
                                                                    <br>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td valign="top"><?php echo PACKTYP;?></td>
                                                            <td align="left">
                                                                <select name="packageType" id="packageType">
                                                                    <?php
                                                                    foreach ($Packagetype as $key => $value) { // display package type
                                                                        if ($packagingTypes == '') {
                                                                            $pt = YOUR_PACK;
                                                                        } else {
                                                                            $pt = $packagingTypes;
                                                                        }
                                                                        if ($key == $pt) {
                                                                            $check = "selected";
                                                                        } else {
                                                                            $check = '';
                                                                        }
                                                                        ?>
                                                                        <option value="<?php echo $key; ?>"  <?php echo $check; ?>><?php echo $value; ?></option>

                                                                        <?php
                                                                    } // end for each 
                                                                    ?>
                                                                </select></td>
                                                        </tr>-->
                                                    </table>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top">&nbsp;</td>
                                            <td align="left">&nbsp;</td>
                                        </tr>
                                    </table>

                                </div>
                                <div align="center"><input type="submit" name="submit" value="<?php echo 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.fedexShipping.fedexaccno.value=="")
                {
                    alert("<?php echo PLS_FAC;?>");
                    document.fedexShipping.fedexaccno.focus();
                    return false;
                }
	
                if(document.fedexShipping.fedexmeterno.value=="")
                {
                	alert("<?php echo PLS_FNO;?>");
                    document.fedexShipping.fedexmeterno.focus();
                    return false;
                }
                
                 if(document.fedexShipping.fedexpassword.value=="")
                {
                	alert("<?php echo PLS_FPASSWORD;?>");
                    document.fedexShipping.fedexpassword.focus();
                    return false;
                }
                 if(document.fedexShipping.fedexkey.value=="")
                {
                	alert("<?php echo PLS_FKEY;?>");
                    document.fedexShipping.fedexkey.focus();
                    return false;
                }
                else {
                          return true;

                }
	
	
	
            }	


        </script>
