<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Home extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();

		$currency = '';

		$this->$currency =  GeneralSettings();
	}

	public function test()
	{
		// Example usage:
		$date = date('d-m-Y'); // Change this to any date
		// echo $result = getWeekdayOccurrence($date);
		// var_dump(getThithis('TRAYODASHI'));

		// $weekdayNames = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
		// $occurrence = ['FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH'];
		// echo "The date {$date} is the ".$occurrence[$result['occurrence']]." ". $weekdayNames[$result['weekday']] . " of the month.";
		$this->load->view('test');
	}

	public function index()
	{

		$data['page'] = 'Home';
		$banner = getWebSyncsData('Banner Images', 'bannerImages', 'ACTIVE');
		$data['slider_image'] = sortBySequenceId($banner);

		$filter['query'] = ['aspectType' => 'ServiceSetup', 'serviceCategoryTypes' => 'EVENTS', 'sourceTypes' => 'WEBSITE', 'status' => 'ACTIVE'];

		$data['upcoming_events'] =  getServiceRequestData($filter);
		$data['partishipent_events'] =  getPartisipentEvnt();

		$this->load->view('home', $data);
	}



	public function getpanchangamData()
	{
		$lat = $this->input->post('lat');
		$long = $this->input->post('long');
		$tzone = $this->input->post('tzone');

		$year = date('Y');
		$month = date('m');
		$day = date('d');
		$hours = date('H');
		$minute = date('i');

		$panchangam = getPanchangamData($lat, $long, $tzone, $year, $month, $day, $hours, $minute);


		$panchangam = json_decode(json_encode($panchangam), true);

		$html = '';
		$html .= '<div class="table-responsive panchangam-table-large-screen"><table class="table table-responsive table-bordered table-striped" style="border-collapse: collapse;">
		<thead>
		<tr style="text-align: center; border: 2px solid #642318;border-bottom: 0;">
		<th>Date</th>
		<th>Day</th>
		<th>Tithi</th>
		<th>Nakshatra</th>
		<th>Yog</th>
		<th>Karan</th>
		<th>Sunrise</th>
		<th>Sunset</th>
		<th>Vedic Sunrise</th>
		<th>Vedic Sunset</th>
		</tr>
		</thead>
		<tbody>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>' . date('m/d/Y') . '</td>
		<td>' . $panchangam['day'] . '</td>
		<td>' . $panchangam['tithi'] . '</td>
		<td>' . $panchangam['nakshatra'] . '</td>
		<td>' . $panchangam['yog'] . '</td>
		<td>' . $panchangam['karan'] . '</td>
		<td>' . $panchangam['sunrise'] . '</td>
		<td>' . $panchangam['sunset'] . '</td>
		<td>' . $panchangam['vedic_sunrise'] . '</td>
		<td>' . $panchangam['vedic_sunset'] . '</td>
		</tr>
		</tbody>
		</table>
		</div>


		<div class="table-responsive panchangam-table-small-screen">
		<table class="table table-responsive table-bordered table-striped" style="border-collapse: collapse;">
		
		
		
		
		<tbody>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Date</td>
		<td>' . date('m/d/Y') . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Day</td>
		<td>' . $panchangam['day'] . '</td>
		<tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Tithi</td>
		<td>' . $panchangam['tithi'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Nakshatra</td>
		<td>' . $panchangam['nakshatra'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Yog</td>
		<td>' . $panchangam['yog'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Karan</td>
		<td>' . $panchangam['karan'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Sunrise</td>
		<td>' . $panchangam['sunrise'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Sunset</td>
		<td>' . $panchangam['sunset'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Vedic Sunrise</td>
		<td>' . $panchangam['vedic_sunrise'] . '</td>
		</tr>
		<tr style="text-align: center; border: 2px solid #642318;border-top: 1px solid #642318;">
		<td>Vedic Sunset</td>
		<td>' . $panchangam['vedic_sunset'] . '</td>
		</tr>
		</tbody>
		</table>
		</div>


		';
		echo json_encode($html);
	}
	public function Calendar()
	{
		$data['title'] = 'Calendar';
		$data['page'] = 'Calendar';
		$data['calendar_events'] =  getWebSyncsData('Temple Calendar', 'templeCalendar', '');
		// var_dump($data['calendar_events'] );die();
		$data['religious_data'] = json_decode(json_encode(Religious()->data), true);
		$data['calender_services'] = getCalenderServices()->data;
		// echo '<pre>';
		// print_r($data['calender_services']);
		// die;
		$this->load->view('calendar', $data);
	}

	public function Gallery()
	{
		$data['page'] = 'Gallery';
		$data['title'] = 'Gallery';
		$data['gallery_data'] = getWebSyncsData('Gallery Settings', 'gallerySettings', '');
		$this->load->view('gallery', $data);
	}

	public function FilterGalleryBy($refDataname, $id)
	{
		$data['page'] = 'Gallery';
		$res = getWebSyncsData('Gallery Settings', 'gallerySettings', '');
		foreach ($res as $item) {
			if ($item['_id'] == $id) {

				$data['parent_data'] = $item['Parent'];
				$data['Child_Grid'] = $item['Child Grid'];
			}
		}

		$this->load->view('filtered-gallery', $data);
	}





	public function GetServiceCatTypes()
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . filterAPI()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"componentConfig\": {   
			\"moduleName\": \"Master Data Management\",  
			\"productID\": \"" . ApiBaseUrl()['productID'] . "\",   
			\"clientID\": \"" . ApiBaseUrl()['clientID'] . "\",       
			\"aspectType\": \"serviceCategoryTypes\",     
			\"query\": {        \"aspectType\": \"serviceCategoryTypes\",  \"status\": \"ACTIVE\"},   
			\"userName\": \"\",     
			\"skip\": 0,    
			\"next\": 1020    
		} }");
		$token = $this->session->userdata('token');
		$headers = array();
		$headers[] = 'Authorization: Bearer ' . $token . '';
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		$response = json_decode($result);


		// print_r($response->data);

		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}

		curl_close($ch);
		return json_decode(json_encode($response->data), true);
	}

	public function getServiceDetailsById()
	{
		$this->session->unset_userdata('serviceDetails');

		$serviceId = $this->input->post('serviceId');
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . getServiceDetailbyId()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{          
			\"_id\": \"" . $serviceId . "\",          
			\"productId\":\" " . ApiBaseUrl()['productID'] . "\",           
			\"clientId\": \"" . ApiBaseUrl()['clientID'] . "\",           
			\"username\":\"asdf\"        
		}");

		$headers = array();
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);

		$response = json_decode($result);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		$serviceDeails = json_decode(json_encode($response->data[0]), true);

		echo json_encode($serviceDeails);
	}






	public function checkLoginStatus()
	{
		if ($this->session->userdata('logged_in') == 1) {
			echo json_encode(1);
		} else {
			echo json_encode(0);
		}
	}



	public function SignUpOld()
	{

		if (!empty($this->input->post('fname')) || !empty($this->input->post('email')) || !empty($this->input->post('email'))) {
			$fname = $this->input->post('fname');
			$lname = $this->input->post('lname');
			$email = $this->input->post('email');
			$phone = $this->input->post('phone');
			$countryCode = $this->input->post('countryCode');
			$data = array('refDataName' => $fname . ' ' . $lname, 'email' => $email, 'phone' => $phone, 'contryCode' => $countryCode, 'firstName' => $fname, 'lastName' => $lname);
			$postfield = json_encode($data);

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerSignup()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
				\n      \"componentConfig\": {\n        \"moduleName\": \"" . customerSignup()['moduleName'] . "\",\n        \"productID\": \"" . ApiBaseUrl()['productID'] . "\",\n        \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"\n    }}");

			$headers = array();
			$headers[] = 'Content-Type:application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);

			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);
			echo json_encode($result);
		} else {
			echo 'Something Went Wrong!!';
		}
	}

		public function SignUp()
	{

		if (!empty($this->input->post('fname')) || !empty($this->input->post('email')) || !empty($this->input->post('email'))) {
			$fname = $this->input->post('fname');
			$lname = $this->input->post('lname');
			$email = $this->input->post('email');
			$phone = $this->input->post('phone');
			$phone = preg_replace('/[^\d]/', '', $phone);
			$countryCode = $this->input->post('countryCode');
			$data = array('refDataName' => $fname . ' ' . $lname, 'email' => $email, 'phone' => $phone, 'contryCode' => $countryCode, 'firstName' => $fname, 'lastName' => $lname);

			$zipcode = @$this->input->post('zipcode');
			$city = @$this->input->post('city');
			$state = @$this->input->post('state');
			$address_line1 = @$this->input->post('address_line1');
			$address_line2 = @$this->input->post('address_line2');
			if (!empty(trim($zipcode))) {
				$data['zip'] = $zipcode;
			}
			if (!empty(trim($address_line1))) {
				$data['addressLine1'] = $address_line1;
			}
			if (!empty(trim($address_line2))) {
				$data['addressLine2'] = $address_line2;
			}
			if (!empty(trim($state))) {
				$data['stateTypes'] = $state;
			}
			if (!empty(trim($city))) {
				$data['cityTypes'] = $city;
			}

			$postfield = json_encode($data);

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerSignup()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
				\n      \"componentConfig\": {\n        \"moduleName\": \"" . customerSignup()['moduleName'] . "\",\n        \"productID\": \"" . ApiBaseUrl()['productID'] . "\",\n        \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"\n    }}");

			$headers = array();
			$headers[] = 'Content-Type:application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);

			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);
			echo json_encode($result);
		} else {
			echo 'Something Went Wrong!!';
		}
	}
	
	public function Login()
	{


		if (!empty($this->input->post('email')) || !empty($this->input->post('phone'))) {


			$email = $this->input->post('email');
			$phone = $this->input->post('phone');
			$LoginTabName = $this->input->post('LoginTabName');


			if ($LoginTabName == 'Management') {
				$moduleName = 'Management Directory';
			} else {
				$moduleName = customerLogin()['moduleName'];
			}

			if (!empty($email)) {
				$data = array('email' => $email, 'isMobile' => false, 'phone' => $phone);
			} else {
				$data = array('email' => $email, 'isMobile' => true, 'phone' => $phone);
			}

			$postfield = $data;

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerLogin()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);


			$dataJson = $postfield;
			$moduleName = $moduleName;
			$productID = ApiBaseUrl()['productID'];
			$clientID = ApiBaseUrl()['clientID'];

			$componentConfig = array(
				"moduleName" => $moduleName,
				"productID" => $productID,
				"clientID" => $clientID
			);

			$payload = array(
				"dataJson" => $dataJson,
				"componentConfig" => $componentConfig
			);

			$jsonPayload = json_encode($payload);

			curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);

			$headers = array();
			$headers[] = 'Content-Type:application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);
			$response = json_decode($result);

			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}


			// print_r($response);
			if ($response->statusCode == 1) {
				if ($email != "" || $this->input->post('sessionCreate') == 1) {


					if ($moduleName == 'Management Directory') {

						$logged_in_sess = array(
							'id'           => $response->data[0]->_id,
							'refDataName'         => $response->data[0]->refDataName,
							'email'         => $response->data[0]->email,
							'phone'       => $response->data[0]->phone,
							'logged_in'    => 1,
							'token' => $response->data[0]->token,
							'memberTypes' => @$response->data[0]->memberTypes,
							'address' => @$response->data[0]->address,
							'userType' => 'Managements'

						);
					} else {

						$logged_in_sess = array(
							'id'           => $response->data[0]->_id,
							'refDataName'         => $response->data[0]->refDataName,
							'email'         => $response->data[0]->email,
							'phone'       => $response->data[0]->phone,
							'logged_in'    => 1,
							'token' => @$response->data[0]->token,
							'memberTypes' => @$response->data[0]->memberTypes,
							'membershipPaymentStatus' => @$response->data[0]->membershipPaymentStatus,
							'membershipStatus' => @$response->data[0]->membershipStatus,
							'membershipId' => @$response->data[0]->membershipId,
							'memberShipExpiryDate' => @$response->data[0]->memberShipExpiryDate,
							'membershipName' => @$response->data[0]->membershipName,
							'membershipStartDate' => @$response->data[0]->membershipStartDate,
							'address' => @$response->data[0]->address,
							'userType' => 'Devotee'

						);
					}
					$this->session->set_userdata($logged_in_sess);
				}


				echo json_encode($response);
			} else {
				echo json_encode('User not found!!');
			}
		} else {
			echo json_encode('Something Went Wrong!!');
		}
	}



	public function sendEmailOTP()
	{



		$email = $this->input->post('email');


		$data = array('email' => $email, 'isMobile' => false, 'phone' => '');



		$postfield = json_encode($data);

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerLogin()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);


		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
			\"componentConfig\": {       \"moduleName\": \"" . customerLogin()['moduleName'] . "\",       \"productID\": \"" . ApiBaseUrl()['productID'] . "\",       \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"   }}");



		$headers = array();
		$headers[] = 'Content-Type:application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$result = curl_exec($ch);
		$response = json_decode($result);




		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}

		// $response->statusCode == 1;
		if ($response->statusCode == 1) {
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . sendEmailOTP()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"emailID\":\"" . $email . "\",\"clientID\":\"" . ApiBaseUrl()['clientID'] . "\"}");

			$headers = array();
			$headers[] = 'Content-Type: application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);
			$response = json_decode($result);
			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);






			if ($response->user->statusCode == 0) {
				$response->user->statusCode = '2';
			}

			echo json_encode($response->user);
		} else {
			echo json_encode($response);
		}



		/*--------------------------*/
	}

	public function verifyEmailOTP()
	{

		$otp = $this->input->post('otp');
		$email = $this->input->post('email');

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . verifyEmailOTP()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"emailID\":\"" . $email . "\",\"code\":\"" . $otp . "\"}");

		$headers = array();
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		$response = json_decode($result);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);
		echo json_encode($response->user);
	}




	///MOBILE NUMBER AUTH
	public function sendMobileOTP()
	{
		$phone = $this->input->post('phone');
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . sendEmailOTP()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"emailID\": \"" . $phone . "\"}");

		$headers = array();
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		$response = json_decode($result);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);


		echo json_encode($response->user);
	}


	public function addServiceCart()
	{
		//Post data
		$email 			= 			$this->input->post('email');
		$fname 			= 			$this->input->post('fname');
		$lname 			= 			$this->input->post('lname');
		$fullPackage 			= 			$this->input->post('fullPackage');
		$transactionId 	= 			$this->input->post('transaction_id');
		$serviceAmount 	= 			$this->input->post('serviceAmount');
		$totalAmount 	= 			$this->input->post('serviceAmount');

		$service_Id 	= 			$this->input->post('service_Id');
		$service_name 	= 			$this->input->post('serviceName');

		$serviceCategoryTypes 	= 			$this->input->post('serviceCategoryTypes');
		$serviceTypes 	= 			$this->input->post('serviceTypes');

		$start_date 	= 			$this->input->post('startDate');
		$qty 			= 			$this->input->post('qty');
		$time 			= 			$this->input->post('startTime');
		$day 			= 			$this->input->post('dayTypes');

		$serviceAddress 			= 			$this->input->post('serviceAddress');

		$ch = curl_init();

		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . addServiceCart()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{         
			\"productId\": \"" . ApiBaseUrl()['productID'] . "\",
			\"clientId\": \"" . ApiBaseUrl()['clientID'] . "\",      
			\"memberId\":\"" . $this->session->userdata('id') . "\",      
			\"memberName\":\"" . $this->session->userdata('refDataName') . "\",      
			\"prsnEmail\": \"" . $this->session->userdata('email') . "\",      
			\"prsnPhone\": \"" . $this->session->userdata('phone') . "\", 

			\"data\": [{              
				\"_id\": \"" . $service_Id . "\", 
				\"serviceName\": \"" . $service_name . "\", 
				\"fullPackage\": \"" . $fullPackage . "\", 
				\"serviceCategory\": \"" . $serviceCategoryTypes . "\", 
				\"serviceType\": \"" . $serviceTypes . "\", 
				\"serviceAmount\": " . $serviceAmount . ", 
				\"startDate\":\"" . $start_date . "\" , 
				\"qty\": " . $qty . ", 
				\"time\": \"" . $time . "\", 
				\"day\":\"" . $day . "\" , 
				\"serviceAddress\":\"" . $serviceAddress . "\"  
				}], 

				\"paymentType\": \"CREDIT CARD\", 
				\"bankName\":\"\" ,
				\"chequeNo\":\"\" , 
				\"chequeAmount\":\"\" , 
				\"chequeDate\": \"\", 
				\"totalAmount\": " . $totalAmount . ", 
				\"transactionId\":\"" . $transactionId . "\",
				\"source\":\"WEBSITE\",
				\"stationName\":\"WEBSITE\",
				\"userId\":\"\",
				\"stationId\":\"WEBSITE\"

			}     
			");
		$token = $this->session->userdata('token');
		$headers = array();
		$headers[] = 'Authorization: Bearer ' . $token . '';
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);
		$response2 = json_decode($result);

		if ($response2->statusCode == 1) {
			$this->updateTransactionStatus($response2->data[0]->_id, $response2->data[0]->invoiceNo, $transactionId);
		}

		echo json_encode($response2);
	}

	public function updateTransactionStatus($id, $invoiceNo, $transactionId)
	{

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . updateTransactionStatus()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{         
			\"productId\": \"" . ApiBaseUrl()['productID'] . "\",
			\"clientId\": \"" . ApiBaseUrl()['clientID'] . "\",  
			\"_id\":\"" . $id . "\",      
			\"invoiceNo\":\"" . $invoiceNo . "\",      
			\"paymentStatus\": \"COMPLETED\",      
			\"transactionId\": \"" . $transactionId . "\"

		}     
		");

		$token = $this->session->userdata('token');

		$headers = array();

		$headers[] = 'Authorization: Bearer ' . $token . '';

		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);
		$response = json_decode($result);
	}
	// public function contact_us(){
	// 	$data['page'] = 'CONTACT-US';
	// 	$data['title'] = 'CONTACT-US';
	// 	$this->load->view('contact_us',$data);
	// }


	public function submitContactForm()
	{


		$phone = $this->input->post('phone');

		$new_phone = str_replace('-', '', $phone);

		$fname = $this->input->post('fname');
		$lname = $this->input->post('lname');
		$email = $this->input->post('email');
		$regardingTypes = @$this->input->post('regardingTypes');
		$state = $this->input->post('state');
		$city = $this->input->post('city');
		$zipcode = $this->input->post('zipcode');
		$address = $this->input->post('address');
		$message = $this->input->post('message');


		$captcha_response = trim($this->input->post('g-recaptcha-response'));

		if ($captcha_response != '') {

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . sendContactEmail()['url']);


			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{        
				\"firstName\":\"" . $fname . "\",        
				\"lastName\": \"" . $lname . "\",        
				\"phone\": \"" . $new_phone . "\",        
				\"email\": \"" . $email . "\",        
				\"regardingTypes\":\"" . $regardingTypes . "\",        
				\"address\":\"" . $address . "\",        
				\"state\":\"" . $state . "\",        
				\"city\":\"" . $city . "\",        
				\"zipcode\":\"" . $zipcode . "\",        
				\"purpose\":\"\",        
				\"message\":\"" . $message . "\",        
				\"clientID\":\"" . ApiBaseUrl()['clientID'] . "\"      
			}");

			$headers = array();
			$headers[] = 'Content-Type: application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);
			$response = json_decode($result);

			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);



			// print_r($response);

			// die();


			if (@$response->statusCode == 1) {
				$this->session->set_flashdata('success', 'We will contact you as soon as possible.');
				redirect(base_url('contact-us'), 'refresh');
			} else {
				$this->session->set_flashdata('failure', 'Something went wrong!');
				redirect(base_url('contact-us'), 'refresh');
			}
		} else {
			$this->session->set_flashdata('failure', 'Captcha Validation Failed');
			redirect(base_url('contact-us'), 'refresh');
		}
	}

	public function Logout()
	{
		$this->session->sess_destroy();
		$this->session->unset_userdata('logged_in');
		redirect(base_url());
	}



	// *************************++++++++++++++++++++****************************

	public function AddServicetoSession()
	{


		if ($this->input->post('id')) {
			$data = $this->input->post();

			$array = array();
			foreach ($this->input->post('id') as $key => $value) {

				$array[] = array(
					'_id' => $data['id'][$key],
					'serviceName' => $data['serviceName'][$key],

					// 'serviceCategory' => $data['serviceCategory'][$key],
					// 'serviceType' => $data['serviceType'][$key],

					'serviceAmount' => $data['serviceAmount'][$key],
					'startDate' => $data['startDate'][$key],


					'qty' => $data['qty'][$key],

					'time' => $data['startTime'][$key],
					// 'day' => $data['day'][$key],

					// 'serviceAddress' => $data['serviceAddress'][$key],

				);
			}

			$newArray = array(
				'totalPrice' => sprintf("%.2f", $this->input->post('totalPrice')),
				'itemList' => $array,
			);

			$this->session->set_userdata('service_cart', $newArray);
		}


		print_r($newArray);

		$response = array('status' => '1', 'message' => "Success");
		echo json_encode($response);
	}

	public function SubscribeNewsletter()
	{

		// print_r($this->session->userdata());

		if ($this->session->userdata('logged_in') == 1) {

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . SubscribeNewsletter()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{
				\"dataJson\": {
					\"MemberId\": \"" . $this->session->userdata('id') . "\",
					\"Email\": \"" . base64_decode($this->session->userdata('email')) . "\",
					\"DOB\": \"\",
					\"Name\": \"" . $this->session->userdata('refDataName') . "\",
					\"Mobile\": \"" . $this->session->userdata('phone') . "\",
					\"City\": \"\",
					\"State\": \"\",
					\"Nakshatram\": \"\",
					\"gotraName\": \"\",
					\"ZipCode\": \"\",
					\"SpouseName\": \"\",
					\"ChildrenDetails\": \"\",
					\"recCreDate\": \"\",
					\"menberType\": \"" . $this->session->userdata('memberTypes') . "\"
					},
					\"clientId\": \"" . ApiBaseUrl()['clientID'] . "\"
				}");

			$headers = array();
			$headers[] = 'Content-Type: application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);
			$response = json_decode($result);
			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);

			// print_r($response);

			if (isset($response)) {
				if ($response->statusCode == 1) {
					echo json_encode('Yo have successfully subscribed our newsletter.');
				} elseif ($response->statusCode == -1) {
					echo json_encode('You are already subscribed our newsletter!');
				}
			} else {
				echo 	'Something went wrong! Please contact to Administration or Admin.';
			}
		} else {
			redirect(base_url());
		}
	}

	public function getServiceAvailability()
	{

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . getServiceAvailability()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{
			\"clientId\": \"" . ApiBaseUrl()['clientID'] . "\",
			\"aspectType\": \"serviceBooking\",
			\"ServiceSetup\": \"Vadamala Pooja (108 Vadas)\",
			\"startDate\": \"2023-02-01\",
			\"endDate\": \"2023-02-31\",
			\"serviceTypes\": \"VADAMALA\"
		}");

		$headers = array();
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);


		$response = json_decode($result);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);


		print_r($response);
	}

	public function AddFeedback()
	{


		$data['memberId'] = $this->session->userdata('id');
		$data['name'] = $this->session->userdata('refDataName');
		$data['emailId'] = base64_decode($this->session->userdata('email'));
		$data['phoneNo'] = base64_decode($this->session->userdata('phone'));
		$data['feedbackData'] = strtoupper($this->input->post('emoji'));
		$data['feedbackQuestion'] = 'How do you rate our service?';
		$data['date'] = date('m/d/Y');
		$data['time'] = date('H:i A');
		$data['stationName'] = '';
		$data['source'] = 'WEBSITE';


		$postfield = json_encode($data);



		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . addAPI()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{
			\"dataJson\": $postfield,
			\"componentConfig\": {
				\"moduleName\": \"Feedbacks\",
				\"productID\": \"" . ApiBaseUrl()['productID'] . "\",
				\"clientID\": \"" . ApiBaseUrl()['clientID'] . "\",
				\"userName\": \"" . $this->session->userdata('refDataName') . "\"
			}}");

		$token = $this->session->userdata('token');
		$headers = array();
		$headers[] = 'Authorization: Bearer ' . $token . '';
		$headers[] = 'Content-Type:application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);

		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);
		echo json_encode($result);
	}

	public function GetCity()
	{
		$stateName = $this->input->post('stateCode');


		$CI = &get_instance();
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . filterAPI()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"componentConfig\":    {      
			\"moduleName\": \"Master Data Management\",      
			\"productID\":\"" . ApiBaseUrl()['productID'] . "\",      
			\"clientID\": \"" . ApiBaseUrl()['clientID'] . "\",      
			\"aspectType\":\"cityTypes\",      
			\"query\": {        \"aspectType\": \"cityTypes\",   \"refDataCode\" : \"" . $stateName . "\"   },    
			\"skip\": 0,      
			\"next\": 700    }    }");

		$headers = array();

		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);

		$response = json_decode($result);

		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);

		$option = '<option value="" selected disabled>Select City</option>';


		$keys = array_column($response->data, 'refDataName');
		array_multisort($keys, SORT_ASC, $response->data);

		foreach ($response->data as $item) {

			$option .= '<option value="' . $item->refDataName . '">' . $item->refDataName . '</option>';
		}

		echo $option;
	}

	public function GetPriestAvailibility()
	{
		$serviceDate = $this->input->post('serviceDate');
		$targetTime = $this->input->post('serviceTime');

		$result = '';
		if (!empty($serviceDate) && !empty($targetTime)) {
			$result = GetPriestAvailibility($serviceDate, $targetTime);
		}
		$PriestData = $result->data;
		// $userDetails = getUserDetails()->data[0];

		$options = '';
		$options .= '<option value=" " selected disabled>Select Preferred Priest</option>';
		if (!empty($PriestData)) {
			foreach ($PriestData as $item) {
				if ($item->availability == 'Available') {
					$options .= '<option value="' . $item->refDataName . '" email="' . base64_decode($item->email) . '" phone="' . base64_decode($item->phone) . '" priestID="' . $item->_id . '">' . $item->refDataName . '</option>';
				}
			}
		} else {
			$options .= '<option value="" selected disabled>Priest Not Available.</option>';
		}

		// $options .= '<option value="Any Priest" email="" phone="" priestId="0">Any Priest</option>';


		echo $options;
	}

	public function sendMemberAuthCode()
	{



		$email = $this->input->post('email');

		$data = array('email' => $email, 'isMobile' => false, 'phone' => '');



		$postfield = json_encode($data);

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerLogin()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
			\n      \"componentConfig\": {\n        \"moduleName\": \"" . customerLogin()['moduleName'] . "\",\n        \"productID\": \"" . ApiBaseUrl()['productID'] . "\",\n        \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"\n    }}");
		$headers = array();
		$headers[] = 'Content-Type:application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$result = curl_exec($ch);
		$response = json_decode($result);




		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}

		// $response->statusCode == 1;
		if ($response->statusCode != 1) {
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . sendEmailOTP()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"emailID\":\"" . $email . "\",\"clientID\":\"" . ApiBaseUrl()['clientID'] . "\"}");

			$headers = array();
			$headers[] = 'Content-Type: application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);
			$response = json_decode($result);
			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);






			if ($response->user->statusCode == 0) {
				$response->user->statusCode = '2';
			}
			echo json_encode($response->user);
		} else {
			$response->statusCode = -1;
			$response->message = "Email Already Exist.Please Login To Continue.";
			echo json_encode($response);
		}
	}

	public function SignUpLogin()
	{

		if (!empty($this->input->post('fname')) || !empty($this->input->post('email')) || !empty($this->input->post('email'))) {
			$fname = $this->input->post('fname');
			$lname = $this->input->post('lname');
			$email = $this->input->post('email');
			$phone = $this->input->post('phone');
			$phone = preg_replace('/[^\d]/', '', $phone);
			$countryCode = $this->input->post('countryCode');
			$data = array('refDataName' => $fname . ' ' . $lname, 'email' => $email, 'phone' => $phone, 'contryCode' => $countryCode, 'firstName' => $fname, 'lastName' => $lname);







			$postfield = json_encode($data);

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerSignup()['url']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
				\n      \"componentConfig\": {\n        \"moduleName\": \"" . customerSignup()['moduleName'] . "\",\n        \"productID\": \"" . ApiBaseUrl()['productID'] . "\",\n        \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"\n    }}");

			$headers = array();
			$headers[] = 'Content-Type:application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

			$result = curl_exec($ch);

			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}
			curl_close($ch);
			$resultres = json_decode($result);
			// var_dump($result->statusCode);die();
			if ($resultres->statusCode == 1) {
				$data = array('email' => $email, 'isMobile' => false, 'phone' => '');



				$postfield = json_encode($data);

				$ch = curl_init();
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

				curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . customerLogin()['url']);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_POST, 1);
				curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"dataJson\": $postfield,
			\n      \"componentConfig\": {\n        \"moduleName\": \"" . customerLogin()['moduleName'] . "\",\n        \"productID\": \"" . ApiBaseUrl()['productID'] . "\",\n        \"clientID\": \"" . ApiBaseUrl()['clientID'] . "\"\n    }}");
				$headers = array();
				$headers[] = 'Content-Type:application/json';
				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
				$result1 = curl_exec($ch);
				$response = json_decode($result1);




				if (curl_errno($ch)) {
					echo 'Error:' . curl_error($ch);
				}

				if ($response->statusCode == 1) {
					$logged_in_sess = array(
						'id'           => $response->data[0]->_id,
						'refDataName'         => $response->data[0]->refDataName,
						'email'         => $response->data[0]->email,
						'phone'       => $response->data[0]->phone,
						'logged_in'    => 1,
						'token' => $response->data[0]->token,
						'memberTypes' => @$response->data[0]->memberTypes,
						'membershipPaymentStatus' => @$response->data[0]->membershipPaymentStatus,
						'membershipStatus' => @$response->data[0]->membershipStatus,
						'membershipId' => @$response->data[0]->membershipId,
						'memberShipExpiryDate' => @$response->data[0]->memberShipExpiryDate,
						'membershipName' => @$response->data[0]->membershipName,
						'membershipStartDate' => @$response->data[0]->membershipStartDate,
						'address' => @$response->data[0]->address,
						'userType' => 'Devotee'

					);
					$this->session->set_userdata($logged_in_sess);
				}

				// var_dump($result1);die();
				echo json_encode($result1);
			} else {
				echo json_encode($result);
			}
		} else {
			echo 'Something Went Wrong!!';
		}
	}


	public function updateLoginSessionData()
	{
		$response = getUserDetails();
		if ($response->statusCode == 1) {
			$logged_in_sess = array(
				'id'           => $response->data[0]->_id,
				'refDataName'         => $response->data[0]->refDataName,
				'email'         => $response->data[0]->email,
				'phone'       => $response->data[0]->phone,
				'logged_in'    => 1,
				'token' => $response->data[0]->token,
				'memberTypes' => @$response->data[0]->memberTypes,
				'membershipPaymentStatus' => @$response->data[0]->membershipPaymentStatus,
				'membershipStatus' => @$response->data[0]->membershipStatus,
				'membershipId' => @$response->data[0]->membershipId,
				'memberShipExpiryDate' => @$response->data[0]->memberShipExpiryDate,
				'membershipName' => @$response->data[0]->membershipName,
				'membershipStartDate' => @$response->data[0]->membershipStartDate,
				'address' => @$response->data[0]->address,
				'userType' => 'Devotee'

			);
			$this->session->set_userdata($logged_in_sess);
		}
		echo json_encode(1);
	}
	function updateCartCount()
	{
		$service_cart_items = @$this->session->userdata('service_cart');
		$sponser_cart_items = @$this->session->userdata('sponsorship_cart');
		$event_cart_items = @$this->session->userdata('events_cart');
		$donation_cart_items = @$this->session->userdata('donations_cart');
		$books_cart_items = @$this->session->userdata('books_cart');
		//  $sponser_cart_items = $this->session->userdata($session_data);
		// var_dump($sponser_cart_items);die();
		$totalItemsCount = 0;

		$totalItemsCount += !empty($service_cart_items) && isset($service_cart_items['ids']) ? count($service_cart_items['ids']) : 0;
		$totalItemsCount += !empty($sponser_cart_items) && isset($sponser_cart_items['ids']) ? count($sponser_cart_items['ids']) : 0;
		$totalItemsCount += !empty($event_cart_items) && isset($event_cart_items['ids']) ? count($event_cart_items['ids']) : 0;
		$totalItemsCount += !empty($donation_cart_items) && isset($donation_cart_items['ids']) ? count($donation_cart_items['ids']) : 0;
		$totalItemsCount += !empty($books_cart_items) && isset($books_cart_items['ids']) ? count($books_cart_items['ids']) : 0;
		echo json_encode($totalItemsCount);
	}

	public function PoojaListPdf()
	{
		$this->load->view('pooja-list');
	}

		public function PoojaListPdf2()
	{
		$this->load->view('pooja-list2');
	}

	public function loadPartishipentModal($id = null)
	{
		$data['page'] = 'Home';
		$data['action'] = 'addParticipateEvent';
		$data['data'] = getPartisipentEvnt($id); // optional
		$data['userdata'] = getUserDetails(); // optional
		$this->load->view('includes/dynamic-modal', $data); // return partial view
	}



	public function sendPanchangaPdfMail()
	{

		if ($this->session->userdata('logged_in') == 1) {

			$mailBody = "Hello " . $this->session->userdata("refDataName") ?? "Devotee";
			$mailBody .= "! Thank you for subscribe panchangam.";

			$data = array(
				"clientId" => ApiBaseUrl()['clientID'],
				// "filePath" => "C=>/xampp/htdocs/WEBSITE_sreedevipeetham/assets/pdf/Calendar-2025.pdf",
				// "filePath" => APPPATH."assets/pdf/Calendar-2025.pdf",
				"filePath" => FCPATH . "assets/pdf/Calendar-2025.pdf",
				"toMail" => base64_decode($this->session->userdata("email")),
				"subject" => "Calendar Punchangam Subcribe",
				"mailBody" => $mailBody
			);



			$postfield = json_encode($data);
			// var_dump($postfield);
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

			curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'] . "api/genpdf/sendPanchangaPdfMail");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
			$headers = array();
			$headers[] = 'Content-Type:application/json';
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			$result = curl_exec($ch);
			$response = json_decode($result);




			if (curl_errno($ch)) {
				echo 'Error:' . curl_error($ch);
			}


			// echo json_encode($response);
			echo json_encode([
				"statusCode" =>  $response->statusCode ?? "-1",
				"message" =>  $response->msg ?? "Something went wrong",
				"data" => []
			]);
		} else {
			// $response['res'] = "-1";
			// $response['msg'] = "Please Login";
			echo json_encode([
				"statusCode" => "-1",
				"message" => "Please login.",
				"data" => []
			]);
		}
	}
	public function terminate()
	{
		$this->load->view('terminate');
	}

		public function QRregistration()
	{
		$this->session->sess_destroy();
		$this->session->unset_userdata('logged_in');
			$data['page'] 		= 'Home';
		$data['pageTitle'] 	= 'SIGNUP';
		$data['GetState'] = GetState();
		$data['header_data'] = getWebSyncsData('Header Settings', 'headerSettings', '');
		$this->load->view('qr-registration',$data);
	}


	public function QRLogin()
	{
		$this->session->sess_destroy();
		$this->session->unset_userdata('logged_in');
			$data['page'] 		= 'Home';
		$data['pageTitle'] 	= 'LOGIN';
		$data['GetState'] = GetState();
		$data['header_data'] = getWebSyncsData('Header Settings', 'headerSettings', '');
		$this->load->view('qr-login',$data);
	}



	
}
