Page through users list by 1st letter of lastname

17 years 7 months ago #20662 by sanzalure
I wanted to page through our member list by first letter of their last name instead of by groups of 20, so I made the following changes in the code.

1. in /administrator/components/com_comprofiler/comprofiler.class.php

after the function: (line 1031)

function writePagesLinks($limitstart, $limit, $total,$ue_base_url,$search=null,$prefix="")

I inserted this new function:

[code:1]
function writeAlphaLinks ($vAlpha,$ue_base_url)
{$vHREFS = '';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=A') . '">' . ($vAlpha=='A'?'<STRONG>A</STRONG>':'a') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=B') . '">' . ($vAlpha=='B'?'<STRONG>B</STRONG>':'b') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=C') . '">' . ($vAlpha=='C'?'<STRONG>C</STRONG>':'c') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=D') . '">' . ($vAlpha=='D'?'<STRONG>D</STRONG>':'d') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=E') . '">' . ($vAlpha=='E'?'<STRONG>E</STRONG>':'e') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=F') . '">' . ($vAlpha=='F'?'<STRONG>F</STRONG>':'f') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=G') . '">' . ($vAlpha=='G'?'<STRONG>G</STRONG>':'g') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=H') . '">' . ($vAlpha=='H'?'<STRONG>H</STRONG>':'h') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=I') . '">' . ($vAlpha=='I'?'<STRONG>I</STRONG>':'i') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=J') . '">' . ($vAlpha=='J'?'<STRONG>J</STRONG>':'j') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=K') . '">' . ($vAlpha=='K'?'<STRONG>K</STRONG>':'k') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=L') . '">' . ($vAlpha=='L'?'<STRONG>L</STRONG>':'l') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=M') . '">' . ($vAlpha=='M'?'<STRONG>M</STRONG>':'m') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=N') . '">' . ($vAlpha=='N'?'<STRONG>N</STRONG>':'n') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=O') . '">' . ($vAlpha=='O'?'<STRONG>O</STRONG>':'o') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=P') . '">' . ($vAlpha=='P'?'<STRONG>P</STRONG>':'p') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=Q') . '">' . ($vAlpha=='Q'?'<STRONG>Q</STRONG>':'q') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=R') . '">' . ($vAlpha=='R'?'<STRONG>R</STRONG>':'r') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=S') . '">' . ($vAlpha=='S'?'<STRONG>S</STRONG>':'s') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=T') . '">' . ($vAlpha=='T'?'<STRONG>T</STRONG>':'t') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=U') . '">' . ($vAlpha=='U'?'<STRONG>U</STRONG>':'u') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=V') . '">' . ($vAlpha=='V'?'<STRONG>V</STRONG>':'v') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=W') . '">' . ($vAlpha=='W'?'<STRONG>W</STRONG>':'w') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=X') . '">' . ($vAlpha=='X'?'<STRONG>X</STRONG>':'x') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=Y') . '">' . ($vAlpha=='Y'?'<STRONG>Y</STRONG>':'y') . '</a> ';
$vHREFS.= '<a class="pagenav" href="' . sefRelToAbs($ue_base_url . '&vAlpha=Z') . '">' . ($vAlpha=='Z'?'<STRONG>Z</STRONG>':'z') . '</a>';
return $vHREFS;}
[/code:1]

2. in /components/com_comprofiler/comprofiler.html.php

I modified the function usersList (line 628) like this:

[code:1]
function usersList($row,$lfields,$lists,$listid)
{global $database, $limitstart, $search, $mosConfig_sitename, $ueConfig, $_POST, $acl, $_REQUEST, $my, $mainframe;

$vAlpha = (isset($_REQUEST) ? $_REQUEST : 'A' ); // STG 2006-09-09

if ( method_exists($mainframe,"setPageTitle"))
{$mainframe->setPageTitle( getLangDefinition($row->title));}
if ( method_exists($mainframe,"appendPathWay"))
{$mainframe->appendPathWay( htmlspecialchars(getLangDefinition($row->title)));}

$search = cbEscapeSQLsearch(cbGetEscaped(trim( strtolower( $search))));
$option_itemid = (isset($_REQUEST)) ? "&amp;Itemid=".htmlspecialchars($_REQUEST) : getCBprofileItemid(true);
$ue_base_url = "index.php?option=com_comprofiler&amp;task=usersList&amp;listid=".$listid.$option_itemid; // Base URL string
$adminimagesdir = "components/com_comprofiler/images/";
$isModerator=isModerator($my->id);

$allusergids=array();
$usergids=explode(",",$row->usergroupids);
foreach ($usergids AS $usergid)
{$allusergids[]=$usergid;
if ($usergid==29 || $usergid==30)
{$groupchildren = array();
$groupchildren = $acl->get_group_children( $usergid, 'ARO','RECURSE' );
$allusergids = array_merge($allusergids,$groupchildren);}}

$usergids=implode(",",$allusergids);

// Select query
if ($row->sortfields!='')
{$orderby = " ORDER BY " . $row->sortfields;}
$filterby="";
if ($row->filterfields!='')
{$filterby = " AND " . utf8RawUrlDecode(substr($row->filterfields,1));}

// Search total
$query = "SELECT count(u.id) FROM #__users u, #__comprofiler ue WHERE u.id=ue.id AND u.block !=1 AND ue.approved=1".( !($isModerator) ? " AND ue.banned=0" : "")." AND ue.confirmed=1 AND u.gid IN (".$usergids.")";
if (isset($search) && $search != "")
{$query .= " AND (";
$query .= ($ueConfig!='3') ? " u.name LIKE '%$search%' " : " ";
$query .= ($ueConfig!='3' && $ueConfig!='1') ? "OR" : " ";
$query .= ($ueConfig!='1') ? " u.username LIKE '%$search%'" : " ";
$query .= ")";}

$query .= " " . $filterby;
if (!$database->setQuery($query))
{print $database->getErrorMsg();}
$total = $database->loadResult();

if (empty($limitstart))
{$limitstart = 0;}
$limit = $ueConfig;
if ($limit > $total)
{$limitstart = 0;}

// STG 2006-09-09 (next 16 lines)
if (isset($search) && $search != "")
{$query = "SELECT *, '' AS 'NA' FROM #__users u, #__comprofiler ue WHERE u.id=ue.id AND u.block!=1 and ue.approved=1".( !($isModerator) ? " AND ue.banned=0" : "")." AND ue.confirmed=1 AND u.gid IN (".$usergids.")";
$query .= " AND (";
$query .= ($ueConfig!='3') ? " u.name LIKE '%$search%' " : " ";
$query .= ($ueConfig!='3' && $ueConfig!='1') ? "OR" : " ";
$query .= ($ueConfig!='1') ? " u.username LIKE '%$search%'" : " ";
$query .= ")";
$query .= " " . $filterby;
$query .= " " . $orderby;
$query .= " LIMIT $limitstart, $limit";}
else
{$query = "SELECT *, '' AS 'NA' FROM #__users u, #__comprofiler ue WHERE left(ue.lastname,1)='$vAlpha' AND u.id=ue.id AND u.block!=1 and ue.approved=1".( !($isModerator) ? " AND ue.banned=0" : "")." AND ue.confirmed=1 AND u.gid IN (".$usergids.")";
$query .= " " . $filterby;
$query .= " " . $orderby;}

$database->setQuery($query);
$users=$database->loadObjectList();
?>
<TABLE WIDTH="100%" CELLPADDING="4" CELLSPACING="0" BORDER="0" ALIGN="center" CLASS="contentpane">
<TR>
<TD COLSPAN="2"><SPAN CLASS="contentheading"><?php echo getLangDefinition($row->title); ?></SPAN></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="contentdescription" COLSPAN="2">
<?php
if ((isset($search) && $search != "") || ($row->filterfields!=''))
{echo "<b>" . $total . "</b> " . _UE_USERPENDAPPRACTION . ":";}
else
{echo $mosConfig_sitename . " " . _UE_HAS . ": <b>" . $total . "</b> " . _UE_USERS;}
?>
</TD>
</TR>
<TR>
<TD>
<FORM NAME="adminForm" METHOD="post" ACTION="<?php echo sefRelToAbs($ue_base_url."&amp;action=search");?>" >
<TABLE WIDTH="100%" CELLPADDING="4" CELLSPACING="0" BORDER="0" ALIGN="center" CLASS="contentpane">
<TR>
<TD STYLE="width:50%;">
<INPUT TYPE="text" NAME="search" CLASS="inputbox" SIZE="15" MAXLENGTH="100"<?php if (isset($search)) {echo " value=\"".htmlspecialchars(cbGetUnEscaped(cbUnEscapeSQLsearch($search)))."\"";} ?> />
<INPUT TYPE="image" SRC="<?php echo $adminimagesdir; ?>search.gif" ALT="<?php echo _UE_SEARCH; ?>" ALIGN="top" STYLE="border: 0px;" />
</TD>
<TD STYLE="width:50%;text-align:right;">
<?php echo $lists; ?>
</TD>
</TR>
</TABLE>
</FORM>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD><A HREF="<?php echo sefRelToAbs($ue_base_url); ?>" onClick="javascript:adminForm.search.value=''"><?php echo _UE_LIST_ALL; ?></A></TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<DIV STYLE="width:100%;text-align:center;">
<?php // STG 2006-09-09 (next 4 lines)
if (isset($search) && $search != "")
{echo writePagesLinks($limitstart,$limit,$total,$ue_base_url,$search);}
else
{echo writeAlphaLinks($vAlpha,$ue_base_url);}
?>
</DIV>
<HR SIZE="1" />
<SCRIPT TYPE="text/javascript"><!--//--><![CDATA[//><!--

var cbW3CDOM = (document.createElement && document.getElementsByTagName);
var cbUserURLs = new Array(<?php if (is_array($users)) {foreach($users as $user) {echo "\"".unHtmlspecialchars(sefRelToAbs("index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$user->id.$option_itemid))."\",";}} ?>"");

function cbInitUserClick()
{
if (!cbW3CDOM) return;
var nav = document.getElementById('cbUserTable');
var trs = nav.getElementsByTagName('tr');
for (var i=0;i<trs.length;i++)
{
if (trs.id) {
trs.onclick = cbUserClick;
}
}
}

function cbUserClick(thisevent)
{
/* ddumpObject(thisevent,"event",3,0); */
/* alert("clicked!"+this.toString()+window.event.target+window.event.currentTarget+(window.event.target==window.event.currentTarget));
*/
var mine;
if (thisevent) {
// alert("event!"+thisevent.toString()+thisevent.target+thisevent.target.toString()+(thisevent.target.parentNode == this));
mine = (thisevent.target.parentNode == this);
} else if (window.event.target) {
// alert("clickedWE!"+this.toString()+window.event.target+window.event.currentTarget+(window.event.target==window.event.currentTarget));
mine = (window.event.target==window.event.currentTarget);
} else if (window.event.srcElement) {
// alert("eventSRC!"+window.event.srcElement+window.event.srcElement.toString()+(window.event.srcElement.parentNode == this));
mine = (window.event.srcElement.parentNode == this);
}
if (mine) {
window.location=cbUserURLs[this.id.substr(3)]; // cbUxxx --> xxx
}
return !mine;
}

function cbAddEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}

cbAddEvent(window, 'load', cbInitUserClick);

//--><!]]></SCRIPT>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ID="cbUserTable">
<TR>
<?php
echo '<td><b>'.getLangDefinition($row->col1title)."</b></td>\n";
if ($row->col2enabled) echo '<td><b>'.getLangDefinition($row->col2title)."</b></td>\n";
if ($row->col3enabled) echo '<td><b>'.getLangDefinition($row->col3title)."</b></td>\n";
if ($row->col4enabled) echo '<td><b>'.getLangDefinition($row->col4title)."</b></td>\n";
?>
</TR>
<?php
$i = 0;
if (is_array($users) && count($users)>0)
{foreach($users as $user)
{$evenodd = $i % 2;
if ($evenodd == 0)
{$class = "sectiontableentry1";}
else
{$class = "sectiontableentry2";}
//print $user->name;
if($ueConfig==1)
{$style = "style=\"cursor:hand;cursor:pointer;\"";
$style .= " id=\"cbU".$i."\"";}
// $style .= " onclick=\"javascript:window.location='".sefRelToAbs("index.php?option=com_comprofiler&amp;task=userProfile&amp;user=".$user->id.$option_itemid)."'\"";
else
{$style = "";}
if ($user->banned)
{$colsNbr = 1+($row->col2enabled ? 1:0)+($row->col3enabled ? 1:0)+($row->col4enabled ? 1:0);
echo "\t<tr class=\"$class\"><td colspan=\"".$colsNbr."\"><span class=\"error\" style=\"color:red;\">"._UE_BANNEDUSER." ("._UE_VISIBLE_ONLY_MODERATOR.") :</span></td></tr>";}
print "\t<tr class=\"$class\" ".$style.">\n";
//print $lfields;
$str = null;
eval("\$str = \"$lfields\";");
echo $str. "\n";
print "</tr>\n";
$i++;}}
else
{$colsNbr = 1+($row->col2enabled ? 1:0)+($row->col3enabled ? 1:0)+($row->col4enabled ? 1:0);
echo "\t<tr class=\"sectiontableentry1\"><td colspan=\"".$colsNbr."\">"._UE_NO_USERS_IN_LIST."</td></tr>";}
?>
</TABLE>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<HR SIZE="1" />
<DIV STYLE="width:100%;text-align:center;">
<?php // STG 2006-09-09 (next 4 lines)
if (isset($search) && $search != "")
{echo writePagesLinks($limitstart,$limit,$total,$ue_base_url,$search);}
else
{echo writeAlphaLinks($vAlpha,$ue_base_url);}
?>
</DIV>
</TD>
</TR>
</TABLE>
<?php }

/******************************
Registration Functions
******************************/

[/code:1]

And it worked.

When I make a search, it reverts to the normal pagination.

Serge Grenier

Post edited by: sanzalure, at: 2006/09/10 15:08

Please Log in to join the conversation.

16 years 3 months ago #54275 by jfreak53
I tried this code out and in a way it works and a way it doesn't. First off it's not copying the listid correctly, up on the bar when i click on a letter it says "listid=Array". So of course the site is throwing me an error. So I get rid of the array and add an id of one of my lists like "2" and it then works that way. So one how do I fix the listid problem.

Second problem, when I do this, let's say I change to letter "D" where I have one user. It won't display anything, yes it does acknowledge that I have users there and the headers appear but nothing under them, what am I doing wrong here?

Thanks for any help with this, this is a cool addition something that I have been looking for since this is how I need to separate my lists. I do have two lists both with filters but it still won't work when I get rid of the filters. I'm using J1.5 and the latest version of cb.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.187 seconds

Facebook Twitter LinkedIn