<?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 (isset($_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"] != "") {
    $artistid = $_SESSION["sess_artistid"];
} else {
    header("Location:login.php");
    exit;
}
if(checkArtistExpired($artistid)){
    header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
    exit;
}


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

    header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage']);
}
$qry = "select * from " . $tableprefix . "settings ";
$rs_q = mysql_query($qry) or die(mysql_error());
$rr_settings = mysql_fetch_array($rs_q);

$qryopt = "";

if (isset($_POST['rma_action']) && $_POST['rma_action'] != '') {

    $action = $_POST['rma_action'];
    $qryopt = "r.Status='" . $action . "' and ";
}
/* $sql = "select o.billing_first_name,o.billing_last_name,o.billing_email ,o.order_id,a.artist_name,od.product_name,r.status,r.*
	 from " . $tableprefix . "orders o ," . $tableprefix . "artists a , " . $tableprefix . "order_details od ," . $tableprefix . "refunds r 
	 where " . $qryopt . " o.order_id=r.order_id  AND od.user_refund_id=r.refund_id and od.product_id=r.product_id 
	 and a.artist_id=r.seller_id and r.seller_id=" . $artistid . "  Order by r.refund_id DESC";*/


 $sql = "select o.billing_first_name,o.billing_last_name,o.billing_email,o.order_id,od.product_name,r.status,r.*
	 from " . $tableprefix . "orders o INNER JOIN " . $tableprefix . "order_details od ON od.order_id=o.order_id
	 INNER JOIN " . $tableprefix . "refunds r ON o.order_id=r.order_id and od.product_id=r.product_id  AND od.user_refund_id=r.refund_id
	 where " . $qryopt . " r.seller_id=" . $artistid . "  Order by r.refund_id DESC"; 
if (!(isset($pagenum))) {
    $pagenum = 1;
}

$limit = getSettingsValue('npagination_limit');

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

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

<script>
    function clickSearch()
    {
        document.frmrefunds.submit();
    }

    function addValues(order_value)
    {
		
        var checkbox_values = "";	
	
        for(i=1;i<=document.frmMyProducts1.checkCount.value;i++)
        {
	
            var checkbox_name = "Product_"+i;
			
            if(document.getElementById(checkbox_name).checked)
            {
                checkbox_values += document.getElementById(checkbox_name).value + ',';
            }
				
            document.frmMyProducts2.txtProductId.value = checkbox_values;
		
			
        }		
    }

    function checkAllOrders()
    {

        var checkbox_values = "";	
	
        if(document.frmMyProducts1.checkAllBox.checked)
        {
				
            for(i=1;i<=document.frmMyProducts1.checkCount.value;i++)
            {
		
                var checkbox_name = "Product_"+i;
                document.getElementById(checkbox_name).checked = true;	
                checkbox_values += document.getElementById(checkbox_name).value + ',';
						
            }
		
            document.frmMyProducts2.txtProductId.value = checkbox_values;

        }
        else
        {
            for(i=1;i<=document.frmMyProducts1.checkCount.value;i++)
            {
		
                var checkbox_name = "Product_"+i;
                document.getElementById(checkbox_name).checked = false;	
			
            }
		
            document.frmMyProducts2.txtProductId.value = "";
        }


    }

    function deleteProducts()
    {
        if(document.frmMyProducts2.txtProductId.value == "")
        {
            alert('<?php echo MSG_SEL_PROD_DEL;?>');
        }
        else
        {
		
            var status =  confirm('<?php echo QTN_PROD_DEL;?>');
		
            if(status == true)
            {
                document.frmMyProducts2.submit();
            }	
        }
	
    }


</script>

<body>

<center>

    <div align="left" id="layout">




        <!--header area start -->
        <?php
        include_once("../includes/topheader_seller.php")
        ?>

        <!--header area end -->




        <div align="left" class="main_body">
            <!--main body start -->



            <?php
            include_once("../includes/artisttopmenu.php")
            ?>		


            <div align="left" class="content_area">

                <!--content area start -->

                <div align="left" class="page_title"><?php echo TEXT_REFUND_REQ;?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>
                <div align="left">		
                    <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" name="frmrefunds">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                            <tr>
                                <td width="90%" align="left" valign="middle"><?php echo TEXT_SEARCH;?>
                                    <select class="textarea" name="rma_action">
                                        <option value=""><?php echo TEXT_ALL_REFUND;?></option>
                                        <?php
                                        if ($rr_settings['rma_repair'] == 'Y') {
                                            ?>
                                            <option value="Repair" <?php
                                        if ($action == "Repair") {
                                            echo "selected";
                                        }
                                            ?>><?php echo TEXT_REPAIR;?></option>
                                                    <?php
                                                }
                                                ?>
                                                <?php
                                                if ($rr_settings['rma_replace'] == 'Y') {
                                                    ?>
                                            <option value="Replace" <?php
                                        if ($action == "Replace") {
                                            echo "selected";
                                        }
                                                    ?>><?php echo TEXT_REPLACE;?></option>
                                                    <?php
                                                }
                                                ?>
                                        <?php
                                        if ($rr_settings['rma_refund'] == 'Y') {
                                            ?>
                                            <option value="Refund" <?php
                                                if ($action == "Refund") {
                                                    echo "selected";
                                                }
                                                ?>><?php echo TEXT_REFUND;?></option>
    <?php
}
?>
                                    </select>&nbsp;
                                    &nbsp;<a href="javascript:clickSearch();" class="go_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
                                </td>
                                <td width="22%" align="right">&nbsp;</td>

                            </tr>
                        </table>


                    </form>
<?php
if ($rr_settings[enable_rma] == 'Y') {
    ?>			
                        <table border="0" width="100%" cellpadding="0" cellspacing="0" class="manage_table">
                            <form action="" method="post" name="frmMyProducts1">
                                <tr class="form_header">
                                    <th width="4%" align="left">#</th>
                                    <th width="7%" align="left"><?php echo TEXT_ORDER_ID;?></th>
                                    <th width="9%" align="left"><?php echo TEXT_REFUND_ID;?></th>
                                    <th width="12%" align="left"><?php echo TEXT_BUYER_NAME;?> </th>
                                    <th width="13%" align="left"><?php echo TEXT_PRODUCT;?><?php echo TEXT_NAME;?> </th>
                                    <th width="11%" align="left"><?php echo TEXT_QUANTITY;?></th>
                                    <th width="11%" align="left"><?php echo TEXT_DATE;?> </th>
                                    <th width="15%" align="left"><?php echo TEXT_EMAIL;?></th>
                                    <th width="18%" align="left"><?php echo TEXT_ACTION;?></th>
                                </tr>


    <?php
    if (mysql_num_rows($result) > 0) {
        $i = 1;
        while ($row = mysql_fetch_array($rs)) {
            //--- Update seller view status ---//
            $sql = "UPDATE ".$tableprefix."refunds SET seller_viewed_status = 1 WHERE refund_id = '".addslashes($row['refund_id'])."'";			
            mysql_query($sql) or die (mysql_error());  
            $link = "<a class=links href='editmyproduct.php?productid=" . $row["product_id"] . "&page=" . $_GET['page'] . "'>";
            ?>
                                        <tr> 
                                            <td><?php echo $i ?></td>
                                            <td><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo stripslashes($row["order_id"]); ?></a></td>
                                            <td><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo stripslashes($row["refund_id"]); ?></a></td>
                                            <td align="left"><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo stripslashes($row["billing_first_name"] . " " . $row["billing_last_name"]); ?></a></td>
                                            <td align="left"><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo (stripslashes($row["product_name"])); ?></a></td>
                                            <td align="left"><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo htmlentities($row["quantity"]); ?></a></td>
                                            <td align="left"><?php echo dateFormat($row["date"], "Y-m-d", "m/d/Y"); ?></td>
                                            <td align="left"><a href="view_detail_refunds.php?refund_id=<?php echo $row['refund_id']; ?>"><?php echo htmlentities($row["billing_email"]); ?></a>
                                            </td>
                                            <td align="left" class="text_information"><?php if (htmlentities($row["status"] == '')) { ?><a href="refund_action.php?refund_id=<?php echo $row['refund_id']; ?>" class="text_information"><?php echo TEXT_CHANGE_STATUS;?> </a><?php
                        } else {
                            echo $row['status'];
                        }
                        ?> </td>

                                        </tr>
                                        <?php
                                        $i++;
                                    }
                                    ?>	

                                    <input type="hidden" name="checkCount" value="<?php echo $i - 1 ?>">
                                    <?php
                                } else {
                                    ?>					
                                    <tr>
                                        <td align="center" valign="middle" colspan="9"  class="text_information"><?php echo MSG_NO_REFUND_REQ;?></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'>".TEXT_PAGES_PREV."</a>";
                                }


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

                                    $next = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_PAGES_NEXT."</a>";
                                }
                                ?>


                                <tr>
                                    <td class="page_nos"  align="center" colspan="4">&nbsp;</td>
                                    <td align="right" valign="middle" class="page_nos" colspan="4">&nbsp;</td>
                                    <td align="right" class="btn_gotbl" valign="middle">&nbsp;</td>
                                </tr>
                                            <?php
                                            if ($page < $numofpages || $page > 1) {
                                                ?>
                                    <tr>
                                        <td class="page_nos"  align="center" colspan="9">
											<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 TEXT_PAGES; ?> <?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;<?php echo TEXT_GOTO; ?>
													</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.frmMyProducts1.submit();" class="go_button_2"><?php echo BTN_GO; ?></a>
													</td>
													<td width="41%" align="center"><?php echo $next ?></td>
												</tr>
											</table>
										 </td>
                                    </tr>
        <?php
    }
    ?>
                            </form>
                            <tr>
                                <td colspan="9">

                                </td>
                            </tr>
                        </table>
<?php } ?>
<?php
if ($rr_settings['enable_rma'] == 'N') {
    ?>		
                        <table class="manage_table" cellpadding="5" cellspacing="5" width="100%">
                            <tr><td align="center" class="text_information">&nbsp;<?php echo MSG_CONT_ADMIN;?> </td></tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
<?php } ?>

                </div>


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