4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: V@no on November 22, 2008, 10:10:44 AM

Title: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
Post by: V@no 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 (http://developer.yahoo.com/yui/autocomplete/) javascript.



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

Inline completing

(http://img116.imageshack.us/img116/3316/userselect2rh5.png)

Using wildcard *

(http://img116.imageshack.us/img116/7587/userselect1ng1.png)


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

admin/admin_functions.php (#post_step2)


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

admin/userfind.php
admin/userfind.css



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

Step_1 (#post_step1)Download attached package (#post_attachment). Extract files and upload them to your 4images folder, preserving this tree structure:
admin/userfind.php
admin/userfind.css


Step_2 (#post_step2)Open 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.1 (#post_step2-1)Find: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_name, 2)."\" 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 (#post_tweak1). 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 (#post_tweak2). 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 (http://www.4homepages.de/forum/index.php?topic=20501.0). Redo Step 2.1 (#post_step2-1)

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


Title: Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
Post by: V@no on November 22, 2008, 10:13:55 AM
Reserved
Title: Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
Post by: babe 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
Title: Re: [MOD] AJAX user select in ACP v1.0 (2008-11-22)
Post by: V@no 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
Title: Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
Post by: souwar on January 19, 2009, 09:36:48 PM
Hello, i'm not able to download the attachement please can someone check that.
Thank you
Title: Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
Post by: Nicky on January 19, 2009, 09:44:34 PM
working fine
Title: Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
Post by: zakaria666 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
Title: Re: [MOD] AJAX user select in ACP v1.1 (2008-11-22)
Post by: V@no on August 27, 2010, 12:46:28 AM
Anywhere where user select dropdown is used (add/edit image)