<?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";
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($_POST['gotoPage'])) {

    header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage']);
}
//===========================Tax Settings==============================
$sql = "SELECT * FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);

    $tax_enable = $row['enable_tax'];
} // end result check 
//==============================End tax settings========================
$sql = "SELECT r.*,CASE WHEN rate_enable='1' then 'Enabled' ElSE 'Disabled' END AS rate_enable  FROM " . $tableprefix . "taxrate r";
$result = mysql_query($sql);


/* if(!(isset($pagenum)))
  {
  $pagenum = 1;
  } */

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page']) ? trim($_GET['page']) : 1;

$current_page = isset($_GET['page']) ? trim($_GET['page']) : 1;
if (empty($page)) {
    $page = 1;
}

$result = mysql_query($sql) or die(mysql_error());

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string = " LIMIT $limitvalue, $limit";

$sql = $sql . $query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);




/* $sql=" SELECT u.*,CASE WHEN deleted = 'N' THEN 'Yes' ELSE 'No' END AS user_active
  FROM ".$tableprefix."users u " . $qryopt . "  order by date_registered DESC ";
  $sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch;
  $_SESSION["gbackurl"] = $sess_back;

  $totalrows = mysql_num_rows(mysql_query($sql));

  $navigate = pageBrowser($totalrows,2,2,"&cmbSearchType=$cmbSearchType&txtSearch=$txtSearch",$_GET[numBegin],$_GET[start],$_GET[begin],$_GET[num]);


  $sql = $sql.$navigate[0];
  $rs = mysql_query($sql);
 */

switch ($_GET['msg']) {
    case "a":
        $message = T_SAVED;
        $_GET['msg'] = '';
        break;

    case "u":
        $message = T_SAVED;
        $_GET['msg'] = '';
        break;

    case "d":
        $message = T_DEL;
        $_GET['msg'] = '';
        break;
    case "nd":
        $message = T_NOTDEL;
        $_GET['msg'] = '';
        break;
}//end switch
include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">
    function clickSearch()
    {
        document.frmUsers.submit();
    }
    function ChangeStatus(id,status){

        var frm = document.frmUsers1;
        if(status == "Y"){
            changeto = "<?php echo DISABLE; ?>";
        }else{
            changeto = "<?php echo ENABLE; ?>";
        }
        if(confirm("<?php echo ARE_YOU_SURE_YOU_WANT_TO;?> "+ changeto +" <?php echo THIS_USER;?>?")){
            frm.postback1.value="CS";
            frm.uid.value=id;
            frm.changeto.value=status;
            frm.submit();
        }

    }

    function confirmDelete()
    {
        var con=confirm("<?php echo MSG_TAXDEL;?>");
        if(con)
        {
            return true;
        }	
	
        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/taxmenu.php"); ?></td>
                    </tr>
                    <tr>
                        <td>

                            <div align="left" class="page_title"><?php echo T_OPT?> </div>
                            <?php
                            if (isset($message) && trim($message) != '') {
                                ?>
                                <div align="center" class="text_information grey_tr"><?php echo $message; ?></div>
                                <br>
                                <?php
                            }//end if
                            ?>
                            <?php if ($tax_enable == 1) { ?>
                                <div align="left">
                                    <form action="" method="post" name="frmUsers1">	

                                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                                            <tr class="form_header">
                                                <th width="6%" align="center" valign="middle">#</th>
                                                <th width="19%" align="left" valign="middle"><?php echo T_NAME;?></th>
                                                <th width="21%" align="left" valign="middle"><?php echo T_RATE;?></th>
                                                <th width="25%" align="left" valign="middle"><?php echo APP;?> </th>
                                                <th width="15%" align="center" valign="middle"><?php echo STATUS;?></th>
                                                <th width="14%" align="center" valign="middle" colspan="2"><?php echo ACTION;?></th>

                                            </tr>




                                            <input name="postback1" type="hidden" id="postback1">
                                            <input name="uid" type="hidden" id="uid">
                                            <input name="changeto" type="hidden" id="changeto">

                                            <?php
                                            $i = 1;

                                            if (mysql_num_rows($result) > 0) {

                                                while ($row = mysql_fetch_array($rs)) {
                                                    ?>

                                                    <tr>
                                                        <td height="46" align="center" valign="middle"><?php echo $i ?></td>
                                                        <td align="left" valign="middle"><?php echo htmlentities($row["taxname"]); ?></td>
                                                        <td align="left" valign="middle"><?php echo htmlentities($row["ntaxrate"]); ?></td>
                                                        <td align="left" valign="middle">

                                                            <?php echo htmlentities($row["vCountry"]); ?><br>
                                                            <?php
                                                            if ($row['vState'] != 1) {
                                                                $vstate = $row['vState'];
                                                                $xx = split(",", $vstate);
                                                                foreach ($xx as $value) {
                                                                    if (strlen($value) > 2) {
                                                                        echo '&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;' . $value . '<br>';
                                                                    }//end if
                                                                    else {
                                                                        echo '&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;' . stateName($row["vCountry"], $value) . '<br>';
                                                                    }//end else
                                                                }//end foreach			
                                                            }
                                                            ?>
                                                        </td>
                                                        <td align="center" valign="middle"><?php echo htmlentities($row["rate_enable"]); ?></td>
                                                        <td colspan="2" align="center" valign="middle"><a href="edittax.php?id=<?php echo htmlentities($row["Tid"]); ?>"> <?php echo EDIT;?></a> / <a href="deletetax.php?id=<?php echo htmlentities($row["Tid"]); ?>" onClick="return confirmDelete();"><?php echo DELETE;?></a></td>
                                                    </tr>
                                                    <?php
                                                    $i++;
                                                }
                                            } else {
                                                ?>										

                                                <tr>
                                                    <td align="center" valign="middle" colspan="7" class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
                                                </tr>
                                                <?php
                                            }

                                            if ($page > 1) {
                                                $pageprev = $page - 1;

                                                $previous_page = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pageprev alt='Previous' border='0' class='small_gray_button'>prev</a>";
                                            }

                                            if ($page < $numofpages) {
                                                $pagenext = ($page + 1);

                                                $next = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pagenext alt='Next' border='0' class='small_gray_button'>next</a>";
                                            }
                                            ?>
                                            <tr>
                                                <td colspan="6" align="center">
													<table width="100%" border="0" cellspacing="10" cellpadding="0">
														<tr align="left" valign="middle">
															<td width="21%" align="right"><?php echo $previous_page ?></td>
															<td width="23%" align="right">
																<?php echo PAGE."(".S.")";?> <?php echo $current_page; ?>/<?php echo $numofpages ?>&nbsp;&nbsp;
																<?php echo GO_TO;?>
															</td>
															<td width="8%" align="right">
																<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px; ">
																	<?php
																	for ($i = 1; $i <= $numofpages; $i++) {
																	if ($i == $_GET['page']) {
																	$page_selected = "selected";
																	} else {
																	$page_selected = "";
																	}
																	?>									
																	<option value="<?php echo $i ?>" <?php echo $page_selected ?>><?php echo $i ?></option>
																	<?php
																	}
																	?>									
																</select>
															</td>
															<td width="7%">
																<a onClick="Javascript:document.frmUsers1.submit();" style="cursor:pointer"><img src="../images/go_btn.gif" alt=""  /></a>                                            
															</td>
															<td width="41%" align="center"><?php echo $next ?></td>
														</tr>
													</table>
												</td>
                                            </tr>
                                        </table>

                                    </form>											

                                </div>

                                <?php
                            } else {
                                ?>
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                                    <tr>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="left"><strong><span class="required">* </span><?php echo TAX_NONAVAIL;?> </strong></td>
                                    </tr>
                                    <tr>
                                        <td align="left"><strong><?php echo MSG_TAX;?></strong></td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                </table>
                                <?php
                            }
                            ?>				

                        </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";
        ?>