<?php 

$loging_status = false;
if(!Dap_Session::isLoggedIn()){ 
	$loging_status = true;
	
}
if (!class_exists('Facebook')) {
	include_once( 'includes/plugins/facebookapi/src/facebook.php' );
}  
	// for unset the login session
	$_SESSION['daploginform'] = "";
	unset($_SESSION['daploginform']);
	
	$mp_obj = DAP_MemberPages::loadById($id);
	if($mp_obj && ($mp_obj->getAction() == 'loginFB')){
		//add_action('wp_footer', 'dap_member_login_frontend_print_scripts', 5);
		$action_id = $mp_obj->getId();
		$template =  $mp_obj->getTemplateHtml();
		$template = explode("%%DAPMEMBERLOGINTEMPLATE%%",$template);
		
		$template1 = '';
		if(isset($template[0])){
			$template1 = $template[0];
		}
		if(isset($template[1])){
			$template2 = $template[1];
		}
		if(isset($template[2])){
			$template3 = $template[2];
		}
		
		
		$dap_login_ajax_url =  admin_url( 'admin-ajax.php' );		
        $dap_login_ajax_url = "<script> var  dap_login_ajax_url = '".$dap_login_ajax_url."'</script>";	
		$html   = "<div id='dap_member_login_frontend_shortcode' class='live-links-bootstrap_outer dap_member_frontend_shortcode dap_member_login_frontend_shortcode_".$mp_obj->getId()."'>";
		$html  .= "<link rel='stylesheet' id='dap_member_frontend_common-css'  href='".dap_member_path."includes/css/dap_member_frontend_common.css?10' type='text/css' media='all' />";
		
		
		$html  .= "<link name='dap_member_login_style' rel='stylesheet' href='".dap_member_path."includes/templates/".$mp_obj->getAction()."/".$mp_obj->getTemplate()."/style.css?".rand(10,1000)."'>";
									
			

			
			
				 
		if($loging_status){
			
			wp_register_script( 'jQuery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', null, null, true );
            wp_enqueue_script('jQuery');
            
            wp_register_script( 'dap_jQuery_sweetalert2', '//cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.js', null, null, true );
            wp_enqueue_script('dap_jQuery_sweetalert2');
			 
			$html  .= "<link rel='stylesheet' id='dap_member_bootstrap4-css'  href='".dap_member_path."includes/css/bootstrap4.min.css' type='text/css' media='all' />
						
						<link rel='stylesheet' id='dap_member_sweetalert2-css'  href='//cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.css' type='text/css' media='all' />
						<link rel='stylesheet' id='dap_member_font_awesome-css'  href='//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' type='text/css' media='all' />
						<link rel='stylesheet' id='dap_member_font-css'  href='//fonts.googleapis.com/css?family=Open+Sans%3A400%2C600%2C700&#038;display=swap' type='text/css' media='all' />	
										
						<script type='text/javascript' src='".dap_member_path."includes/js/dap_member_frontend_common.js?".rand(10,1000)."'></script>
						<script type='text/javascript' src='".dap_member_path."includes/js/dap_members_loginFB.js?".rand(10,1000)."'></script>
						<script type='text/javascript' src='".dap_member_path."includes/js/dap_member_frontend_login.js?".rand(10,1000)."'></script>
						";
			
			$signin_display = 'display:none';
			if(isset($_GET['action']) && ($_GET['action'] == 'rp')){
				$html  .= "<div class='user_login reset_password_div' style='display:none' id='reset_password_div_id_".rand(10,10000)."'>";
				$html  .= DapMemberLoginReplaceMergeTags($template1);
				$html  .= "<div class='dap_reset_template_static_div' style='display:none'>".DapMemberLoginReplaceMergeTags($template3)."</div>";
				$html  .= "<input type='hidden' name='dm_reset_pass_key' value='".$_GET['key']."'>";		
				$html .= "</div>";
				//$html .= "<div>";
			}else{
				$signin_display = '';
			}	
			
			if(dapMemberLoginCheckedCaptchaEnable($mp_obj->getId())){			
				$html  .= '<script src="//www.google.com/recaptcha/api.js" async defer></script>';	
				$dm_login_temp_captcha = 'yes';
			}	
			$html  .= "<div class='user_login signin_forgot_password_div' style='".$signin_display."' id='parent_outer_class_".rand(10,1000)."'>";
			$html  .= DapMemberLoginReplaceMergeTags($template1,$mp_obj);
			$html  .= "<div class='dap_forgot_template_static_div' style='display:none'>".DapMemberLoginReplaceMergeTags($template2)."</div>";
			
			
			
		  // $html .= "</div>";
		   $html .= "<div>";
		   $html .= "<input type='hidden' name='action_id' value='".$action_id."'>";		
		   $html .= "<input type='hidden' name='dm_login_temp_captcha' value='".$dm_login_temp_captcha."'>";	
		   $html .= '<input  type="hidden" name="dap_email_empty" value="'.dapMemberGetMessageByKeyAndAction('login','email_empty').'">
				     <input  type="hidden"  name="dap_password_empty" value="'.dapMemberGetMessageByKeyAndAction('login','password_empty').'">
					<input  type="hidden"  name="dap_email_valid" value="'.dapMemberGetMessageByKeyAndAction('login','email_valid').' ">
					<input  type="hidden"  name="dap_email_password_wrong" value="'.dapMemberGetMessageByKeyAndAction('login','email_password_wrong').' ">
					<input  type="hidden"  name="dap_login_success" value="'.dapMemberGetMessageByKeyAndAction('login','login_success').' ">
					<input  type="hidden"  name="dap_email_not_found" value="'.dapMemberGetMessageByKeyAndAction('login','email_not_found').'">
					<input  type="hidden"  name="dap_reset_link" value="'.dapMemberGetMessageByKeyAndAction('login','reset_link').'">
					<input  type="hidden"  name="dap_password_not_match" value="'.dapMemberGetMessageByKeyAndAction('login','password_not_match').'">
					<input  type="hidden"  name="dap_reset_password_success" value="'.dapMemberGetMessageByKeyAndAction('login','reset_password_success').'">
					<input  type="hidden"  name="dap_reset_key_expired" value="'.dapMemberGetMessageByKeyAndAction('login','reset_key_expired').'">
					<input  type="hidden"  name="dap_captcha_not_select" value="'.dapMemberGetMessageByKeyAndAction('login','captcha_not_select').'">
					<input  type="hidden"  name="invalid_captcha" value="'.dapMemberGetMessageByKeyAndAction('login','invalid_captcha').'">
					
					<input  type="hidden"  name="dap_fblogin_email" value="">
					<span class="dap_fblogin_text" style="display:none"></span>
					<span style="display:none" class="dap_login_btn_html"></span>
					<input  type="hidden"  name="facebooklinkheadingmsg" value="'.dapMemberGetMessageByKeyAndAction('loginFB','link_account_heading_msg').'">
					<span style="display:none" class="dap_loader_html"><i class="fa fa-spinner fa-pulse fa-3x fa-fw" style="font-size:36px;"></i></span>
					<div class="facebooklinkmsg" style="display:none">'.stripslashes(dapMemberGetMessageByKeyAndAction('loginFB','link_account_confirm_box_msg')).'</div>
					<input  type="hidden"  name="dapfbloginkey" value="'.Dap_Config::get("FB_API_KEY").'">';
					
					
					
					
				
		   $html .= "</div>";	
		   
		   //For CS login to set the login session	   
		   $_SESSION["daploginform"]="yes";	
		   	
		   $html .= $dap_login_ajax_url;		
		   $html .= DapMemberShowLoader();	
		}else{
			//$html .= "You are already logged in. <a href='".dapMemberGetPostLoginURl($action_id)."'>Click here to continue...</a>";
			$already_login_msg = stripslashes(dapMemberGetMessageByKeyAndAction('login','already_login'));
			
			$redirectURL = Dap_UsersProducts::getLoggedInURL();
			$already_login_msg = str_replace('%%LINKSTART%%','<a href="'.$redirectURL.'">',$already_login_msg);
			$already_login_msg = str_replace('%%LINKEND%%','</a>',$already_login_msg);
			$already_login_msg = str_replace('%%HERE%%','<a href="'.$redirectURL.'">here</a>',$already_login_msg);
			$html .= "<div class='dap_alredy_login'>".$already_login_msg."</div>";
			
			$session = DAP_Session::getSession();
			$user = $session->getUser();	
			if( $session->isAdmin() ) {
				$dap_admin_login_msg = stripslashes(dapMemberGetMessageByKeyAndAction('login','dap_admin_already_login'));
				
				$dap_admin_login_msg = str_replace('%%LINKSTART%%',"<a href='/dap/admin/'>",$dap_admin_login_msg);
				$dap_admin_login_msg = str_replace('%%LINKEND%%','</a>',$dap_admin_login_msg);
				$html .= "<div class='dap_admin_alredy_login dap_alredy_login'>".$dap_admin_login_msg."</div>";
			
				
			
			}else if($user->getAccount_type() == "C" && $user->getCustom_role_id() != ""){	
				try{
					$role = Dap_UserRoles::loadRoleById($user->getCustom_role_id());
					if(isset($role) && $role != ""){
						$dap_account_type_roll_login = dapMemberGetMessageByKeyAndAction('login','dap_account_type_roll_login');
											
						$dap_account_type_roll_login = str_replace('%%LINKSTART%%',"<a href='/dap/admin/'>",$dap_account_type_roll_login);
						$dap_account_type_roll_login = str_replace('%%LINKEND%%','</a>',$dap_account_type_roll_login);
						$dap_account_type_roll_login = str_replace('%%USERROLL%%',$role['name'],$dap_account_type_roll_login);
						$html .= "<div class='dap_alredy_login dap_account_type_c_login'>".$dap_account_type_roll_login."</div>";
						//$html = $html . ">>> <a href='/dap/admin/'>You are logged in as ".$role['name'].". Click here to proceed</a> <<< <br/><br/>";
					}
				}
				catch(Exception $e){
					
					logToFile('DAP-Shortcodes-LoginForm.php: Cant get the role details');
				}
			
			}
			
			
			

		}
	   $html  .= "</div>";	
	   echo $html;	
		
	}
	
	
$admin_url = admin_url('admin-ajax.php');
$admin_post_url = admin_url();
$admin_post_url = $admin_post_url . 'admin-post.php';

$fbClientID = Dap_Config::get("FB_API_KEY");  
$fbapisecret = Dap_Config::get("FB_SECRET"); 



?>
<style>
.error_message_div {display:none;}
</style>

<script>
	var admin_ajaxurl = "<?= $admin_url ?>";
    var admin_post_url = "<?= $admin_post_url ?>";
    var fbClientID = "<?= $fbClientID ?>";
</script>	

