- md5
- 5e4d8da0c16179ba8659421298111c16
- sha1
- 0f874a7ad37a6affdce57c9e3b0af65e86f8b122
- sha256
- 45e38a7a0d03da2fab3cb94a8109cbb0df2527fe298e25dbcecde8c98110cbcd
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
<?php
/**
* @package Joomla.Libraries
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Field to select a user ID from a modal list.
*
* @package Joomla.Libraries
* @subpackage Form
* @since 1.6
*/
class JFormFieldUser extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'User';
/**
* Method to get the user field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
$html = array();
$groups = $this->getGroups();
$excluded = $this->getExcluded();
$link = 'index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id
. (isset($groups) ? ('&groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&excluded=' . base64_encode(json_encode($excluded))) : '');
// Initialize some field attributes.
$attr = !empty($this->class) ? ' class="' . $this->class . '"' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
$attr .= $this->required ? ' required' : '';
// Load the modal behavior script.
JHtml::_('behavior.modal', 'a.modal_' . $this->id);
// Build the script.
$script = array();
$script[] = ' function jSelectUser_' . $this->id . '(id, title) {';
$script[] = ' var old_id = document.getElementById("' . $this->id . '_id").value;';
$script[] = ' if (old_id != id) {';
$script[] = ' document.getElementById("' . $this->id . '_id").value = id;';
$script[] = ' document.getElementById("' . $this->id . '").value = title;';
$script[] = ' document.getElementById("' . $this->id . '").className = document.getElementById("' . $this->id . '").className.replace(" invalid" , "");';
$script[] = ' ' . $this->onchange;
$script[] = ' }';
$script[] = ' SqueezeBox.close();';
$script[] = ' }';
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Load the current username if available.
$table = JTable::getInstance('user');
if (is_numeric($this->value))
{
$table->load($this->value);
}
// Handle the special case for "current".
elseif (strtoupper($this->value) == 'CURRENT')
{
$table->load(JFactory::getUser()->id);
}
else
{
$table->username = JText::_('JLIB_FORM_SELECT_USER');
}
// Create a dummy text field with the user name.
$html[] = '<div class="input-append">';
$html[] = ' <input type="text" id="' . $this->id . '" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"'
. ' readonly' . $attr . ' />';
// Create the user select button.
if ($this->readonly === false)
{
$html[] = ' <a class="btn btn-primary modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"'
. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
$html[] = '<i class="icon-user"></i></a>';
}
$html[] = '</div>';
// Create the real field, hidden, that stored the user id.
$html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . (int) $this->value . '" />';
return implode("\n", $html);
}
/**
* Method to get the filtering groups (null means no filtering)
*
* @return mixed array of filtering groups or null.
*
* @since 1.6
*/
protected function getGroups()
{
return null;
}
/**
* Method to get the users to exclude from the list of users
*
* @return mixed Array of users to exclude or null to to not exclude them
*
* @since 1.6
*/
protected function getExcluded()
{
return null;
}
}
The same content is in 2 releases, Joomla 3.2.0 to 3.2.1. See them all, or every version of this file.