<?php global $vis_language; ?>
<script src="<?= VIS_PATH_SCRIPT; ?>slider/pStrength.jquery.js"></script>
<script>
	$(document).ready(function(){
		function change_password_strength(strengthPercentage, is_valid){
			$("#password_strength_per").val(strengthPercentage);
			$("#password_strength_show").show();
			var show_password_result;
				if(strengthPercentage>=0 && strengthPercentage<50){show_password_result='<span class="label vh-yellow-bg"> <?=$vis_language['TXTWEAK'];?> </span>';}
				else if(strengthPercentage>=50 && strengthPercentage<70){show_password_result='<span class="label vh-green-bg"> <?=$vis_language['TXTMEDIUM'];?> </span>';}
				else if(strengthPercentage>=70 && strengthPercentage<90){show_password_result='<span class="label vh-orange-bg"> <?=$vis_language['TXTSTRONG'];?> </span>';}
				else if(strengthPercentage>=90 && strengthPercentage<=100){show_password_result='<span class="label vh-red-bg"> <?=$vis_language['TXTVERYSTRONG'];?> </span>';}
				if(is_valid=='not_allowed') $('#password_strenght_id').html('<? echo $vis_language['TXTPASSWORDSRENGTH']."&nbsp;&nbsp;"; ?> '+show_password_result+ '&nbsp;&nbsp; <?=$vis_language['TXTNOTALLOWED']?>');
				else if(is_valid=='allowed') $('#password_strenght_id').html('<? echo $vis_language['TXTPASSWORDSRENGTH']."&nbsp;&nbsp;"; ?> '+show_password_result+ '&nbsp;&nbsp; <?=$vis_language['TXTALLOWED']?>');
				return true;	
		}
		
		$('#vis_newpassword').pStrength({
			'changeBackground'          : false,
			'onPasswordStrengthChanged' : function(passwordStrength, strengthPercentage) {
				if(passwordStrength!=0){change_password_strength(strengthPercentage,'not_allowed');}
			},
			'passwordValidFrom': <?= $security_password_limit;?>,
			'onValidatePassword': function(strengthPercentage) {
				change_password_strength(strengthPercentage,'allowed');
			}
		});
	});
</script>
<?
    $database=new class_database();
    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
    $object=new class_setting($database);
    $setting=$object->get_settings('(title="vis_manage_portal_logo" OR title like "vis_manage_logo" OR title like "vis_manage_portal_text" or title="vis_manage_portal_text_bold" or title="vis_manage_portal_text_italic" or title="vis_manage_portal_text_colour") and domain_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA);   
	$style = '';
    if($setting!=-1) for($i=0;$i<count($setting);$i++) {
		if($setting[$i]['title']=='vis_manage_portal_logo') {
			$poral_setting['vis_manage_portal_logo']=$setting[$i]['content'];
		}
		elseif($setting[$i]['title']=='vis_manage_portal_text') {
			$poral_setting['vis_manage_portal_text']=$setting[$i]['content'];
		}
		elseif($setting[$i]['title']=='vis_manage_logo') {
			$poral_setting['vis_manage_logo']=$setting[$i]['content'];
		}
		elseif($setting[$i]['title']=='vis_manage_portal_text_bold') {
			$poral_setting['vis_manage_portal_text_bold']=$setting[$i]['content'];
			$style .= ($setting[$i]['content'] == 1) ? 'font-weight: bold; ' : '';
		}
		elseif($setting[$i]['title']=='vis_manage_portal_text_italic') {
			$poral_setting['vis_manage_portal_text_italic']=$setting[$i]['content'];
			$style .= ($setting[$i]['content'] == 1) ? 'font-style: italic; ' : '';
		}
		elseif($setting[$i]['title']=='vis_manage_portal_text_colour') {
			$poral_setting['vis_manage_portal_text_colour']=$setting[$i]['content'];
			$style .= 'color: '.$setting[$i]['content'].'; ';
		}
	}
	$database->database_disconnect();
    include_once(VIS_PATH_TEMPLATE."header.php");?>
	<? if($poral_setting['vis_manage_logo'] == 'text') { ?><style>.vh-logo .logo-text {<?= $style; ?>}</style><? } else if($poral_setting['vis_manage_portal_logo'] != "" && file_exists(VIS_PATH_PROFILE.$poral_setting['vis_manage_portal_logo'])) {
		
		$imageFile = VIS_PATH_PROFILE.$poral_setting['vis_manage_portal_logo'];				 
       $width = 300;	/* Set the width fixed at 300px; */
		$info = getimagesize($imageFile); /* Get the image info */		 
		$aspectRatio = $info[1] / $info[0]; /* Calculate aspect ratio by dividing width by height*/		 
		$newheight = (int)($aspectRatio * $width) . "px";/* Keep the width fix at 300px, but change the height according to the aspect ratio */		
		$width .= "px";
		 ?><style>.vh-logo .logo-image { background-image: url("<?= VIS_PATH_PROFILE.$poral_setting['vis_manage_portal_logo']; ?>") !important; width: <?= $width; ?> !important; height: <?= $newheight;?> !important; background-size: <?= $width; ?> auto !important;}</style>
	<? } ?>
<body>
<section id="vis_main_panel_div">
    <div class="container login_aside_xl">
		<?
		if($poral_setting['vis_manage_logo']=='text') ?>
        <div class="vh-logo margin-v">
        	<h1><a class="logo-<?= ($poral_setting['vis_manage_logo']=='text') ? 'text' : 'image'; ?>" href=""><?= ($poral_setting['vis_manage_logo']=='text')?$poral_setting['vis_manage_portal_text']:''; ?></a></h1>
        </div>
        <section class="m-b-lg">
            <header class="vis_login_head">
                <? if(isset($operation['message']) && $operation['message']!=''){ ?>
                  <div id="vis_login_msg_div" class="alert <?= ($operation['success']==1)?'alert-success':'alert-danger'; ?>"><strong><?= $operation['message']; ?></strong></div>
                <? } ?>
			</header>
            <form method="post" id="vis_reset_form" action="index.php">
				<div id="vis_login_table">
                    <div class="list-group">
						<div class="login-list-group-item">
							<input type="password" name="vis_newpassword" id="vis_newpassword" class="form-control no-border" placeholder="New password">
						</div>
					</div>
                    
                    <div class="list-group" style="display:none" id="password_strength_show">
                        <div>
                             <input type="hidden" name="password_strength_per" id="password_strength_per" value='0'>
                           <div id="password_strenght_id" class="checkbox-inline"></div>
                        </div>
                     </div>
                    
                    <div class="list-group">
						<div class="login-list-group-item">
							<input type="password" name="vis_confirm" id="vis_confirm" class="form-control no-border" placeholder="Confirm password">
						</div>
					</div>
                    <div class="row m-b-lg m-t-lg">
                        <div class="col-xs-12"><button id="btn_login" type="submit" data-loading-text="Loading..." data-complete-text="finished!" class="btn btn-lg btn-primary btn-block"><? echo $vis_language['TXTUPDATEPASSWORD']; ?></button></div>
                    </div>
                </div>
                <div class="line line-dashed"></div>
                <input type="hidden" name="vis_email" id="vis_email" value="<?= $staff_email; ?>" />
                <input type="hidden" name="vis_passwd_auth" id="vis_passwd_auth" value="<?= $passwd_auth; ?>" />
                <input type="hidden" name="vis_operation" value="set_forgetpassword" /><input type="hidden" name="vis_module" value="home" />
                <div class="list-group">
                    <div class="text-center">
                        <a href="index.php" class="link"><? echo $vis_language['TXTBACKTOLOGIN']; ?></a>
                    </div>
                </div>
            </form>
        </section>
    </div>
</section>
<? include_once(VIS_PATH_TEMPLATE."footer.php"); ?>
<script>
/*  disable scacebar         */
	$(function() {
         var txt = $("input#vis_newpassword");
         var func = function() {
             txt.val(txt.val().replace(/\s/g, ''));
    }
    txt.keyup(func).blur(func);
});
</script>