13, May 2008

User search - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  3rd party modifications (Moderator: Olaf)
Topic: User search
« previous next »
Pages: [1] Print

Author Topic: User search  (Read 580 times)
Cyberpunk Wannabe
*
Posts: 45
342 credits
Members referred : 0


« on: Oct 05, 2007, 01:29:55 AM »

Version 2
can search through, login name, real name, email, access level, and activation type. I used $msg numbers 80 and 81 just because i didnt think it would be used yet but can be changed to anything.

admin_user.php PHP code change for submit
Code:
<?php
if (isset($_POST['Submit'])) {
if ($_POST['Submit'] == "Update") {
$conf_str = (isset($_POST['send_confirmation'])) ? $_POST['send_confirmation'] : ""// the checkbox value to send a confirmation mail
$admin_update->update_user_by_admin($_POST['level'], $_POST['user_id'], $_POST['password'], $_POST['email'], $_POST['activation'], $conf_str);
//change so redirect to main admin page(/admin/index.php)
$admin_update->get_userdata($_POST['login_name']); // this is needed to get the modified data after update
} elseif ($_POST['Submit'] == "Search") {
$act_str = (isset($_POST['search_activation'])) ? $_POST['search_activation'] : "";
$user_search $admin_update->user_search($_POST['search_login'], $_POST['search_real'], $_POST['search_email'], $_POST['operator'], $_POST['search_level'], $act_str);
} elseif ($_POST['Submit'] == "Select") {
$admin_update->get_userdata($_POST['select_user']);
}
} elseif (isset(
$_GET['login_id']) && intval($_GET['login_id']) > 0) {
$admin_update->get_userdata($_GET['login_id'], "is_id");
}
?>


admin_user.php HTML code (i know its ugly looking code)
Code:
<form name"adminedit" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php if ($admin_update->user_found) { ?>
Username:<?php echo $admin_update->user_name?>
<br>
Access Level:<?php echo $admin_update->access_level_menu($admin_update->user_access_level); ?>
<br>
Password:<input type="password" name="password" value="<?php echo (isset($_POST['password'])) ? $_POST['password'] : ""?>">
<br>
Confirm Password:<input type="password" name="confirm_password" value="<?php echo (isset($_POST['confirm_password'])) ? $_POST['confirm_password'] : ""?>">
<br>
Email Address:<input type="text" name="email" value="<?php echo (isset($_POST['email'])) ? $_POST['email'] : $admin_update->old_user_email?>">
<br>
Account Status:<?php echo $admin_update->activation_switch(); ?>
<br>
Send Confermation:<input type="checkbox" name="send_confirmation" value="yes">
<input type="hidden" name="user_id" value="<?php echo (isset($_POST['user_id'])) ? $_POST['user_id'] : $admin_update->user_id ?>">
<input type="hidden" name="login_name" value="<?php echo $admin_update->user_name?>">
<input type="submit" name="Submit" value="Update">
<?php } elseif ($admin_update->find_user) { ?>
Username:<?php echo $user_search?>
<input type="submit" name="Submit" value="Select">
<?php } else { ?>
Username:<input type="text" name="search_login" value="<?php echo (isset($_POST['search_login'])) ? $_POST['search_login'] : "" ?>">
<br>
Real Name:<input type="text" name="search_real" value="<?php echo (isset($_POST['search_real'])) ? $_POST['search_real'] : "" ?>">
<br>
Email Address:<input type="text" name="search_email" value="<?php echo (isset($_POST['search_email'])) ? $_POST['search_email'] : "" ?>">
<br>
Access Level:<?php echo $admin_update->operator_display(); ?><?php echo $admin_update->access_level_menu("0""search_level"); ?>
<br>
Active:<?php echo $admin_update->activation_switch("search_activation"); ?>
<br>
<input type="submit" name="Submit" value="Search">
<?php ?>
</form>

admin_user.php class functions
Code:
<?php
function wildcard_replace($text){
$text str_replace('*''%'$text);
return $text;
}
function operator_display(){
$ary_operator = array('>=','>','=','<','<=''!=');
$menu_operator "<select name=\"operator\">";
foreach ($ary_operator as $dsp_operator){
$menu_operator .= "<option value=\"".$dsp_operator."\">".$dsp_operator."</option>";
}
$menu_operator .= "</select>";
return $menu_operator;
}
function user_search($login$real_name ''$email ''$operator '='$level 0$status ''){
if ($login) {
if ($status == "n") {
$sql sprintf("SELECT login, real_name, email, access_level, active FROM %s WHERE login LIKE '%s' AND access_level >= '0'"$this->table_name$login);
} else {
$sql sprintf("SELECT login, real_name, email, access_level, active FROM %s WHERE login LIKE '%s' AND access_level %s %d"$this->table_name$login$operator$level);
}
$sql .= !empty($real_name) ? sprintf(" AND real_name LIKE '%s'"$real_name) : "";
$sql .= !empty($email) ? sprintf(" AND email LIKE '%s'"$email) : "";
$sql .= !empty($status) ? sprintf(" AND active = '%s'"$status) : "";
$sqlcompl $this->wildcard_replace($sql);
$res_user mysql_query($sqlcompl);
if (mysql_num_rows($res_user) == 1) {
$obj mysql_fetch_object($res_user);
$this->user_name $obj->login;
$this->get_userdata($this->user_name);
} elseif (mysql_num_rows($res_user) > 1){
$menu "<select value=user>";
while ($obj mysql_fetch_object($res_user)) {
$menu .= "<option value=".$obj->login.">".$obj->login."</option>";
}
$menu .= "</select>";
$this->find_user true;
return $menu;
mysql_free_result($res_user);
} else {
$this->the_msg $this->messages(80);
}
} else {
$this->the_msg $this->messages(81);
}
}
?>


error msg additions.
Code:
<?php
$msg
[80] = "Account not found.";
$msg[81] = "The username to be entered. To search all users use * .";
?>




Version 1
found this access_user class not to long ago, have to say saved me a big headache.

went through the forums didn't see any answers to a user search function for it, so i wrote one, but wanted to see if there was a more efferent say to do it? it works, but after looking at your code structure its a better then what i was taught years ago heh

can use * as a wild card to search for names, ie. adm* or *min* and will bring up the matches in a option list

this is what i have for the if statements for the top of admin_user.php
Code:
if (isset($_POST['Submit'])) {
if ($_POST['Submit'] == "Update") {
$conf_str = (isset($_POST['send_confirmation'])) ? $_POST['send_confirmation'] : ""; // the checkbox value to send a confirmation mail
$admin_update->update_user_by_admin($_POST['level'], $_POST['user_id'], $_POST['password'], $_POST['email'], $_POST['activation'], $conf_str);
//change so redirect to main admin page(/admin/index.php)
$admin_update->get_userdata($_POST['login_name']); // this is needed to get the modified data after update
} elseif ($_POST['Submit'] == "Search") {
$admin_update->user_search($_POST['login_name']);
} elseif ($_POST['Submit'] == "Select") {
$admin_update->get_userdata($_POST['user']);
}
} elseif (isset($_GET['login_id']) && intval($_GET['login_id']) > 0) {
$admin_update->get_userdata($_GET['login_id'], "is_id");
}

added a elseif in the html part of admin.php incase of multi users
Code:
<?php } elseif ($admin_update->find_user) { ?>
Username:<?php echo $admin_update->user_search($_POST['login_name']); ?>
<input type="submit" name="Submit" value="Select">

in the admin_users file added "var find_user = false;

and this function
Code:
function user_search($search){
$search = str_replace('*', '%', $search); //removed if statment
$sql = sprintf("SELECT login FROM %s WHERE login LIKE '%s'", $this->table_name, $search);
$res_user = mysql_query($sql);
if (mysql_num_rows($res_user) == 1) {
$obj = mysql_fetch_object($res_user);
$this->user_name = $obj->login;
$this->get_userdata($this->user_name);
} elseif (mysql_num_rows($res_user) > 1) {
$menu = "<select name=\"user\">\n";
while ($obj = mysql_fetch_object($res_user)) {
$menu .= "  <option value=\"".$obj->login."\">".$obj->login."</option>\n";
}
$menu .= "</select><br>\n";
$this->find_user = true;
mysql_free_result($res_user);
return $menu;
} else {
$this->the_msg = $this->admin_message(13);
}
}

for the error msg
Code:
$admin_msg[13] = "Account not found.";

PS: if i make no sense and a year behind the times, just slap me and ignore me LOL, was just trying to help, but i am very slow to help most the time, or thats what my friends tell me ROFL
Code:
« Last Edit: Oct 17, 2007, 06:16:23 PM by stickdragon »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6236
38242 credits
Members referred : 374


It's time to use PHP5!


Re: User search (is this effecient)
« Reply #1 on: Oct 05, 2007, 09:14:18 AM »

Thanks for sharing this!


Last blog : Database Management with phpMyAdmin
Cyberpunk Wannabe
*
Posts: 45
342 credits
Members referred : 0


« Reply #2 on: Oct 05, 2007, 05:34:02 PM »

forgot that i had made a few modifications so might not have worked just by coping and pasting, i fixed the $admin_update->update_user_by_admin line and also changed the str_replace if line with just $search = str_replace('*', '%', $search); to help fix a bug that would happen every now and then with searching with the wildcard
Cyberpunk Wannabe
*
Posts: 45
342 credits
Members referred : 0


« Reply #3 on: Oct 17, 2007, 06:16:34 PM »

added version 2 to first post
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7187
Tags : user search Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  3rd party modifications (Moderator: Olaf)
Topic: User search
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 13, 2008, 06:43:41 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 34.931
Total Topics: 7.262
Total Members: 3.482
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: ondho

14 Guests, 4 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.