<?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");
$page = $_GET['page'];
$limit = $_GET['limit'];
if (!($limit)){
$limit =45;} // 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 settle WHERE payer_id != 0 && date_now between '".$fromdate."' and '".$todate."'");
	}else{
$numresults = $db->query("select * from settle WHERE payer_id != 0");
}// 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.
?>
<!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>
<?php include("maintemplate/mainheader.php");?>
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine-fa.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript"></script>
<script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.1.js"></script>
<script type="text/javascript" src="js/lang.js"></script>
<link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" />
</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;" id="wpbody-content">
        <div id="screen-meta">
            <div class="wrap">
                <div id="icon-index" class="icon32"><br></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="epay.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:100%;">
                            <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>
<table class="listTable" dir="rtl" style="border:1px solid #069; border-collapse:collapse; margin-top:30px;width:99%" cellspacing="3" border="1">
  <thead>
			<tr>
				<th  align="center"> كد </th>
				<th  align="center"> نام کاربری </th>
				<th  align="center"> نام و نام خانوادگی </th>
				<th  align="center"> نام بانک </th>
				<th  align="center"> روش پرداخت </th>
				<th  align="center"> پول پرداخت شده </th>
				<th  align="center" dir="rtl"> شماره فيش (batch_number) </th>
				<th  align="center"> تاریخ ثبت</th>
				<th  align="center"> تاریخ پرداخت</th>
				<th  align="center"> امکانات </th>
			</tr>
		</thead>
		<tbody>
<?php
if ($_GET['dell']==1){		 
	$dellscid="delete from  settle where settle_id='".$_GET['settle_id']."'";
	$query1= $db->query($dellscid);
    echo debug_message('حذف با موفقیت انجام شد ...','2','');
	echo '<form action="epay.php" method="post">
               <p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';		   
}
//-------------------------------------
//-------------------------------------
		
if ($_GET['edit']==1){		 
	
	$sql="update settle set
	state='2'
	where settle_id='".$_GET['settle_id']."'";
    $query= $db->query($sql);
	
	$sql="update credit set
	amount = amount+".(int)$_POST['cost']."
	where user_id='".$_POST['payer_id']."'";
    $query= $db->query($sql);
			$remain = get_credit_amount($_POST['payer_id']);
			$db->execute("INSERT INTO transfers SET user_id = '".(int)$_POST['payer_id']."',
															tDescription = 'خريد اعتبار',
															tDate = now(),
															tAmount = '".(int)$_POST['cost']."',
															tRemain = '".$remain."',
															tKind = '1'");

    echo debug_message('پرداخت با موفقیت تایید شد  ...','2','');
	//selecct the user
				$euser=$db->query("select * from u_users where ID ='".(int)$_POST['payer_id']."'");
 				$user=$db->fetchNextArray($euser);
				
				sendSms(returnConfig('linkSms'),returnConfig('userNameSms'),returnConfig('passSms'),'مبلغ پرداختی شما در حساب کاربری شما ثبت شد',$user['mobile']);
				
	echo '<form action="epay.php" method="post">
               <p align="center"><input type="submit" id="button" value="OK"></p>
		</form>';		   
}
$i = $numrows-$page;
 		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 settle WHERE payer_id != 0 && date_now between '".$fromdate."' and '".$todate."' ORDER BY settle_id desc  LIMIT $page, $limit");		
			}else{
		$sql =$db->query("select * from settle WHERE payer_id != 0 ORDER BY settle_id desc  LIMIT $page, $limit");
		}
		while($result = $db->fetchNextArray($sql)){
         if($result['state']=='2') {$type_taead= '<img src="images/ok.gif" alt="تایید شده" title="تایید شده">';}
		 else{$type_taead= '
		              <form action="epay.php?edit=1&settle_id='.$result['settle_id'].'" method="post">
						<input type="hidden" name="payer_id" value='.$result['payer_id'].'>
						<input type="hidden" name="cost" value='.$result['amount'].'>
						<input type="hidden" name="settle_id" value='.$result['settle_id'].'>
						<input type="submit" value="" style="background-image: url(images/no_ok.gif);border:0;width:20px; height:20px" title="تایید نشده" alt="برای تایید کلیک کنید">
				      </form>';} 
         if ($result['settle_kind']== 1){$type_epay= 'پرداخت آنلاین';} elseif($result['settle_kind']== 2) {$type_epay= 'پرداخت دستی';}
         if ($result['bank_id']=='SB'){$type_bk= 'بانک سامان';}
		 elseif ($result['bank_id']=='SIBA'){$type_bk= 'بانک ملی';}
		 elseif ($result['bank_id']=='MELLAT'){$type_bk= 'بانک ملت';}
		 elseif ($result['bank_id']=='mellat'){$type_bk= 'بانک ملت';}
		 elseif ($result['bank_id']=='SAMAN'){$type_bk= 'بانک سامان';}
		 elseif ($result['bank_id']=='ENBANK'){$type_bk= 'بانک اقتصاد نوین';}
		 elseif ($result['bank_id']=='PASARGAD'){$type_bk= 'بانک پاسارگاد';}
		 elseif ($result['bank_id']=='SADERAT'){$type_bk= 'بانک صادرات';}
		 elseif ($result['bank_id']=='TEJARAT'){$type_bk= 'بانک تجارت';}
		 elseif ($result['bank_id']=='PARSIAN'){$type_bk= 'بانک پارسیان';}
		 elseif ($result['bank_id']=='SINA'){$type_bk= 'بانک سینا';}
		if($result['visited'] == 0){
			$sytle = 'style="color:#390"';
		}else{
			$style = '';
		}
		if(($i % 2) == 0) {
			$class = 'tableRow2';
			$classOver='tableRowOver2';
		}else{
			$class = 'tableRow1';
			$classOver='tableRowOver';
		}
		 $time = explode(' ',$result['date_now']);
		echo '<tr   class="'.$class.'" onmouseover="this.className=\''.$classOver.'\'" onmouseout="this.className=\''.$class.'\'" >';
		echo   '<td  align="center" > pishsakhteh-'.$result['settle_id'].'</td>
				<td  align="center" > '.get_user_name($result['payer_id']).'</td>
				<td  align="center" > '.get_user_name_lastname($result['payer_id']).'</td>
				<td  align="center" >'.$type_bk.'</td>
				<td  align="center" >'.$type_epay.'</td>
				<td  align="center" >'.number_format($result['amount']).'</td>
				<td  align="center" >'.$result['acc_num'].'</td>
				<td  align="center" >'.tep_hejri1($result['date_now']).'<br/>'.$time[1].'</td>
				<td  align="center" >'.$result['pay_year'].'/'.$result['pay_month'].'/'.$result['pay_day'].'</td>
				<td  align="center" >
				
					<table>
					<tr>  
                      <td>'.$type_taead.'</td>					  
					  <td>					  
					  <form action="epay.php?dell=1&settle_id='.$result['settle_id'].'" method="POST">
						<input type="hidden" name="settle_id" value='.$result['settle_id'].'>
						<input type="submit" value="" style="background-image: url(images/dell_2.gif);border:0;width:20px; height:20px" title="&#1581;&#1584;&#1601;">
				      </form>
					  </td>
					</tr>
				   </table>						  				
				</td>
			</tr>';
			$i--;
		}
?>    		
		</tbody>
  </table>
<p align="center">
<?php
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a style=\"text-decoration:none;color:#F30\"   href=\"$PHP_SELF?page=$back_page&limit=$limit\" class=\"pages\">back</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 style=\"text-decoration:none;color:#F30\"  class=\"pages_on\">".Convertnumber2farsi($i)."</b> \n");} // If current page don't give link, just text.
 else{
 echo("<a style=\"text-decoration:none;color:#F30\"  href=\"$PHP_SELF?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  style=\"text-decoration:none;color:#F30\"  href=\"$PHP_SELF?page=$next_page&limit=$limit\" class=\"pages\">next</a>\n");}

echo '</p>';
?>
                            </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
$db->execute("UPDATE settle SET visited = '1' WHERE visited = '0' AND payer_id != 0");} ?>