Changeset 1660 in ExiteCMS for trunk/members.php


Ignore:
Timestamp:
08/21/08 16:07:21 (4 years ago)
Author:
hverton
Message:

updated the members list with better filters, and a sort option on username, email, last visit date and country.
Rewritten the setup procedure to make it more fail-safe
Fixed getmxxrr() function, to return the lowest MX record first
Added the compiled locale files for Dutch (setup/global)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/members.php

    r1195 r1660  
    2828if (!isset($country) || strlen($country) != 2) $country = ""; 
    2929if (!isset($sortby) || strlen($sortby) != 1) $sortby = "all"; 
     30if (!isset($order)) $order = "username"; 
     31if (!isset($field)) $field = "username"; 
    3032 
    3133// get the name of the country requested 
     
    3537$rows = 0; 
    3638if (iMEMBER) { 
    37     // create the where clause 
    38     $filter = "user_status = 0";    // only show activated accounts 
    39     if ($sortby == "all") { 
    40         if ($country != "") { 
    41             $filter .= " AND user_cc_code = '".$country."'"; 
    42         } 
    43     } else { 
    44         if ($country == "") { 
    45             $filter .= " AND (user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%')"; 
    46         } else { 
    47             $filter .= " AND (user_cc_code = '".$country."' AND (user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%'))"; 
    48         } 
     39    // create the letter filter SQL clause and the selection sort SQL clause 
     40    switch($order) { 
     41        case "country": 
     42            $sortfield = "user_cc_code ASC, user_level DESC, user_name ASC"; 
     43            break; 
     44        case "email": 
     45            $sortfield = "user_email ASC, user_level DESC"; 
     46            break; 
     47        case "lastvisit": 
     48            $sortfield = "user_lastvisit DESC, user_name ASC"; 
     49            break; 
     50        case "username": 
     51        default: 
     52            $sortfield = "user_level DESC, user_name ASC"; 
     53            break; 
    4954    } 
     55    // create the query filter SQL clause 
     56    $where = ""; 
     57    switch($field) { 
     58        case "country": 
     59            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_cc_code,1,1)))"; 
     60            break; 
     61        case "email": 
     62            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_email,1,1)))"; 
     63            if ($sortby != "all") { 
     64                $where = "(user_email LIKE '".stripinput($sortby)."%' OR user_email LIKE '".strtolower(stripinput($sortby))."%')"; 
     65            } 
     66            break; 
     67        case "lastvisit": 
     68            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_name,1,1)))"; 
     69            if ($sortby != "all") { 
     70                $where = "(user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%')"; 
     71            } 
     72            break; 
     73        case "username": 
     74        default: 
     75            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_name,1,1)))"; 
     76            if ($sortby != "all") { 
     77                $where = "(user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%')"; 
     78            } 
     79            break; 
     80    } 
     81    // add the country filter if requested 
     82    $where .= $country == "" ? "" : (($where == "" ? "" : " AND ").("user_cc_code = '$country'")); 
     83 
    5084    // get the list of members 
    5185    $variables['members'] = array(); 
    5286    if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0; 
    53     $result = dbquery("SELECT * FROM ".$db_prefix."users ".($filter==""?"":("WHERE ".$filter))." ORDER BY user_level DESC, user_name LIMIT ".$rowstart.", ".$settings['numofthreads']); 
     87    $result = dbquery("SELECT * FROM ".$db_prefix."users".($where == ""?"":(" WHERE ".$where))." ORDER BY ".$sortfield." LIMIT ".$rowstart.", ".$settings['numofthreads']); 
    5488    $rows = dbrows($result); 
     89    if ($rows == 0 && !empty($where)) { 
     90        // no results? Try again without a filter 
     91        $result = dbquery("SELECT * FROM ".$db_prefix."users ORDER BY ".$sortfield." LIMIT ".$rowstart.", ".$settings['numofthreads']); 
     92        $rows = dbrows($result); 
     93        $sortby="all"; 
     94        $where = ""; 
     95    }  
    5596    $variables['members'] = array(); 
    5697    if ($rows != 0) { 
     
    83124    // starting characters to filter on. Make sure there are an even number! 
    84125    $variables['search'] = array(); 
    85     $result = dbquery("SELECT DISTINCT(UPPER(SUBSTRING(user_name,1,1))) AS letter FROM ".$db_prefix."users ORDER BY letter"); 
     126    $result = dbquery("SELECT ".$letterfilter." AS letter FROM ".$db_prefix."users".($where == ""?"":(" WHERE ".$where))." ORDER BY letter"); 
    86127    while ($data = dbarray($result)) { 
    87128        // get rid of unwanted characters. Need to find a beter solution for this 
     
    89130    } 
    90131    if (count($variables['search'])%2) $variables['search'][] = ""; 
     132    $variables['field'] = $field; 
     133    $variables['order'] = $order; 
    91134    $variables['sortby'] = $sortby; 
    92     $variables['rows'] = dbcount("(*)", "users", $filter); 
     135    $variables['rows'] = dbcount("(*)", "users", $where); 
    93136    $variables['rowstart'] = $rowstart; 
    94137    $variables['items_per_page'] = $settings['numofthreads']; 
    95     $variables['pagenav_url'] = FUSION_SELF."?sortby=$sortby&".($country==""?"":"country=$country&"); 
     138    $variables['pagenav_url'] = FUSION_SELF."?sortby=$sortby&field=$field&".($country==""?"":"country=$country&"); 
    96139} 
    97140 
Note: See TracChangeset for help on using the changeset viewer.