377 lines
14 KiB
PHP
Executable File

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Test extends MX_Controller {
function __construct() {
parent::__construct();
$this->load->model('Test_model');
}
public function index() {
// $this->load->library('Loadenv');
// pre($_ENV);die;
// $time=new Date();
// echo date("l jS \of F Y h:i:s A");die;
$this->load->view('home/dashboard'); // just the header file
$this->load->view('input');
$this->load->view('home/footer'); // just the footer file
}
public function check() {
$address = $_POST['street_name'];
$address = $_POST['apt']!=''? $address.' '.$_POST['apt'] : $address;
$zip=$_POST['zip'];
$this->load->helper('map_helper');
// $this->load->helper('address_helper');
$this->load->model('Test_model');
// pre($_POST);die;
if($_POST['api']=='google'){
$data['output']=map_address($address.'+'.$zip);
}else if($_POST['api']=='geocoding'){
// pre($address);pre($zip);die;
$data['output']=$this->geocoding_api($address,$zip);
// pre($data['output']);die;
}else if($_POST['api']=='mapquest'){
// pre($address);pre($zip);die;
$data['output']=$this->mapquest_api($address,$zip);
// pre($data['output']);die;
}else{
$output=address_info($address,$zip);
$formated=[];
if($output['geo_info']['status_code']=200){
$formated['lat']=$output['geo_info']['latlong']['Latitude'];
$formated['long']=$output['geo_info']['latlong']['Longitude'];
}
if($output['address_info']['status_code']=200){
$formated['city']=$output['address_info']['address']['city'];
$formated['county']=$output['address_info']['address']['county'];
$formated['state']=$output['address_info']['address']['state'];
$formated['street']=$output['address_info']['address']['street'];
$state=$this->Test_model->name_by_code($formated['state']);
$formated['state_name']=$state->name;
}
$data['output']=$formated;
}
$data['near_city_google']=nearestCity($data['output']['latitude'],$data['output']['longitude']);
$data['near_city_zipcodestogo']=$this->zipcodestogo_nearest($zip,100);
// $data['ipGeoAddress']=$this->ipgeoAddressAPI();
$data['NearCityByIp']=$this->getNearCityByIp();
pre($data);die;
//
// $ip=$this->getNearCityByIp();
// pre($ip);die;
// echo json_encode($data);
// $this->outputformat($data['output']);
// $this->load->view('home/dashboard'); // just the header file
// $this->load->view('input',$data);
// $this->load->view('home/footer'); // just the footer file
}
function getIP() {
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
}
}
public function getNearCityByIp($ip='103.217.235.3'){
$ip=$this->getIP();
// return $ip;
// echo 'getNearCityByIp';
if($ip=='::1')
$ip='34.77.181.223';
$response=json_decode(file_get_contents('http://getnearbycities.geobytes.com/GetNearbyCities?radius=100&locationcode='.$ip), true);
// return $output;
$output=[];
if($response){
$i=0;
foreach ($response as $set) {
$output[$i]['city']=$set[1];
$output[$i]['Kilometres']=$set[7];
$output[$i]['Miles']=$set[11];
$i++;
}
// pre($output);
return $output;
}
}
public function zipcodestogo_nearest($zip='',$radious='',$max_count=12) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.zipcodestogo.com/radius/radius-search.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post_data = "zipcode=".$zip."&miles=".$radious."&button=Submit";
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$data2=explode('<br>',$result);
$output=[];
for ($i=2; $i <=count($data2) && $i<$max_count ; $i++) {
$single=explode('-',$data2[$i]);
if(!in_array($single[1], $output) && $single[1]!=''){
$output[]=$single[1];
}
}
$data['city']=$output;
return $output;
// $this->load->view('home/dashboard'); // just the header file
// $this->load->view('input',$data);
// $this->load->view('home/footer'); // just the footer file
}
public function distance() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.zipcodestogo.com/radius/radius-search.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post_data = "zipcode=".$_POST['zip']."&miles=".$_POST['radius']."&button=Submit";
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$data2=explode('<br>',$result);
$output=[];
for ($i=2; $i <=count($data2) ; $i++) {
$single=explode('-',$data2[$i]);
if(!in_array($single[1], $output) && $single[1]!=''){
$output[]=$single[1];
}
}
$data['city']=$output;
pre($data2);die;
// $this->load->view('home/dashboard'); // just the header file
// $this->load->view('input',$data);
// $this->load->view('home/footer'); // just the footer file
}
public function geocoding_api($address,$zip){
$this->load->model('Test_model');
// return $address.$zip;
// $apiKey = 'd17faffa0a6feff29ee9386dfed2963a'; // usgeocoder.com API KEY.
// $prepAddr = str_replace(' ','+',$address);
$url = "https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address=".urlencode($address)."+".$zip."&benchmark=Public_AR_Census2020&vintage=Census2010_Census2020&format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$responseJson = curl_exec($ch);
curl_close($ch);
$response = json_decode($responseJson);
if(isset($response->result->addressMatches[0]->addressComponents->state))
$output['state_code']=$response->result->addressMatches[0]->addressComponents->state;
if(isset($response->result->addressMatches[0]->addressComponents->city))
$output['city']=$response->result->addressMatches[0]->addressComponents->city;
if(isset($response->result->addressMatches[0]->coordinates->x))
$output['latitude']=$response->result->addressMatches[0]->coordinates->x;
if(isset($response->result->addressMatches[0]->coordinates->y))
$output['longitude']=$response->result->addressMatches[0]->coordinates->y;
if(isset($response->result->addressMatches[0]->geographies->States[0]->BASENAME))
$output['stateName']=$response->result->addressMatches[0]->geographies->States[0]->BASENAME;
if(isset($response->result->addressMatches[0]->geographies->Counties[0]->BASENAME))
$output['county']=$response->result->addressMatches[0]->geographies->Counties[0]->BASENAME;
return $output;
}
public function mapquest_api($address,$zip){
$this->load->model('Test_model');
$apiKey = MAPQUEST_API_KEY;
$prepAddr = $address.','.$zip;
$url = "https://www.mapquestapi.com/geocoding/v1/address?key=".$apiKey."&location=".urlencode($prepAddr)."";
// return $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$responseJson = curl_exec($ch);
curl_close($ch);
$response = json_decode($responseJson);
if(isset($response->results[0]->locations[0]->adminArea5))
$output['city']=$response->results[0]->locations[0]->adminArea5;
if(isset($response->results[0]->locations[0]->adminArea4))
$output['county']=$response->results[0]->locations[0]->adminArea4;
if(isset($response->results[0]->locations[0]->adminArea3)){
$output['state_code']=$response->results[0]->locations[0]->adminArea3;
$state=$this->Test_model->name_by_code($output['state_code']);
$output['state_name']=$state->name;
}
if(isset($response->results[0]->locations[0]->latLng->lat))
$output['latitude']=$response->results[0]->locations[0]->latLng->lat;
if(isset($response->results[0]->locations[0]->latLng->lng))
$output['longitude']=$response->results[0]->locations[0]->latLng->lng;
return $output;
}
public function ipgeoAddress($ip=NULL){
$res=$this->ipgeoAddressAPI($ip);
echo '<pre>'; print_r($res);
}
public function ipgeoAddressAPI($ip=NULL){
$apiKey = '7cba03079a814ebcbd04059e7830e2fa';
if($ip){
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
}else{
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$responseJson = curl_exec($ch);
curl_close($ch);
$response = json_decode($responseJson);
return $response;
}
public function outputformat($data){
echo '<pre>';
foreach($data as $key=>$value){
echo $key.'='.$value.'<br>';
}
}
/********************Test CORN */
public function test_corn(){
exit(0);
$this->load->model('Test_model');
$data['url']=current_url();
$data['time']=date('Y-m-d H:i:s');
date_default_timezone_set("UTC");
$data['time_utc']=date('Y-m-d H:i:s');
$this->Test_model->inset_test_corn($data);
// pre($data);
}
public function testEmailSend(){
$to_email=$this->input->get('to');
$permission=$this->input->get('pw');
if($permission=='hgsdtd52fd3e'){
if($to_email!=''){
$from=array(
// 'name' => 'WeCuro Admin',
// 'email' => 'naransaha1111@gmail.com',
'name'=>'WeCuro',
'email'=>'info@wecuro.com'
);
$subject='Test Email';
$message="Hello this is a test mail!";
send_email($from,$to_email,$subject,$message);
echo "mail sent successfully";
}else{
echo "need recipient email";
}
}else{
echo "Permission denied";
exit(0);
}
}
function pdf_create_new(){
exit(0);
$this->load->helper('generatepdf_helper');
$id=1000;
$unique_id=str_pad($id,6,"0",STR_PAD_LEFT);
/*pdf-1*/
[$basic_data,$form_data,$image_data]=[[],[],[]];
$basic_data=[
'slug'=>'nursing_assessment_page_1_',
'unique_id'=>$unique_id,
'pdf_file'=>'systemfiles/testpdfs/test1.pdf',
'pdf_upload_path'=>'uploads/testpdfs/nurse_assessment_'.$unique_id.'/'
];
$form_data=[
'patient_name'=>'Naran Saha',
'patient_dob'=>'01/05/1997'
];
$pdf_data[]=(object)[
'basic_data'=>isset($basic_data)?$basic_data:[],
'form_data'=>isset($form_data)?$form_data:[],
'image_data'=>isset($image_data)?$image_data:[]
];
/*pdf-1*/
/*pdf-2*/
[$basic_data,$form_data,$image_data]=[[],[],[]];
$basic_data=[
'slug'=>'nursing_assessment_page_2_',
'unique_id'=>$unique_id,
'pdf_file'=>'systemfiles/testpdfs/test2.pdf',
'pdf_upload_path'=>'uploads/testpdfs/nurse_assessment_'.$unique_id.'/'
];
$form_data=[
'location'=>'Kolkata',
'frequency'=>'20'
];
$image_data[]=(object)[
'image_file'=>'uploads/testpdfs/body.png',
'x'=>48,
'y'=>155,
'w'=>72,
'h'=>52
];
$image_data[]=(object)[
'image_file'=>'uploads/testpdfs/feet.png',
'x'=>125,
'y'=>162,
'w'=>70,
'h'=>40
];
$pdf_data[]=(object)[
'basic_data'=>isset($basic_data)?$basic_data:[],
'form_data'=>isset($form_data)?$form_data:[],
'image_data'=>isset($image_data)?$image_data:[]
];
/*pdf-2*/
$pdfBulkDatas=(object)[
'common'=>(object)[
'id'=>$id,
'unique_id'=>$unique_id,
'slug'=>'nursing_assessment_',
'upload_path'=>'uploads/testpdfs/nurse_assessment_'.$unique_id.'/'
],
'pdf_datas'=>$pdf_data
];
$pdf_response=ci_single_page_pdf_creation($pdfBulkDatas);
pre($pdf_response);
}
public function getDistance(){
try{
$this->load->helper("map_helper");
$x1=37.77712;
$y1=-122.41966;
$x2=38.25489;
$y2=-85.76666;
$distance=distanceApi($x1,$y1,$x2,$y2);
pre($distance);
}catch(Exception $e){
$getMsg="Test - getDistance: ".$e->getMessage();
echo $getMsg;
}
}
}