<?php
class viewuser{
    var $id;
    
    function user(){
        $user = mysql_query("SELECT users.blokir ,users.username ,users.id_level ,detail_user.* FROM users ,detail_user WHERE users.username = detail_user.username AND detail_user.id_user = '$this->id'");
        $c = mysql_fetch_array($user);
        
            $data = array(
                        'id_user' => $c[id_user],
                        'username' => $c[username],
                        'nama' => $c[nama],
                        'nip' => $c[nip],
                        'email' => $c[email],
                        'alamat' => $c[alamat],
                        'telpon' => $c[telpon],
                        'keterangan' => $c[keterangan],
                        'blokir' => $c[blokir],
                        'id_level' => $c[id_level]
                        
                     );
        
        return($data);
    }
    
    function listuser(){
            $user = mysql_query("SELECT users.blokir ,detail_user.* FROM users ,detail_user WHERE users.username = detail_user.username ORDER BY detail_user.id_user DESC");
        
        
        while ($c = mysql_fetch_array($user)){
            $data[$i] = array(
                        'id_user' => $c[id_user],
                        'username' => $c[username],
                        'nama' => $c[nama],
                        'nip' => $c[nip],
                        'email' => $c[email],
                        'alamat' => $c[alamat],
                        'telpon' => $c[telpon],
                        'keterangan' => $c[keterangan],
                        'blokir' => $c[blokir],
                        'id_level' => $c[id_level]
                     );
            
            $i++;
        }
        
        return $data;
    }
    
    function adduser($username,$password,$status,$blokir,$nama,$id_level,$nip,$email,$alamat,$telpon,$keterangan){
        
        mysql_query("INSERT INTO users( username,
                                        password,
                                        nama_lengkap,
                                        id_level,
                                        status,
                                        blokir,
                                        id_session) 
                                        VALUES(
                                        '$username',
                                        '$password',
                                        '$nama',
                                        '$id_level',    
                                        '$status',
                                        '$blokir',    
                                        '$password')");
        
        mysql_query("INSERT INTO detail_user(   username,
                                                nama,
                                                nip,
                                                email,
                                                alamat,
                                                telpon,
                                                keterangan) 
                                                VALUES(
                                                '$username',
                                                '$nama',
                                                '$nip',
                                                '$email',
                                                '$alamat',
                                                '$telpon',
                                                '$keterangan')");
    }
    
    function edituser($status,$nama,$id_level,$nip,$email,$alamat,$telpon,$keterangan){
        
        
        mysql_query("UPDATE detail_user SET     nama            = '$nama',
                                                nip             = '$nip',
                                                email           = '$email', 
                                                alamat          = '$alamat',
                                                telpon          = '$telpon',  
                                                pav             = '$pav', 
                                                poli            = '$poli',
                                                keterangan      = '$keterangan'    
                                                WHERE 
                                                id_user       = $this->id");
        
    }
    
    function editpassword($password,$username){
        
        
        mysql_query("UPDATE users SET password = '$password' WHERE username = '$username'");
    }
    
    function editlevel($id_level,$username){
        
        
        mysql_query("UPDATE users SET id_level = $id_level WHERE username = '$username'");
    }
    
    function deleteuser($username){
        
        mysql_query("DELETE FROM users where username = '$username'");
        
        mysql_query("DELETE FROM detail_user where id_user = $this->id");
        
    }
    
    function aktifuser($username,$blokir){
        mysql_query("UPDATE users SET blokir = '$blokir' WHERE username = '$username'");
    }
    
    function searchuser($username){
        $user = mysql_query("SELECT * FROM users WHERE username = '$username'");
        
        $data=mysql_num_rows($user);
        
        return($data);
        
    }
    
    function iduser($username){
        $user = mysql_query("SELECT id_user FROM detail_user WHERE username = '$username'");
        $u = mysql_fetch_array($user);
        
        $data=$u[id_user];
        
        return($data);
        
    }
    
    function ketstatus($keterangan){
        mysql_query("UPDATE detail_user SET keterangan  = '$keterangan' WHERE id_user = $this->id");
    }
}
    

