4ad7ac18d62c2cd5749c3661ecdb102ab9c6bf43
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $GLOBALS['isso:callback']->load('api', null
);
24 require_once('./includes/functions_datastore.php');
25 require_once('./includes/class_sort.php');
31 * @copyright Copyright ©2002 - [#]year[#], Blue Static
36 class UserAPI
extends API
44 'userid' => array(TYPE_UINT
, REQ_AUTO
, 'verify_nozero'),
45 'email' => array(TYPE_STR
, REQ_YES
, ':self'),
46 'displayname' => array(TYPE_STR
, REQ_YES
, ':self'),
47 'usergroupid' => array(TYPE_UINT
, REQ_YES
, ':self'),
48 'password' => array(TYPE_STR
, REQ_YES
),
49 'salt' => array(TYPE_STR
, REQ_SET
),
50 'authkey' => array(TYPE_STR
, REQ_SET
),
51 'showemail' => array(TYPE_BOOL
, REQ_NO
),
52 'showcolours' => array(TYPE_BOOL
, REQ_NO
),
53 'languageid' => array(TYPE_UINT
, REQ_NO
),
54 'timezone' => array(TYPE_INT
, REQ_NO
),
55 'usedst' => array(TYPE_BOOL
, REQ_NO
),
56 'hidestatuses' => array(TYPE_STR
, REQ_NO
, ':self'),
57 'defaultsortkey' => array(TYPE_STR
, REQ_NO
, ':self'),
58 'defaultsortas' => array(TYPE_STR
, REQ_NO
, ':self')
73 var $prefix = TABLE_PREFIX
;
75 // ###################################################################
83 $this->set('salt', $this->registry
->funct
->rand(array(1, 15)));
86 // ###################################################################
92 function set_authkey()
94 $this->set('authkey', $this->registry
->funct
->rand());
97 // ###################################################################
103 function pre_insert()
105 $this->set('password', md5(md5($this->values
['password']) . md5($this->values
['salt'])));
108 // ###################################################################
114 function post_insert()
119 // ###################################################################
125 function verify_email()
127 if (!is_bool($ne = $this->verify_noempty('email')))
132 if (!$this->registry
->funct
->is_valid_email($this->values
['email']))
134 return $this->registry
->lang
->string('The specified email is invalid.');
136 if ($this->registry
->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email = '" . $this->registry
->db
->escape_string($this->values
['email']) . "' AND userid <> " . $this->values
['userid']))
138 return $this->registry
->lang
->string('The specified email is already in use.');
143 // ###################################################################
145 * Verify: displayname
149 function verify_displayname()
151 if (!is_bool($ne = $this->verify_noempty('displayname')))
156 if ($this->registry
->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE displayname = '" . $this->registry
->db
->escape_string($this->values
['displayname']) . "' AND userid <> " . $this->values
['userid']))
158 return $this->registry
->lang
->string('That display name is already in use by another user.');
163 // ###################################################################
165 * Verify: usergroupid
169 function verify_usergroupid()
171 if (!isset($this->registry
->datastore
['usergroup'][ $this->values
['usergroupid'] ]))
178 // ###################################################################
184 function pre_update()
186 $this->set_condition();
189 if ($this->values
['password'] == '')
191 $this->set('password', $this->objdata
['password']);
195 $this->registry
->debug("updating password = true");
196 $this->set('password', md5(md5($this->values
['password']) . md5($this->objdata
['salt'])));
200 // ###################################################################
206 function post_update()
211 // ###################################################################
217 function pre_delete()
219 if ($this->values
['userid'] == $this->registry
->userinfo
['userid'])
221 $this->error($lang->string('You cannot delete your own account!'));
224 if ($this->values
['usergroupid'] == 6)
226 $count = $this->registry
->db
->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> " . $this->values
['userid']);
227 if ($count['count'] < 1)
229 $this->error($lang->string('At least one other administrator needs to be present before you can delete this user'));
234 // ###################################################################
238 * @todo Finish post-delete user data cleanup
242 function post_delete()
244 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = " . $this->values
['userid']);
245 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $this->values
['userid']);
246 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = " . $this->values
['userid']);
251 // ###################################################################
253 * Verify: hidestatuses
257 function verify_hidestatuses()
259 if (is_array($this->values
['hidestatuses']))
261 $this->set('hidestatuses', implode(',', $this->values
['hidestatuses']));
267 // ###################################################################
269 * Verify: defaultsortkey
273 function verify_defaultsortkey()
275 if (!ListSorter
::fetch_by_text($this->values
['defaultsortkey']))
283 // ###################################################################
285 * Verify: defaultsortas
289 function verify_defaultsortas()
291 if (!ListSorter
::fetch_as_text($this->values
['defaultsortas']))
300 /*=====================================================================*\
301 || ###################################################################
304 || ###################################################################
305 \*=====================================================================*/