Changeset 1660 in ExiteCMS for trunk/administration/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/administration/members.php

    r1195 r1660  
    3030// parameter validation 
    3131if (isset($user_id) && !isNum($user_id)) fallback("index.php"); 
     32if (!isset($step)) $step = ""; 
     33if (!isset($user_id)) $user_id= 0; 
    3234if (!isset($country) || strlen($country) != 2) $country = ""; 
    3335if (!isset($sortby) || strlen($sortby) != 1) $sortby = "all"; 
    34 if (!isset($step)) $step = ""; 
    35 if (!isset($user_id)) $user_id= 0; 
    36  
    37 if (isset($_POST['cancel_delete'])) fallback(FUSION_SELF.$aidlink."&sortby=$sortby&rowstart=$rowstart"); 
     36if (!isset($order)) $order = "username"; 
     37if (!isset($field)) $field = "username"; 
     38 
     39if (isset($_POST['cancel_delete'])) fallback(FUSION_SELF.$aidlink."&order=$order&sortby=$sortby&field=$field&rowstart=$rowstart"); 
    3840 
    3941if ($step == "add") { 
     
    144146$rows = 0; 
    145147if (iMEMBER) { 
    146     // create the where clause 
    147     if ($sortby == "all") { 
    148         if ($country == "") { 
    149             $orderby = ""; 
    150         } else { 
    151             $orderby = " user_cc_code = '".$country."'"; 
    152         } 
    153     } else { 
    154         if ($country == "") { 
    155             $orderby = " user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%'"; 
    156         } else { 
    157             $orderby = " user_cc_code = '".$country."' AND (user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%')"; 
    158         } 
    159     } 
     148    // create the letter filter SQL clause and the selection sort SQL clause 
     149    switch($order) { 
     150        case "country": 
     151            $sortfield = "user_cc_code ASC, user_level DESC, user_name ASC"; 
     152            break; 
     153        case "email": 
     154            $sortfield = "user_email ASC, user_level DESC"; 
     155            break; 
     156        case "username": 
     157        default: 
     158            $sortfield = "user_level DESC, user_name ASC"; 
     159            break; 
     160    } 
     161    // create the query filter SQL clause 
     162    $where = ""; 
     163    switch($field) { 
     164        case "country": 
     165            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_cc_code,1,1)))"; 
     166            break; 
     167        case "email": 
     168            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_email,1,1)))"; 
     169            if ($sortby != "all") { 
     170                $where = "(user_email LIKE '".stripinput($sortby)."%' OR user_email LIKE '".strtolower(stripinput($sortby))."%')"; 
     171            } 
     172            break; 
     173        case "username": 
     174        default: 
     175            $letterfilter = "DISTINCT(UPPER(SUBSTRING(user_name,1,1)))"; 
     176            if ($sortby != "all") { 
     177                $where = "(user_name LIKE '".stripinput($sortby)."%' OR user_name LIKE '".strtolower(stripinput($sortby))."%')"; 
     178            } 
     179            break; 
     180    } 
     181    // add the country filter if requested 
     182    $where .= $country == "" ? "" : (($where == "" ? "" : " AND ").("user_cc_code = '$country'")); 
     183 
     184 
    160185    // get the list of members 
    161186    $variables['members'] = array(); 
    162187    if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0; 
    163     $result = dbquery("SELECT * FROM ".$db_prefix."users".($orderby==""?"":" WHERE").$orderby." ORDER BY user_level DESC, user_name LIMIT ".$rowstart.", ".$settings['numofthreads']); 
     188    $result = dbquery("SELECT * FROM ".$db_prefix."users".($where == ""?"":(" WHERE ".$where))." ORDER BY ".$sortfield." LIMIT ".$rowstart.", ".$settings['numofthreads']); 
    164189    $rows = dbrows($result); 
    165190    $variables['members'] = array(); 
     
    197222    // starting characters to filter on. Make sure there are an even number! 
    198223    $variables['search'] = array(); 
    199     $result = dbquery("SELECT DISTINCT(UPPER(SUBSTRING(user_name,1,1))) AS letter FROM ".$db_prefix."users ORDER BY letter"); 
     224    $result = dbquery("SELECT ".$letterfilter." AS letter FROM ".$db_prefix."users".($where == ""?"":(" WHERE ".$where))." ORDER BY letter"); 
    200225    while ($data = dbarray($result)) { 
    201226        // get rid of unwanted characters. Need to find a beter solution for this 
    202227        $variables['search'][] = str_replace(array('&', '?'), array('',''), $data['letter']); 
    203228    } 
    204     if (count($variables['search'])%2) $variables['search'][] = ""; 
     229    if (count($variables['search']) > 1 && count($variables['search'])%2) $variables['search'][] = ""; 
    205230    $variables['sortby'] = $sortby; 
    206     $variables['rows'] = dbcount("(*)", "users", $orderby); 
     231    $variables['rows'] = dbcount("(*)", "users", $where); 
    207232    $variables['rowstart'] = $rowstart; 
    208233    $variables['items_per_page'] = $settings['numofthreads']; 
    209     $variables['pagenav_url'] = FUSION_SELF.$aidlink."&sortby=$sortby&".($country==""?"":"country=$country&"); 
     234    $variables['pagenav_url'] = FUSION_SELF.$aidlink."&sortby=$sortby&field=$field&order=$order&".($country==""?"":"country=$country&"); 
    210235} 
    211236 
    212237$variables['step'] = $step; 
    213238$variables['user_id'] = $user_id; 
     239$variables['field'] = $field; 
     240$variables['order'] = $order; 
    214241$template_panels[] = array('type' => 'body', 'name' => 'admin.members', 'template' => 'admin.members.tpl', 'locale' => array("admin.members", "main.user_fields")); 
    215242$template_variables['admin.members'] = $variables; 
Note: See TracChangeset for help on using the changeset viewer.