<?php
// $Id: media.php,v 1.1.1.1 2002/09/15 22:26:15 root Exp $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Jim McDonald
// Purpose of file: Show media items in amazon
// ----------------------------------------------------------------------

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

/**
 * get information on block
 */
function amazon_mediablock_info()
{
    // Values
    return array( 'text_type' => 'Media',
                  'module' => 'Amazon',
                  'text_type_long' => 'Media Parters',
                  'allow_multiple' => true,
                  'form_content' => false,
                  'form_refresh' => false,
                  'show_preview' => true );
}

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

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

    $blockHTML = ''
        . '<div>'
        . '<div style="padding-bottom:3px"><b>Media Partners</b></div>'
        . '<div>'
        . '<a href="http://www.mix100.com" target="_blank"><img src="/images/media/media-mix100-logo02.gif" width="61" height="35" border="0"></a>'
        . '<img src="/images/global/pix.gif" width="10" height="20" border="0">'
        . '<a href="http://radio.disney.go.com/mystation/denver/" target="_blank"><img src="/images/media/media-radiodisney2.gif" width="80" height="42" border="0"></a>'
        . '</div>'
        . '<div><img src="/images/global/pix.gif" width="1" height="10" border="0"></div>'

//        . '<div align="center">'
//        . '<a href="http://cw2.trb.com" target="_blank"><img src="/images/media/media-cw2.gif" width="57" height="32" border="0"></a>'
//        . '</div>'
//
//        . '<div><img src="/images/global/pix.gif" width="1" height="16" border="0"></div>'

        . '<div align="center">'
        . '  <a href="/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=5001"><img src="/images/logos/LinkToUs.gif" width="150" height="48" border="0"></a>'
        . '</div>'


        . '</div>'
        ."\n";

    $output->Text( $blockHTML );

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

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

    // Get variables from content block
    $vars = pnBlockVarsFromContent( $blockinfo['content'] );

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

    // Database information
    pnModDBInfoLoad( 'Amazon' );
    list( $dbconn ) = pnDBGetConn();
    $pntable =pnDBGetTables();
    $amazontable = $pntable['amazon'];
    $amazoncolumn = &$pntable['amazon_column'];

    // Query
    $sql = "SELECT $amazoncolumn[tid],
                   $amazoncolumn[name]
            FROM $amazontable
            ORDER by $amazoncolumn[name]";
    $result = $dbconn->SelectLimit( $sql, $vars['numitems'] );

    if ( $dbconn->ErrorNo() != 0 )
    {
        return;
    }

    if ( $result->EOF )
    {
        return;
    }
    // Create output object
    $output = new pnHTML();

    // Display each item, permissions permitting
    for ( ; !$result->EOF; $result->MoveNext() )
    {
        list( $tid, $name ) = $result->fields;

        if ( pnSecAuthAction( 0,
                              'Amazon::',
                              "$name::$tid",
                              ACCESS_OVERVIEW ) )
        {
            if ( pnSecAuthAction( 0,
                                  'Amazon::',
                                  "$name::$tid",
                                  ACCESS_READ ) )
            {
                $output->URL( pnModURL( 'Amazon',
                                        'user',
                                        'viewdetail',
                                        array('tid' => $tid) ),
                                        $name );
            }
            else
            {
                $output->Text( $name );
            }
            $output->Linebreak();
        }

    }

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

/**
 * modify block settings
 */
function amazon_mediablock_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_mediablock_update( $blockinfo )
{
    $vars['numitems'] = pnVarCleanFromInput( 'numitems' );

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

    return $blockinfo;
}

?>
