<?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=reportsStatistic"> 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=publisher">
<input type="hidden" name="optsearch" value="1" />
 
 
 

<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">af </div>
<div class="col-md-4"> 
<select name="affiliates_id" id="affiliates_id" class="form-control" data-rel="chosen">
<option value="0">Select af</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['affiliates_id']==$rowProv['affiliates_id']){?> selected<?php } ?>><?php echo($rowProv['affiliates_name']); ?></option>
	<?php
	
	}
 ?>
</select>


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




<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>
</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 && $_REQUEST['fromd']!='' && $_REQUEST['tod']!='' 
					   && $_REQUEST['affiliates_id']!=0  && $_REQUEST['landingPage_id']!=0){ ?>
                       
                       <div class="row">
                       <div class="col-md-12">
                     

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr style="header">
                             <td  >#</td>
                             <td >Publisher ID </td>
                             <td  >Count</td>
                             <td  >Leads</td>
                             <td  >Subscriber</td>
                             <td  >Percent</td>
                           </tr>
                           <?php  
						   
						
			 
			 $query_Services="SELECT count(*) count,

 `affil_landingLogs_pubid`




FROM `affil_landinglogs`    
 
where affil_landingLogs_affLandID



" ;
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 affil_landingLogs_affid = '".$_REQUEST['affiliates_id']."'";
	 
	//}
	//if($_REQUEST['landingPage_id']!=0){
	$query_Services=$query_Services." and affil_landingLogs_landingID = '".$_REQUEST['landingPage_id']."'";
	 
//	}
 	 
		 
		 
//if($_REQUEST['fromd']!='' && $_REQUEST['tod']!=''){
$query_Services=$query_Services." and date(affil_landingLogs_date) between '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'";
 
	 
//	}


//echo($query_Services);
		 
		 
			 $Services_res=mysqli_query($connect,$query_Services ."   group by `affil_landingLogs_pubid` order by 1 desc ");
			
			 if($Services_res){ $x=0;
			 
			 
			 
			 $count=0;
			 $leads=0;
			 $subs=0;
			 
				 while($row=mysqli_fetch_assoc($Services_res))
				 {
				$x++;
				
				
				
				
				
				
			 $selectSubsciberslogs=mysqli_query($connect,"SELECT count(distinct(SubscribersLogs_phone)) c FROM `SubscribersLogs` WHERE
			   `SubscribersLogs_pubid`='".$row['affil_landingLogs_pubid']."'
and date(SubscribersLogs_date)  between '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'
and `SubscribersLogs_affi`= '".$_REQUEST['affiliates_id']."'
and `SubscribersLogs_landingid`='".$_REQUEST['landingPage_id']."'

");
			 $rosublogs=mysqli_fetch_array($selectSubsciberslogs);
				
				
				
			 $selectSubscibers=mysqli_query($connect,"SELECT count(*) c FROM `Subscribers` WHERE
			   `Subscribers_pubid`='".$row['affil_landingLogs_pubid']."'
and date(Subscribers_date)  between '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'
and `Subscribers_affi`= '".$_REQUEST['affiliates_id']."'
and `Subscribers_landingid`='".$_REQUEST['landingPage_id']."'

");
			 $rosub=mysqli_fetch_array($selectSubscibers);
				
			  ?>
						
                           <tr>
                             <td><?php echo($x);?></td>
                             <td><?php echo($row['affil_landingLogs_pubid']); ?></td>
                          <td><?php echo($row['count']);  $count+= $row['count'];  ?></td>
                           <td><?php echo($rosublogs['c']);  $leads+= $rosublogs['c'];?></td>
                          <td><?php echo($rosub['c']);  $subs+= $rosub['c'];?></td>
                          <td><?php   
						  
						  echo(round($rosub['c']/$row['count'],6));
						  ?></td>
                           </tr>
                          
                           
                           
                           <?php  } ?> <tr  >
                             <td>&nbsp;</td>
                             <td>Total</td>
                             <td><?php  echo($count);?></td>
                             <td><?php  echo($leads);?></td>
                             <td><?php  echo($subs);?></td>
                             <td>&nbsp;</td>
                           </tr><?php }  ?>
                        
                  </table>
                  <br />


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