<?php
namespace admin\view;

class Adverts {

  public function edit( $id = '' )
  {
    global $lang;

    $out = \admin\view\PagePanel::show( false , true , true , $lang -> getTrans( 'T_REKLAMA' ) );

		$dbedit = new \DataEdit( 'pcms_adverts' , 'id' , $id );
		$dbedit -> addPosition( 'name'        , $lang -> getTrans( 'T_NAZWA' )            , 'text' );
		$dbedit -> addPosition( 'date_start'  , $lang -> getTrans( 'T_DATA_POCZATKOWA' )  , 'text' , 'onFocus="if ( $( this ).val() == \'\' ) $(this).val( \'' . date( 'Y-m-d' ) . '\');"' );
		$dbedit -> addPosition( 'date_end'		, $lang -> getTrans( 'T_DATA_KONCOWA' )     , 'text' , 'onFocus="if ( $( this ).val() == \'\' ) $(this).val( \'' . date( 'Y-m-d' ) . '\');"' );
		$dbedit -> addPosition( 'enabled'     , $lang -> getTrans( 'T_AKTYWNY' )          , 'radio' , '' , \System::getComboYesNo() );
		$dbedit -> addPosition( 'img'         , $lang -> getTrans( 'T_ZDJECIE' )          , 'file' );
		$dbedit -> setUploadFolder( 'image' , 'upload/adverts/' );
		$out .= $dbedit -> draw();

		return $out;
  }

  public function show()
  {
    global $lang;

    $out = \admin\view\PagePanel::show( true , false , false , $lang -> getTrans( 'T_REKLAMA' ) );

    $dbrowse = new \DataBrowse( 'pcms_adverts' );
    $dbrowse -> addPosition( 'name'       , $lang -> getTrans( 'T_NAZWA' ) );
    $dbrowse -> addPosition( 'date_start' , $lang -> getTrans( 'T_DATA_POCZATKOWA' ) );
    $dbrowse -> addPosition( 'date_end'   , $lang -> getTrans( 'T_DATA_KONCOWA' ) );
    $dbrowse -> addPosition( 'enabled'    , $lang -> getTrans( 'T_AKTYWNY' )      , '' , \System::getComboYesNo() );
    $dbrowse -> addPositionSimple( $lang -> getTrans( 'T_EDYTUJ' )  , '' , 'index.php?rw=edit' );
    $dbrowse -> addPositionSimple( $lang -> getTrans( 'T_USUN' )    , '' , '' , \System::deleteAction() );
    $dbrowse -> setParam( 'id' );
    $dbrowse -> addSort( 'name ASC' );
    $dbrowse -> addLp();
    $dbrowse -> addFiltr( 'name'    , $lang -> getTrans( 'T_NAZWA' )        , $tab );
    $dbrowse -> addFiltr( 'enabled' , $lang -> getTrans( 'T_AKTYWNY' )      , \System::getComboYesNo() );
    $out .= $dbrowse -> draw();

    return $out;
  }
}
?>
