[eluser]monkeypaw201[/eluser]
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Account {
function login($username,$password)
{
$this->CI =& get_instance();
$query = $this->CI->db->query("SELECT * FROM `clients` WHERE `username` = '".$username."' AND `password` = '".sha1($password)."'");
if ($query->num_rows() > 0)
{
$row = $query->row();
$this->CI->session->set_userdata('client_id', $row->client_id);
return TRUE;
}else{
return FALSE;
}
}
function logout()
{
$this->CI =& get_instance();
$this->CI->session->unset_userdata('client_id');
}
function data($column='username')
{
$this->CI =& get_instance();
$client_id = $this->CI->session->userdata('client_id');
$query = $this->CI->db->query("SELECT * FROM `clients` WHERE `client_id` = '".$client_id."'");
$row = $query->row_array();
return $row[$column];
}
function notices()
{
$this->CI =& get_instance();
$client_id = $this->CI->session->userdata('client_id');
$query = $this->CI->db->query("SELECT * FROM `notices` WHERE `client_id` = '".$client_id."' AND `read` = '0'");
$output = '<div class="pad20">';
foreach ($query->result() as $row)
{
$output .= '<div class="message '.$row->type.' close" id="'.$row->notice_id.'">
<h2>'.$row->title.'!</h2>
<p>'.$row->message.'</p>
</div>';
}
$output .= '</div>';
return $output;
}
function update($column,$value)
{
$this->CI =& get_instance();
$client_id = $this->CI->session->userdata('client_id');
$query = $this->CI->db->query("UPDATE `clients` SET `".$column."` = '".$value."' WHERE `client_id` = '".$client_id."' LIMIT 1");
}
}
?>