<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<?php  
if($_SESSION['role']!=1){ 
exit("You dont have permisiion to access this page ");}
?>
 <div>
    <ul class="breadcrumb">
        <li>
            <a href="index.php">Home</a>
        </li>
        <li>
            <a href="index.php?page=reports"> Add Services</a>
        </li>
    </ul>
</div>

<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class=" glyphicon glyphicon-th-list"></i> Subscribers Reports</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-setting btn-round btn-default"><i
                                class="glyphicon glyphicon-cog"></i></a>
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                
                <br />
 
                       
                       
                       
                       
                       
                       
                       
                       
                       
                      
                  <fieldset>
<legend>Search</legend>
                       
                       
                       <form method="post"  class="login_form"  action="index.php?page=reportsViews1">
<input type="hidden" name="optsearch" value="1" />
 <?php /*?>
<div class="form-group">
<div class="row ">
<div class="col-md-2">Name</div>
<div class="col-md-4"><input type="text" name="ServicesOperator_nameSearch" id="ServicesOperator_nameSearch" class="form-control" placeholder="ServicesOperator_name" value="<?php echo($_REQUEST['ServicesOperator_nameSearch']); ?>" /></div>
 
<div class="col-md-2">operator</div>
<div class="col-md-4">

<select name="ServicesOperator_operatorID" class="form-control" data-rel="chosen">
<option value="0">select operator</option>
<?php $seloperator=mysqli_query($connect,"select * from operator");

while($rowProv=mysqli_fetch_array($seloperator)){
	?>
	<option value="<?php echo($rowProv['Operator_id']); ?>"
    <?php  if($_REQUEST['ServicesOperator_operatorID']==$rowProv['Operator_id']){?> selected<?php } ?>
    ><?php echo($rowProv['Operator_name']); ?></option>
	<?php
	
	}
 ?>
</select>


 
</div>
</div>
</div>
 

<div class="form-group">
<div class="row ">
<div class="col-md-2">Services </div>
<div class="col-md-4"> 

<select name="ServicesOperator_servicesID" class="form-control" data-rel="chosen">
<option value="0">select Services</option>
<?php $seloperator=mysqli_query($connect,"select * from services");


while($rowProv=mysqli_fetch_array($seloperator)){
	?>
	<option value="<?php echo($rowProv['Services_id']); ?>" <?php if($_REQUEST['ServicesOperator_servicesID']==$rowProv['Services_id']){?> selected<?php } ?>><?php echo($rowProv['Services_name']); ?></option>
	<?php
	
	}
 ?>
</select>


</div>
 
<div class="col-md-2">Affiliates </div>
<div class="col-md-4"> 
<select name="affiliates_id" id="affiliates_id" class="form-control" data-rel="chosen">
<option value="0">Select Affiliates</option>
<?php $selaffiliatesr=mysqli_query($connect,"select * from affiliates");


while($rowProv=mysqli_fetch_array($selaffiliatesr)){
	?>
	<option value="<?php echo($rowProv['affiliates_id']); ?>" <?php if($_REQUEST['id']==$rowProv['affiliates_id']){?> selected<?php } ?>><?php echo($rowProv['affiliates_name']); ?></option>
	<?php
	
	}
 ?>
</select>


</div>
</div>
</div>
<?php */?>



<div class="form-group">
<div class="row ">
<div class="col-md-2">Landing Page </div>
<div class="col-md-4"> 
<select name="landingPage_id" id="landingPage_id" class="form-control" data-rel="chosen">
<option value="0">Select Landing page</option>
<?php $selaffiliatesr=mysqli_query($connect," select * from landingpage");


while($rowProv=mysqli_fetch_array($selaffiliatesr)){
	?>
	<option value="<?php echo($rowProv['landingPage_id']); ?>" <?php if($_REQUEST['landingPage_id']==$rowProv['landingPage_id']){?> selected<?php } ?>><?php echo($rowProv['landingPage_name']); ?></option>
	<?php
	
	}
 ?>
</select>


</div>






<div class="col-md-2">Device  </div>
<div class="col-md-4"> 
<select name="deviceType" id="deviceType" class="form-control" data-rel="chosen">
<option value="0">All</option>
 <option value="desktop" <?php if($_REQUEST['deviceType']=='desktop'){ ?> selected<?php  } ?>>desktop</option>
 <option value="Mobile" <?php if($_REQUEST['deviceType']=='Mobile'){ ?> selected<?php  } ?>>Mobile</option>
 <option value="Tablet" <?php if($_REQUEST['deviceType']=='Tablet'){ ?> selected<?php  } ?>>Tablet</option>
 <option value="ios" <?php if($_REQUEST['deviceType']=='ios'){ ?> selected<?php  } ?>>ios</option>
  <option value="android" <?php if($_REQUEST['deviceType']=='android'){ ?> selected<?php  } ?>>android</option>
 
 
</select>


</div>









</div>
</div>



<div class="form-group">
<div class="row ">
<div class="col-md-2">Group by</div>
<div class="col-md-4"><select name="groupBy" id="groupBy" class="form-control" data-rel="chosen">
 
 <option value="Hour" <?php if($_REQUEST['groupBy']=='Hour'){ ?> selected<?php  } ?>>Hour</option>
 <option value="date" <?php if($_REQUEST['groupBy']=='date'){ ?> selected<?php  } ?>>Day</option>
 <option value="week" <?php if($_REQUEST['groupBy']=='week'){ ?> selected<?php  } ?>>week</option>
  <option value="month" <?php if($_REQUEST['groupBy']=='month'){ ?> selected<?php  } ?>>month</option>
 <option value="year" <?php if($_REQUEST['groupBy']=='year'){ ?> selected<?php  } ?>>year</option>
 
 
 
 
 
 
</select>



</div>
  
</div>
</div>




<div class="form-group">
<div class="row ">
<div class="col-md-2">from</div>
<div class="col-md-4"><input type="date" name="fromd" id="fromd" class="form-control" placeholder="From Date" value="<?php echo($_REQUEST['fromd']); ?>" /></div>
 
<div class="col-md-2">To</div>
<div class="col-md-4"><input type="date" name="tod" id="tod" class="form-control" placeholder="To Date" value="<?php echo($_REQUEST['tod']); ?>" /></div>
</div>
</div>

 



<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="update_Services" value="Search" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>
                       
                       
                       
                       
                      
            </fieldset>           
                       
                       
                       
                       
                       
                       
                       
                     <?php if($_REQUEST['optsearch']==1){ ?>  
                       
                       
                       <div class="row">
                       <div class="col-md-12">
                     <?php  
					 $query_Services="";
					 
if($_REQUEST['fromd']!='' && $_REQUEST['tod']!=''){
$query_Services=$query_Services." and date(affil_landingLogs_date) between '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'";
	 
	}else{
		
$query_Services=$query_Services." and affil_landingLogs_date > date_sub(now(),interval 24 hour)
 	";	
		}
/*
if($_REQUEST['ServicesOperator_operatorID']!=0){
$query_Services=$query_Services." and Operator_id='".$_REQUEST['ServicesOperator_operatorID']."'";
	 
	}
	if($_REQUEST['ServicesOperator_servicesID']!=0){
$query_Services=$query_Services." and ServicesOperator_servicesID='".$_REQUEST['ServicesOperator_servicesID']."'";
	 
	}
if($_REQUEST['ServicesOperator_nameSearch']!=''){
	$query_Services=$query_Services." and ServicesOperator_name like '%".$_REQUEST['ServicesOperator_nameSearch']."%'";
	 
	}
	if($_REQUEST['affiliates_id']!=0){
	$query_Services=$query_Services." and affiliates_id = '".$_REQUEST['affiliates_id']."'";
	 
	}
	*/
	 if($_REQUEST['deviceType']!='0'){
	$query_Services=$query_Services." and affil_landingLogs_device  like  '%".$_REQUEST['deviceType']."%'";
	 
	}
	
	
	
	
	$groupby ="  DATE(  `affil_landingLogs_date` ) , HOUR(  `affil_landingLogs_date` )  ";
	$orderby ="  order by DATE(  `affil_landingLogs_date` ) asc,   HOUR(  `affil_landingLogs_date` ) asc   ";
	
 
	 if($_REQUEST['groupBy']!='Hour'){
	$groupby =" ".$_REQUEST['groupBy']."(  `affil_landingLogs_date` ) ";
	$orderby =" order by   ".$_REQUEST['groupBy']."(  `affil_landingLogs_date` )  asc ";
	 }
	
	 
	
	
	
					 
					 ?>
<div id="container"></div>
 <script> 







Highcharts.chart('container', {
    chart: {
        type: 'line'
    },
    title: {
        text: 'Views per Affiliates in last 24 Hour'
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        categories: [
		
		
		
		
		
		
		
		
		
		<?php  $selectLandingAffilatesViews=mysqli_query($connect,"SELECT COUNT( * ) c , ".$groupby." hourCoun
		 
		
		
FROM  `affil_landinglogs` 
where   affil_landingLogs_landingID='".$_REQUEST['landingPage_id']."'
  ".$query_Services."
GROUP BY ".$groupby."

".$orderby."  ");
 

$numaffiltesview=mysqli_num_rows($selectLandingAffilatesViews);
$xv=0;
while($rowAffilatesv=mysqli_fetch_array($selectLandingAffilatesViews)){

$xv++;
		
		
		
	?>'<?php echo($rowAffilatesv['hourCoun']); ?>'<?php if($numaffiltesview!=$xv){ ?>
	,  
	
	<?php } } ?>  
		
		
		
		
		
		
		
		
		
		
		
		]
    },
    yAxis: {
        title: {
            text: 'Views Count'
        }
    },
    plotOptions: {
        line: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: true
        }
    },
    series: [
	
	
	
	
	
	<?php  $selectLandingAffilates=mysqli_query($connect,"SELECT affiliates.*,landingPage_id,affiliates_landing_id FROM `landingpage`     
inner join affiliates_landing on `affiliates_landing_landingId`=landingPage_id
inner join affiliates on `affiliates_id`=`affiliates_landing_affID`
where `landingPage_id`='".$_REQUEST['landingPage_id']."'
   ");
  
$numaffiltes=mysqli_num_rows($selectLandingAffilates);
$x=0;
while($rowAffilates=mysqli_fetch_array($selectLandingAffilates)){

$x++;
?>{
        name: '<?php echo($rowAffilates['affiliates_name']); ?>',
        data: [
		
		
		
		
		<?php  $selectLandingAffilatesViews=mysqli_query($connect,"SELECT COUNT( * ) c , ".$groupby." 
		
FROM  `affil_landinglogs` 
where   affil_landingLogs_landingID='".$rowAffilates['landingPage_id']."'
 and affil_landingLogs_affLandID='".$rowAffilates['affiliates_landing_id']."'
 
   ".$query_Services."
GROUP BY ".$groupby."

".$orderby." ");

$numaffiltesview=mysqli_num_rows($selectLandingAffilatesViews);
$xv=0;
while($rowAffilatesv=mysqli_fetch_array($selectLandingAffilatesViews)){

$xv++;
		
		echo($rowAffilatesv['c']);
		
	?><?php if($numaffiltesview!=$xv){ ?>
	,  
	
	<?php } } ?>  
		
		
		
		]
    }
	<?php if($numaffiltes!=$x){ ?>
	,  
	
	<?php } } ?>
	
	
	
	
	
	
	
	
	
	
	
	
	
	]
});


</script> 
                 
                  </div></div>
                  
                  
                  
                  <?php  } ?>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
               <?php /*?>   SELECT COUNT( * ) total, COUNT( 
CASE WHEN  `hadaraAPILogs` =0
THEN 1 
END ) sucess, COUNT( 
CASE WHEN  `hadaraAPILogs` = -1
THEN 1 
END ) faild, COUNT( 
CASE WHEN  `hadaraAPILogs` =11
THEN 1 
END ) wrongcode, COUNT( 
CASE WHEN  `hadaraAPILogs` IS NULL 
THEN 1 
END ) nextStep, DATE( SubscribersLogs_date ) 
FROM  `SubscribersLogs` 
WHERE  `SubscribersLogs_date` > DATE_SUB( NOW( ) , INTERVAL 24 HOUR ) 
GROUP BY DATE( SubscribersLogs_date ) 
LIMIT 0 , 30
                  <?php */?>
                       
                     <?php if($_REQUEST['optsearch']==1){ ?>  
                       
                       
                       <div class="row">
                       <div class="col-md-12">
                     <?php  
					 $query_Services="";
					 
if($_REQUEST['fromd']!='' && $_REQUEST['tod']!=''){
$query_Services=$query_Services." and date(SubscribersLogs_date) between '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'";
	 
	}else{
		
$query_Services=$query_Services." and SubscribersLogs_date > date_sub(now(),interval 24 hour)
 	";	
		}
  
	
	
	
	
	$groupby ="  DATE(  `SubscribersLogs_date` ) , HOUR(  `SubscribersLogs_date` )  ";
	$orderby ="  order by DATE(  `SubscribersLogs_date` ) asc,   HOUR(  `SubscribersLogs_date` ) asc   ";
	
 
	 if($_REQUEST['groupBy']!='Hour'){
	$groupby =" ".$_REQUEST['groupBy']."(  `SubscribersLogs_date` ) ";
	$orderby =" order by   ".$_REQUEST['groupBy']."(  `SubscribersLogs_date` )  asc ";
	 }
	
	 
	
	
	
					 
					 ?>
                     
                      
<div id="containerSubs"></div>
 <script> 







Highcharts.chart('containerSubs', {
    chart: {
        type: 'line'
    },
    title: {
        text: 'Subscribers Count '
    },
    subtitle: {
        text: ''
    },
    xAxis: {
        categories: [
		
		
		
		
		
		
		
		
		
		<?php  $selectLandingAffilatesViews=mysqli_query($connect,"
		
		
		SELECT COUNT( * ) total, COUNT( 
CASE WHEN  `hadaraAPILogs` =0
THEN 1 
END ) sucess, COUNT( 
CASE WHEN  `hadaraAPILogs` = -1
THEN 1 
END ) faild, COUNT( 
CASE WHEN  `hadaraAPILogs` =11
THEN 1 
END ) wrongcode, COUNT( 
CASE WHEN  `hadaraAPILogs` IS NULL 
THEN 1 
END ) nextStep, ".$groupby." hourCoun
FROM  `SubscribersLogs` 
WHERE    SubscribersLogs_landingid='".$_REQUEST['landingPage_id']."'
  ".$query_Services."
GROUP BY ".$groupby."

".$orderby." 

		  ");
 
 
 
 

$numaffiltesview=mysqli_num_rows($selectLandingAffilatesViews);
$xv=0;
while($rowAffilatesv=mysqli_fetch_array($selectLandingAffilatesViews)){

$xv++;
		
		
		
	?>'<?php echo($rowAffilatesv['hourCoun']); ?>'<?php if($numaffiltesview!=$xv){ ?>
	,  
	
	<?php } } ?>  
		
		
		
		
		
		
		
		
		
		
		
		]
    },
    yAxis: {
        title: {
            text: 'Views Count'
        }
    },
    plotOptions: {
        line: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: true
        }
    },
    series: [
	
	
	
	
	
	<?php $arrayTitle=array("Total", "succsses", "Faild", "Wrong Code" ,"next step Empty ");
$arrayTitleCase=array("*", "CASE WHEN  hadaraAPILogs=0 THEN 1 END ", "CASE WHEN  hadaraAPILogs=-1 THEN 1 END",
 "CASE WHEN  hadaraAPILogs=11 THEN 1 END" ,"CASE WHEN  hadaraAPILogs is null THEN 1 END ");


for($i=0;$i<sizeof($arrayTitle);$i++){
 
?>{
        name: '<?php echo($arrayTitle[$i]); ?>',
        data: [
		
		
		
		
		<?php  $selectLandingAffilatesViews=mysqli_query($connect,"
		
		
		
		SELECT  count(".$arrayTitleCase[$i].") c ,".$groupby." hourCoun
FROM  `SubscribersLogs` 
WHERE    SubscribersLogs_landingid='".$_REQUEST['landingPage_id']."' 
   ".$query_Services."
GROUP BY ".$groupby."

".$orderby."
		
  ");

$numaffiltesview=mysqli_num_rows($selectLandingAffilatesViews);
$xv=0;
while($rowAffilatesv=mysqli_fetch_array($selectLandingAffilatesViews)){

$xv++;
		
		echo($rowAffilatesv['c']);
		
	?><?php if($numaffiltesview!=$xv){ ?>
	,  
	
	<?php } } ?>  
		
		
		
		]
    }
	<?php if($numaffiltes!=$xv){ ?>
	,  
	
	<?php } } ?>
	
	
	
	
	
	
	
	
	
	
	
	
	
	]
});


</script> 
                 
                  </div></div>
                  
                  
                  
                  <?php  } ?>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                   
                </div>
            </div>
        </div>
