<?php
/**
 * Template Name: login Page Template
 *
 * Description: A page template that provides a key component of WordPress as a CMS
 * by meeting the need for a carefully crafted introductory page. The front page template
 * in Twenty Twelve consists of a page content area for adding text, images, video --
 * anything you'd like -- followed by front-page-only widgets in one or two columns.
 *
 * @package WordPress
 * @subpackage Soluk
 * @since Soluk
 */
//if(@$_POST['username'])

$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";


$site_icon=get_theme_mod('login_bg_icon');
$site_name=get_bloginfo( 'name' );
$captcha=get_captcha();
$url_prefix=get_site_url();


 ?>




	<img class="login_background" src="<?php echo get_theme_mod('login_bg'); ?>">
	 <div class="container-fluid">
			<div class="row">
				<div class="col-md-5" style="margin:auto;direction: rtl;">
					<div class="login_card_container <?php if(get_theme_mod('login_box_position')=='راست') echo 'login_right_position'; else  if(get_theme_mod('login_box_position')=='چپ') echo 'login_left_position'; else echo 'login_center_position';  ?>">
						
						<?php

							if( get_theme_mod('login_box_header')!='0' && get_theme_mod('login_box_header')!=' ' && get_theme_mod('login_box_header')!='')
								{ ?>
									<div class="login_box_header" 
										 style="display:flex; justify-content:center; align-items:center; text-align:center; //height:300px;">
										<p style="margin:0;"><?php echo get_theme_mod('login_box_header'); ?></p>
									</div>
									<?php
								}
								
								$msg='';
								if(!check_login_register_time('login'))
									$msg= get_time_of_login(); // پیام پایان زمان ورود

								if( get_theme_mod('active_login_checkbox')==1 && !str_starts_with($msg, 'زمان حضور در انتخابات') || $admin)
									{
										if( get_theme_mod('mobile_login_checkbox')=='1')
											{
												if(str_starts_with($msg, 'در حال حاظر ورود'))
													echo '<p class="msg-box-time">'.$msg.'</p>';
																		
									?>
											
													<div>
													</div>
													<!-- فرم ارسال کد otp -->
													<div id="send_otp_form" class="<?php  if( get_theme_mod('password_login_checkbox')=='1') echo 'hide_content';?>">
												
														<div class="input_container"> <img class="menu_logo_img" style="display: block;" src="<?php echo $site_icon; ?>"/>
															<span style="display: block;text-align: center;border-bottom: 1px solid #a1a1a1;padding-bottom: 7px;"><?php echo $site_name; ?></span>
														</div>

														<div id="mobile_msg"></div>
												
														<form id="otp_login_form">
														
															<div class="input_container">
																<label for="mobile">شماره همراه :</label><input style="width: 100%;direction: ltr;" id="otp_mobile" placeholder="09..." type="text" name="mobile" class="login_input no_farsi">
															</div>
															
															<div class="input_container" style="padding: 11px 0px;"><label for="captcha">کد امنیتی عبور:</label>
																
																<?php
																	echo "<img id='captcha_image' style='height:38px' src='data:image/jpeg;base64," . $captcha . "' />";
																?>
															
																<input id="captcha_mobile" style="width: 43%;float: left;height:38px;text-align: center;" type="text" class="login_input no_farsi" name="captcha">
															</div>
														</form>
												
														<div>
															<a class="otp_btn enter_btn" id="otp_send_code_btn">ارسال کد تایید</a>
														</div>
													
													<?php 
													
														if( get_theme_mod('guest_login_checkbox')=='1')
														{
														
															?>
														
															<div>
															<a class="otp_btn accounting_btn_margin x-accounting_btn_margin" style="background-color: #7e7e7e;" href="<?php echo $url_prefix; ?>/panel">ورود به صورت میهمان</a>
															</div>

															<?php
														}
													?>
												</div> <!-- فرم ارسال کد otp -->

													<!-- فرم تایید کد otp -->
													<div id="otp_login" class="hide_content">
														<div id="mobile_msg_otp"></div>
														
														<div class="input_container">
															<label for="mobile">کد پیامکی را وارد کنید</label><input  autocomplete="one-time-code" id="otp_input" type="text" name="mobile" class="login_input">
														</div>
														
														<div>
															<a id="otp_lgin_btn_ajax" class="login_btn_login_box otp_btn  enter_btn" >ورود</a>
														</div>
													</div><!-- فرم تایید کد otp -->

												<?php 

											}
												//فرم ورد با پسورد
												if( get_theme_mod('password_login_checkbox')=='1')
												{
													if( get_theme_mod('username_caption')!='0')
														$username_caption=get_theme_mod('username_caption');
													else
														$username_caption='کد ملی: 10 رقمی';


													if( get_theme_mod('password_caption')!='0')
														$password_caption=get_theme_mod('password_caption');
													else
														$password_caption='رمز عبور:';


													?>
													<form action="<?php echo plugins_url( 'form_submit.php', __FILE__ ); ?>" method="post" id="normal_login" style="margin-bottom: 0px">

															<div class="input_container"> <img class="menu_logo_img" style="display: block;" src="<?php echo $site_icon; ?>"/>
																<span style="display: block;text-align: center;border-bottom: 1px solid #a1a1a1;padding-bottom: 7px;"><?php echo $site_name; ?></span>
															</div>
														
																<?php

														$msg='';
														if(@$_GET['msg'])
															{
																switch($_GET['msg'])
																{
																	case 'error':
																		$msg='نام کاربری یا رمز عبور وارد شده نادرست است';
																		break;
																		
																	case 'captcha_error':
																		$msg='کد امنیتی وارد شده اشتباه است';
																		break;
																		
																	case 'username_error':
																		$msg='نام کاربری وارد شده اشتباه است';
																		break;
																		
																	case 'password_error':
																		$msg='رمز عبور وارد شده اشتباه است';
																		break;
																		
																	case 'error_time':
																		$msg='زمان غیرمجاز برای ورود';
																		break;
																		
																	case 'pending':
																		$msg='عضویت شما در حال حاضر تایید نگردیده است';
																		break;
																	
																	default:
																		$msg='خطا ناشناخته';
																		break;
																}
																?>
																<div class="input_container"><span class="login_error_msg" ><?php echo $msg; ?></span></div>

																<?php
															}
															?>		
														

														<div class="input_container" style="padding: 4px 0px;"><label for="username"><?php echo $username_caption; ?></label><input value="<?php if(@$_GET['username']) echo $_GET['username']; else echo ''; ?>" style="width:100%" type="text" name="username" class="login_input no_farsi">
														</div>
														
														<div class="input_container" style="padding: 4px 0px;"><label for="password"><?php echo $password_caption; ?></label><input style="width:100%" type="
														<?php if(get_theme_mod('star_password_toggle')=='0') echo 'text'; else echo 'password';?>" class="login_input no_farsi" name="password">
														</div>
														
														<div class="input_container" style="padding: 11px 0px;"><label for="captcha">کد عبورامنیتی :</label>
													
															<?php
																echo "<img style='height:38px' src='data:image/jpeg;base64," . $captcha . "' />";
															?>
															
															<input style="width: 43%;float: left;height:38px;text-align: center;" type="text" class="login_input" name="captcha">
															
														</div> 
														
													<div class="row">	
															<div class="col-12 col-md-12">
																<input type="hidden" value="<?php echo $actual_link ?>" name="backlink">
																	<input  class="login_btn_login_box accounting_btn_margin enter_btn" type="submit" name="submit" value="ورود به سامانه">
															</div>
															
															<?php 
																if( get_theme_mod('mobile_login_checkbox')=='1')
																{
															?>
																	<div class="col-12 col-md-12">
																		<span class="otp_btn btn_hover" id="otp_send_form">ورود با تلفن همراه (رمز پیامکی)</span>
																	</div>
													
															<?php
																}
															?>

													



												<?php 
														if( get_theme_mod('guest_login_checkbox')=='1' )
														{
															$url_prefix=get_site_url();
													?>
															<div class="col-12 col-md-12">
																<a class="login_btn_login_box accounting_btn_margin x-accounting_btn_margin" href="<?php echo $url_prefix; ?>/panel">ورود به صورت میهمان</a>
															</div>

												<?php
														}
														
														if( get_theme_mod('register_btn_visible')=='1' )
														{
															$url_prefix=get_site_url();
													?>
															<div class="col-12 col-md-12">
																<a class="login_btn_login_box accounting_btn_margin" style="background-color: #47af70;" href="<?php echo $url_prefix; ?>/register">ثبت نام</a>
															</div>

												<?php
														}
													?>
															</div>
														</form>
													<?php
												}
											?>


											<?php
									}
							else{
							 $msg= get_time_of_login(); // پیام پایان زمان ورود
													 
	?>

							<div id="otp_login">
							
								<div class="input_container msg-box-time">
									<label for="mobile"> <?php echo $msg; ?> </label>
								</div>
								
								<div class="col-12 col-md-12" style="color:red;text-align: center">
								</div>
								
								<div class="col-12 col-md-12">
									<a class="login_btn_login_box" style="background-color: #7e7e7e;" href="<?php echo $url_prefix; ?>/panel">ورود به صورت میهمان</a>
								</div>
								
								<script type="text/javascript">
									setTimeout(function()
									{

										//window.location.href = url_prefix+'/panel/';

									}, 5000);
								</script>
								
							</div>

									<?php
								}
							?>
							<div>
								<span class="login_help_link" title="راهنمای ورود">
									<svg viewBox="0 0 24 24" width="25" height="25" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
										<circle cx="12" cy="12" r="10"></circle>
										<path d="M9.09 9a3 3 0 1 1 5.82 1c0 2-3 2-3 4"></path>
										<line x1="12" y1="17" x2="12" y2="17"></line>
									</svg>
								</span>
								
								<div class="login_question_bg">
									<div class="login_question">
										<div class="close_btn"><span>X</span></div>
											<?php
												if( get_theme_mod('mobile_login_checkbox')=='1')
												{
													echo get_theme_mod('login_guid_mobile_textarea');
												}
												if( get_theme_mod('password_login_checkbox')=='1')
												{
													echo get_theme_mod('login_guid_password_textarea');
												}
											?>
									</div>
								</div>
							</div>
							<?php


								if( get_theme_mod('login_box_footer')!='0' && get_theme_mod('login_box_footer')!=' ' && get_theme_mod('login_box_footer')!='')
								{
							?>
									<div class="login_box_footer"
										style="display:flex; justify-content:center; align-items:center; text-align:center;">
										<p style="margin:0";><?php echo get_theme_mod('login_box_footer'); ?></p>
									</div>
							<?php
								}
							?>

					</div>
				</div>
			</div>
		</div>

		<style type="text/css">
			header,footer{
				display: none !important;
			}
			.fbox {
				padding: 0px !important;
				margin-bottom: 0px;
			}
			.msg-box-time {
				background: #ff8800;           /* بک‌گراند نارنجی */
				color: #fff;                   /* رنگ متن سفید */
				padding: 10px 2px;            /* فاصله داخلی */
				text-align: right;            /* مرکز چین افقی */
				display: flex;
				align-items: center;           /* مرکز چین عمودی */
				justify-content: center;       /* مرکز چین افقی با فلکس */
				border-radius: 8px;            /* گوشه‌های گرد */
				font-size: 15px;               /* سایز مناسب */
				font-weight: 600;              /* ضخامت */
				margin: 10px auto;                /* فاصله از بالا و پایین */
				direction: rtl;
			}
			
			.login_help_link {
				display: inline-flex;
				align-items: center;
				cursor: pointer;
				color: #6b7280;
				transition: all 0.2s ease;
			}

			.login_help_link:hover {
				color: #0073aa;
				transform: scale(1.1);
			}



		</style>


<?php
?>
