ultimix
pmsg_access.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_message`';
39 
50  var $Database = false;
51  var $DatabaseAlgorithms = false;
52  var $Security = false;
53  var $SecurityParser = false;
54 
65  function __construct()
66  {
67  try
68  {
69  $this->Database = get_package( 'database' , 'last' , __FILE__ );
70  $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
71  $this->Security = get_package( 'security' , 'last' , __FILE__ );
72  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
73  }
74  catch( Exception $e )
75  {
76  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
77  }
78  }
79 
90  var $AddLimitations = '1 = 1';
91 
110  function set_add_limitations( $theAddLimitation )
111  {
112  try
113  {
114  if( $this->AddLimitations === '1 = 1' )
115  {
116  $this->AddLimitations = $theAddLimitation;
117  }
118  else
119  {
120  throw( new Exception( '"AddLimitations" was already set' ) );
121  }
122  }
123  catch( Exception $e )
124  {
125  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
126  }
127  }
128 
151  function unsafe_select( $Condition )
152  {
153  try
154  {
155  $this->Database->query_as( DB_OBJECT );
156 
157  return(
158  $this->Database->select( '*' , $this->NativeTable , "( $this->AddLimitations ) AND $Condition" )
159  );
160  }
161  catch( Exception $e )
162  {
163  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
164  }
165  }
166 
205  function select( $Start = false , $Limit = false , $Field = false ,
206  $Order = false , $Condition = '1 = 1' )
207  {
208  try
209  {
210  $Condition = $this->DatabaseAlgorithms->select_condition(
211  $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
212  );
213 
214  return( $this->unsafe_select( $Condition ) );
215  }
216  catch( Exception $e )
217  {
218  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
219  }
220  }
221 
244  function delete( $id , $Condition = ' 1 = 1' )
245  {
246  try
247  {
248  $id = $this->Security->get( $id , 'integer_list' );
249  $this->Database->delete( $this->NativeTable , "( $Condition ) AND id IN ( $id )" );
250  $this->Database->commit();
251  }
252  catch( Exception $e )
253  {
254  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
255  }
256  }
257 
277  {
278  try
279  {
280  $Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
281  $Settings->load_file( dirname( __FILE__ ).'/conf/cf_pmsg_settings' );
282 
283  return( $Settings->get_setting( 'admin_login' , 'admin' ) );
284  }
285  catch( Exception $e )
286  {
287  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
288  }
289  }
290 
313  function create( $Record )
314  {
315  try
316  {
317  $Record = $this->SecurityParser->parse_parameters(
318  $Record , 'author:string;recipient:string;subject:string;message:string'
319  );
320 
321  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
322 
323  $Fields [] = 'creation_date';
324  $Values [] = 'NOW()';
325 
326  $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
327 
328  $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
329  $EventManager->trigger_event( 'on_after_create_message' , array( 'id' => $id ) );
330 
331  return( $id );
332  }
333  catch( Exception $e )
334  {
335  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
336  }
337  }
338 
361  function update( $id , $Record )
362  {
363  try
364  {
365  $id = $this->Security->get( $id , 'integer_list' );
366  $Record = $this->SecurityParser->parse_parameters(
367  $Record , 'deleted:integer;recipient:string;author:string;subject:string;'.
368  'message:string;`read`:integer' , 'allow_not_set'
369  );
370 
371  list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
372 
373  if( isset( $Fields[ 0 ] ) )
374  {
375  $this->Database->update(
376  $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
377  );
378  $this->Database->commit();
379  }
380  }
381  catch( Exception $e )
382  {
383  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
384  }
385  }
386  }
387 
388 ?>