C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\xoops\html\kernel\user.php


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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
<?php
// $Id: user.php,v 1.11.6.22.2.4 2005/09/28 19:16:22 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
    exit();
}
/**
 * Class for users
 * @author Kazumi Ono <onokazu@xoops.org>
 * @copyright copyright (c) 2000-2003 XOOPS.org
 * @package kernel
 */
class XoopsUser extends XoopsObject
{

    
/**
     * Array of groups that user belongs to
     * @var array
     * @access private
     */
    
var $_groups = array();
    
/**
     * @var bool is the user admin?
     * @access private
     */
    
var $_isAdmin null;
    
/**
     * @var string user's rank
     * @access private
     */
    
var $_rank null;
    
/**
     * @var bool is the user online?
     * @access private
     */
    
var $_isOnline null;

    
/**
    * @var object reference to a {@link XoopsProfile} object
    * @access private
    */
    
var $_profile;

    
/**
     * constructor
     * @param array $id Array of key-value-pairs to be assigned to the user. (for backward compatibility only)
     * @param int $id ID of the user to be loaded from the database.
     */
    
function XoopsUser($id null)
    {
        
$this->initVar('uid'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('loginname'XOBJ_DTYPE_TXTBOXnulltrue25);
        
$this->initVar('uname'XOBJ_DTYPE_TXTBOXnulltrue55);
        
$this->initVar('name'XOBJ_DTYPE_TXTBOX""false75);
        
$this->initVar('email'XOBJ_DTYPE_TXTBOXnulltrue60);
        
$this->initVar('pass'XOBJ_DTYPE_TXTBOXnullfalse32);
        
$this->initVar('rank'XOBJ_DTYPE_INT0false);
        
$this->initVar('level'XOBJ_DTYPE_INT0false);
        
$this->initVar('user_avatar'XOBJ_DTYPE_TXTBOX"blank.gif"false30);
        
// for backward compatibility
        
if (!is_null($id)) {
            if (
is_array($id)) {
                
$this->assignVars($id);
            } else {
                
$member_handler =& xoops_gethandler('member');
                
$user =& $member_handler->getUser($id);
                foreach (
$user->vars as $k => $v) {
                    
$this->assignVar($k$v['value']);
                }
                
$this->_profile =& $user->getProfile();
            }
        }
        else {
            
$profile_handler =& xoops_gethandler('profile');
            
$this->_profile =& $profile_handler->create();
            
$this->_profile->setNew();
            
$this->_profile->init($profile_handler->loadFields());
        }
    }

    
/**
    * Assign values to attributes
    *
    * @param array $vars key => value pair array of values
    *
    * @return void
    **/
    
function assignVars($vars) {
        
$uservars array_keys($this->getVars());
        foreach (
$vars as $key => $value) {
            if (
in_array($key$uservars)) {
                
$this->assignVar($key$value);
            }
            
/*
            * Dynamic user profiles - Mith
            */
            
else {
                
$this->_profile->assignVar($key$value);
            }
            
/*
            * Dynamic user profiles end
            */
        
}
    }

    
/**
    * Get user profile
    *
    * @return object
    */
    
function getProfile() {
        return 
$this->_profile;
    }

    
/**
    * returns a specific variable for the object in a proper format
    *
    * @access public
    * @param string $key key of the object's variable to be returned
    * @param string $format format to use for the output
    * @return mixed formatted value of the variable
    */
    
function getVar($key$format "s") {
        
$uservars array_keys($this->getVars());
        if (!
in_array($key$uservars)) {
            return 
$this->_profile->getVar($key$format);
        }
        return 
parent::getVar($key$format);
    }

    
/**
    * assign a value to a variable
    *
    * @access public
    * @param string $key name of the variable to assign
    * @param mixed $value value to assign
    * @param bool $not_gpc
    */
    
function setVar($key$value$not_gpc false) {
        
$uservars array_keys($this->getVars());
        if (!
in_array($key$uservars)) {
            return 
$this->_profile->setVar($key$value$not_gpc);
        }
        return 
parent::setVar($key$value$not_gpc);
    }


    
/**
     * check if the user is a guest user
     *
     * @return bool returns false
     *
     */
    
function isGuest()
    {
        return 
false;
    }


    
/**
     * Updated by Catzwolf 11 Jan 2004
     * find the username for a given ID
     *
     * @param int $userid ID of the user to find
     * @param int $usereal switch for usename or realname
     * @return string name of the user. name for "anonymous" if not found.
     */
    
function getUnameFromId$userid$usereal )
    {
        
$userid intval($userid);
        
$usereal intval($usereal);
        if (
$userid 0) {
            
$member_handler =& xoops_gethandler('member');
            
$user =& $member_handler->getUser($userid);
            if (
is_object($user)) {
                
$ts =& MyTextSanitizer::getInstance();
                if ( 
$usereal ) {
                    return 
$ts->htmlSpecialChars($user->getVar('name'));
                } else {
                    return 
$ts->htmlSpecialChars($user->getVar('uname'));
                }
            }
        }
        return 
$GLOBALS['xoopsConfig']['anonymous'];
    }
    
/**
     * increase the number of posts for the user
     *
     * @deprecated
     */
    
function incrementPost(){
        
$member_handler =& xoops_gethandler('member');
        return 
$member_handler->updateUserByField($this'posts'$this->getVar('posts') + 1);
    }
    
/**
     * set the groups for the user
     *
     * @param array $groupsArr Array of groups that user belongs to
     */
    
function setGroups($groupsArr)
    {
        if (
is_array($groupsArr)) {
            
$this->_groups =& $groupsArr;
        }
    }
    
/**
     * get the groups that the user belongs to
     *
     * @return array array of groups
     */
    
function &getGroups()
    {
        if (empty(
$this->_groups)) {
            
$member_handler =& xoops_gethandler('member');
            
$this->_groups $member_handler->getGroupsByUser($this->getVar('uid'));
        }
        return 
$this->_groups;
    }
    
/**
     * alias for {@link getGroups()}
     * @see getGroups()
     * @return array array of groups
     * @deprecated
     */
    
function &groups()
    {
        
$return =& $this->getGroups();
        return 
$return;
    }
    
/**
     * Is the user admin ?
     *
     * This method will return true if this user has admin rights for the specified module.<br />
     * - If you don't specify any module ID, the current module will be checked.<br />
     * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module
     *
     * @param int $module_id check if user is admin of this module
     * @return bool is the user admin of that module?
     */
    
function isAdmin$module_id null ) {
        if ( 
is_null$module_id ) ) {
            
$module_id = isset($GLOBALS['xoopsModule']) ? $GLOBALS['xoopsModule']->getVar'mid''n' ) : 1;
        } elseif ( 
intval($module_id) < ) {
            
$module_id 0;
        }
        if (
is_null($this->_isAdmin) || !isset($this->_isAdmin[$module_id])) {
            
$moduleperm_handler =& xoops_gethandler('groupperm');
            
$groups $this->getGroups();
            if (
count($groups) > ) {
                
$this->_isAdmin[$module_id] = $moduleperm_handler->checkRight('module_admin'$module_id$groups);
            }
        }
        return 
$this->_isAdmin[$module_id];
    }
    
/**
     * get the user's rank
     * @return array array of rank ID and title
     */
    
function rank()
    {
        if (!isset(
$this->_rank)) {
            
$this->_rank xoops_getrank($this->getVar('rank'), $this->getVar('posts'));
        }
        return 
$this->_rank;
    }
    
/**
     * is the user activated?
     * @return bool
     */
    
function isActive()
    {
        return (
$this->getVar('level') > 0);
    }

    
/**
     * is the user disabled?
     * @return bool
     */
    
function isDisabled()
    {
        return (
$this->getVar('level') == -1);
    }

    
/**
     * is the user currently logged in?
     * @return bool
     */
    
function isOnline()
    {
        if (!isset(
$this->_isOnline)) {
            
$onlinehandler =& xoops_gethandler('online');
            
$this->_isOnline = ($onlinehandler->getCount(new Criteria('online_uid'$this->getVar('uid'))) > 0) ? true false;
        }
        return 
$this->_isOnline;
    }
    
/**#@+
    * specialized wrapper for {@link XoopsObject::getVar()}
    *
    * kept for compatibility reasons.
    *
    * @see XoopsObject::getVar()
    * @deprecated
    */
    /**
     * get the users UID
     * @return int
     */
    
function uid()
    {
        return 
$this->getVar("uid");
    }

    
/**
     * get the users name
     * @param string $format format for the output, see {@link XoopsObject::getVar()}
     * @return string
     */
    
function name($format="S")
    {
        return 
$this->getVar("name"$format);
    }

    
/**
     * get the user's uname
     * @param string $format format for the output, see {@link XoopsObject::getVar()}
     * @return string
     */
    
function uname($format="S")
    {
        return 
$this->getVar("uname"$format);
    }

    
/**
     * get the user's email
     *
     * @param string $format format for the output, see {@link XoopsObject::getVar()}
     * @return string
     */
    
function email($format="S")
    {
        return 
$this->getVar("email"$format);
    }

    function 
url($format="S")
    {
        return 
$this->getVar("url"$format);
    }

    function 
user_avatar($format="S")
    {
        return 
$this->getVar("user_avatar");
    }

    function 
user_regdate()
    {
        return 
$this->getVar("user_regdate");
    }

    function 
user_icq($format="S")
    {
        return 
$this->getVar("user_icq"$format);
    }

    function 
user_from($format="S")
    {
        return 
$this->getVar("user_from"$format);
    }
    function 
user_sig($format="S")
    {
        return 
$this->getVar("user_sig"$format);
    }

    function 
user_viewemail()
    {
        return 
$this->getVar("user_viewemail");
    }

    function 
actkey()
    {
        return 
$this->getVar("actkey");
    }

    function 
user_aim($format="S")
    {
        return 
$this->getVar("user_aim"$format);
    }

    function 
user_yim($format="S")
    {
        return 
$this->getVar("user_yim"$format);
    }

    function 
user_msnm($format="S")
    {
        return 
$this->getVar("user_msnm"$format);
    }

    function 
pass()
    {
        return 
$this->getVar("pass");
    }

    function 
posts()
    {
        return 
$this->getVar("posts");
    }

    function 
attachsig()
    {
        return 
$this->getVar("attachsig");
    }

    function 
level()
    {
        return 
$this->getVar("level");
    }

    function 
theme()
    {
        return 
$this->getVar("theme");
    }

    function 
timezone()
    {
        return 
$this->getVar("timezone_offset");
    }

    function 
umode()
    {
        return 
$this->getVar("umode");
    }

    function 
uorder()
    {
        return 
$this->getVar("uorder");
    }

    
// RMV-NOTIFY
    
function notify_method()
    {
        return 
$this->getVar("notify_method");
    }

    function 
notify_mode()
    {
        return 
$this->getVar("notify_mode");
    }

    function 
user_occ($format="S")
    {
        return 
$this->getVar("user_occ"$format);
    }

    function 
bio($format="S")
    {
        return 
$this->getVar("bio"$format);
    }

    function 
user_intrest($format="S")
    {
        return 
$this->getVar("user_intrest"$format);
    }

    function 
last_login()
    {
        return 
$this->getVar("last_login");
    }
    
/**#@-*/
}

/**
 * Class that represents a guest user
 * @author Kazumi Ono <onokazu@xoops.org>
 * @copyright copyright (c) 2000-2003 XOOPS.org
 * @package kernel
 */
class XoopsGuestUser extends XoopsUser
{
    
/**
     * check if the user is a guest user
     *
     * @return bool returns true
     *
     */
    
function isGuest()
    {
        return 
true;
    }
}


/**
* XOOPS user handler class.
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS user class objects.
*
* @author  Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
* @package kernel
*/
class XoopsUserHandler extends XoopsPersistableObjectHandler
{
    
/**
    * Reference to the {@link XoopsProfileHandler} instance
    */
    
var $_pHandler;
    
/**
    * Constructor
    **/
    
function XoopsUserHandler(&$db) {
        
$this->XoopsPersistableObjectHandler($db'users''XoopsUser''uid''uname');
        
$this->_pHandler =& xoops_gethandler('profile');
    }

    
/**
     * insert a new user in the database
     *
     * @param object $user reference to the {@link XoopsUser} object
     * @param bool $force
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
     */
    
function insert(&$user$force false)
    {
        if (!
parent::insert($user$force)) {
            return 
false;
        }
        
$profile $user->getProfile();
        
$profile->setVar('profileid'$user->getVar('uid'));

        
// save profile
        
if (!$this->_pHandler->insert($profile$force)) {
            foreach (
$profile->getErrors() as $error) {
                
$user->setErrors($error);
            }
            return 
false;
        }
        return 
true;
    }

    
/**
     * delete a user from the database
     *
     * @param object $user reference to the user to delete
     * @param bool $force
     * @return bool FALSE if failed.
     */
    
function delete(&$user$force false)
    {

        if (!
parent::delete($user$force)) {
            return 
false;
        }
        
// delete user profile
        
$profile =& $user->getProfile();
        return 
$this->_pHandler->delete($profile$force);
    }

    
/**
     * retrieve users from the database
     *
     * @param object $criteria {@link CriteriaElement} conditions to be met
     * @param bool $id_as_key use the UID as key for the array?
     * @param bool $as_object return array of objects or array of arrays?
     * @return array array of {@link XoopsUser} objects
     */
    
function getObjects($criteria null$id_as_key false$as_object true)
    {
        if (
is_null($criteria)) {
            
$criteria = new Criteria('uid'0'!=');
        }
        
$ret = array();
        
$limit $start 0;
        
$sql 'SELECT * FROM '.$this->db->prefix('users').' u, '.$this->_pHandler->table.' p WHERE u.'.$this->keyName.' = p.'.$this->_pHandler->keyName;
        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {
            
$clause $criteria->render();
            if (
$clause != "") {
                
$sql .= ' AND '.$clause;
            }
            if (
$criteria->getSort() != '') {
                
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
            }
            
$limit $criteria->getLimit();
            
$start $criteria->getStart();
        }
        
$result $this->db->query($sql$limit$start);
        if (!
$result) {
            return 
$ret;
        }
        return 
$this->convertResultSet($result$id_as_key$as_object);
    }

    
/**
     * Convert a database resultset to a returnable array
     *
     * @param object $result database resultset
     * @param bool $id_as_key
     * @param bool $as_object
     *
     * @return array
     */
    
function convertResultSet($result$id_as_key false$as_object true) {
        
$ret = array();
        
$fields $this->_pHandler->loadFields();
        while (
$myrow $this->db->fetchArray($result)) {
            
$obj =& $this->create(false);
            
$obj->_profile =& $this->_pHandler->create(false);
            
$obj->_profile->init($fields);
            
$obj->assignVars($myrow);
            if (!
$id_as_key) {
                if (
$as_object) {
                    
$ret[] =& $obj;
                }
                else {
                    
$ret[] = $obj->toArray();
                }
            } else {
                if (
$as_object) {
                    
$ret[$myrow[$this->keyName]] =& $obj;
                }
                else {
                    
$ret[$myrow[$this->keyName]] = $obj->toArray();
                }
            }
            unset(
$obj);
        }

        return 
$ret;
    }

    
/**
     * count users matching a condition
     *
     * @param object $criteria {@link CriteriaElement} to match
     * @return int count of users
     */
    
function getCount($criteria null)
    {
        
$profile_handler =& xoops_gethandler('profile');
        
$sql 'SELECT COUNT(*) FROM '.$this->table.' u, '.$profile_handler->table.' p WHERE u.'.$this->keyName.' = p.'.$this->_pHandler->keyName;
        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {
            
$clause $criteria->render();
            if (
$clause != "") {
                
$sql .= ' AND '.$clause;
            }
        }
        
$result $this->db->query($sql);
        if (!
$result) {
            return 
0;
        }
        list(
$count) = $this->db->fetchRow($result);
        return 
$count;
    }

    
/**
     * get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @return array associative array of user-IDs and names
     */
    
function getList($criteria null$limit 0$start 0) {
        
$ret = array();
        
$profile_handler =& xoops_gethandler('profile');
        
$sql 'SELECT '.$this->keyName.', '.$this->identifierName.' FROM '.$this->table.' u, '.$profile_handler->table.' p WHERE u.'.$this->keyName.' = p.'.$this->_pHandler->keyName;
        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {
            
$clause $criteria->render();
            if (
$clause != "") {
                
$sql .= ' AND '.$clause;
            }
            if (
$criteria->getSort() != '') {
                
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
            }
            else {
                
$sql .= ' ORDER BY '.$this->identifierName;
            }
            
$limit $criteria->getLimit();
            
$start $criteria->getStart();
        }
        
$result $this->db->query($sql$limit$start);
        if (!
$result) {
            return 
$ret;
        }

        
$myts =& MyTextSanitizer::getInstance();
        while (
$myrow $this->db->fetchArray($result)) {
            
//identifiers should be textboxes, so sanitize them like that
            
$ret[$myrow[$this->keyName]] = $myts->htmlSpecialChars($myrow[$this->identifierName]);
        }
        return 
$ret;
    }

    
/**
     * delete users matching a set of conditions
     *
     * @param object $criteria {@link CriteriaElement}
     * @return bool FALSE if deletion failed
     */
    
function deleteAll($criteria null)
    {
        
$users $this->getList($criteria);
        
$newcriteria = new Criteria('uid'"(".implode(','array_keys($users)).")""IN");
        if (
parent::deleteAll($newcriteria)) {
            unset(
$newcriteria);
            
$newcriteria = new Criteria('profileid'"(".implode(','array_keys($users)).")""IN");
            return 
$this->_pHandler->deleteAll($newcriteria);
        }
        return 
false;
    }

    
/**
     * Change a value for users with a certain criteria
     *
     * @param   string  $fieldname  Name of the field
     * @param   string  $fieldvalue Value to write
     * @param   object  $criteria   {@link CriteriaElement}
     *
     * @return  bool
     **/
    
function updateAll($fieldname$fieldvalue$criteria null)
    {
        
$profile_fields array_keys($this->_pHandler->loadFields());
        if (!
in_array($fieldname$profile_fields)) {
            return 
parent::updateAll($fieldname$fieldvalue$criteria);
        }
        else {
            return 
$this->_pHandler->updateAll($fieldname$fieldvalue$criteria);
        }
    }

    
/**
     * log in a user - we need this instead of getObjects since the profile table may not be there, in the case of upgrading
     *
     * @param string $uname username as entered in the login form
     * @param string $pwd password entered in the login form
     * @param bool $md5 whether the password is already md5'ed
     *
     * @return object XoopsUser reference to the logged in user. FALSE if failed to log in
     */
    
function &loginUser($uname$pwd$md5 false) {
        if (!
$md5) {
            
$pwd md5($pwd);
        }
        
$criteria = new CriteriaCompo(new Criteria('loginname'$uname));
        
$criteria->add(new Criteria('pass'$pwd));

        
//First try with profile
        
$user $this->getObjects($criteria);
        if (
$user != array() && is_object($user[0]) ) {
            return 
$user[0];
        }
        
//But profile will not work, when you are upgrading from XOOPS 2.0.x
        //so we need to have this extra stuff or an admin would not be able to
        //log in to upgrade the system.
        //It will add another query to wrong logins, but that's not a big problem
        
$sql "SELECT * FROM ".$this->table;
        
$sql .= " ".$criteria->renderWhere();
        
$result $this->db->query($sql);
        
$user $this->convertResultSet($resultfalse);
        if (!
$user || count($user) != 1) {
            
$return false;
            return 
$return;
        }
        return 
$user[0];
    }

    
/**
    * Update a user by field
    *
    * @param    string  $fieldName  name of field to change
    * @param    mixed   $fieldValue Value to set field to
    * @param    int     $uid        ID of user to modify
    *
    * @return   bool
    */
    
function updateUserByField($fieldName$fieldValue$uid) {
        
$fields $this->_pHandler->loadFields();
        if (
in_array($fieldNamearray_keys($fields))) {
            
$keyName 'profileid';
        }
        else {
            
$keyName 'uid';
        }
        
$criteria = new Criteria($keyName$uid);
        return 
$this->updateAll($fieldName$fieldValue$criteria);
    }
}
?>