[turba] Sorting addressbook with national alphabet

Rashid N. Achilov achilov-rn at askd.ru
Wed Jul 15 11:42:38 UTC 2009


On Monday 13 July 2009, Rashid N. Achilov wrote:
> When turba displays addressbook, it split content per 'perpage' lines, when 
> addressbook records quantity more than 'perpage' and displays 'guide' to 
> addressbook as line with letters A,B,C... and displays at these pages only 
> records, started from A, from B, from C...

Sorry, I have sent unfinished letter.

I'll answer by myself. I had have implemented this. Now I can see in 
addressbook view line with links "russian A, russian B, russian W..." and 
when I pressing this link I'll see records, started from this letter. But I 
do not know how to do this by universal matter, because I have done some 
descructive patches.

First. For generating russian guides I have changed 
turba/templates/list/alphaPager.inc

--- alphaPager.inc.old	2009-05-01 17:12:37.000000000 +0700
+++ alphaPager.inc	2009-07-15 16:41:17.000000000 +0700
@@ -9,8 +9,10 @@
     echo Horde::link(Horde::applicationUrl(Util::addParameter($viewurl, 
array('page'=> '*', 'show' => $show)))) . _("All") . '</a>&nbsp;';
 }
-for ($i = 65; $i < 91; $i++) {
-    $a = chr($i);
+
+for ($i = 192; $i <= 223; $i++) {
+    $a = String::convertCharset(chr($i), "cp1251", "utf-8");
+
     if ($currentPage == $a) {
         echo '<strong>(' . $a . ')</strong>&nbsp;';
     } else {

I have used another range and instead of chr() use String::convert to convert 
generated one-byte chars to UTF8. Now I'll see russian letters. As you can 
see, here is hardcoded codepage and chars range. I do not know how to adopt 
this to another national alphabet

Than, I had changed the processor turba/lib/ListView.php

--- ListView.php.old	2009-05-01 17:12:37.000000000 +0700
+++ ListView.php	2009-07-15 14:44:33.000000000 +0700
@@ -236,10 +236,10 @@
                 $page = '*';
             }
             if ($this->count() > $prefs->getValue('perpage')) {
-                $page = Util::getFormData('page', 'A');
-                if (!preg_match('/^[A-Za-z*]$/', $page)) {
+                $page = Util::getFormData('page', 'п░');
+/*                if (!preg_match('/^[A-Za-z*]$/', $page)) {
                     $page = 'A';
-                }
+                }*/
             }
 
             $listHtml = $this->getAlpha($numDisplayed, $page);
@@ -469,9 +469,11 @@
     function skip(&$ob)
     {
         $name = Turba::formatName($ob);
-        if ($this->_alpha != '*' && String::lower(substr($name, 0, 1)) != 
$this->_alpha) {
+
+        if ($this->_alpha != '*' &&
+        	String::lower(substr($name, 0, 2)) != $this->_alpha)
             return true;
-        }
+         else
         return false;
     }
 
As you can see, I have deleted 'A' (latin capital A) and insert russian 
capital A in UTF8 codepage. This is hardcoded value, it should be 
parametrized to use another national alphabet. Also, I have commneted check 
on match base latin-1 letters. 

In filter class I have changed length of taken substirng - UTF8 chars required 
2 bytes on each. Because LDAP keeps non-latin data in UTF8, we should keep 
letters also in UTF8.

Patches attached. This way completely break displaying records with 
non-russian names, it can viewed only in All mode.
-- 
   With Best Regards.
   Rashid N. Achilov (RNA1-RIPE), JID: citycat4 at jabber.org
   OOO "ACK" telecommunications administrator, e-mail: achilov-rn [at] askd.ru
   PGP: 83 CD E2 A7 37 4A D5 81 D6 D6 52 BF C9 2F 85 AF 97 BE CB 0A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: listview.php.patch
Type: text/x-diff
Size: 1006 bytes
Desc: not available
URL: <http://lists.horde.org/archives/turba/attachments/20090715/1cd888d0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alphaPager.inc.patch
Type: text/x-diff
Size: 604 bytes
Desc: not available
URL: <http://lists.horde.org/archives/turba/attachments/20090715/1cd888d0/attachment-0001.bin>


More information about the turba mailing list