ultimix
paging_markup.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 
17 
28  var $CachedMultyFS = false;
29  var $Settings = false;
30  var $Security = false;
31 
46  function __construct()
47  {
48  try
49  {
50  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
51 
52  $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
53  $this->Security = get_package( 'security' , 'last' , __FILE__ );
54  }
55  catch( Exception $e )
56  {
57  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
58  }
59  }
60 
91  function compile_non_ajaxed_left_slider( &$Paging , $Control )
92  {
93  try
94  {
95  $Fields = $_GET;
96  $Fields[ $Paging->PageField ] = $Paging->Page - 1;
97  $Fields = $Paging->Utilities->pack_into_url( $Fields , array( 'page_name' ) );
98  $Fields = str_replace( '=' , '[eq]' , $Fields );
99 
100  $Code = '{href:form_id='.$Paging->FormId.
101  ";tpl=submit0;text=left_side_switcher;action=./[page_name].html?$Fields}";
102 
103  return( str_replace( '{left_slide}' , $Code , $Control ) );
104  }
105  catch( Exception $e )
106  {
107  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
108  }
109  }
110 
133  function compile_reorder_field( &$Paging )
134  {
135  try
136  {
137  $ReorderField = '';
138 
139  if( $this->Security->get_gp( 'reorder_field' ) )
140  {
141  $Field = $this->Security->get_gp( 'reorder_field' , 'command' );
142  $Order =
143  $this->Security->get_gp( 'order' , 'command' ) === 'ascending' ? 'ascending' : 'descending';
144  $ReorderField = " , 'reorder_field' : '$Field' , 'order' : '$Order'";
145  }
146 
147  return( $ReorderField );
148  }
149  catch( Exception $e )
150  {
151  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
152  }
153  }
154 
177  function compile_left_slider( &$Paging , $Control )
178  {
179  try
180  {
181  if( $Paging->Page > 1 )
182  {
183  return( $this->compile_non_ajaxed_left_slider( $Paging , $Control ) );
184  }
185  else
186  {
187  return( str_replace( '{left_slide}' , '{lang:left_side_switcher}' , $Control ) );
188  }
189  }
190  catch( Exception $e )
191  {
192  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
193  }
194  }
195 
222  function compile_controller_options( &$Paging , &$Settings )
223  {
224  try
225  {
226  $Limit = $Settings->get_setting( 'limit' , 1000 );
227  $Values = array(
228  1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ,
229  20 , 30 , 40 , 50 , 100 , 200 , 300 , 400 , 500 , 1000
230  );
231  $Options = '';
232  foreach( $Values as $k => $v )
233  {
234  if( $v <= $Limit )
235  {
236  $Options .= $this->CachedMultyFS->get_template(
237  __FILE__ , 'records_per_page_options.tpl'
238  );
239  $Options = str_replace(
240  array( '{value}' , '{title}' , '{selected}' ) ,
241  array( $v , $v , ( $Paging->RecordsPerPage == $v ? ' selected' : '' ) ) ,
242  $Options
243  );
244  }
245  }
246  return( $Options );
247  }
248  catch( Exception $e )
249  {
250  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
251  }
252  }
253 
276  private function get_fields( &$Paging )
277  {
278  try
279  {
280  $Fields = $_GET;
281  $Fields[ $Paging->PageField ] = 1;
282  $Fields = $Paging->Utilities->pack_into_url( $Fields , array( 'page_name' ) );
283 
284  return( str_replace( '=' , '[eq]' , $Fields ) );
285  }
286  catch( Exception $e )
287  {
288  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
289  }
290  }
291 
318  function get_records_per_page_control( &$Paging , &$Settings )
319  {
320  try
321  {
322  $Fields = $this->get_fields( $Paging );
323 
324  $Code = $this->CachedMultyFS->get_template( __FILE__ , 'records_per_page_control.tpl' );
325 
326  $Macro = array( '{reorder_field}' , '{prefix}' , '{fields}' , '{form_id}' , '{options}' );
327  $Data = array(
328  $this->Security->get_gp( 'reorder_field' , 'command' , '' ) , $Paging->Prefix , $Fields ,
329  $Paging->FormId , $this->compile_controller_options( $Paging , $Settings )
330  );
331  $Code = str_replace( $Macro , $Data , $Code );
332 
333  return( $Code );
334  }
335  catch( Exception $e )
336  {
337  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
338  }
339  }
340 
363  function compile_records_per_page_control( &$Paging , $Control )
364  {
365  try
366  {
367  $Control = str_replace(
368  '{records_per_page_control}' , '{records_per_page_control:type=default}' , $Control
369  );
370 
371  for( ; $Parameters = $Paging->String->get_macro_parameters( $Control , 'records_per_page_control' ) ; )
372  {
373  $this->Settings->load_settings( $Parameters );
374 
375  $Code = $this->get_records_per_page_control( $Paging , $this->Settings );
376 
377  $Control = str_replace( "{records_per_page_control:$Parameters}" , $Code , $Control );
378  }
379 
380  return( $Control );
381  }
382  catch( Exception $e )
383  {
384  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
385  }
386  }
387 
418  function compile_non_ajaxed_right_slider( &$Paging , $Control )
419  {
420  try
421  {
422  $Fields = $_GET;
423  $Fields[ $Paging->PageField ] = $Paging->Page + 1;
424  $Fields = $Paging->Utilities->pack_into_url( $Fields , array( 'page_name' ) );
425  $Fields = str_replace( '=' , '[eq]' , $Fields );
426 
427  return(
428  str_replace(
429  '{right_slide}' ,
430  '{href:form_id='.$Paging->FormId.";tpl=submit0;text=right_side_switcher;action=./".
431  "[page_name].html?$Fields}" , $Control
432  )
433  );
434  }
435  catch( Exception $e )
436  {
437  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
438  }
439  }
440 
471  function compile_right_slider( &$Paging , $CountOfRecords , $Control )
472  {
473  try
474  {
475  if( $CountOfRecords === $Paging->RecordsPerPage + 1 )
476  {
477  return( $this->compile_non_ajaxed_right_slider( $Paging , $Control ) );
478  }
479  else
480  {
481  return( str_replace( '{right_slide}' , '{lang:right_side_switcher}' , $Control ) );
482  }
483  }
484  catch( Exception $e )
485  {
486  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
487  }
488  }
489 
516  function set_order_data( &$Paging , $HiddenFields )
517  {
518  try
519  {
520  $ReorderField = $this->Security->get_gp( 'reorder_field' , 'command' , false );
521 
522  if( $ReorderField && $this->Settings->get_setting( 'dbfield' ) === $ReorderField )
523  {
524  $Order = ( $this->Security->get_gp( 'order' , 'command' ) === 'ascending' ?
525  'ascending' : 'descending' );
526  $HiddenFields = str_replace( '{order}' , $Order , $HiddenFields );
527  $HiddenFields = str_replace(
528  '{field}' , $this->Settings->get_setting( 'dbfield' ) , $HiddenFields
529  );
530  }
531 
532  return( $HiddenFields );
533  }
534  catch( Exception $e )
535  {
536  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
537  }
538  }
539 
566  function compile_sort_link( &$Paging , $HiddenFields )
567  {
568  try
569  {
570  for( ; $Parameters = $Paging->String->get_macro_parameters( $Paging->Header , 'sort_link' ) ; )
571  {
572  $this->Settings->load_settings( $Parameters );
573 
574  $HiddenFields = $this->set_order_data( $Paging , $HiddenFields );
575 
576  $Paging->Header = str_replace( "{sort_link:$Parameters}" , "{href:style=display:block;text=".
577  $this->Settings->get_setting( 'text' ).";page=javascript:ultimix.Reorder( '#".$Paging->FormId.
578  "' , ".( $Paging->Ajaxed ? 'true' : 'false' )." , './[page_name].html' , '".
579  $this->Settings->get_setting( 'dbfield' )."' )}" , $Paging->Header
580  );
581  }
582 
583  return( $HiddenFields );
584  }
585  catch( Exception $e )
586  {
587  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
588  }
589  }
590  }
591 
592 ?>