Arrow Home arrow Forums
larger font smaller font default font Fixed screen resolution Auto adjust screen size

Joomlapolis Forums  


Page through users list by 1st letter of lastname
Date: 2006/09/10 14:59 By: sanzalure Status: User  
Karma: 0  
Fresh Joomlapolitan

Posts: 3
graphgraph
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:

  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;}



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

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

Code:

  function usersList($row,$lfields,$lists,$listid)  {global $database$limitstart$search$mosConfig_sitename$ueConfig$_POST$acl$_REQUEST$my$mainframe;      $vAlpha = (isset($_REQUEST['vAlpha']) ? $_REQUEST['vAlpha'] : 'A' ); // STG 2006-09-09   if ( method_exists($mainframe,"setPageTitle"))    {$mainframe->setPageTitlegetLangDefinition($row->title));}   if ( method_exists($mainframe,"appendPathWay"))    {$mainframe->appendPathWayhtmlspecialchars(getLangDefinition($row->title)));}     $search cbEscapeSQLsearch(cbGetEscaped(trimstrtolower$search))));     $option_itemid = (isset($_REQUEST['Itemid'])) ? "&amp;Itemid=".htmlspecialchars($_REQUEST['Itemid']) : 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['name_format']!='3') ?  " u.name LIKE '%$search%' " " ";                          $query .= ($ueConfig['name_format']!='3' && $ueConfig['name_format']!='1') ? "OR" " ";                         $query .= ($ueConfig['name_format']!='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['num_per_page'];     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['name_format']!='3') ?  " u.name LIKE '%$search%' " " ";                          $query .= ($ueConfig['name_format']!='3' && $ueConfig['name_format']!='1') ? "OR" " ";                         $query .= ($ueConfig['name_format']!='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['plists']; ?> </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[i].id) {       trs[i].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['allow_profilelink']==1)      {$style = "style=\"cursor:hand;cursor<img src="http://www.joomlapolis.com/components/ com_joomlaboard/emoticons/tongue.png" alt="" style="vertical-align: middle;border:0px;" />ointer;\"" ;       $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 ******************************/



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
Click here to see the profile of this user The topic has been locked.

Re:Page through users list by 1st letter of lastna
Date: 2008/01/14 03:30 By: jfreak53 Status: User  
Karma: 0  
Fresh Joomlapolitan

Posts: 6
graphgraph
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.
Click here to see the profile of this user The topic has been locked.

Documentation

Documentation Subscription Service
(updated for CB 1.2 RC4)

What?

Why?

Where?

Just click here for answers!

Click here for a yearly subscription: subscribe now

Download Latest Release

The latest stable Community Builder Release is version 1.1 for Joomla 1.0 and Mambo.
You need to be a registered member of Joomlapolis to download.

The latest release candidate of Community Builder is version 1.2 RC4, native for Joomla 1.0, 1.5 and Mambo.
It is available as "thank you" to all CB documentation subscribers and now also to all registered joomlapolitans.

CB Login