<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Administrator_model extends CI_Model {
public function __construct()
{
// Call the Model constructor
parent::__construct();
}
function login($username, $password)
{
$this->db->where('username', $username);
$this->db->from('accounts');
$this->db->limit(1);
$query = $this->db->get();
$admin = $query->row();
if (is_object($admin) && $admin->password == sha1($this->config->item('member_salt') . $password)) {
return $admin;
} else {
return false;
}
}
function get_countries($country = FALSE)
{
$this->db->from('countries');
$query = $this->db->get();
return $query;
}
function get_states()
{
$this->db->from('states');
$this->db->join('countries', 'countries.country_id=states.country_id', 'left');
$this->db->order_by('countries.country_name','asc');
$this->db->order_by('states.state_name', 'asc');
$query = $this->db->get();
return $query;
}
function get_provinces()
{
$this->db->from('provinces');
$this->db->join('states', 'states.state_id=provinces.state_id', 'left');
$this->db->join('countries', 'countries.country_id=states.country_id', 'left');
$this->db->order_by('countries.country_name','asc');
$this->db->order_by('states.state_name', 'asc');
$this->db->order_by('provinces.province_name', 'asc');
$query = $this->db->get();
return $query;
}
function get_members($letter){
$this->db->like('username',$letter, 'after');
$this->db->from('members');
$this->db->join('provinces', 'provinces.province_id=members.location_id', 'left');
$this->db->join('states', 'states.state_id=provinces.state_id', 'left');
$this->db->join('countries', 'countries.country_id=states.country_id', 'left');
$this->db->join('memberships', 'memberships.membership_id=members.membership_id', 'left');
$query = $this->db->get();
return $query;
}
// add a country to the DB
function add_country($country)
{
// add the $country object/array to the DB
$this->db->insert('countries', $country);
// fetch the inserted id (auto incremented value of country_id) and return it
return $this->db->insert_id();
}
function add_state($state)
{
// add the $country object/array to the DB
$this->db->insert('states', $state);
// fetch the inserted id (auto incremented value of country_id) and return it
return $this->db->insert_id();
}
function update_state($state, $state_id)
{
// add the $country object/array to the DB
$this->db->where('state_id', $state_id);
$this->db->update('states', $state);
}
function add_province($province)
{
// add the $country object/array to the DB
$this->db->insert('provinces', $province);
// fetch the inserted id (auto incremented value of country_id) and return it
return $this->db->insert_id();
}
function update_province($province, $province_id)
{
// add the $country object/array to the DB
$this->db->where('province_id', $province_id);
$this->db->update('provinces', $province);
}
function get_reports(){
$this->db->from('reports');
$this->db->join('members', 'members.member_id = reports.reported_member_id', 'left');
$query = $this->db->get();
return $query;
}
function read_report($read)
{
// add the $country object/array to the DB
$this->db->where('read', 0);
$this->db->update('reports', $read);
// fetch the inserted id (auto incremented value of country_id) and return it
return $this->db->insert_id();
}
function get_text($id)
{
$this->db->where('id', $id);
$this->db->from('texts');
$query = $this->db->get();
return $query->row();
}
function edit_text($id, $text)
{
$this->db->where('id', $id);
$this->db->update('texts', $text);
}
}
/* End of file event_model.php */
/* Location: ./application/models/event_model.php */