<?php if(isset($_SESSION['uid'])){   
   if($page == 'myaccount'){ // Page User Account
   
?>
<style>
.icon-left {
  float: left;
  margin-left: 10px;
  margin-top: -44px;
  padding-right:10px;
  position: relative;
  z-index: 2;
}
.buttonchu-right{
    float: right;
  margin-right: 8px;
  margin-top: -48px;
  position: relative;
  z-index: 2;
}
.icon-right {
  float: right;
  margin-right: 10px;
  margin-top: -44px;
  position: relative;
  z-index: 2;
}
.field-icon {
  float: right;
  margin-right: 10px;
  margin-top: -44px;
  position: relative;
  z-index: 2;
}
.left-icon {
  float: left;
  margin-left: 10px;
  margin-top: -44px;
  padding-right:10px;
  position: relative;
  z-index: 2;
}
</style>

<div class="w3-row w3-margin-bottom">
<div class="w3-half w3-hide-small w3-hide-medium_" style="max-width:100%;height:auto;">
<?php include THM.$set['theme'].'/user_sidebar.php'; 
$time = date("H");    
    $timezone = date("e");    
    if ($time < "10") {
        $hello = $lng['good_morning'];
    } else    
    if ($time >= "10" && $time < "18") {
        $hello = $lng['good_day'];
    } else    
    if ($time >= "18" && $time < "20") {
        $hello = $lng['good_evening'];
    } else    
    if ($time >= "20") {
        $hello = $lng['good_evening'];
    }
?>
</div>

<div class="w3-rest">
<div class="w3-row">
<div class="w3-container">
<h3 class="w3-center w3-border-bottom w3-margin-bottom"><i class="fa fa-user-o w3-xxxlarge"></i><br/><?=$hello?> <strong><?php if(!empty($_SESSION['first_name'])){echo $_SESSION['first_name'];}else{$grun = explode('-', $_SESSION['user_name']); echo $grun[0];} ?></strong>,<br/><?=$lng['user_myacc_hello_content']?></h3>

<?php 
include(BASE);
$check_log = $dbc->query("SELECT date FROM user_log WHERE uid='{$_SESSION['uid']}' ORDER BY date DESC LIMIT 1");
$last_change = $check_log->fetch_assoc();
$dbc->close();

$ldatec = date_create(date('Y-m-d', strtotime($last_change['date'])));
//$ldatec = date_create('2018-10-12'); // de test
$today  = date_create(date('Y-m-d'));
$interval = date_diff($today, $ldatec);
$timeofch = $interval->format("%a");
//echo $interval->format("Month: %m, days: %d.");
if($timeofch > 0){
?>
<div class="w3-container w3-margin-bottom">

<form action="" method="post">
<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_change_user_name_ask']?></label>
<input class="w3-input w3-border w3-xlarge" type="text" value="<?php if(isset($_POST['user_name'])){echo $_POST['user_name'];}else{echo $_SESSION['user_name'];} ?>" name="user_name" placeholder="<?=$lng['user_myacc_change_user_form_ph']?>" style="padding-left:60px;"/><i class="fa fa-fw fa-user icon-left w3-xxlarge w3-text-bluepm w3-border-right"></i>
<?php if(empty($available)){ ?>
<button class="w3-button w3-bluepm w3-hover-seagreen buttonchu-right" type="submit"><i class="fa fa-fw fa-search w3-xlarge" title="<?=$lng['user_myacc_change_user_form_btn_title']?>"></i></button>
<?php } ?>
<?php if(isset($unexist)){ ?>
<button class="w3-button w3-bluepm w3-hover-seagreen buttonchu-right" type="submit"><i class="fa fa-fw fa-search w3-xlarge" title="<?=$lng['user_myacc_change_user_form_btn_title']?>"></i></button>
<?php } ?>
<?php if(isset($available)){ ?>
<i class="fa fa-fw fa-check w3-xxlarge w3-text-green icon-right" title="<?=$lng['user_myacc_change_user_form_available_title']?>"></i>
<?php } ?>


</div>
<input type="hidden" name="chechun" value="true"/>
</form>


<?php if(isset($unexist)){ ?>
<div class="w3-margin w3-center w3-panel w3-text-red">
<?=$lng['user_myacc_change_user_form_not_available']?>
</div>
<?php } ?>
<?php if(isset($available)){ ?>
<form action="" method="post">
<div class="w3-margin w3-center">
<input id="password-field" class="w3-input w3-border w3-xlarge" name="passch" type="password" placeholder="<?=$lng['user_myacc_change_user_form_pass_ph']?>" style="padding-left:60px;"/><i class="fa fa-fw fa-key left-icon w3-xxlarge w3-text-brown w3-border-right"></i><span toggle="#password-field" class="fa fa-fw fa-eye-slash field-icon w3-xxlarge toggle-password w3-text-brown"></span>
</div>

<div class="w3-margin w3-center">
<button class="w3-button w3-bluepm w3-hover-green" type="submit"><?=$lng['user_myacc_change_user_form_btn']?></button>
</div>
<input type="hidden" name="sesun" value="<?=$_SESSION['user_name']?>"/>
<input type="hidden" name="user_name" value="<?=$_POST['user_name']?>"/>
<input type="hidden" name="chgusrnm" value="true"/>
</form>
</div>
<?php } ?>

<?php if(isset($unupdate) == '1'){ ?>
<div class="w3-margin w3-center w3-panel w3-text-green">
<?=$lng['user_myacc_change_user_updated']?>
</div>
<?php }elseif(isset($err_update) == '1'){ ?>
<div class="w3-margin w3-center w3-panel w3-text-red">
<?=$lng['user_myacc_change_user_wrong_pass']?>
</div>
<?php }
  }
?>


<?php
include(BASE);
$showuserdet = $dbc->query("SELECT * FROM users WHERE uid='{$_SESSION['uid']}' LIMIT 1");
$usdt = $showuserdet->fetch_assoc();
$showuserdetD = $dbc->query("SELECT * FROM user_details WHERE uid='{$_SESSION['uid']}' LIMIT 1");
$usdtD = $showuserdetD->fetch_assoc();
$dbc->close();

?>

<?php if(isset($accupdate) == '1'){ ?>
<div class="w3-margin w3-center w3-panel w3-text-green">
<?=$lng['user_myacc_updated']?>
</div>
<?php }elseif(isset($err_accupdate) == '1'){ ?>
<div class="w3-margin w3-center w3-panel w3-text-red">
<?=$lng['user_myacc_not_updated']?>
</div>
<?php } ?>

<form action="" method="post" autocomplete="off" style="font-size: small;">

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_first_name_label']?></label>
<input class="w3-input w3-border w3-large" type="text" name="first_name" placeholder="<?=$lng['user_myacc_first_name_ph']?>" value="<?php if(isset($usdt['first_name'])){echo $usdt['first_name'];}elseif($_POST['first_name']){echo $_POST['first_name'];}?>"/>
</div>

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_last_name_label']?></label>
<input class="w3-input w3-border w3-large" type="text" name="last_name" placeholder="<?=$lng['user_myacc_last_name_ph']?>" value="<?php if(isset($usdt['last_name'])){echo $usdt['last_name'];}elseif($_POST['last_name']){echo $_POST['last_name'];}?>"/>
</div>

<div class="w3-row">

<div class="w3-quarter w3-margin-bottom">
<label><?=$lng['user_myacc_you_are_label']?></label>
<select class="w3-select w3-border" name="gender" style="padding-left:10px;">
<?php
if($usdt['sex'] == '0'){ ?>
<option value="" selected="" disabled=""><?=$lng['user_myacc_form_select']?></option>
<option value="1"><?=$lng['user_myacc_form_select_man']?></option>
<option value="2"><?=$lng['user_myacc_form_select_woman']?></option>
<?php }elseif($usdt['sex'] == '1'){ ?>
<option value="" disabled=""><?=$lng['user_myacc_form_select']?></option>
<option value="1" selected=""><?=$lng['user_myacc_form_select_man']?></option>
<option value="2"><?=$lng['user_myacc_form_select_woman']?></option>
<?php }elseif($usdt['sex'] == '2'){ ?>
<option value="" disabled=""><?=$lng['user_myacc_form_select']?></option>
<option value="1"><?=$lng['user_myacc_form_select_man']?></option>
<option value="2" selected=""><?=$lng['user_myacc_form_select_woman']?></option>
<?php } ?>

</select>
</div>

<div class="w3-threequarter w3-margin-bottom">
<label style="padding-left:15px;"><?=$lng['user_myacc_form_date_label']?></label>

<div class="w3-row-padding">

<div class="w3-quarter">
<select class="w3-select w3-border" name="year" style="padding-left:10px;">
<?php
if(date('Y', strtotime($usdt['birthday'])) == '0000'){ ?>
<option value="" selected="" disabled=""><?=$lng['user_myacc_form_date_select_year']?></option>
<?php }
foreach (range(date('Y')-18, date('Y')-60) as $year){
    $yearset = date('Y', strtotime($usdt['birthday']));
    if($year == $yearset){$sely = ' selected=""';}else{$sely = '';}
    echo '<option value="'.$year.'"'.$sely.'>'.$year.'</option>';
}
?>
</select>
</div>

<div class="w3-half">
<select class="w3-select w3-border" name="month" style="padding-left:10px;">
<?php if(date('m', strtotime($usdt['birthday'])) == '00'){ ?>
<option value="" selected="" disabled=""><?=$lng['user_myacc_form_date_select_month']?></option>
<?php } $long = array(
  '1'=>$lng['user_myacc_january'], 
  '2'=>$lng['user_myacc_february'], 
  '3'=>$lng['user_myacc_march'], 
  '4'=>$lng['user_myacc_april'], 
  '5'=>$lng['user_myacc_may'], 
  '6'=>$lng['user_myacc_june'], 
  '7'=>$lng['user_myacc_july'], 
  '8'=>$lng['user_myacc_august'], 
  '9'=>$lng['user_myacc_september'], 
  '10'=>$lng['user_myacc_october'], 
  '11'=>$lng['user_myacc_november'], 
  '12'=>$lng['user_myacc_december']
);
foreach (range(1, 12) as $mnr) {
    $monthset = date('n', strtotime($usdt['birthday']));
    if($mnr == $monthset){$selm = ' selected=""';}else{$selm = '';}
    echo '<option value="'.$mnr.'"'.$selm.'>'.$long[$mnr].'</option>';
}
?>
</select>
</div>

<div class="w3-quarter">
<select class="w3-select w3-border" name="day" style="padding-left:10px;">
<?php if(date('d', strtotime($usdt['birthday'])) == '00'){ ?>
<option value="" selected="" disabled=""><?=$lng['user_myacc_form_date_select_day']?>'</option>
<?php }
foreach (range(1, 31) as $day) {
    $dayset = date('j', strtotime($usdt['birthday']));
    if($day == $dayset){$seld = ' selected=""';}else{$seld = '';}
    echo '<option value="'.$day.'"'.$seld.'>'.$day.'</option>';
}
?>
</select>
</div>

</div>

</div>

</div>

<div class="w3-margin-bottom w3-hide">
<label><?=$lng['user_myacc_form_phone_label']?></label>
<input class="w3-input w3-border w3-large" type="tel" name="phone" placeholder="<?=$lng['user_myacc_form_phone_ph']?>" value="<?php if(isset($usdt['phone'])){echo $usdt['phone'];}elseif($_POST['phone']){echo $_POST['phone'];}?>"/>
</div>

<div class="w3-margin-bottom w3-hide">
<label><?=$lng['user_myacc_form_fax_label']?></label>
<input class="w3-input w3-border w3-large" type="tel" name="fax" placeholder="<?=$lng['user_myacc_form_fax_ph']?>" value="<?php if(isset($usdt['fax'])){echo $usdt['fax'];}elseif($_POST['fax']){echo $_POST['fax'];}?>"/>
</div>

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_form_mobile_label']?></label>
<input class="w3-input w3-border w3-large" type="tel" name="mobile" placeholder="<?=$lng['user_myacc_form_mobile_ph']?>" value="<?php if(isset($usdt['mobile'])){echo $usdt['mobile'];}elseif($_POST['mobile']){echo $_POST['mobile'];}?>"/>
</div>

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_form_url']?></label>
<input class="w3-input w3-border w3-large" type="text" name="user_website" placeholder="<?=$lng['user_myacc_form_url']?>" value="<?php if(isset($usdtD['url'])){echo $usdtD['url'];}elseif($_POST['user_website']){echo $_POST['user_website'];}?>"/>
</div>


<div class="w3-margin w3-center">
<button class="w3-button w3-bluepm w3-hover-green w3-large" type="submit"><i class="fa fa-refresh"></i> <?=$lng['user_myacc_form_update_btn']?></button>
</div>
<input type="hidden" name="uid" value="<?=$_SESSION['uid']?>"/>
<input type="hidden" name="usraccountupdate" value="true"/>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
$(".toggle-password").click(function() {

  $(this).toggleClass("fa-eye fa-eye-slash");
  var input = $($(this).attr("toggle"));
  if (input.attr("type") == "password") {
    input.attr("type", "text");
  } else {
    input.attr("type", "password");
  }
});

function phoneMask() { 
    var num = $(this).val().replace(/\D/g,''); 
    $(this).val(num.substring(0,1) + '(' + num.substring(1,4) + ')' + num.substring(4,7) + '-' + num.substring(7,11)); 
}
$('[type="tel"]').keyup(phoneMask);
</script>


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

</div>
<?php }elseif($page == 'change_password'){ // Page User Account
    ?>
<style>
.field-icon {
  float: right;
  margin-right: 10px;
  margin-top: -30px;
  position: relative;
  z-index: 2;
}
.left-icon {
  float: left;
  margin-left: 10px;
  margin-top: -30px;
  padding-right:10px;
  position: relative;
  z-index: 2;
}
</style>
<div class="w3-row w3-margin-bottom">
<div class="w3-col l6 m6 s12" style="max-width:100%;height:auto;">
<?php include THM.$set['theme'].'/user_sidebar.php'; ?>
</div>

<div class="w3-col l6 m6 s12">
<div class="w3-row">
<div class="w3-container">
<h2 class="w3-center w3-border-bottom w3-margin-bottom"><i class="fa fa-key w3-xxxlarge"></i><br/><?=$lng['user_myacc_cps_title']?></h2>

<?php
include(BASE);
$showuserdet = $dbc->query("SELECT * FROM users WHERE uid='{$_SESSION['uid']}' LIMIT 1");
$usdt = $showuserdet->fetch_assoc();
$dbc->close();

?>

<?php if(isset($pass)){ ?>
<div class="w3-margin w3-center w3-panel w3-text-green">
<?=$pass?>
</div>
<?php }elseif(isset($nopass)){ ?>
<div class="w3-margin w3-center w3-panel w3-text-red">
<?=$nopass?>
</div>
<?php }if(isset($not)){ ?>
<div class="w3-margin w3-center w3-panel w3-text-red">
<?=$not?>
</div>
<?php } ?>


<form action="" method="post" autocomplete="off">

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_cps_curr_pass_label']?></label>
<input id="password-field-c" class="w3-input w3-border" type="password" name="c_pass" placeholder="<?=$lng['user_myacc_cps_curr_pass_ph']?>" autocomplete="off" tabindex="1" style="padding-left:60px;font-size:12px;"/><i class="fa fa-fw fa-key left-icon w3-xlarge w3-text-bluepm w3-border-right"></i><span toggle="#password-field-c" class="fa fa-fw fa-eye-slash field-icon w3-xlarge toggle-password w3-text-bluepm"></span>
</div>

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_cps_new_pass_label']?></label>
<input id="password-field-n" class="w3-input w3-border" type="password" name="n_pass" placeholder="<?=$lng['user_myacc_cps_new_pass_ph']?>" autocomplete="off" tabindex="2" style="padding-left:60px;font-size:12px;"/><i class="fa fa-fw fa-key left-icon w3-xlarge w3-text-bluepm w3-border-right"></i><span toggle="#password-field-n" class="fa fa-fw fa-eye-slash field-icon w3-xlarge toggle-password w3-text-bluepm"></span>
</div>

<div class="w3-margin-bottom">
<label><?=$lng['user_myacc_cps_cnp_pass_label']?></label>
<input id="password-field-r" class="w3-input w3-border" type="password" name="r_pass" placeholder="<?=$lng['user_myacc_cps_cnp_pass_ph']?>" autocomplete="off" tabindex="3" style="padding-left:60px;font-size:12px;"/><i class="fa fa-fw fa-key left-icon w3-xlarge w3-text-bluepm w3-border-right"></i><span toggle="#password-field-r" class="fa fa-fw fa-eye-slash field-icon w3-xlarge toggle-password w3-text-bluepm"></span>
</div>


<div class="w3-margin w3-center">
<button class="w3-button w3-bluepm w3-hover-green w3-large" type="submit"><i class="fa fa-refresh"></i> <?=$lng['user_myacc_cps_update_btn']?></button>
</div>
<input type="hidden" name="uid" value="<?=$_SESSION['uid']?>"/>
<input type="hidden" name="usrpassupdate" value="true"/>
</form>

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

</div>
   
<?php   } 
 }else{
    $url = PATH.'login.html';
    ob_end_clean();
    header("Location: $url");
    exit();
  }
?>