Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezuser.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezuser.php 9798 2003-04-09 13:09:07Z jhe $
5 //
6 // Definition of eZUser class
7 //
8 // Created on: <26-Sep-2000 18:47:27 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
67 // include_once( "classes/ezdb.php" );
68
69 // include_once( "ezaddress/classes/ezaddress.php" );
70 // include_once( "classes/ezdatetime.php" );
71
72 // include_once( "ezsession/classes/ezsession.php" );
73 // include_once( "ezuser/classes/ezusergroup.php" );
74
75 class eZUser
76 {
83 function __construct( $id=-1 )
84 {
85 $this->InfoSubscription = 0;
86 $this->SimultaneousLogins = 0;
87 $this->GroupString = false;
88 $this->AccountNumber = 0;
89 $this->HasRoot = -1;
90
91 if ( is_array( $id ) )
92 {
93 $this->fill( $id );
94 }
95 else if ( $id != -1 )
96 {
97 $this->ID = $id;
98 $this->get( $this->ID );
99 }
100 }
101
105 function store()
106 {
107 $db =& eZDB::globalDatabase();
108
109 $dbError = false;
110 $db->begin( );
111
112 $email = $db->escapeString( $this->Email );
113 $firstname = $db->escapeString( $this->FirstName );
114 $lastname = $db->escapeString( $this->LastName );
115 $signature = $db->escapeString( $this->Signature );
116 $login = $db->escapeString( $this->Login );
117 $account_number = $db->escapeString( $this->AccountNumber );
118
119 if ( !isset( $this->ID ) )
120 {
121 $db->lock( "eZUser_User" );
122
123 $nextID = $db->nextID( "eZUser_User", "ID" );
124
125 // backwards compatible passwords
126 if ( $db->isA() == "mysql" )
127 {
128 $db->query( "INSERT INTO eZUser_User SET
129 ID='$nextID',
130 Login='$login',
131 Password=PASSWORD('$this->Password'),
132 Email='$email',
133 InfoSubscription='$this->InfoSubscription',
134 FirstName='$firstname',
135 LastName='$lastname',
136 Signature='$signature',
137 CookieLogin='$this->CookieLogin',
138 AccountNumber='$account_number',
139 SimultaneousLogins='$this->SimultaneousLogins'" );
140 $this->ID = $nextID;
141 }
142 elseif ( $db->isA() == "sqlite" )
143 {
144 // Calculate MySQL-style hash in PHP so SQLite can just compare strings
145 $hash = '*' . strtoupper( sha1( hex2bin( sha1( $password ) ) ) );
146
147 $db->query( "INSERT INTO eZUser_User
148 ( ID, Login, Password, Email, InfoSubscription, FirstName, LastName, Signature, CookieLogin, AccountNumber,SimultaneousLogins )
149 VALUES
150 ( '$nextID',
151 '$login',
152 '$hash',
153 '$email',
154 '$this->InfoSubscription',
155 '$firstname',
156 '$lastname',
157 '$signature',
158 '$this->CookieLogin',
159 '$account_number',
160 '$this->SimultaneousLogins')" );
161
162 $this->ID = $nextID;
163 }
164 else
165 {
166 $password = md5( $this->Password );
167
168 $db->query( "INSERT INTO eZUser_User
169 ( ID, Login, Password, Email, InfoSubscription, FirstName, LastName, Signature, CookieLogin, AccountNumber,SimultaneousLogins )
170 VALUES
171 ( '$nextID',
172 '$login',
173 '$password',
174 '$email',
175 '$this->InfoSubscription',
176 '$firstname',
177 '$lastname',
178 '$signature',
179 '$this->CookieLogin',
180 '$account_number',
181 '$this->SimultaneousLogins')" );
182
183 $this->ID = $nextID;
184 }
185
186 }
187 else
188 {
189 $db->query( "UPDATE eZUser_User SET
190 Login='$login',
191 Email='$email',
192 InfoSubscription='$this->InfoSubscription',
193 FirstName='$firstname',
194 Signature='$signature',
195 LastName='$lastname',
196 CookieLogin='$this->CookieLogin',
197 AccountNumber='$account_number',
198 SimultaneousLogins='$this->SimultaneousLogins'
199 WHERE ID='$this->ID'" );
200
201 // update password if set.
202 if ( isset( $this->Password ) )
203 {
204 // backwards compatible passwords
205 if ( $db->isA() == "mysql" )
206 {
207 $db->query( "UPDATE eZUser_User SET
208 Password=PASSWORD('$this->Password')
209 WHERE ID='$this->ID'" );
210 }
211 // backwards compatible passwords
212 if ( $db->isA() == "sqlite" )
213 {
214 // Calculate MySQL-style hash in PHP so SQLite can just compare strings
215 $hash = '*' . strtoupper( sha1( hex2bin( sha1( $this->Password ) ) ) );
216 $db->query( "UPDATE eZUser_User SET
217 Password='$hash'
218 WHERE ID='$this->ID'" );
219 }
220 else
221 {
222 $password = md5( $this->Password );
223
224 $db->query( "UPDATE eZUser_User SET
225 Password='$password'
226 WHERE ID='$this->ID'" );
227 }
228 }
229 }
230
231 $db->unlock();
232
233 if ( $dbError == true )
234 $db->rollback( );
235 else
236 $db->commit();
237
238 return true;
239 }
240
245 function delete()
246 {
247 $db =& eZDB::globalDatabase();
248
249 if ( isset( $this->ID ) )
250 {
251 $db->query( "DELETE FROM eZUser_UserGroupLink WHERE UserID='$this->ID'" );
252 $db->query( "DELETE FROM eZUser_UserAddressLink WHERE UserID='$this->ID'" );
253 $db->query( "DELETE FROM eZUser_UserShippingLink WHERE UserID='$this->ID'" );
254
255 $db->query( "DELETE FROM eZUser_User WHERE ID='$this->ID'" );
256 }
257
258 return true;
259 }
260
266 function get( $id=-1 )
267 {
268 $db =& eZDB::globalDatabase();
269
270 $ret = false;
271 if ( $id != "" )
272 {
273 $db->array_query( $user_array, "SELECT * FROM eZUser_User WHERE ID='$id'", 0, 1 );
274
275 if ( count( $user_array ) == 1 )
276 {
277 $this->fill( $user_array[0] );
278 $ret = true;
279 }
280 elseif ( count( $user_array ) == 1 )
281 {
282 $this->ID = 0;
283 }
284 }
285 return $ret;
286 }
287
291 function fill( &$user_array )
292 {
293 $db =& eZDB::globalDatabase();
294
295 $this->ID =& $user_array[$db->fieldName("ID")];
296 $this->Login =& $user_array[$db->fieldName("Login")];
297 $this->Email =& $user_array[$db->fieldName("Email")];
298 $this->InfoSubscription =& $user_array[$db->fieldName("InfoSubscription")];
299 $this->FirstName =& $user_array[$db->fieldName("FirstName")];
300 $this->LastName =& $user_array[$db->fieldName("LastName")];
301 $this->Signature =& $user_array[$db->fieldName("Signature")];
302 $this->CookieLogin =& $user_array[$db->fieldName("CookieLogin")];
303 if ( $user_array[$db->fieldName("AccountNumber")] != NULL )
304 $this->AccountNumber =& $user_array[$db->fieldName("AccountNumber")];
305 $this->SimultaneousLogins =& $user_array[$db->fieldName("SimultaneousLogins")];
306 }
307
311 static public function &getAllCount( $search = false )
312 {
313 $db =& eZDB::globalDatabase();
314
315 $query = new eZQuery( array( "FirstName", "LastName",
316 "Login", "Email" ), $search );
317
318 if ( $search != false )
319 $db->query_single( $user_array, "SELECT count( ID ) AS Count FROM eZUser_User
320 WHERE " . $query->buildQuery() );
321 else
322 $db->query_single( $user_array, "SELECT count( ID ) AS Count FROM eZUser_User" );
323
324 return $user_array[$db->fieldName("Count")];
325 }
326
330 static public function &getAll( $order="Login", $as_object = true, $search = false, $max = -1, $index = 0 )
331 {
332 $db =& eZDB::globalDatabase();
333
334 switch ( $order )
335 {
336 case "name" :
337 {
338 $orderBy = "LastName, FirstName";
339 }
340 break;
341
342 case "lastname" :
343 {
344 $orderBy = "LastName";
345 }
346 break;
347
348 case "firstname" :
349 {
350 $orderBy = "FirstName";
351 }
352 break;
353
354 case "lastname" :
355 {
356 $orderBy = "LastName";
357 }
358 break;
359
360 case "email" :
361 {
362 $orderBy = "Email";
363 }
364 break;
365
366 default :
367 $orderBy = "Login";
368 break;
369 }
370
371 $return_array = array();
372 $user_array = array();
373
374 if ( $as_object )
375 $select = "*";
376 else
377 $select = "ID";
378
379 if ( $search )
380 {
381 $db->array_query( $user_array, "SELECT $select FROM eZUser_User
382 WHERE FirstName LIKE '%$search%' OR
383 LastName LIKE '%$search%' OR
384 Login LIKE '%$search%' OR
385 Email LIKE '%$search%'
386 ORDER By $orderBy",
387 array( "Limit" => $max,
388 "Offset" => $index ) );
389 }
390 else
391 {
392 $db->array_query( $user_array, "SELECT $select FROM eZUser_User
393 ORDER By $orderBy",
394 array( "Limit" => $max,
395 "Offset" => $index ) );
396 }
397
398 if ( $as_object )
399 {
400 foreach ( $user_array as $user )
401 {
402 $return_array[] = new eZUser( $user );
403 }
404 }
405 else
406 {
407 foreach ( $user_array as $user )
408 {
409 $return_array[] = $user[ $db->fieldName( "ID" ) ];
410 }
411 }
412 return $return_array;
413 }
414
420 static public function getUser( $login )
421 {
422 $db =& eZDB::globalDatabase();
423 $ret = false;
424
425 $db->array_query( $user_array, "SELECT * FROM eZUser_User
426 WHERE Login='$login'" );
427 if ( count( $user_array ) == 1 )
428 {
429 $ret = new eZUser( $user_array[0][$db->fieldName("ID")] );
430 }
431 return $ret;
432 }
438 function getUserByEmail( $email )
439 {
440 $db =& eZDB::globalDatabase();
441 $return = false;
442
443 $db->array_query( $user_array, "SELECT * FROM eZUser_User
444 WHERE Email='$email'" );
445
446 // how to limit multiple accounts with same email and different pw / user?
447 // ideas: sql limit, if limit?,
448
449 if ( count( $user_array ) == 1 )
450 {
451 $return = new eZUser( $user_array[0][$db->fieldName("ID")] );
452 }
453 return $return;
454 }
455
456
462 function getUsersByEmail( $email , $as_object = true )
463 {
464 $db =& eZDB::globalDatabase();
465 $return = false;
466
467 $return_array = array();
468 $user_array = array();
469
470 $db->array_query( $user_array, "SELECT * FROM eZUser_User
471 WHERE Email='$email'" );
472
473 // how to limit multiple accounts with same email and different pw / user?
474 // ideas: sql limit, if limit?,
475
476 if ( $as_object )
477 {
478 foreach ( $user_array as $user )
479 {
480 $return_array[] = new eZUser( $user );
481 }
482 }
483 else
484 {
485 foreach ( $user_array as $user )
486 {
487 $return_array[] = $user[ $db->fieldName( "ID" ) ];
488 }
489 }
490 return $return_array;
491
492
493 // if ( count( $user_array ) == 1 )
494 // {
495 // $return = new eZUser( $user_array[0][$db->fieldName("ID")] );
496 // }
497 //return $return;
498 }
499
505 function validateUser( $login, $password )
506 {
507 $db =& eZDB::globalDatabase();
508 $ret = false;
509 $user_array = array();
510
511 $login = $db->escapeString( $login );
512 $password = $db->escapeString( $password );
513
514
515 if ( $db->isA() == "mysql" )
516 {
517 $sqlQuery = "SELECT * FROM eZUser_User
518 WHERE Login='$login'
519 AND Password=CONCAT('*', UPPER(SHA1(UNHEX(SHA1('$password')))));";
520 $db->array_query( $user_array, $sqlQuery );
521 }
522 elseif ( $db->isA() == "sqlite" )
523 {
524 // Calculate MySQL-style hash in PHP so SQLite can just compare strings
525 $hash = '*' . strtoupper( sha1( hex2bin( sha1( $password ) ) ) );
526
527 $sqlQuery = "SELECT *
528 FROM eZUser_User
529 WHERE Login='$login'
530 AND Password = '$hash'";
531 $db->array_query( $user_array, $sqlQuery );
532 }
533 else
534 {
535 $password = md5( $password );
536
537 $db->array_query( $user_array, "SELECT * FROM eZUser_User
538 WHERE Login='$login'
539 AND Password='$password'" );
540 }
541
542 if ( count( $user_array ) == 1 )
543 {
544 $ret = new eZUser( $user_array[0][$db->fieldName("ID")] );
545 $GLOBALS["eZCurrentUserObject"] =& $ret;
546 }
547 return $ret;
548 }
549
556 static public function exists( $login )
557 {
558 $db =& eZDB::globalDatabase();
559 $ret = false;
560 $user_array = array();
561
562 $db->array_query( $user_array, "SELECT * FROM eZUser_User
563 WHERE Login='$login'" );
564
565 if ( count( $user_array ) == 1 )
566 {
567 $ret = new eZUser( $user_array[0][$db->fieldName("ID")] );
568 }
569
570 return $ret;
571 }
572
576 function id()
577 {
578 if ( isset( $this->ID ) )
579 return $this->ID;
580 }
581
585 function signature()
586 {
587 return $this->Signature;
588 }
589
593 function login( $html = true )
594 {
595 if ( $this->Login != null && $html )
596 return htmlspecialchars( $this->Login );
597 else
598 return $this->Login;
599 }
600
601
605 function infoSubscription()
606 {
607 $ret = false;
608
609 if ( $this->InfoSubscription == 1 )
610 {
611 $ret = true;
612 }
613 return $ret;
614 }
615
616
620 function email()
621 {
622 return $this->Email;
623 }
624
628 function namedEmail()
629 {
630 return $this->name() . " <" . $this->email() . ">";
631 }
632
636 function accountNumber()
637 {
638 return $this->AccountNumber;
639 }
643 function name()
644 {
645 return $this->firstName() . " " . $this->lastName();
646 }
647
651 function firstName( $html = true )
652 {
653 if ( isset( $this->FirstName ) && $html )
654 return htmlspecialchars( $this->FirstName );
655 else
656 return $this->FirstName;
657 }
658
662 function lastName( $html = true )
663 {
664 if ( isset( $this->LastName ) && $html )
665 return htmlspecialchars( $this->LastName );
666 else
667 return $this->LastName;
668 }
669
673 function cookieLogin()
674 {
675 $ret = false;
676 if ( $this->CookieLogin == 1 )
677 $ret = true;
678 return $ret;
679 }
680
681
685 function simultaneousLogins()
686 {
687 return htmlspecialchars( $this->SimultaneousLogins );
688 }
689
693 function setSignature( $value )
694 {
695 $this->Signature = $value;
696 }
697
701 function setLogin( $value )
702 {
703 $this->Login = $value;
704 }
705
706
710 function setPassword( $value )
711 {
712 $this->Password = $value;
713 }
714
718 function setEmail( $value )
719 {
720 $this->Email = $value;
721 }
722
729 function setInfoSubscription( $value )
730 {
731 if ( $value == true )
732 {
733 $this->InfoSubscription = 1;
734 }
735 else
736 {
737 $this->InfoSubscription = 0;
738 }
739 }
740
744 function setAccountNumber( $value )
745 {
746 $this->AccountNumber = $value;
747 }
751 function setFirstName( $value )
752 {
753 $this->FirstName = $value;
754 }
755
759 function setLastName( $value )
760 {
761 $this->LastName = $value;
762 }
763
767 function setSimultaneousLogins ( $value )
768 {
769 $this->SimultaneousLogins = $value;
770
771 setType( $this->SimultaneousLogins, "integer" );
772 }
773
777 function setCookieLogin ( $value )
778 {
779 if ( $value == true )
780 $this->CookieLogin = 1;
781 else
782 $this->CookieLogin = 0;
783 }
784
785 function setGroupDefinition( $group )
786 {
787 if ( is_a( $group, "eZUserGroup" ) )
788 $group = $group->ID();
789
790 $db =& eZDB::globalDatabase();
791 $db->begin();
792 $res[] = $db->query( "DELETE FROM eZUser_UserGroupDefinition WHERE UserID='" . $this->ID . "'" );
793 $db->lock( "eZUser_UserGroupDefinition" );
794 $nextID = $db->nextID( "eZUser_UserGroupDefinition", "ID" );
795 $res[] = $db->query( "INSERT INTO eZUser_UserGroupDefinition
796 (ID, UserID, GroupID)
797 VALUES
798 ('$nextID', '$this->ID', '$group')" );
799 $db->unlock();
800 eZDB::finish( $res, $db );
801 }
802
809 static public function loginUser( &$user )
810 {
811 $ret = false;
812
813 if ( is_a( $user, "eZUser" ) )
814 {
815 $session =& eZSession::globalSession();
816
817 if ( !$session->fetch() )
818 {
819 $session->store();
820 }
821
822 $session->refresh();
823
824 $session->setVariable( "AuthenticatedUser", $user->id() );
825
826 $GLOBALS["eZCurrentUserObject"] =& $user;
827
828 $ret = true;
829 }
830 return $ret;
831 }
832
837 static public function autoCookieLogin( $hash )
838 {
839 $db =& eZDB::globalDatabase();
840
841 if ( $hash )
842 {
843 $db->array_query( $userArray, "SELECT UserID FROM eZUser_Cookie WHERE Hash='$hash'" );
844 if ( count ( $userArray ) == 1 )
845 {
846 $user = new eZUser( $userArray[0][$db->fieldName("UserID")] );
847 if ( $user )
848 {
849 eZUser::loginUser( $user );
850 return true;
851 }
852 }
853 }
854 return false;
855 }
856
857 static public function clearAutoCookieLogin()
858 {
859 $user =& eZUser::currentUser();
860 $db =& eZDB::globalDatabase();
861
862 setCookie( "eZUser_AutoCookieLogin", "", 0, "/", "", 0 );
863 setCookie( "eZUser_AutoCookieLogin" );
864
865 if ( $user )
866 {
867 $userID = $user->id();
868 $db->query( "DELETE FROM eZUser_Cookie WHERE UserID='$userID'" );
869 }
870 }
871
876 static public function logout()
877 {
878 $session =& eZSession::globalSession();
879 if ( $session->fetch() )
880 {
881 $session->setVariable( "AuthenticatedUser", "" );
882 }
883 }
884
885
886
896 static public function &currentUser()
897 {
898 $user =& $GLOBALS["eZCurrentUserObject"];
899
900 if ( ( is_a( $user, "eZUser" ) ) and ( is_numeric( $user->id() ) ) )
901 {
902 return $user;
903 }
904
905
906 $session =& eZSession::globalSession();
907
908 $returnValue = false;
909
910 if ( $session->fetch( false ) )
911 {
912 $user = new eZUser( $session->variable("AuthenticatedUser" ) );
913
914 // $val =& $session->variable( "AuthenticatedUser" );
915 // $user = new eZUser( $val );
916
917 // print( $session->variable( "AuthenticatedUser" ) );
918
919 $idle = $session->idle();
920 $idle = $idle / 60;
921
922 if ( ( $idle > $user->timeoutValue() ) && ( $user->timeoutValue() != 0 ) )
923 {
924 $user->logout();
925 $user = false;
926 }
927 else
928 {
929 if ( ( $user->id() != 0 ) && ( $user->id() != "" ) )
930 {
931 $session->refresh( );
932 $returnValue = $user;
933 }
934 }
935 }
936
937 return $returnValue;
938 }
939
940
946 static public function currentUsers()
947 {
948 $globalSession =& eZSession::globalSession();
949
950 $ret = array();
951
952 $sessionIDArray =& $globalSession->getByVariable( "AuthenticatedUser" );
953
954 foreach ( $sessionIDArray as $sessionID )
955 {
956 $session = new eZSession( $sessionID );
957 $user = new eZUser( $session->variable( "AuthenticatedUser" ) );
958
959 $idle = $session->idle();
960 $idle = $idle / 60;
961
962 if ( ( $idle > $user->timeoutValue() ) && ( $user->timeoutValue() != 0 ) )
963 {
964 $session->delete( );
965 }
966 else
967 {
968 if ( ( $user->id() != 0 ) && ( $user->id() != "" ) )
969 {
970 $ret[] = array( $user, $session );
971 }
972 }
973 }
974
975 return $ret;
976 }
977
981 function getLogins( $userId )
982 {
983 $userSessionList =& eZUser::currentUsers();
984 $logins = 0;
985 foreach ( $userSessionList as $userSessionItem )
986 {
987 if ( $userSessionItem[0]->id() == $userId )
988 $logins++;
989 }
990 return $logins;
991 }
992
998 function groupString()
999 {
1000 $groupStr = "";
1001 if ( $this->GroupString == false )
1002 {
1003 $groupIDArray =& $this->groups( false );
1004 sort( $groupIDArray );
1005 $first = true;
1006 foreach ( $groupIDArray as $groupID )
1007 {
1008 $first ? $groupStr .= "$groupID" : $groupStr .= "-$groupID";
1009 $first = false;
1010 }
1011 $this->GroupString = $groupStr;
1012 }
1013
1014 return $this->GroupString;
1015 }
1016
1021 function groups( $as_object = true )
1022 {
1023 $ret = array();
1024 $db =& eZDB::globalDatabase();
1025
1026 $db->array_query( $user_group_array, "SELECT * FROM eZUser_UserGroupLink
1027 WHERE UserID='$this->ID'" );
1028
1029 foreach ( $user_group_array as $group )
1030 {
1031 !$as_object ? $ret[] = $group[$db->fieldName( "GroupID" )] : $ret[] = new eZUserGroup( $group[$db->fieldName( "GroupID" )] );
1032 }
1033
1034 return $ret;
1035 }
1036
1037 function groupDefinition( $as_object = false )
1038 {
1039 $db =& eZDB::globalDatabase();
1040
1041 $db->array_query( $groups, "SELECT * FROM eZUser_UserGroupDefinition WHERE UserID='" . $this->ID . "'" );
1042
1043 if ( count( $groups ) > 1 )
1044 die( "Error in database" );
1045 else if ( count( $groups ) == 0 )
1046 return false;
1047 else if ( $as_object )
1048 return new eZUserGroup( $groups[0][$db->fieldName( "GroupID" )] );
1049 else
1050 return $groups[0][$db->fieldName( "GroupID" )];
1051 }
1052
1056 function hasRootAccess()
1057 {
1058 $result = array();
1059
1060 if ( $this->HasRoot < 0 )
1061 {
1062 $db =& eZDB::globalDatabase();
1063 $db->query_single( $result, "SELECT count( * ) as Count FROM eZUser_UserGroupLink, eZUser_Group
1064 WHERE eZUser_UserGroupLink.UserID='$this->ID'
1065 AND eZUser_Group.ID=eZUser_UserGroupLink.GroupID
1066 AND eZUser_Group.IsRoot='1'" );
1067 if ( $result[$db->fieldName( "Count" )] > 0 )
1068 $this->HasRoot = true;
1069 else
1070 $this->HasRoot = false;
1071 }
1072 return $this->HasRoot;
1073 }
1074
1075
1079 function removeGroups()
1080 {
1081 $db =& eZDB::globalDatabase();
1082 $db->query( "DELETE FROM eZUser_UserGroupLink
1083 WHERE UserID='$this->ID'" );
1084 }
1085
1089 function addAddress( $address )
1090 {
1091 $db =& eZDB::globalDatabase();
1092 if ( is_a( $address, "eZAddress" ) )
1093 {
1094 $addressID = $address->id();
1095 $db->begin( );
1096 $db->lock( "eZUser_UserAddressLink" );
1097
1098 $nextID = $db->nextID( "eZUser_UserAddressLink", "ID" );
1099
1100 $res = $db->query( "INSERT INTO eZUser_UserAddressLink
1101 ( ID, UserID, AddressID )
1102 VALUES
1103 ( '$nextID', '$this->ID', '$addressID' )" );
1104
1105 $db->unlock();
1106
1107 if ( $res == false )
1108 $db->rollback();
1109 else
1110 $db->commit();
1111 }
1112 }
1113
1117 function removeAddress( $address )
1118 {
1119 $db =& eZDB::globalDatabase();
1120 if ( is_a( $address, "eZAddress" ) )
1121 {
1122 $addressID = $address->id();
1123 $db->begin( );
1124
1125 $res = $db->query( "DELETE FROM eZUser_UserAddressLink
1126 WHERE AddressID='$addressID'" );
1127
1128 if ( $res == false )
1129 $db->rollback();
1130 else
1131 $db->commit();
1132
1133 eZAddress::delete( $addressID );
1134 // $db->query( "DELETE FROM eZContact_Address
1135 // WHERE ID='$addressID'" );
1136 }
1137 }
1138
1143 function removeAddresses( $id = false )
1144 {
1145 $db =& eZDB::globalDatabase();
1146 if ( !$id )
1147 $id = $this->ID;
1148
1149 $addresses = $this->addresses( $id, false );
1150 foreach ( $addresses as $address )
1151 {
1152 eZAddress::delete( $address );
1153 }
1154 $db->query( "DELETE FROM eZUser_UserAddressLink
1155 WHERE UserID='$id'" );
1156 }
1157
1162 function addresses( $id = false, $as_object = true )
1163 {
1164 $db =& eZDB::globalDatabase();
1165
1166 if ( !$id )
1167 $id = $this->ID;
1168
1169 $db->array_query( $address_array, "SELECT AddressID FROM eZUser_UserAddressLink
1170 WHERE UserID='$id' ORDER BY AddressID" );
1171
1172 $ret = array();
1173 if ( $as_object )
1174 {
1175 foreach ( $address_array as $address )
1176 {
1177 $ret[] = new eZAddress( $address[$db->fieldName( "AddressID" )] );
1178 }
1179 }
1180 else
1181 {
1182 foreach ( $address_array as $address )
1183 {
1184 $ret[] = $address[$db->fieldName( "AddressID" )];
1185 }
1186 }
1187
1188 return $ret;
1189 }
1190
1195 function mainAddress( $as_object = true )
1196 {
1197 $db =& eZDB::globalDatabase();
1198
1199 $id = $this->ID;
1200
1201 $db->array_query( $address_array, "SELECT AddressID FROM eZAddress_AddressDefinition
1202 WHERE UserID='$id' ORDER BY AddressID" );
1203
1204 if (count($address_array))
1205 {
1206 if ( $as_object )
1207 {
1208 if ( $address_array[0][$db->fieldName( "AddressID" )] != 0 )
1209 $ret = new eZAddress( $address_array[0][$db->fieldName( "AddressID" )] );
1210 }
1211 else
1212 {
1213 $ret = $address_array[0][$db->fieldName( "AddressID" )];
1214 }
1215 return $ret;
1216 }
1217 return null;
1218 }
1219
1220 function trustees( $id = -1, $as_object = false )
1221 {
1222 $db =& eZDB::globalDatabase();
1223 if ( is_a( $id, "eZUser" ) )
1224 $id = $id->ID();
1225 if ( $id < 0 )
1226 $id = $this->ID;
1227 $select = $as_object ? "*" : "UserID";
1228 $db->array_query( $trusteeArray, "SELECT $select FROM eZUser_Trustees WHERE OwnerID='$id'" );
1229 $ret = array();
1230 if ( $as_object )
1231 {
1232 foreach ( $trusteeArray as $trustee )
1233 {
1234 $ret[] = new eZUser( $trustee[ $db->fieldName( "UserID" ) ] );
1235 }
1236 }
1237 else
1238 {
1239 foreach ( $trusteeArray as $trustee )
1240 {
1241 $ret[] = $trustee[ $db->fieldName( "UserID" ) ];
1242 }
1243 }
1244 return $ret;
1245 }
1246
1247 function getByTrustee( $id = -1, $as_object = false )
1248 {
1249 $db =& eZDB::globalDatabase();
1250 if ( !is_integer( $id ) && get_class( $id ) )
1251 $id = $id->ID();
1252 if ( $id < 0 )
1253 $id = $this->ID;
1254 $select = $as_object ? "*" : "OwnerID";
1255 $db->array_query( $trusteeArray, "SELECT $select FROM eZUser_Trustees WHERE UserID='$id'" );
1256 $ret = array();
1257 if ( $as_object )
1258 {
1259 foreach ( $trusteeArray as $trustee )
1260 {
1261 $ret[] = new eZUser( $trustee[ $db->fieldName( "OwnerID" ) ] );
1262 }
1263 }
1264 else
1265 {
1266 foreach ( $trusteeArray as $trustee )
1267 {
1268 $ret[] = $trustee[ $db->fieldName( "OwnerID" ) ];
1269 }
1270 }
1271 return $ret;
1272 }
1273
1274 function addTrustee( $user )
1275 {
1276 if ( is_a( $user, "eZUser" ) )
1277 {
1278 $user = $user->ID();
1279 }
1280 $db =& eZDB::globalDatabase();
1281 $db->begin();
1282 $db->lock( "eZUser_Trustees" );
1283 $nextID = $db->nextID( "eZUser_Trustees", "ID" );
1284 $res[] = $db->query( "INSERT INTO eZUser_Trustees (ID, OwnerID, UserID) VALUES
1285 ('$nextID', '" . $this->ID() . "', '$user')" );
1286 $db->unlock();
1287 eZDB::finish( $res, $db );
1288 }
1289
1290 function removeTrustee( $user )
1291 {
1292 if ( is_a( $user, "eZUser" ) )
1293 {
1294 $user = $user->ID();
1295 }
1296 $db =& eZDB::globalDatabase();
1297 $db->begin();
1298 $res[] = $db->query( "DELETE FROM eZUser_Trustees WHERE OwnerID='" .
1299 $this->ID() . "' AND UserID='$user'" );
1300 eZDB::finish( $res, $db );
1301 }
1302
1303 function setCookieValues()
1304 {
1305 $user =& eZUser::currentUser();
1306 $db =& eZDB::globalDatabase();
1307
1308 if ( $user )
1309 {
1310 $db->begin( );
1311
1312 $db->lock( "eZUser_Cookie" );
1313 $nextID = $db->nextID( "eZUser_Cookie", "ID" );
1314
1315 $userID = $user->id();
1316 $hash = md5( microTime() );
1317
1318 $db->query( "DELETE FROM eZUser_Cookie WHERE UserID='$userID'" );
1319 $res = $db->query( "INSERT INTO eZUser_Cookie ( ID, Hash, UserID )
1320 VALUES ( '$nextID',
1321 Hash='$hash',
1322 UserID='$userID')" );
1323
1324 setCookie( "eZUser_AutoCookieLogin", $hash, time()+1209600, "/", "", 0 );
1325
1326 $db->unlock();
1327
1328 if ( $res == false )
1329 $db->rollback( );
1330 else
1331 $db->commit();
1332
1333 }
1334 }
1335
1340 function timeoutValue()
1341 {
1342 if ( isset( $this->StoredTimeout ) && is_numeric( $this->StoredTimeout ) )
1343 return $this->StoredTimeout;
1344
1345 $ret = 30;
1346
1347 $db =& eZDB::globalDatabase();
1348 $db->array_query( $timeout_array, "SELECT eZUser_Group.SessionTimeout
1349 FROM eZUser_User, eZUser_UserGroupLink, eZUser_Group
1350 WHERE eZUser_User.ID=eZUser_UserGroupLink.UserID
1351 AND eZUser_Group.ID=eZUser_UserGroupLink.GroupID
1352 AND eZUser_User.ID='$this->ID'
1353 ORDER BY eZUser_Group.SessionTimeout ASC",
1354 array( "Limit" => 1 ) );
1355
1356 if ( count( $timeout_array ) == 1 )
1357 {
1358 $ret = $timeout_array[0][$db->fieldName("SessionTimeout")];
1359 }
1360 $this->StoredTimeout = $ret;
1361 return $ret;
1362 }
1363
1367 function search( $queryText, $order = false, $LastName="", $FirstName="", $EMail="", $Login="", $match="AND" ) // gwf
1368 {
1369 $db =& eZDB::globalDatabase();
1370
1371 switch ( $order )
1372 {
1373 case "name" : $orderBy = "LastName, FirstName"; break;
1374 case "lastname" : $orderBy = "LastName"; break;
1375 case "firstname" : $orderBy = "FirstName"; break;
1376 case "lastname" : $orderBy = "LastName"; break;
1377 case "email" : $orderBy = "Email"; break;
1378 default : $orderBy = "Login"; break;
1379 }
1380
1381 if ($match =="") $match = "AND";
1382
1383 $query_ext = "";
1384 $i=0;
1385 if ($LastName != "")
1386 {
1387 $i = 1;
1388 $query_ext = " LastName LIKE '%$LastName%' ";
1389 }
1390 if ($FirstName !="")
1391 {
1392 if ($i == 1) $query_ext .= " $match ";
1393 $query_ext .= " FirstName LIKE '%$FirstName%' ";
1394 $i = 1;
1395 }
1396 if ($EMail !="")
1397 {
1398 if ($i == 1) $query_ext .= " $match ";
1399 $query_ext .= " Email LIKE '%$EMail%' ";
1400 $i = 1;
1401 }
1402
1403 if ($Login !="")
1404 {
1405 if ($i == 1) $query_ext .= " $match ";
1406 $query_ext .= " Login LIKE '%$Login%' ";
1407 $i = 1;
1408 }
1409
1410 if ($i == 0 and $query_ext == "")
1411 $query_ext = " Login LIKE '%$queryText%' OR Email LIKE '%$queryText%'
1412 OR FirstName LIKE '%$queryText%' OR LastName LIKE '%$queryText%' ";
1413
1414 $return_array = array();
1415 $user_array = array();
1416 $query = "SELECT * FROM eZUser_User WHERE $query_ext ORDER BY $orderBy";
1417
1418 $db->array_query( $user_array, $query );
1419 for ( $i = 0; $i < count( $user_array ); $i++ )
1420 {
1421 $return_array[$i] = new eZUser( $user_array[$i][$db->fieldName("ID")] );
1422 }
1423 return $return_array;
1424 }
1425
1426 var $ID;
1427 var $Login;
1428 var $Password;
1429 var $Email;
1430 var $FirstName;
1431 var $LastName;
1432 var $InfoSubscription;
1433 var $Signature;
1434 var $CookieLogin = 0;
1435 var $SimultaneousLogins;
1436 var $StoredTimeout;
1437 var $HasRoot;
1438 var $AccountNumber;
1439
1441 var $GroupString;
1442 }
1443
1444 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$session
$session
Definition: admin/articlelist.php:44
$userID
else $userID
Definition: appointmentedit.php:121
$address
$address
Definition: checkout.php:588
eZAddress
Definition: ezaddress.php:42
eZAddress\delete
static delete( $id=false)
Definition: ezaddress.php:176
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZQuery
Definition: ezquery.php:54
eZSession
Definition: lib/ezsession/classes/ezsession.php:65
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614
eZUserGroup
Definition: ezusergroup.php:66
eZUser
Definition: ezuser.php:76
eZUser\setInfoSubscription
setInfoSubscription( $value)
Definition: ezuser.php:729
eZUser\$FirstName
$FirstName
Definition: ezuser.php:1430
eZUser\getLogins
getLogins( $userId)
Definition: ezuser.php:981
eZUser\getByTrustee
getByTrustee( $id=-1, $as_object=false)
Definition: ezuser.php:1247
eZUser\groupString
groupString()
Definition: ezuser.php:998
eZUser\autoCookieLogin
static autoCookieLogin( $hash)
Definition: ezuser.php:837
eZUser\$Email
$Email
Definition: ezuser.php:1429
eZUser\removeGroups
removeGroups()
Definition: ezuser.php:1079
eZUser\$HasRoot
$HasRoot
Definition: ezuser.php:1437
eZUser\$SimultaneousLogins
$SimultaneousLogins
Definition: ezuser.php:1435
eZUser\fill
fill(&$user_array)
Definition: ezuser.php:291
eZUser\login
login( $html=true)
Definition: ezuser.php:593
eZUser\removeTrustee
removeTrustee( $user)
Definition: ezuser.php:1290
eZUser\firstName
firstName( $html=true)
Definition: ezuser.php:651
eZUser\groups
groups( $as_object=true)
Definition: ezuser.php:1021
eZUser\mainAddress
mainAddress( $as_object=true)
Definition: ezuser.php:1195
eZUser\getUsersByEmail
getUsersByEmail( $email, $as_object=true)
Definition: ezuser.php:462
eZUser\setPassword
setPassword( $value)
Definition: ezuser.php:710
eZUser\$ID
$ID
Definition: ezuser.php:1426
eZUser\getAllCount
static & getAllCount( $search=false)
Definition: ezuser.php:311
eZUser\$CookieLogin
$CookieLogin
Definition: ezuser.php:1434
eZUser\setSignature
setSignature( $value)
Definition: ezuser.php:693
eZUser\trustees
trustees( $id=-1, $as_object=false)
Definition: ezuser.php:1220
eZUser\$LastName
$LastName
Definition: ezuser.php:1431
eZUser\addTrustee
addTrustee( $user)
Definition: ezuser.php:1274
eZUser\$StoredTimeout
$StoredTimeout
Definition: ezuser.php:1436
eZUser\addAddress
addAddress( $address)
Definition: ezuser.php:1089
eZUser\store
store()
Definition: ezuser.php:105
eZUser\signature
signature()
Definition: ezuser.php:585
eZUser\getUser
static getUser( $login)
Definition: ezuser.php:420
eZUser\email
email()
Definition: ezuser.php:620
eZUser\logout
static logout()
Definition: ezuser.php:876
eZUser\simultaneousLogins
simultaneousLogins()
Definition: ezuser.php:685
eZUser\setCookieValues
setCookieValues()
Definition: ezuser.php:1303
eZUser\search
search( $queryText, $order=false, $LastName="", $FirstName="", $EMail="", $Login="", $match="AND")
Definition: ezuser.php:1367
eZUser\$InfoSubscription
$InfoSubscription
Definition: ezuser.php:1432
eZUser\$AccountNumber
$AccountNumber
Definition: ezuser.php:1438
eZUser\getAll
static & getAll( $order="Login", $as_object=true, $search=false, $max=-1, $index=0)
Definition: ezuser.php:330
eZUser\setCookieLogin
setCookieLogin( $value)
Definition: ezuser.php:777
eZUser\cookieLogin
cookieLogin()
Definition: ezuser.php:673
eZUser\removeAddress
removeAddress( $address)
Definition: ezuser.php:1117
eZUser\hasRootAccess
hasRootAccess()
Definition: ezuser.php:1056
eZUser\validateUser
validateUser( $login, $password)
Definition: ezuser.php:505
eZUser\getUserByEmail
getUserByEmail( $email)
Definition: ezuser.php:438
eZUser\lastName
lastName( $html=true)
Definition: ezuser.php:662
eZUser\setLastName
setLastName( $value)
Definition: ezuser.php:759
eZUser\groupDefinition
groupDefinition( $as_object=false)
Definition: ezuser.php:1037
eZUser\currentUsers
static currentUsers()
Definition: ezuser.php:946
eZUser\removeAddresses
removeAddresses( $id=false)
Definition: ezuser.php:1143
eZUser\$GroupString
$GroupString
string with the member groups, used for storing permissions in cache files
Definition: ezuser.php:1441
eZUser\timeoutValue
timeoutValue()
Definition: ezuser.php:1340
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZUser\__construct
__construct( $id=-1)
Definition: ezuser.php:83
eZUser\exists
static exists( $login)
Definition: ezuser.php:556
eZUser\setFirstName
setFirstName( $value)
Definition: ezuser.php:751
eZUser\setSimultaneousLogins
setSimultaneousLogins( $value)
Definition: ezuser.php:767
eZUser\$Password
$Password
Definition: ezuser.php:1428
eZUser\infoSubscription
infoSubscription()
Definition: ezuser.php:605
eZUser\addresses
addresses( $id=false, $as_object=true)
Definition: ezuser.php:1162
eZUser\id
id()
Definition: ezuser.php:576
eZUser\loginUser
static loginUser(&$user)
Definition: ezuser.php:809
eZUser\accountNumber
accountNumber()
Definition: ezuser.php:636
eZUser\$Signature
$Signature
Definition: ezuser.php:1433
eZUser\setLogin
setLogin( $value)
Definition: ezuser.php:701
eZUser\setGroupDefinition
setGroupDefinition( $group)
Definition: ezuser.php:785
eZUser\namedEmail
namedEmail()
Definition: ezuser.php:628
eZUser\clearAutoCookieLogin
static clearAutoCookieLogin()
Definition: ezuser.php:857
eZUser\name
name()
Definition: ezuser.php:643
eZUser\$Login
$Login
Definition: ezuser.php:1427
eZUser\setAccountNumber
setAccountNumber( $value)
Definition: ezuser.php:744
eZUser\setEmail
setEmail( $value)
Definition: ezuser.php:718
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$search
$search
Definition: export_froogle.php:153
$db
$db
Definition: ezarticle/user/authorlist.php:53
$groups
if( $CategoryID !=0) $groups
Definition: ezbulkmail/admin/categoryedit.php:108
$user_array
while( $tmpTime->isGreater( $stopTime)) $user_array
Definition: ezcalendar/user/dayview.php:495
$index
$index
Definition: ezforum/user/messageedit.php:36
$groupID
$groupID
Definition: ezgroupeventcalendar/user/dayview.php:90
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$EMail
$EMail
Definition: ezuser/admin/userlist.php:77
$order
$order
Definition: productreport.php:182
$userSessionList
$userSessionList
Definition: sessioninfo.php:69
Email
</td ></tr >< tr >< td style="color:<?= isset( $error['email'] ) ?> Email
Definition: step1.php:141
Password
</td ></tr >< tr >< td style="color:<?= isset( $error['password1'] ) ?> Password
Definition: step1.php:146
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.