<?php
/**
 * Site Footer contain all required scripts And Validation for login,forget Password Forms
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    10-08-2020
 * @edited_by      Mohammad aljaouni
 * @last_edit_date 10-08-2020
 * @todo           Nothing
 */
if(empty($chain) || $chain != "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad") {
    header("location: index.php");
	exit;
}
if(empty($disableSiteFooter) || $disableSiteFooter === false)
	include("siteFooter.php");
?>
<!-- Start Footer page-->
    </div>
    <!-- end layout-wrapper -->

    <!--Overlay-->
    <div class="overlay"></div>

    <!-- JQUERY 3.4.1 -->
    
    <!-- Bootstrap v4.4.1 -->
    <script src="../assets/js/<?php echo $_SESSION['langSymbol'];?>/bootstrap.bundle.min.js"></script>
    <!-- Menu Links v4.4.1 -->
    <script src="../assets/libs/metismenu/metisMenu.min.js"></script>
    <!-- For Scroll Bar -->
    <script src="../assets/libs/simplebar/simplebar.min.js"></script>
    <!-- Click Animation -->
    <script src="../assets/libs/node-waves/waves.min.js"></script>
    <!-- Icons -->
    <script src="../assets/libs/monochrome/bundle.min.js"></script>
    
    <!--Jquery Validation-->
    <script src="../assets/libs/jquery-validate/jquery.validate.min.js" ></script>
    <script src="../assets/libs/jquery-validate/additional-methods.min.js" ></script>
    <script src="../assets/js/<?php echo $_SESSION['langSymbol'];?>/validate.js" ></script>

    <!-- Custom Script to run Previous Scripts -->
    <script src="../assets/js/<?php echo $_SESSION['langSymbol'];?>/app.js"></script>
    <?php
if(isset($callLoginValidation) && $callLoginValidation) {
     ?>
     <script src='https://www.google.com/recaptcha/api.js?hl=ar'></script>
     <script>
         <?php
         if(!empty($_SESSION["captcha"])){
         ?>
         $(function(){
             function rescaleCaptcha(){
                 var width = $('.g-recaptcha').parent().width();
                 var scale;
                 if (width < 302)
                     scale = width / 302;
                 else
                     scale = 1.0;
                 $('.g-recaptcha').css('transform', 'scale(' + scale + ')');
                 $('.g-recaptcha').css('-webkit-transform', 'scale(' + scale + ')');
                 $('.g-recaptcha').css('transform-origin', '0 0');
                 $('.g-recaptcha').css('-webkit-transform-origin', '0 0');
                 $('.g-recaptcha').css('transform-origin', '<?php echo $align?> top');
             }
             rescaleCaptcha();
             $( window ).resize(function() { rescaleCaptcha(); });
         });
         function recaptchaCallback() {
             $('#hiddenRecaptcha').valid();
         }
         <?php }?>
         var id = "#loginForm";

         $(id).validate({
           <?php
           if(!empty($_SESSION["captcha"])){
           ?>
           ignore: ".ignore",
           <?php }?>
		   rules: {
			   user: {
				   required: true,
				   minlength: 2
			   },
			   pass: {
				   required: true,
				   minlength: 5
			   }
               <?php
               if(!empty($_SESSION["captcha"])){
               ?>,
               hiddenRecaptcha: {
                   required: function () {
                       if (grecaptcha.getResponse() == '') {
                           return true;
                       } else {
                           return false;
                       }
                   }
               }
               <?php }?>
		   },
		   messages: {
			   user: {
				   required: msg.loginForm.username,
				   minlength: msg.loginForm.usernameMinlength
			   },
			   pass: {
				   required: msg.loginForm.password,
				   minlength: msg.loginForm.passwordMinlength
			   }
               <?php
               if(!empty($_SESSION["captcha"])){
               ?>,
               hiddenRecaptcha: {
                   required: msg.forgetPassword.checkCapatch,
               }
                <?php }?>
		   },
		   errorElement: 'div',
		   errorPlacement: function (error, element) {
			   error.addClass('invalid-feedback');
			   element.closest('.form-group').append(error);
		   },
		   highlight: function (element, errorClass, validClass) {
			   $(id).addClass('was-validated');
			   element.setCustomValidity("is-invalid");
			   $(element).addClass('is-invalid');
		   },
		   unhighlight: function (element, errorClass, validClass) {
			   $(id).addClass('was-validated');
			   element.setCustomValidity("");
			   $(element).removeClass('is-invalid');
		   },
		   invalidHandler: function(event, validator) {
			   $(id).addClass('was-validated');
		   }
		   /*,
		  submitHandler: function() {
			  alert("ok");
		  }*/
	   });
     </script>
     <?php
}
if(isset($callForgetValidation) && $callForgetValidation) {
    ?>
     <script src='https://www.google.com/recaptcha/api.js?hl=ar'></script>
     <script>
         $(function(){
             function rescaleCaptcha(){
                 var width = $('.g-recaptcha').parent().width();
                 var scale;
                 if (width < 302)
                     scale = width / 302;
                 else
                     scale = 1.0;
                 $('.g-recaptcha').css('transform', 'scale(' + scale + ')');
                 $('.g-recaptcha').css('-webkit-transform', 'scale(' + scale + ')');
                 $('.g-recaptcha').css('transform-origin', '0 0');
                 $('.g-recaptcha').css('-webkit-transform-origin', '0 0');
                 $('.g-recaptcha').css('transform-origin', '<?php echo $align?> top');
             }
             rescaleCaptcha();
             $( window ).resize(function() { rescaleCaptcha(); });
         });

         function recaptchaCallback() {
             $('#hiddenRecaptcha').valid();
         }
    var id = "#forgetForm";
	  $(id).validate({
          ignore: ".ignore",
		  rules: {
              hiddenRecaptcha: {
                  required: function () {
                      if (grecaptcha.getResponse() == '') {
                          return true;
                      } else {
                          return false;
                      }
                  }
              }
		  },
		  messages: {
			  required: msg.forgetPassword.email,
			  required: msg.forgetPassword.mobile,
			  email: msg.forgetPassword.validEmail,
              hiddenRecaptcha: {
                  required: msg.forgetPassword.checkCapatch,
              }
		  },

		  errorElement: 'div',
		  errorPlacement: function (error, element) {
			  error.addClass('invalid-feedback');
			  element.closest('.form-group').append(error);
		  },
		  highlight: function (element, errorClass, validClass) {
			  $(id).addClass('was-validated');
			  element.setCustomValidity("is-invalid");
			  $(element).addClass('is-invalid');
		  },
		  unhighlight: function (element, errorClass, validClass) {
			  $(id).addClass('was-validated');
			  element.setCustomValidity("");
			  $(element).removeClass('is-invalid');
		  },
		  invalidHandler: function(event, validator) {
			  $(id).addClass('was-validated');
		  }
		  /*,
		  submitHandler: function() {
			  alert("ok");
		  }*/
	  });
    </script>
    <?php
}
?>
<!-- End Footer page-->
  </body>
</html>
