Cyberpunk Wannabe
Posts: 46
352 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)
<?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
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:
Posts: 6349
38918 credits Members referred : 374
Cyberpunk Wannabe
Posts: 46
352 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: 46
352 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