Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('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
  18.  */
  19. class JFormFieldUser extends JFormField
  20. {
  21.     /**
  22.      * The form field type.
  23.      *
  24.      * @var    string 
  25.      * @since  1.6
  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
  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 !empty($this->class' class="' $this->class . '"' '';
  47.         $attr .= !empty($this->size' size="' $this->size . '"' '';
  48.         $attr .= $this->required ? ' required' '';
  49.  
  50.         // Load the modal behavior script.
  51.         JHtml::_('behavior.modal''a.modal_' $this->id);
  52.  
  53.         // Build the script.
  54.         $script array();
  55.         $script['    function jSelectUser_' $this->id . '(id, title) {';
  56.         $script['        var old_id = document.getElementById("' $this->id . '_id").value;';
  57.         $script['        if (old_id != id) {';
  58.         $script['            document.getElementById("' $this->id . '_id").value = id;';
  59.         $script['            document.getElementById("' $this->id . '").value = title;';
  60.         $script['            document.getElementById("' $this->id . '").className = document.getElementById("' $this->id . '").className.replace(" invalid" , "");';
  61.         $script['            ' $this->onchange;
  62.         $script['        }';
  63.         $script['        SqueezeBox.close();';
  64.         $script['    }';
  65.  
  66.         // Add the script to the document head.
  67.         JFactory::getDocument()->addScriptDeclaration(implode("\n"$script));
  68.  
  69.         // Load the current username if available.
  70.         $table JTable::getInstance('user');
  71.  
  72.         if (is_numeric($this->value))
  73.         {
  74.             $table->load($this->value);
  75.         }
  76.         // Handle the special case for "current".
  77.         elseif (strtoupper($this->value== 'CURRENT')
  78.         {
  79.             $table->load(JFactory::getUser()->id);
  80.         }
  81.         else
  82.         {
  83.             $table->username JText::_('JLIB_FORM_SELECT_USER');
  84.         }
  85.  
  86.         // Create a dummy text field with the user name.
  87.         $html['<div class="input-append">';
  88.         $html['    <input type="text" id="' $this->id . '" value="' htmlspecialchars($table->nameENT_COMPAT'UTF-8''"'
  89.             . ' readonly' $attr ' />';
  90.  
  91.         // Create the user select button.
  92.         if ($this->readonly === false)
  93.         {
  94.             $html['        <a class="btn btn-primary modal_' $this->id . '" title="' JText::_('JLIB_FORM_CHANGE_USER''" href="' $link '"'
  95.                 . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
  96.             $html['<i class="icon-user"></i></a>';
  97.         }
  98.  
  99.         $html['</div>';
  100.  
  101.         // Create the real field, hidden, that stored the user id.
  102.         $html['<input type="hidden" id="' $this->id . '_id" name="' $this->name . '" value="' . (int) $this->value . '" />';
  103.  
  104.         return implode("\n"$html);
  105.     }
  106.  
  107.     /**
  108.      * Method to get the filtering groups (null means no filtering)
  109.      *
  110.      * @return  mixed  array of filtering groups or null.
  111.      *
  112.      * @since   1.6
  113.      */
  114.     protected function getGroups()
  115.     {
  116.         return null;
  117.     }
  118.  
  119.     /**
  120.      * Method to get the users to exclude from the list of users
  121.      *
  122.      * @return  mixed  Array of users to exclude or null to to not exclude them
  123.      *
  124.      * @since   1.6
  125.      */
  126.     protected function getExcluded()
  127.     {
  128.         return null;
  129.     }
  130. }

Documentation generated on Tue, 19 Nov 2013 15:16:20 +0100 by phpDocumentor 1.4.3