Author Topic: [MOD] AJAX user select in ACP v1.1 (2008-11-22)  (Read 15333 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] AJAX user select in ACP v1.1 (2008-11-22)
« on: November 22, 2008, 10:10:44 AM »

----------------- [ Index ] -----------------


----------------- [ Introduction ] -----------------

This mod replaces user selection drop down menu with text input field in ACP (Admin Control Panel). It will suggest user names while you type. If entered user name is not correct, administrator's will be used instead.
There is a side effect in this mod: if you type incorrect/non-existing user name and submit the forum, it will use your name instead without any warnings.

For the sake of experiment, I've tested this mod with over 2M members on my local computer. The result was: no performance lose, pages open instantly (except for "Send email" menu) and suggestions showed up with no lag.

But, unless you have lots of members, you probably don't need this mod.

P.S.
This mod uses Yahoo! UI Library: AutoComplete javascript.



----------------- [ Screenshots ] -----------------

Inline completing



Using wildcard *




----------------- [ Changed files ] -----------------

admin/admin_functions.php


----------------- [ New files ] -----------------

admin/userfind.php
admin/userfind.css



----------------- [ Installation ] -----------------

Step_1Download attached package. Extract files and upload them to your 4images folder, preserving this tree structure:
admin/userfind.php
admin/userfind.css


Step_2Open admin/admin_functions.php
Find:
Code: [Select]
  </head>

Insert ABOVE:
Code: [Select]
<!-- Combo-handled YUI CSS files: -->
<link rel="stylesheet" type="text/css" href="<?php echo ROOT_PATH?>admin/userfind.css">
<!-- Combo-handled YUI JS files: -->
<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo/yahoo-min.js&2.6.0/build/event/event-min.js&2.6.0/build/connection/connection-min.js&2.6.0/build/dom/dom-min.js&2.6.0/build/datasource/datasource-min.js&2.6.0/build/autocomplete/autocomplete-min.js"></script> 


Step_2.1Find:function show_user_select_row($title$user_id$i 0) {


Replace it with:/*
MOD ajax user select
start replace

function show_user_select_row($title, $user_id, $i = 0) {
*/
$user_id_name_input "user_id";
if (isset(
$HTTP_POST_VARS['user_id_name_input']))
{
  
$user_id_name_input $HTTP_POST_VARS['user_id_name_input'];
}
if (isset(
$HTTP_POST_VARS['user_id_name_i']))
{
  
$n intval($HTTP_POST_VARS['user_id_name_i']);
  for (
$i 0$i <= $n$i++)
  {
    if (isset(
$HTTP_POST_VARS['user_id_name_'.$i]))
    {
      if (isset(
$HTTP_POST_VARS['user_id_name_array']) && $HTTP_POST_VARS['user_id_name_array'])
      {
        
$HTTP_POST_VARS[$user_id_name_input][$i] = get_user_id_by_name($HTTP_POST_VARS['user_id_name_'.$i]);
      }
      else
      {
        
$HTTP_POST_VARS[$user_id_name_input.'_'.$i] = get_user_id_by_name($HTTP_POST_VARS['user_id_name_'.$i]);
      }
    }
  }
}
elseif (isset(
$HTTP_POST_VARS['user_id_name']))
{
  
$HTTP_POST_VARS[$user_id_name_input] = get_user_id_by_name($HTTP_POST_VARS['user_id_name']);
}
function 
get_user_id_by_name($user_name)
{
  global 
$site_db$user_table_fields;
  
$sql "SELECT ".get_user_table_field("""user_id")."
          FROM "
.USERS_TABLE."
          WHERE "
.get_user_table_field("""user_name")." = '".$user_name."'";
  
$result $site_db->query_firstrow($sql);
  return @
$result['user_id'];
}

function 
show_user_select_row($title$user_id$i ""$size 0$input "user_id"$array 0$orig 0$full 1)
{
  global 
$error$lang$HTTP_POST_VARS$site_db$user_table_fields$user_select_row_cache$site_sess$textinput_size;
  
  if (
$orig)
  {
    return 
_show_user_select_row($title$user_id$i);
  }
  
$user_id_name "";
  if (isset(
$error[$input.'_'.$i]) || isset($error[$input]))
  {
    
$title sprintf("<span class=\"marktext\">%s *</span>"$title);
  }
  if (!
$size)
  {
    
$size $textinput_size;
  }
  if (!
$user_id)
  {
    
$user_id 0;
  }
  
$user_id_array = array($user_id);
  if (isset(
$HTTP_POST_VARS[$input.'_'.$i]))
  {
    
$user_id_array[] = $HTTP_POST_VARS[$input.'_'.$i];
  }
  elseif (
$array && isset($HTTP_POST_VARS[$input][$i]))
  {
    
$user_id_array[] = $HTTP_POST_VARS[$input][$i];
  }
  elseif (isset(
$HTTP_POST_VARS[$input]) && !is_array($HTTP_POST_VARS[$input]))
  {
    
$user_id_array[] = $HTTP_POST_VARS[$input];
  }
  if (isset(
$HTTP_POST_VARS['user_id_name_'.$i]))
  {
    
$user_id_name stripslashes($HTTP_POST_VARS['user_id_name_'.$i]);
  }
  elseif (isset(
$HTTP_POST_VARS['user_id_name']))
  {
    
$user_id_name stripslashes($HTTP_POST_VARS['user_id_name']);
  }
  
$sql "SELECT ".get_user_table_field("""user_name")."
          FROM "
.USERS_TABLE."
          WHERE "
.get_user_table_field("""user_id")." IN (".implode(","$user_id_array).")";
  if (
$result $site_db->query_firstrow($sql))
  {
    
$user_id_name $result['user_name'];
  }
  if (
$full)
  {
    echo 
"<tr class=\"".get_row_bg()."\">\n<td><p class=\"rowtitle\">".$title."</p></td>\n";
    echo 
"<td>\n";
  }
  if (
$input != "user_id")
  {
    echo 
"<input type=\"hidden\" name=\"user_id_name_input\" value=\"".$input."\">\n";
  }
  echo 
"<input type=\"hidden\" name=\"user_id_name_array\" value=\"".$array."\">\n";
  if (
$i !== "")
  {
    echo 
"<input type=\"hidden\" name=\"user_id_name_i\" value=\"".$i."\">\n";
    
$i "_".$i;
  }
  echo 
'<div class="yui-ac" style="width:'.($size/2).'em; padding-bottom:2em;">';
  echo 
"<input type=\"text\" name=\"user_id_name".$i."\" id=\"user_id_name".$i."\" value=\"".format_text($user_id_name2)."\" size=\"".$size."\" style=\"width:".($size/2)."em;\" class=\"yui-ac-input\">\n";
  echo 
'
	
<div id="usernameauto'
.$i.'" class="yui-ac-container" style="width:'.($size/2).'em;"></div>
</div>
<script type="text/javascript" language="javascript">
YAHOO.example.BasicRemote = function() {
    // Use an XHRDataSource
    var oDS = new YAHOO.util.XHRDataSource("'
.ROOT_PATH.'admin/userfind.php");
    // Set the responseType
    oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
    // Define the schema of the delimited results
    oDS.responseSchema = {
        recordDelim: "\n",
        fieldDelim: "\t" 
    };
    // Enable caching
    oDS.maxCacheEntries = 10;
    // Instantiate the AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("user_id_name'
.$i.'", "usernameauto'.$i.'", oDS);
// Enable type ahead
    oAC.typeAhead = false;
// Enable a drop-shadow under the container element 
    oAC.useShadow = true;  
// Display up to 30 results in the container 
    oAC.maxResultsDisplayed = 30;
    return {
        oDS: oDS,
        oAC: oAC
    };
}();
</script>'
;
  if (
$full)
  {
    echo 
"</td>\n</tr>\n";
  }
}

function 
_show_user_select_row($title$user_id$i 0) {
/*
MOD ajax user select
end replace
*/




----------------- [ Tweaks ] -----------------

1. If you want inline auto complete (automatically selects and enters first name from the list) then set to true in admin/admin_functions.php:
Code: [Select]
// Enable type ahead
    oAC.typeAhead = false;


2. By default first 30 names will be showed. You can change that number in admin/admin_functions.php:
Code: [Select]
// Display up to 30 results in the container
    oAC.maxResultsDisplayed = 30;
And in admin/userfind.php:
Code: [Select]
          LIMIT 30";


----------------- [ Version history ] -----------------

v1.1 (2008-11-21)
- Added support for non-standard use of the function. Needed for [MOD] Batch Copy/Move/Edit Images. Redo Step 2.1

v1.0 (2008-11-21)
- First release


« Last Edit: November 26, 2008, 03:39:49 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
« Reply #1 on: November 22, 2008, 10:13:55 AM »
Reserved
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline babe

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
« Reply #2 on: November 22, 2008, 12:23:20 PM »
That is FAST! THANKS!

And it works great with the regular images.php, but can I also integrate this in your Copy/Move/Edit MOD? When I hit submit searching for images using your MOD, it just shows a blank page forever. Is this also related with the large userbase?

Another page it doesn't seem to affect: Send email to users.

PS: Small typo in step 2: user_functions.php should be admin_functions.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
« Reply #3 on: November 22, 2008, 06:27:36 PM »
but can I also integrate this in your Copy/Move/Edit MOD? When I hit submit searching for images using your MOD, it just shows a blank page forever. Is this also related with the large userbase?
Yes, working on it ;)
[EDIT]it should work now from v4.11[/EDIT]

Another page it doesn't seem to affect: Send email to users.
Yes, send email doesn't use same function, and I don't see how it can be fixed without hustle for admin to type each name...

PS: Small typo in step 2: user_functions.php should be admin_functions.php
Thanks
« Last Edit: November 22, 2008, 08:11:49 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline souwar

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
« Reply #4 on: January 19, 2009, 09:36:48 PM »
Hello, i'm not able to download the attachement please can someone check that.
Thank you

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
« Reply #5 on: January 19, 2009, 09:44:34 PM »
working fine
« Last Edit: January 20, 2009, 01:41:31 AM by V@no »
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline zakaria666

  • Full Member
  • ***
  • Posts: 211
    • View Profile
Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
« Reply #6 on: August 26, 2010, 10:55:29 PM »
im on admin control panel but i cannot seem to find the screen shots area that u have provided. where do i go to test this on my admin?

thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
« Reply #7 on: August 27, 2010, 12:46:28 AM »
Anywhere where user select dropdown is used (add/edit image)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)