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 'groupids' => array(TYPE_STR
, REQ_NO
, ':self'),
49 'password' => array(TYPE_STR
, REQ_YES
),
50 'salt' => array(TYPE_STR
, REQ_SET
),
51 'authkey' => array(TYPE_STR
, REQ_SET
),
52 'showemail' => array(TYPE_BOOL
, REQ_NO
),
53 'showcolors' => array(TYPE_BOOL
, REQ_NO
),
54 'languageid' => array(TYPE_UINT
, REQ_NO
),
55 'timezone' => array(TYPE_FLOAT
,REQ_NO
),
56 'usedst' => array(TYPE_BOOL
, REQ_NO
),
57 'hidestatuses' => array(TYPE_STR
, REQ_NO
, ':self'),
58 'defaultsortkey' => array(TYPE_STR
, REQ_NO
, ':self'),
59 'defaultsortas' => array(TYPE_STR
, REQ_NO
, ':self'),
60 'columnoptions' => array(TYPE_STR
, REQ_NO
, ':self'),
61 'authid' => array(TYPE_STR
, REQ_NO
)
76 var $prefix = TABLE_PREFIX
;
78 // ###################################################################
86 $this->set('salt', $this->registry
->funct
->rand(array(1, 15)));
89 // ###################################################################
95 function set_authkey()
97 $this->set('authkey', $this->registry
->funct
->rand());
100 // ###################################################################
106 function pre_insert()
108 $this->set('password', md5(md5($this->values
['password']) . md5($this->values
['salt'])));
111 // ###################################################################
117 function post_insert()
119 $this->registry
->db
->query("
120 INSERT INTO " . TABLE_PREFIX
. "useremail
121 (userid, mask, relation)
123 (" . $this->insertid
. ", 32, 0),
124 (" . $this->insertid
. ", 320, 1),
125 (" . $this->insertid
. ", 1984, 2),
126 (" . $this->insertid
. ", 64, 4),
127 (" . $this->insertid
. ", 64, 8),
128 (" . $this->insertid
. ", 256, 16
134 // ###################################################################
140 function verify_email()
142 if (!is_bool($ne = $this->verify_noempty('email')))
147 if (!$this->registry
->funct
->is_valid_email($this->values
['email']))
149 return _('The specified email is invalid.');
151 if ($this->registry
->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email = '" . $this->registry
->db
->escape_string($this->values
['email']) . "' AND userid <> " . $this->registry
->clean($this->values
['userid'], TYPE_UINT
)))
153 return _('The specified email is already in use.');
158 // ###################################################################
160 * Verify: displayname
164 function verify_displayname()
166 if (!is_bool($ne = $this->verify_noempty('displayname')))
171 if ($this->registry
->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE displayname = '" . $this->registry
->db
->escape_string($this->values
['displayname']) . "' AND userid <> " . $this->registry
->clean($this->values
['userid'], TYPE_UINT
)))
173 return _('That display name is already in use by another user.');
178 // ###################################################################
180 * Verify: usergroupid
184 function verify_usergroupid()
186 if (!isset($this->registry
->datastore
['usergroup'][ $this->values
['usergroupid'] ]))
193 // ###################################################################
199 function verify_groupids()
201 $groups = $this->values
['groupids'];
202 if (!is_array($groups))
204 $groups = explode(',', $this->values
['groupids']);
206 $groups = $this->registry
->funct
->array_strip_empty($groups);
208 foreach ($groups AS $group)
210 if (!isset($this->registry
->datastore
['usergroup']["$group"]))
216 $this->values
['groupids'] = implode(',', $groups);
221 // ###################################################################
227 function pre_update()
229 $this->set_condition();
232 if ($this->values
['password'] == '')
234 $this->set('password', $this->objdata
['password']);
238 $this->registry
->debug("updating password = true");
239 $this->set('password', md5(md5($this->values
['password']) . md5($this->objdata
['salt'])));
243 // ###################################################################
249 function post_update()
251 if (isset($this->values
['displayname']))
253 $username = $this->registry
->escape($this->values
['displayname']);
254 $id = $this->values
['userid'];
256 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET username = '$username' WHERE userid = $id");
257 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET lastpostbyname = '$username' WHERE lastpostby = $id");
258 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET hiddenlastpostbyname = '$username' WHERE hiddenlastpostby = $id");
261 if (isset($this->values
['displayname']) OR isset($this->values
['email']))
267 // ###################################################################
273 function pre_delete()
275 if ($this->values
['userid'] == $this->registry
->userinfo
['userid'])
277 $this->error(_('You cannot delete your own account!'));
280 if ($this->values
['usergroupid'] == 6)
282 $count = $this->registry
->db
->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> " . $this->values
['userid']);
283 if ($count['count'] < 1)
285 $this->error(_('At least one other administrator needs to be present before you can delete this user'));
290 // ###################################################################
296 function post_delete()
298 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = " . $this->values
['userid']);
299 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "favorite WHERE userid = " . $this->values
['userid']);
300 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = " . $this->values
['userid']);
301 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $this->values
['userid']);
302 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "search WHERE userid = " . $this->values
['userid']);
307 // ###################################################################
309 * Verify: hidestatuses
313 function verify_hidestatuses()
315 if (is_array($this->values
['hidestatuses']))
317 $this->set('hidestatuses', implode(',', $this->values
['hidestatuses']));
323 // ###################################################################
325 * Verify: defaultsortkey
329 function verify_defaultsortkey()
331 if (!ListSorter
::fetch_by_text($this->values
['defaultsortkey']))
339 // ###################################################################
341 * Verify: defaultsortas
345 function verify_defaultsortas()
347 if (!ListSorter
::fetch_as_text($this->values
['defaultsortas']))
355 // ###################################################################
357 * Verify: columnoptions
361 function verify_columnoptions()
363 if (is_array($this->values
['columnoptions']))
365 $this->set('columnoptions', serialize($this->values
['columnoptions']));
371 /*=====================================================================*\
372 || ###################################################################
375 || ###################################################################
376 \*=====================================================================*/