Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Creating a block
  • Posted: 12.01.2005, 02:03
     
    quasiman
    rank:
    Freshman Freshman
    registered:
     April 2003
    Status:
    offline
    last visit:
    03.07.07
    Posts:
    37
    I had a script that would externally connect to the database, and display random items from my pncommerce installation. Now I'm trying to make it a PostNuke module, and I can't seem to get it to work. I'm fairly new at PHP, so I'm probably missing something obvious to you veterans out there.

    Could someone please take a look at this? Any help would be greatly appreciated!

    [edit]
    I guess I could be a little more precise about the problem...

    After uploading the block, I go to Administration > Blocks and I see this error: "Creation attempt failed"
    If I try to make the block, I still see that error and the block doesn't create.
    [/edit]

    Code

    <?php
    if (strpos($_SERVER['PHP_SELF'], 'randomshopitem.php')) {
        die ("You can't access this file directly...");
    }


    $blocks_modules['RandItem'] = array(
        'func_display' => 'RandItem_block',
        'func_edit' => 'RandItem_edit',
        'text_type' => 'RandItem Block',
        'text_type_long' => 'Random pnCommerce Item',
        'allow_multiple' => true,
        'form_content' => false,
        'form_refresh' => false,
        'show_preview' => true
    );


        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();


    pnSecAddSchema('RandItem::', 'Block title::');

    function RandItem_block($row) {

        if (!pnSecAuthAction(0, 'randomshopitemblock::', "$row[title]::", ACCESS_READ)) {
            return;
        }

        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();
        $column = &$pntable['users_column'];
        $query = "SELECT * FROM $pntable[pncommerce_items] ORDER BY MD5(rand()) LIMIT 1";
        $results = $dbconn->Execute($query);
            if ($dbconn->ErrorNo() <> 0) {
                echo "DB Error: ".$dbconn->ErrorNo().": ".$dbconn->ErrorMsg()."<br>";
                exit();
        }
    // For all the rows that you selected
    while ($row = mysql_fetch_array($result))

    {
    // Display them to the screen...

    echo "<a href=\"../module-pncommerce-itemview-ItemID-" . $row["ItemID"] . ".phtml\"><img src=\"../modules/pncommerce/product_images/" . $row["ItemSKU"] . "tn.jpg\" border=0 alt=\"" . $row["ItemName"] . "\"></a><br />";
    echo "<a href=\"../module-pncommerce-itemview-ItemID-" . $row["ItemID"] . ".phtml\">" . $row["ItemName"] . "</a><br />";
    echo "<a href=\"../module-pncommerce-itemview-ItemID-" . $row["ItemID"] . ".phtml\">" . $row["ItemCost"] . "</a><br />";
    echo "<div align=\"left\">";
    echo "<form action=\"../index.php?module=pncommerce&func=itemedit\" method=\"post\">";
    echo "<input type='hidden' name='authid' value='".pnSecGenAuthKey()."'><font class='pn-normal'>Add</font>";
    echo "<input type='text' name='ItemQuantity' value='1' size='2'><br />";
    echo "<input type='hidden' name='ItemID' value=\"" . $row["ItemID"] . "\">";
    echo "<input type='hidden' name='Mode' value='add'>";
    echo "<input class='pn-button' TYPE='submit' VALUE='Add to my Cart'>";
    echo "<input type='hidden' name='cartview' value='on' >";
    echo "</form>";
    echo "</div>";
    }
    $results -> Close();
    $row['content'] = $content;
    return themesideblock($row);
    }
    ?>


    --
    born ok the first time
  • Posted: 12.01.2005, 04:33
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    Take a look at the 'first' block included with the example module - this is the very latest base template for writing a block. It's uses pnRender and be then be dropped into the pnblocks directory of pnCommerce.

    -Mark
  • Posted: 12.01.2005, 05:03
     
    quasiman
    rank:
    Freshman Freshman
    registered:
     April 2003
    Status:
    offline
    last visit:
    03.07.07
    Posts:
    37
    Hey Mark,

    Yeah I've been looking at that, but like I said...I'm fairly new to PHP, and most of that doesn't make sense to me.
    PnRender for instance is WAY over my head. I'm just starting out learning how to connect to databases and display information, so if I see something like:

    Code

    // Call the modules API to get the items
        $items = pnModAPIFunc('Example',
                              'user',  
                              'getall');
    I have no idea what it means, or if I even need to keep it. lol, and there's a lot of things in there I've never seen before!

    --
    born ok the first time
  • Posted: 12.01.2005, 13:46
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    That line calls the getall API from the example module. The PN API pmModAPIFunc calls a module API function; the API takes a number of parameters. I suggest a review of the development resources especially the API reference (linked in the development resources block to the left).

    I would also suggest a look at the available API's made available as part of the pnCommerce module. It would seem that, at least, these two would be pre-requisites to writing a block for pnCommerce.

    -Mark

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula