search by user name? search by user name?
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

search by user name?

Started by djyeo, January 24, 2005, 01:38:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

djyeo

Hi,
Is it possible to create a search function so that guests can search by members name? For example if I'm looking for Sam's album, I can just type sam in the search box and it should give me the link to sams album. Thank you.

Darwin

yoshikiwei

I did one for my site
modified from search.php
you might wanna give it a try

copy the below codes to a new file and name it searchusers.php
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.0                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002,2003 Gregory DEMAR                                     //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- //
/*
$Id: searchusers.php,v 1.5 2004/08/20 09:26:09 yoshikiwei Exp $
*/

define('IN_COPPERMINE'true);
define('SEARCHUSERS_PHP'true);

require(
'include/init.inc.php');

pageheader($lang_search_php[0]);
$searchusers $HTTP_GET_VARS['searchusers'];
starttable('100%'$lang_searchusers_php[0] . " - \"$searchusers\"");
list_users($searchusers);

function 
list_users($name)
{
    global 
$CONFIG$PAGE$FORBIDDEN_SET;
    global 
$lang_list_users$lang_errors$template_user_list_info_box;

    if (
defined('UDB_INTEGRATION')) {
        
$result udb_list_users_query($user_count);
    } else {
//        $sql = "SELECT user_id," . "        user_name," . "        COUNT(DISTINCT a.aid) as alb_count," . "        COUNT(DISTINCT pid) as pic_count," . "        MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_USERS']} AS u " . "INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON category = " . FIRST_USER_CAT . " + user_id " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' " . "$FORBIDDEN_SET " . "GROUP BY user_id " . "ORDER BY user_name ";
// Fixed correct album count DJMaze
        
$sql "SELECT user_id, " .
               
"user_name, " .
               
"COUNT(DISTINCT a.aid) as alb_count, " .
               
"COUNT(DISTINCT pid) as pic_count, " .
               
"MAX(pid) as thumb_pid " .
               
"FROM {$CONFIG['TABLE_USERS']} AS u " .
               
"INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON category = " FIRST_USER_CAT " + user_id " .
               
"LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.aid = a.aid AND approved = 'YES') " .
   "WHERE user_name like '%$name%' ";
        if (
$FORBIDDEN_SET != ""$sql .= "AND $FORBIDDEN_SET ";
        
$sql .= "GROUP BY user_id " .
                
"ORDER BY user_name";
        
$result db_query($sql);

        
$user_count mysql_num_rows($result);
    }

    if (!
$user_count) {
        
msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '''''100%');
        
mysql_free_result($result);
        return;
    }

    
$user_per_page $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
    
$totalPages ceil($user_count $user_per_page);
    
$PAGE 1;
    
$lower_limit = ($PAGE-1) * $user_per_page;
    
$upper_limit min($user_count$PAGE $user_per_page);
    
$row_count $upper_limit $lower_limit;

    if (
defined('UDB_INTEGRATION')) {
        
$rowset udb_list_users_retrieve_data($result$lower_limit$row_count);
    } else {
        
$rowset = array();
        
$i 0;
        
mysql_data_seek($result$lower_limit);
        while ((
$row mysql_fetch_array($result)) && ($i++ < $row_count)) $rowset[] = $row;
        
mysql_free_result($result);
    }

    
$user_list = array();
    foreach (
$rowset as $user) {
        
$user_thumb '<img src="images/nopic.jpg" class="image" border="0" />';
        
$user_pic_count $user['pic_count'];
        
$user_thumb_pid $user['thumb_pid'];
        
$user_album_count $user['alb_count'];

        if (
$user_pic_count) {
            
$sql "SELECT filepath, filename, url_prefix, pwidth, pheight " "FROM {$CONFIG['TABLE_PICTURES']} " "WHERE pid='$user_thumb_pid'";
            
$result db_query($sql);
            if (
mysql_num_rows($result)) {
                
$picture mysql_fetch_array($result);
                
mysql_free_result($result);
                
$pic_url =  get_pic_url($picture'thumb');
                if (!
is_image($picture['filename'])) {
                        
$image_info getimagesize($pic_url);
                        
$picture['pwidth'] = $image_info[0];
                        
$picture['pheight'] = $image_info[1];
                }
                
$image_size compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
$user_thumb "<img src=\"" get_pic_url($picture'thumb') . "\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
            }
        }

        
$albums_txt sprintf($lang_list_users['n_albums'], $user_album_count);
        
$pictures_txt sprintf($lang_list_users['n_pics'], $user_pic_count);

        
$params = array('{USER_NAME}' => $user['user_name'],
            
'{USER_ID}' => $user['user_id'],
            
'{ALBUMS}' => $albums_txt,
            
'{PICTURES}' => $pictures_txt,
            );
        
$caption template_eval($template_user_list_info_box$params);

        
$user_list[] = array('cat' => FIRST_USER_CAT $user['user_id'],
            
'image' => $user_thumb,
            
'caption' => $caption,
            );
    }
    
theme_display_thumbnails($user_list$user_count''''1$PAGE$totalPagesfalsetrue'user');
}
endtable();
pagefooter();
ob_end_flush();

?>


open search.php
search for pagefooter();, above it insert
starttable(500, $lang_search_php[1]);
echo <<< EOT
        <tr>
                <form method="get" action="searchusers.php" name="searchcpg">
        <td class="tableb" align="center" height="60">
                <input type="input" style="width: 90%" name="searchusers" maxlength="255" value="" class="textinput">
                </td>
        </tr>
        <tr>
                <td colspan="8" align="center" class="tablef">
                        <input type="submit" value="{$lang_search_php[1]}" class="button">
                </td>
                </form>
        </tr>

EOT;
endtable();


in your language file
find
0 => 'Search the file collection',
insert after
1 => 'Search a user',

scroll to the end of the file and insert
// ------------------------------------------------------------------------- //
// File searchusers.php - OK
// ------------------------------------------------------------------------- //

if (defined('SEARCHUSERS_PHP')) $lang_searchusers_php = array(
  0 => 'Search results',
);


it should work now, hoped i didnt miss out anything

Joachim Müller

should imo rather go into the memberlist page, but thanks for the contribution. Will be considered for the future.

Joachim

Tranz

Thing with the memberlist page is that it's not accessible to guests, and only to logged in users if allowed in admin config.

Joachim Müller

...but could easily be changed on the way to have 3 options in config:
- don't display memberlist at all
- display memberlist to everyone (guests and registered)
- display memberlist to registered users only

The memberlist is in fact just another view of the usermgr (without the controls to modify anything), and a search for users is available there as well (in the devel version at least), so why make the search accessible for non-admins as well?

Joachim

djyeo