PHP Scripts Development » 3rd party script modifications

User Search for Access_user (1.99)

(2 posts)

Great offers not only for geeks!


  1. sakefox

    sakefox
    Member

    Thought i should bring this over since you have your own forums now.

    Here is a link to the complete file: admin_user.rar

    Complete change snippets below.

    Version 2.1:
    Fixed naming errors (there was many)
    Added missing quotes in select function
    Added \n's on select function
    ----
    add following functions to admin_user.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 name=\"select_user\">\n";
    			while ($obj = mysql_fetch_object($res_user)) {
    				$menu .= "<option value=\"".$obj->login."\">".$obj->login."</option>\n";
    			}
    			$menu .= "</select>\n";
    			$this->find_user = true;
    			return $menu;
    			mysql_free_result($res_user);
    		} else {
    			$this->the_msg = "Account not found.";
    		}
    	} else {
    		$this->the_msg = "The username to be entered. To search all users use * .";
    	}
    }

    Change submit functions with

    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");
    }
    $error = $admin_update->the_msg; // error message

    change HTML form with (very ugly coding):

    <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>
    Posted 3 months ago #
  2. hehe, yeah the admin_user extension was very ugly coded :D

    thanks for sharing this, I used my "own" version in some application (incl. search) and will compare all code and hope with some time to include the function into some official release.

    Posted 3 months ago #

RSS feed for this topic

Reply

You must log in to post.