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 'showcolors' => array(TYPE_BOOL
, REQ_NO
),
53 'languageid' => array(TYPE_UINT
, REQ_NO
),
54 'timezone' => array(TYPE_FLOAT
,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'),
59 'columnoptions' => array(TYPE_STR
, REQ_NO
, ':self')
74 var $prefix = TABLE_PREFIX
;
76 // ###################################################################
84 $this->set('salt', $this->registry
->funct
->rand(array(1, 15)));
87 // ###################################################################
93 function set_authkey()
95 $this->set('authkey', $this->registry
->funct
->rand());
98 // ###################################################################
104 function pre_insert()
106 $this->set('password', md5(md5($this->values
['password']) . md5($this->values
['salt'])));
109 // ###################################################################
115 function post_insert()
117 $this->registry
->db
->query("
118 INSERT INTO " . TABLE_PREFIX
. "useremail
119 (userid, mask, relation)
121 (" . $this->insertid
. ", 32, 0),
122 (" . $this->insertid
. ", 320, 1),
123 (" . $this->insertid
. ", 1984, 2),
124 (" . $this->insertid
. ", 64, 4),
125 (" . $this->insertid
. ", 64, 8),
126 (" . $this->insertid
. ", 256, 16
132 // ###################################################################
138 function verify_email()
140 if (!is_bool($ne = $this->verify_noempty('email')))
145 if (!$this->registry
->funct
->is_valid_email($this->values
['email']))
147 return _('The specified email is invalid.');
149 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
)))
151 return _('The specified email is already in use.');
156 // ###################################################################
158 * Verify: displayname
162 function verify_displayname()
164 if (!is_bool($ne = $this->verify_noempty('displayname')))
169 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
)))
171 return _('That display name is already in use by another user.');
176 // ###################################################################
178 * Verify: usergroupid
182 function verify_usergroupid()
184 if (!isset($this->registry
->datastore
['usergroup'][ $this->values
['usergroupid'] ]))
191 // ###################################################################
197 function pre_update()
199 $this->set_condition();
202 if ($this->values
['password'] == '')
204 $this->set('password', $this->objdata
['password']);
208 $this->registry
->debug("updating password = true");
209 $this->set('password', md5(md5($this->values
['password']) . md5($this->objdata
['salt'])));
213 // ###################################################################
219 function post_update()
221 $username = $this->registry
->escape($this->values
['displayname']);
222 $id = $this->values
['userid'];
224 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET username = '$username' WHERE userid = $id");
225 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET lastpostbyname = '$username' WHERE lastpostby = $id");
226 $this->registry
->db
->query("UPDATE " . TABLE_PREFIX
. "bug SET hiddenlastpostbyname = '$username' WHERE hiddenlastpostby = $id");
231 // ###################################################################
237 function pre_delete()
239 if ($this->values
['userid'] == $this->registry
->userinfo
['userid'])
241 $this->error(_('You cannot delete your own account!'));
244 if ($this->values
['usergroupid'] == 6)
246 $count = $this->registry
->db
->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> " . $this->values
['userid']);
247 if ($count['count'] < 1)
249 $this->error(_('At least one other administrator needs to be present before you can delete this user'));
254 // ###################################################################
260 function post_delete()
262 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = " . $this->values
['userid']);
263 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "favorite WHERE userid = " . $this->values
['userid']);
264 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = " . $this->values
['userid']);
265 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $this->values
['userid']);
266 $this->registry
->db
->query("DELETE FROM " . TABLE_PREFIX
. "search WHERE userid = " . $this->values
['userid']);
271 // ###################################################################
273 * Verify: hidestatuses
277 function verify_hidestatuses()
279 if (is_array($this->values
['hidestatuses']))
281 $this->set('hidestatuses', implode(',', $this->values
['hidestatuses']));
287 // ###################################################################
289 * Verify: defaultsortkey
293 function verify_defaultsortkey()
295 if (!ListSorter
::fetch_by_text($this->values
['defaultsortkey']))
303 // ###################################################################
305 * Verify: defaultsortas
309 function verify_defaultsortas()
311 if (!ListSorter
::fetch_as_text($this->values
['defaultsortas']))
319 // ###################################################################
321 * Verify: columnoptions
325 function verify_columnoptions()
327 if (is_array($this->values
['columnoptions']))
329 $this->set('columnoptions', serialize($this->values
['columnoptions']));
335 /*=====================================================================*\
336 || ###################################################################
339 || ###################################################################
340 \*=====================================================================*/