Slavok wrote:

You want to say that you rename $db to $db_pun in 'include/common.php'? It's not a good way. Place code were you have problem here or send an e-mail to me

The code is the above just pasted into the hello world module tutorial in #0

If I use some other php code instead it works, but the code in #0 doesn't and give the mentioned error. hmm

I still get the same error.
I have tried to remove the db connection, both with or without the close connection lines, rename the db connection variable (-> $db_pun so it doesn't conflict with Joomla's), pretty much every option available with the above code lines...still same error hmm don't know what I'm doing wrong... sad

sry forgot to mention, that before the above code is the following

$db = mysql_connect("server", "user", "password")or die("error message!");
mysql_select_db("dbname",$db)or die("error message 2!");

and. it works if I just create a .php page with the code, but when it's incorporated in a joomla module it doesn't (above error), the db is the same for both punbb and Joomla hmm

it's pretty weird... can anyone elaborate what the error means? sad

Is there any other way to get the username?

PunBB version 1.2.17

I would like to create a Joomla 1.5 module which shows the punBB username. I have been looking at:
http://dev.joomla.org/component/option, … llo_world/

I have then tried to put the following code in the module file, helper file and default.php (/tmpl/), but I get the error below.
-Fatal error: Call to a member function query() on a non-object in /var/www/...site.../forum/include/functions.php on line 125

If I put the code in another file, and just use a wrapper it works.

define('PUN_ROOT', './forum/');
require PUN_ROOT.'include/common.php';
define('PUN_QUIET_VISIT', 1);

echo 'Logged in as: <b>'.pun_htmlspecialchars($pun_user['username']).'</b>';

I want to have a page which can only be viewed if the user is logged in, also I want a login box if the user isn't logged in, so the user can login on that page.

but I'm not quite sure what I need and what I can remove this is what I have at the moment...which work, there's properly alot of the code which isn't needed...

<?php
define('PUN_ROOT', './fora/');
require PUN_ROOT.'include/common.php';
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
?>

Hello 
<?php 
//echo pun_htmlspecialchars($pun_user['username']); 


if ($pun_user['is_guest'])
{
echo ("please log in");

//alot from login.php

// Load the login.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';

$action = isset($_GET['action']) ? $_GET['action'] : null;

if (isset($_POST['form_sent']) && $action == 'in')
{
    $form_username = trim($_POST['req_username']);
    $form_password = trim($_POST['req_password']);

    $username_sql = ($db_type == 'mysql' || $db_type == 'mysqli') ? 'username=\''.$db->escape($form_username).'\'' : 'LOWER(username)=LOWER(\''.$db->escape($form_username).'\')';

    $result = $db->query('SELECT id, group_id, password, save_pass FROM '.$db->prefix.'users WHERE '.$username_sql) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
    list($user_id, $group_id, $db_password_hash, $save_pass) = $db->fetch_row($result);

    $authorized = false;

    if (!empty($db_password_hash))
    {
        $sha1_in_db = (strlen($db_password_hash) == 40) ? true : false;
        $sha1_available = (function_exists('sha1') || function_exists('mhash')) ? true : false;

        $form_password_hash = pun_hash($form_password);    // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)

        if ($sha1_in_db && $sha1_available && $db_password_hash == $form_password_hash)
            $authorized = true;
        else if (!$sha1_in_db && $db_password_hash == md5($form_password))
        {
            $authorized = true;

            if ($sha1_available)    // There's an MD5 hash in the database, but SHA1 hashing is available, so we update the DB
                $db->query('UPDATE '.$db->prefix.'users SET password=\''.$form_password_hash.'\' WHERE id='.$user_id) or error('Unable to update user password', __FILE__, __LINE__, $db->error());
        }
    }

    if (!$authorized)
        message($lang_login['Wrong user/pass'].' <a href=test.php?action=forget">'.$lang_login['Forgotten pass'].'</a>');

    // Update the status if this is the first time the user logged in
    if ($group_id == PUN_UNVERIFIED)
        $db->query('UPDATE '.$db->prefix.'users SET group_id='.$pun_config['o_default_user_group'].' WHERE id='.$user_id) or error('Unable to update user status', __FILE__, __LINE__, $db->error());

    // Remove this users guest entry from the online list
    $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape(get_remote_address()).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());

    $expire = ($save_pass == '1') ? time() + 31536000 : 0;
    pun_setcookie($user_id, $form_password_hash, $expire);

    redirect(htmlspecialchars($_POST['redirect_url']), $lang_login['Login redirect']);
}


else if ($action == 'out')
{
    if ($pun_user['is_guest'] || !isset($_GET['id']) || $_GET['id'] != $pun_user['id'])
    {
        header('Location: index.php');
        exit;
    }

    // Remove user from "users online" list.
    $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$pun_user['id']) or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());

    // Update last_visit (make sure there's something to update it with)
    if (isset($pun_user['logged']))
        $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $db->error());

    pun_setcookie(1, random_pass(8), time() + 31536000);

    redirect('index.php', $lang_login['Logout redirect']);
}


else if ($action == 'forget' || $action == 'forget_2')
{
    if (!$pun_user['is_guest'])
        header('Location: index.php');

    if (isset($_POST['form_sent']))
    {
        require PUN_ROOT.'include/email.php';

        // Validate the email-address
        $email = strtolower(trim($_POST['req_email']));
        if (!is_valid_email($email))
            message($lang_common['Invalid e-mail']);

        $result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE email=\''.$db->escape($email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());

        if ($db->num_rows($result))
        {
            // Load the "activate password" template
            $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/activate_password.tpl'));

            // The first row contains the subject
            $first_crlf = strpos($mail_tpl, "\n");
            $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
            $mail_message = trim(substr($mail_tpl, $first_crlf));

            // Do the generic replacements first (they apply to all e-mails sent out here)
            $mail_message = str_replace('<base_url>', $pun_config['o_base_url'].'/', $mail_message);
            $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);

            // Loop through users we found
            while ($cur_hit = $db->fetch_assoc($result))
            {
                // Generate a new password and a new password activation code
                $new_password = random_pass(8);
                $new_password_key = random_pass(8);

                $db->query('UPDATE '.$db->prefix.'users SET activate_string=\''.pun_hash($new_password).'\', activate_key=\''.$new_password_key.'\' WHERE id='.$cur_hit['id']) or error('Unable to update activation data', __FILE__, __LINE__, $db->error());

                // Do the user specific replacements to the template
                $cur_mail_message = str_replace('<username>', $cur_hit['username'], $mail_message);
                $cur_mail_message = str_replace('<activation_url>', $pun_config['o_base_url'].'/profile.php?id='.$cur_hit['id'].'&action=change_pass&key='.$new_password_key, $cur_mail_message);
                $cur_mail_message = str_replace('<new_password>', $new_password, $cur_mail_message);

                pun_mail($email, $mail_subject, $cur_mail_message);
            }

            message($lang_login['Forget mail'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
        }
        else
            message($lang_login['No e-mail match'].' '.htmlspecialchars($email).'.');
    }


    $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_login['Request pass'];
    $required_fields = array('req_email' => $lang_common['E-mail']);
    $focus_element = array('request_pass', 'req_email');
    require PUN_ROOT.'header.php';

?>
<div class="blockform">
    <h2><span><?php echo $lang_login['Request pass'] ?></span></h2>
    <div class="box">
        <form id="request_pass" method="post" action="test.php?action=forget_2" onsubmit="this.request_pass.disabled=true;if(process_form(this)){return true;}else{this.request_pass.disabled=false;return false;}">
            <div class="inform">
                <fieldset>
                    <legend><?php echo $lang_login['Request pass legend'] ?></legend>
                    <div class="infldset">
                        <input type="hidden" name="form_sent" value="1" />
                        <input id="req_email" type="text" name="req_email" size="50" maxlength="50" />
                        <p><?php echo $lang_login['Request pass info'] ?></p>
                    </div>
                </fieldset>
            </div>
            <p><input type="submit" name="request_pass" value="<?php echo $lang_common['Submit'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
        </form>
    </div>
</div>
<?php

    require PUN_ROOT.'footer.php';
}


if (!$pun_user['is_guest'])
    header('Location: index.php');

// Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
$redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';

$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Login'];
$required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);
$focus_element = array('login', 'req_username');
require PUN_ROOT.'header.php';

?>
<div class="blockform">
    <h2><span><?php echo $lang_common['Login'] ?></span></h2>
    <div class="box">
        <form id="login" method="post" action="test.php?action=in" onsubmit="return process_form(this)">
            <div class="inform">
                <fieldset>
                    <legend><?php echo $lang_login['Login legend'] ?></legend>
                        <div class="infldset">
                            <input type="hidden" name="form_sent" value="1" />
                            <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                            <label class="conl"><strong><?php echo $lang_common['Username'] ?></strong><br /><input type="text" name="req_username" size="25" maxlength="25" tabindex="1" /><br /></label>
                            <label class="conl"><strong><?php echo $lang_common['Password'] ?></strong><br /><input type="password" name="req_password" size="16" maxlength="16" tabindex="2" /><br /></label>
                            <p class="clearb"><?php echo $lang_login['Login info'] ?></p>
                            <p><a href="register.php" tabindex="4"><?php echo $lang_login['Not registered'] ?></a>  
                            <a href="test.php?action=forget" tabindex="5"><?php echo $lang_login['Forgotten pass'] ?></a></p>
                        </div>
                </fieldset>
            </div>
            <p><input type="submit" name="login" value="<?php echo $lang_common['Login'] ?>" tabindex="3" /></p>
        </form>
    </div>
</div>

<?php

}
else
{
echo pun_htmlspecialchars($pun_user['username']);
}
?>

Hey :-)

I'm pretty new to all this, hope 'you' will help me with my little projekt...

I want to make a kind og voting script not supposed to be shown in the forum, just on another 'clean' page, where the user should login with the punbb name and pass. Thereby giving them acces to the page where a certain amount of forms (let's say 5 in this case) are placed, the 5 forms "choice's" is supposed to be filled with some names (which I have in another DB)

I plan to fill the forms using:

$query  = "SELECT name FROM namelist";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Name :{$row['name']} <br>";

}

The user should then select different names in all the forms and push a button, and then update the 5 name choices to their profile, so that the next time they go to that page, the forms show the names they have previusly selected, and they can change the names again.

I would also like to be able to, differentiate between the different forms , so for example they are choice1, choice2... where I can count and rank the names which is in 'choice1' form field.

It should then be possible to extract how many have selected the different names with a mysql call...


I'm not quite sure how to do this in a good and simpel way. Hope someone have some input to get me a little further :-) thx...