<?php
include_once 'admin/config.php';
$connection=mysqli_connect('localhost','ridhinyh_new_ur','nuUBcNPn$RKC','ridhinyh__new_travel') or die(mysqli_connect_error());
//Authentication funtion returns tokenid
$sel_qry= "select * from tokenAuthenticate where generated_date_time = '$today_dateTime'";
$sel_token_Q= mysqli_query($connection,$sel_qry) or die(mysqli_error($con));

if(mysqli_num_rows($sel_token_Q)>0){
$tokenData=mysqli_fetch_array($sel_token_Q);
global $tokenID;
if(!isset($_SESSION['tokenVal'])){
$tokenID=$tokenData['tokenID'];
$_SESSION['tokenVal']=$tokenID;
}else{
$tokenID=$_SESSION['tokenVal'];
}
}else{
$ClientId="tboprod";
$UserName="JAIR005";
$EndUserIp="103.53.43.82";
$Password="#tbolive#005@";
$data=array("ClientId"=>"$ClientId","UserName"=>"$UserName","EndUserIp"=>"$EndUserIp","Password"=>"$Password");
$data_string=json_encode($data);
//$data_string;
$ch=curl_init('https://api.travelboutiqueonline.com/SharedAPI/SharedData.svc/rest/Authenticate');
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/json','Content-Length:'.strlen($data_string)));
$result = curl_exec($ch);
curl_close($ch);
$jsona = json_decode($result,true);

if($jsona['Status']=='1'){
if(!isset($_SESSION['tokenVal'])){
global $tokenID;
$tokenID= $jsona['TokenId'];
$_SESSION['tokenVal']=$tokenID;
}else{
$tokenID=$_SESSION['tokenVal'];
}
//insert token ID
$insertData = "insert into tokenAuthenticate(tokenID,generated_date_time,expire_date_time,authenticationLogs) values('$tokenID','$token_gen_dateTime','$token_exp_dateTime','$result')";
$ins_token_Q= mysqli_query($connection,$insertData) or die(mysqli_error($con));

}
else{
return '0';
}

}



class Admin{
//select place name
function select_all_place($table,$cond){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name $cond order by place_name") or die("Select query fail".mysqli_error($con));
return $qry;
}

function select_all_flight_code($table,$cond){
$this->table_name=$table;
global $con;
$select_Q = "SELECT * FROM $this->table_name $cond";
$qry=mysqli_query($con,$select_Q) or die(mysqli_error($con));
return $qry;
}

//select middla package
function select_all_package($table,$cond){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE place_name='$cond' order by id") or die("Select query fail".mysqli_error($con));
return $qry;
}
//select middla package
function select_all_related_package($table,$cond){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE type='$cond' order by rand() limit 10") or die("Select query fail".mysqli_error($con));
return $qry;
}
//select middla package
function select_all_package1($table){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT distinct place_name FROM $this->table_name  WHERE type='L' order by id") or die("Select query fail".mysqli_error($con));
return $qry;
}

//select middla package
function select_all_package2($table){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT distinct place_name FROM $this->table_name  WHERE type='M' order by id") or die("Select query fail".mysqli_error($con));
return $qry;
}

//select middla package
function select_all_package3($table){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT distinct place_name FROM $this->table_name  WHERE type='R' order by id") or die("Select query fail".mysqli_error($con));
return $qry;
}

//select all tour package
function select_all_tour_pack($table,$pid){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE place_name='$pid' order by id ") or die("Select query fail".mysqli_error($con));
return $qry;
}
//select all tour package time table
function select_all_tour_pack_time($table,$hid,$pid){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE heading='$hid' and package='$pid' order by id") or die("Select query fail".mysqli_error($con));
return $qry;
}
//select all tour cost
function select_tour_cost($table,$pid){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE package='$pid' order by id ") or die("Select query fail".mysqli_error($con));
return mysqli_fetch_array($qry);
}
//select other information
function select_other_info($table,$pid){
$this->table_name=$table;
global $con;
$qry=mysqli_query($con,"SELECT * FROM $this->table_name  WHERE package='$pid'  ") or die("Select query fail".mysqli_error($con));
return mysqli_fetch_array($qry);
}



}//close of class
?>