<?php
$pageTitle = 'One Link Report';
$buttonAction ='';$buttonName = 'Reset';

if($this->input->get()){
	$buttonName = 'Back To List';
	$backUrl = base_url().'admin/'.$categoryFor;
    $buttonAction = "window.location.href='".$backUrl."'";
}

$act_url = current_url().'?'.$_SERVER['QUERY_STRING'];;


$PER_PAGE = $GLOBALS['PER_PAGE'];
$page = 20;

if($this->input->cookie('perPage',true)){
  $page = $this->input->cookie('perPage',true);
}

if($this->input->get('sub_link_id',true) ){
    $link_id = $this->input->get('sub_link_id',true);
}else if($this->input->get('link_id',true) ) {
    $link_id = $this->input->get('link_id',true);
}else{
    $link_id='';
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title><?php echo $pageTitle ?> List - ACP -<?php echo site_name(); ?></title>

<?php $this->load->view('admin/ap_top'); ?>

<!-- Chart JS -->
<script src="<?php echo base_url(); ?>assets/ap_assets/js/plugin/chart.js/chart.min.js"></script>
<!-- jQuery Sparkline -->
<!--<script src="<?php //echo base_url(); ?>assets/ap_assets/js/plugin/jquery.sparkline/jquery.sparkline.min.js"></script>-->
<!-- Chart Circle -->
<!--<script src="<?php //echo base_url(); ?>assets/ap_assets/js/plugin/chart-circle/circles.min.js"></script>-->

<script type="text/javascript">

 function doActionFn(action,id){
	 if(action == 'edit' || action == 'view'){
        window.location= '<?php echo base_url('admin/'.$categoryFor.'/manager/'); ?>'+action+'/'+id;
	}	
	else{
		 $('#doAction').val(action);	
 		 if(id != 'all' && $('#checked_'+id).length){
			 $('.checkedAll').prop('checked',false); 	
			 $('#checked_'+id).prop('checked',true); 
		  }
		 var checkBox = false;
		$.each($("input[name='ids[]']:checked"), function() {
			checkBox =  true;
		});
 		 if(checkBox == false){
			$('#showActionErr').html(' <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> Please select at least one item </div>');	 
 			return false;
		 }
		 if(action == 'delete'){
			if (confirm("Are you sure you want to delete?")) {
				$('#listFrm').submit();
			}	
		} else{
			$('#listFrm').submit();
		}
 	}
  }

    function change_link_red(id)
    {
        const paramsString = window.location.search;
        const searchParams = new URLSearchParams(paramsString);
        
        let sub_link_id = searchParams.get("sub_link_id");
        
        if(sub_link_id == '' || id == '' || id == undefined){
            searchParams.delete('sub_link_id');
        }
        else{
            searchParams.set('sub_link_id', id );
        }
        window.location.href = window.location.pathname + '?' + searchParams.toString();
    }
    
</script>

</head>

<body>
    
    <div class="wrapper" >
        <?php $this->load->view('admin/navbar'); ?>
            
		<div class="main-panel main-panel-custom">
		    <div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title"><?php echo $categoryForPage;?></h4>
						<ul class="breadcrumbs">
							<li class="nav-home">
								<a href="<?php echo base_url('admin/dashboard');?>">
									<i class="flaticon-home"></i>
								</a>
							</li>
							<li class="separator">
								<i class="flaticon-right-arrow"></i>
							</li>
							<li class="nav-item">
								<a href="<?php echo base_url('admin/one_link');?>">One Link List</a>
							</li>
							<li class="separator">
								<i class="flaticon-right-arrow"></i>
							</li>
							<li class="nav-item">
								<a href="#"><?php echo $pageTitle;?></a>
							</li>
							
						</ul>
					</div>
                    <div class="row">
						
		                <div class="col-md-12">
							<div class="card">
								<!--<div class="card-header">-->
									
								<!--</div>-->
								<div class="card-body">
								    
								    <div class="row">
                                        <div class="col-md-12 " style="padding: 0rem 1.25rem;">
                                            <div class="row">
                                                <div class="form-group col-md-8" >
                                                  <!--<div class="align-items-center">-->
                                                    <h4 class=""> <b>Main Link Name : </b><?php echo (isset($blogRow->link_name)&&!empty($blogRow->link_name)?$blogRow->link_name:""); ?>
                                                    &nbsp;&nbsp;&nbsp;<b>Main Link : </b><?php echo (isset($blogRow->share_link)&&!empty($blogRow->share_link)?$blogRow->share_link:""); ?>
                                                    </h4>
                                                    <!--<h4 class=""> </h4>-->
                                                    <?php
                                                    if(isset($blogRow->sub_link_flag) && !empty($blogRow->sub_link_flag) ) {
                                                        $sub_link_listRow = $this->admin_onelink_model->get_Sublink_list($blogRow->id);
                                                        $sub_link_list=[];
                                            			if(!empty($sub_link_listRow)){
                                            				$sub_link_list = $sub_link_listRow;
                                            			}
                                            			
                                            			if(!empty($sub_link_list)){
                                            			 //   var_dump($sub_link_list);
                                            			    ?>
                                            			    <div class="form-inline" >
                                            			        <div class="form-group col-md-5" >
                                        			            <label>Sublinks </label>
                                                                <select class="form-control input-full " onchange='change_link_red(this.value)' name="sublinks" id="sublinks">
                                                               <?php
                                                                if(isset($sub_link_id) && !empty($sub_link_id)){
                                                                    $sub_link_id=$sub_link_id;
                                                                }else $sub_link_id='';
                                                                
                                                                $selected_link = '';
                                                                echo '<option value="" '.$selected.'>Select Sub-link</option>';
                                                                foreach($sub_link_list as $cck){
                                                                    if($sub_link_id == $cck->id){ $selected='selected'; $selected_link = $cck->share_link; }
                                                                    else{$selected='';}
                                                                    echo '<option value="'.$cck->id.'" '.$selected.'>'.$cck->sublink_name.'</option>';
                                                                }
                                                                ?>
                                                                </select>
                                                            </div>
                                                                <div class="form-group col-md-5">
                                                                   <b>Sub Link :&nbsp;&nbsp; </b><?php echo (isset($selected_link)&&!empty($selected_link)?$selected_link:"-"); ?>
                                                                </div>
                                                             </div>
                                            			    <?php
                                            			}
                                                    }
                                                    ?>
                                              </div>
                                             
                                            <div class="form-group col-md-4" >
                                                
        									    <div class="card-tools" style="float: right;">
        											<ul class="nav nav-pills nav-secondary nav-pills-no-bd " role="tablist">
        											    <li class="nav-item">
        										            <a class="nav-link active btn-primary" href="<?php echo base_url('admin/one_link/manager/edit/'.$link_id) ?>"> <i class="fas fa-pencil-alt"></i>&nbsp; Edit </a>
        									            </li>
        											    <li class="nav-item">
        										            <a class="nav-link active btn-success" style="background: #28a745;!important"  href="<?php echo base_url('admin/one_link/manager/view/'.$link_id) ?>"> <i class="fas fa-info"></i>&nbsp; View </a>
        									            </li>
        									            <li class="nav-item">
        										            <a class="nav-link active btn-secondary " style="background: #007bff;!important"  href="<?php echo base_url('admin/one_link/statistics?link_id='.$link_id) ?>"> <i class="fas fa-chart-bar fa-lg"></i>&nbsp; Report</a>
        									            </li>
        									            <!--<li class="nav-item">-->
        									                <!--<a class="nav-link active btn-refresh-card" style="background: #007bff;!important">Reload</a>-->
        										           <!-- <button id="table-refresh" class="nav-link active btn-refresh-card btn-refresh-card" ><span class="fa fa-sync-alt"></span></button>-->
        									            <!--</li>-->
        											</ul>
        										</div>
    									

                                              </div>
                                            </div>
                                            <div class="row">
                                                <div class="form-group col-md-8" >
                                                  
                                		            <h3 class=""> Total Clicks :  <?php echo (isset($blogRow->hits)&&!empty($blogRow->hits)?$blogRow->hits:0)?></h3>
                                		            <!--&nbsp;&nbsp;&nbsp; App ID : <strong>1</strong></h3>-->
                                		            <?php 
                                		            $res_cfap = $this->Admin_stat_model->get_click_count_by_id();
                                		            ?>
                                		            <h3 class=""> Clicks :  <?php echo (isset($res_cfap)&&!empty($res_cfap)?$res_cfap:0)?></h3>
                                              </div>
                                             
                                                <div class="form-group col-md-4" >
                                                <!--<label for="daterange_By">Date Range By</label>-->
                                                <div class="input-icon ">
                                                <?php
                                                   
                                                    if($this->input->get('reportrange',true)){
                                                        $set_Date_value=$this->input->get('reportrange',true);
                                                    }else $set_Date_value='';
                                                    
                                                    $data = array( 'name' => 'reportrange','autoComplete' => 'off',
                                                    'value' => set_value('reportrange',$set_Date_value), 
                                                    'id' => 'reportrange',  'class' => 'form-control', );
                                                    echo form_input($data);
                                                    ?>                                                      
                                                </div>
                                              </div>
                                            </div>
                                        </div>
                                    </div>
								    
								    
									<ul class="p-3 nav nav-pills nav-secondary" id="pills-tab" role="tablist">
										
										<li class="nav-item submenu">
											<a class="nav-link active show" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Device</a>
										</li>
										<li class="nav-item submenu">
											<a class="nav-link " id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Country</a>
										</li>
										<li class="nav-item submenu">
											<a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Destination</a>
										</li>
									</ul>
									<div class="tab-content mt-2 mb-3" id="pills-tabContent">
									    
										<div class="tab-pane fade active show" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
										    
										    <div class="card-body">
                            		            <?php
                                					$listUrl = base_url($act_url.'?'); 
                                				    if($this->input->get()){
                                					    $arrGet = $this->input->get(); unset($arrGet['per_page']);
                                					    $listUrl   = base_url('admin/'.$categoryFor).'?'.  http_build_query($arrGet);
                                  					}
                                 					$GLOBALS['ARR_ACP_PAGIN_CONF']['base_url'] = $listUrl;
                                					$GLOBALS['ARR_ACP_PAGIN_CONF']['per_page'] = $this->Admin_stat_model->limit;	
                                					$total_rows = $GLOBALS['ARR_ACP_PAGIN_CONF']['total_rows'] = $this->Admin_stat_model->get_device_chart_data('count');	
                                 					$this->pagination->initialize($GLOBALS['ARR_ACP_PAGIN_CONF']);
                                                    $arrList = $this->Admin_stat_model->get_device_chart_data('list');
                                                    
                                					$listUrl1 = "";
                                					$sortBy = 'registerDate';$sortOrder = 'desc';
                            					    if($this->input->get('sortBy',true) && $this->input->get('sortOrder',true)){
                                						 $sortBy = $this->input->get('sortBy',true);$sortOrder = $this->input->get('sortOrder',true);
                            					    }
                            					    
                                					if(isset($arrGet)){
                                						unset($arrGet['sortBy']); unset($arrGet['sortOrder']);
                            						    $listUrl  = base_url($act_url).'?'. http_build_query($arrGet);
                            						    $listUrl1  = $act_url.'?'. http_build_query($arrGet);
                                					}
      							                ?>
                                    		    <div class="table-responsive">
        										    <table id="feedback_list_table" class="display table table-striped table-hover table-bordered " >
        											<thead>
         					                            <tr>
                                                            <th>#</th>
                                                            <th>Device Name</th>
                                                            <th>Count</th>
                                                            <th>Installation Count</th>
                                                            <!--<th>Region</th>-->
                                                            <!--<th>City</th>-->
                                                        </tr>
        											</thead>
        										
        											<tbody>
        									            <?php
                                 					    if($arrList){
                                						    $res_insall = $this->Admin_stat_model->get_installation_count();
                                						  //  var_dump($res_insall);exit;
                                						    $Res_count['android']=0;
 	                                                        $Res_count['ios']=0;
                                						    if(!empty($res_insall)){
                                						        $Res_count['android']=$res_insall['android'];
 	                                                            $Res_count['ios']=$res_insall['ios'];
                                						    }
                                						    
                                						    $sno = (($this->Admin_stat_model->page) * $this->Admin_stat_model->limit)+1;
                            						        foreach($arrList as $objRow){
                                							?>
                                                                <tr>
                                                                    <td><?php echo $sno;?></td>
                                                                    <td><?php echo (isset($objRow->os_group_name) && !empty($objRow->os_group_name) ? $objRow->os_group_name:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->total_c) && !empty($objRow->total_c) ? $objRow->total_c:"0" );?></td>
                                                                    <td>
                                                                        <?php 
                                                                        if(isset($objRow->os_group_name) && !empty($objRow->os_group_name)){
                                                                            if( strtolower($objRow->os_group_name) =='android'){
                                                                                echo $Res_count['android'];
                                                                            }
                                                                            else if( strtolower($objRow->os_group_name) =='ios'){
                                                                                echo $Res_count['ios'];
                                                                            }
                                                                            else{
                                                                                echo 0;
                                                                            }
                                                                        }
                                                                        ?>
                                                                    </td>
                                                                </tr>
                                                            <?php	
                                							$sno++;
                                						    }	 
        					                            }else{
        						                        ?>
                                                        <tr>
                                                            <td colspan="11" align="center">No records</td>
                                                        </tr>
                                                        <?php	 
                                    					}
        		                                        ?>
        											</tbody>
        										</table>
        									    </div>
    								        </div>
								           
										</div>
										
										<div class="tab-pane fade  " id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
											<div class="card-body">
                            		            <?php
                                					$listUrl = base_url($act_url.'?'); 
                                				    if($this->input->get()){
                                					    $arrGet = $this->input->get(); unset($arrGet['per_page']);
                                					    $listUrl   = base_url('admin/'.$categoryFor).'?'.  http_build_query($arrGet);
                                  					}
                                 					$GLOBALS['ARR_ACP_PAGIN_CONF']['base_url'] = $listUrl;
                                					$GLOBALS['ARR_ACP_PAGIN_CONF']['per_page'] = $this->Admin_stat_model->limit;	
                                					$total_rows = $GLOBALS['ARR_ACP_PAGIN_CONF']['total_rows'] = $this->Admin_stat_model->get_country_chart_data('count');	
                                 					$this->pagination->initialize($GLOBALS['ARR_ACP_PAGIN_CONF']);
                                                    $arrList = $this->Admin_stat_model->get_country_chart_data('list');
                                                    
                                					$listUrl1 = "";
                                					$sortBy = 'registerDate';$sortOrder = 'desc';
                            					    if($this->input->get('sortBy',true) && $this->input->get('sortOrder',true)){
                                						 $sortBy = $this->input->get('sortBy',true);$sortOrder = $this->input->get('sortOrder',true);
                            					    }
                            					    
                                					if(isset($arrGet)){
                                						unset($arrGet['sortBy']); unset($arrGet['sortOrder']);
                            						    $listUrl  = base_url($act_url).'?'. http_build_query($arrGet);
                            						    $listUrl1  = $act_url.'?'. http_build_query($arrGet);
                                					}
      							                ?>
                                    		    <div class="table-responsive">
        										    <table id="feedback_list_table" class="display table table-striped table-hover table-bordered " >
        											<thead>
         					                            <tr>
                                                            <th>#</th>
                                                            <th>Country</th>
                                                            <th>Count</th>
                                                            <!--<th>Country</th>-->
                                                            <!--<th>Region</th>-->
                                                            <!--<th>City</th>-->
                                                        </tr>
        											</thead>
        										
        											<tbody>
        									            <?php
                                 					    if($arrList){
                                						 
                                						    $sno = (($this->Admin_stat_model->page) * $this->Admin_stat_model->limit)+1;
                            						        foreach($arrList as $objRow){
                                							?>
                                                                <tr>
                                                                    <td><?php echo $sno;?></td>
                                                                    <td><?php echo (isset($objRow->country_name) && !empty($objRow->country_name) ? $objRow->country_name:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->total_c) && !empty($objRow->total_c) ? $objRow->total_c:"0" );?></td>
                                                                </tr>
                                                            <?php	
                                							$sno++;
                                						    }	 
        					                            }else{
        						                        ?>
                                                        <tr>
                                                            <td colspan="11" align="center">No records</td>
                                                        </tr>
                                                        <?php	 
                                    					}
        		                                        ?>
        											</tbody>
        										</table>
        									    </div>
    								        </div>
    								        <?php
										    if(isset($total_rows) &&!empty($total_rows) && $total_rows > 10){
										    ?>
								                <div class="card-footer ">
								     <div class="btn-wrapper text-center d-flex justify-content-between">
                        		        <div class="d-flex align-items-center">
                        		            <h4 class="card-title"></h4>
                        		        </div>
                        		        <div class="d-flex align-items-center">
                        		             <div class="form-group col-md-4">
                                                  <div class="">
                                                    <?php  echo $this->pagination->create_links();  ?>
                                                  </div>
                                            </div>
                        		        </div>
                        		    </div>
        								    <div class="btn-wrapper text-center d-flex justify-content-between">
        								        <div class="d-flex align-items-center">
        											
        										</div>
        										<div class="d-flex align-items-center">
        										    
        											<form action="<?php echo $_SERVER['REQUEST_URI']?>" name="perPageForm" method="post">
        											    <input type="hidden" name="listUrl" value="<?php echo $act_url ?>">
                                                        <?php
                                            				$js = 'class="form-control" id="perPage" style="width:auto;" onchange="this.form.submit()"  '; 
                                            				echo form_dropdown('perPage', $PER_PAGE,set_value('perPage',$page), $js); 
                                            			?>
                                                    </form>
                                                    
        										</div>
                                            </div>
                                        </div>
                                        <?php
									    }
									    ?>
										</div>
										
										
										<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
											<div class="card-body">
                            		            <?php
                                					$listUrl = base_url($act_url.'?'); 
                                				    if($this->input->get()){
                                					    $arrGet = $this->input->get(); unset($arrGet['per_page']);
                                					    $listUrl   = base_url('admin/'.$categoryFor).'?'.  http_build_query($arrGet);
                                  					}
                                 					$GLOBALS['ARR_ACP_PAGIN_CONF']['base_url'] = $listUrl;
                                					$GLOBALS['ARR_ACP_PAGIN_CONF']['per_page'] = $this->Admin_stat_model->limit;	
                                					$total_rows = $GLOBALS['ARR_ACP_PAGIN_CONF']['total_rows'] = $this->Admin_stat_model->get_destination_listdata('count');	
                                 					$this->pagination->initialize($GLOBALS['ARR_ACP_PAGIN_CONF']);
                                                    $arrList = $this->Admin_stat_model->get_destination_listdata('list');
                                                    
                                					$listUrl1 = "";
                                					$sortBy = 'registerDate';$sortOrder = 'desc';
                            					    if($this->input->get('sortBy',true) && $this->input->get('sortOrder',true)){
                                						 $sortBy = $this->input->get('sortBy',true);$sortOrder = $this->input->get('sortOrder',true);
                            					    }
                            					    
                                					if(isset($arrGet)){
                                						unset($arrGet['sortBy']); unset($arrGet['sortOrder']);
                            						    $listUrl  = base_url($act_url).'?'. http_build_query($arrGet);
                            						    $listUrl1  = $act_url.'?'. http_build_query($arrGet);
                                					}
      							                ?>
                                    		    <div class="table-responsive">
        										    <table id="feedback_list_table" class="display table table-striped table-hover table-bordered " >
        											<thead>
         					                            <tr>
                                                            <th>#</th>
                                                            <th>Destination Links </th>
                                                            <th>Count</th>
                                                        </tr>
        											</thead>
        										
        											<tbody>
        									            <?php
                                 					    if($arrList){
                                						 
                                						    $sno = (($this->Admin_stat_model->page) * $this->Admin_stat_model->limit)+1;
                            						        foreach($arrList as $objRow){
                                							?>
                                                                <tr>
                                                                    <td><?php echo $sno;?></td>
                                                                    <td><?php echo (isset($objRow->d_link) && !empty($objRow->d_link) ? $objRow->d_link:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->total_c) && !empty($objRow->total_c) ? $objRow->total_c:"0" );?></td>
                                                                </tr>
                                                            <?php	
                                							$sno++;
                                						    }	 
        					                            }else{
        						                        ?>
                                                        <tr>
                                                            <td colspan="11" align="center">No records</td>
                                                        </tr>
                                                        <?php	 
                                    					}
        		                                        ?>
        											</tbody>
        										</table>
        									    </div>
    								        </div>
										</div>
									</div>
								</div>
							</div>
						</div>
						
						<div class="col-md-12">
							<div class="card">
								
								<div class="card-header">
								    <div class="card-head-row">
									    <h4 class="card-title"><?php echo $pageTitle; ?></h4>
									    
									    <div class="card-tools">
											<ul class="nav nav-pills nav-secondary nav-pills-no-bd " role="tablist">
											    <!--<li class="nav-item">-->
										     <!--       <a class="nav-link active" style="background: #28a745;!important"  href="<?php echo base_url('admin/'.$categoryFor.'/manager') ?>"> <i class="fa fa-plus"></i>&nbsp; Add New Share Link</a>-->
									      <!--      </li>-->
									            <!--<li class="nav-item">-->
										           <!-- <a class="nav-link active" style="background: #007bff;!important"  href="app_export.php"> <i class="fas fa-file-export"></i>&nbsp; Export</a>-->
									            <!--</li>-->
									            <!--<li class="nav-item">-->
									                <!--<a class="nav-link active btn-refresh-card" style="background: #007bff;!important">Reload</a>-->
										           <!-- <button id="table-refresh" class="nav-link active btn-refresh-card btn-refresh-card" ><span class="fa fa-sync-alt"></span></button>-->
									            <!--</li>-->
											</ul>
										</div>
									</div>
								</div>
								
								<!--notifiactions-->
    							<div class="container" id="">
                                    <?php 
                             		$errMsg = validation_errors('* ');
                            		if(empty($errMsg)){ $errMsg = $this->session->flashdata('errMsg');  }
                            		$warningMsg = $this->session->flashdata('warningMsg');
                            		$successMsg = $this->session->flashdata('successMsg');
                            		if(isset($errMsg) && !empty($errMsg)){ echo showMessage($errMsg,'error'); }  
                            		if(isset($warningMsg) && !empty($warningMsg)){ echo showMessage($warningMsg,'warning'); }
                            		if(isset($successMsg) && !empty($successMsg)){ echo showMessage($successMsg,'success'); }
                            	?>
                                </div>
                                
								
								<div class="card-body">
								    
							        
								    <div class="card-body">
    
    						            <div class="row">
								            <div class="col-md-6">
                    							<div class="card">
                    							    <div class="card-header">
            									        <div class="card-title">Device Based</div>
                    								</div>
                    								<div class="card-body">
                        							    <?php
                        							    $res_pie_chart = $this->Admin_stat_model->get_device_chart_data();
                    							        $res_country_chart = $this->Admin_stat_model->get_country_chart_data();
            									        if(!empty($res_pie_chart))
            									        {
            									            ?>
                        									<div class="chart-container"><div class="chartjs-size-monitor" style="position: absolute; inset: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;"><div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div></div><div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:200%;height:200%;left:0; top:0"></div></div></div>
                        										<canvas id="pieChart" style="width: 322px; height: 300px; display: block;" width="402" height="375" class="chartjs-render-monitor"></canvas>
                        									</div>
            									            <?php
            									        }else{
            									            echo 'No data';
            									        }
                        							    ?>
                    								</div>
                    							</div>
                    						</div>
                    						
                    						<div class="col-md-6">
                        						<div class="card">
                        						    <div class="card-header">
            									        <div class="card-title">Country Based</div>
                    								</div>
                    								<div class="card-body">
                        							    <?php
                    							        $res_country_chart = $this->Admin_stat_model->get_country_chart_data();
                        							    
            									        if(!empty($res_country_chart))
            									        {
            									           ?>
                        									<div class="chart-container"><div class="chartjs-size-monitor" style="position: absolute; inset: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;"><div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div></div><div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:200%;height:200%;left:0; top:0"></div></div></div>
                        										<canvas id="doughnutChart" style="width: 322px; height: 300px; display: block;" width="402" height="375" class="chartjs-render-monitor"></canvas>
                        									</div>
                            								<?php
            									        }else{
            									            echo 'No data';
            									        }
                        							    ?>
                    							    </div>
                    							</div>
                    						</div>
								            
								            
								            <!--<div class="col-md-12">-->
                    <!--    						<div class="card">-->
                    <!--								<div class="card-header">-->
                    <!--									<div class="card-title">Multiple Bar Chart</div>-->
                    <!--								</div>-->
                    <!--								<div class="card-body">-->
                    <!--									<div class="chart-container"><div class="chartjs-size-monitor" style="position: absolute; inset: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;"><div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div></div><div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:200%;height:200%;left:0; top:0"></div></div></div>-->
                    <!--										<canvas id="multipleBarChart" width="402" height="375" style="display: block; height: 300px; width: 322px;" class="chartjs-render-monitor"></canvas>-->
                    <!--									</div>-->
                    <!--								</div>-->
                    <!--							</div>-->
                    <!--						</div>-->
    								            
								        </div>
    							    </div>
								</div>
							</div>
						</div>
						
						<div class="col-md-12">
					    	<div class="card">
						         
					            <div class="card-body">
								                
								               
                            		            <div class="btn-wrapper text-center d-flex justify-content-between">
                                    		        <div class="d-flex align-items-center">
                                    		            <h4 class="card-title"> <?php echo $pageTitle; ?> List</h4>
                                    		        </div>
                                    		        <!--<div class="d-flex align-items-center">-->
                                    		             <!--<form action="<?php //echo $_SERVER['REQUEST_URI']?>" name="perPageForm" method="post">-->
                                    		                 <!--<input type="hidden" name="listUrl" value="<?php //echo $act_url ?>">-->
                                                          <?php  
                                            				
                                            				// $js = 'class="form-control" id="perPage" style="width:auto;" onchange="this.form.submit()"  '; 
                                            				// echo form_dropdown('perPage', $PER_PAGE, set_value('perPage',$page), $js); 
                                            			?>
                                                        <!--</form>-->
                                    		        <!--</div>-->
                                    		    </div>
                            		            <?php
                            		                
                                					$listUrl = base_url($act_url.'?'); 
                                				    if($this->input->get()){
                                					    $arrGet = $this->input->get(); unset($arrGet['per_page']);
                                					    $listUrl   = base_url('admin/'.$categoryFor).'?'.  http_build_query($arrGet);
                                  					}
                                 					$GLOBALS['ARR_ACP_PAGIN_CONF']['base_url'] = $listUrl;
                                					$GLOBALS['ARR_ACP_PAGIN_CONF']['per_page'] = $this->Admin_stat_model->limit;	
                                					$total_rows = $GLOBALS['ARR_ACP_PAGIN_CONF']['total_rows'] = $this->Admin_stat_model->get_visitlog_List('count');	
                                 					$this->pagination->initialize($GLOBALS['ARR_ACP_PAGIN_CONF']);
                                                    $arrList = $this->Admin_stat_model->get_visitlog_List('list');
                                                    
                                					$listUrl1 = "";
                                					$sortBy = 'registerDate';$sortOrder = 'desc';
                            					    if($this->input->get('sortBy',true) && $this->input->get('sortOrder',true)){
                                						 $sortBy = $this->input->get('sortBy',true);$sortOrder = $this->input->get('sortOrder',true);
                            					    }
                            					    
                                					if(isset($arrGet)){
                                						unset($arrGet['sortBy']); unset($arrGet['sortOrder']);
                            						    $listUrl  = base_url($act_url).'?'. http_build_query($arrGet);
                            						    $listUrl1  = $act_url.'?'. http_build_query($arrGet);
                                					}
      							                ?>
      							                
                            		            <div class="btn-wrapper text-center d-flex justify-content-between">
                                    		        <div class="d-flex align-items-center">
                                    		            <h4 class="card-title"> Total Clicks : <?php echo $total_rows;?></h4>
                                    		        </div>
                                    		        <!--<div class="d-flex align-items-center">-->
                                    		             <!--<div class="form-group col-md-4">-->
                                                   <!--           <div class="">-->
                                                                <?php  //echo $this->pagination->create_links();  ?>
                                                        <!--      </div>-->
                                                        <!--</div>-->
                                    		        <!--</div>-->
                                    		    </div>
                            		    
                                    		    <div class="table-responsive">
								                
        										    <table id="feedback_list_table" class="display table table-striped table-hover table-bordered " >
        										    
        											<thead>
         					                            <input type="hidden" name="listUrl" value="<?php echo $listUrl1 ?>">
                                                        <tr>
                                                            <th>#</th>
                                                            <th>IP Address</th>
                                                            <th>Device</th>
                                                            <th>Country</th>
                                                            <th>Region</th>
                                                            <th>City</th>
                                                            <th>Recorded at (TZ:Asia/Calcutta)</th>
                                                        </tr>
        											</thead>
        										
        											<tbody>
        									            <?php
                                 					    if($arrList){
                                						 
                                						    $sno = (($this->Admin_stat_model->page) * $this->Admin_stat_model->limit)+1;
                            						        foreach($arrList as $objRow){
                                							?>
                                                                <tr>
                                                                    <td><?php echo $sno;?></td>
                                                                    <td><?php echo (isset($objRow->ip) && !empty($objRow->ip) ? $objRow->ip:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->os_group_name) && !empty($objRow->os_group_name) ? $objRow->os_group_name:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->country_name) && !empty($objRow->country_name) ? $objRow->country_name:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->region_name) && !empty($objRow->region_name) ? $objRow->region_name:"-" );?></td>
                                                                    <td><?php echo (isset($objRow->city_name) && !empty($objRow->city_name) ? $objRow->city_name:"-" );?></td>
                                                                    <td>
                                                                        <?php
                                                                            // echo echo gmdate('d.m.Y H:i', strtotime('2012-06-28 23:55'));
                                                                           
                                                                            $dtime =  (isset($objRow->request_time) && !empty($objRow->request_time) ? $objRow->request_time:"" );
                                                                            //  echo gmdate('d.m.Y H:i', $dtime);
                                                                            $datetime = new DateTime("@$dtime");
                                                                            $date_time_format = $datetime->format('Y-m-d H:i:s');
                                                                            $time_zone_from="UTC";
                                                                            $time_zone_to='Asia/Calcutta';
                                                                            $display_date = new DateTime($date_time_format, new DateTimeZone($time_zone_from));
                                                                            $display_date->setTimezone(new DateTimeZone($time_zone_to));
                                                                            echo $display_date->format('d-m-Y h:i:s A')
                                                                        ?>
                                                                    </td>
                                                                </tr>
                                                            <?php	
                                							$sno++;
                                						    }	 
        					                            }else{
        						                        ?>
                                                        <tr>
                                                            <td colspan="11" align="center">No records</td>
                                                        </tr>
                                                        <?php	 
                                    					}
        		                                        ?>
        											</tbody>
        										</table>
        									    </div>
    								        </div>
								<div class="card-footer ">
								     <div class="btn-wrapper text-center d-flex justify-content-between">
                        		        <div class="d-flex align-items-center">
                        		            <h4 class="card-title"></h4>
                        		        </div>
                        		        <div class="d-flex align-items-center">
                        		             <div class="form-group col-md-4">
                                                  <div class="">
                                                    <?php  echo $this->pagination->create_links();  ?>
                                                  </div>
                                            </div>
                        		        </div>
                        		    </div>
								    <div class="btn-wrapper text-center d-flex justify-content-between">
								        <div class="d-flex align-items-center">
											
										</div>
										<!--<div class="d-flex align-items-center">-->
											<!--<form action="<?php //echo $_SERVER['REQUEST_URI']?>" name="perPageForm" method="post">-->
											    <!--<input type="hidden" name="listUrl" value="<?php //echo $act_url ?>">-->
                                                <?php
                                    				// $js = 'class="form-control" id="perPage" style="width:auto;" onchange="this.form.submit()"  '; 
                                    				// echo form_dropdown('perPage', $PER_PAGE,set_value('perPage',$page), $js); 
                                    			?>
                                            <!--</form>-->
										</div>
                                    </div>
                                </div>
						    </div>
						</div>
					</div>
				</div>
			</div>
		    <!--<footer class="footer">-->
			    <?php //footer();?>
			<!--</footer>-->
		</div>
	</div>

</body>

<script type="text/javascript">
 
$(function() {
  $('#reportrange').daterangepicker({
        autoUpdateInput: false,
        locale: {
          cancelLabel: 'Clear',
          format: 'MMMM D, YYYY',
        },
        ranges: {
        'Today': [moment(), moment()],
        'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
        'Last 7 Days': [moment().subtract(6, 'days'), moment()],
        'Last 30 Days': [moment().subtract(29, 'days'), moment()],
        'This Month': [moment().startOf('month'), moment().endOf('month')],
        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
    },
  });
  
  $('#reportrange').on('apply.daterangepicker', function(ev, picker) {
      $(this).val(picker.startDate.format('MMMM D, YYYY') + ' - ' + picker.endDate.format('MMMM D, YYYY'));
      
        const paramsString = window.location.search;
        const searchParams = new URLSearchParams(paramsString);
        vall = picker.startDate.format('MMMM D, YYYY') + ' - ' +picker.endDate.format('MMMM D, YYYY');
        searchParams.set('reportrange', vall );
        window.location.href = window.location.pathname + '?' + searchParams.toString();

  });
  $('#daterange_By').on('cancel.daterangepicker', function(ev, picker) {
      $(this).val('');
  });
});

</script>

<script>
    <?php
    if(isset($res_pie_chart) && !empty($res_pie_chart)){
    
        $p_count = array(0=>"0" ,1=>"0" ,2=>"0" ,3=>"0");
        foreach($res_pie_chart as $da){
            if($da->os_group_name == 'Windows' ){
                $p_count[0] = $da->total_c;
            }
            if($da->os_group_name == 'iOS' ){
                $p_count[1] = $da->total_c;
            }
            if($da->os_group_name == 'Android' ){
                $p_count[2] = $da->total_c;
            }
            if($da->os_group_name == 'Unknown Platform' ){
                $p_count[3] = $da->total_c;
            }
        }
        ?>
        pieChart = document.getElementById('pieChart');
        
        myPieChart = new Chart(pieChart, {
            	type: 'pie',
                data: {
    			datasets: [{
    				data: <?php echo json_encode(array_values($p_count)); ?> ,
    				backgroundColor : ["#1d7af3","#f3545d","#fdaf4b","#17a2b8"] ,
    				borderWidth: 0
    			}],
    			labels: ["Windows","iOS","Android","Unknown Platform"] 
                },
                options : {
    				responsive: true, 
    				maintainAspectRatio: false,
    				legend: {
    					position : 'left',
    					labels : {
    						fontColor: 'rgb(154, 154, 154)',
    						fontSize: 14,
    						usePointStyle : true,
    						padding: 20
    					}
    				},
    				pieceLabel: {
    					render: 'percentage',
    					fontColor: 'white',
    					fontSize: 14,
    				},
    				tooltips: false,
    				layout: {
    					padding: {
    						left: 20,
    						right: 20,
    						top: 20,
    						bottom: 20
    					}
    				}
    			}
                });
    
    <?php
    }
    ?>
    
    <?php
    // $p_count = array(0=>"0" ,1=>"0" ,2=>"0" );
    if(!empty($res_country_chart)){
        foreach($res_country_chart as $da){
        
            if($da->country_name){
                $c_name[] = $da->country_name;
            }
            if($da->total_c){
                $c_count[] = $da->total_c;
            }
        }
        
        // $country_chart_arr = $res_country_chart;
        $bg = array("#1d7af3","#f3545d","#fdaf4b", "#31ce36" ,"#6c757d", "#17a2b8");
        $bg_set = array_slice($bg,0,count($c_name));
        
        ?>
        
        doughnutChart = document.getElementById('doughnutChart');
        var myDoughnutChart = new Chart(doughnutChart, {
			type: 'doughnut',
			data: {
				datasets: [{
					data: <?php echo json_encode(array_values($c_count));?>,
					backgroundColor: <?php echo json_encode(($bg_set));?>
				}],

				labels: <?php echo json_encode(array_values($c_name));?>
			},
			options: {
				responsive: true, 
				maintainAspectRatio: false,
				legend : {
					position: 'bottom'
				},
				layout: {
					padding: {
						left: 20,
						right: 20,
						top: 20,
						bottom: 20
					}
				}
			}
		});
        
        <?php
    }
    ?>
    
//     multipleBarChart  = document.getElementById('multipleBarChart');
//     var myMultipleBarChart = new Chart(multipleBarChart, {
// 			type: 'bar',
// 			data: {
// 				labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
// 				datasets : [{
// 					label: "First time visitors",
// 					backgroundColor: '#59d05d',
// 					borderColor: '#59d05d',
// 					data: [95, 100, 112, 101, 144, 159, 178, 156, 188, 190, 210, 245],
// 				},{
// 					label: "Visitors",
// 					backgroundColor: '#fdaf4b',
// 					borderColor: '#fdaf4b',
// 					data: [145, 256, 244, 233, 210, 279, 287, 253, 287, 299, 312,356],
// 				}, {
// 					label: "Pageview",
// 					backgroundColor: '#177dff',
// 					borderColor: '#177dff',
// 					data: [185, 279, 273, 287, 234, 312, 322, 286, 301, 320, 346, 399],
// 				}],
// 			},
// 			options: {
// 				responsive: true, 
// 				maintainAspectRatio: false,
// 				legend: {
// 					position : 'bottom'
// 				},
// 				title: {
// 					display: true,
// 					text: 'Traffic Stats'
// 				},
// 				tooltips: {
// 					mode: 'index',
// 					intersect: false
// 				},
// 				responsive: true,
// 				scales: {
// 					xAxes: [{
// 						stacked: true,
// 					}],
// 					yAxes: [{
// 						stacked: true
// 					}]
// 				}
// 			}
// 		});

</script>

</html>