PDA

View Full Version : Brian or Zachery...can you look at this?


Fargo
11-14-2004, 01:25 AM
This is the code for a module im working on and im really hoping you can spot my problem.

How it works:
The module first looks at the siteid (a variable passed from the main CMPS page) and secondly looks at the action (do) variable passed to determine what content to display on that page.

Initially, I had coded this as a standalone page for development purposes, but now its time to actually make it a functioning module.

Everything worked perfectly (though the code may not be very efficient) when it was a standalone page, however, now that ive made my few changes so it can be included in a CMPS page im having a problem with a particular section of the code that generates a screenshots page. If you look below, the troublesome code starts with:

//we want further information to determine what action to take
//starting with most complex action
if ($_REQUEST['do'] == 'screenshots')
{
//$thispage = $_SERVER['PHP_SELF']
$perpage = 18;
$pertr = 3;



<?php
//define('VBA_PORTAL', true);
//define('VBA_PAGE', 'forums_home');
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'game_content'); // change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(

);

// get special data templates from the datastore
$specialtemplates = array(

);

// pre-cache templates used by all actions
$globaltemplates = array(
'gamedisplay','gamedetail','gamemaps','gamesysreq','gameoverview','gamescreensho ts','gamescreenshotsbit',
);

// pre-cache templates used by specific actions
$actiontemplates = array(

);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');


// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
globalize($_GET, $_REQUEST, $_SERVER, array(
'page' => INT, 'siteid' => INT,));

//first things first - check for a siteid since its required by the entire script
if (empty($_REQUEST['siteid']))
{
//Return proper error here. For dev. purposes, we'll perform default action
//$getgames = $DB_site->query("SELECT * FROM site_game_info");
}
else
{

//we want further information to determine what action to take
//starting with most complex action
if ($_REQUEST['do'] == 'screenshots')
{
//$thispage = $_SERVER['PHP_SELF']
$perpage = 18;
$pertr = 3;

// Verify arguments
///////////////////////
$type = $_REQUEST['type'] ? $_REQUEST['type'] : 1;

// Query: count rows
////////////////////////

$result = $DB_site->query_first("SELECT COUNT(*) AS count FROM site_game_screenshots WHERE siteid=$siteid");

// Build page scope
///////////////////////
$pagenumber = $page > 0 ? $page : 1;
$rows = $result['count'];
$pages = ceil($rows / $perpage);

if ($pagenumber < 1)
{
$pagenumber = 1;
}
else if ($pagenumber > $rows)
{
$pagenumber = $rows;
}

$minlimit = ($pagenumber - 1) * $perpage+1;
$maxlimit = ($pagenumber) * $perpage;

if ($maxlimit > $rows)
{
$maxlimit = $rows;
$minlimit = $minlimit > $rows ? $rows-$perpage : $minlimit;
}

$minlimit = $minlimit <= 0 ? 1 : $minlimit;
$pagenav = construct_page_nav($rows,"$_SERVER[PHP_SELF]?$session[sessionurl]siteid=$siteid&amp;do=screenshots", "&amp;pp=$perpage");

// Request: thumbnail picture
///////////////////////////////
if ($type == 1)
{
// Query: fetch profile pictures
////////////////////////////////////


$images = $DB_site->query("SELECT * FROM site_game_screenshots WHERE siteid=$siteid LIMIT " . ($minlimit-1) . ", $perpage");

$type = 'image';

$count = 1;
$rows = $DB_site->num_rows($images);

if (!$rows)
{
//eval('$games .= "' . fetch_template('gamescreenshotsbit') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamescreenshotsbit') . '";');
}
else
{
while ($image = $DB_site->fetch_array($images))
{
//eval('$games .= "' . fetch_template('gamescreenshotsbit') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamescreenshotsbit') . '";');

if ($count == $pertr && $count != $rows)
$count = 0;

$count++;
}

while ($count != 1 && $count <= $pertr)
{
//eval('$games .= "' . fetch_template('gamescreenshotsbit') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamescreenshotsbit') . '";');

$count++;
}
}
}
}

else
{
$getgames = $DB_site->query("SELECT * FROM site_game_info WHERE siteid=$siteid");

while($game = $DB_site->fetch_array($getgames))
{
//call bbcodeparse.php to parse bbcode within overview and requirements fields
require_once('./includes/functions_bbcodeparse.php');
$game['overview'] = parse_bbcode2($game['overview'], 1, 1, 1, 1);
$game['rec_sys_req'] = parse_bbcode2($game['rec_sys_req'], 1, 1, 1, 1);
$game['min_sys_req'] = parse_bbcode2($game['min_sys_req'], 1, 1, 1, 1);

if ($_REQUEST['do'] == 'all')
{
//eval('$games .= "' . fetch_template('gamedetail') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamedetail') . '";');
}
else if ($_REQUEST['do'] == 'overview')
{
//eval('$games .= "' . fetch_template('gameoverview') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gameoverview') . '";');
}
else if ($_REQUEST['do'] == 'sysreq')
{
//eval('$games .= "' . fetch_template('gamesysreq') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamesysreq') . '";');
}
else if ($_REQUEST['do'] == 'maps')
{
//eval('$games .= "' . fetch_template('gamemaps') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamemaps') . '";');
}
}
}
}


////NAVBIT CODE NOT NECESSARY DUE TO TEMPLATE EDITS - LEFT HERE JUST CUZ I CAN
$navbits = array();
$navbits[$parent] = 'Game Info';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
//////////////////////////////////////////////////////////////////////////////

if (empty($_REQUEST['siteid']))
{
//SEE NO EVIL, HEAR NO EVIL, RETURN NO EVIL
}
else
{
if (empty($_REQUEST['do']))
{
//SOMEONE MUSTA JACKED OUR VARIABLES!
//RETURN EMPTY
}
else if ($_REQUEST['do'] == 'screenshots')
{
//eval('$HTML = "' . fetch_template('gamescreenshots') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamescreenshots') . '";');
}
else
{
//eval('$HTML = "' . fetch_template('gamedisplay') . '";');
eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('gamedisplay') . '";');
}
}

//print_portal_output($home, $HTML);
?>


Please look and see if there is anything in particular that may cause the page to die (empty white page, when calling index.php?siteid=xx&do=screenshots).

I realize youre both busy with your own lives and projects, but ive exhausted my ability to figure it out in the past 2 days and its a crutial part of this weekends deadline...sigh.


I noticed the PHP code above added a space in the template definations for 'gamescreenshotsbit' - this space is not in the actual file, nor is it shown in the message text. Obviously a small bug in vbulletins editor.

Fargo
11-14-2004, 02:15 AM
well, seems that this:
$pages = ceil($rows / $perpage);

was causing my big problem there. I dunno why it was but commenting it out worked and the script still (appears) to work properly.

Sorry for the constant posts this weekend guys...its been hectic!

Our Sponsors
 

Brian
11-15-2004, 07:05 PM
Glad you got it figured out. :)