ultimix
user_access_utilities.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $NativeTable = '`umx_user`';
39 
50  var $GuestUserId = 2;
51 
62  var $Database = false;
63  var $DatabaseAlgorithms = false;
64  var $Security = false;
65  var $SecurityParser = false;
66 
77  var $UsersCache = array();
78 
89  function __construct()
90  {
91  try
92  {
93  $this->Database = get_package( 'database' , 'last' , __FILE__ );
94  $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
95  $this->Security = get_package( 'security' , 'last' , __FILE__ );
96  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
97  }
98  catch( Exception $e )
99  {
100  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
101  }
102  }
103 
126  function rise_create_event( $Login , $id )
127  {
128  try
129  {
130  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
131  $EventManager->trigger_event( 'on_after_create_user' , array( 'login' => $Login , 'id' => $id ) );
132  $EventManager->trigger_event( 'anonimous' , array( 'master_id' => $id , 'master_type' => 'user' ) );
133  }
134  catch( Exception $e )
135  {
136  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
137  }
138  }
139 
162  function rise_activate_event( $Login , $id )
163  {
164  try
165  {
166  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
167  $EventManager->trigger_event( 'on_after_activate_user' , array( 'login' => $Login , 'id' => $id ) );
168  $EventManager->trigger_event( 'anonimous' , array( 'master_id' => $id , 'master_type' => 'user' ) );
169  }
170  catch( Exception $e )
171  {
172  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
173  }
174  }
175 
194  function rise_deactivate_event( $id )
195  {
196  try
197  {
198  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
199  $EventManager->trigger_event( 'on_after_deactivate_user' , array( 'id' => $id ) );
200  $EventManager->trigger_event( 'anonimous' , array( 'master_id' => $id , 'master_type' => 'user' ) );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
226  function rise_update_event( $id )
227  {
228  try
229  {
230  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
231  $EventManager->trigger_event( 'on_after_update_user' , array( 'id' => $id ) );
232  $EventManager->trigger_event( 'anonimous' , array( 'master_id' => $id , 'master_type' => 'user' ) );
233  }
234  catch( Exception $e )
235  {
236  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
237  }
238  }
239 
266  private function handle_sex_field( &$Fields , &$Values , $v )
267  {
268  try
269  {
270  if( $v != 1 && $v != 2 )
271  {
272  $v = 0;
273  }
274 
275  $Fields [] = 'sex';
276  $Values [] = $v;
277  }
278  catch( Exception $e )
279  {
280  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
281  }
282  }
283 
310  private function handle_active_field( &$Fields , &$Values , $v )
311  {
312  try
313  {
314  if( $v == '1' )
315  {
316  $Fields [] = 'active';
317  $Values [] = "'active'";
318  }
319  else
320  {
321  $Fields [] = 'active';
322  $Values [] = "'".md5( microtime() )."'";
323  }
324  }
325  catch( Exception $e )
326  {
327  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
328  }
329  }
330 
357  private function handle_password_field( &$Fields , &$Values , $v )
358  {
359  try
360  {
361  if( $v !== '' )
362  {
363  $Fields [] = 'password';
364  $Values [] = "'".md5( $v )."'";
365  }
366  }
367  catch( Exception $e )
368  {
369  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
370  }
371  }
372 
395  function handle_update_record( &$Record )
396  {
397  try
398  {
399  $Fields = $Values = array();
400  foreach( $Record as $f => $v )
401  {
402  switch( $f )
403  {
404  case( 'sex' ):
405  $this->UserAccessUtilieis->handle_sex_field( $Fields , $Values , $v );
406  break;
407  case( 'active' ):
408  $this->handle_active_field( $Fields , $Values , $v );
409  break;
410  case( 'password' ):
411  $this->handle_password_field( $Fields , $Values , $v );
412  break;
413  default:
414  $Fields [] = $f;
415  $Values [] = "'$v'";
416  break;
417  }
418  }
419  return( array( $Fields , $Values ) );
420  }
421  catch( Exception $e )
422  {
423  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
424  }
425  }
426  }
427 
428 ?>