<?php
 global $wpdb;
$prefix='wpsociline_';
$table=$prefix.'user_profile';
if (isset($_POST['socilineid'])) {
  $wpsocilineid = sanitize_text_field($_POST['socilineid']);

  $delete =$wpdb->prepare("delete from `".$table."` where id='".$wpsocilineid."'");
 $wpdb->query($delete);
}
?>
	

	<div class="container-fluid" >
		<div  id="wpsociline_dashboard">
			<div class="row">
				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
					<ul id="wpsociline_dash_nav" >
						<li><a href="admin.php?page=wp_sociline_dashboard"><i class="fa fa-users"></i> User Profile</a></li>
						<li><a href="admin.php?page=wp_sociline_settings"> <i class="fa fa-cogs" style="margin-right: 8px;"></i>Template Settings</a></li>
						<li><a href="admin.php?page=wp_sociline_addprofile"><i class="fa fa-plus-circle"></i> Add New Profile</a></li>
						
					</ul>
				</div>

			</div>

			<div class="wpsociline_addgroup" style="background-color: white;">
				<div class="container-fluid">
					<div class="row">
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12" style="background-color:#4B75A0;height:40px;">
								<div class="wpsociline_table-profile">
									
								<p class="wpsociline_template_name"><i class="fa fa-table"></i>User Profile Data</p>
								</div>
								
						</div>
					</div>
					

					<div class="row">
<div class="col-sm-12">  
<div class="panel panel-primary">
<div class="panel-body" style="margin-top:20px;">					
<div class="table-responsive">
<table class="table table-striped">
    <thead>
      <tr>
		<th>Profile Name</th>
        <th>Created At </th>
        <th>Status</th>
		<th>Action</th>
        
      </tr>
    </thead>
    <tbody>
	
      
	  <?php global $wpdb;
									$prefix='wpsociline_';
									$table=$prefix.'user_profile'; ?>
	  <?php 
	  if(isset($_GET['wpcrpagecount']))
	  {
		  $wpcridin=sanitize_text_field($_GET['wpcrpagecount']);
		  $sql="select * from ".$table." where id <%d order by id desc";
	   $records=$wpdb->get_results($wpdb->prepare($sql,array($wpcridin)));
	  }
	  else
	  {
		$sql="select * from ".$table." order by id desc";
	   $records=$wpdb->get_results($sql);  
	  }
       
	   $wpcrcount=0;
	   $pid=0;
	   foreach($records as $data)
	   {   $wpcrcount++;
		   $pid=(int)$data->id;
		   $id=$pid;
		   
		   $action="<form action='' method='post'>	<a href='admin.php?page=wp_sociline_addprofile&id=".esc_attr($id)."' title='Edit' class='btn unstyled-button'><i class='text-primary fas fa-edit'></i></a>
		   <button type='submit' class='btn unstyled-button' value='".esc_attr($id)."' name='socilineid' data-toggle='tooltip' title='Delete Record'><i class='text-danger fas fa-trash'></i></button></form>";
		    $wpsociline_id=get_option('wpsociline_userid')== $data->id ? 'checked' : '';
		   echo "<tr><td>".esc_html($data->username)."</td>";
		   echo "<td>".esc_html($data->created_at)."</td>";
		   echo "<td><label class='switch'>
  <input type='checkbox' name='wpsociline_my_checkbox' onclick='wpsociline_check(this);' class='wpsociline_profilecheck' value='".esc_attr($id)."' ".esc_attr($wpsociline_id)." >
  <span class='slider round'></span>
</label></td>";
		   echo "<td>".$action;"</td>
		    </td>";
		   echo "</tr>";
		    if($wpcrcount==10)
		   {
			   
			   break;
		   }
	   }
	   $num_rows=$wpdb->get_var("SELECT count(distinct(`id`)) AS `count_id`  FROM `".$table."`");
	  ?>
	 <tr><td class="total-data" colspan=10><center><?php echo "Total No Of Records:".esc_html($num_rows);?></center></td></tr>
	  </tbody>
	  </table>
<ul class="pager">
	  
	<?php
if(isset($_GET['wpcrpagecount']))
 {
?>
  <script type="text/javascript">
function goBack() {
    window.history.back();
}
</script>
  <li class="previous" onclick="goBack()"><a style="cursor:pointer"><button type="submit" class="btn btn-primary" style="float: left; margin:8px; width: 10%;" >Previous</button></a></li>
 <?php } ?> 
 
 <?php
if($wpcrcount==10)
 {

?>
 
<li ><a href="<?php echo esc_url($_SERVER['http_host'].$_SERVER['REQUEST_URI'].'&wpcrpagecount='.$pid); ?>"><button type="submit" class="btn btn-primary" style="float: right; margin:8px; width: 10%;" >Next</button></a></li>

 <?php } ?>
 </ul>
 	  </div>
 </div></div></div></div>
				</div>
			</div>
			
		</div>
		
		
			
		
			
		
	</div>
	<span style="right:0px;bottom:40px;position:absolute;"><a href="https://teknikforce.com" target="_BLANK"><img src="<?php echo esc_url(plugins_url("assets/images/tekniklogo.png",__FILE__)); ?>" style="max-height:40px;max-width:150px"></a></span>
<script type="text/javascript">
	 function wpsociline_check(input)
    {
    	 if (input.checked)
		  {
        var wpsociline_a = input.value;
		var editcsrf="<?php echo wp_create_nonce('editcsrf'); ?>";
          jQuery(document).ready(function($){
           $.ajax({
     	type: 'POST',
       url: "<?php echo admin_url('admin-ajax.php');?>",
               	data:  "action=sociline_edit&wpsociline_a="+wpsociline_a+"&editcsrf="+editcsrf,
success: function(msg){

             }
});
 });       
  }

  else{
  	var wpsociline_b=0;
	  var deltecsrf="<?php echo wp_create_nonce('deltecsrf'); ?>";

          jQuery(document).ready(function($){
 $.ajax({
     	type: 'POST',
       url: "<?php echo admin_url('admin-ajax.php');?>",
               	data:  "action=sociline_delete&wpsociline_b="+wpsociline_b+"&deltecsrf="+deltecsrf,
success: function(msg){

             }
});

   
          });

  } 
    }
   jQuery(document).ready(function($){

    $('.wpsociline_profilecheck').on('change', function() {
        $('.wpsociline_profilecheck').not(this).prop('checked', false);  
    });
});
</script>

