0
|
1 |
<?php
|
|
2 |
class Aulib
|
|
3 |
{
|
|
4 |
private $obj = NULL;
|
|
5 |
|
|
6 |
function Aulib()
|
|
7 |
{
|
|
8 |
$this->obj =& get_instance();
|
|
9 |
$this->obj->load->model('aumodel');
|
|
10 |
$this->obj->config->load('auconfig');
|
|
11 |
if ($this->obj->config->item('au_language') != '')
|
|
12 |
$curLang = $this->obj->config->item('au_language');
|
|
13 |
else
|
|
14 |
$curLang = $this->obj->config->item('language');
|
|
15 |
$this->obj->lang->load('au', $curLang);
|
|
16 |
}
|
|
17 |
|
|
18 |
/*
|
|
19 |
* Return "welcome" string with link to login page
|
|
20 |
* Call this function every time on you main page
|
|
21 |
*/
|
|
22 |
function getLoginLink()
|
|
23 |
{
|
|
24 |
$id = $this->getSessionId();
|
|
25 |
if($id)
|
|
26 |
{
|
|
27 |
$logoff_link = $this->obj->lang->line('logout_link_name');
|
|
28 |
$welcome_str = $this->obj->lang->line('welcome_string');
|
|
29 |
if($welcome_str != '')
|
|
30 |
{
|
|
31 |
$welcome_str = str_replace('%name%', $this->obj->aumodel->userInfo($id, 'name'), $welcome_str);
|
|
32 |
$welcome_str = str_replace('%logoff%', anchor('au/logout',$logoff_link), $welcome_str);
|
|
33 |
}
|
|
34 |
return $welcome_str;
|
|
35 |
}
|
|
36 |
else
|
|
37 |
{
|
|
38 |
$login_link = $this->obj->lang->line('login_link_name');
|
|
39 |
$registers_link = $this->obj->lang->line('registers_link_name');
|
|
40 |
$login_str = $this->obj->lang->line('login_string');
|
|
41 |
if($login_str != '')
|
|
42 |
{
|
|
43 |
$login_str = str_replace('%registers%', anchor('au/registers',$registers_link), $login_str);
|
|
44 |
$login_str = str_replace('%login%', anchor('au/login',$login_link), $login_str);
|
|
45 |
}
|
|
46 |
|
|
47 |
return $login_str;
|
|
48 |
}
|
|
49 |
}
|
|
50 |
|
|
51 |
/*
|
|
52 |
* Return link for call back-end system
|
|
53 |
* This back-end can help you manage users & groups
|
|
54 |
*/
|
|
55 |
function getManagerLink()
|
|
56 |
{
|
|
57 |
return anchor('aumanager', $this->obj->lang->line('manager_link_name'));
|
|
58 |
}
|
|
59 |
|
|
60 |
/*
|
|
61 |
* function block for set/get session userID
|
|
62 |
*/
|
|
63 |
function setSessionId($id, $storable = FALSE)
|
|
64 |
{
|
|
65 |
if( $id < 1 )
|
|
66 |
{
|
|
67 |
$this->obj->session->unset_userdata('id');
|
|
68 |
$this->obj->session->unset_userdata('flash');
|
|
69 |
}
|
|
70 |
else
|
|
71 |
{
|
|
72 |
$this->obj->session->set_userdata('flash', !$storable);
|
|
73 |
$offset = (int) $this->obj->config->item('id_offset');
|
|
74 |
|
|
75 |
if($storable)
|
|
76 |
$this->obj->session->set_userdata('id', $id * $offset);
|
|
77 |
else
|
|
78 |
{
|
|
79 |
$this->obj->session->set_flashdata('id', $id * $offset);
|
|
80 |
$this->obj->session->set_flashdata('expire', time()+$this->obj->config->item('autologin_timeout'));
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
function getSessionId()
|
|
85 |
{
|
|
86 |
$this->keepSession();
|
|
87 |
if($this->obj->session->userdata('flash'))
|
|
88 |
{
|
|
89 |
if( !$this->obj->session->flashdata('id') )
|
|
90 |
return 0;
|
|
91 |
}
|
|
92 |
$offset = (int) $this->obj->config->item('id_offset');
|
|
93 |
if(!$this->obj->session->userdata('flash'))
|
|
94 |
$real_id = ($this->obj->session->userdata('id') / $offset);
|
|
95 |
else
|
|
96 |
$real_id = ($this->obj->session->flashdata('id') / $offset);
|
|
97 |
if(ceil($real_id) != floor($real_id))
|
|
98 |
{
|
|
99 |
$this->logout();
|
|
100 |
return 0;
|
|
101 |
}
|
|
102 |
else
|
|
103 |
return $real_id;
|
|
104 |
}
|
|
105 |
function keepSession()
|
|
106 |
{
|
|
107 |
if( ($this->obj->session->userdata('flash')) && ($this->obj->session->flashdata('expire') >= time()) )
|
|
108 |
{
|
|
109 |
$this->obj->session->keep_flashdata('id');
|
|
110 |
$this->obj->session->set_flashdata('expire', time()+$this->obj->config->item('autologin_timeout'));
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
/*
|
|
115 |
* Return TRUE if user is logged on
|
|
116 |
*/
|
|
117 |
function isLogged() { return (bool) $this->getSessionId(); }
|
|
118 |
|
|
119 |
/*
|
|
120 |
* Return TRUE if user is in group
|
|
121 |
*/
|
|
122 |
function isGroup($group_name)
|
|
123 |
{
|
|
124 |
return ($this->obj->aumodel->getRefId('augroup', $group_name) == $this->obj->aumodel->userInfo($this->getSessionId(), 'group_id'));
|
|
125 |
}
|
|
126 |
|
|
127 |
/*
|
|
128 |
* Return TRUE if user has specified role
|
|
129 |
*/
|
|
130 |
function isRole($role_name)
|
|
131 |
{
|
|
132 |
return ( $this->obj->aumodel->getRefId('aurole', $role_name) == $this->obj->aumodel->userInfo($this->getSessionId(), 'role_id') );
|
|
133 |
}
|
|
134 |
|
|
135 |
/*
|
|
136 |
* Show "deny access" page
|
|
137 |
*/
|
|
138 |
function denyAccess()
|
|
139 |
{
|
|
140 |
$this->obj->load->helper('url');
|
|
141 |
redirect('au/denyaccess');
|
|
142 |
}
|
|
143 |
|
|
144 |
/*
|
|
145 |
* Create and return captcha
|
|
146 |
* Use standart CI plugin
|
|
147 |
*/
|
|
148 |
function getCaptcha()
|
|
149 |
{
|
|
150 |
$this->obj->load->helper('url');
|
|
151 |
$this->obj->load->plugin('captcha');
|
|
152 |
$vals = array(
|
|
153 |
'word' => '',
|
|
154 |
'img_path' => $this->obj->config->item('au_captcha_store_path'),
|
|
155 |
'img_url' => $this->obj->config->item('au_captcha_img_url'),
|
|
156 |
'font_path' => '/system/fonts/texb.ttf',
|
|
157 |
'img_width' => '120',
|
|
158 |
'img_height' => '40',
|
|
159 |
'expiration' => '7200'
|
|
160 |
);
|
|
161 |
$cap = create_captcha($vals);
|
|
162 |
return $cap;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
?>
|