PageRenderTime 24ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/cms/form/field/user.php

https://bitbucket.org/eternaware/joomus
PHP | 128 lines | 63 code | 15 blank | 50 comment | 3 complexity | 6333a89ee5725e99a964a5d5f498e030 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Libraries
  4 * @subpackage  Form
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('JPATH_PLATFORM') or die;
 11
 12/**
 13 * Field to select a user id from a modal list.
 14 *
 15 * @package     Joomla.Libraries
 16 * @subpackage  Form
 17 * @since       1.6.0
 18 */
 19class JFormFieldUser extends JFormField
 20{
 21	/**
 22	 * The form field type.
 23	 *
 24	 * @var    string
 25	 * @since  1.6.0
 26	 */
 27	public $type = 'User';
 28
 29	/**
 30	 * Method to get the user field input markup.
 31	 *
 32	 * @return  string  The field input markup.
 33	 *
 34	 * @since   1.6.0
 35	 */
 36	protected function getInput()
 37	{
 38		$html = array();
 39		$groups = $this->getGroups();
 40		$excluded = $this->getExcluded();
 41		$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id
 42			. (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
 43			. (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');
 44
 45		// Initialize some field attributes.
 46		$attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
 47		$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
 48
 49		// Initialize JavaScript field attributes.
 50		$onchange = (string) $this->element['onchange'];
 51
 52		// Load the modal behavior script.
 53		JHtml::_('behavior.modal', 'a.modal_' . $this->id);
 54
 55		// Build the script.
 56		$script = array();
 57		$script[] = '	function jSelectUser_' . $this->id . '(id, title) {';
 58		$script[] = '		var old_id = document.getElementById("' . $this->id . '_id").value;';
 59		$script[] = '		if (old_id != id) {';
 60		$script[] = '			document.getElementById("' . $this->id . '_id").value = id;';
 61		$script[] = '			document.getElementById("' . $this->id . '_name").value = title;';
 62		$script[] = '			' . $onchange;
 63		$script[] = '		}';
 64		$script[] = '		SqueezeBox.close();';
 65		$script[] = '	}';
 66
 67		// Add the script to the document head.
 68		JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
 69
 70		// Load the current username if available.
 71		$table = JTable::getInstance('user');
 72		if ($this->value)
 73		{
 74			$table->load($this->value);
 75		}
 76		else
 77		{
 78			$table->username = JText::_('JLIB_FORM_SELECT_USER');
 79		}
 80
 81		// Create a dummy text field with the user name.
 82		$html[] = '<div class="fltlft">';
 83		$html[] = '	<input type="text" id="' . $this->id . '_name"' . ' value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"'
 84			. ' disabled="disabled"' . $attr . ' />';
 85		$html[] = '</div>';
 86
 87		// Create the user select button.
 88		$html[] = '<div class="button2-left">';
 89		$html[] = '  <div class="blank">';
 90		if ($this->element['readonly'] != 'true')
 91		{
 92			$html[] = '		<a class="modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '"' . ' href="' . $link . '"'
 93				. ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
 94			$html[] = '			' . JText::_('JLIB_FORM_CHANGE_USER') . '</a>';
 95		}
 96		$html[] = '  </div>';
 97		$html[] = '</div>';
 98
 99		// Create the real field, hidden, that stored the user id.
100		$html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . (int) $this->value . '" />';
101
102		return implode("\n", $html);
103	}
104
105	/**
106	 * Method to get the filtering groups (null means no filtering)
107	 *
108	 * @return  mixed  array of filtering groups or null.
109	 *
110	 * @since   1.6.0
111	 */
112	protected function getGroups()
113	{
114		return null;
115	}
116
117	/**
118	 * Method to get the users to exclude from the list of users
119	 *
120	 * @return  mixed  Array of users to exclude or null to to not exclude them
121	 *
122	 * @since   1.6.0
123	 */
124	protected function getExcluded()
125	{
126		return null;
127	}
128}