<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                    
                </h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?php echo base_url();?>">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="<?php echo base_url()."index.php/".$link;?>"><?php echo $titlebefore;?></a></li>
                    <li class="breadcrumb-item active"><?php echo $title;?></li>
                </ol>
            </div>
        </div>
    </div>
</section>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-default">
                    <?php 
                        $setdisabled= "";
                        $setid      = "";
                        $setnama    = "";
                        $setuser    = "";
                        $settipeuser= "";
                        $setloket   = "";

                        $setdisloket    = "disabled=''";
                        $setdisklinik   = "disabled=''";

                        $setstatus  = 1;
                        if ($actionform=="prosesview"){
                            $setdisabled="disabled=''";
                        }
                        if ($actionform!="prosesadd"){
                            $setid      = $us->row('mu_id');
                            $setnama    = $us->row('mu_namalengkap');
                            $setuser    = $us->row('mu_namauser');
                            $settipeuser= $us->row('mu_tipeuser_id');
                            $setstatus  = $us->row('mu_status');
                            $setloket   = $us->row('mu_loket_id');
                            $setklinik  = $us->row('mu_klinik_id');

                            if($settipeuser=="3"){
                                $setdisloket    = "";
                            }if ($settipeuser=="4") {
                                $setdisklinik   = "";
                            }
                        }
                    ?>
                    <form action="<?php echo(base_url()); ?>index.php/<?php echo $link;?>/<?php echo $actionform; ?>" method="post" autocomplete="off">
                        <div class="card-header">
                            <h3 class="card-title"><?php echo $title;?></h3>
                        </div>
                        <div class="card-body">
                            <?php if(validation_errors()){ ?>
                                <div id="alert" class="alert alert-danger alert-dismissable">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <i class="icon fa fa-ban"></i> Alert!
                                        <?php echo validation_errors() ?>
                                </div>
                                <script> 
                                    setTimeout(function() {
                                        $('#alert').hide('fast');
                                    }, 5000);
                                </script>
                            <?php } ?>
                            <div class="form-group row">
                                <label for="nama" class="col-sm-2 col-form-label">Nama Lengkap</label>
                                <div class="col-sm-6">
                                    <input type="hidden" name="id" value="<?php echo $setid;?>"/>
                                    <input id="nama" name="nama" type="text" <?php echo $setdisabled;?> class="form-control" placeholder="Masukan Nama Lengkap" value="<?php echo $setnama;?>" />
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="user" class="col-sm-2 col-form-label">User</label>
                                <div class="col-sm-6">
                                    <input id="user" name="user" type="text" <?php echo $setdisabled;?> class="form-control" placeholder="Masukan Nama User" value="<?php echo $setuser;?>" />
                                </div>
                            </div>
                            <?php 
                            if($actionform!="prosesadd"){
                            ?>
                            <div class="form-group row">
                                <label for="passworduser" class="col-sm-2 col-form-label">Password</label>
                                <div class="col-sm-6">
                                    <div class="input-group">
                                        <input disabled="" id="passworduser" class="form-control" name="passworduser" type="password" placeholder="Masukan Password" value=""/>
                                        <div class="input-group-prepend">
                                            <span class="input-group-text">
                                                <input <?php echo $setdisabled; ?> id="setaktif" type="checkbox" onchange="aktif()" />
                                            </span>
                                        </div>
                                    </div> 
                                </div>
                                <div class="col-sm-2">
                                    <code>Ubah Password</code>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="repassworduser" class="col-sm-2 col-form-label">Retype Password</label>
                                <div class="col-sm-6">
                                    <input disabled="" id="repassworduser" class="form-control" <?php if($actionform!="prosesadd"){}?> name="repassworduser" type="password" placeholder="Masukan Retype Password" value=""/>
                                </div>
                            </div>
                                <script>
                                    function aktif(){
                                        if ($('#setaktif').is(":checked"))
                                        {   
                                            $("#passworduser").prop('disabled', false);
                                            $("#repassworduser").prop('disabled', false);
                                        }else{
                                            document.getElementById('passworduser').value="";
                                            document.getElementById('repassworduser').value="";
                                            $("#passworduser").prop('disabled', true);
                                            $("#repassworduser").prop('disabled', true);  
                                        }
                                    }
                                </script>
                                <?php }else{
                                ?>
                                
                            <div class="form-group row">
                                <label for="passworduser" class="col-sm-2 col-form-label">Password</label>
                                <div class="col-sm-6">
                                    <input id="passworduser" class="form-control" name="passworduser" type="password" placeholder="Masukan Password" value=""/>
                                </div>
                            </div> 
                            <div class="form-group row">
                                <label for="repassworduser" class="col-sm-2 col-form-label">Retype Password</label>
                                <div class="col-sm-6">
                                    <input id="repassworduser" class="form-control" name="repassworduser" type="password" placeholder="Masukan Retype Password" value=""/>
                                </div>
                            </div>
                                <?php  
                                }?>
                            <div class="form-group row">
                                <label for="tipeuser" class="col-sm-2 col-form-label">Tipe User</label>
                                <div class="col-sm-6">
                                    <select <?php echo $setdisabled; ?> onchange="setpel()" id="tipeuser" name="tipeuser" class="form-control select" >
                                        <option value="">Pilih Tipe User</option>
                                        <?php 
                                            foreach ($tu as $dat) {
                                                $select="";
                                                if($settipeuser==$dat->mt_id){$select="selected='selected'";}
                                                echo "<option value='".$dat->mt_id."'".$select.">".$dat->mt_nama."</option>";
                                            }
                                        ?>
                                  </select>
                                </div>
                            </div>
                            <script>
                                function setpel(){
                                    var tp = document.getElementById("tipeuser").value;
                                    if(tp==3){
                                        document.getElementById("loket").value = "";
                                        document.getElementById("klinik").value = "";
                                        $("#loket").prop('disabled', false);
                                        $("#klinik").prop('disabled', true);
                                        
                                    }else if(tp==4){
                                        document.getElementById("loket").value = "";
                                        document.getElementById("klinik").value = "";
                                        $("#loket").prop('disabled', true);
                                        $("#klinik").prop('disabled', false);
                                    }else{
                                        $("#loket").prop('disabled', true);
                                        $("#klinik").prop('disabled', true);
                                    }
                                }
                            </script>
                            <div class="form-group row">
                                <label for="loket" class="col-sm-2 col-form-label">Loket Rajal</label>
                                <div class="col-sm-6">
                                    <select <?php echo $setdisloket; echo $setdisabled; ?> id="loket" name="loket" class="form-control">
                                        <option value="">Pilih Loket Rajal</option>
                                        <?php 
                                            foreach ($lo as $dat) {
                                                $select="";
                                                if($setloket==$dat->mlrj_id){$select="selected='selected'";}
                                                echo "<option value='".$dat->mlrj_id."'".$select.">".$dat->mlrj_nama."</option>";
                                            }
                                        ?>
                                  </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="klinik" class="col-sm-2 col-form-label">Klinik</label>
                                <div class="col-sm-6">
                                    <select <?php echo $setdisklinik; echo $setdisabled; ?> id="klinik" name="klinik" class="form-control">
                                        <option value="">Pilih Klinik</option>
                                        <?php 
                                            foreach ($kl as $dat) {
                                                $isiket="";
                                                if($dat->mk_ket!=""){
                                                    $isiket="( ".$dat->mk_ket." )";
                                                }
                                                $select="";
                                                if($setklinik==$dat->mk_id){$select="selected='selected'";}
                                                echo "<option value='".$dat->mk_id."'".$select.">".$dat->mk_nama." | ".$dat->mk_kode." ".$isiket."</option>";
                                            }
                                        ?>
                                  </select>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label"></label>
                                <div class="col-sm-2">
                                    <input id="status" name="status" type="checkbox" value="1" <?php echo $setdisabled;?> <?php if($setstatus==1){echo "checked";}?> data-bootstrap-switch data-off-color="danger" data-on-color="success"/>
                                </div>
                            </div>
                        </div>
                        <div class="card-footer">
                            <?php if ($actionform!="prosesview"){ ?>
                                <button type="submit" class="btn btn-info">Simpan</button>
                            <?php } ?>
                            <a href="<?php echo base_url()."index.php/".$link;?>" class="btn btn-default float-right">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
