Path : /var/www/html/main/
File Upload :
Current File : /var/www/html/main/api.php

<?php
/*!
 * Copyright Anucha Puangpaka
 * Contact anucha.ppk@icloud.com 062-479-9836
 */

include('ap.php');
include('connDB.php');

if($_GET['nu']=="ap_settings"){
	header("Access-Control-Allow-Origin: *");
  header("Content-Type: application/json; charset=UTF-8");

  $headers = apache_request_headers();

  if((isset($headers['Token']) && $headers['Token']=="$token") || $_GET['Token']=="$token"){
		
		$sql = "select * from ap_settings";
		$query = mysqli_query($conn, $sql);
		$num_fields = mysqli_num_fields($query);
		$result = array();
		while($rows = mysqli_fetch_array($query)){
			$result_field = array();
			for($i=0; $i<$num_fields; $i++){
				$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
			}
			array_push($result,$result_field);
		}
		echo json_encode($result);

	}
}

if($_GET['nu']=="ap_pages"){
	header("Access-Control-Allow-Origin: *");
  header("Content-Type: application/json; charset=UTF-8");

  $headers = apache_request_headers();

  if((isset($headers['Token']) && $headers['Token']=="$token") || $_GET['Token']=="$token"){
		
		if(empty($_GET['id'])){
			if(empty($_GET['q'])){
				$sql = "select * from ap_pages order by date_time desc";
			}else{
				$sql = "select * from ap_pages where title like '%$_GET[q]%' or info like '%$_GET[q]%' or info2 like '%$_GET[q]%' order by date_time desc";
			}
		}else{
			$sql = "select * from ap_pages where id='$_GET[id]'";
		}
		$query = mysqli_query($conn, $sql);
		$num_fields = mysqli_num_fields($query);
		$result = array();
		while($rows = mysqli_fetch_array($query)){
			$result_field = array();
			for($i=0; $i<$num_fields; $i++){
				$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
			}
			array_push($result,$result_field);
		}
		echo json_encode($result);

	}
}

if($_GET['nu']=="checkip"){
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");

  $headers = array("Content-Type: application/json", "Method: GET", "");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "http://ip-api.com/json/$_GET[ip]");
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($ch);
  curl_close($ch);

  echo $result;
}

if($_GET['nu']=="statistic"){
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");

	$sql = "select count(id) as total from ap_counters where lang='$_GET[q2]'";
	$query = mysqli_query($conn,$sql);
	$num_fields = mysqli_num_fields($query);
	$result = array();
	while($rows = mysqli_fetch_array($query)){
		$result_field = array();
		for($i=0; $i<$num_fields; $i++){
			$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
		}
		array_push($result,$result_field);
	}

	echo json_encode($result);
}

if($_GET['nu']=="slides"){
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");

	$d = date('Ymd');
	$sql = "select name,images,url_link as link from ap_slides where date_time>'$d' and place='1' and status='1' order by date_time asc";
	$query = mysqli_query($conn,$sql);
	$num_fields = mysqli_num_fields($query);
	$result = array();
	while($rows = mysqli_fetch_array($query)){
		$result_field = array();
		for($i=0; $i<$num_fields; $i++){
			$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
		}
		array_push($result,$result_field);
	}

	echo json_encode($result);
}

if($_GET['nu']=="news"){
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");

	$sql = "select * from ap_pages order by date_time desc";
	$query = mysqli_query($conn,$sql);
	$num_fields = mysqli_num_fields($query);
	$result = array();
	while($rows = mysqli_fetch_array($query)){
		$result_field = array();
		for($i=0; $i<$num_fields; $i++){
			$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
		}
		array_push($result,$result_field);
	}

	echo json_encode($result);
}

if($_GET['nu']=="get_news"){
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");

	$data = json_decode(file_get_contents("php://input"));
	$id = $data->playlistId;
	$sql = "select * from ap_pages where id='$id' ";
	$query = mysqli_query($conn,$sql);
	$num_fields = mysqli_num_fields($query);
	$result = array();
	while($rows = mysqli_fetch_array($query)){
		$result_field = array();
		for($i=0; $i<$num_fields; $i++){
			$result_field[mysqli_fetch_field_direct($query,$i)->name] = $rows[$i];
		}
		array_push($result,$result_field);
	}
	
	echo json_encode($result);
}

mysqli_close($conn);
?>