PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/com_flexicontent_v2.x/admin/elements/flexiusergroup.php

http://flexicontent.googlecode.com/
PHP | 179 lines | 105 code | 21 blank | 53 comment | 31 complexity | 1bcecb235ffb17c8eb5f7dfc52125dd7 MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @version 1.5 stable $Id: flexiusergroup.php 1348 2012-06-19 02:38:15Z ggppdk $
  4. * @package Joomla
  5. * @subpackage FLEXIcontent
  6. * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
  7. * @license GNU/GPL v2
  8. *
  9. * FLEXIcontent is a derivative work of the excellent QuickFAQ component
  10. * @copyright (C) 2008 Christoph Lukes
  11. * see www.schlu.net for more information
  12. *
  13. * FLEXIcontent is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. // Check to ensure this file is included in Joomla!
  19. defined('_JEXEC') or die('Restricted access');
  20. if (FLEXI_J16GE) {
  21. jimport('joomla.html.html');
  22. jimport('joomla.form.formfield');
  23. jimport('joomla.form.helper');
  24. //jformhelper::loadFieldClass('usergroup');
  25. }
  26. /**
  27. * Form Field class for the Joomla Platform.
  28. * Supports a nested check box field listing user groups.
  29. * Multiselect is available by default.
  30. *
  31. * @package Joomla
  32. * @subpackage FLEXIcontent
  33. * @since 1.5
  34. */
  35. class JFormFieldFLEXIUsergroup extends JFormField // JFormFieldUsergroup
  36. {
  37. /**
  38. * The form field type OR name
  39. * @access protected
  40. * @var string
  41. */
  42. protected $type = 'FLEXIUsergroup';
  43. /**
  44. * Method to get the user group field input markup.
  45. *
  46. * @return string The field input markup.
  47. *
  48. * @since 11.1
  49. */
  50. protected function getInput()
  51. {
  52. if (FLEXI_J16GE) $node = & $this->element;
  53. // Get attribute array
  54. if (FLEXI_J16GE) {
  55. $node = & $this->element;
  56. $attributes = get_object_vars($node->attributes());
  57. $attributes = $attributes['@attributes'];
  58. $children = $node->children();
  59. } else {
  60. $attributes = & $node->_attributes;
  61. $children = & $node->_children;
  62. }
  63. // Get values array
  64. $values = FLEXI_J16GE ? $this->value : $value;
  65. if ( empty($values) ) $values = array();
  66. else if ( ! is_array($values) ) $values = !FLEXI_J16GE ? array($values) : explode("|", $values);
  67. // Get field and element name
  68. $fieldname = FLEXI_J16GE ? $this->name : $control_name.'['.$name.']';
  69. $element_id = FLEXI_J16GE ? $this->id : $control_name.$name;
  70. // Initialize variables.
  71. $extra_options = array();
  72. $allowAll = @$attributes['allowall'];
  73. $faGrps = @$attributes['fagrps'];
  74. // Iterate through the children and build an array of options.
  75. foreach ($children as $option)
  76. {
  77. // Only add <option /> elements.
  78. $is_option = (FLEXI_J16GE && $option->getName()=='option') || (!FLEXI_J16GE && $option->_name=='option');
  79. if ( !$is_option ) continue;
  80. // Get variable for creating an extra option object based on the <option /> element
  81. $option_value = (string)( FLEXI_J16GE ? $option['value'] : $option->_attributes['value']);
  82. $option_text = (string)( FLEXI_J16GE ? trim((string) $option) : $option->_data);
  83. $option_disabled = (string)( FLEXI_J16GE ? $option['disabled'] : $option->_attributes['disabled']);
  84. $option_disabled = ((string) $option_disabled == 'true');
  85. // Create the extra option object
  86. $tmp = JHtml::_('select.option', $option_value, $option_text, 'value', 'text', $option_disabled);
  87. // Class / JS / other attributes
  88. $tmp->class = (string)( FLEXI_J16GE ? $option['class'] : $option->_attributes['class']);
  89. $tmp->onclick = (string)( FLEXI_J16GE ? $option['onclick'] : $option->_attributes['onclick']);
  90. // Add the option object to the result set.
  91. $extra_options[] = $tmp;
  92. }
  93. $db = JFactory::getDBO();
  94. if ( FLEXI_ACCESS && $faGrps ) {
  95. $db->setQuery(
  96. 'SELECT a.id AS value, a.name AS text, 1 AS level' .
  97. ' FROM #__flexiaccess_groups AS a' .
  98. ' ORDER BY a.name ASC'
  99. );
  100. $options = $db->loadObjectList();
  101. for ($i = 0, $n = count($options); $i < $n; $i++)
  102. {
  103. $options[$i]->text = str_replace('FLEXIACCESS_GR_REGISTERED', '** Registered **', $options[$i]->text);
  104. $options[$i]->text = str_replace('FLEXIACCESS_GR_PUBLIC', '** Public **', $options[$i]->text);
  105. }
  106. } else if (!FLEXI_J16GE) {
  107. $acl = JFactory::getACL();
  108. $options = $acl->get_group_children_tree( null, 'USERS', false );
  109. } else {
  110. $db->setQuery(
  111. 'SELECT a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level' .
  112. ' FROM #__usergroups AS a' .
  113. ' LEFT JOIN `#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt' .
  114. ' GROUP BY a.id' .
  115. ' ORDER BY a.lft ASC'
  116. );
  117. $options = $db->loadObjectList();
  118. if ($db->getErrorNum()) JFactory::getApplication()->enqueueMessage(__FUNCTION__.'(): SQL QUERY ERROR:<br/>'.nl2br($db->getErrorMsg()),'error');
  119. if ( !$options ) return null;
  120. for ($i = 0, $n = count($options); $i < $n; $i++)
  121. {
  122. $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
  123. }
  124. }
  125. // If all usergroups is allowed, push it into the array.
  126. if ($allowAll) {
  127. array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_GROUPS')));
  128. }
  129. $options = array_merge($extra_options, $options);
  130. $attribs = 'style="float:left;"';
  131. $initial_size = @$attributes['size'] ? intval($attributes['size']) : 5;
  132. $maximize_size = @$attributes['maxsize'] ? intval($attributes['maxsize']) : count($options);
  133. // SPECIAL CASE: this field is always multiple, we will add '[]' WHILE checking for the attribute ...
  134. if ( @$attributes['multiple']=='multiple' || @$attributes['multiple']=='true' ) {
  135. $attribs .=' multiple="multiple"';
  136. $attribs .= ' size="'.$initial_size.'" ';
  137. $fieldname .= !FLEXI_J16GE ? "[]" : ""; // NOTE: this added automatically in J2.5
  138. $maximize_link = "<a style='display:inline-block;".(FLEXI_J16GE ? 'float:left; margin: 6px 0px 0px 18px;':'margin:0px 0px 6px 12px')."' href='javascript:;' onclick='$element_id = document.getElementById(\"$element_id\"); if ($element_id.size<".$maximize_size.") { ${element_id}_oldsize=$element_id.size; $element_id.size=".$maximize_size.";} else { $element_id.size=${element_id}_oldsize; } ' >Maximize/Minimize</a>";
  139. } else {
  140. $maximize_link = '';
  141. }
  142. if ($initial_size >= count($options) || $initial_size>= $maximize_size) $maximize_link = '';
  143. // Initialize some field attributes.
  144. $attribs .= ((string) @$this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
  145. // Initialize JavaScript field attributes.
  146. $attribs .= @$this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
  147. $classes = '';
  148. if ( @$attributes['required'] && @$attributes['required']!='false' ) {
  149. $classes .= ' required';
  150. }
  151. if ( $node->attributes('validation_class') ) {
  152. $classes .= ' '.$node->attributes('validation_class');
  153. }
  154. $attribs .= ' class="'.$classes.'"';
  155. $html = JHTML::_('select.genericlist', $options, $fieldname, $attribs, 'value', 'text', $values, $element_id);
  156. return $html.$maximize_link;
  157. }
  158. }