<?php

/**
 * initialise block
 */
function amazon_readerappreciationdayblock_init()
{
    // Security
    pnSecAddSchema( 'Amazon:ReaderAppreciationDayblock:', 'Block title::' );
}

/**
 * get information on block
 */
function amazon_readerappreciationdayblock_info()
{
    // Values
    return array( 'text_type' => 'ReaderAppreciationDay',
                  'module' => 'Amazon',
                  'text_type_long' => 'Reader Appreciation Day',
                  'allow_multiple' => true,
                  'form_content' => false,
                  'form_refresh' => false,
                  'show_preview' => true );
}

/**
 * display block
 */
function amazon_readerappreciationdayblock_display( $blockinfo )
{
    // Security check
    if ( !pnSecAuthAction( 0,
                           'Amazon:ReaderAppreciationDayblock:',
                           "$blockinfo[title]::",
                           ACCESS_READ ) )
    {
        return;
    }

    $output = new pnHTML();
    $output->SetInputMode( _PNH_VERBATIMINPUT );

    $blockHTML = ''
        . '<div align="center">'
        . '  <a href="/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=5076"><img src="/images/events/2006-04/kp-sixflagsday-banner.gif" width="150" height="200" border="0"></a>'
        . '</div>';

    $output->Text( $blockHTML );

    // Populate block info and pass to theme
    $blockinfo['content'] = $output->GetOutput();
    return themesideblock( $blockinfo );
}

/**
 * modify block settings
 */
function amazon_readerappreciationdayblock_modify( $blockinfo )
{
    // Create output object
    $output = new pnHTML();

    // Get current content
    $vars = pnBlockVarsFromContent( $blockinfo['content'] );

    // Defaults
    if ( empty( $vars['numitems'] ) )
    {
        $vars['numitems'] = 5;
    }

    // Create row
    $row = array();
    $output->SetOutputMode( _PNH_RETURNOUTPUT );
    $row[] = $output->Text( _NUMITEMS );
    $row[] = $output->FormText( 'numitems',
                                pnVarPrepForDisplay( $vars['numitems'] ),
                                5,
                                5 );
    $output->SetOutputMode( _PNH_KEEPOUTPUT );

    // Add row
    $output->SetInputMode( _PNH_VERBATIMINPUT );
    $output->TableAddRow( $row, 'left' );
    $output->SetInputMode( _PNH_PARSEINPUT );

    // Return output
    return $output->GetOutput();
}

/**
 * update block settings
 */
function amazon_readerappreciationdayblock_update( $blockinfo )
{
    $vars['numitems'] = pnVarCleanFromInput( 'numitems' );

    $blockinfo['content'] = pnBlockVarsToContent( $vars );

    return $blockinfo;
}

?>
