[mod] Listing attributes on users page

3rd party code for phpList

[mod] Listing attributes on users page

Postby at4z » 2:34am, Fri 10 Feb, 2006

Basically what I am looking for is a way to add the "name" attribute to one of the columns on the list of all users page.

I know this would require some lines of custom code, but I dont have the faintest idea of where to start from. Anyone willing to help out?
at4z
phpLister
 
Posts: 8
Joined: 12:06am, Wed 03 Nov, 2004

Postby bevan » 2:04pm, Fri 10 Feb, 2006

Find a php programmer and pay him a bit to do it for you. It's fairly simple and shouldn't cost much.

Btw, what do you need it for? if it's just a one time export, you could probably use the export feature of phpList. I'm not sure if it exports attributes though...
bevan
PL Master
 
Posts: 465
Joined: 8:07pm, Sun 05 Feb, 2006
Location: Buenos Aires, Argentina

Postby at4z » 12:58am, Sat 11 Feb, 2006

well I decided to take this on as my very first mini php project.

I made some progress and have it to the point where I have a column for the name attribute and I(think) I correctly queried the database for the desired information.

The only problem is what the name column is filled in with.
Here is an image of what it looks like now.
Image

What do the "Resource id #XXX" mean? What is producing the error?

I will keep trying to figure it out on my own but any expert opininions would be appreciated.
at4z
phpLister
 
Posts: 8
Joined: 12:06am, Wed 03 Nov, 2004

Postby at4z » 4:47am, Sat 11 Feb, 2006

Well, I finally figured it out. :D
at4z
phpLister
 
Posts: 8
Joined: 12:06am, Wed 03 Nov, 2004

Postby Thrasher » 11:13am, Sun 12 Feb, 2006

at4z wrote:Well, I finally figured it out. :D


Would you mind sharing the code?

I need to have Name along with email also.
Thrasher
phpLister
 
Posts: 5
Joined: 1:08am, Fri 10 Feb, 2006

Postby at4z » 9:27pm, Sun 12 Feb, 2006

this code is assuming all that you have is one attribute

first thing is to display the names on the page that lists all of the users...

/admin/users.php
line: 8

from
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist");


to
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist","namefield");



somewhere around line: 294

from
Code: Select all
$msgs = Sql_query("SELECT count(*) FROM ".$tables["usermessage"]." where userid = ".$user["id"]);
  $nummsgs = Sql_fetch_row($msgs);
  $onblacklist = isBlackListed($user["email"]);
$ls->addElement($user["email"],PageURL2("user&start=$start&id=".$user["id"].$find_url));


to
Code: Select all
$msgs = Sql_query("SELECT count(*) FROM ".$tables["usermessage"]." where userid = ".$user["id"]);
  $nummsgs = Sql_fetch_row($msgs);
  $onblacklist = isBlackListed($user["email"]);
  $resultname = mysql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]);
  $rowname = mysql_fetch_array( $resultname );
  $ls->addElement($user["email"],PageURL2("user&start=$start&id=".$user["id"].$find_url));


Somewhere around line:322
from

Code: Select all
$ls->addColumn($user["email"],"bncs",$user["bouncecount"]);


to

Code: Select all
  $ls->addColumn($user["email"],"bncs",$user["bouncecount"]);
  $ls->addColumn($user["email"],"name",$rowname["value"]);


now we edit /admin/commonlib/users.php

add this code about line 372(add it after everything, dont replace anything):


Code: Select all
if (in_array("namefield",$columns)) {
  $resultname = mysql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]);
  $rowname = mysql_fetch_array( $resultname );
     $ls->addColumn($user["email"],name,$rowname["value"]);
 }




now to display the names of the people on the subscribers of a list page...

we will edit admin/members.php
line 269:

from

Code: Select all
$ls->addColumn($user["email"],$GLOBALS['I18N']->get("# msgs"),$msgcount[0]);
       if (ENABLE_RSS) {


to
Code: Select all
$ls->addColumn($user["email"],$GLOBALS['I18N']->get("# msgs"),$msgcount[0]);
    $resultname = mysql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]);
  $rowname = mysql_fetch_array( $resultname );
     $ls->addColumn($user["email"],name,$rowname["value"]);
    if (ENABLE_RSS) {


if you want to display an attribute other than the name, or if you have more than one attribute all the sql statements will have to be something like this

SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"] and attributeid =X

X being the attribute number you would like to display

this is my first attempt at really modifying some php/mysql stuff, so it might not be pretty but it works
at4z
phpLister
 
Posts: 8
Joined: 12:06am, Wed 03 Nov, 2004

Postby bevan » 5:14pm, Mon 13 Feb, 2006

I've moved this thread to contributions and mods.

Thanks for the cotribution!! :)

Can other users please confirm whether the code and instructions worked for them.
bevan
PL Master
 
Posts: 465
Joined: 8:07pm, Sun 05 Feb, 2006
Location: Buenos Aires, Argentina

adiing attribute code

Postby hm » 1:00pm, Thu 16 Feb, 2006

I tried this code and it worked
but what should I do to veiw all the attributes?
thank you a lot
hm
phpList newbie
 
Posts: 3
Joined: 6:41pm, Sun 05 Feb, 2006

didn't work so well for me

Postby congoclash » 3:06pm, Mon 19 Feb, 2007

Imho, listing name and country is a very needed feature as it helps you to understand who your subscribers are and what type of information you should provide to them.

Unfortunately it has not worked so well for me, possibly because this code was written for an older version. On many records instead of the name I get a different attribute, eg.: address, site, ip, phone or blank (my list was successfully imported from a cvs file if it matters). And yes I have other attributes, I suppose it doesn't like that.

If anyone got this code to work on v.2.10.4 and/or knows anything about this problem, please help.
thanks in advance.
congoclash
phpList newbie
 
Posts: 2
Joined: 2:38pm, Mon 19 Feb, 2007

Postby congoclash » 6:17pm, Mon 19 Feb, 2007

It seems that if you have other attributes besides the name you need to specify the id. Like this??
Code: Select all
$resultname = mysql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"] and attributeid = 1);

but where exactly do you put it? I tried following instructions above but adding it in members.php doesn't do anything, adding it in either of users.php causes the list not to display anything.
congoclash
phpList newbie
 
Posts: 2
Joined: 2:38pm, Mon 19 Feb, 2007

Postby bobdog » 1:53am, Wed 20 Jun, 2007

Unfortunately, this does not work for me either. As stated earlier in this thread, it may not be compatible with the latest version.
bobdog
phpLister
 
Posts: 10
Joined: 2:18am, Fri 08 Jun, 2007

Postby rjc » 7:55am, Thu 04 Oct, 2007

Good news, Ladies & Gents! This mod can be made to work with 2.10.4. I haven't tried it on 2.10.5 yet; will do soon.

The mod as listed by at4z requires some slight modification to get to work with 2.10.4. Instead of trying to adjust his coding above, for clarity's sake I will simply list all the changes I made.

v2.10.4 seems to create a joined table (called phplist_user_user_attribute) with only three items: attributeid, userid, and value. I assume it creates it for faster lookup/searching. The reason why random attributes were coming out when using at4z's version in 2.10.4 was because it extracted ALL the values of ALL the attributes. So to get it working properly you must specifically state which attribute id you are talking about.

It's important to note that your user name attribute will probably be different to mine. The code below assumes that it is attributeid 2, but you will have to find out which attributeid your name field is (or whatever value you want to list). You can do this by logging into the admin, going to the Main Page, clicking "attributes" under Configuration Functions. The page that appears will list all your attributes, each in their own table, with the attributeid listed first (e.g. "Attribute: 2"). Use this value in the place of mine below (where it says attributeid=2). If someone more familiar with mySQL knows a way around this which works out of the the box for everyone, let us know.


IN ADMIN/USERS.PHP

CHANGED:
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist");

TO:
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist","namefield");


IN ADMIN/COMMONLIB/PAGES/USERS.PHP

AFTER:
Code: Select all
$ls->addElement($user["email"],PageURL2("user&start=$start&id=".$user["id"].$find_url));

ADDED:
Code: Select all
// RJC ADDED for "List attributes in users list" mod
  if (in_array("namefield",$columns)) {
    $resultname1 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=2");
    $rowname1 = Sql_fetch_array( $resultname1 );
    $fullname = $rowname1["value"];

  $ls->addColumn($user["email"],"name",$fullname,"","left");
  }
// END RJC ADDED


IN ADMIN/MEMBERS.PHP

AFTER:
Code: Select all
$ls->addElement($user["email"],PageUrl2("user&id=".$user["id"]));

ADDED:
Code: Select all
  // RJC ADDED for "List attributes in users list" mod
    $resultname1 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=2");
    $rowname1 = Sql_fetch_array( $resultname1 );
    $fullname = $rowname1["value"];
    $ls->addColumn($user["email"],"name",$fullname,"","left");
  // END RJC ADDED


at4z also made some changes in admin/users.php (the two titled "Somewhere around line 294" and Somewhere around line 322"). I found that these did not seem to be necessary, as the users.php in commonlib seems to override these anyway. Someone correct me if I'm wrong.

Enhanced Version:
As an enhancement, my names are actually made from two components in the database, "First Name" and "Last Name", not just a single "Full Name". So I've provided an enhanced version below which actually retrieves two attributes, attributeid 2 & 3, and joins them together. If you want to do the same, use the code below:

IN ADMIN/USERS.PHP
(Same as above)
CHANGED:
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist");

TO:
Code: Select all
$columns = array("messages","lists","bounces","rss","blacklist","namefield");


IN ADMIN/COMMONLIB/PAGES/USERS.PHP

AFTER:
Code: Select all
$ls->addElement($user["email"],PageURL2("user&start=$start&id=".$user["id"].$find_url));

ADDED:
Code: Select all
  // RJC ADDED for "List attributes in users list" mod
  if (in_array("namefield",$columns)) {
    $resultname1 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=2");
    $rowname1 = Sql_fetch_array( $resultname1 );
    $resultname2 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=3");
    $rowname2 = Sql_fetch_array( $resultname2 );
   $fullname = $rowname1["value"] . " " . $rowname2["value"];
   $namelength = strlen($fullname);
   if ($namelength > 20) { $fullname = $rowname1["value"] . "<br>" . $rowname2["value"]; }   // If name is long, split first & last names over two lines
   $ls->addColumn($user["email"],"name",$fullname,"","left");
  }
  // END RJC ADDED


IN ADMIN/MEMBERS.PHP

AFTER:
Code: Select all
$ls->addElement($user["email"],PageUrl2("user&id=".$user["id"]));

ADDED:
Code: Select all
  // RJC ADDED for "List attributes in users list" mod
    $resultname1 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=2");
    $rowname1 = Sql_fetch_array( $resultname1 );
    $resultname2 = Sql_query("SELECT * FROM ".$tables["user_attribute"]." where userid = ".$user["id"]." and attributeid=3");
    $rowname2 = Sql_fetch_array( $resultname2 );
   $fullname = $rowname1["value"] . " " . $rowname2["value"];
   $namelength = strlen($fullname);
   if ($namelength > 20) { $fullname = $rowname1["value"] . "<br>" . $rowname2["value"]; }   // If name is long, split first & last names over two lines
   $ls->addColumn($user["email"],"name",$fullname,"","left");
  // END RJC ADDED
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby mike240se » 1:16am, Mon 05 Nov, 2007

thanks so much for this, i needed exactly this!


One question, which code would i remove to get rid of the "key" column and the black list column? Adding the name has made the table too wide and i would like to remove those 2 columns i dont need. thanks
mike240se
phpLister
 
Posts: 6
Joined: 1:14am, Mon 05 Nov, 2007

Postby rjc » 1:34am, Tue 06 Nov, 2007

Mike240se,

Glad it helped you. I also found that it was too cluttered, so I removed the "key" column, and shortened the name of the blacklist from "bl l" to "bl"

To remove a column, just comment out the lines. You comment out by using a double slash (//) at the start of the line.


IN ADMIN/COMMONLIB/PAGES/USERS.PHP

To Remove the "bl l" column, find the line that starts with

Code: Select all
  if (in_array("blacklist",$columns)) {


and comment out that line and all others until the closing }, like this:

Code: Select all
//  if (in_array("blacklist",$columns)) {
//    $onblacklist = isBlackListed($user["email"]);
//    $ls->addColumn($user["email"],$GLOBALS['I18N']->get('bl l'),
//    $onblacklist?$GLOBALS["img_tick"]:$GLOBALS["img_cross"]);
//  }


To remove the "key" column, find the line that starts with:

Code: Select all
  if (isset($user['foreignkey'])) {


and comment out that line and all others until the closing }, like this:

Code: Select all
//  if (isset($user['foreignkey'])) {
//    $ls->addColumn($user["email"],$GLOBALS['I18N']->get('key'), $user["foreignkey"]);
//  }



Note that instead of removing the blacklist column, I shortened it's name by changing the third line
from
Code: Select all
$ls->addColumn($user["email"],$GLOBALS['I18N']->get('bl l'),

to:
Code: Select all
$ls->addColumn($user["email"],$GLOBALS['I18N']->get('bl'),


It then seemed to fit everything fine.
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby bob denar » 6:45pm, Wed 19 Dec, 2007

Thank you for your efforts.
It doesn't work for me. On my phplist version 2.10.5, I tried the "enhanced" version from rjc (Posted: 7:55am, Thu 04 Oct, 2007).
The page just shows the title at the top, the rest is blank.
I am looking forward to find a solution...
bob denar
phpLister
 
Posts: 8
Joined: 7:50pm, Tue 18 Dec, 2007

Next

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests

cron