<?php include('accesscheck2.php'); 
require_once('Connections/courier.php');
require_once('functions/functions.php');
mysql_select_db($database_courier, $courier);

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$id = $_POST['id'];
$user_details = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE id = '$id'"));
?>

<div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <i class="icon-home"></i>
            <a href="index.html">Home</a>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Admin Utilities</span>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Edit User Details</span>
        </li>
    </ul>
    <div class="page-toolbar">
        <div class="btn-group pull-right">
            <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> Actions
                <i class="fa fa-angle-down"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li onclick="getstep('<?php echo $action; ?>', '<?php echo $id; ?>');">
                    <a href="#">
                        <i class="icon-refresh"></i> Refresh 
                    </a>
                </li>
                <li onclick="getstep('list_of_users');">
                    <a href="#">
                        <i class="fa fa-list"></i> List of Users 
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
                    <!-- END PAGE HEADER-->
                    <div class="row">
                        <div class="col-md-12">
                            <div class="profile-content">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="portlet light ">
                                            <div class="portlet-title">
                                                <div class="caption caption-md">
                                                    <i class="icon-globe theme-font hide"></i>
                                                    <span class="caption-subject bold uppercase font-dark"> USER DETAILS </span>
                                                </div>
                                            </div>
                                            
                                             <div class="portlet-body form">
        <div class="row">
            <div class="form-body">
                <div class="row">    
                    <div class="col-lg-12 col-xs-12 col-md-12">
                        <form id="save_new_user" role="form" action="#" class="form-horizontal">
                            <div class="form-body">
                                <div class="row" id="investment_plan_wrapper">    
                                    <div class="col-lg-12 col-xs-12 col-md-12">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left">Username</span></label>
                                                <div class="col-md-7">
                                                    <input name="username" id="username" type="text" class="form-control" value="<?php echo $user_details['username']; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left">Surname</span></label>
                                                <div class="col-md-7">
                                                    <input name="surname" id="surname" type="text" class="form-control" value="<?php echo $user_details['surname']; ?>">
                                                </div>
                                            </div>
                                            
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left">Other Names</span></label>
                                                <div class="col-md-7">
                                                   <input name="othernames" id="othernames" type="text" class="form-control" value="<?php echo $user_details['firstnames']; ?>">
                                                </div>
                                            </div>
                                            
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Phone Number</span></label>
                                                <div class="col-md-7">
                                                   <input name="phone_number" id="phone_number" type="text" class="form-control" value="<?php echo $user_details['tel']; ?>">
                                                </div>
                                            </div>
                                            
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Security Level </span></label>
                                                <div class="col-md-7">
                                                   <select name="security_level" id="security_level" class="form-control">
                                                       <option value="">--Select--</option>
                                                        <?php 
                                                        $security = mysql_query("SELECT * FROM security WHERE status = 'Active'");
                                                        while($row = mysql_fetch_assoc($security)){ ?>
                                                       <option <?php if($row['security_symbol'] == $user_details['security']){ echo 'selected=""'; } ?> value="<?php echo $row['security_symbol'];?>"><?php echo $row['security_name'];?></option>
                                                       <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                           
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Branch Name </span></label>
                                                <div class="col-md-7">
                                                   <select name="branch_id" id="branch_id" class="form-control">
                                                       <option value="">--Select--</option>
                                                        <?php 
                                                        $security = mysql_query("SELECT * FROM branches WHERE status = 'Active'");
                                                        while($row = mysql_fetch_assoc($security)){ ?>
                                                       <option <?php if($row['id'] == $user_details['branch_id']){ echo 'selected=""'; } ?> value="<?php echo $row['id'];?>"><?php echo $row['branch_name'];?></option>
                                                       <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Password </span></label>
                                                <div class="col-md-7">
                                                    <input name="password" id="password" type="password" class="form-control">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Staff Id/No. </span></label>
                                                <div class="col-md-7">
                                                    <input name="staff_id" id="staff_id" type="text" class="form-control" value="<?php echo $user_details['staffid']; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group" id="">
                                                <label class="col-md-5 control-label"> <span class="pull-left">Email Address</span></label>
                                                <div class="col-md-7">
                                                    <input name="email_address" id="email_address" type="text" class="form-control" value="<?php echo $user_details['email']; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group" id="" style="display:none;">
                                                <label class="col-md-5 control-label"> <span class="pull-left"> Address </span></label>
                                                <div class="col-md-7">
                                                    <input name="address" id="address" type="text" class="form-control" value="<?php echo $user_details['address']; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group" id="">
                                                <label class="col-md-5 control-label"> <span class="pull-left"> Permission Role </span></label>
                                                <div class="col-md-7">
                                                    <select name="perm_role" id="perm_role" class="form-control">
                                                        <option value="">--Select--</option>
                                                       <?php 
                                                        $security = mysql_query("SELECT * FROM security_level_roles ORDER BY security_role");
                                                        while($row = mysql_fetch_assoc($security)){ ?>
                                                           <option <?php if($row['id'] == $user_details['perm_role_id']){ echo 'selected=""';} ?> value="<?php echo $row['id'];?>"><?php echo $row['security_role'];?></option>
                                                       <?php } ?> 
                                                    </select>
                                                </div>
                                            </div>
                                             <div class="form-group" id="">
                                                <label class="col-md-5 control-label"> <span class="pull-left"> Account Status </span></label>
                                                <div class="col-md-7">
                                                    <select name="account_status" id="account_status" class="form-control">
                                                        <option value=""></option>
                                                        <option <?php if($user_details['account_status'] == 'Active'){ echo 'selected=""'; } ?> value="Active">Active</option>
                                                        <option <?php if($user_details['account_status'] == 'Deactivated'){ echo 'selected=""'; } ?> value="Deactivated">Deactivate</option>
                                                    </select>
                                                </div>
                                            </div>

<div class="form-group">
                                                <label class="col-md-5 control-label"><span class="pull-left"> Stationed Branch </span></label>
                                                <div class="col-md-7">
                                                   <select name="branch_id_station" id="branch_id_station" class="form-control">
                                                       <option value="">--Select--</option>
                                                        <?php 
                                                        $security = mysql_query("SELECT * FROM branches WHERE status = 'Active' AND type='branch'");
                                                        while($row = mysql_fetch_assoc($security)){ ?>
                                                       <option <?php if($row['id']==$user_details['active_branch_id']){echo 'selected=""';} ?> value="<?php echo $row['id'];?>"><?php echo $row['branch_name'];?></option>
                                                       <?php } ?>
                                                    </select>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            
            <div class="form-actions right">
                <button type="reset" class="btn default"> <i class="fa fa-refresh"></i> Reset </button>
            <a class="btn green" onclick="saveInformation2('update_user_details','<?php echo $id; ?>','form#save_new_user','#currentarea');return false;"> Save User <i class="fa fa-check"></i> </a>
        </div>
        </div>
    </div>
                                          
                                </div>
                            </div>
                        </div>
                    </div>