94 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
95 $this->DatabaseAlgorithms =
get_package(
'database::database_algorithms' ,
'last' , __FILE__ );
96 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
97 $this->SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
99 'user::user_access::user_access_utilities' ,
'last' , __FILE__
102 catch( Exception $e )
142 if( $this->AddLimitations ===
'1 = 1' )
144 $this->AddLimitations = $theAddLimitation;
148 throw(
new Exception(
'"AddLimitations" was already set' ) );
151 catch( Exception $e )
190 $this->Database->select(
191 $this->NativeTable.
'.* , file_path AS avatar_path , '.
192 'IF( banned_to >= NOW() , 1 , 0 ) AS banned' ,
193 $this->NativeTable.
' , umx_uploaded_file' ,
194 "( $this->AddLimitations ) AND umx_uploaded_file.id = ".
195 $this->NativeTable.
".avatar AND $Condition"
199 catch( Exception $e )
231 if( isset( $this->UsersCache[ $Login ] ) )
233 return( $this->UsersCache[ $Login ] );
236 $Login = $this->Security->get( $Login ,
'string' );
240 if( count( $Users ) === 0 || count( $Users ) > 1 )
242 throw(
new Exception(
'User with login '.$Login.
' was not found' ) );
246 $this->UsersCache[ $Login ] = $Users[ 0 ];
247 return( $Users[ 0 ] );
250 catch( Exception $e )
282 $Login = $this->Security->get( $Login ,
'string' );
283 $Password = $this->Security->get( $Password ,
'string' );
289 $Record = array(
'password' =>
"md5( '$Password' )" );
292 catch( Exception $e )
324 $Login = $this->Security->get( $Login ,
'string' );
325 $ImageId = $this->Security->get( $ImageId ,
'integer' );
329 $Record = array(
'avatar' =>
"$ImageId" );
332 catch( Exception $e )
360 private function fetch_update_data( &$Record )
364 $Record = $this->SecurityParser->parse_parameters(
366 'password:string;email:email;active:command;active_to:string;'.
367 'banned_to:string;name:string;sex:integer;site:string;about:string' ,
371 list( $Fields , $Values ) = $this->UserAccessUtilities->handle_update_record( $Record );
373 return( array( $Fields , $Values ) );
375 catch( Exception $e )
407 $id = $this->Security->get( $id ,
'integer_list' );
409 list( $Fields , $Values ) = $this->fetch_update_data( $Record );
411 if( count( $Fields ) == 0 )
415 $this->EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
416 $this->EventManager->trigger_event(
417 'on_before_update_user' , array(
'id' => $id ,
'data' => $Record )
420 $this->Database->update(
421 $this->NativeTable , $Fields , $Values ,
"( $this->AddLimitations ) AND id IN ( $id )"
423 $this->Database->commit();
425 $this->UserAccessUtilities->rise_update_event( $id );
427 catch( Exception $e )
451 function delete( $ids )
455 $ids = $this->Security->get( $ids ,
'integer_list' );
457 $this->Database->delete( $this->NativeTable ,
"( $this->AddLimitations ) AND id IN ( $ids )" );
458 $this->Database->commit();
461 $Link->delete_link(
"$ids" ,
false ,
'user' ,
'permit' );
462 $Link->delete_link(
"$ids" ,
false ,
'user' ,
'group' );
464 catch( Exception $e )
492 $Ids = $this->Security->get( $Ids ,
'integer' );
494 $Record = array(
'active' =>
'1' );
495 $this->
update( implode(
',' , $Ids ) , $Record );
497 foreach( $Ids as $id )
499 $this->UserAccessUtilities->rise_activate_event(
'' , $id );
502 catch( Exception $e )
530 $Ids = $this->Security->get( $Ids ,
'integer' );
532 $Record = array(
'active' =>
'inactive' );
533 $this->
update( implode(
',' , $Ids ) , $Record );
535 foreach( $Ids as $id )
537 $this->UserAccessUtilities->rise_activate_event(
'' , $id );
540 catch( Exception $e )
568 $Hash = $this->Security->get( $Hash ,
'command' );
572 if( isset( $Users[ 0 ] ) )
579 catch( Exception $e )
607 $id = $this->Security->get( $id ,
'integer' );
609 $Record = array(
'active' =>
'0' );
610 $this->
update( $id , $Record );
612 $this->UserAccessUtilities->rise_deactivate_event( $id );
614 catch( Exception $e )
638 private function set_fields( &$Record )
642 $Record =
set_field( $Record ,
'active' , md5( microtime() ) );
643 $Record =
set_field( $Record ,
'password' , md5(
get_field( $Record ,
'password' ) ) );
645 catch( Exception $e )
677 $Record = $this->SecurityParser->parse_parameters(
679 'login:string;password:string;email:email;name:string;sex:integer;site:string;about:string'
682 $this->set_fields( $Record );
684 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
686 $Fields [] =
'registered';
687 $Values [] =
'NOW()';
689 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
691 $this->UserAccessUtilities->rise_create_event(
get_field( $Record ,
'login' ) , $id );
693 return( array( $id ,
get_field( $Record ,
'active' ) ) );
695 catch( Exception $e )
727 $id = $this->Security->get( $id ,
'integer_list' );
729 return( $this->
unsafe_select( $this->NativeTable.
".id IN ( $id )" ) );
731 catch( Exception $e )
775 function select( $Start =
false , $Limit =
false , $Field =
false ,
776 $Order =
false , $Condition =
'1 = 1' )
780 $Condition = $this->DatabaseAlgorithms->select_condition(
781 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
786 catch( Exception $e )
816 foreach( $Records as $k => $v )
818 $Records[ $k ]->title = $v->id ? $v->login :
'{lang:not_defined}';
823 catch( Exception $e )