ultimix
default_views_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 $CachedMultyFS = false;
39  var $ContextSetUtilities = false;
40  var $Search = false;
41  var $Security = false;
42  var $Settings = false;
43  var $String = false;
44 
55  var $Prefix = false;
56 
67  var $Provider = false;
68 
79  var $ContextSet = false;
80 
91  var $QueryString = '1 = 1';
92 
107  function __construct()
108  {
109  try
110  {
111  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
112  $this->ContextSetUtilities = get_package(
113  'gui::context_set::context_set_utilities' , 'last' , __FILE__
114  );
115  $this->Search = get_package( 'search' , 'last' , __FILE__ );
116  $this->Security = get_package( 'security' , 'last' , __FILE__ );
117  $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
118  $this->String = get_package_object( 'settings::settings' , 'last' , __FILE__ );
119  }
120  catch( Exception $e )
121  {
122  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
123  }
124  }
125 
148  function set_constants( &$ContextSet , &$Options )
149  {
150  try
151  {
152  $this->Prefix = $ContextSet->Prefix;
153  $this->Provider = $ContextSet->Provider;
154  $this->ContextSet = &$ContextSet;
155  }
156  catch( Exception $e )
157  {
158  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
159  }
160  }
161 
188  function apply_posted_data_for_create_form( &$Options , $Form )
189  {
190  try
191  {
192  if( $Options->get_setting( 'get_post_extraction_script' , false ) )
193  {
194  $ExtractionScript = $Options->get_setting( 'get_post_extraction_script' );
195  $SecurityParser = get_package( 'security::security_utilities' , 'last' , __FILE__ );
196  $Record = $SecurityParser->parse_http_parameters( $ExtractionScript );
197  $Form = $this->String->print_record( $Form , $Record );
198  }
199 
200  return( $Form );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
226  private function compile_query_string( $CommonStateConfigPath )
227  {
228  try
229  {
230  $Conf = $this->CachedMultyFS->file_get_contents( $CommonStateConfigPath );
231  $Conf = str_replace( '{prefix}' , $this->Prefix , $Conf );
232  $this->Settings->load_settings( $Conf );
233  $Fields = $this->Settings->get_setting( 'search_fields' , false );
234 
235  if( $Fields !== false )
236  {
237  $Fields = explode( ',' , $Fields );
238 
239  $this->QueryString = $this->Search->build_query_string( $Fields );
240  }
241  }
242  catch( Exception $e )
243  {
244  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
245  }
246  }
247 
266  private function build_query_string( $Options )
267  {
268  try
269  {
270  $this->QueryString = '1 = 1';
271  $SearchString = $this->Security->get_gp( 'search_string' , 'string' , '' );
272 
273  if( strlen( $SearchString ) )
274  {
275  $CommonStateConfigFileName = $Options->get_setting(
276  'common_state_config_search_form' , 'cfcxs_search_form'
277  );
278 
279  $ComponentPath = dirname( $Options->get_setting( 'file_path' ) );
280 
281  $CommonStateConfigPath = "$ComponentPath/conf/$CommonStateConfigFileName";
282 
283  if( $this->CachedMultyFS->file_exists( $CommonStateConfigPath ) )
284  {
285  $this->compile_query_string( $CommonStateConfigPath );
286  }
287  }
288  }
289  catch( Exception $e )
290  {
291  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
292  }
293  }
294 
325  function compile_form( &$Options , $Form , $IdList = false )
326  {
327  try
328  {
329  if( $IdList !== false )
330  {
331  $Record = $this->ContextSetUtilities->get_data_record( $Options , $IdList );
332 
333  $Record = $this->ContextSetUtilities->extract_data_from_request(
334  $Options , $Record , 'get_post_extraction_script' , $this->Prefix
335  );
336 
337  $Form = $this->ContextSetUtilities->set_form_data( $Form , $Record );
338  }
339 
340  if( strpos( $Form , '{prefix}' ) !== false )
341  {
342  $Form = str_replace( '{prefix}' , $this->Prefix , $Form );
343  }
344 
345  $Changed = false;
346  $Form = $this->ContextSet->compile_special_macro( $Options , $Form , $Changed );
347 
348  return( $Form );
349  }
350  catch( Exception $e )
351  {
352  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
353  }
354  }
355 
378  private function set_paging_templates( &$Options , &$Paging )
379  {
380  try
381  {
382  $this->ContextSetUtilities->set_header_template( $Options , $Paging , $this->Prefix );
383  $this->ContextSetUtilities->set_item_template( $Options , $Paging , $this->Prefix );
384  $this->ContextSetUtilities->set_no_data_found_message( $Options , $Paging );
385  $this->ContextSetUtilities->set_footer_template( $Options , $Paging , $this->Prefix );
386  $this->ContextSetUtilities->set_main_settings( $Options , $Paging );
387  $this->ContextSetUtilities->set_grid_data( $Options , $Paging , $this->QueryString );
388  }
389  catch( Exception $e )
390  {
391  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
392  }
393  }
394 
417  function construct_paging( &$Options , &$Paging )
418  {
419  try
420  {
421  /* Paging primary initialization */
422  $Paging->set( 'FormId' , $this->Prefix.'_form' );
423  $Paging->set( 'Prefix' , $this->Prefix );
424 
425  /* Header buttons creation */
426  $HeaderFields =
427  '<input type="hidden" name="{prefix}_context_action" id="{prefix}_context_action" value="">
428  <input type="hidden" name="{prefix}_action" id="{prefix}_action" value="">
429  <input type="hidden" name="{prefix}_record_id" id="{prefix}_record_id" value="">';
430 
431  $Paging->set( 'CustomButtons' , $HeaderFields );
432 
433  $this->build_query_string( $Options );
434 
435  $this->set_paging_templates( $Options , $Paging );
436  }
437  catch( Exception $e )
438  {
439  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
440  }
441  }
442 
469  function get_template( &$Options , $TemplateName )
470  {
471  try
472  {
473  $Template = $Options->get_setting( $TemplateName , '' );
474 
475  if( $Template !== '' )
476  {
477  $Template = dirname( $Options->get_setting( 'file_path' ) )."/res/templates/$TemplateName.tpl";
478 
479  $Template = $this->CachedMultyFS->file_get_contents( $Template );
480  }
481 
482  return( $Template );
483  }
484  catch( Exception $e )
485  {
486  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
487  }
488  }
489  }
490 
491 ?>