<?php
$username=$this->session->userdata('username');
$result=$this->db->query("SELECT * FROM web_admin WHERE user='$username'");
foreach ($result->result() as $baris)  {
$nama=$baris->nama;
$email=$baris->email;
$password=$baris->pass;
}


?>

    <!-- Main content -->
    <section class="content">

      <div class="row">
        <div class="col-md-3">

          <!-- Profile Image -->
          <div class="box box-primary">
            <div class="box-body box-profile">
              <img src="<?php echo base_url('assets/img/avatar5.png'); ?>" class="img-circle" alt="User Image" />

              <h3 class="profile-username text-center"><?php echo $this->session->userdata('nama'); ?></h3>

            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
        <div class="col-md-9">
          <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#profile" data-toggle="tab">Profile</a></li>
              <li><a href="#settings" data-toggle="tab">Settings</a></li>
            </ul>
            <div class="tab-content">
              <div class="active tab-pane" id="profile">
                <form class="form-horizontal">
                  <div class="form-group">
                    <label for="inputName" class="col-sm-2 control-label">Nama</label>
                    <div class="col-sm-10">
                      <input type="email" class="form-control" placeholder="Name" value="<?php echo $nama;?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                      <input type="email" class="form-control"  placeholder="Email" value="<?php echo $email;?>">
                    </div>
                  </div>

                </form>

              </div>

              <div class="tab-pane" id="settings">
                <form action="" method="post" enctype="multipart/form-data" class="form-horizontal">
                  <div class="form-group">
                    <label for="inputName" class="col-sm-2 control-label">Nama</label>
                    <div class="col-sm-10">
                      <input type="text" class="form-control" name="nama" placeholder="Nama" value="<?php echo $nama;?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                      <input type="email" class="form-control"  name="email" placeholder="Email" value="<?php echo $email;?>">
                    </div>
                  </div>

				  <div class="form-group">
                    <label for="inputSkills" class="col-sm-2 control-label">Password</label>
                    <div class="col-sm-10">
                      <input type="password" class="form-control" name="password1" placeholder="Password" value="<?php echo $password;?>">
                    </div>
                  </div>
				  <div class="form-group">
                    <label for="inputSkills" class="col-sm-2 control-label">Password Lagi</label>
                    <div class="col-sm-10">
                      <input type="password" class="form-control" name="password2" placeholder="Password Lagi" value="<?php echo $password;?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                      <button type="submit" name="btnsave" class="btn btn-danger">
								<span class="glyphicon glyphicon-save"></span> &nbsp; Edit Profile
								</button>
                    </div>
                  </div>
                </form>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
          </div>
          <!-- /.nav-tabs-custom -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

    </section>
<?php
	if(isset($_POST['btnsave']))
 {
  $nama = $_POST['nama'];
  $email = $_POST['email'];
  $password1 = md5($_POST['password1']);
  $password2 = md5($_POST['password2']);


  if(empty($nama)){
   $errMSG = "Please Enter Nama.";
  }

  else if(empty($email)){
   $errMSG = "Please Enter Email.";
  }
  else if(empty($password1)){
   $errMSG = "Please Enter Password.";
  }
  else if(empty($password2)){
   $errMSG = "Please Enter password Lagi.";
  }
  else if($password1 <> $password2){
   $errMSG = "Password Tidak Sama.";
  }

  if(!isset($errMSG))
  {
	  $result=$this->db->query("UPDATE web_admin SET nama ='$nama', email='$email', password='$password1' WHERE user='$username'");

	  header("refresh:1;profil");
  }
 }

?>
