<?php
include("include/config.php");
include("include/protect.class.php");
include("include/jdf.php");
include('include/functions.php');
$prot=new protect();
if ($prot->showPage) {
$db=new DB($globalConfig['dbase'], $globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass']);
mysql_query("SET NAMES utf8");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>پرداخت های کاربران</title>
<link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="fancybox/jquery.fancybox-1.3.1.js"></script>
<?php include("maintemplate/mainheader.php");?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript" src="maintemplate/js/gen_validatorv4.js" type="text/javascript" xml:space="preserve"></script>
<script type="text/javascript" charset="utf-8">

	function getcat (){
		var part_id = $("#part_id").val();
		
		$(document).ready(function (){
			
			
			$("#loading").fadeIn("slow",function(){
});
			$.ajax({
				type: "POST",
				url: "send_ajax_chitasoft.php?act=getcat",
				dataType: "html",
				data: "part_id="+part_id,
				success: function(data){
					$("#cat_id").html(data);
					 $("#loading").fadeOut("slow");
				}
			
			});
 
        
       	
    
		});
	}
	
</script>
</head>
<body>
<div id="wpwrap">
<div id="wpcontent">
	<?php include("include/menutop.php");?> 
<div id="wpbody">
	<?php include("include/header.php");?>
    <div style="overflow:hidden; padding-bottom:50px;" id="wpbody-content">
        <div id="screen-meta">
            <div class="wrap">
                <div id="icon-index" class="icon32"><b4r></div>
                <h2>پرداخت های کاربران</h2>
               
                <div id="dashboard-widgets-wrap">
                    <div id="dashboard-widgets" class="metabox-holder">
              	<div class="postbox-container" style="width:38%;">
                            <div id="normal-sortables" class="meta-box-sortables ui-sortable"><div id="dashboard_recent_comments" class="postbox ">
                   			<div class="handlediv" title="برای جانشینی کلیک کنید"><br></div>
                   			<h3 class="hndle"><span>فیلتر تاریخ</span></h3>
                   <form action="buys.php?detail" method="post">
                                     <table class="form-table">
<tbody>
<tr class="even" valign="top">
<th scope="row"><label for="from">از تاریخ</label></th>
<td>
<select id="from" name="fromday">
	
    
	<option value="1"><?php echo Convertnumber2farsi(1);?></option>
    <option value="2"><?php echo Convertnumber2farsi(2);?></option>
    <option value="3"><?php echo Convertnumber2farsi(3);?></option>
    <option value="4"><?php echo Convertnumber2farsi(4);?></option>
    <option value="5"><?php echo Convertnumber2farsi(5);?></option>
    <option value="6"><?php echo Convertnumber2farsi(6);?></option>
    <option value="7"><?php echo Convertnumber2farsi(7);?></option>
    <option value="8"><?php echo Convertnumber2farsi(8);?></option>
    <option value="9"><?php echo Convertnumber2farsi(9);?></option>
    <option value="10"><?php echo Convertnumber2farsi(10);?></option>
    <option value="11"><?php echo Convertnumber2farsi(11);?></option>
    <option value="12"><?php echo Convertnumber2farsi(12);?></option>
    <option value="13"><?php echo Convertnumber2farsi(13);?></option>
    <option value="14"><?php echo Convertnumber2farsi(14);?></option>
    <option value="15"><?php echo Convertnumber2farsi(15);?></option>
    <option value="16"><?php echo Convertnumber2farsi(16);?></option>
    <option value="17"><?php echo Convertnumber2farsi(17);?></option>
    <option value="18"><?php echo Convertnumber2farsi(18);?></option>
    <option value="19"><?php echo Convertnumber2farsi(19);?></option>
    <option value="20"><?php echo Convertnumber2farsi(20);?></option>
    <option value="21"><?php echo Convertnumber2farsi(21);?></option>
    <option value="22"><?php echo Convertnumber2farsi(22);?></option>
    <option value="23"><?php echo Convertnumber2farsi(23);?></option>
    <option value="24"><?php echo Convertnumber2farsi(24);?></option>
    <option value="25"><?php echo Convertnumber2farsi(25);?></option>
    <option value="26"><?php echo Convertnumber2farsi(26);?></option>
    <option value="27"><?php echo Convertnumber2farsi(27);?></option>
    <option value="28"><?php echo Convertnumber2farsi(28);?></option>
    <option value="29"><?php echo Convertnumber2farsi(29);?></option>
    <option value="30"><?php echo Convertnumber2farsi(30);?></option>
    <option value="31"><?php echo Convertnumber2farsi(31);?></option>
  
    
</select>
<select id="frommonth" name="frommonth">
	<option value="1" >فروردین</option>
    <option value="2" >اردیبهشت</option>
    <option value="3" >خرداد</option>
    <option value="4" >تیر</option>
    <option value="5" >مرداد</option>
    <option value="6" >شهریور</option>
    <option value="7" >مهر</option>
    <option value="8" >آبان</option>
    <option value="9" >آذر</option>
    <option value="10" >دی</option>
    <option value="11" >بهمن</option>
    <option value="12" >اسفند</option>
</select>
<select id="fromyear" name="fromyear">
<option value="1389"><?php echo Convertnumber2farsi(89); ?></option>
<option value="1390"><?php echo Convertnumber2farsi(90); ?></option>
<option value="1391"><?php echo Convertnumber2farsi(91); ?></option>
<option value="1392"><?php echo Convertnumber2farsi(92); ?></option>
<option value="1393"><?php echo Convertnumber2farsi(93); ?></option>
<option value="1394"><?php echo Convertnumber2farsi(94); ?></option>
<option value="1395"><?php echo Convertnumber2farsi(95); ?></option>
<option value="1396"><?php echo Convertnumber2farsi(96); ?></option>
<option value="1397"><?php echo Convertnumber2farsi(97); ?></option>
<option value="1398"><?php echo Convertnumber2farsi(98); ?></option>
<option value="1399"><?php echo Convertnumber2farsi(99); ?></option>
</select>
</td>
</tr>
<tr class="odd" valign="top">
<th scope="row"><label for="to">تا تاریخ</label></th>
<td>

<select id="to" name="today">
	
    
	<option value="1"><?php echo Convertnumber2farsi(1);?></option>
    <option value="2"><?php echo Convertnumber2farsi(2);?></option>
    <option value="3"><?php echo Convertnumber2farsi(3);?></option>
    <option value="4"><?php echo Convertnumber2farsi(4);?></option>
    <option value="5"><?php echo Convertnumber2farsi(5);?></option>
    <option value="6"><?php echo Convertnumber2farsi(6);?></option>
    <option value="7"><?php echo Convertnumber2farsi(7);?></option>
    <option value="8"><?php echo Convertnumber2farsi(8);?></option>
    <option value="9"><?php echo Convertnumber2farsi(9);?></option>
    <option value="10"><?php echo Convertnumber2farsi(10);?></option>
    <option value="11"><?php echo Convertnumber2farsi(11);?></option>
    <option value="12"><?php echo Convertnumber2farsi(12);?></option>
    <option value="13"><?php echo Convertnumber2farsi(13);?></option>
    <option value="14"><?php echo Convertnumber2farsi(14);?></option>
    <option value="15"><?php echo Convertnumber2farsi(15);?></option>
    <option value="16"><?php echo Convertnumber2farsi(16);?></option>
    <option value="17"><?php echo Convertnumber2farsi(17);?></option>
    <option value="18"><?php echo Convertnumber2farsi(18);?></option>
    <option value="19"><?php echo Convertnumber2farsi(19);?></option>
    <option value="20"><?php echo Convertnumber2farsi(20);?></option>
    <option value="21"><?php echo Convertnumber2farsi(21);?></option>
    <option value="22"><?php echo Convertnumber2farsi(22);?></option>
    <option value="23"><?php echo Convertnumber2farsi(23);?></option>
    <option value="24"><?php echo Convertnumber2farsi(24);?></option>
    <option value="25"><?php echo Convertnumber2farsi(25);?></option>
    <option value="26"><?php echo Convertnumber2farsi(26);?></option>
    <option value="27"><?php echo Convertnumber2farsi(27);?></option>
    <option value="28"><?php echo Convertnumber2farsi(28);?></option>
    <option value="29"><?php echo Convertnumber2farsi(29);?></option>
    <option value="30"><?php echo Convertnumber2farsi(30);?></option>
    <option value="31"><?php echo Convertnumber2farsi(31);?></option>
  
    
</select>
<select id="tomonth" name="tomonth">
	<option value="1" >فروردین</option>
    <option value="2" >اردیبهشت</option>
    <option value="3" >خرداد</option>
    <option value="4" >تیر</option>
    <option value="5" >مرداد</option>
    <option value="6" >شهریور</option>
    <option value="7" >مهر</option>
    <option value="8" >آبان</option>
    <option value="9" >آذر</option>
    <option value="10" >دی</option>
    <option value="11" >بهمن</option>
    <option value="12" >اسفند</option>
</select>
<select id="toyear" name="toyear">
<option value="1389"><?php echo Convertnumber2farsi(89); ?></option>
<option value="1390"><?php echo Convertnumber2farsi(90); ?></option>
<option value="1391"><?php echo Convertnumber2farsi(91); ?></option>
<option value="1392"><?php echo Convertnumber2farsi(92); ?></option>
<option value="1393"><?php echo Convertnumber2farsi(93); ?></option>
<option value="1394"><?php echo Convertnumber2farsi(94); ?></option>
<option value="1395"><?php echo Convertnumber2farsi(95); ?></option>
<option value="1396"><?php echo Convertnumber2farsi(96); ?></option>
<option value="1397"><?php echo Convertnumber2farsi(97); ?></option>
<option value="1398"><?php echo Convertnumber2farsi(98); ?></option>
<option value="1399"><?php echo Convertnumber2farsi(99); ?></option>
</select>
<input type="hidden" name="product" value="<?php echo $_GET['product'];?>" />
</td>
</tr>
</tbody>
</table>
<p class="submit" align="center">
<input name="process" class="button-primary" value="نمایش گزارش" type="submit">
</p>
                                     </form>
                    </div>
                            </div>
                        </div>
					<div class="postbox-container" style="width:98%;">
                                <div id="normal-sortables" class="meta-box-sortables ui-sortable"><div id="dashboard_recent_comments" class="postbox ">
                                   <div class="handlediv" title="برای جانشینی کلیک کنید"><br></div><h3 class="hndle"><span>پرداخت های کاربران</span></h3>
                             <div align="center" style="padding:5px;">
                                               
<?php $page = $_GET['page'];
$limit = $_GET['limit'];
if (!($limit)){
$limit = 20;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
if(isset($_GET['detail'])){
	$fromdatearr=jalali_to_gregorian($_POST['fromyear'],$_POST['frommonth'],$_POST['fromday'],'/');
	$fromdate=$fromdatearr[0].'-'.$fromdatearr[1].'-'.$fromdatearr[2];
	
	$todatearr=jalali_to_gregorian($_POST['toyear'],$_POST['tomonth'],$_POST['today'],'/');
	$todate=$todatearr[0].'-'.$todatearr[1].'-'.$todatearr[2];
	$numresults = $db->query("select * from transfers where tDate between '".$fromdate."' and '".$todate."' ORDER BY tDate");
	}else{
	$numresults = $db->query("select * from transfers ORDER BY tDate"); 
	}// the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
$pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows%$limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
 
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.?>      
<div class="text1"> 
<table width="100%" border="0">
	<tr>
  		<td width="50%" align="right">
موارد يافت شده:  <b><?=Convertnumber2farsi($first)?></b> تا <b><?=Convertnumber2farsi($last)?></b> از <b><?=Convertnumber2farsi($numrows)?></b> مورد
  		</td>
  		<td width="50%" align="left">
صفحه <b><?=Convertnumber2farsi($current)?></b> از <b><?=Convertnumber2farsi($total)?></b> صفحه
  		</td>
 	</tr>
 	<tr>
  		<td colspan="2" align="left">&nbsp;</td>
 	</tr>
 	<tr>
  		<td colspan="2" align="left">
چند مورد نشان داده شود: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5"><?=Convertnumber2farsi(5)?></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10"><?=Convertnumber2farsi(10)?></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20"><?=Convertnumber2farsi(20)?></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50"><?=Convertnumber2farsi(50)?></a>
  		</td>
 	</tr>
</table>
	<?
    //Go back into PHP mode.
    
    // Now we can display results.
	if(isset($_GET['detail'])){
	$fromdatearr=jalali_to_gregorian($_POST['fromyear'],$_POST['frommonth'],$_POST['fromday'],'/');
	$fromdate=$fromdatearr[0].'-'.$fromdatearr[1].'-'.$fromdatearr[2];
	
	$todatearr=jalali_to_gregorian($_POST['toyear'],$_POST['tomonth'],$_POST['today'],'/');
	$todate=$todatearr[0].'-'.$todatearr[1].'-'.$todatearr[2];
	$sql = $db->query("select * from transfers where tDate between '".$fromdate."' and '".$todate."' ORDER BY tDate DESC LIMIT $page, $limit");
	}else{
    $sql = $db->query("select * from transfers ORDER BY tDate DESC LIMIT $page, $limit");
	}
    if ($numrows == 0){
    echo("<center>موردی يافت نشد.</center>"); // bah, modify the "Not Found" error for your needs.
    }
    ?>
	<table class="listTable" dir="rtl" border="0">
		<tr align="center">
            <th>كد تراكنش</th>
            <th>کاربر</th>
            <th>شرح گردش حساب</th>
            <th>تاريخ</th>
            <th>مبلغ</th>
            <th>مانده حساب</th>
        </tr>
<?php
while($data=$db->fetchNextArray($sql)){
		if(($i % 2) == 0) {
			$class = 'tableRow2';
			$classOver = 'tableRowOver2';
		}else{
			$class = 'tableRow1';
			$classOver = 'tableRowOver';
		}
		$kind = '';
		if($data['tKind'] == 1){
			$kind = '+';
		}elseif($data['tKind'] == 2){
			$kind = '-';
		}
		echo '<tr class="'.$class.'" onmouseover="this.className=\''.$classOver.'\'" onmouseout="this.className=\''.$class.'\'">';
?>
    		<td><b> <?php echo Convertnumber2farsi($data['trans_id']); ?></b></td>
            <td/><?php $query=$db->query("select * from u_users where ID=".$data['user_id']."");
			$res = $db->fetchNextArray($query);
			echo $res['lastName']; ?></td>
        	<td><?php echo Convertnumber2farsi($data['tDescription']); ?></td>
        	<td><?php echo Convertnumber2farsi(tep_hejri3($data['tDate'])); ?></td>
        	<td><?php echo Convertnumber2farsi(number_format($data['tAmount'])).$kind; ?></td>
        	<td><?php echo Convertnumber2farsi(number_format($data['tRemain'])); ?></td>
<?php
	echo '</tr>';
	$i++;
	}
?>
	</table>
	<p align="center" style="margin-top:20px; color:#666;">
<?
	if ($page != 0) { // Don't show back link if current page is first page.
	$back_page = $page - $limit;
	echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\" class=\"pages\">قبلی</a>    \n");}
	
	for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
	{
	 $ppage = $limit*($i - 1);
	 if ($ppage == $page){
	 echo("<b class=\"pages_on\">".Convertnumber2farsi($i)."</b> \n");} // If current page don't give link, just text.
	 else{
	 echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\" class=\"pages\">".Convertnumber2farsi($i)."</a> \n");}
	}
	
	if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
	$next_page = $page + $limit;
	echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\" class=\"pages\">بعدی</a>\n");}
?>
	</p>

        </div>          
                                                </div>

                              </div>
                            </div>
                        </div>
               
                    </div>
                    <div class="clear"></div>
                </div><!-- dashboard-widgets-wrap -->
            </div><!-- wrap -->
			<div class="clear"></div></div><!-- wpbody-content -->
			<div class="clear"></div></div><!-- wpbody -->
			<div class="clear"></div></div><!-- wpcontent -->
        </div>
    </div><!-- wpcontent -->
</div><!-- wpwrap -->
<?php include("include/footer.php");?>
</div>
</div>
</body>
</html><?php } ?>