<?php include("includes/header.php");

	require("includes/function.php");
	require("language/language.php");

	$tableName="tbl_ringtone";   
      $targetpage = "ringtone.php"; 
      $limit = 10; 
      
      $query = "SELECT COUNT(*) as num FROM $tableName  where tbl_ringtone.status=1";
      $total_pages = mysqli_fetch_array(mysqli_query($mysqli,$query));
      $total_pages = $total_pages['num'];
      
      $stages = 3;
      $page=0;
      if(isset($_GET['page'])){
      $page = mysqli_real_escape_string($mysqli,$_GET['page']);
      }
      if($page){
        $start = ($page - 1) * $limit; 
      }else{
        $start = 0; 
        } 
      

    
    
    




    
    
    
    
    
    
    $search="";
    if(isset($_POST['search'])){
        $search=$_POST['search'];
    }
     
$data_qry="SELECT tbl_ringtone.* FROM tbl_ringtone where tbl_ringtone.status=1 AND( '$search'='' OR title LIKE '%$search%'  ) ORDER BY tbl_ringtone.id DESC LIMIT $start, $limit";

	$result=mysqli_query($mysqli,$data_qry);
	
	if(isset($_GET['ringtone_id']))
	{
 
		$cat_res=mysqli_query($mysqli,'SELECT * FROM tbl_ringtone WHERE id=\''.$_GET['ringtone_id'].'\'');
		$cat_res_row=mysqli_fetch_assoc($cat_res);

 
		Delete('tbl_ringtone','id='.$_GET['ringtone_id'].'');


	    $_SESSION['msg']="12";
		header( "Location:ringtone.php");
		exit;
     
	}	
	 
?>

<style>

</style>
<script>

</script>
                
    <div class="row">
      <div class="col-xs-12">
      <style>.add_btn_primary2 {
    float: right;
}
.add_btn_primary2 a {
    background-color: #1782de;
    box-shadow: 0 2px 3px rgba(9, 80, 119, 0.3);
    border: 2px solid #02006826;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    border-radius: 10px;
    border-style: 1px solid;
    margin-bottom: 7px;
    transition: all 0.3s ease 0s;
    padding: 10px 30px;
    color: #ffffff;
}</style>










<div class="col-md-6">
                                <div class="col-lg-12">
                                    <form  method="POST">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="search" value="<?php  if(isset($_GET['search'])) echo $_GET['search']; ?>" placeholder="Search With Ringtone Title" aria-label="...">
                                            <?php
                                            if(isset($_GET['sp_category']) && $_GET['sp_category'] != ""){
                                                ?>
                                                <input type="hidden" name="sp_category" value="<?php echo $_GET['sp_category']; ?>">
                                                <?php
                                            }
                                            ?>
                                            <input type="hidden" name="page" value="1">
                                            <div class="input-group-btn">
                                                <button type="submit" class="btn btn-primary dropdown-toggle"  >Search</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>







                            
                            
                            
      <div class="add_btn_primary2"> <a href="add_ringtone.php?add=yes">Add Ringtone</a> </div>
        <div class="card mrg_bottom">
        <div class="page_title">Ringtone</div>
          <div class="row mrg-top">
            <div class="col-md-12">
           
              <div class="col-md-12 col-sm-12">
                <?php if(isset($_SESSION['msg'])){?> 
               	 <div class="alert alert-success alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                	<?php echo $client_lang[$_SESSION['msg']] ; ?></a> </div>
                <?php unset($_SESSION['msg']);}?>	
              </div>
            </div>
          </div>
          <div class="col-md-12 mrg-top">
            <table class="table table-striped table-bordered table-hover">
              <thead>
                <tr>      
                <th>Rington</th>
                  <th>Title</th>
                  <th>Views</th>
                  <th>Download</th>
                  <th>Status</th>	
                  <th class="cat_action_list">Action</th>
                </tr>
              </thead>
              <tbody>
              	<?php	
						$i=0;
						while($row=mysqli_fetch_array($result))
						{					
				?>

        <style>
          a.btn1 {
          margin-right: 20px;
          color: #2196F3;
          }
          .btn1:hover {
            margin-right: 20px;
          color: #fa0000;
          }
        </style>
        <style>
          a.btn2 {
          margin-right: 20px;
          color: #fa0000;
          }
          .btn2:hover {
            margin-right: 20px;
          color: #2196F3;
          }

          h5.text {
    color: #1782de;
}
        </style>
        

        
                <tr> 
                 <td><div class="mediPlayer"><audio class="listen" preload="none" data-size="50" src="<?php echo $row['url']; ?>"></audio></div></td>
                  <td><h5 class="text"><?php echo $row['title'];?></h5></td>
                  <td><h5 class="text"><?php echo $row['total_views'];?> views</h5></td>
                  
                  <td><h5 class="text"><?php echo $row['total_download'];?> download</h5></td>
                  
                  
                  <td>
	                  <?php if($row['status']!="0"){?>
	                    <a title="Change Status" class="toggle_btn_a" href="javascript:void(0)" data-id="<?=$row['id']?>" data-action="deactive" data-column="status"><span class="badge badge-success badge-icon"><i class="fa fa-check" aria-hidden="true"></i><span>Enable</span></span></a>

	                  <?php }else{?>
	                    <a title="Change Status" class="toggle_btn_a" href="javascript:void(0)" data-id="<?=$row['id']?>" data-action="active" data-column="status"><span class="badge badge-danger badge-icon"><i class="fa fa-check" aria-hidden="true"></i><span>Disable </span></span></a>
	                  <?php }?>
	               </td>
		    

                  <td><a href="edit_ringtone.php?ringtone_id=<?php echo $row['id'];?>" class="btn1">Edit</a>
                    <a href="?ringtone_id=<?php echo $row['id'];?>" class="btn2" onclick="return confirm('Are you sure you want to delete ?');">Delete</a></td>
                </tr>
                <?php
						
						$i++;
				     	}
				?> 
              </tbody>
            </table>
          </div>
           <div class="col-md-12 col-xs-12">
            <div class="pagination_item_block">
              <nav>
                <?php if(!isset($_POST["data_search"])){ include("pagination.php");}?>     
              </nav>
            </div>
          </div>
          <div class="clearfix"></div>
        </div>
      </div>
    </div>
        
<?php include("includes/footer.php");?> 

<script type="text/javascript">

	$(".toggle_btn_a").on("click",function(e){
	    e.preventDefault();
	    
	    var _for=$(this).data("action");
	    var _id=$(this).data("id");
	    var _column=$(this).data("column");
	    var _table='tbl_ringtone';

	    $.ajax({
	      type:'post',
	      url:'processData.php',
	      dataType:'json',
	      data:{id:_id,for_action:_for,column:_column,table:_table,'action':'toggle_status','tbl_id':'id'},
	      success:function(res){
	          console.log(res);
	          if(res.status=='1'){
	            location.reload();
	          }
	        }
	    });

	  });

	$(".btn_delete_a").on("click",function(e){

		var _id=$(this).data("id");

	    if(confirm("Are you sure you want to delete this user?")){
          $.ajax({
            type:'post',
            url:'processData.php',
            dataType:'json',
            data:{id:_id,'action':'removeData','tbl_nm':"tbl_users","tbl_id":"id"},
            success:function(res){
                console.log(res);
                if(res.status=='1'){
                  location.reload();
                }
                else if(res.status=='-2'){
                  alert(res.message);
                }
              }
          });
        }
	});
</script>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="assets/js/my_player.js"></script> 
<script>
     $(document).ready(function () {
        $('.mediPlayer').mediaPlayer();
    });
    
</script>v
