<?php 
	
// check if pay per post is enabled or not
	
	$id = $payPerPostData->getId();
	$productid = $payPerPostData->getProductId();
	$enable_pay_per_post = $payPerPostData->getEnablePayPerPost();
	$not_logged_in_msg = $payPerPostData->getNotLoggedIn();
	$no_access_msg = $payPerPostData->getNotHaveAccess();
	$button_layout = $payPerPostData->getButtonLayoutoption();
	$showTeaser = $payPerPostData->getShowTeaserContent();
	$teaserContent = $payPerPostData->getTeaserContent();
	$teaserContent = $before_more_tag_text.$teaserContent;
	
	echo '<div class="pp-post-content-outer">';	
			
	if($enable_pay_per_post == 'N'){
		echo $content; //pay per post is not enabled so show the content and return		 
		return;
	}

	//pay per post is enabled 
	
	//check if user is logged in
	
	$payPerPostMetaData = pppLoadHtmlToShow($pageid, $payPerPostData);
	
	$session = Dap_Session::getSession();
	$user = $session->getUser();
	
	if( !Dap_Session::isLoggedIn()  || !isset($user) ) {
		if($enable_pay_per_post == "Y"){
			?>
			<link rel="stylesheet" href=<?php echo plugin_dir_url(__FILE__) ."includes/css/payPerPost.css?v=".rand(10,1000); ?> />
			<?php
			echo $teaserContent.'<hr><div class="pp-post-message">'. $not_logged_in_msg. '</div>'; /*user is not logged in to , so show not logged in message and return*/
			echo $payPerPostMetaData;	
			return;  
		}
	}
	if( isset($user) ) {	
		
		//user is logged in
		//check if user have access to this post
		
		$userId = $user->getId();
	
		//check if user have access to the content
	
		$hasAccess = DAP_UserPayPerPost::hasAccessTo($userId,$pageid);
		
		if($hasAccess){
			
			echo $content; //user have access to this post, show the content and return
			return;
		}else{
			?>
			<link rel="stylesheet" href=<?php echo plugin_dir_url(__FILE__) ."includes/css/payPerPost.css?v=".rand(10,1000); ?> />
			<?php
			if($showTeaser == 'Y'){
				echo $teaserContent.'<hr><div class="pp-post-message">'. $no_access_msg. '</div>'; // user doesnt have access to post
			}else{
				echo '<div class="pp-post-message">'. $no_access_msg. '</div>'; // user doesnt have access to post	
			}
			
			
			echo $payPerPostMetaData;	
					
		}
	
	}
	echo '</div>';
?>	


	
	
