Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/includes/blocks/button.php
<?php
// File: $Id: button.php,v 1.19 2001/12/04 00:50:22 gregorrothfuss Exp $ $Name:  $
// ----------------------------------------------------------------------
// 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: Patrick Kellum
// Purpose of file: Display a list of button links in random order
// ----------------------------------------------------------------------

$blocks_modules['button'] = array (
    'func_display' => 'blocks_button_display',
    'func_update' => 'blocks_button_update',
    'func_edit' => 'blocks_button_edit',
    'text_type' => 'Button',
    'text_type_long' => 'Button Link Block',
    'allow_multiple' => true,
    'form_content' => false,
    'form_refresh' => false,
    'show_preview' => true
);

addinstanceschemainfo('Buttonblock::', 'Block name:Target URL:Image URL');

function blocks_button_display($row)
{
    global $pntable, $dbconn;
    $buttons = array ();
    $column = &$pntable['blocks_buttons_column'];
    $result = $dbconn->Execute("SELECT $column[title] as title, $column[url] as url, $column[images] as images
                              FROM $pntable[blocks_buttons]
                              WHERE $column[bid]=$row[bid]");
    while(!$result->EOF) {
        $brow = $result->getRowAssoc(false);
        $result->MoveNext();
        $buttons[] = $brow;
    }
    srand(time());
    shuffle($buttons);
    shuffle($buttons);
    $row['content'] = '<center>';
    $content = 0;
    foreach ($buttons as $v)
    {
        $img = explode('|', $v['images']);
        if (count($img) > 1)
        {
            $x = rand(0, count($img) - 1);
            $img = $img[$x];
        } else {
            $img = $img[0];
        }
        $v['title'] = stripslashes($v['title']);
        if (!authorised(0, 'Buttonblock::', "$row[title]:$url:$img", ACCESS_READ)) {
            continue;
        }
        $row['content'] .= "<a href=\"$v[url]\" target=\"_blank\" title=\"$v[title]\"><img src=\"$img\" alt=\"$v[title]\" border=\"0\" $imgsize[3]></a><br>\n";
        $content = 1;
    }
    $row['content'] .= '</center>';
    if ($content == 1) {
        themesideblock($row);
    }
}

function blocks_button_update($vars)
{
    global $pntable, $dbconn;
    // add link
    if ($vars['button_name'] && $vars['button_url'] && $vars['button_image'])
    {
        $column = &$pntable['blocks_buttons_column'];

// FTO add SEQ suffix avoid objects conflict in Oracle

        $nextid = $dbconn->GenId("{$pntable['blocks_buttons']}_SEQ");
        $dbconn->Execute("INSERT INTO $pntable[blocks_buttons] ($column[id], $column[bid], $column[title], $column[url], $column[images]) VALUES ($nextid, $vars[bid], '$vars[button_name]', '$vars[button_url]', '$vars[button_image]')");
    }
    // update link name
    if (count($vars['bname']))
    {
        foreach ($vars['bname'] as $k=>$v)
        {
            if ($v)
            {
                $v = addslashes($v);
                $column = &$pntable['blocks_buttons_column'];
                $dbconn->Execute("UPDATE $pntable[blocks_buttons] SET $column[title]='$v' WHERE $column[id]=$k");
            }
        }
    }
    // update link url
    if (count($vars['bname']))
    {
        foreach ($vars['burl'] as $k=>$v)
        {
            if ($v)
            {
                $v = addslashes($v);
                $column = &$pntable['blocks_buttons_column'];
                $dbconn->Execute("UPDATE $pntable[blocks_buttons] SET $column[url]='$v' WHERE $column[id]=$k");
            }
        }
    }
    // remove link
    if (count($vars['delete_link']))
    {
        foreach ($vars['delete_link'] as $v)
        {
            if ($v)
            {
                $column = &$pntable['blocks_buttons_column'];
                $dbconn->Execute("DELETE FROM $pntable[blocks_buttons] WHERE $column[id]=$v");
            }
        }
    }
    // add image
    if (count($vars['images']))
    {
        foreach ($vars['images'] as $k=>$v)
        {
            if ($v)
            {
                $column = &$pntable['blocks_buttons_column'];
                $result = $dbconn->Execute("SELECT $column[images] as images
                                          FROM $pntable[blocks_buttons]
                                          WHERE $column[id]=$k");
                $brow = $result->GetRowAssoc(false);
                $result->MoveNext();
                if ($brow['images'])
                {
                    $images = "$brow[images]|$v";
                } else {
                    $images = $v;
                }
                $column = &$pntable['blocks_buttons_column'];
                $dbconn->Execute("UPDATE $pntable[blocks_buttons]
                                SET $column[images]='$images'
                                WHERE $column[id]=$k");
            }
        }
    }
    // remove image
    if (count($vars['bdel_img']))
    {
        foreach ($vars['bdel_img'] as $k=>$v)
        {
            $images = '';
            $flag = false;
            if (count($v))
            {
                $column = &$pntable['blocks_buttons_column'];
                $result = $dbconn->Execute("SELECT $column[images] as images
                                          FROM $pntable[blocks_buttons]
                                          WHERE $column[id]=$k");
                $brow = $result->GetRowAssoc(false);
                $result->MoveNext();
                $c = 1;
                $img = explode('|', $brow['images']);
                foreach ($img as $v2)
                {
                    if (!in_array($c, $v))
                    {
                        if ($flag)
                        {
                            $images .= '|';
                        }
                        $images .= $v2;
                        $flag = true;
                    }
                    $c++;
                }
                $column = &$pntable['blocks_buttons_column'];
                $dbconn->Execute("UPDATE $pntable[blocks_buttons] SET $column[images]='$images' WHERE $column[id]=$k");
            }
        }
    }
    return $vars;
}

function blocks_button_edit($row)
{
    global $pntable, $dbconn;
    $output = '<tr><td valign="top" class="pn-normal">Buttons:</td><td>'
        .'<table border="1" width=\"100%\"><tr><td align="center" class="pn-normal" style="text-align:center">Title</td><td align="center" class="pn-normal" style="text-align:center">URL</td><td align="center" class="pn-normal" style="text-align:center">Images</td><td align="center" class="pn-normal" style="text-align:center">Delete</td></tr>'
    ;
    $column = &$pntable['blocks_buttons_column'];
    $result = $dbconn->Execute("SELECT $column[id] as id, $column[bid] as bid, $column[title] as title, $column[url] as url, $column[images] as images
                              FROM $pntable[blocks_buttons]
                              WHERE $column[bid]=$row[bid]
                              ORDER BY $column[title]");
    while(!$result->EOF) {
        $brow = $result->GetRowAssoc(false);
        $result->MoveNext();

        $c = 1;
        $img = '';
        $buttons = explode('|', $brow['images']);
        foreach ($buttons as $v)
        {
            if ($v)
            {
                $imgsize_alt = str_replace('"', '', $imgsize[3]);
                $img .= "<img src=\"$v\" $imgsize[3] alt=\"$v - $imgsize_alt\">&nbsp;Delete:&nbsp;<input type=\"checkbox\" name=\"bdel_img[$brow[id]][]\" value=\"$c\"><br>\n";
                $c++;
            }
        }
        $brow['title'] = stripslashes($brow['title']);
        $output .= "<tr><td valign=\"top\"><input type=\"text\" name=\"bname[$brow[id]]\" size=\"30\" maxlength=\"255\" value=\"$brow[title]\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"text\" name=\"burl[$brow[id]]\" size=\"30\" maxlength=\"255\" value=\"$brow[url]\" class=\"pn-normal\"></td><td valign=\"top\" class=\"pn-normal\">$img<input type=\"text\" name=\"images[brow[id]]\" size=\"10\" maxlength=\"255\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"checkbox\" name=\"delete_link[]\" value=\"$brow[id]\" class=\"pn-normal\"></td></tr>\n";
    }
    $output .= "<tr><td><input type=\"text\" name=\"button_name\" size=\"30\" maxlength=\"255\" class=\"pn-normal\"></td><td><input type=\"text\" name=\"button_url\" size=\"30\" maxlength=\"255\" class=\"pn-normal\"></td><td colspan=\"2\" class=\"pn-normal\"><input type=\"text\" name=\"button_image\" size=\"10\" maxlength=\"255\" class=\"pn-normal\">&nbsp;&nbsp;New</td></tr>\n";
    $output .= '</table></td></tr>';
    return $output;
}
?>
Return current item: ProNuke. Postnuke To Oracle