<?php
require_once ("../config.inc.php"); 
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");

$message	= "";

if (!$objDB) {
    $message	= "Unable to Locate Database Server.";
    exit;

} else {}

include_once('title.inc.php');

?>
<link href="../js/searchstyle.css" rel="stylesheet" type="text/css">
<link href="../js/newstyle.css" rel="stylesheet" type="text/css">

<script language='javascript' src='../fusionchart/JSClass/FusionCharts.js'></script>
 <script src="https://charts.iscripts.com/ChartJs/chart-min.js"></script> 

<script type="text/javascript">
    $(document).ready(function() {

    });

</script>

<?php include_once('tophtml.php');?>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72%" valign="top">
                        <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td height="10">&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td width="41%" class="headings1">Dashboard</td>
                                        </tr>
                                    </table>
                                    <div class="bordernew padding2">
                                        <div class="">
                                            <div class="box-pnl">
                                                <div class="bx-pnl-hd">Free Members in the last 7 days <a href="users.php"  style="float: right; color: #666;text-decoration: none">View all</a></div>
                                                <?php
//Start - Fusionchart Implementation - Free Members ----------------------------------------------------------------//
                                                    
                                                    # Add category names
                                                    $i    = 0;
                                                    $date = date('Y-n-j');
                                                    $time = time()+86400;
                                                    $date_n=array();
                                                    while($i<7)
                                                    {
                                                        $i++;
                                                        $time-= 86400;
                                                        //$date = date('Y-n-j', $time);
                                                        //$date = date('D', $time);
                                                        $date_n[] = date('M d', $time);

                                                       // $FD->addCategory($date);
                                                    }
                                                   
                                                    $catNames1 =   '"' . implode ( '", "', $date_n ) . '"';
                                                   //  print_r($catNames);echo "<br>"."<br>"."<br>"."<br>";
                                                    # Add a new dataset with dataset parameters
                                                   /// $FD->addDataset("Free Members");

                                                    $i    = 0;
                                                    $date = date('Y-n-j');
                                                    $time = time()+86400;
                                                    $free_members = array();
                                                    while($i<7)
                                                    {
                                                        $i++;
                                                        $time-= 86400;                     
                                                        $date_data = date('Y-m-d', $time);
                                                        
                                                        $sql = "SELECT
                                                                 COUNT(U.nUser_Id) AS free_members, U.nUser_Id, P.nPayment_Id
                                                                 FROM ".TABLEPREFIX."payments as P JOIN ".TABLEPREFIX."user as U ON P.nUser_Id = U.nUser_Id
                                                                 WHERE P.vTxn_Id LIKE 'FREE' AND P.vReason LIKE 'Profile Registration'
                                                                 AND DATE_FORMAT(U.dStartDate , '%Y-%m-%d') = '".$date_data."' ";
                                                        //echo $sql."<br>";

                                                       $res = mysql_query($sql);
                                                        if(mysql_num_rows($res)>0){
                                                           $row=mysql_fetch_array($res);
                                                           $free_members[] = $row['free_members'];
                                                           
                                                        }
                                                       
                                                              // $FD->addChartData($free_members);
                                                          
                                                    }
                                                    $freeMembs1 = implode(",",$free_members); 
                                                   // print_r($freeMembs);

                                                    /*
                                                    $FD->addDataset("Views","parentYaxis=S");
                                                    $FD->addChartData("23");
                                                    $FD->addChartData("34");
                                                    $FD->addChartData("45");
                                                    $FD->addChartData("45");
                                                    $FD->addChartData("34");
                                                    $FD->addChartData("45");
                                                    $FD->addChartData("45");
                                                    */

                                                    

                                                ?>
                                                <div id="">
                        
                                                      <canvas id='myChartd' ></canvas> 
                                               </div> 
                                            </div>

                                            <div class="box-pnl">
                                                <div class="bx-pnl-hd">Paid Members in the last 7 days <a href="users.php"  style="float: right; color: #666;text-decoration: none">View all</a></div>

                                                <?php
//Start - Fusionchart Implementation - Paid Members --------------------------------------------------------------//

                                                    # Add category names
                                                    $i    = 0;
                                                    $date = date('Y-n-j');
                                                    $time = time()+86400;
                                                    $date_n = array();
                                                    while($i<7)
                                                    {
                                                        $i++;
                                                        $time-= 86400;
                                                        //$date = date('Y-n-j', $time);
                                                        //$date = date('D', $time);
                                                        $date_n[] = date('M d', $time);

                                                       
                                                    }
                                                    $catNames =   '"' . implode ( '", "', $date_n ) . '"';
                                                 //  print_r($catNames);echo "<br>"."<br>"."<br>"."<br>";
                                                    # Add a new dataset with dataset parameters
                                                   

                                                    $i    = 0;
                                                    $date = date('Y-n-j');
                                                    $time = time()+86400;
                                                    $free_members1 = array();
                                                    while($i<7)
                                                    {
                                                        $i++;
                                                        $time-= 86400;
                                                        $date_data = date('Y-m-d', $time);

                                                        $sql = "SELECT
                                                                 COUNT(U.nUser_Id) AS free_members, U.nUser_Id, P.nPayment_Id
                                                                 FROM ".TABLEPREFIX."payments as P JOIN ".TABLEPREFIX."user as U ON P.nUser_Id = U.nUser_Id
                                                                 WHERE P.vTxn_Id != 'FREE'  AND P.vReason LIKE 'Profile Registration'
                                                                 AND DATE_FORMAT(U.dStartDate , '%Y-%m-%d') = '".$date_data."' ";
                                                        
                                                         //echo $sql."<br>";
                                                        $res = mysql_query($sql);
                                                        if(mysql_num_rows($res)>0){
                                                           $row=mysql_fetch_array($res);
                                                           $free_members1[] = $row['free_members'];
                                                           
                                                           
                                                        }
                                                        
                                                      
                                                       
                                                    
                                                    }
                                                 $freeMembs = implode(",",$free_members1); 
                                                  // print_r($freeMembs);
                                                    

//End - Fusionchart Implementation - Paid Members --------------------------------------------------------------//
                                                ?>
                                                <div id="">
                        
                                                      <canvas id='myChartu' ></canvas> 
                                               </div> 

                                            </div>



                                            <div class="box-pnl-dwn">
                                                <div class="bx-pnl-hd">Recent Registrations<a href="users.php"  style="float: right; color: #666;text-decoration: none">View all</a> </div>
                                                 <?php
                                                     $sql_latest_registration = "SELECT * FROM ".TABLEPREFIX."user WHERE vStatus LIKE 'A%' ORDER BY nUser_Id DESC LIMIT 0,10";
                                                     //$res_latest_registration = mysql_query($sql_latest_registration);
                                                     $res	= @mysql_query($sql_latest_registration);
                                                        if (@mysql_num_rows($res) > 0) {
                                                                while ($row = @mysql_fetch_array($res)) {
                                                                        $array1[]	= $row;
                                                                }
                                                        }
                                                        @mysql_free_result($res);

                                                        
                                                          
                                                    ?>
                                                <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="box-table-a">
                                                    
                                                    
                                               

                                                    <?php
                                                    if(count($array1)>0){
                                                    ?>
                                                <thead>
                                                     <tr align="left">
                                                   <th scope="col"><strong class="boldtext latest">Username</strong></th>

                                                    <th scope="col"><strong class="boldtext latest">Gender</strong></th>
                                                   <th scope="col"><strong class="boldtext latest">Created On</strong></th>
                                                    <th scope="col"><strong class="boldtext latest">Email</strong></th>
                                                    <th scope="col"><strong class="boldtext latest">Status</strong></th>
                                                     </tr>
                                                   </thead>
                                               
                                           
                                                     <?php
                                                     $i=0;
                                                     foreach ($array1 as $key => $value) {

                                                     $i++;
                                                     if($i%2==0)
                                                         {
                                                         $style='odd';
                                                         }
                                                     else{
                                                          $style='even';
                                                         }
                                                    ?>
                                                <tr align="left" >

                                                    
                                                    <td class="<?php echo $style ?>" width="15%"><a href="viewprofile.php?id=<?php echo $value['nUser_Id']?>"><?php echo htmlspecialchars(stripslashes($value['vLogin']))?></a></td>

                                                    <td class="<?php echo $style ?>" width="10%"><?php echo $value['vGender']?></td>
                                                    <td class="<?php echo $style ?>" width="14%"><?php echo date("m/d/Y",strtotime($value['dStartDate']))?></td>
                                                    <td class="<?php echo $style ?>" width="4%"><?php echo htmlspecialchars(stripslashes($value['vEmail']))?></td>
                                                    <td class="<?php echo $style ?>"width="10%"><?php if ($value['vStatus'] == "ANNN") echo "Active"; else if ($value['vStatus'] == "SNNN") echo "Suspended"; else if ($value['vStatus'] == "ENNN") echo "Expired";else echo "Inactive";?></td>
                                                    
                                                </tr>

                                                    <?php } } else{?>

                                                <tr><td colspan="5" align="center">No data found</td></tr>
                                                   <?php }?>

                                                </table>
                                            </div>
                                            <div class="box-pnl-dwn">
                                                <div class="bx-pnl-hd">Subscription Expired Users<a href="users.php?ddlProfile=expire"  style="float: right; color: #666;text-decoration: none">View all</a> </div>
                                                 <?php
                                                     $sql_expired_registration = "SELECT * FROM ".TABLEPREFIX."user WHERE vStatus  LIKE 'E%'  ORDER BY nUser_Id DESC LIMIT 0,10";
                                                     //$res_latest_registration = mysql_query($sql_latest_registration);
                                                     $res_expired	= @mysql_query($sql_expired_registration);
                                                        if (@mysql_num_rows($res_expired) > 0) {
                                                                while ($row = @mysql_fetch_array($res_expired)) {
                                                                        $array_ex[]	= $row;
                                                                }
                                                        }
                                                        @mysql_free_result($res_expired);

                                                        
                                                          
                                                    ?>
                                                <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="box-table-a">
                                                    
                                                    
                                               

                                                    <?php
                                                    if(count($array_ex)>0){
                                                    ?>
                                                <thead>
                                                     <tr align="left">
                                                   <th scope="col"><strong class="boldtext latest">Username</strong></th>

                                                    <th scope="col"><strong class="boldtext latest">Gender</strong></th>
                                                   <th scope="col"><strong class="boldtext latest">Created On</strong></th>
                                                    <th scope="col"><strong class="boldtext latest">Email</strong></th>
                                                    <th scope="col"><strong class="boldtext latest">Status</strong></th>
                                                     </tr>
                                                   </thead>
                                               
                                           
                                                     <?php
                                                     $i=0;
                                                     foreach ($array_ex as $key => $value) {

                                                     $i++;
                                                     if($i%2==0)
                                                         {
                                                         $style='odd';
                                                         }
                                                     else{
                                                          $style='even';
                                                         }
                                                    ?>
                                                <tr align="left" >

                                                    
                                                    <td class="<?php echo $style ?>" width="15%"><a href="viewprofile.php?id=<?php echo $value['nUser_Id']?>"><?php echo htmlspecialchars(stripslashes($value['vLogin']))?></a></td>

                                                    <td class="<?php echo $style ?>" width="10%"><?php echo $value['vGender']?></td>
                                                    <td class="<?php echo $style ?>" width="14%"><?php echo date("m/d/Y",strtotime($value['dStartDate']))?></td>
                                                    <td class="<?php echo $style ?>" width="4%"><?php echo htmlspecialchars(stripslashes($value['vEmail']))?></td>
                                                    <td class="<?php echo $style ?>"width="10%"><?php if ($value['vStatus'] == "ANNN") echo "Active"; else if ($value['vStatus'] == "SNNN") echo "Suspended"; else if ($value['vStatus'] == "ENNN") echo "Expired";else echo "Inactive";?></td>
                                                    
                                                </tr>

                                                    <?php } } else{?>

                                                <tr><td colspan="5" align="center">No data found</td></tr>
                                                   <?php }?>

                                                </table>
                                            </div>
                                            <!--<div class="box-pnl-dwn">
                                                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                    <tr>
                                                        <td colspan="2">&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                </table>
                                            </div>-->
                                            <div class="clear"></div>
                                        </div>
                                        <div class="clear"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<?php include_once('bottomhtml.php');?>

<script type="text/javascript">
    var ctx1 = document.getElementById('myChartd').getContext('2d');

var myChart = new Chart(ctx1, {
     type: 'line',
    data: {
        labels: [<?php echo $catNames1;?>],
        datasets: [{
           
            data: [<?php echo $freeMembs1;?>],
            label: "Free Members",
            lineTension: 0.3,
            fill: false,
            borderColor: '#007790',
            backgroundColor: 'transparent',
           // pointBorderColor: 'red',
            pointBackgroundColor: '#007790',
            pointRadius: 1,
            pointHoverRadius: 5,
            pointHitRadius: 8,
            pointBorderWidth: 2,
            pointStyle: 'circle',
           
            borderWidth: 1
        }]
    },
     options: {
        layout: {
            padding: {
                left: 20,
                right: 0,
                top: 30,
                bottom: 0
            }
        },
        legend: {

      display: false,
      position: 'bottom',
      labels: {
       
       usePointStyle: true,
           
      }
      },
        // tooltips: {
        //      mode: 'dataset'
        // },
         tooltips: {
      mode: 'index',
      intersect: false
   },
   hover: {
      mode: 'index',
      intersect: false
   },
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                },
                scaleLabel: {
        display: true,
        labelString: "Count",
        fontColor:'black'
      }
            }],
            xAxes: [{
                 scaleLabel: {
        display: true,
        labelString: 'Date',
        fontColor:'black'
      }

            }]
        }
    }
});


var ctx2 = document.getElementById('myChartu').getContext('2d');

var myChart = new Chart(ctx2, {
     type: 'line',
    data: {
        labels: [<?php echo $catNames1;?>],
        datasets: [{
           
            data: [<?php echo $freeMembs;?>],
             label: "Paid Members",
            lineTension: 0.3,
            fill: false,
            borderColor: '#007790',
            backgroundColor: 'transparent',
           // pointBorderColor: 'red',
            pointBackgroundColor: '#007790',
            pointRadius: 1,
            pointHoverRadius: 5,
            pointHitRadius: 8,
            pointBorderWidth: 2,
            pointStyle: 'circle',
           
            borderWidth: 1
        }]
    },
     options: {
        layout: {
            padding: {
                left: 20,
                right: 0,
                top: 30,
                bottom: 0
            }
        },
        legend: {
            
                display: false,
                    
        },
        // tooltips: {
        //      mode: 'dataset'
        // },
         tooltips: {
      mode: 'index',
      intersect: false
   },
   hover: {
      mode: 'index',
      intersect: false
   },
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                },
                scaleLabel: {
        display: true,
        labelString: "Count",
        fontColor:'black'
      }
            }],
            xAxes: [{
                 scaleLabel: {
        display: true,
        labelString: 'Date',
        fontColor:'black'
      }

            }]
        }
    }
});


</script>