<?php  include("includes/connection.php");
 	  include("includes/function.php"); 	
	
	$file_path = 'http://'.$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']).'/';
	
	define("PACKAGE_NAME",$settings_details['package_name']);
	$get_method = checkSignSalt($_POST['data']);
	
	 if($get_method['method_name']=="song_search"){
        
         $jsonObj= array();	
    	
    	$page_limit=10;
    		
    	$limit=($get_method['page']-1) * $page_limit;
    	
    
    	$query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid 
    	WHERE tbl_ringtone.status='1' AND tbl_ringtone.title like '%".addslashes($get_method['search_text'])."%' 
    	ORDER BY tbl_ringtone.id DESC LIMIT $limit, 10";
    
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    
    		
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    		 
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="cat_songs"){
         
       $jsonObj= array();	
     		
     	$page_limit=10;
    		
    	$limit=($get_method['page']-1) * $page_limit;
     	
    	$cat_id=$get_method['cat_id'];
    
    	$jsonObj= array();	
    
        $query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid 
    	where tbl_ringtone.cat_id='".$cat_id."' AND tbl_ringtone.status='1' ORDER BY tbl_ringtone.id LIMIT $limit, $page_limit";
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    			
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    		 
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    
    else if($get_method['method_name']=="most_viewed"){
        
       	$jsonObj= array();	
       	
       	
    
    	$query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid 
    	WHERE tbl_ringtone.total_views ORDER BY tbl_ringtone.total_views DESC LIMIT 10";
    
    	
    
    	$jsonObj= array();	
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    
    	
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    		 
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="all_songs"){
         
       $jsonObj= array();	
     		
     	$page_limit=10;
    		
    	$limit=($get_method['page']-1) * $page_limit;
     	
    	$query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid 
    	WHERE tbl_ringtone.status='1' ORDER BY tbl_ringtone.id DESC LIMIT $limit, $page_limit";
    
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    
    		
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    		 
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="cat_list"){
     	
     	$jsonObj= array();
    	
    	$query="SELECT cid,category_name,category_image FROM tbl_category ORDER BY tbl_category.cid DESC";
    	$sql = mysqli_query($mysqli,$query)or die(mysql_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
     }
     else if($get_method['method_name']=="user_register"){	
      
      	if($get_method['name']!='' AND $get_method['email']!='' AND $get_method['password']!=''){
    
    		$qry = "SELECT * FROM tbl_users WHERE email = '".$get_method['email']."'"; 
    		$result = mysqli_query($mysqli,$qry);
    		$row = mysqli_fetch_assoc($result);
    		
    		if($row['email']!=""){
    		    
    			$set['banostudio'][]=array('msg' => $app_lang['email_exist'],'success'=>'0');
    		}else{ 
     			$qry1="INSERT INTO tbl_users (`name`,`email`,`password`,`phone`,`status`) VALUES ('".$get_method['name']."','".$get_method['email']."','".$get_method['password']."','".$get_method['phone']."','1')"; 
                
                $result1=mysqli_query($mysqli,$qry1);  										 
    					 
    			$set['banostudio'][]=array('msg' => $app_lang['register_success'],'success'=>'1');
    		}
    	}
    
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="user_login"){
    
      	$email = $get_method['email'];
    	$password = $get_method['password'];
    
    	$qry = "SELECT * FROM tbl_users WHERE email = '".$email."' and password = '".$password."'"; 
    	$result = mysqli_query($mysqli,$qry);
    	$num_rows = mysqli_num_rows($result);
    	$row = mysqli_fetch_assoc($result);
    	
    	if ($num_rows > 0){ 
    		$set['banostudio'][]=array('user_id' => $row['id'],'name'=>$row['name'],'success'=>'1','msg' =>$app_lang['login_success']); 
    	}else{
    		$set['banostudio'][]=array('msg' =>$app_lang['login_fail'],'success'=>'0');	 
    	}
    
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    
    }
    
    else if($get_method['method_name']=="user_profile"){
        
      	$qry = "SELECT * FROM tbl_users WHERE id = '".$get_method['user_id']."'"; 
    	$result = mysqli_query($mysqli,$qry);
    	 
    	$row = mysqli_fetch_assoc($result);
      				 
        $set['banostudio'][]=array('user_id' => $row['id'],'name'=>$row['name'],'email'=>$row['email'],'phone'=>$row['phone'],'success'=>'1');
    
        header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="user_profile_update"){
        
      	if($get_method['password']!=""){
    		$user_edit= "UPDATE tbl_users SET name='".$get_method['name']."',email='".$get_method['email']."',password='".$get_method['password']."',phone='".$get_method['phone']."' WHERE id = '".$get_method['user_id']."'";	 
    	}else{
    		$user_edit= "UPDATE tbl_users SET name='".$get_method['name']."',email='".$get_method['email']."',phone='".$get_method['phone']."' WHERE id = '".$get_method['user_id']."'";	 
    	}
       	
       	$user_res = mysqli_query($mysqli,$user_edit);
     	 
    	$set['banostudio'][]=array('msg'=>$app_lang['update_success'],'success'=>'1');
    
      	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="songs"){
        
    	$jsonObj= array();	
    
    	$query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid
    	WHERE tbl_ringtone.id='".$get_method['songs_id']."'";
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		 
    		
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    
    		
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    
    
    		array_push($jsonObj,$row);
    	
    	}
    
    	$view_qry=mysqli_query($mysqli,"UPDATE tbl_ringtone SET total_views = total_views + 1 WHERE id = '".$get_method['songs_id']."'");
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();	
    }
    else if($get_method['method_name']=="download"){
        
    	$jsonObj= array();		
    	 
        $view_qry=mysqli_query($mysqli,"UPDATE tbl_ringtone SET total_download = total_download + 1 WHERE id = '".$get_method['download_id']."'");
      
    
    	$total_dw_sql="SELECT * FROM tbl_ringtone WHERE id='".$get_method['download_id']."'";
        $total_dw_res=mysqli_query($mysqli,$total_dw_sql);
        $total_dw_row=mysqli_fetch_assoc($total_dw_res);
        
             
        $jsonObj = array( 'total_download' => $total_dw_row['total_download']);
    
        $set['banostudio'][] = $jsonObj;
        header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="user_id_by_songs"){
        
    	$jsonObj= array();		
    	 
        $use_id=$get_method['user_by_id'];
    	
    	$page_limit=10;
    		
    	$limit=($get_method['page']-1) * $page_limit;
    	
    
        $query="SELECT * FROM tbl_ringtone
    	LEFT JOIN tbl_category ON tbl_ringtone.cat_id= tbl_category.cid 
    	where tbl_ringtone.user_id='".$use_id."' ORDER BY tbl_ringtone.id DESC LIMIT $limit, 10";
    
    	$sql = mysqli_query($mysqli,$query)or die(mysqli_error());
    
    	while($data = mysqli_fetch_assoc($sql))
    	{
    		$row['id'] = $data['id'];
    		$row['cat_id'] = $data['cat_id'];
    		$row['title'] = $data['title'];
    		$row['ringtone_id'] = $data['id'];
    
    		$row['url'] = $data['url'];
    		$row['total_views'] = $data['total_views'];
    		$row['total_download'] = $data['total_download'];
    			
    		$row['cid'] = $data['cid'];
    		$row['category_name'] = $data['category_name'];
    		$row['category_image'] = $file_path.'images/'.$data['category_image'];
    		$row['category_image_thumb'] = $file_path.'images/thumbs/'.$data['category_image'];
    		 
    		array_push($jsonObj,$row);
    	
    	}
    
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();
    }
    else if($get_method['method_name']=="app_details"){
    
    	$jsonObj= array();
    	
    	$query="SELECT * FROM tbl_settings WHERE id='1'";
    	$sql = mysqli_query($mysqli,$query);
    
    	while($data = mysqli_fetch_assoc($sql)){
    	    
    //	$row['publisher_id'] = $data['publisher_id'];
    //	$row['interstital_ad'] = $data['interstital_ad'];
    //	$row['interstital_ad_id'] = $data['interstital_ad_id'];
   // 	$row['interstital_ad_click'] = $data['interstital_ad_click'];
   // 	$row['banner_ad'] = $data['banner_ad'];
   // 	$row['banner_ad_id'] = $data['banner_ad_id'];
    
  //     $row['facebook_interstital_ad'] = $data['facebook_interstital_ad'];
   //    $row['facebook_interstital_ad_id'] = $data['facebook_interstital_ad_id'];
  //  	$row['facebook_interstital_ad_click'] = $data['facebook_interstital_ad_click'];		
 //   	$row['facebook_banner_ad'] = $data['facebook_banner_ad'];
 //   	$row['facebook_banner_ad_id'] = $data['facebook_banner_ad_id'];
     		
     	$row['company'] = $data['company'];
    	$row['email'] = $data['email'];
    	$row['website'] = $data['website'];
    	$row['contact'] = $data['contact'];
    	
    	$row['purchase_code'] = $data['purchase_code'];
       $row['banostudio_key'] = $data['banostudio_key'];
    
    		array_push($jsonObj,$row);
    	}
    	
    	$set['banostudio'] = $jsonObj;
    	
    	header( 'Content-Type: application/json; charset=utf-8' );
        echo $val= str_replace('\\/', '/', json_encode($set,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
    	die();	
    }	
    else
    {
    	$get_method = checkSignSalt($_POST['data']);
    }

?>