<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;

// Check user is logged in and redirect to user page
$login_referer = isset($_GET['referer']) ? $_GET['referer'] : '';

$fb_login = isset($campoal_options['conikal_fb_login_field']) ? $campoal_options['conikal_fb_login_field'] : 0;
$google_login = isset($campoal_options['conikal_google_login_field']) ? $campoal_options['conikal_google_login_field'] : 0;
$condition_text = isset($campoal_options['conikal_condition_text_field']) ? $campoal_options['conikal_condition_text_field'] : '';
$choose_username = isset($campoal_options['conikal_choose_username_field']) ? $campoal_options['conikal_choose_username_field'] : 0;
$two_input_name = isset($campoal_options['conikal_two_input_name_field']) ? $campoal_options['conikal_two_input_name_field'] : 0;
$repeat_password = isset($campoal_options['conikal_repeat_password_field']) ? $campoal_options['conikal_repeat_password_field'] : 0;
$recaptcha_login = isset($campoal_options['conikal_google_recaptcha_login_field']) ? $campoal_options['conikal_google_recaptcha_login_field'] : 1;
$recaptcha_forgot_password = isset($campoal_options['conikal_google_recaptcha_forgot_password_field']) ? $campoal_options['conikal_google_recaptcha_forgot_password_field'] : 1;
$remember_login = isset($campoal_options['conikal_remember_login_field']) ? $campoal_options['conikal_remember_login_field'] : 'all';
$signup_newsletters = isset($campoal_options['conikal_signup_newsletters_field']) ? $campoal_options['conikal_signup_newsletters_field'] : 'checked';

// get location of user by GeoIp
$geoip_info = function_exists('conikal_client_geoip_info') ? conikal_client_geoip_info() : false;
?>

<!-- SIGN IN AND SIGN UP MODAL -->
<div class="ui modal" id="signinModal">
    <i class="close icon"></i>
    <div class="content">
        <div class="ui two column middle aligned stackable internally celled grid">
            <div class="column">
                <div class="respon-message" id="signinMessage"></div>
                <form class="ui form sign-up" id="userSignupForm">
                    <?php if ($two_input_name != 0) : ?>
                    <div class="two fields">
                        <div class="required field">
                            <label><?php esc_html_e('First Name', 'campoal') ?></label>
                            <div class="ui right icon large input">
                                <input type="text" name="firstnameSignup" id="firstnameSignup" placeholder="<?php esc_attr_e('First Name', 'campoal') ?>">
                            </div>
                        </div>
                        <div class="required field">
                            <label><?php esc_html_e('Last Name', 'campoal') ?></label>
                            <div class="ui right icon large input">
                                <input type="text" name="lastnameSignup" id="lastnameSignup" placeholder="<?php esc_attr_e('Last Name', 'campoal') ?>">
                                <i class="user icon"></i>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                    <?php if ($choose_username == 1) : ?>
                    <div class="required field">
                        <label><?php esc_html_e('Username', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="text" name="usernameSignup" id="usernameSignup" placeholder="<?php esc_attr_e('Enter your username', 'campoal') ?>">
                            <i class="user icon"></i>
                        </div>
                    </div>
                    <?php endif; ?>
                    <?php if ($two_input_name != 1) : ?>
                    <div class="required field">
                        <label><?php esc_html_e('Full Name', 'campoal') ?></label>
                        <div class="ui right icon large input">
                    <?php endif; ?>
                        <input 
                            type="<?php echo esc_attr($two_input_name == 0 ? 'text' : 'hidden') ?>" 
                            name="nameSignup" 
                            id="nameSignup"
                            <?php if ($two_input_name == 0) : ?>
                            placeholder="<?php echo esc_attr__('Enter your fullname', 'campoal') ?>" 
                            <?php endif; ?>>
                    <?php if ($two_input_name != 1) : ?>
                            <i class="user icon"></i>
                        </div>
                    </div>
                    <?php endif; ?>
                    <div class="required field">
                        <label><?php esc_html_e('Email', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="text" name="emailSignup" id="emailSignup" placeholder="<?php esc_attr_e('Enter your e-mail', 'campoal') ?>">
                            <i class="mail icon"></i>
                        </div>
                    </div>
                    <div class="required field">
                        <label><?php esc_html_e('Password', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="password" name="passSignup" id="passSignup" class="password-strength" placeholder="<?php esc_attr_e('Enter your password', 'campoal') ?>">
                            <i class="toggle-password eye link icon"></i>
                        </div>
                    </div>
                    <?php get_template_part('templates/form/password-strength') ?>
                    <?php if ($repeat_password == 1) : ?>
                    <div class="required field">
                        <label><?php esc_html_e('Repeat Password', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="password" name="repassSignup" id="repassSignup" placeholder="<?php esc_attr_e('Repeat your password', 'campoal') ?>">
                            <i class="toggle-password eye link icon"></i>
                        </div>
                    </div>
                    <?php endif; ?>
                    <?php if (conikal_show_google_reCaptcha() && $recaptcha_login == 1) { ?>
                        <?php get_template_part('templates/google', 'recaptcha'); ?>
                    <?php } ?>
                    <div class="ui grid">
                        <div class="eight wide column">
                            <a href="#" class="ui primary large button password-strength-btn" id="submitSignup"><?php esc_html_e('Sign Up', 'campoal') ?></a>
                        </div>
                        <div class="eight wide right aligned column">
                            <a href="#" class="signin-btn"><?php esc_html_e('Sign In', 'campoal') ?></a>
                        </div>
                    </div>
                    <input type="hidden" id="citySignup" name="citySignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->city->name : '') ?>">
                    <input type="hidden" id="stateSignup" name="stateSignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->mostSpecificSubdivision->name : '') ?>">
                    <input type="hidden" id="neighborhoodSignup" name="neighborhoodSignup" value="">
                    <input type="hidden" id="countrySignup" name="countrySignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->country->isoCode : '') ?>">
                    <input type="hidden" id="latSignup" name="latSignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->location->latitude : '') ?>">
                    <input type="hidden" id="lngSignup" name="lngSignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->location->longitude : '') ?>">
                    <input type="hidden" id="zipSignup" name="zipSignup" value="<?php echo esc_attr($geoip_info ? $geoip_info->continent->geonameId : '') ?>">

                    <div class="ui hidden divider"></div>

                    <?php if ($signup_newsletters != 'none') : ?>
                        <div class="field">
                            <div class="ui checkbox<?php echo esc_attr($signup_newsletters == 'checked' ? ' checked' : '') ?>">
                              <input type="checkbox" tabindex="0" value="1" name="signupNewsletter" id="signupNewsletter" class="hidden" <?php echo esc_attr($signup_newsletters == 'checked' ? 'checked' : '') ?>>
                              <label><?php esc_html_e('Sign up for newsletters', 'campoal') ?></label>
                            </div>
                        </div>
                    <?php endif; ?>

                    <?php if ($condition_text != '') { ?>
                        <div class="field">
                            <?php echo wp_kses_post($condition_text); ?>
                        </div>
                    <?php } ?>
                    <?php wp_nonce_field('signup_ajax_nonce', 'securitySignup', true); ?>
                </form>

                <form class="ui form sign-in display none" id="userLoginForm">
                    <div class="required field">
                        <label><?php esc_html_e('Email', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="text" name="usernameSignin" id="usernameSignin" placeholder="<?php esc_attr_e('Username', 'campoal') ?>">
                            <i class="user icon"></i>
                        </div>
                    </div>
                    <div class="required field">
                        <label><?php esc_html_e('Password', 'campoal') ?></label>
                        <div class="ui right icon large input">
                            <input type="password" name="passwordSignin" id="passwordSignin" placeholder="<?php esc_attr_e('Password', 'campoal') ?>">
                            <i class="toggle-password eye link icon"></i>
                        </div>
                    </div>
                    <?php if (conikal_show_google_reCaptcha() && $recaptcha_login == 1) { ?>
                        <?php get_template_part('templates/google', 'recaptcha'); ?>
                    <?php } ?>

                    <?php wp_nonce_field('signin_ajax_nonce', 'securitySignin', true); ?>
                    <?php wp_referer_field(); ?>
                    <input type="hidden" name="signSignin" id="signSignin" value="">
                    <input type="hidden" name="refererID" id="refererID" value="<?php echo esc_attr( $login_referer ) ?>">
                    <div class="inline field">
                        <div class="ui toggle <?php echo esc_attr(in_array($remember_login, array('all', 'login')) ? 'checked ' : '') ?>checkbox">
                            <input type="checkbox" name="rememberme" id="rememberSignin" class="hidden" <?php echo esc_attr(in_array($remember_login, array('all', 'login')) ? 'checked' : '') ?>>
                            <label><?php esc_html_e('Remember me', 'campoal') ?></label>
                        </div>
                        <input type="hidden" name="remembermePetition" id="rememberSigninPetition" class="hidden" value="<?php echo esc_attr(in_array($remember_login, array('all', 'petition')) ? 1 : 0) ?>">
                    </div>
                    <div class="field">
                        <div class="ui grid">
                            <div class="nine wide column">
                                <a href="#" class="ui primary large button" id="submitSignin"><?php esc_html_e('Sign In', 'campoal') ?></a>
                            </div>
                            <div class="seven wide right aligned column">
                                <a href="#" class="forgot-password" id="forgotPass"><?php esc_html_e('Forgot password?', 'campoal') ?></a>
                            </div> 
                        </div>
                    </div>
                </form>
            </div>
            <div class="center aligned column">
                <button class="signup-btn ui huge labeled icon button signup-btn-style btn-modal" id="signup-button">
                  <i class="signup icon"></i>
                  <?php esc_html_e('Sign Up', 'campoal') ?>
                </button>
                <button class="signin-btn ui huge primary labeled icon button btn-modal" id="signin-button">
                  <i class="sign in icon"></i>
                  <?php esc_html_e('Sign In', 'campoal') ?>
                </button>
                <?php if($fb_login == 1 || $google_login == 1) { ?>
                    <div class="ui horizontal section divider"><?php esc_html_e('Or', 'campoal') ?></div>
                <?php } ?>
                <?php if($google_login == 1) { ?>
                    <p>
                        <div id="googleSigninButton"></div>
                        <!-- <button class="ui google plus large labeled icon button google-signin" id="googleSigninBtn">
                            <i class="icon"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 48 48" class="abcRioButtonSvg"><g><path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"></path><path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"></path><path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"></path><path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"></path><path fill="none" d="M0 0h48v48H0z"></path></g></svg></i>
                            <?php esc_html_e('Sign in with Google', 'campoal') ?>
                        </button> -->
                    </p>
                <?php } ?>
                <?php if($fb_login == 1) { ?>
                    <p>
                    <button class="ui facebook labeled icon large circular button signinFBText" id="fbLoginBtn">
                        <i class="facebook f icon"></i>
                        <?php esc_html_e('Continue with Facebook', 'campoal') ?>
                    </button>
                    <p>
                <?php } ?>
            </div>
        </div>
    </div>
</div>