[DEV] Guest management MOD

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

[DEV] Guest management MOD

Post by bourmad »

Hi,

I'm working to a new mod : Guest Management.

With this mod :
- you can rename any guest user.
- you can assign guest messages to a registered user.

An I will add other features if needed.
Tell me what you think about this mod, and what you want to see in it.

Now, I have some questions :

- I want to display all messages from an unregistered user :
A query search for all messages from posts table matching post_username
I want to display all these messages in a standard view (I don't want to rewrite all).
Is it possible to do that ?

Thanks.
AbelaJohnB
Former Team Member
Posts: 5674
Joined: Fri Jul 06, 2001 11:56 pm

Post by AbelaJohnB »

About the only way possible, that I can think of off the top of my head, would be to do it based upon the IP address.


However, that has it's own set of problems. :?


Good luck!
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

In my forum, some users have registered, but they often post messages as anonymous, only entering their name (without loging).
So it's easy to associate users.

For display all messages from a guest user by its name (post_username), I think I can't use search.php.
In search.php, there are parameters for search by username (registered users), by keyword... but not by "post_username".

My goal is to make a mod without modifying any original phpBB file, so I prefer to not modify search.php.
Maybe I will do my own search, using "post_username", and display result myself.

I will post a preview (alpha) release tomorrow...
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

[ALPHA] Guest management MOD

Post by bourmad »

Finally, I have released the first alpha now.
You can download, and try it.

Its really easy to install : only some files to copy.

you can download the files here : guestmgt.zip
Night4554
Registered User
Posts: 99
Joined: Sun Apr 07, 2002 3:09 am

Post by Night4554 »

it's a promising mod, but i can't get the thing to work, so many errors...
Brandons
I am too lazy to register

Post by Brandons »

Its a good idea.. but i took a couple minutes to install..

Got this error upon clicking "List Guest Usernames"

Code: Select all

Couldn't obtain posts data

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax near 's biggest fan!'' at line 1

SELECT user_id, username FROM phpbb_users WHERE username ='P.O.D.'s biggest fan!'

Line : 173
File : /home/virtual/site7/fst/var/www/html/php/boards/admin/admin_guest_mgt.php
Looks as though if usernames have ['] it reads them
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

Brandons wrote: Couldn't obtain posts data

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax near 's biggest fan!'' at line 1

SELECT user_id, username FROM phpbb_users WHERE username ='P.O.D.'s biggest fan!'

Line : 173
File : /home/virtual/site7/fst/var/www/html/php/boards/admin/admin_guest_mgt.php


I will try to correct that.
User avatar
Mav
Former Team Member
Posts: 2261
Joined: Wed May 15, 2002 9:19 am
Location: England
Contact:

Post by Mav »

just noting my interest in this :D
haven't installed it yet, think i'll wait for the next release with the bug fixes (hopefully).
Night4554
Registered User
Posts: 99
Joined: Sun Apr 07, 2002 3:09 am

Post by Night4554 »

I second Brandons who said if usernames have ' in them it screws up. That seems to be my problem as well
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

I have corrected the problem, but forget changes to my office.
I will post them tomorrow.
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

I have corrected the problem.
This is new version of admin_guest_mgt.php file.
You need to change lines I have highlighted in RED, or replace your file with this one.
admin_guest_mgt.php wrote: <?php
/***************************************************************************
* admin_messages_assignment.php
* -------------------
* time : Aug 2002
* author : Mehdi BOURMAD
* email : [email protected]
*
*
*
***************************************************************************/

/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/

define('IN_PHPBB', 1);

$filename = basename(__FILE__);
if( !empty($setmodules) )
{
// $filename = basename(__FILE__);
$module['Users']['Guest Management'] = append_sid($filename);

return;
}

//
// Include required files, get $phpEx and check permissions
//
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_guest_mgt.' . $phpEx);

if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
{
$mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
}
else
{
//
// These could be entered via a form button
//
if( isset($HTTP_POST_VARS['list']) )
{
$mode = "list";
}
else if( isset($HTTP_POST_VARS['rename']) )
{
$mode = "rename";
}
else if( isset($HTTP_POST_VARS['assign']) )
{
$mode = "assign";
}
else
{
$mode = "";
}
}

if( $mode != "" )
{
//
// List all guest users, and display them in a table...
//
if( $mode == "list" )
{
$template->set_filenames(array(
"body" => "admin/guest_mgt_list.tpl")
);

if( isset($HTTP_GET_VARS['sortmode']) || isset($HTTP_POST_VARS['sortmode']) )
{
$sort_mode = ($HTTP_GET_VARS['sortmode']) ? $HTTP_GET_VARS['sortmode'] : $HTTP_POST_VARS['sortmode'];
}
if(isset($HTTP_POST_VARS['sortorder']))
{
$sort_order = ($HTTP_POST_VARS['sortorder'] == 'ASC') ? 'ASC' : 'DESC';
}
else if(isset($HTTP_GET_VARS['sortorder']))
{
$sort_order = ($HTTP_GET_VARS['sortorder'] == 'ASC') ? 'ASC' : 'DESC';
}
else
{
$sort_order = 'ASC';
}


$template->assign_vars(array(
"L_USER_TITLE" => $lang['Username'],
"L_COUNT_TITLE" => $lang['Posts'],
"L_LAST_POST_TITLE" => $lang['Last_Post'],
"L_RENAME" => $lang['Rename'],
"L_ASSIGN" => $lang['Assign User'],
"L_SELECT_SORT_METHOD" => $lang['Select_sort_method'],
"L_ORDER" => $lang['Order'],
"L_SUBMIT" => $lang['Sort'],
"ROW_CLASS1" => $theme['td_class1'],
"ROW_CLASS2" => $theme['td_class2'],

"L_GUEST_MGT_TITLE" => $lang['Guest Mgt List Title'],
"L_GUEST_MGT_TEXT" => $lang['Guest Mgt List Text'])
);

// Construct sort_order listbox
$select_sort_mode = '<select name="sortmode">';
$selected = ($sort_mode==$lang['Username']) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $lang['Username'] . '"' . $selected . '>' . $lang['Username'] . '</option>';
$selected = ($sort_mode==$lang['Posts']) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $lang['Posts'] . '"' . $selected . '>' . $lang['Posts'] . '</option>';
$selected = ($sort_mode==$lang['Last_Post']) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $lang['Last_Post'] . '"' . $selected . '>' . $lang['Last_Post'] . '</option>';
$select_sort_mode .= '</select>';

$select_sort_order = '<select name="sortorder">';
$selected = ($sort_order=='ASC') ? ' selected="selected"' : '';
$select_sort_order .= '<option value="ASC"' . $selected . '>' . $lang['Sort_Ascending'] . '</option>';
$selected = ($sort_order=='DESC') ? ' selected="selected"' : '';
$select_sort_order .= '<option value="DESC"' . $selected . '>' . $lang['Sort_Descending'] . '</option>';
$select_sort_order .= '</select>';

$s_form_params = '<input type=hidden name=mode value=list>';

$template->assign_vars(array(
'S_FORM_PARAMS' => $s_form_params,
'S_MODE_SELECT' => $select_sort_mode,
'S_ORDER_SELECT' => $select_sort_order)
);

// List all guest users in post table
$sql = "SELECT post_username, count(post_username) as posts, max(post_time) as last_post FROM " . POSTS_TABLE;
$sql .= " GROUP BY post_username";
switch ($sort_mode) {
case $lang['Username']:
$sql .= " ORDER BY post_username " . $sort_order;
break;
case $lang['Posts']:
$sql .= " ORDER BY posts " . $sort_order;
break;
case $lang['Last_Post']:
$sql .= " ORDER BY last_post " . $sort_order;
break;
}

if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data", "", __LINE__, __FILE__, $sql);
}
$guest_users_count = $db->sql_numrows($result);
$guest_users_rows = $db->sql_fetchrowset($result);

// for each guest user...
for($i = 0; $i < $guest_users_count; $i++)
{
$guest_username = $guest_users_rows[$i]['post_username'];
$guest_user_count = $guest_users_rows[$i]['posts'];
$guest_user_last_post = create_date($board_config['default_dateformat'], $guest_users_rows[$i]['last_post'], $board_config['board_timezone']);
if (strlen($guest_username) > 0)
{
// Look in users table is guest_user is registered
$sql = "SELECT user_id, username FROM " . USERS_TABLE .
" WHERE username ='" . AddSlashes($guest_username) . "'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data", "", __LINE__, __FILE__, $sql);
}
$users_count = $db->sql_numrows($result);
$users_rows = $db->sql_fetchrowset($result);
$guest_user_id = $users_rows[$users_count-1]['user_id'];
$guest_user_reg_name = $users_rows[$users_count-1]['username'];
// User is already registered, add a link to the profile
if ($guest_user_id > 0)
{
$guest_user_profile_url = append_sid("admin_users.$phpEx?mode=edit&u=" . $guest_user_id);
$guest_user_caption = "<a href = '" . $guest_user_profile_url . "'>" . $guest_username . "</a>";
}
else
{
$guest_user_caption = $guest_username;
}

$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

$template->assign_block_vars("guest_users", array(
"ROW_COLOR" => "#" . $row_color,
"ROW_CLASS" => $row_class,
"GUEST_USER_NAME" => $guest_user_caption,
"GUEST_USER_COUNT" => $guest_user_count,
"GUEST_USER_LAST_POST" => $guest_user_last_post,

"U_GUEST_USER_RENAME" => append_sid($filename . "?mode=rename&username=$guest_username"),
"U_GUEST_USER_ASSIGN" => append_sid($filename . "?mode=assign&username=$guest_username&posts=$guest_user_count"))
);
}
}
}
//
// Rename a guest username, or display a form for choose the new name...
//
else if( $mode == "rename" )
{
$template->set_filenames(array(
"body" => "admin/guest_mgt_rename.tpl")
);

if( isset($HTTP_GET_VARS['username']) || isset($HTTP_POST_VARS['username']) )
{
$guest_username = ($HTTP_GET_VARS['username']) ? $HTTP_GET_VARS['username'] : $HTTP_POST_VARS['username'];
}
else
{
message_die(GENERAL_ERROR, $lang['Guest Mgt Err Calling']);
}

if( isset($HTTP_GET_VARS['new_username']) || isset($HTTP_POST_VARS['new_username']) )
{
// Rename the user
$guest_new_username = ($HTTP_GET_VARS['new_username']) ? $HTTP_GET_VARS['new_username'] : $HTTP_POST_VARS['new_username'];

// Rename guest "$guest_username" to "$guest_new_username"
$sql = "UPDATE " . POSTS_TABLE;
$sql .= " SET post_username = \"" . $guest_new_username . "\"";
$sql .= " WHERE post_username = \"" . $guest_username . "\"";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data", "", __LINE__, __FILE__, $sql);
}
else
{
$message = 'Guest username ' . StripSlashes($guest_username) . ' was renamed to ' . StripSlashes($guest_new_username);
// $message .= $sql . '<br><br><a href="'.append_sid($filename."?mode=list").'">Return</a>';
$message .= '<br><br><a href="'.append_sid($filename."?mode=list").'">Return</a>';
message_die(GENERAL_MESSAGE, $message);
}
}
else
{
// Display a form for rename the user
$template->assign_vars(array(
"L_OLD_NAME" => $lang['Username'],
"L_NEW_NAME" => $lang['Rename'],
"L_RENAME" => $lang['Rename'],
"GUEST_USER_NAME" => StripSlashes($guest_username),
"ROW_CLASS1" => $theme['td_class1'],
"ROW_CLASS2" => $theme['td_class2'],

"L_GUEST_MGT_TITLE" => $lang['Guest Mgt Rename Title'],
"L_GUEST_MGT_TEXT" => $lang['Guest Mgt Rename Text'])
);

// Input box...
$s_guest_new_username = '<input type=text name="new_username" value="' . StripSlashes($guest_username) . '">';
$s_guest_new_username .= '<input type=hidden name=mode value=rename>';
$s_guest_new_username .= '<input type=hidden name=username value="'. StripSlashes($guest_username).'">';

$template->assign_vars(array(
'S_GUEST_NEW_USER_NAME' => $s_guest_new_username)
);
}
}
//
// Assign all messages from a guest username to an assigned user, or display a form for choose the registered user...
//
else if( $mode == "assign" )
{
$template->set_filenames(array(
"body" => "admin/guest_mgt_assign.tpl")
);

if( isset($HTTP_GET_VARS['username']) || isset($HTTP_POST_VARS['username']) )
{
$guest_username = ($HTTP_GET_VARS['username']) ? $HTTP_GET_VARS['username'] : $HTTP_POST_VARS['username'];
}
else
{
message_die(GENERAL_ERROR, $lang['Guest Mgt Err Calling']);
}
if( isset($HTTP_GET_VARS['posts']) || isset($HTTP_POST_VARS['posts']) )
{
$guest_user_posts = ($HTTP_GET_VARS['posts']) ? $HTTP_GET_VARS['posts'] : $HTTP_POST_VARS['posts'];
}
else
{
message_die(GENERAL_ERROR, $lang['Guest Mgt Err Calling']);
}

if( isset($HTTP_GET_VARS['registered_userid']) || isset($HTTP_POST_VARS['registered_userid']) )
{
// Assign all messages from a guest username to a registered user
$registered_userid = ($HTTP_GET_VARS['registered_userid']) ? $HTTP_GET_VARS['registered_userid'] : $HTTP_POST_VARS['registered_userid'];

// Assign all messages from guest "$guest_username" to registered user id "$registered_userid
$sql = "UPDATE " . POSTS_TABLE;
$sql .= " SET post_username = \"\", poster_id=" . $registered_userid . ", enable_sig=1";
// $sql .= ", enable_sig=(SELECT user_attachsig FROM " . USERS_TABLE . " WHERE user_id = " . $registered_userid . ")";
$sql .= " WHERE post_username = \"" . $guest_username . "\"";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data" . $sql, "", __LINE__, __FILE__, $sql);
}
else
{
$sql = "UPDATE " . USERS_TABLE;
$sql .= " SET user_posts = user_posts+" . $guest_user_posts;
$sql .= " WHERE user_id = " . $registered_userid;
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data", "", __LINE__, __FILE__, $sql);
}
else
{
$message = $guest_user_posts . ' message(s) from ' . StripSlashes($guest_username) . ' was assigned to registered user id ' . $registered_userid;
// $message .= $sql . '<br><br><a href="'.append_sid($filename."?mode=list").'">Return</a>';
$message .= '<br><br><a href="'.append_sid($filename."?mode=list").'">Return</a>';
message_die(GENERAL_MESSAGE, $message);
}
}
}
else
{
// Display a form for assign the user
$template->assign_vars(array(
"L_GUEST_NAME" => $lang['Username'],
"L_ASSIGN" => $lang['Assign User'],
"GUEST_USER_NAME" => StripSlashes($guest_username),
"ROW_CLASS1" => $theme['td_class1'],
"ROW_CLASS2" => $theme['td_class2'],

"L_GUEST_MGT_TITLE" => $lang['Guest Mgt Assign Title'],
"L_GUEST_MGT_TEXT" => $lang['Guest Mgt Assign Text'])
);

// Construct registered users listbox
$s_registered_list = '<select name="registered_userid">';
// Get all registered users from users table
$sql = "SELECT user_id, username, user_posts FROM " . USERS_TABLE . " ORDER BY username";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain posts data", "", __LINE__, __FILE__, $sql);
}
$users_count = $db->sql_numrows($result);
$users_rows = $db->sql_fetchrowset($result);
// for each guest user...
for($i = 0; $i < $users_count; $i++)
{
$user_id = $users_rows[$i]['user_id'];
$username = $users_rows[$i]['username'];
$user_posts = $users_rows[$i]['user_posts'];
$selected = (!strcasecmp($username, $guest_username))?"selected":"";
$s_registered_list .= '<option value="' . $user_id . '"' . $selected . '>' . $username . ' (' . $user_posts . ' ' . $lang['Posts'] . ') </option>';
}
$s_registered_list .= '</select>';
$s_form_params = '<input type=hidden name=mode value=assign>';
$s_form_params .= '<input type=hidden name=posts value='.$guest_user_posts.'>';

$template->assign_vars(array(

'S_FORM_PARAMS' => $s_form_params,
'S_REGISTERED_LIST' => $s_registered_list)
);
}
}
}
else
{
//
// Show the default page
//
$template->set_filenames(array(
"body" => "admin/guest_mgt_body.tpl")
);

$template->assign_vars(array(
"S_FORM_ACTION" => append_sid($filename),
"L_GUEST_MGT_SUBMIT" => $lang['Guest Mgt List Title'],

"L_GUEST_MGT_TITLE" => $lang['Guest Mgt Body Title'],
"L_GUEST_MGT_TEXT" => $lang['Guest Mgt Body Text'])
);

}

$template->pparse("body");

include('./page_footer_admin.'.$phpEx);

?>
[/b]
Brandons
I am too lazy to register

Post by Brandons »

Nice. Problem Fixed. Thanks.

Please Submit It To The Mod Database If You Havent Yet. Good Job :wink:
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

I want to improve this mod, but have no idea....
Maybe I will try to associate guests with their IP... but I'm not sure.

I also want to
- display messages from a guest before assign them,
- search for a username in message signature, and associate messages too.

I think I will finish all these changes before submit it.
Or maybe submit v1.0.0, and made changes for next release.
User avatar
Mav
Former Team Member
Posts: 2261
Joined: Wed May 15, 2002 9:19 am
Location: England
Contact:

Post by Mav »

cheers for this mod, works very nicely.
found it especially useful to reasign posts after i imported my old ezboard.
just deleted the users that the importer creates (if they've changed their username) and then use your mod to asign those posts to the new username. sweeet. :D :D
User avatar
bourmad
Registered User
Posts: 43
Joined: Sun Mar 10, 2002 6:28 pm

Post by bourmad »

You can download now version 1.0.0a2.

I have included correction for names with special characters.
I have added a preview of all posts from a guest username.

If this version have no problems, I will release it as official 1.0.0 in mods database.
Don't hesitate to post your feedback here.
Post Reply

Return to “[2.0.x] MODs in Development”