Hi All
Quite long ago I needed alphabetic sorting for the Xdir, with help from riaanvdb I got it to work.
I didn't used it for a while, but now I found out it acts weirdly!!! very weirdly
Sometimes it gives the right list in the right letter, sometimes it don't (clicking "a" or "b" or "c" or "d" gives the "a" list all the time, but clicking on "g" gives the "g" list all the time - it acts badly ... but in a constant manner , and I really don't see the logic in it.
It comes originaly (I think ... don't remember) from the WF downloads alphanetic sorting - looks almost the same
I post the codes here for someone to take a look, changed from Hebrew to English .....
file: include/functions.php (eof - at the end of it add this function)
function letters()
{
global $xoopsModule;
$letterchoice .= "[ ";
$alphabet = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$num = count($alphabet) - 1;
$counter = 0;
while (list(, $ltr) = each($alphabet))
{
$letterchoice .= "$ltr' style='font-size: 11px;'>$ltr";
if ($counter == round($num / 2))
$letterchoice .= " ]
[ ";
elseif ($counter != $num)
$letterchoice .= " | ";
$counter++;
}
$letterchoice .= " ]";
return $letterchoice;
}
viewlist.php (complete) looks like this:
include "header.php";
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
$mytree = new XoopsTree($xoopsDB->prefix("xdir_cat"),"cid","pid");
$xoopsOption['template_main'] = 'xdir_viewlist.html';
include XOOPS_ROOT_PATH."/header.php";
//generates top 10 charts by rating and hits for each main category
$list = $HTTP_GET_VARS['list'];
$rate = $HTTP_GET_VARS['rate'];
// Tzvook //
$letters = letters();
$xoopsTpl->assign('letters', $letters);
$xoopsTpl->assign('xmid', $xoopsModule->getVar('mid'));
if(isset($rate)){
$sort = _MD_RATING;
$sortDB = "rating";
}else{
$sort = _MD_HITS;
$sortDB = "hits";
}
$xoopsTpl->assign('lang_sortby' ,$sort);
$xoopsTpl->assign('lang_rank' , _MD_RANK);
$xoopsTpl->assign('lang_phone', _MD_BUSPHONE);
$xoopsTpl->assign('lang_title' , _MD_TITLE);
$xoopsTpl->assign('lang_category' , _MD_CATEGORY);
$xoopsTpl->assign('lang_hits' , _MD_HITS);
$xoopsTpl->assign('lang_rating' , _MD_RATING);
$xoopsTpl->assign('lang_vote' , _MD_VOTE);
$arr=array();
$result=$xoopsDB->query("select cid, title from ".$xoopsDB->prefix("xdir_cat")." where pid=0");
$e = 0;
$rankings = array();
while(list($cid, $ctitle)=$xoopsDB->fetchRow($result)){
$rankings[$e]['title'] = sprintf(_MD_TOP10, $myts->htmlSpecialChars($ctitle));
$query = "select lid, cid, title, phone, hits, rating, votes from ".$xoopsDB->prefix("xdir_links")." where status>0 and (title LIKE '$list%'";
// get all child cat ids for a given cat id
$arr=$mytree->getAllChildId($cid);
$size = count($arr);
for($i=0;$i<$size;$i++){
$query .= " or cid=".$arr[$i]."";
}
$query .= ") order by ".$sortDB." DESC";
$result2 = $xoopsDB->query($query,50,0);
$rank = 1;
while(list($lid,$lcid,$ltitle,$phone,$hits,$rating,$votes)=$xoopsDB->fetchRow($result2)){
$catpath = $mytree->getPathFromId($lcid, "title");
$catpath= substr($catpath, 1);
$catpath = str_replace("/"," » ",$catpath);
$rankings[$e]['links'][] = array('id' => $lid, 'cid' => $cid, 'rank' => $rank, 'title' => $myts->htmlSpecialChars($ltitle), 'category' => $catpath, 'hits' => $hits, 'rating' => number_format($rating, 2), 'votes' => $votes, 'phone' => $phone);
$rank++;
}
$e++;
}
$xoopsTpl->assign('rankings', $rankings);
include XOOPS_ROOT_PATH.'/footer.php';
?>
in each file I want the Alphabetic order - I call the function ( files: index.php , viewcat.php , singlelink.php ) and in it's templates acordingly I call it:
<{$letters}>
(the template is full of hebrew hardcoded Chars - so I can't post it in full, but you need to add this wherever you want the alpabetic line to be) ...
Thsi hack is almost working good ... exept of what I mentioned above.
I wonder if somebody (from all those who asked me before about it) finds the fix for that
I am realy lost with it ... need fresh eyes on that one !!!!