<?php

$GLOBALS['STtax'] = 1;
$GLOBALS['SBCesstax'] = 0;
$GLOBALS['KKCesstax'] = 0;
$GLOBALS['currDateTime'] = date('Y-m-d H:i:s');
$GLOBALS['currDate']= date('Y-m-d');
$GLOBALS['currTime']= date('H:i:s');

//$con_obj	= mysql_connect('localhost','steelmin_apitest','apitest1@3') or die('On Maintenance, please try again in some minutes.');
//$seldb		= mysql_select_db("steelmin_api_test", $con_obj) or die(mysql_error());

//include_once ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
include_once("/home/steelmin/public_html/inc/config1.php");
include_once("/home/steelmin/public_html/hf.php");

//require("cf.php");
//require("cf_new.php");
//ini_set('display_errors',1);

/*
$evnts = getEvents();
print_R($evnts); */
//$type = "All, Upcoming, Expaired";
function getEventsOptions($event_id=0, $user_id=0, $options='', &$optionsArr, &$option_type){
	//$optionsArr = array();
	//$option_type = 1;
	include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
	if($options){
		$options_arry = explode(',',$options);
		
		
		if($user_id){
			
			/**
			  Added by anamika for special case of event 23 and 25
			  to make the participant list common for both event 
			  date : 21 August 2019
			*/
			/*$_sql = "SELECT registering_id
			FROM `final_status`
			WHERE (`complementary` = 'Y' || `closed` = 'Y')
			AND `eventid` = '$event_id' and registering_id='$user_id'";*/
			
			if($event_id==23 || $event_id==25){
			$_sql = "SELECT registering_id
			FROM `final_status`
			WHERE (`complementary` = 'Y' || `closed` = 'Y')
			AND `eventid` in (23,25) and registering_id='$user_id'";
			}else{
			  $_sql = "SELECT registering_id
				  FROM `final_status`
				  WHERE (`complementary` = 'Y' || `closed` = 'Y')
				  AND `eventid` = '$event_id' and registering_id='$user_id'";
			}
			
			
			
			$is_active = qryToCommaSepString($_sql);
			if($is_active)
				$option_type = 3;
			else
				$option_type = 2;			
		}		
		
		if($option_type!=3){
			$diff_a = array('scan_qr_code', 'chat_history','saved_contacts');
			$options_arry_1 = array_diff($options_arry, $diff_a);
		}else{
			$options_arry_1 = array_diff($options_arry, array('book_ticket'));			
		}
		
		foreach($options_arry_1 as $key=>$val){
			if(in_array($option_type, array_keys($GLOBALS['options_menu_items'][$val])) !== false ){
				$optionsArr[] = $val;
			}
		}
	}
	include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );
}

function getEvents($type='All', $user_id = '', $event_id=''){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    $whrcond="1";

    if('Upcoming'==$type)
        $whrcond = "status >= 0 ";
    if('Expired'==$type)
        $whrcond = "status = 0";   
	 
	if(!empty($event_id)){
        if($whrcond!="1")
			$whrcond .= " and id = $event_id";  
		else
			$whrcond = " id = $event_id";  
	}
	
	$_sql ="
		select floor_plan, id as event_id, event_name, event_start_date, event_end_date, event_venue, agenda, status, event_image, event_video, options, tentative_itinerary
		from tbl_sm_events_events
		where $whrcond
		and status <> 3
		order by status, id desc
	";
	$rs = mysql_query($_sql)or die(mysql_error().$_sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        $thumb ='';$image=''; $event_video=$row['event_video'];
	
        if('' != $row['event_image']){
            $thumb = 'https://www.steelmint.com/sm_group_events/images/events/thumb_'.$row['event_image'];
            $image = 'https://www.steelmint.com/sm_group_events/images/events/'.$row['event_image'];
        }

        $venue_arr = explode(",", $row['event_venue']);
        $event_venue='';
        $event_location='';

        /* if($tot = count($venue_arr) >=2 ){
            $event_location = $venue_arr[$tot-1];
            $event_venue= str_replace(','.$event_location, "", $row['event_venue']);
        }else{
            $event_venue='';
            $event_location=$row['event_venue'];
        } */
		$event_location=$row['event_venue'];
        $event_start_date = $row['event_start_date'];
        $event_end_date = $row['event_end_date'];
        $options = $row['options'];
        $event_id = $row['event_id'];
		$floor_plan = $row['floor_plan'];
		$tentative_itinerary = $row['tentative_itinerary'];
		
		$optionsArr = array();
		$option_type = 1;
		getEventsOptions($event_id, $user_id, $options, $optionsArr, $option_type);
		/* if($options){
			$options_arry = explode(',',$options);
			
			
			if($user_id){
				$_sql = "SELECT registering_id
				FROM `final_status`
				WHERE (`complementary` = 'Y' || `closed` = 'Y')
				AND `eventid` = '$event_id' and registering_id='$user_id'";
				
				$is_active = qryToCommaSepString($_sql);
				if($is_active)
					$option_type = 3;
				else
					$option_type = 2;			
			}		
			
			
			foreach($options_arry as $key=>$val){
				if(in_array($option_type, array_keys($GLOBALS['options_menu_items'][$val])) !== false ){
					$optionsArr[] = $val;
				}
			}
		} */
			
        $event_date = null ;
		if( $event_start_date == '0000-00-00' )
			$event_date = 'Coming Soon!!';
        elseif($event_start_date > '2000-01-01' && $event_start_date!=$event_end_date)
            $event_date = date("d", strtotime($event_start_date)).'-'.date("d M Y", strtotime($event_end_date));
        else
            $event_date = date("d M Y", strtotime($event_start_date));

        if($row['status']==1){
            $_rs_array[] = [
                'id'=>$row['event_id'],
                'name'=>$row['event_name'],
                'timestamp'=>$event_date,
                'venue'=>$event_venue,
                'floor_plan'=>$floor_plan,
				'tentative_itinerary'=>$tentative_itinerary,
                'location'=>$event_location,
                'agenda'=>$row['agenda'],
                'thumb_img'=>$thumb,
                'img'=>$image,
                'video'=>$event_video ,
                'enable' => true,
				'speakers' => getSpeakers($event_id),
				'active_for_event' => $option_type,
				'item_options' => $optionsArr 
            ];
        }else{
            $_rs_array[] = [
                'id'=>$row['event_id'],
                'name'=>$row['event_name'],
                'timestamp'=>$event_date ,
                'venue'=>$event_venue,
				'floor_plan'=>$floor_plan,
				'tentative_itinerary'=>$tentative_itinerary,
                'location'=>$event_location,
                'agenda'=>$row['agenda'],
                'thumb_img'=>$thumb,
                'img'=>$image,
                'video'=>$event_video ,
                'enable' => false ,
                'speakers' => getSpeakers($event_id),
				'active_for_event' => $option_type,
                'item_options' => $optionsArr 
            ];
        }
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;

}

function getEventsOld($type='All'){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    $whrcond="1";

    if('Upcoming'==$type)
        $whrcond = "status >= 1";
    if('Expired'==$type)
        $whrcond = "status = 0";

    $rs = mysql_query("
		select id as event_id, event_name, event_start_date, event_end_date, event_venue, agenda, status, event_image, event_video
		from tbl_sm_events_events
		where $whrcond
		order by status, event_start_date desc
	")or die(mysql_error());

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        $thumb ='';$image=''; $event_video=$row['event_video'];
	
        if('' != $row['event_image']){
            $thumb = 'https://www.steelmint.com/sm_group_events/images/events/thumb_'.$row['event_image'];
            $image = 'https://www.steelmint.com/sm_group_events/images/events/'.$row['event_image'];
        }

        $venue_arr = explode(",", $row['event_venue']);
        $event_venue='';
        $event_location='';

        /* if($tot = count($venue_arr) >=2 ){
            $event_location = $venue_arr[$tot-1];
            $event_venue= str_replace(','.$event_location, "", $row['event_venue']);
        }else{
            $event_venue='';
            $event_location=$row['event_venue'];
        } */
		$event_location=$row['event_venue'];
        $event_start_date = $row['event_start_date'];
        $event_end_date = $row['event_end_date'];

        $event_date = null ;

        if($event_start_date > '2000-01-01' && $event_start_date!=$event_end_date)
            $event_date = date("d", strtotime($event_start_date)).'-'.date("d M Y", strtotime($event_end_date));
        else
            $event_date = date("d M Y", strtotime($event_start_date));

        if($row['status']==1){
            $_rs_array[] = [
                'id'=>$row['event_id'],
                'name'=>$row['event_name'],
                'timestamp'=>$event_date,
                'venue'=>$event_venue,
                'location'=>$event_location,
                'agenda'=>$row['agenda'],
                'thumb_img'=>$thumb,
                'img'=>$image,
                'video'=>$event_video ,
                'enable' => true ,
            ];
        }else{
            $_rs_array[] = [
                'id'=>$row['event_id'],
                'name'=>$row['event_name'],
                'timestamp'=>$event_date ,
                'venue'=>$event_venue,
                'location'=>$event_location,
                'agenda'=>$row['agenda'],
                'thumb_img'=>$thumb,
                'img'=>$image,
                'video'=>$event_video ,
                'enable' => false ,
            ];
        }
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;

}

/////////////////////////////Speakers list//////////////
/*
$event_id='5';//optional default it returns current event Speakers list
$evnts = getSpeakers();
print_R($evnts); */
function getSpeakers($event_id=''){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    $whrcond="1";

    if($event_id=='')
        $event_id = getActiveEventId();

    $whrcond = " t.event_id = $event_id";
    //$whrcond = " t.event_id = '$event_id' or like '%,$event_id' or like '$event_id,%'";
//    $sql ="
//		select s.id, s.name,s.designation,s.company,s.basic_profile,t.topic,t.event_id,image
//		from tbl_sm_events_speakers as s
//		left outer join
//		tbl_sm_events_speakers_topic as t
//		ON s.id=t.speaker_id
//		where $whrcond
//		order by id asc
//	";
//    $sql = "
//		select s.*, t.topic
//		from
//		(
//			select 	id, name, designation, company, basic_profile, $event_id as eventId
//			from 	tbl_sm_events_speakers
//			where  	( event_id like ',$event_id,' or event_id like '%,$event_id' or event_id like '$event_id,%' or event_id = '$event_id')
//		) as s
//
//		left outer join tbl_sm_events_speakers_topic as t ON s.id = t.speaker_id
//		AND  t.event_id = $event_id
//		order by 2 asc
//	";
//    $sql = "
//        select s.*, t.topic
//        from
//        (
//        select id, name, designation, company, basic_profile, $event_id as event_id, image
//        from tbl_sm_events_speakers
//        where  	( event_id like ',$event_id,' or event_id like '%,$event_id' or event_id like '$event_id,%' or event_id = '$event_id')
//        ) as s
//
//        left outer join tbl_sm_events_speakers_topic as t ON s.id = t.speaker_id
//        AND  t.event_id = $event_id
//        order by 2 asc
//        ";

    /*$sql = "
		select 	s.id,
				t.topic,
				s.image,
				s.event_id,
				s.name,
				s.designation,
				s.company,
				s.basic_profile,
				
				s.country
				
		from
		(
			select 	id, name, designation, company, basic_profile, $event_id as event_id, image, country
			from 	tbl_sm_events_speakers
			where  	( event_id = '$event_id')
		) as s

		left outer join tbl_sm_events_speakers_topic as t ON s.id = t.speaker_id
		AND  t.event_id = $event_id
		order by 2 asc
	";*/

    $sql = "SELECT es.`id`, es.`event_id`, es.`name`, es.`designation`, es.`company`, es.`country`, es.`basic_profile`, es.`image`";
    $sql .= " FROM `tbl_sm_events_speakers` es WHERE es.`event_id` = " . $event_id . " order by  es.`name`";

    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)) {
        $thumb ='';
        $image='';

        if($row['image']){
            $thumb = 'https://www.steelmint.com/sm_group_events/images/events/speakers/thumb_'.$row['image'];
            $image = 'https://www.steelmint.com/sm_group_events/images/events/speakers/'.$row['image'];
        }

        $topics = array();
        $sql = "SELECT `topic`, `presentation_url` FROM `tbl_sm_events_speakers_topic` WHERE `speaker_id` = " . $row['id'] . " AND `event_id` = " . $row['event_id'];
        $topicQuery = mysql_query($sql);
        if($topicQuery != false && mysql_num_rows($topicQuery) > 0) {
            while($topic = mysql_fetch_assoc($topicQuery)) {
                $topics[$topic['topic']] = $topic['presentation_url'];
            }
        }

        $subjects = array_keys($topics);
		
		if(empty($topics))
			$topics = json_encode($topics, JSON_FORCE_OBJECT);
		 
        $_rs_array[] = array(
            'id'            =>  $row['id'] ,
            'event_id'      =>  $row['event_id'],
            'name'          =>  str_replace(PHP_EOL, '', $row['name']),
            'position'      =>  $row['designation'],
            'company'       =>  $row['company'] . ", " . $row['country'],
            'desc'          =>  $row['basic_profile'] ,
            'subject'       =>  isset($subjects[0]) ? $subjects[0] : '',
            'thumb_img'     =>  $thumb,
            'image'         =>  $image,
            'topics'        =>  $topics
        );
    }
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;
}

//Capitalize the First Letter of All Words in a string and if a word is 3 characters or less, make the whole word Capitalized in the string
function customUCWord($string){
	$string = strtolower($string);
	$array = explode(' ', $string);
	foreach($array as $k => $v) {
		$v = rtrim($v, ',');
		if(strlen($v) <= 3) {
			$array[$k] = strtoupper($v); //completely upper case
		}
		else {
			$array[$k] = ucfirst($v); //only first character upper case
		}
	}
	return $string = implode(' ', $array);
}

/////////////////////////////Sponsers list//////////////
/*
$event_id=5;//optional default it returns current event Speakers list
$type='';//optional exhibitor/sponser
$evnts = getSponsors();
//$evnts = getSponsors($event_id,$type);
print_R($evnts); */

function getSponsors($event_id='', $type=''){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    if($event_id=='')
        $event_id = getActiveEventId();

    $whrcond = " (  event_id = $event_id ) ";


    if(''!=$type)
        $whrcond .= " AND sponser_or_exhibitor = '$type'";
    $sql = "
		select id , event_id, sponser_type, company, logo, location, sponser_website_link, sponser_or_exhibitor
		from tbl_sm_events_sponsors
		where $whrcond
		order by 
		CASE 		
			WHEN sponser_type = 'Principal Sponsor' then 1
			WHEN sponser_type = 'Platinum Sponsor' then 2
			WHEN sponser_type = 'Associate Platinum Sponsor' then 3
			WHEN sponser_type = 'Gold Sponsor' then 4
			WHEN sponser_type = 'Associate Gold Sponsor' then 5
			WHEN sponser_type = 'Silver Sponsor' then 6
			WHEN sponser_type = 'Lunch Sponsor' then 7
			WHEN sponser_type = 'Delegate Sponsor' then 8
			WHEN sponser_type = 'Delegate Kit Sponsor' then 9
			WHEN sponser_type = 'Associate Sponsor' then 10
			ELSE 99
		END
	";

    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    $_rs_array['exhibitors'] = [];

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        $thumb ='';$image='';
        if($row['logo']){
            $thumb = 'https://www.steelmint.com/sm_group_events/images/events/sponsers/thumb_'.$row['logo'];
            $image = 'https://www.steelmint.com/sm_group_events/images/events/sponsers/'.$row['logo'];
        }

        if($row['sponser_or_exhibitor']=='sponsor'){
            $_rs_array['sponsors'][$row['sponser_type']][] = array(
                'id'        => strval($row['id']) ,
                'event_id'  =>$row['event_id'],
                'name'      =>$row['company'],
//                'region'    =>$row['state'].", ".$row['city'],
                'region'    => $row['location'] ,
                'website'   =>$row['sponser_website_link'],
                'thumb_img'=>     $thumb,
                'img'=>$image
            );

        }else if ($row['sponser_or_exhibitor']=='exhibitor'){
            $_rs_array['exhibitors'][] = array(
                'id' => strval($row['id']) ,
                'event_id'=>$row['event_id'],
                'name'=>$row['company'],
                'region'=>$row['location'],
                'website'=>$row['sponser_website_link'],
                'thumb_img'=>$thumb,
                'img'=>$image
            );
        }
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;
}

/////////////////////////////Sponsers list//////////////
/*
$event_id=5;//optional default it returns current event Speakers list
$type='';//optional exhibitor/sponser
$evnts = getSponsors();
//$evnts = getSponsors($event_id,$type);
print_R($evnts); */

function getAccommodations($event_id=''){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    if($event_id=='')
        $event_id = getActiveEventId();

    $whrcond = " (  event_id = $event_id ) ";

    $sql = "
		select name, distance_frm_venue, price_per_night, website, address, location, email, phone_no, concat('https://www.steelmint.com/sm_group_events/images/events/accomodation/', thumb_image) as thumb_image, images, f_description , f_rating
		from tbl_sm_events_accomodation
		where $whrcond		
	";

    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    $_rs_array['accommodations'] = [];

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        if($row['images']){
			$a =  "https://www.steelmint.com/sm_group_events/images/events/accomodation/" . str_replace(",", ',https://www.steelmint.com/sm_group_events/images/events/accomodation/', $row['images']);
			$row['images'] = explode(',', $a);
        }else
			$row['images'] = array();		
		
        $_rs_array['accommodations'][] = $row;
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;
}

/////////////////////////////Participant list//////////////
//
//$event_id=5;//optional default it returns current event Speakers list
//
////1) for all delegates/Participant
////$evnts = getParticipant($event_id);
//
////2) with fillters => delegates/Participant
////$fillters['country'] = '5,6,15';///comma seprated values
//$fillters['company'] = 'steel,SteelMint';///comma seprated values
////$fillters['designation'] = '1,9,2,5';///comma seprated values
////$fillters['profile'] = '35,34,37';///comma seprated values
//
//$evnts = getParticipant($event_id,$fillters);
//print_R($evnts);

///delegate_profile = companytype in tbl_members
/*
*/
//print_R($evnts);
function getDelegatesIds($event_id){
    if($event_id=='')
        $event_id = getActiveEventId();
    //$whrcond = " event_id = $event_id and inv_no <> '' ";
	if($event_id==23 || $event_id==25  ){
		$whrcond = " event_id in (23,25)";
	}
	else
		$whrcond = " event_id = $event_id ";
    
	if($event_id==23 || $event_id==25  ){
		$whrcond_final_status = " eventid in (23,25)";
	}
	else
		$whrcond_final_status = " eventid = $event_id ";
$_sql = "
		SELECT `delegates_ids`
		FROM `tbl_sm_events_payment_details`
		WHERE $whrcond
		AND `registering_id`
		IN (

		SELECT registering_id
		FROM `final_status`
		WHERE (`closed` = 'Y')
		AND $whrcond_final_status

		)
		AND `inv_no` <> ''
		
		UNION 

		SELECT registering_id
		FROM `final_status`
		WHERE (`complementary` = 'Y' || `closed` = 'Y')
		AND $whrcond_final_status
		
	";
	/* UNION All

		SELECT `memid`
		FROM `tbl_event_tag_mapping`		
		WHERE `tag` = 'CLOSED' 
		group by memid
	*/
	$del_ids =  qryToCommaSepString($_sql);
	$del_arr = array_values(array_unique(array_filter(explode(",",$del_ids))));
	return $del_final_ids = implode(",",$del_arr);
    /* return qryToCommaSepString("
		SELECT delegates_ids
		from tbl_sm_events_payment_details
		where $whrcond
	"); */
}


function getParticipant($event_id='', $fillters=array()){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    include_once ('/home/steelmin/public_html/hf.php');
//    $event_id = 1 ;
    if($event_id=='')
        $event_id = getActiveEventId();

    $delegates_ids = getDelegatesIds($event_id);

//    var_dump($delegates_ids) ;

    if($delegates_ids=='')
        $delegates_ids=0;
//print_r ($fillters);
    $whrcond = " d.id in ($delegates_ids) and d.id<>56350 ";
   /*  if(isset($fillters['profile'])){
        $profile = "'". str_replace( ",", "','", $fillters['profile'])."'";
        $whrcond .= " AND d.companytype in ($profile)";
    } */

    $having='';
    if(isset($fillters['country'])){
        $_contry_ids = $fillters['country'];
        $whrcond .= " AND d.country in ($_contry_ids)";
    }

    if(isset($fillters['company'])){
        $company = "'". str_replace( ",", "','", $fillters['company'])."'";
        $whrcond .= " AND d.company in ($company)";
    }

    /* if(isset($fillters['profile'])){
        $profile = "'". str_replace( ",", "','", $fillters['profile'])."'";
        $having .= " AND delegate_profile in ($profile)";
    } */

     if(isset($fillters['profile']) && '' != $fillters['profile']){
		$short_comptype = "'". str_replace( ",", "','", $fillters['profile'])."'";			
		$comptypeId = qryToCommaSepString("
										select id 
										from tbl_companytype 
										where short_comptype in ($short_comptype) 
									  ");
									 
        if( $comptypeId != '' )
			$whrcond .= " AND d.companytype in ($comptypeId)";
    }

    /* if(isset($fillters['designation'])){
        $designation = "'". str_replace( ",", "','", $fillters['designation'])."'";
        $whrcond .= " AND designation in ($designation)";
    } */

    if($having)$having = " having 1 ".$having;

     $sql = "
		select 
			(SELECT short_comptype from tbl_companytype where id = d.companytype) as company_type,
			d.company_profile,
			d.profile_pic,d.id, 
			
			CASE 
				when d.billing_name = '' then d.name
				else d.billing_name
			END as billing_name, 
			 
			
			job_title, company,
			CASE 
				when send_email_to = 'R' then email
				else addtnl_email
			END as email, 
			CASE 
				when send_sms_to = 'R' then phoneno
				else alternate_mob_no
			END as phoneno,
			c.country as 'location'
		from tbl_members d
		
		left join tbl_state_city sc
		ON d.country=sc.country_id
		AND d.state=sc.state_id
		AND d.city=sc.city_id
		left join tbl_country c
		ON d.country=c.id
		where $whrcond
		group by d.id
		$having
		order by company
	";
    $rs = mysql_query($sql)or die(mysql_error().$sql);
    $_rs_array = array();
    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        $image='';
        if($row['profile_pic']){
			$image = 'https://www.steelmint.com/images/clients/'.$row['profile_pic'];//
			}
		
		if(strlen($row['location']) <= 3)
			$loctn = strtoupper($row['location']);
		else
			$loctn = ucwords(strtolower($row['location']));
		
		$_rs_array[] = array(
            "company_type" => $row['company_type'] ,
            "id" => $row['id'] ,
            'name'=> htmlspecialchars_decode ( trim(str_replace(array("Mr.", "Mr", "Miss", "Miss."), "", $row['billing_name'])), ENT_QUOTES),
            'designation'=>$row['job_title'],
            'company'=> htmlspecialchars_decode($row['company'], ENT_QUOTES),
            'email'=>strtolower($row['email']),
            'phoneno'=>$row['phoneno'],
            'profile'=>htmlspecialchars_decode($row['company_profile'], ENT_QUOTES),
            'region'=>$loctn,
            'thumb_img'=>$image,
            'img'=> $image
        );
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );
    return $_rs_array;
}

//
//$event_id=5
//print_r(getParticipantFilters($event_id));

function getParticipantFilters($event_id=''){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
//    $event_id =1 ;
    if($event_id=='')
        $event_id = getActiveEventId();

    $delegates_ids = getDelegatesIds($event_id);

    $_participant =array();

   /*  $_participant['designation'] = array( ['filter'=>'Director' ],
        ['filter'=>'Executive'],
        ['filter'=>'Manager']
    );

    $_participant['designation'] = array_values($_participant['designation']) ; */

    //$_participant['company'] = array('OMC','NMDC','PIG_IRON');
   /*  $_participant['profile'] = array( ['filter'=>'Broker' ],
        ['filter'=>'Trader'],
        ['filter'=>'Exporter'],
        ['filter'=>'Importer'],
        ['filter'=>'Manufacture']);

    $_participant['profile'] = array_values($_participant['profile']) ; */
    $whrcond = " d.id in ($delegates_ids) and d.id<>56350 ";

/* 	$sql = "
			SELECT 	d.country as country_id, 
					c.country AS country_name,
					d.company as company_name,
					(SELECT short_comptype from tbl_companytype where id = d.companytype) as short_comptype
			from tbl_members d
			left outer join	tbl_country c
			ON d.country=c.id
			where $whrcond
	";
	 $rs = mysql_query($sql)or die(mysql_error().$sql);
    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
		//form country filter
        if(!empty($row['country_id'] ) )
            $_participant['country'][$row['country_id']] = array(
                "filter" => $row['country_name'] );
        else
            $_participant['country']['0'] = array( "filter" => 'Others' ) ;
		
		//form comapny name filter
        if(!empty($row['company_name']))
            $_participant['company'][] = array(
                "filter" => trim($row['company_name']));
		
		//form comapny type filter
        if(!empty($row['short_comptype']))
            $_participant['profile'][] = array(
                "filter" => trim($row['short_comptype']));
    }
	$_participant['country'] = (array_values($_participant['country'])) ;
	$_participant['profile'] = (array_values($_participant['profile'])) ; 	
	$_participant['company'] = (array_values($_participant['company'])) ;  */	
	$sql = "
			SELECT 	d.country as country_id, 
					TRIM(c.country) AS country_name,
					d.company as company_name,
					(SELECT short_comptype from tbl_companytype where id = d.companytype) as short_comptype
			from tbl_members d
			left outer join	tbl_country c
			ON d.country=c.id
			where $whrcond
	";
	$result = mysql_query($sql) or die("Error: " . mysql_error() . "<br />" . $sql);

	$tempCountries = array();
	$tempCompanies = array();
	$tempProfiles = array();
	$profiles = array();
	$companies = array();
	$countries = array();
	
	if(mysql_num_rows($result) > 0) {
		while ($row = mysql_fetch_assoc($result)) {
			if($row['country_id'] && !empty($row['country_name'])) {
				if(strlen($row['country_name']) <= 3) {
					$location = strtoupper($row['country_name']);
				} else {
					$location = ucwords(strtolower($row['country_name']));
				}
				$cntryName = $location;
			} else {
				$cntryName = "Others";
			}
			
			if(!in_array($cntryName, $tempCountries)){
				$tempCountries[] = $cntryName;
				$countries[] = array(
					'filter'	=>	$cntryName
				);
			}
			
			$cName = ucwords(strtolower(trim($row['company_name'])));
			if($row['company_name'] && !in_array($cName, $tempCompanies)) {
				$tempCompanies[] = $cName;
				$companies[] = array(
					'filter'	=>	$cName
				);
			}

			if($row['short_comptype'] && !in_array($row['short_comptype'], $tempProfiles)) {
				$tempProfiles[] = $row['short_comptype'];
				$profiles[] = array(
					'filter'	=>	ucwords(strtolower(trim($row['short_comptype'])))
				);
			}
		}
	}

/* 	 sort($tempProfiles);
	 sort($tempCompanies);
	 sort($tempCountries);
 */
	usort($profiles, function($a, $b) {
		if($a['filter']==$b['filter']) return 0;
		return $a['filter'] > $b['filter']?1:-1;
	});

	usort($companies, function($a, $b) {
		if($a['filter']==$b['filter']) return 0;
		return $a['filter'] > $b['filter']?1:-1;
	});

	usort($countries, function($a, $b) {
		if($a['filter']==$b['filter']) return 0;
		return $a['filter'] > $b['filter']?1:-1;
	});
			

/* 	if($tempProfiles) {
		foreach($tempProfiles as $tempProfile) {
			$profiles[] = array(
				'filter'	=>	$tempProfile
			);
		}
	}

	if($tempCompanies) {
		foreach($tempCompanies as $tempCompany) {
			$companies[] = array(
				'filter'	=>	$tempCompany
			);
		}
	}

	if($tempCountries) {
		foreach($tempCountries as $tempCountry) {
			$countries[] = array(
				'filter'	=>	$tempCountry
			);
		}
	} */
	$_participant['country'] = (array_values($countries)) ;
	$_participant['profile'] = (array_values($profiles)) ; 	
	$_participant['company'] = (array_values($companies)) ;
	
	//form country filter
/*     $sql = "
		SELECT DISTINCT d.country as country_id, c.country AS country_name
		from tbl_members d
		left outer join
		tbl_country c
		ON d.country=c.id
		where $whrcond
		HAVING country_id <>0
		order by country_name asc
	";
    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        if(!empty($row['country_id'] ) )
            $_participant['country'][$row['country_id']] = array(
                "filter" => $row['country_name'] );
        else
            $_participant['country']['0'] = array( "filter" => 'Others' ) ;
    }

    $_participant['country'] = array_values($_participant['country']) ;

	//form comapny name filter
    $sql = "
		SELECT DISTINCT company as company_name
		from tbl_members d
		where $whrcond

		order by company_name asc
	";
    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        if(!empty($row['company_name']))
            $_participant['company'][] = array(
                "filter" => trim($row['company_name']));
    }

	//form comapny type filter
    $sql = "
		(SELECT short_comptype from tbl_companytype where id = d.companytype) as short_comptype
		from tbl_members as d
		where $whrcond
		order by company_name asc
	
	
		SELECT DISTINCT short_comptype
		from tbl_companytype
		order by short_comptype asc
	";
    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
        if(!empty($row['short_comptype']))
            $_participant['profile'][] = array(
                "filter" => trim($row['short_comptype']));
    }
	$_participant['profile'] = array_values($_participant['profile']) ; */
	
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );
    return $_participant;
}


/* /////////////////////////////Speakers list//////////////
$event_id='5';//optional default it returns current event Schedules list
$evnts = getSchedules();
print_R($evnts);  */
function getSchedules($event_id='', $timezone = 'Asia/Kolkata'){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    $whrcond="1";

    if($event_id=='')
        $event_id = getActiveEventId();

    $whrcond = " event_id = $event_id ";
    //$whrcond = " t.event_id = '$event_id' or like '%,$event_id' or like '$event_id,%'";
    $sql ="
		select *
		from tbl_sm_events_schedule
		where $whrcond
		order by id asc 
	";
    $rs = mysql_query($sql)or die(mysql_error().$sql);

    $_rs_array = array();

    while($row = mysql_fetch_array($rs,MYSQL_ASSOC)){

        $date = new DateTime($row['schedule_date'] . " ".$row['schedule_time'] , new DateTimeZone($timezone));
        $timestamp =  $date->getTimestamp();
        $_rs_array[] = [
//            "time" => strtotime($row['schedule_date'] . " ".$row['schedule_time'] ) ,
            "time" => $timestamp ,
//            "temp" => $row['schedule_date'] . " ".$row['schedule_time'] ,
            ///"title" => ucwords(strtolower($row['schedule_title'])) ,//as by akash on 02/01/2019
            "title" => $row['schedule_title'] ,
            "desc" => $row['schedule_desciption'] ,
            "event_time" => $row['formatted_time'],
            "hall_name" => $row['hall_name'],
            "hall_session_title" => $row['hall_session_title']
        ] ;
    }
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;
}

/////////////////////////////An Event Details //////////////
/*
$event_id='5';//optional default it returns current event Schedules list
$ip='103.46.241.130';

$evnts = getEventPackageDetail();
print_R($evnts);
 */
function get_client_ip()
 {
      $ipaddress = '';
      if (getenv('HTTP_CLIENT_IP'))
          $ipaddress = getenv('HTTP_CLIENT_IP');
      else if(getenv('HTTP_X_FORWARDED_FOR'))
          $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
      else if(getenv('HTTP_X_FORWARDED'))
          $ipaddress = getenv('HTTP_X_FORWARDED');
      else if(getenv('HTTP_FORWARDED_FOR'))
          $ipaddress = getenv('HTTP_FORWARDED_FOR');
      else if(getenv('HTTP_FORWARDED'))
          $ipaddress = getenv('HTTP_FORWARDED');
      else if(getenv('REMOTE_ADDR'))
          $ipaddress = getenv('REMOTE_ADDR');
      else
          $ipaddress = 'UNKNOWN';

      return $ipaddress;
 }

function getEventPackageDetail($ip='', $event_id='', $_prices_for='', $currencyCode){
   
   $no_of_delegate = 3; 
  
  /*  if($event_id!=12){
		return getEventPackageDetail_old($ip, $event_id, $_prices_for);
   } 
     */ 
	include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
	  include_once ('/home/steelmin/public_html/hf.php');
    $_rs_array = array();
    if($event_id=='')
        $event_id = getActiveEventId();

    $event_details = get_latest_event_details($event_id);
	//print_r($event_details);
    list($event_venue , $event_date , $event_name , $indian_first_delegate , $indian_second_delegate , $indian_third_delegate , $nonindian_first_delegate , $nonindian_second_delegate , $nonindian_third_delegate, $is_offer_active , $std_indian_first_delegate , $std_indian_second_delegate , $std_indian_third_delegate , $std_nonindian_first_delegate , $std_nonindian_second_delegate , $std_nonindian_third_delegate, $is_onspot_active , $onspot_indian_first_delegate , $onspot_indian_second_delegate , $onspot_indian_third_delegate , $onspot_nonindian_first_delegate , $onspot_nonindian_second_delegate , $onspot_nonindian_third_delegate, $early_bird_date, $is_std_active, $super_early_bird_date, $super_early_bird_active, $event_image, $other_event_name, $other_event_logo, $other_event_note, $event_start_date, $onspotDate,$event_pos, $event_gst, $del_cal_type, $email_id, $mobile_number, $currencyCodes) = explode('/*/',$event_details);
	
	$avilableIncurrencyCodes = explode(',',$currencyCodes);
	if(strpos($event_date, "-") !== false){
		list($event_day, $event_end_date) = explode('-', $event_date);
	}else
		$event_end_date = $event_date;
	

    if( $currencyCode == "INR" )
        $ip_countryName = "INDIA";
    else    
        $ip_countryName = "NOTINDIA";
        
	//$ip_countryName='';
	//$ip_countryName = ipTocntry($ip);
	
	//following lines commented by tarun on 3-July-2017 as for upcoming event only USD is considered; consider getting country_name from APP itself
/* 	$url = "https://www.freegeoip.net/json/".$ip;
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $response = curl_exec($ch);
    curl_close($ch);	
    $ipToCountryApiData = (array) json_decode($response, true);	
    $ip_countryName = strtoupper($ipToCountryApiData['country_name']); */

	//$ip_countryName='';
	/* $dt=json_decode(@file_get_contents('https://freegeoip.net/json/'.$ip));
	if ($dt!=null) $ip_countryName= strtoupper($dt->country_name); */
	//$ip_countryName = ipTocntry($ip);
	//echo "ip_countryName:" . $ip_countryName;
    if($is_offer_active==1 || $super_early_bird_active==1)
        $is_std_active =2;
	
	 if($is_onspot_active!=1)
        $is_onspot_active =2;
	else{
		$is_std_active =0;
	}
	///if event expire
	if(strtotime($event_end_date)<strtotime($GLOBALS['currDateTime'])){
		$is_offer_active =0;
		$super_early_bird_active =0;
		$is_std_active =0;
		$is_onspot_active =0;
	}
	
	$super_early_bird_datetime = strtotime($super_early_bird_date);
	$currDateTime = strtotime($GLOBALS['currDateTime']);
    
	
	$is_gst_applicable=false;
	 if($event_id==18)
		 $is_gst_applicable=true;
	
	if(($event_id==23 || $event_id==25 || $event_id==26) && $ip_countryName == 'INDIA'){
		$ip_countryName = 'NOTININDIA';
		$is_gst_applicable=true;
	}
	
	$_rs_array_plans=array();
	if(in_array("INR", $avilableIncurrencyCodes) !== false)
		$inr = "INR";
	else
		$inr = "USD";
	
	if($event_id==26){
		$no_of_delegate = 1; 
		$_rs_array_plans['standard']= array(
			'is_active' => 1,
			'standard_date' => date("d M Y", strtotime($event_start_date . "-1 days")),
			"p_type" => "USD" ,
			"tab_name" => "Standard",
			"delegate" => array(
				'Price' => intval ($indian_first_delegate ).'-1'
				)
		);
	}
	elseif(!empty($other_event_name)){
		$no_of_delegate = 1; 
		$_rs_array_plans['standard']= array(
			'is_active' => 1,
			'standard_date' => date("d M Y", strtotime($event_start_date . "-1 days")),
			"p_type" => "USD" ,
			"tab_name" => "Standard",
			"delegate" => array(
				'Conference (1 Day)' => intval ($std_nonindian_first_delegate).'-'.$no_of_delegate,
				'Conference + Plant Tour (2 Days)'=> intval ($nonindian_first_delegate).'-'.$no_of_delegate
				)
		);
	}else{
		if(trim($ip_countryName) == 'INDIA'){ //&& $event_id!=17
		//if(0){///for bangkok event all in Dollers
			
			//if($currDateTime <= $super_early_bird_datetime){//super early bird date
			if($super_early_bird_active){//super early bird date
				$_rs_array_plans['early_bird']= array(
					'is_active' => (int)$super_early_bird_active,
					'onspot_date' => $super_early_bird_date,
					'p_type'=>(string)$inr,
					"tab_name" => "Super Early Bird",
					"delegate" => array(
						'1 Delegates' => intval ($indian_first_delegate ).'-1',
						'2 Delegates'=> $indian_second_delegate.'-2',
						'3 Delegates'=> $indian_third_delegate.'-3'
						)
				);
			}else{
				$_rs_array_plans['early_bird']= array(
					'is_active' => (int)$is_offer_active,
					'onspot_date' => $early_bird_date,
					'p_type'=>(string)$inr,
					"tab_name" => "Early Bird",
					"delegate" => array(
						'1 Delegates' => intval ($indian_first_delegate ).'-1',
						'2 Delegates'=> $indian_second_delegate.'-2',
						'3 Delegates'=> $indian_third_delegate.'-3'
						)
				);
			}
			
			$_rs_array_plans['standard']= array(
				'is_active' => (int)$is_std_active,
				'standard_date' => date("d M Y", strtotime($event_start_date . "-1 days")),
				'p_type'=>(string)$inr,
				"tab_name" => "Standard",
				"delegate" => array(
					'1 Delegates' =>intval ($std_indian_first_delegate).'-1',
					'2 Delegates'=> $std_indian_second_delegate.'-2',
					'3 Delegates'=> $std_indian_third_delegate.'-3'
					)
			);
			$_rs_array_plans['onspot']= array(
				'is_active' => (int)$is_onspot_active,
				'p_type'=>(string)$inr,
				"tab_name" => "On Spot",
	//            'onspot_date' => $onspot_date,
				"delegate" => array(
					'1 Delegates' => intval ($onspot_indian_first_delegate).'-1',
					'2 Delegates'=> $onspot_indian_second_delegate.'-2',
					'3 Delegates'=> $onspot_indian_third_delegate.'-3'
					)
			);

		}else{
			$inr = "USD";
			
			//if($currDateTime <= $super_early_bird_datetime){//super early bird date
			if($super_early_bird_active){//super early bird date
				$_rs_array_plans['early_bird']= array(
					'is_active' => (int)$super_early_bird_active,
					"p_type" => (string)$inr,
					"tab_name" => "Super Early Bird",
					'onspot_date' => $early_bird_date,
					"delegate" => array(
						'1 Delegates' => intval ($nonindian_first_delegate ).'-1',
						'2 Delegates'=> $nonindian_second_delegate.'-2' ,
						'3 Delegates'=> $nonindian_third_delegate.'-3'
						)
				);
			}else{
				$_rs_array_plans['early_bird']= array(
					'is_active' => (int)$is_offer_active,
					"p_type" => (string)$inr,
					"tab_name" => "Early Bird",
					'onspot_date' => $early_bird_date,
					"delegate" => array(
						'1 Delegates' => intval ($nonindian_first_delegate ).'-1',
						'2 Delegates'=> $nonindian_second_delegate.'-2' ,
						'3 Delegates'=> $nonindian_third_delegate.'-3'
						)
				);
			}
			$_rs_array_plans['standard']= array(
				'is_active' => (int)$is_std_active,
				"p_type" => (string)$inr ,
				 'standard_date' => date("d M Y", strtotime($event_start_date . "-1 days")),
				"tab_name" => "Standard",
				"delegate" => array(
					'1 Delegates' => intval ($std_nonindian_first_delegate ).'-1',
					'2 Delegates'=> $std_nonindian_second_delegate.'-2' ,
					'3 Delegates'=> $std_nonindian_third_delegate.'-3'
					)
			);
			$_rs_array_plans['onspot']= array(
				'is_active' => (int)$is_onspot_active,
	//            'onspot_date' => $onspot_date,
				"p_type" => (string)$inr ,
				"tab_name" => "On Spot",
				"delegate" => array(
					'1 Delegates' => intval ($onspot_nonindian_first_delegate).'-1',
					'2 Delegates'=> $onspot_nonindian_second_delegate.'-2'  ,
					'3 Delegates'=> $onspot_nonindian_third_delegate.'-3'
					)
			);
		}
	}
	$_rs_array['note'] = '';
	$_rs_array['plans'] = $_rs_array_plans;
     if($super_early_bird_active)
		$_rs_array['note'] = 'Super Early Bird Service Expires on '. date('d/M/Y', strtotime($super_early_bird_date));
	 elseif($is_offer_active==1 && $early_bird_date!='0000-00-00')
		$_rs_array['note'] = 'Early Bird Service Expires on '. date('d/M/Y', strtotime($early_bird_date));
	 elseif($is_std_active==1 && $event_start_date!='0000-00-00')
		$_rs_array['note'] = 'Standard Service Expires on '. date('d/M/Y', strtotime($event_start_date . ' - 1 days'));
		//Commented on 16 Mar'23 by YKV as the message of on spot expiring was incorrect
	 // elseif($onspotDate!='0000-00-00')
		// $_rs_array['note'] = 'On Spot Service Expires on '. date('d/M/Y', strtotime($onspotDate));
	
	$_rs_array['delegate_note'] = "For more than ".$no_of_delegate." Delegates ";
	$_rs_array['is_tax_applicable'] ="";
	if( $event_id == 15 ){
		$_rs_array['note'] .= '<b>FOR NEPALESE DELEGATES
		Please contact Ms Rachna Rana for registration fee details at 
		Call +918770591843, 
		Email rachna.rana@steelmint.com</b>';
	}
	/* if( $event_id == 25 ){
		$_rs_array['note'] .= '<b>FOR NEPALESE DELEGATES
		Please contact Ms Vinamrata Jaisinghani for registration fee details at 
		Call +6263751163, 
		Email vinamrata@steelmint.com</b>';
	} */
	if(trim($ip_countryName) == 'INDIA' || $is_gst_applicable==true){// && $event_id!=17
		//$_round_doller = round(currencyInINR(1),2);
		if($_rs_array['note'])
			$_rs_array['note'].='; ';
        $_rs_array['note'] .= "GST @18% applicable for Indian Clients";
		//$_rs_array['note'] .= "GST @18% applicable for Indian Clients; 1USD=INR70 conversion for Indian clients";
		//$_rs_array['is_tax_applicable'] = " + GST ".$GLOBALS['STtax']."%";
		$_rs_array['is_tax_applicable'] = " + GST 18%";
	}
	
	$_rs_array['del_cal_type'] = $del_cal_type;
/*	if( $event_id == 20){
		$_rs_array['del_cal_type'] = 'multi';
	}*/
	$_rs_array['email_id'] = $email_id;
	$_rs_array['mobile_number'] = $mobile_number;
	$_rs_array['avilable_currencyCodes'] = $avilableIncurrencyCodes;
	
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    if($_prices_for!='')
        return $_rs_array[$_prices_for];
    else
        return $_rs_array;///alll
}

function getEventPackageDetail_old($ip='', $event_id='', $_prices_for=''){
    $no_of_delegate=3;
	include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    $_rs_array = array();
    if($event_id=='')
        $event_id = getActiveEventId();

    $event_details = get_latest_event_details($event_id);
	//print_r($event_details);
   // list($event_venue , $event_date , $event_name , $indian_first_delegate , $indian_second_delegate , $indian_third_delegate , $nonindian_first_delegate , $nonindian_second_delegate , $nonindian_third_delegate, $is_offer_active , $std_indian_first_delegate , $std_indian_second_delegate , $std_indian_third_delegate , $std_nonindian_first_delegate , $std_nonindian_second_delegate , $std_nonindian_third_delegate, $is_onspot_active , $onspot_indian_first_delegate , $onspot_indian_second_delegate , $onspot_indian_third_delegate , $onspot_nonindian_first_delegate , $onspot_nonindian_second_delegate , $onspot_nonindian_third_delegate, $early_bird_date, $is_std_active, $super_early_bird_date, $super_early_bird_active, $event_image, $event_start_date, $onspotDate) = explode('/*/',$event_details);
list($event_venue , $event_date , $event_name , $indian_first_delegate , $indian_second_delegate , $indian_third_delegate , $nonindian_first_delegate , $nonindian_second_delegate , $nonindian_third_delegate, $is_offer_active , $std_indian_first_delegate , $std_indian_second_delegate , $std_indian_third_delegate , $std_nonindian_first_delegate , $std_nonindian_second_delegate , $std_nonindian_third_delegate, $is_onspot_active , $onspot_indian_first_delegate , $onspot_indian_second_delegate , $onspot_indian_third_delegate , $onspot_nonindian_first_delegate , $onspot_nonindian_second_delegate , $onspot_nonindian_third_delegate, $early_bird_date, $is_std_active, $super_early_bird_date, $super_early_bird_active, $event_image, $other_event_name, $other_event_logo, $other_event_note, $event_start_date, $onspotDate,$event_pos, $event_gst, $del_cal_type) = explode('/*/',$event_details);

    //$ip_countryName = ipTocntry($ip); // This function was giving time out
    //$url = "https://www.ip-api.com/json/".$ip;
	
	//following lines commented by tarun on 3-July-2017 as for upcoming event only USD is considered; consider getting country_name from APP itself
	$url = "https://www.freegeoip.net/json/".$ip;
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $response = curl_exec($ch);
    curl_close($ch);	
    $ipToCountryApiData = (array) json_decode($response, true);	
    $ip_countryName = strtoupper($ipToCountryApiData['country_name']);

//    $is_std_active = 0;
    if($is_offer_active==1)
        $is_std_active =2;
	
	 if($is_onspot_active!=1)
        $is_onspot_active =2;
	else{
		$is_std_active =0;
	}
	
	$super_early_bird_datetime = strtotime($super_early_bird_date);
	$currDateTime = strtotime($GLOBALS['currDateTime']);
    
	if($event_id==11)
		$ip_countryName = 'NOTININDIA';
	
	if(trim($ip_countryName) == 'INDIA' ){/// && $event_id!=17
    //if(0){///for bangkok event all in Dollers
        
		//if($currDateTime <= $super_early_bird_datetime){//super early bird date
		if($super_early_bird_active){//super early bird date
			$_rs_array['early_bird']= array(
				'is_active' => $is_offer_active,
				'onspot_date' => $super_early_bird_date,
				'p_type'=>(string)"INR" ,
				"tab_name" => "Super Early Bird" ,
				"delegate" => array(
					'1 Delegates' => intval ($indian_first_delegate ),
					'2 Delegates'=> $indian_second_delegate ,
					'3 Delegates'=> $indian_third_delegate
					),
			);
		}else{
			$_rs_array['early_bird']= array(
				'is_active' => $is_offer_active,
				'onspot_date' => $early_bird_date,
				'p_type'=>(string)"INR" ,
				"tab_name" => "Early Bird" ,
				"delegate" => array(
					'1 Delegates' => intval ($indian_first_delegate ),
					'2 Delegates'=> $indian_second_delegate,
					'3 Delegates'=> $indian_third_delegate
					),
			);
		}
		
        $_rs_array['standard']= array(
            'is_active' => $is_std_active,
            'p_type'=>(string)"INR" ,
			"tab_name" => "Standard" ,
            "delegate" => array(
                '1 Delegates' =>intval ($std_indian_first_delegate),
                '2 Delegates'=> $std_indian_second_delegate ,
                '3 Delegates'=> $std_indian_third_delegate
                ),
        );
        $_rs_array['onspot']= array(
            'is_active' => $is_onspot_active,
            'p_type'=>(string)"INR" ,
			"tab_name" => "On Spot" ,
//            'onspot_date' => $onspot_date,
            "delegate" => array(
                '1 Delegates' => intval ($onspot_indian_first_delegate),
                '2 Delegates'=> $onspot_indian_second_delegate ,
                '3 Delegates'=> $onspot_indian_third_delegate
                ),
        );

    }else{
        
		//if($currDateTime <= $super_early_bird_datetime){//super early bird date
		if(strtotime($currDate) <= $super_early_bird_datetime){//super early bird date
			$_rs_array['early_bird']= array(
				'is_active' => $is_offer_active,
				"p_type" => "USD" ,
				"tab_name" => "Super Early Bird" ,
				'onspot_date' => $early_bird_date,
				"delegate" => array(
					'1 Delegates' => intval ($nonindian_first_delegate ),
					'2 Delegates'=> $nonindian_second_delegate ,
					'3 Delegates'=> $nonindian_third_delegate
					),
			);
		}else{
			$_rs_array['early_bird']= array(
				'is_active' => $is_offer_active,
				"p_type" => "USD" ,
				"tab_name" => "Early Bird" ,
				'onspot_date' => $early_bird_date,
				"delegate" => array(
					'1 Delegates' => intval ($nonindian_first_delegate ),
					'2 Delegates'=> $nonindian_second_delegate ,
					'3 Delegates'=> $nonindian_third_delegate
					),
			);
		}
        $_rs_array['standard']= array(
            'is_active' => $is_std_active,
            "p_type" => "USD" ,
			"tab_name" => "Standard" ,
            "delegate" => array(
                '1 Delegates' => intval ($std_nonindian_first_delegate ),
                '2 Delegates'=> $std_nonindian_second_delegate ,
                '3 Delegates'=> $std_nonindian_third_delegate
                ) ,
        );
        $_rs_array['onspot']= array(
            'is_active' => $is_onspot_active,
//            'onspot_date' => $onspot_date,
            "p_type" => "USD" ,
			"tab_name" => "On Spot" ,
            "delegate" => array(
                '1 Delegates' => intval ($onspot_nonindian_first_delegate),
                '2 Delegates'=> $onspot_nonindian_second_delegate  ,
                '3 Delegates'=> $onspot_nonindian_third_delegate
                ),
        );
    }
	$arrDesig = array();
	$a = mysql_query("select * from tbl_designation ");
	$arrDesig1[] = array(
		'value' => "Select Designation",
		'id' => 0
	);
	while($b = mysql_fetch_array($a)){
		$arrDesig1[] = array(
			'value' => $b['name'],
			'id' => $b['id']
        );
	}	
	
	$arrDesig = $arrDesig1;
	$_rs_array['designation']= array(
		$arrDesig
	);
	
    /* $_rs_array['early_bird']= array(
                            'is_active' => $is_offer_active,
                            'onspot_date' => $early_bird_date,
                            'indian_first_delegate' => $std_indian_first_delegate,
                            'indian_second_delegate'=>$std_indian_second_delegate ,
                            'indian_third_delegate'=>$std_indian_third_delegate ,
                            'nonindian_first_delegate'=>$std_nonindian_first_delegate ,
                            'nonindian_second_delegate'=>$std_nonindian_second_delegate ,
                            'nonindian_third_delegate'=>$std_nonindian_third_delegate
                        );
    $is_std_active = 0;
    if($is_onspot_active==0 && $is_offer_active==0)
        $is_std_active =1;

    $_rs_array['standard']= array(
                            'is_active' => $is_std_active,
                            'indian_first_delegate' => $indian_first_delegate,
                            'indian_second_delegate'=>$indian_second_delegate ,
                            'indian_third_delegate'=>$indian_third_delegate ,
                            'nonindian_first_delegate'=>$nonindian_first_delegate ,
                            'nonindian_second_delegate'=>$nonindian_second_delegate ,
                            'nonindian_third_delegate'=>$nonindian_third_delegate
                        );
    $_rs_array['onspot']= array(
                            'is_active' => $is_onspot_active,
                            'onspot_date' => $onspot_date,
                            'indian_first_delegate' => $onspot_indian_first_delegate,
                            'indian_second_delegate'=>$onspot_indian_second_delegate ,
                            'indian_third_delegate'=>$onspot_indian_third_delegate ,
                            'nonindian_first_delegate'=>$onspot_nonindian_first_delegate ,
                            'nonindian_second_delegate'=>$onspot_nonindian_second_delegate ,
                            'nonindian_first_delegate'=>$onspot_nonindian_third_delegate
                        ); */

     if($currDateTime <= $super_early_bird_datetime)
		$_rs_array['note'] = 'Super Early Bird Service Expires on '. date('d/M/Y', strtotime($super_early_bird_date));
	 elseif($is_offer_active==1)
		$_rs_array['note'] = 'Early Bird Service Expires on '. date('d/M/Y', strtotime($early_bird_date));
	 elseif($is_std_active==1)
		$_rs_array['note'] = 'Standard Service Expires on '. date('d/M/Y', strtotime($event_start_date . ' - 1 days'));
	 else
		$_rs_array['note'] = 'On Spot Service Expires on '. date('d/M/Y', strtotime($onspotDate));
   // $_rs_array['note'] = 'Diwali Savings Offer Expires on '. date('d/M/Y H:s', strtotime($early_bird_date));
	$_rs_array['note'] .= "; GST @18% applicable for Indian Clients; 1USD=INR70 conversion for Indian clients";
	
	$_rs_array['delegate_note'] = "For more than ".$no_of_delegate." Delegates ";
	
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    if($_prices_for!='')
        return $_rs_array[$_prices_for];
    else
        return $_rs_array;///alll
}

///////////////////prceedWithDelegatesDetails/////////////////
/*
$event_id=6;
$ip='182.73.37.246';
$_no_delegates=3;
//$is_indian=true;
$tab_type='early_bird';
$memid=56014;/// blank when new or not loggedin else memid of user when loggedin in
$evnts = getPaymentDetails($ip, $memid, $event_id, $_no_delegates, $tab_type);
print_R($evnts);
 */
function getPaymentDetails($ip='', $memid='', $event_id='', $_no_delegates=1, $type='early_bird', $price_type='INR'){

    $_rs_array = array();
    if($event_id=='')
        $event_id = getActiveEventId();

    $ip_countryName = ipTocntry($ip);

    $_prices = getEventPackageDetail($ip, $event_id, $_prices_for=$type);

    $subtot=0; $discount=0;
   // print_r($_prices);

    $subtot+=$_prices["delegate"][$_no_delegates . ' Delegates'];

    $_rs_array['delegates'][$_no_delegates . ' Delegates'] = strval( $_prices["delegate"][$_no_delegates . ' Delegates'] );

    if((strtoupper($ip_countryName)=='INDIA' && $price_type=='USD') || $price_type=='INR'){

       /*  $_rs_array['delegates']['Service Tax ' . $GLOBALS['STtax'] .'%'] = strval ($subtot_st=(($subtot * $GLOBALS['STtax'])/100) );
        $_rs_array['delegates']['Swachh Bharat Cess ' . $GLOBALS['SBCesstax'] .'%'] = strval($subtot_st_cess=(($subtot * $GLOBALS['SBCesstax'])/100) );
        $_rs_array['delegates']['Krishi Kalyan Cess ' . $GLOBALS['KKCesstax'] .'%'] = strval($subtot_st_cess1=(($subtot * $GLOBALS['KKCesstax'])/100) ); */
		// $_rs_array['delegates']['GST ' . $GLOBALS['STtax'] .'%'] = strval ($subtot_st=(($subtot * $GLOBALS['STtax'])/100) );
		 //$_rs_array['delegates']['GST ' . $GLOBALS['STtax'] .'%'] = strval ($subtot_st=(($subtot * $GLOBALS['STtax'])/100) );
		 $_rs_array['delegates']['GST 18%'] = strval ($subtot_st=(($subtot * $GLOBALS['STtax'])/100) );
        $_rs_array['delegates']['subtot']= strval($subtot);
        $_rs_array['delegates']['discount']= strval($discount);
        $_rs_array['delegates']['Total']= strval( $total=$subtot_st_cess+$subtot_st_cess1+$subtot_st+$subtot );
    }else{
		/* $_rs_array['delegates']['Service Tax ' . $GLOBALS['STtax'] .'%'] = 0;
        $_rs_array['delegates']['Swachh Bharat Cess ' . $GLOBALS['SBCesstax'] .'%'] = 0;
        $_rs_array['delegates']['Krishi Kalyan Cess ' . $GLOBALS['KKCesstax'] .'%'] = 0; */
		//$_rs_array['delegates']['GST ' . $GLOBALS['STtax'] .'%'] = 0;
		$_rs_array['delegates']['GST 18%'] = 0;
        $_rs_array['delegates']['subtot']= strval($subtot);
        $_rs_array['delegates']['discount']= strval($discount);
		$_rs_array['delegates']['Total']= strval( $total=$subtot );
    }
    /* if($is_indian){
        if($_no_delegates>=1){
            $subtot+=$_prices['indian_first_delegate'];
            $_rs_array['delegates']['First Delegate'] = $_prices['indian_first_delegate'];
        }
        if($_no_delegates>=2){
            $subtot+=$_prices['indian_second_delegate'];
            $_rs_array['delegates']['Second Delegate']= $_prices['indian_second_delegate'];
        }
        if($_no_delegates>=3){
            $subtot+=$_prices['indian_third_delegate'];
            $_rs_array['delegates']['Third Delegate'] = $_prices['indian_third_delegate'];
        }

        $_rs_array['delegates']['Service Tax ' . $GLOBALS['STtax'] .'%'] = $subtot_st=(($subtot * $GLOBALS['STtax'])/100);
        $_rs_array['delegates']['Swachh Bharat Cess ' . $GLOBALS['SBCesstax'] .'%'] = $subtot_st_cess=(($subtot * $GLOBALS['SBCesstax'])/100);

        $_rs_array['delegates']['Total']= $total=$subtot_st_cess+$subtot_st+$subtot;
    }else{
        if($_no_delegates<=1){
            $subtot+=$_prices['nonindian_first_delegate'];
            $_rs_array['delegates']['First Delegate'] = $_prices['nonindian_first_delegate'];
        }
        if($_no_delegates<=2){
            $subtot+=$_prices['nonindian_second_delegate'];
            $_rs_array['delegates']['Second Delegate'] = $_prices['nonindian_second_delegate'];
        }
        if($_no_delegates<=3){
            $subtot+=$_prices['indian_third_delegate'];
            $_rs_array['delegates']['Third Delegate'] = $_prices['nonindian_third_delegate'];
        }

        $_rs_array['delegates']['Total']= $total=$subtot;
    } */

    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    if($memid){
        $qry = mysql_query("
					select email, name, company, phoneno, designation, id as memid
					from tbl_members
					where id=$memid
				")or die(mysql_error());
        $row=mysql_fetch_array($qry,MYSQL_ASSOC);
        $_rs_array['user_details'] = $row;
    }

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

    return $_rs_array;
}

///////////////////prceedWithDelegatesDetails/////////////////
//
//$event_id='6';//optional default it returns current event
//$_no_delegates=3;
//$memid=56014;
//$type='early_bird';
//$ip='';

///prceedWithDelegatesDetails($ip, $event_id, $memid,$input, $_no_delegates, $type);

//function prceedWithDelegatesDetails($ip='', $event_id='', $memid='',$input=array() , $_no_delegates=1, $type='early_bird', $visited_on="MOBAPP", $selected_ids='', $subTotal='', $discount='', $SBCess='', $serviceTax='' ){//8NFffUZzSR7EhRQ55OuJExGcIlfhX21A
function prceedWithDelegatesDetails($ip='', $event_id='', $memid='',$input=array() , $_no_delegates=1, $type='early_bird', $visited_on="MOBAPP", $selected_ids='', $subTotal=0, $discount=0, $SBCess=0, $serviceTax=0, $amtToCharge=0 ) {
    $_rs_array = array();
    if($event_id=='')
        $event_id = getActiveEventId();

    $ip_countryName = ipTocntry($ip);
	
	/* if(($event_id==25 || $event_id==23 ) && "INDIA" == strtoupper($ip_countryName)){
		$ip_countryName = "NOTINDIA";
	} */
//    $_prices = getEventPackageDetail($ip, $event_id, $_prices_for=$type);
//    $subtot = $_prices["delegate"][$_no_delegates . ' Delegates'];///sub total
//
//    if(strtoupper($ip_countryName)=='INDIA'){
//        $subtot_st=(($subtot * $GLOBALS['STtax'])/100);
//        $subtot_st_cess=(($subtot * $GLOBALS['SBCesstax'])/100);
//        $_rs_array['delegates']['Total']= $total=$subtot_st_cess+$subtot_st+$subtot;
//    }else{
//        $_rs_array['delegates']['Total']= $total=$subtot;
//    }
/* if($memid==56350){
	
return $input; */

//return "<br /> email---" .  $input['delegates'][0]['email'];
/* echo "<br /> event_id---" .  $event_id;
echo "<br /> no_delegates---" .  $_no_delegates;
echo "<br /> type---" .  $type;
echo "<br /> visited_on---" .  $visited_on;
echo "<br /> subTotal---" .  $subTotal;
echo "<br /> discount---" .  $discount;
echo "<br /> SBCess---" .  $SBCess;
echo "<br /> serviceTax---" .  $serviceTax;
echo "<br /> amtToCharge---" .  $amtToCharge;  */
//return json_encode($input);
/* return $input;
    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php');
	die;
} */
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');

    if($memid==''){
        $email = $input['delegates'][0]['email'];
        $memid='';$verified='';
        $_is_exist= isEmailExists($id = '', $email, $memid, $verified);

        if($_is_exist==0){
           /*  $name = htmlentities( $input['delegates'][0]['name'], ENT_QUOTES);
            $email = $input['delegates'][0]['email'];
            $company = htmlentities($input['delegates'][0]['company'], ENT_QUOTES);
            $phoneno = $input['delegates'][0]['phoneno'];
            $city = $input['delegates'][0]['city'];
            $state = $input['delegates'][0]['state'];
            $country = $input['delegates'][0]['country'];
            $other_city = $input['delegates'][0]['other_city'];
//            $input['delegates'][0]['password'] = $phoneno ;



            $column.='name,company,email,username,phoneno,ipaddress,date,main_source,source_from,city,state,country,other_city,ol_be';
            $value.="'".$name."','".$company."','".$email."','".$email."','".$phoneno."','".$ip."','".$GLOBALS['currDateTime']."','Events Mobileapp','Registering ID','".$city."','".$state."','".$country."','".$other_city."','EVT MOBAPP'";*/

            
			$phoneno = $input['delegates'][0]["phoneno"];
			$isd_code = $input['delegates'][0]["country"];
			$name = htmlentities( $input['delegates'][0]['name'], ENT_QUOTES). " " .htmlentities( $input['delegates'][0]['lastname'], ENT_QUOTES);;
			//$password = htmlentities($input['delegates'][0]["password"], ENT_QUOTES);
			$password = '123456';
			$company = htmlentities($input['delegates'][0]["company"], ENT_QUOTES);
			$designation = $input['delegates'][0]["designation"];
			$member_id = $memid;
			
			list($cnty, $std_code) = explode(" ", $isd_code);
			
			$country = qryToCommaSepString("
					select id
					from tbl_country
					where std_code='$std_code'");			
			
			$column.='designation,name,password,company,email,username,phoneno,ipaddress,date,main_source,source_from,country,ol_be,primary_source,lead_type';
            $value.="'$designation', '$name','".$password."','".$company."','".$email."','".$email."','".$phoneno."','".$ip."','".$GLOBALS['currDateTime']."','Events Mobileapp','Registering ID','".$country."','EVT MOBAPP', 'CAMP24','A1'";
			
			mysql_query("insert into  tbl_members (".$column.") values(".$value.")")or die(mysql_error(). "insert into  tbl_members (".$column.") values(".$value.")");
            $memid = mysql_insert_id();
            $rid = $memid; 
			
        } else {
            $rid = $memid;
        }
    }else{
        $qry = mysql_query("
					select email, name, company, phoneno, designation, id as memid
					from tbl_members
					where id=$memid
				")or die(mysql_error(). $qry);
        $row=mysql_fetch_array($qry,MYSQL_ASSOC);
        $memid = $row['memid'];
        $email = $row['email'];
        $phoneno = $row['phoneno'];
        $rid = $memid;
    }
//    $_reg_log_sql ="
//			insert into  tbl_sm_events_registration_logs (datetime,email,mobile,event_id)
//			values(NOW(), '$email', '$phoneno', " . $event_id . ")
//		";
//
//
//    mysql_query($_reg_log_sql) or die(mysql_error());
//    $log_id = mysql_insert_id();
//    makeEntryInTableFinalStatus($email, $event_id);
    makeEntryInTableFinalStatus($memid, $event_id);
    $_com_sql ="INSERT INTO tbl_comments(memid, `f_date`, `f_time`, `comments`, `created_by`, `comments_for`, event_id) VALUES ($rid, '".$GLOBALS['currDate']."', '".$GLOBALS['currTime']."', 'Visited on mobileapp', 'Created from event attendee page', 'EV', ".$event_id.")";
    mysql_query($_com_sql) or die(mysql_error() . $_com_sql);

    $del_ids='';

    foreach($input['delegates'] AS $_delegates){
        /* $name = htmlentities($_delegates['name'], ENT_QUOTES);
        $email = $_delegates['email'];
        $company = htmlentities($_delegates['company'], ENT_QUOTES);
        $phoneno = $_delegates['phoneno'];
        $city = $_delegates['city'];
        $state = $_delegates['state'];
        $country = $_delegates['country'];
        $other_city = $_delegates['other_city']; */
//        $_delegates['password'] = $phoneno ;
		$email = $_delegates["email"];
		$phoneno = $_delegates["phoneno"];
		$isd_code = $_delegates["country"];
		$name = htmlentities( $_delegates['name'], ENT_QUOTES). " " .htmlentities( $_delegates['lastname'], ENT_QUOTES);;
		//$password = htmlentities($_delegates["password"], ENT_QUOTES);
		$password = '123456';
		$company = htmlentities($_delegates["company"], ENT_QUOTES);
	
		
		list($cnty, $std_code) = explode(" ", $isd_code);
		
		$country = qryToCommaSepString("
				select id
				from tbl_country
				where std_code='$std_code'");	

        $memid='';$verified='';
        $_is_exist= isEmailExists($id = '', $email, $memid, $verified);

        if($_is_exist==0){
            $insrt="INSERT INTO `tbl_members`(designation, billing_name, password, `name` ,`company`,`phoneno`, `date`, `ipaddress`,email,username,  `country`, ol_be, main_source,source_from,primary_source, lead_type) VALUES ('$designation', '$name', '$password', '".$name."', '".$company."', '".$phoneno."', NOW(),'".$ip."', '".$email."', '".$email."','".$country."', 'EVT MOBAPP','Events Mobileapp','new delegate', 'CAMP24' ,'A1')";
            //echo  "<br>tbl_members for  delegates : ".  $insrt;
            mysql_query($insrt) or die(mysql_error().$insrt);
            $memid = mysql_insert_id();
        }
        if($del_ids)
            $del_ids.=",";
        $del_ids.=$memid;///DELGATES IDS
    }
    $newPage='';
	
    if($del_ids)
    {
        $bill_no = getSMorderNoForCCAVENUE("EVENTS");
        //$bill_no = '';
        //$bill_no = 'EVENTS_test'; 
       // $amtToCharge = $type;
	    // if( "india" == strtolower($ip_countryName)){
			// include_once($_ENV['COMMON_ROOT_PATH'].'/cf_inv.php');
			// $amtToCharge = round(currencyInINR($amtToCharge));
			// $amtToCharge += ($amtToCharge * 0.18);
				
			// $mode='IS';
			//if($state==5)
			//	$mode='CG';
			// $taxAmt = getTaxBreakUps($amtToCharge, $mode);
			///list($amountWOTax, $ST, $SBCess, $roundOffVal,$KKcess) = explode("/*/", $taxAmt);
			// list($subTotal, $serviceTax, $SBCess, $round_off,$KKcess) = explode("/*/", $taxAmt);		
	   
		// }
	    //$round_off=0;
        //if($serviceTax)$round_off = $amtToCharge - (($subTotal-$discount) + $SBCess + $serviceTax);

        $payment_gateway = null ;
		if( "india" != strtolower($ip_countryName))//paypal  || $event_id==17
        { 
			include_once("/home/steelmin/public_html/sm_group_events/regProcess/paypal_country.php");
			$crncy = 'USD';
			if(in_array(strtoupper($ip_countryName), $_paypal_country) !== false)
			{////paypal
				$insrt = "INSERT INTO `tbl_sm_events_payment_details` (`event_id`, `registering_id`, `pay_amt`, `pay_date`, `pymt_details`, `pym_mode`, `bill_no`, `nb_order_no`, `nb_bid`, `card_category`, `bank_name`, `comments`, `delegates_ids`,  selected_services,sub_total,discount,stax,cess,round_off, no_of_memids, f_currency,paymentstatus) VALUES(".$event_id.",".$rid.", '$amtToCharge', '".$GLOBALS['currDateTime']."', 'PAYPAL', 'NEFT/Online', '$bill_no', '', '', '', '', '', '$del_ids', '" . $selected_ids . "', '" . $subTotal . "', '" . $discount . "', '" . $serviceTax . "', '" . $SBCess . "', '" . $round_off . "', '$_no_delegates', '$crncy','Pending');";				
			}else{
				$insrt = "INSERT INTO `tbl_sm_events_payment_details` (`event_id`, `registering_id`, `pay_amt`, `pay_date`, `pymt_details`, `pym_mode`, `bill_no`, `nb_order_no`, `nb_bid`, `card_category`, `bank_name`, `comments`, `delegates_ids`,  selected_services,sub_total,discount,stax,cess,round_off, no_of_memids, f_currency,paymentstatus) VALUES(".$event_id.",".$rid.", '$amtToCharge', '".$GLOBALS['currDateTime']."', 'CCAVENUE', 'NEFT/Online', '$bill_no', '', '', '', '', '', '$del_ids', '" . $selected_ids . "', '" . $subTotal . "', '" . $discount . "', '" . $serviceTax . "', '" . $SBCess . "', '" . $round_off . "', '$_no_delegates', '$crncy','Pending');";
			}
        }else{
			$crncy = 'INR';
			if(($event_id==23 || $event_id==25 || $event_id==26) && $ip_countryName == 'INDIA'){
				$subTotal = $subTotal*70;
			}
            $insrt = "INSERT INTO `tbl_sm_events_payment_details` (`event_id`, `registering_id`, `pay_amt`, `pay_date`, `pymt_details`, `pym_mode`, `bill_no`, `nb_order_no`, `nb_bid`, `card_category`, `bank_name`, `comments`, `delegates_ids`, selected_services,sub_total,discount,stax,cess,round_off, no_of_memids, f_currency,paymentstatus) VALUES(".$event_id.",".$rid.", '$amtToCharge', '".$GLOBALS['currDateTime']."', 'CCAVENUE', 'NEFT/Online', '$bill_no', '', '', '', '', '', '$del_ids', '" . $selected_ids . "', '" . $subTotal . "', '" . $discount . "', '" . $serviceTax . "', '" . $SBCess . "', '" . $round_off . "', '$_no_delegates', '$crncy','Pending');";
		}
//        if( "INDIA" != $ip_countryName)//paypal
//            $insrt = "INSERT INTO `tbl_sm_events_payment_details` (`event_id`, `registering_id`, `pay_amt`, `pay_date`, `pymt_details`, `pym_mode`, `bill_no`, `nb_order_no`, `nb_bid`, `card_category`, `bank_name`, `comments`, `delegates_ids`, log_id) VALUES(".$event_id.",".$rid.", '$amtToCharge', '".$GLOBALS['currDateTime']."', 'PAYPAL', 'NEFT/Online', '$bill_no', '', '', '', '', '', '$del_ids', '" . $log_id . "');";
//        else
//            $insrt = "INSERT INTO `tbl_sm_events_payment_details` (`event_id`, `registering_id`, `pay_amt`, `pay_date`, `pymt_details`, `pym_mode`, `bill_no`, `nb_order_no`, `nb_bid`, `card_category`, `bank_name`, `comments`, `delegates_ids`, log_id) VALUES(".$event_id.",".$rid.", '$amtToCharge', '".$GLOBALS['currDateTime']."', 'CCAVENUE', 'NEFT/Online', '$bill_no', '', '', '', '', '', '$del_ids', '" . $log_id . "');";
////mysql_query($insrt); return mysql_error().' got it <pre>'.$insrt.'</pre>'.mysql_error();
        mysql_query($insrt) or die(mysql_error().$insrt);

        $reg_log_ids = $evnt_pay_id =mysql_insert_id();
		
		$_symbols = array(",");
		//$amtToCharge = str_replace($_symbols, "", $amtToCharge);
		$amtToCharge = str_replace($_symbols, "", $subTotal);///tax will be calucated on GST page

		$item_desc = urlencode(getActiveEventName($event_id));
		$applicable_tax_amt =0;
       if( "india" != strtolower($ip_countryName) ){// || $event_id==17		
						
			if(1){
				//include_once("https://www.steelmint.com/sm_group_events/regProcess/paypal_country.php");
				include_once("/home/steelmin/public_html/sm_group_events/regProcess/paypal_country.php");

			   /// $item_desc = urlencode(getActiveEventName($event_id));

				if(in_array(strtoupper($ip_countryName), $_paypal_country) !== false)
					$newPage = BASEURL."paypal/common_payment.php?reglogs_id=".$evnt_pay_id."&amt=" . intval($amtToCharge) . "&orderid=" . $bill_no. "&orderid=" . $bill_no. "&pymtSrc=mobileapp&crency=$crncy&productPurchased=" . $item_desc."&item_desc=" . $item_desc."&page_name=Events";
				else
					$newPage = BASEURL."pay/commonCheckOut.php?reglogs_id=".$evnt_pay_id."&amt=" . intval($amtToCharge) . "&orderid=" . $bill_no. "&uid=".$rid."&pymtSrc=mobileapp&productPurchased=" . $item_desc."&crency=$crncy&page_name=Events";
			}
        }else {
            $payment_gateway = "CCAVENUE" ;
			/* if($event_id==11){
				$amtToCharge = round(currencyInINR($amtToCharge));
				$amtToCharge += ($amtToCharge * 0.18);
			} */
			//$amtToCharge = round(currencyInINR($amtToCharge));
			$applicable_tax_amt = $amtToCharge * 0.18;
			$amtToCharge += ($amtToCharge * 0.18);
            $newPage = "https://www.steelmint.com/sm_group_events/regProcess/checkout.php?reglogs_id=".$evnt_pay_id."&amt=" . intval($amtToCharge) . "&orderid=" . $bill_no;
			
            ///$newPage = "https://www.steelmint.com/sm_group_events/regProcess/checkout.php?reglogs_id=".$evnt_pay_id."&amt=" . intval($amtToCharge) . "&orderid=" . $bill_no;
			$newPage = BASEURL."pay/commonCheckOut.php?reglogs_id=".$evnt_pay_id."&amt=" . intval($amtToCharge) . "&orderid=" . $bill_no. "&uid=".$rid."&pymtSrc=mobileapp&productPurchased=" . $item_desc."&crency=$crncy&page_name=Events";
        }
		
		/* if($applicable_tax_amt > 0 && $evnt_pay_id!=''){
			$reglog_update = mysql_query("update tbl_sm_events_payment_details set stax	='$applicable_tax_amt'  where id =" . $evnt_pay_id) or die(mysql_error());	
		} */
		
       /*  return array(
            "page" => $newPage ,
            "bill_no" => $bill_no ,
            "log_id" => $evnt_pay_id ,
            "payment_gateway" => $payment_gateway ,
        ); */
		
		return $newPage;
    }else
        return false;
}

///////////////////onclick of "contact us for more delegates"/////////////////
//$event_id=6;
//$memid=56014;
//$input1['name']='Mohan R';
//$input1['email']='mohan@steelmint.com';
//$input1['phoneno']='9691633274';
//$input1['company']='SM';
//$input1['country']='INDIA';
//
//contactUs($event_id, $memid,$input1);

function contactUs($event_id='', $memid='',$input=array()){
    include ($_ENV['COMMON_ROOT_PATH'].'/config1.php');
    if($memid != ''){
        $qry = mysql_query("
					select tm.email, tm.name, tm.company, tm.phoneno, (select name from tbl_designation where id = tm.designation) as designation, tm.id as memid
					from tbl_members as tm
					where tm.id = $memid
				")or die(mysql_error());
        $row=mysql_fetch_array($qry,MYSQL_ASSOC);
        $input = $row;

    }
    $name = $input['name'];

    $subject = 'Steelmint Events: Mr. '.$name.' wants to register for more than 3 delegates on mobile app';
    $body = '';
    foreach($input as $key=>$val){
        if($body)$body.='<br>';
        $body.= $key. ' <strong> : '.$val.'</strong>';
    }

    include "/home/steelmin/public_html/mf.php";
    $res = sendSMMail($body, "kapil@steelmint.com", "", $subject, "", "info@steelmint.com", "SteelMint Events", "info@steelmint.com");

    include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );
    return "Some one from our Team will contact you soon";
}

include ($_ENV['COMMON_ROOT_PATH'].'/desconfig.php' );

