<?php
// $Id: first.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 first items in shopping
// ----------------------------------------------------------------------

/**
 * initialise block
 */
function shopping_firstblock_init()
{
    // Security
    pnSecAddSchema( 'Shopping:Firstblock:', 'Block title::' );
}

/**
 * get information on block
 */
function shopping_firstblock_info()
{
    // Values
    return array( 'text_type' => 'First',
                  'module' => 'Shopping',
                  'text_type_long' => 'Show first example items (alphabetical)',
                  'allow_multiple' => true,
                  'form_content' => false,
                  'form_refresh' => false,
                  'show_preview' => true );
}

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

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

    $blockHTML =
         "<div align=\"center\">"

        // Target
        ."<a href=\"http://click.linksynergy.com/fs-bin/click?id=5hShjPYxFP4&offerid=45613.10000100&subid=0&type=4\" target=\"kpstore\"><IMG border=\"0\" width=\"120\" height=\"90\" alt=\"Shop Kids 120x90\" src=\"http://ad.linksynergy.com/fs-bin/show?id=5hShjPYxFP4&bids=45613.10000100&subid=0&type=4\"></a>"
        ."<br/><br/>"

        // Wal-Mart.com USA, LLC
        ."<a href=\"http://click.linksynergy.com/fs-bin/click?id=5hShjPYxFP4&offerid=40579.10000055&type=4&subid=0\" target=\"kpstore\"><IMG width=\"120\" height=\"90\" alt=\"Toys_120x90_v2\" border=\"0\" src=\"http://www.walmart.com/a/lks/toys_120x90_v2.gif\"></a><IMG border=\"0\" width=\"1\" height=\"1\" src=\"http://ad.linksynergy.com/fs-bin/show?id=5hShjPYxFP4&bids=40579.10000055&type=4&subid=0\">"
        ."<br/><br/>"

        // 1-800-FLOWERS.COM
        ."<a href=\"http://click.linksynergy.com/fs-bin/click?id=5hShjPYxFP4&offerid=42865.10000318&type=4&subid=0\" target=\"kpstore\"><IMG width=\"120\" height=\"90\" alt=\"Send Flowers\" border=\"0\" src=\"http://affiliate.1800flowers.com/graphics/generic/XF11b05aF2.gif\"></a><IMG border=\"0\" width=\"1\" height=\"1\" src=\"http://ad.linksynergy.com/fs-bin/show?id=5hShjPYxFP4&bids=42865.10000318&type=4&subid=0\">"
        ."<br/><br/>"

        // Oriental Trading Co
//        ."<a href=\"http://click.linksynergy.com/fs-bin/click?id=5hShjPYxFP4&offerid=10012.10000108&type=4&subid=0\" target=\"kpstore\"><IMG width=\"120\" height=\"90\" alt=\"Holiday 2003\" border=\"0\" src=\"http://www.oriental.com/images/Holiday_2003_120x90.jpg\"></a><IMG border=\"0\" width=\"1\" height=\"1\" src=\"http://ad.linksynergy.com/fs-bin/show?id=5hShjPYxFP4&bids=10012.10000108&type=4&subid=0\">"

        .'<a href="http://click.linksynergy.com/fs-bin/click?id=5hShjPYxFP4&offerid=10012.15&type=4&subid=0" target="kpstore"><IMG  width="120" height="90" alt="120x90otcstandard2" border="0" src="http://www.orientaltrading.com/images/banners/oriental120x90.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=5hShjPYxFP4&bids=10012.15&type=4&subid=0">'
        ."<br/><br/>"

        ."<a href=\"/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=12&page=1\">More...</a>"

        ."</div>\n";
    $output->Text( $blockHTML );

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



/*
function shopping_firstblock_display( $blockinfo )
{
    // Security check
    if ( !pnSecAuthAction( 0,
                           'Shopping:Firstblock:',
                           "$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( 'Shopping' );
    list( $dbconn ) = pnDBGetConn();
    $pntable =pnDBGetTables();
    $shoppingtable = $pntable['shopping'];
    $shoppingcolumn = &$pntable['shopping_column'];

    // Query
    $sql = "SELECT $shoppingcolumn[tid],
                   $shoppingcolumn[name]
            FROM $shoppingtable
            ORDER by $shoppingcolumn[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,
                              'Shopping::',
                              "$name::$tid",
                              ACCESS_OVERVIEW ) )
        {
            if ( pnSecAuthAction( 0,
                                  'Shopping::',
                                  "$name::$tid",
                                  ACCESS_READ ) )
            {
                $output->URL( pnModURL( 'Shopping',
                                        '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 shopping_firstblock_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 shopping_firstblock_update( $blockinfo )
{
    $vars['numitems'] = pnVarCleanFromInput( 'numitems' );

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

    return $blockinfo;
}

?>
