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]
<?phpif (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 selectedwhile ($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