php class Analytics_model extends CI_Model public function __construct

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class Analytics_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->database();
$this->load->library('session');
}
public function get_downloaders($filter = array()) {
if ($filter == false)
{
$query = $this->db->query('SELECT * FROM downloaders ORDER BY date DESC');
return $query->result_array();
}
$query = $this->db->get_where('resourses', $filter);
return $query->row_array();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('login'));
$password = $this->security->xss_clean($this->input->post('password'));
$res = $this->db->query("SELECT salt FROM users WHERE login = ?", array($username));
$salt = $res->row();
if ($salt) {
$password = sha1($password . $salt->salt);
$this->db->where('login', $username);
$this->db->where('password', $password);
$query = $this->db->get('users');
if($query->num_rows == 1) {
$row = $query->row();
$data = array(
'adminid' => $row->id,
'aname' => $row->login,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
}
return false;
}
public function get_page_content($page) {
if ($page == 'downloaders') {
$res = $this->db->query("SELECT * FROM downloaders ORDER BY date DESC");
return $res->result_array();
}
}
public function logout() {
$this->session->sess_destroy();
return true;
}
}