229 private function load_scripts()
234 $PageJS =
get_package(
'page::page_js' ,
'last' , __FILE__ );
235 $PageJS->add_javascript(
"{http_host}/$Path/include/js/paging.js" );
237 $this->NoDataFoundMessage = $this->CachedMultyFS->get_template(
238 __FILE__ ,
'data_for_grid_was_not_found.tpl'
241 $this->CallbackFunc = create_function(
242 '$Template , $Record',
243 '$String = get_package( "string" , "last" , __FILE__ );'.
244 'return( $String->print_record( $Template , $Record ) );'
247 catch( Exception $e )
271 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
272 $this->PagingMarkup =
get_package(
'gui::paging::paging_markup' ,
'last' , __FILE__ );
273 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
275 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
276 $this->Utilities =
get_package(
'utilities' ,
'last' , __FILE__ );
278 $this->load_scripts();
280 catch( Exception $e )
304 function set( $FieldName , $FieldValue )
306 $this->$FieldName = $FieldValue;
327 private function compile_hidden_fields()
331 if( $this->Security->get_gp(
'add_hidden_fields' ,
'integer' , 1 ) )
333 $Code =
'<input type="hidden" name="ajaxed" value="'.( $this->Ajaxed ? 1 : 0 ).
'">
334 <!--input type="hidden" name="page" value="'.$this->Page.
'"-->
335 <input type="hidden" id="reorder_field" class="reorder_field" name="reorder_field" value="{field}">
336 <input type="hidden" id="order" class="order" name="order" value="{order}">'.$this->CustomButtons;
342 catch( Exception $e )
370 $this->FormRequired = $this->Security->get_gp(
'paging_require_form' ,
'integer' ,
true );
372 $HiddenFields = $this->compile_hidden_fields();
374 $HiddenFields = $this->PagingMarkup->compile_sort_link( $this , $HiddenFields );
376 if( $this->FormRequired )
378 return(
'<form id="'.$this->FormId.
'" action="" method="post">'.$HiddenFields.$this->Header );
382 return( $HiddenFields.$this->Header );
385 catch( Exception $e )
413 $this->Footer = str_replace(
'{page_name}' , $this->PageField , $this->Footer );
414 $this->Footer = str_replace(
'{records_per_page}' , $this->RecordsPerPage , $this->Footer );
416 if( $this->FormId !==
false && $this->FormRequired )
418 return( $this->Footer.
'</form>' );
422 return( $this->Footer );
425 catch( Exception $e )
453 private function compile_items( &$DataToDisplay )
458 $c = count( $DataToDisplay );
464 $Tmp = call_user_func( $this->CallbackFunc , $Tmp , $DataToDisplay[ $i ] );
465 $Tmp = str_replace(
'{odd_factor}' , ( $i % 2 === 0 ?
'even' :
'odd' ) , $Tmp );
472 catch( Exception $e )
500 private function compile_macros( &$DataToDisplay )
504 $RetView = $this->compile_items( $DataToDisplay );
506 $RetView = $this->
compile_header().
'{set_var:name='.$this->FormId.
'_records_count;value='.
507 count( $DataToDisplay ).
'}'.$RetView.$this->compile_footer();
509 $RetView = $this->PagingMarkup->compile_left_slider( $this , $RetView );
510 $RetView = $this->PagingMarkup->compile_records_per_page_control( $this , $RetView );
511 $RetView = $this->PagingMarkup->compile_right_slider( $this , count( $DataToDisplay ) , $RetView );
513 return( str_replace(
'{prefix}' , $this->Prefix , $RetView ) );
515 catch( Exception $e )
539 private function compile_no_data_to_display()
543 $this->FormRequired = $this->FormId ===
false ?
false :
true;
544 $this->NoDataFoundMessage = str_replace(
'{prefix}' , $this->Prefix , $this->NoDataFoundMessage );
546 if( $this->FormRequired )
549 '{set_var:name='.$this->FormId.
'_records_count;value=0}<form id="'.$this->FormId.
550 '" action="" method="post">'.$this->CustomButtons.$this->NoDataFoundMessage.
'</form>'
555 return(
'{set_var:name='.$this->FormId.
'_records_count;value=0}'.$this->NoDataFoundMessage );
558 catch( Exception $e )
586 private function get_data_to_display( &$Options )
590 $ReorderField = $this->Security->get_gp(
'reorder_field' ,
'command' ,
false );
591 $Order = $this->Security->get_gp(
'order' ,
'command' ,
false );
593 if( strlen( $ReorderField ) == 0 )
595 $ReorderField =
false;
597 if( strlen( $Order ) == 0 )
602 $DataToDisplay = call_user_func(
603 $this->DataAccessor , ( $this->Page - 1 ) * $this->RecordsPerPage ,
604 $this->RecordsPerPage + 1 , $ReorderField , $Order , $Options
607 return( $DataToDisplay );
609 catch( Exception $e )
633 private function primary_init( &$Options )
637 $this->GridId = md5( microtime(
true ) );
639 $this->Page = $this->Security->get_gp( $this->PageField ,
'integer' , 1 );
641 $this->RecordsPerPage = $Options->get_setting(
'records_per_page' , $this->RecordsPerPage );
643 $this->RecordsPerPage = $this->Security->get_c(
644 $this->Prefix.
'_records_per_page' ,
'integer' , $this->RecordsPerPage
647 catch( Exception $e )
679 function draw( $DataToDisplay =
false , $Options =
false )
683 $this->primary_init( $Options );
685 if( $DataToDisplay ===
false && $this->DataAccessor ===
false )
687 throw(
new Exception(
'No data was specified' ) );
689 if( $this->DataAccessor )
691 $DataToDisplay = $this->get_data_to_display( $Options );
694 if( count( $DataToDisplay ) === 0 )
696 return( $this->compile_no_data_to_display() );
699 return( $this->compile_macros( $DataToDisplay ) );
701 catch( Exception $e )