<?php require_once('includes/check-login.php'); ?>
<?php require_once('includes/header.php'); ?>
<?php require_once('includes/menu.php'); ?>
<?php require_once('includes/config.php');


   !empty ( $_REQUEST['edit'] ) ? $id = $_REQUEST['edit'] : $id = 0;
      if( $id != 0 ) {
        $update = true;
        $sql = "SELECT ud.*, ur.role_id, u.sub_category_id ,u.user_id FROM user_details ud JOIN user_roles ur ON ur.user_id = ud.user_id JOIN users u ON u.user_id = ud.user_id  WHERE ud.user_id = '".$id."'";

        $result = $con->query($sql);
        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
              $name         = $row["name"];
              $email        = $row["email"];
              $mobile       = $row["phone"];
              $altMobile    = $row["alternate_phone"];
              $city         = $row["city"];
              $state        = $row["state"];
              $country      = $row["country"];
              $pincode      = $row["pincode"];
              $address      = $row["address_line_one"];
              $role_id      = $row["role_id"];
              $sub_cat_id   = $row["sub_category_id"];

            }
        }
      }
 ?>
<!------ Include the above in your HEAD tag ---------->
<style type="text/css">
.stepwizard-step p {
    margin-top: 10px;
}
.stepwizard-row {
    display: table-row;
}
.stepwizard {
    display: table;
    width: 50%;
    position: relative;
}
.stepwizard-step button[disabled] {
    opacity: 1 !important;
    filter: alpha(opacity=100) !important;
}
.stepwizard-row:before {
    top: 14px;
    bottom: 0;
    position: absolute;
    content: " ";
    width: 100%;
    height: 1px;
    background-color: #ccc;
    z-order: 0;
}
.stepwizard-step {
    display: table-cell;
    text-align: center;
    position: relative;
}
.btn-circle {
}
</style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
      <!-- Content Header (Page header) -->
            <section class="content-header">                
                    <small><a href="javascript:void(0);"><i class="fa fa-plus"></i> Users</a></small>                    
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Users</a></li>                    
                        <li class="active"><a href="users.php">Users</a></li>           
                    </ol>                
            </section>

<div class="stepwizard col-md-offset-3">
    <div class="stepwizard-row setup-panel">
      <div class="stepwizard-step">
        <a href="#step-1" type="button" class="btn btn-primary btn-circle">1</a>
        <p>Step 1</p>
      </div>
      <div class="stepwizard-step">
        <a href="#step-2" type="button" class="btn btn-default btn-circle" disabled="disabled">2</a>
        <p>Step 2</p>
      </div>
      <div class="stepwizard-step">
        <a href="#step-3" type="button" class="btn btn-default btn-circle" disabled="disabled">3</a>
        <p>Step 3</p>
      </div>
    </div>
  </div>
  <form id="userData" method="post">
    <center><div class="message"></div></center>
    <div class="row setup-content" id="step-1">
      <div class="col-xs-6 col-md-offset-3">
        <div class="col-md-12">
            <center><h3>Basic User Info</h3></center>
              <div class="form-group">
                <label class="control-label">User Name</label>
                <input type="hidden" name="id" value="<?php echo $id; ?>">
                <input  id="name" name="name" value="<?php echo $name; ?>" type="text" class="form-control" placeholder="Enter User Name"  />
              </div>
              <?php  if( !$update ) { ?>
              <div class="form-group">
                <label class="control-label">Password</label>
                <input id="password" name="password"  type="password" class="form-control" placeholder="Enter Password" />
              </div>
            <?php } ?>
              <div class="form-group">
                <label class="control-label">Email</label>
                <input id="email" name="email" value="<?php echo $email; ?>" type="text" class="form-control" placeholder="Enter Email" />
              </div>
              <div class="form-group">
                <label class="control-label">Mobile</label>
                <input  type="text" id="mobile" name="mobile" value="<?php echo $mobile; ?>" maxlength="10" minlength="10" class="form-control" placeholder="Enter Mobile Number" />
              </div>
              <div class="form-group">
                <label class="control-label">Alternate Mobile</label>
                <input  type="text" id="altMobile" name="altMobile" value="<?php echo $altMobile; ?>" maxlength="10" minlength="10" class="form-control" placeholder="Enter Alternate Mobile Number" />
              </div>  
             <a class="btn btn-primary nextBtn btn-lg pull-right validationClick1" data-current="step-1" data-next="step-2">Next</a>
        </div>
      </div>
    </div>
    <div class="row setup-content" id="step-2">
      <div class="col-xs-6 col-md-offset-3">
        <div class="col-md-12">
            <center><h3>User Address Detail</h3></center>
              <div class="form-group">
                <label class="control-label">City</label>
                <input id="city" name="city" type="text" value="<?php echo $city; ?>"  class="form-control" placeholder="Enter City" />
              </div>
              <div class="form-group">
                <label class="control-label">State</label>
                <input  type="text" id="state" name="state" value="<?php echo $state; ?>" class="form-control" placeholder="Enter State" />
              </div>
              <div class="form-group">
                <label class="control-label">Country</label>
                <input  type="text" id="country" name="country" value="<?php echo $country; ?>" class="form-control" placeholder="Enter Counry" />
              </div>
              <div class="form-group">
                <label class="control-label">PinCode</label>
                <input  type="text" id="pincode" name="pincode" value="<?php echo $pincode; ?>" class="form-control" maxlength="6" minlength="6" placeholder="Enter Pin Code" />
              </div> 
              <div class="form-group">
                <label class="control-label">Address</label>
                <textarea id="address" name="address" type="text" class="form-control" placeholder="Enter Permenent Address"><?php echo $address; ?></textarea> 
              </div>              
          <a class="btn btn-primary nextBtn btn-lg pull-right validationClick2" data-current="step-2" data-next="step-3">Next</a>
        </div>
      </div>
    </div>
    <div class="row setup-content" id="step-3">
      <div class="col-xs-6 col-md-offset-3">
        <div class="col-md-12">
        <center><h3> User Roles </h3></center>
            <div class="form-group">
                <label class="control-label">User Type</label>
                    <?php 
                        $psql = "SELECT role_id,role_name FROM roles WHERE active=1";
                        $pexe = mysqli_query( $con, $psql );
                        ?>
                    <select id="user_type_id" name="user_type_id" class="form-control">
                        <option value="-1">---Select User type---</option>
                        <?php while( $prows = mysqli_fetch_assoc( $pexe ) ) { ?>
                            <option value="<?php echo $prows['role_id']; ?>" <?php if( $role_id == $prows['role_id'] ) { echo 'selected = "selected"'; } ?> ><?php echo $prows['role_name']; ?></option>
                        <?php } ?>
                    </select>
            </div>  
         <?php if ($update == true): ?>
            <button class="btn btn-primary btn-lg pull-right" id="updateValue" type="submit" name="update" >update</button>
         <?php else: ?>
            <button class="btn btn-success btn-lg pull-right" id="submitValue" type="button" >Submit</button>
         <?php endif ?>
        </div>
      </div>
    </div>
  </form>
</div>
<script src="js/common.js"></script>  
<script src="js/users/script.js"></script>     
<?php require_once('includes/footer.php'); ?>