 <?php $this->include('rs/utils.php')?>
 <?= $this->extend('rs/template-user', $data); ?>
 <?= $this->section('content'); ?>
 <link rel="stylesheet" href="intlTelInput/css/intlTelInput.css">
	<style>
		.categ{border:1px solid #CCC;border-radius:5px;display:block;padding:10px 20px;margin:10px}
		form{width:100%}
		.form-control{max-width:350px!important}
	</style>
	<script type="text/javascript">document.getElementById("profile").classList.add("active");</script>
	<div class="card shadow">
		<a href="#collapsePrimary" class="d-block card-header py-3" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="collapseReception">
			<h6 class="m-0 font-weight-bold text-primary">Company account</h6>
		</a>
		<div class="collapse show" id="collapsePrimary">
			<div class="card-body">
				<?php if (session()->get('success')): ?>
				   <div class="alert alert-success" role="alert">
					 <?= session()->get('success') ?>
				   </div>
				 <?php endif; ?>
				 <form class="" id="frmdata" action="/profile" method="post" >
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Company name</label>
						<input readonly type="text" class="form-control" name="companyname" id="companyname" value="<?= set_value('companyname', $user['companyname']) ?>">
					   </div>
					 </div>
					 
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">VAT number</label>
						<input readonly type="text" class="form-control" name="vatnumber" id="vatnumber" value="<?= set_value('vatnumber', $user['vatnumber']) ?>">
					   </div>
					 </div>
					 
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Country</label>
						 <select class="form-control-sm select2" name ="country" id="country" style="width:350px"  value="<?= set_value('country', $user['country']) ?>" required>
								   <option />
								   <option <?php if($user['country']=='Bulgaria'){echo 'selected';}?>>Bulgaria</option>
								   <option <?php if($user['country']=='Romania'){echo 'selected';}?>>Romania</option>
							</select>
					   
					   </div>
					 </div>
					 
					 <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">District</label>
						<input type="text" class="form-control" name="district" id="district" value="<?= set_value('district', $user['district']) ?>">
					   </div>
					 </div>
					 
					 <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">City</label>
						<input type="text" class="form-control" name="city" id="city" value="<?= set_value('city', $user['city']) ?>">
					   </div>
					 </div>
					 
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Street address</label>
						<input type="text" class="form-control" name="address" id="address" value="<?= set_value('address', $user['address']) ?>">
					   </div>
					 </div>
					 
					 <div class="col-12 col-sm-6">
					   <div class="form-group">
						<label for="firstname">First name</label>
						<input type="text" class="form-control" name="firstname" id="firstname" value="<?= set_value('firstname', $user['firstname']) ?>">
					   </div>
					 </div>
					 <div class="col-12 col-sm-6">
					   <div class="form-group">
						<label for="lastname">Family name</label>
						<input type="text" class="form-control" name="lastname" id="lastname" value="<?= set_value('lastname', $user['lastname']) ?>">
					   </div>
					 </div>
					 
					 <div class="col-12 col-sm-6">
						 <div class="form-group">
						   <label for="phone">Phone number </label>
						   <div class="input-group">
								<input type="tel"  class="form-control" name="phone" id="phone" value="<?= set_value('phone',$user['phone']) ?>"  required>										
							</div>
					   </div>	
					 </div>
					 
					 <div class="col-12">
					   <div class="form-group">
						<label for="email">Company email address</label>
						<input type="text" class="form-control" readonly id="email" value="<?= $user['email'] ?>">
					   </div>
					 </div>
					
					<div class="col-12 col-sm-6">
					   <div class="form-group">
						<a href="/changepwd">Change your password</a>
					  </div>
					</div>
					
				   <?php if (isset($validation)): ?>
					 <div class="col-12">
					   <div class="alert alert-danger" role="alert">
						 <?= $validation->listErrors() ?>
					   </div>
					 </div>
				   <?php endif; ?>
				   
				   
				   
				   <div class="row">
						<div class="col-12 col-sm-4">
						<button type="button" onclick="doSubmit()" class="btn btn-primary">Update</button>
						</div>
					</div>
				</form>
			</div>	   
		</div>
		<hr><hr><hr>
	</div>
			
<script src="/intlTelInput/js/intlTelInput.js"></script>
<script>

  var input = document.querySelector("#phone");
 
  var i=window.intlTelInput(input, {
    utilsScript:"/intlTelInput/js/utils.js"
  });
  
  function doSubmit(){
	  phoneInput=$("#phone");
	  phoneInput.val(i.getNumber());
	  document.getElementById('frmdata').submit();
	 
	}
  
 
  
  function generatePassword() { 
        const passwordLength = 18
        const useSymbols = true
        const useNumbers = true
        const useLowerCase = true
        const useUpperCase = true
        
        let charset = ''; 
        let newPassword = ''; 
  
        if (useSymbols) charset += "!@#$%^&*()"; 
        if (useNumbers) charset += "0123456789"; 
        if (useLowerCase) charset += "abcdefghijklmnopqrstuvwxyz"; 
        if (useUpperCase) charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  
        for (let i = 0; i < passwordLength; i++) { 
            newPassword += charset.charAt( 
                Math.floor(Math.random() * charset.length)); 
        } 
  
        password = newPassword;
		
		$('#password').val(password)
		$('#password').prop('type', 'text');
		//alert(password);
    } 
  
</script>
			
		
<?= $this->endsection(); ?>