<?php

Class Msite extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    public function login($username, $password) {
        $this->db->select('*');
        $this->db->from('user');
        $this->db->where('username', $username);
        $this->db->where("password = MD5('" . $password . "')");
        $this->db->limit(1);

        $query = $this->db->get();

        //echo $this->db->last_query();

        if ($query->num_rows() == 1) {
            return $query->row();
        } else {
            return false;
        }
    }

    public function loginGuru($username, $password) {
        $this->db->select('*');
        $this->db->from('guru');
        $this->db->where('username', $username);
        $this->db->where("password", $password);
        $this->db->limit(1);

        $query = $this->db->get();

        //echo $this->db->last_query();

        if ($query->num_rows() == 1) {
            return $query->row();
        } else {
            return false;
        }
    }

    public function loginSiswa($username, $password) {
        $this->db->select('*');
        $this->db->from('siswa');
        $this->db->join('log_user_login', 'id_peserta=peserta', 'LEFT');
        $this->db->where('username', $username);
        $this->db->where("password", $password);
        $this->db->limit(1);

        $query = $this->db->get();

        //echo $this->db->last_query();

        if ($query->num_rows() == 1) {
            return $query->row();
        } else {
            return false;
        }
    }

}
