I have this class (a simplified version since only 2 functions are the problem)
<?php
if (!defined('IN_PHPBB'))
{
exit;
}
class decks
{
/*
Inserts cards to a user
@param int id the id of the card
@param int person the id of the person
*/
function insert($id, $person)
{
global $db;
$sql_arr = array(
'cardid' => $id,
'userid' => $person,
'status' => "undefined"
);
$sql = 'INSERT INTO ' . USER_CARDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_arr);
$db->sql_query($sql);
}
/*
Add random normal cards to a user
@param int amount the amount of normal cards to be awarded
@param int person the user id of the person getting cards
@param boolean bbcode if the bbcode is required or not
@return the images/bbcodes as a string
*/
function addRandomNormal($amount, $person, $bbcode = false)
{
global $db;
$sql_array = array(
'SELECT' => 'c.id, c.url, d.deck, d.name, c.cardid',
'FROM' => array(CARDS_TABLE => 'c'),
'LEFT_JOIN' => array(
array(
'FROM' => array(DECKS_TABLE => 'd'),
'ON' => 'd.deckid = c.deckid'
)
),
'WHERE' => "d.deny = 0 and d.worth=1",
'ORDER_BY' => "rand()"
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query_limit($sql, $amount);
while($row = $db->sql_fetchrow($result))
{
insert($row['id'], $row['person']);
$card[] = ($bbcode) ? $card[] = '[card]' . basename($row['url'], '.png') . '[/card]' : '<img src="' . $row['url'] . '" alt="' . $row['name'] . $row['cardid'] . '" />';
}
$return = (is_array($card)) ? implode(' ' , $card) : '';
return $return;
}
}
?>
its being called as so
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_decks.' . $phpEx);
$decks = new decks();
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['user_id'] == ANONYMOUS)
{
login_box('', $user->lang['LOGIN']);
}
elseif ($user->data['is_bot'])
{
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}
page_header('Games - Booster Packs');
$template->set_filenames(
array(
'body' => 'game-booster.html',
)
);
if(isset($_POST['Submit']))
{
$prize[] = "<br/><br/>";
$prize[] = $decks->addRandomNormal(11, $user->data['user_id']);
}
$template->assign_vars(
array(
'PRIZE' => (is_array($prize)) ? implode("" , $prize ) : '',
)
);
page_footer();
?>
The error i'm getting
Fatal error: Call to undefined function insert() in /home///new/includes/functions_decks.php on line 281
it seems it wont let me call insert from within addRandomNormal. I've done this successfully before, so i'm wondering if its something to do with it being a class, since before it wasn't.
How do i solve this?