<?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($_POST['postback1'] == "CS"){//for changing status
        $id=$_POST['uid'];
        $changeto=$_POST['changeto'];
        $sqlcs = "UPDATE ".$tableprefix."artists  SET deleted = '$changeto' where artist_id =$id  ";
        //echo $sqlcs;
         mysql_query($sqlcs);
		 
		 $update_product_status = "UPDATE ".$tableprefix."products SET deleted ='".$changeto."' WHERE product_artist_id =".$id;
		 mysql_query($update_product_status);

}

if(isset($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = MSG_USER_DELETED;break;
		default:
			;
	} // switch

}

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

	header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);
	
		
}


$qryopt="";
 $txtSearch=$_GET['cmbSearchType'];
if($txtSearch!= "")
{
	$qryopt="r.Status='".$txtSearch."' and ";
}
/*$sql = " SELECT s.*,CASE WHEN deleted = 'N' THEN 'Yes' ELSE 'No' END AS artist_active
	   FROM ".$tableprefix."artists s " . $qryopt . "  order by date_registered DESC  ";*/
        $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.return_reason,r.refund_id
	 from ".$tableprefix."orders  o ,".$tableprefix."artists a ,".$tableprefix."refunds r ,".$tableprefix."order_details od
	 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  ORDER BY r.refund_id DESC";

        
      
	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = getSettingsValue('npagination_limit');
	
	$page = isset($_GET['page'])? trim($_GET['page']):1;

	
	$page = $_GET['page'];
	
	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 language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmArtists.submit();
}
function ChangeStatus(id,status){

        var frm = document.frmSeller1;
        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_SELLER;?>;")){
                frm.postback1.value="CS";
                frm.uid.value=id;
                frm.changeto.value=status;
                frm.submit();
        }

}
</script>

<body>
<center>
		
		<div align="right" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="right" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="right" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo MANAGE_REFUNDS;?> </div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>
											
					<div align="right">																			
					
					<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="get" name="frmArtists">
										
					<table  width="60%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
								  <tr>
                                                                      <td width="27%" align="left"  class="">
									
									<select name="cmbSearchType" class="textarea2">
									<option value=""><?php echo ALL_REFUNDS;?></option>
									<option value="replace"><?php echo REPLACE;?></option>
									<option value="repair"><?php echo REPAIR;?></option>
									<option value="refund"><?php echo REFUND;?></option>
									
									</select>
								    </td>
									<td width="73%" align="left" >  <a onClick="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a> </td>
								 </tr>
								  <tr>
								    <td> </td>    
								    <td align="right" valign="middle">&nbsp;</td>
				      </tr>
					  </table>
					</form>	
						</div>
					
					
					<div align="right">
					
					<form action="" method="post" name="frmSeller1">
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
					  <tr class="page_title2">
					  <th width="2%" align="center" valign="middle">#</th>
					  <th width="7%" align="center" valign="middle"><?php echo ORDER_ID?> </th>
					  <th width="13%" align="center" valign="middle"><?php echo REFUND_ID?></th>
					  <th width="11%" align="right" valign="middle"><?php echo BUYER_NAME;?></th>
					  <th width="16%" align="right" valign="middle"><?php echo SELLER_NAME;?></th>
					  <th width="16%" align="right" valign="middle"><?php echo PRODUCT_NAME;?></th>
					  <th width="15%" align="center" valign="middle"><?php echo STATUS;?></th>
					<th width="20%" align="center" valign="middle" colspan="2"><?php echo EMAIL;?></th>
					</tr>
					<input name="changeto" type="hidden" id="changeto">
					<input name="uid" type="hidden" id="uid">
					<input name="postback1" type="hidden" id="postback1">

	<?php
										$i = 1;
										
										if(mysql_num_rows($result) > 0 )
										{
													while($row = mysql_fetch_array($rs))
													{
														$link = "<a class=links href='viewrefunds.php?id=".$row["refund_id"]."' class='smalllink'>";
														
														switch ($row["status"])
														{
																case 'Repair':$st1=REPAIR;
																		break;
																case 'Refund' :$st1=REFUND;
																		break;
																case 'Replace' :$st1=REPLACE;
																		break;
														}
												?>		
										<tr>
										<td align="center" valign="middle"><?php echo (($page*$limit)+$i-$limit)?></td>
										<td align="center" valign="middle"><?php echo $row['order_id'];?></td>
										<td align="center" valign="middle"> <?php echo $row['refund_id'];?> </td>
										<td align="right" valign="middle"><?php echo $link .($row["billing_first_name"])."  " .$row["billing_last_name"]." </a>";?></td>
										<td align="right" valign="middle"><?php echo $link .($row["artist_name"]." ". $row["last_name"] )."</a>";?></td>
										<td align="right" valign="middle"><?php echo $link .($row["product_name"])."</a>";?></td>
										<td align="center" valign="middle" class="text_information"><?php if($row["status"]!='') { echo $link .$st1."</a>";} else { echo AWAIT_RESPONSE;}?></td>
										<td colspan="2" align="center" valign="middle"><?php echo $link .htmlentities($row["billing_email"])."</a>";?></td>
										</tr>
<?php

												$i++;
											}
											
										}
										else
										{
										
?>										

										<tr>
											<td align="center" valign="middle" colspan="9" 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'>".TEXT_NEXT."</a>";
											
										}	
	
																				
?>
										<tr>
										  <td align="right" class="btn_gotbl" valign="middle">&nbsp;</td>
										  <td align="left" valign="middle" class="page_nos">&nbsp;</td>
										  <td colspan="6" align="center">&nbsp;</td>
					  </tr>							  <?php
							 if($page < $numofpages || $page > 1)
							  {
							  ?>
										<tr>
											<td colspan="8" align="right" valign="middle">
											  <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 $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;<?php echo GO_TO;?>
													</td>
													<td width="8%" align="right">
														<select class="textarea2" name="gotoPage">
															<?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.frmSeller1.submit();" class="go_button_2"><?php echo GO; ?></a>
													</td>
													<td width="41%" align="center"><?php echo $next?></td>
												</tr>
											</table>
										  </td>
										</tr>
										<?php
										}
										?>
										</table>
										
					  </form>											

						</div>
						
						
				<!--content area end-->
								
				</div>
				
				</form>
				
					<div align="right" 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";
?>
																											