1 (edited by mixart 2007-12-29 14:43)

Topic: message() function breaks header when using includes in template

I think I've pin-pointed this scenario where I have problems - hopefully I can explain it.

If I use user templates in my main.tpl such as this:
<pun_include "mybody.php">

and mybody.php has includes like this:

<?php include SITE_ROOT."includes/mainbody.php"; ?>

Then whenever the message function in functions.php is run it does not correctly load the header correctly:
i.e. this line

if (!defined('PUN_HEADER'))
    {
        global $pun_user;
        $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Info'];
        require PUN_ROOT.'header.php';
        // THE LINE ABOVE IS NOT LOADING THE HEADER CORRECTLY IN HEADER.PHP WHEN I HAVE THE TEMPLATE STRUCTURE ABOVE. WHEN I MAKE THE USER INCLUDES NOT HAVE INCLUDES IN THEMSELVES IT WORKS FINE
    }

Let me also add that this error only occurs when the message function is sent without a TRUE parameter (when it does not trigger a redirect). An example of the user behavior is to change your password and enter a mismatched password which triggers the message function without the redirect.

Re: message() function breaks header when using includes in template

Could you explain what you mean by "does not load the header correctly"?
Also, the message function doesn't redirect, it only adds a back link. Is that what you meant?

Could you paste a screenshot to show what you mean (eg: the difference between a normal header and a messed up header?)

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

3 (edited by mixart 2007-12-29 22:30)

Re: message() function breaks header when using includes in template

OK I've been testing by commenting out everything in my user template files and here is what I have come up with...

If I have this code in any of my user template files, it breaks and does not display the full template file:

$results_nav = $mycustomdbclass_db->GetAll("SELECT blah FROM blah WHERE blah ORDER BY disp_order ASC");

BUT, only when this function is called do I have a problem:

message($lang_prof_reg['Pass not match']);

WHEN this function is called it is OK (and does the redirect I was talking about):

message($lang_profile['Pass updated'], true);

Is my line of code out of scope somehow when the message function is called without the true parameter?

P.s. Yes "$mycustomdbclass_db" is intentional - I am using my own DB class for these calls, which works everywhere on punbb except with the message function as shown above.

Re: message() function breaks header when using includes in template

message does not do a redirect, as I said. If it does, that's something you have modified.
The 2nd parameter is used in the following code from the function:

<?php if (!$no_back_link): ?>        <p><a href="javascript: history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
<?php endif; ?>

It would be really helpful if you could give a reduced test case that someone else could replicate to help track down the issue.

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: message() function breaks header when using includes in template

OK thanks - I'll try get more specific info.

Perhaps the message function does not do a redirect but that is the outcome if the true parameter is added.

From the profile page when you edit your password and enter non-matching passwords this is called...
message($lang_prof_reg['Pass not match']);
Which displays the error message.

If you enter matching passwords and it changes the password successfully it calls this
message($lang_profile['Pass updated'], true);
Which does whatever it does then takes you to the redirect page saying "Pass updated" then directs you back to your profile page.

Put simply, my code (that one line of call that does a database call) works fine when the password matches, but does not when there is a password mismatch (or any other message).

I'll  try and gather more info or files to make it easy for you to replicate.

Re: message() function breaks header when using includes in template

mixart: You're looking at the wrong line there wink
As I said, message does not redirect. redirect does (that's why it's called redirect).

redirect('profile.php?section=essentials&id='.$id, $lang_profile['Pass updated redirect']);

That is the line that redirects you if you change your password correctly.

But yeah, it would be really great if you could give us a way to replicate the issue so we can pinpoint what's wrong.

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: message() function breaks header when using includes in template

I tracked the problem after looking more into the punbb code.

Since I'm using another database class alongside the punbb one, I had to declare another global variable ($mydbvar) in the message function.

function message($message, $no_back_link = false)
{
    global $mydbvar, $db, $lang_common, $pun_config, $pun_start, $tpl_main;

Thank you for your patience and help.

Re: message() function breaks header when using includes in template

Aha smile
Moved to Troubleshooting, since this is not a PunBB bug wink

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize