<?php
ob_start(); 
?>
<html>
<head>
<title>Purchased</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function checkform ( form )
{ 
  if (form.to.value == "") {
    alert( "Please the Number." );
    form.to.focus();
    return false ;
  }
  if (form.to.value.length < 12) {
    alert( "Please enter 12 digits Number." );
    form.to.focus();
    return false ;
  }
  if (form.message.value.length > 160) {
    alert( "Message Should be 160 Characters" );
    form.message.focus();
    return false ;
  }
   if (form.message.value == "") {
    alert( "Please the Message." );
    form.message.focus();
    return false ;
  }
}
function startTime()
{
var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var today=new Date();
var d=today.getDate();
var y=today.getFullYear();
var k=today.getMonth();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);

document.getElementById('txtDATE').innerHTML="<font face='Tahoma' size='2' >"+d+" "+m_names[k]+" "+y+"</font>";
document.getElementById('txt').innerHTML="<font face='Tahoma' size='2' >"+h+":"+m+":"+s+"</font>";
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

function openwindow()
{
	window.open("streaming_advert.php","mywindow","menubar=0,resizable=0,width=600,height=600");
}
function openchatwindow()
{
	window.open("/chat/login.php","mychatwindow","menubar=0,resizable=0,width=600,height=620");
}
function openwindowadtel()
{
	window.open("http://www.ad-tel.com");
}
function mouseOut()
{
document.b1.src ="Image/Presenters1.bmp";
}
var backColor = new Array();
backColor[0] = '';
backColor[1] = '#CCFF99';
function changeBG(obj,whichColor){
obj.bgColor = backColor[whichColor];
}
function AlertValue(obj) {
$var=obj.options[obj.selectedIndex].value;
if ($var == "Selectedval"){
alert("Please Select your best Program")
exit();}
}
function getCode() (
alert("Code is");
}
//-->
</script>
</head>

<body onLoad="startTime()">

<div align="center"> 

  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="mpesa" method="post" onSubmit="return checkform(this);">

  <table bordercolor="#000000" class="bordertan" width="" >
  <tr> 
      <td width="462" valign="top"> 
<table class="bordertan" >
        <tr> 
		
              <td width="598"  valign="top" bordercolor="#000000" class="bordertan"> 
                <?php include("datacon.php"); 
Include("Ses.inc");?>
                <?php
if (!isset($_SESSION)) {
  session_start();
}
?>
                <?php require_once('./kassonline_conn.php'); ?>
                <?php
$currentPage = $_SERVER["PHP_SELF"];
//echo $currentPage;
$maxRows_rs_articles = 5000000;
$pageNum_rs_articles = 0;
if (isset($_GET['pageNum_rs_articles'])) {
  $pageNum_rs_articles = $_GET['pageNum_rs_articles'];
}
$startRow_rs_articles = $pageNum_rs_articles * $maxRows_rs_articles;

mysql_select_db($database_kassonline_conn, $kassonline_conn);
//SELECT * FROM prpurchased WHERE (((userid)='$MeUser'));
if ($Client!='ALL'){
$mpesaE=" and mpesanumber=$Client";
}
if ($Client=='ALL' && $Productid == 'ALL') {
$query_rs_articles = "SELECT mpesacode.*, operators.fname, operators.sname, operators.lname, operators.destinyh
FROM mpesacode LEFT JOIN operators ON mpesacode.mpesanumber = operators.Userid WHERE (((Left(mpesacode.mpesadate,10))>='$DateF' And (Left(mpesacode.mpesadate,10))<='$DateT')) ORDER BY mpesadate Asc";
}else{
$query_rs_articles = "SELECT mpesacode.*, operators.fname, operators.sname, operators.lname, operators.destinyh
FROM mpesacode LEFT JOIN operators ON mpesacode.mpesanumber = operators.Userid  WHERE (((Left(mpesacode.mpesadate,10))>='$DateF' And (Left(mpesacode.mpesadate,10))<='$DateT')) " . $mpesaE. " ORDER BY mpesadate Asc";
}
//echo $query_rs_articles;
//$query_limit_rs_articles = sprintf($query_rs_articles, $startRow_rs_articles, $maxRows_rs_articles);
$query_limit_rs_articles = sprintf('%s LIMIT %d, %d', $query_rs_articles, $startRow_rs_articles, $maxRows_rs_articles);
//echo $query_limit_rs_articles ;
$rs_articles = mysql_query($query_limit_rs_articles, $kassonline_conn) or die(mysql_error());
$row_rs_articles = mysql_fetch_assoc($rs_articles);

if (isset($_GET['totalRows_rs_articles'])) {
  $totalRows_rs_articles = $_GET['totalRows_rs_articles'];
} else {
  $all_rs_articles = mysql_query($query_rs_articles);
  $totalRows_rs_articles = mysql_num_rows($all_rs_articles);
}
$totalPages_rs_articles = ceil($totalRows_rs_articles/$maxRows_rs_articles)-1;

$queryString_rs_articles = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rs_articles") == false && 
        stristr($param, "totalRows_rs_articles") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rs_articles = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rs_articles = sprintf("&totalRows_rs_articles=%d%s", $totalRows_rs_articles, $queryString_rs_articles);
?>
                <table width="468"  border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="345" align="left" > <table width="103%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
		                  <td> <font size="2" face="Tahoma"><strong><?php echo "Mpesa Codes " . @$InboxNumero ; //<input type="submit" name="purprotduct" value="Add Purchase Product ID">?> </strong></font> 
                          <div align="right">  </div>						  </td>
                          <td align="right"><font size="2" face="Tahoma"><strong>Records 
                            <?php echo ($startRow_rs_articles + 1) ?> to <?php echo min($startRow_rs_articles + $maxRows_rs_articles, $totalRows_rs_articles) ?> 
                            of <?php echo $totalRows_rs_articles ?></strong></font></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td bgcolor="#CCFF99"> <table width="42%" border="0" align="right" >
        <tr> 
          <td width="22%" align="center"><font size="2" face="Tahoma"> 
            <?php if ($pageNum_rs_articles > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rs_articles=%d%s", $currentPage, 0, $queryString_rs_articles); ?>">First</a> 
            <?php }else{echo "First";} // Show if not first page ?>
            </font></td>
          <td width="24%" align="center"><font size="2" face="Tahoma"> 
            <?php if ($pageNum_rs_articles > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rs_articles=%d%s", $currentPage, max(0, $pageNum_rs_articles - 1), $queryString_rs_articles); ?>">Previous</a> 
            <?php }else{echo "Previous";} // Show if not first page ?>
            </font></td>
          <td width="23%" align="center"><font size="2" face="Tahoma"> 
            <?php if ($pageNum_rs_articles < $totalPages_rs_articles) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rs_articles=%d%s", $currentPage, min($totalPages_rs_articles, $pageNum_rs_articles + 1), $queryString_rs_articles); ?>">Next</a> 
            <?php }else{echo "Next";} // Show if not last page ?>
            </font></td>
          <td width="31%" align="center"><font size="2" face="Tahoma"> 
            <?php if ($pageNum_rs_articles < $totalPages_rs_articles) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rs_articles=%d%s", $currentPage, $totalPages_rs_articles, $queryString_rs_articles); ?>">Last</a> 
            <?php }else{echo "Last";} // Show if not last page ?>
            </font></td>
        </tr>
      </table></td>
  </tr>
</table>

                <table width="90%"  bgcolor="#CCFF99" border="0" cellpadding="0" cellspacing="0">
                  <tr> <td> 
				  <table width="473">
				  <tr bgcolor="#00FF00"> 
				   <td height="35" ><strong><font size="2" face="Tahoma">No.</font></strong></td>
				          <td height="35" ><strong><font size="2" face="Tahoma">Code</font></strong></td>

                          <td height="35" ><strong><font size="2" face="Tahoma">Amount</font></strong></td>
                          <td width="65" height="35" ><strong><font size="2" face="Tahoma">Date 
                      </font></strong></td>
					  <td width="65" height="35" ><strong><font size="2" face="Tahoma">Time 
                      </font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Number</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Type</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Active</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Name</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Destiny Helper</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">County</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Town</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Gender</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Register Under</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Issue Code2</font></strong></td>
					  <td height="35" ><strong><font size="2" face="Tahoma">Issue Code1</font></strong></td>
                  </tr>
                  <?php 
				  $Cr2=1;
				  do { 
				  $myColor="bgcolor='#FFFFFF'";
				  if ($row_rs_articles['mpesaact'] == 0){$myColor="bgcolor='#FF0000'";}
				  ?>
				  
                  <tr > <?php
				  //$fname=$row_rs_articles['Number'];
				  //$Sql="Select * from phonebook where Number='$fname' and owner='$MeUser'";
					//$result = mysql_query($Sql); 
					//$myrow = mysql_fetch_array($result); 
					//$DDn=$myrow["Username"];
					//$Cred2=$myrow["fullnames"];
							?>
							
                <td width="90" <?php echo $myColor; ?> ><font size="2" face="Tahoma"><?php echo $Cr2++; ?>	</font></td>
                <td width="90" onClick="getCode()" <?php echo $myColor; ?>> <font size="2" face="Tahoma"><?php echo $row_rs_articles['mpesacode']; ?></font></td>
                <td <?php echo $myColor; ?> ><font size="2" face="Tahoma"><?php echo $row_rs_articles['mpesaamt']; ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo substr($row_rs_articles['mpesadate'],0,-9); ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo substr($row_rs_articles['mpesadate'],11,19); ?></font></td>
                <td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $row_rs_articles['mpesanumber']; ?></font></td>
				
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $row_rs_articles['mpesatype']; ?></font></td>
				<td <?php echo $myColor; ?>>
				<?php 
				if ($row_rs_articles['mpesaact'] == 1) {$mpesaact="Active"; $Mesaage="Deactivate";}else{$mpesaact="Deactive";$Mesaage="Activate";} 
				?>
				<font size=2 face='tahoma'>    <font size="2" face="Tahoma"><?php 
				echo $mpesaact; ?></font>                             </font>				</td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $row_rs_articles['fname'] . "_" . $row_rs_articles['sname'] . "_" . $row_rs_articles['lname']; ?></font></td>
				<?php
				$result = mysql_query("SELECT county,utown,gender,register1 FROM operators WHERE Userid='" . $row_rs_articles['mpesanumber']. "'",$db); 
				
					$result2 = mysql_fetch_array($result)
					 
						  
					
				?>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $row_rs_articles['destinyh']; ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $result2['county']; ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $result2['utown']; ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $result2['gender']; ?></font></td>
				<td <?php echo $myColor; ?>><font size="2" face="Tahoma"><?php echo $result2['register1']; ?></font></td>
				
				<?php include("datacon.php");
					$result = mysql_query("SELECT pridgenerated FROM productidgen WHERE mpesac='" . $row_rs_articles['mpesacode']. "'",$db); 
				
					while ($result1 = mysql_fetch_array($result)) 
					{ 
						echo "<td bgcolor='#FFFFFF'><font size='2' face='Tahoma'>". $result1["pridgenerated"] ."</font></td>";  ;  
					} 
					
				?>
                  </tr>
                  <?php } while ($row_rs_articles = mysql_fetch_assoc($rs_articles)); ?>
                </table>
				</table></td></tr></table>

<?php
mysql_free_result($rs_articles);
?>              </td>
        </tr>
      </table>
      <div align="center"> </div></td>
  </tr>
</table>
</form>
</div>
<?php
include("datacon.php");
	$CurrDate=date("d/M/Y");
	$CurrTime=strftime("%X",time());
	$Progname="mpesaact.php";
	$ActDesc="Mpesa List";
	$AUD_Reff="Listing Mpesa Code";
	$comp=$_SERVER['REMOTE_ADDR'];
	$Printe="0";
	$sql = "INSERT INTO audit_logs (AUD_Date, AUD_Time, AUD_Prog_Name,AUD_Act_Desc,AUD_Reff,AUD_UserID,AUD_Print, AUD_Comp) VALUES ('$CurrDate','$CurrTime','$Progname','$ActDesc','$AUD_Reff','$MeUser','$Printe','$comp')";
	$result = mysql_query($sql);
?>

</body>
</html>
