Example #1
0
	/**
	* @param string The name of the form element
	* @param string The value of the element
	* @param CBSimpleXMLElement  $node The xml element for the parameter
	* @param string The control name
	* @return string The html for the element
	*/
	function _form_usergroup( $name, $value, &$node, $control_name ) {
		$gtree = cbGetAllUsergroupsBelowMe();
	/*
		if ( ! $value ) {
			$value = $_CB_framework->acl->get_group_id('Registered','ARO');
			// array_unshift( $gtree, moscomprofilerHTML::makeOption( '0', '- Select User Group -' ) );
		}
	*/
		if ( ( $node->attributes( 'blanktext' ) ) && ( ( $node->attributes( 'hideblanktext' ) != 'true' ) || ( $value == 0 ) ) ) {
			array_unshift( $gtree, moscomprofilerHTML::makeOption( '0', $node->attributes( 'blanktext' ) ) );
		}
		$content	=	moscomprofilerHTML::selectList( $gtree, $this->control_name( $control_name, $name ), 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '" size="1"', 'value', 'text', (int) $value, 2, false, false );	//  size="10"
		return $content;
	}
	/**
	 * Implements a form usergroup
	 *
	 * @param  string              $name          The name of the form element
	 * @param  string              $value         The value of the element
	 * @param  SimpleXMLElement  $node          The xml element for the parameter
	 * @param  string              $control_name  The control name
	 * @return string                             The html for the element
	 */
	function _form_usergroup( $name, $value, &$node, $control_name ) {
		global $_CB_framework;

		static $texts						=	array();

		$size								=	0;
		$cols								=	$node->attributes( 'cols' );
		$rows								=	$node->attributes( 'rows' );
		$multi								=	( $node->attributes( 'multiple' ) == 'true' );

		if ( $this->_view ) {
			if ( $value === null ) {
				$selected					=	array();
			} else {
				if ( $multi && ( ! is_array( $value ) ) ) {
					$selected				=	explode( '|*|', $value );
				} else {
					$selected				=	array( $value );
				}
			}
			// remap literal groups (such as in default values) to the hardcoded CMS values:
			$selected							=	$_CB_framework->acl->mapGroupNamesToValues( $selected );
			foreach ( $selected as $k => $v ) {
				$selected[$k]					=	(string) $v;	// CB lists require strings to compare to values with ===
			}

			$contentOptions					=	$this->_list_options_selected( $name, $node, $control_name, $node->children(), $selected );
			$contentTexts					=	array();
			$contentValues					=	array();

			foreach ( $contentOptions as $contentOption ) {
				$contentValues[]			=	$contentOption->value;
				$contentTexts[]				=	htmlspecialchars( $contentOption->text );
			}

			foreach ( $selected as $v ) {
				if ( ! in_array( $v, $contentValues ) ) {
					if ( ! isset( $texts[$v] ) ) {
						if ( (int) $v == 0 ) {
							$texts[$v]		=	'-';
						} else {
							$texts[$v]		=	Application::CmsPermissions()->getGroupName( (int) $v );
						}
					}

					$text					=	$texts[$v];

					if ( $text ) {
						switch ( $v ) {
							case -2:
							case 1:
								$class		=	'text-success';
								break;
							case 6:
							case 7:
							case 8:
								$class		=	'text-danger';
								break;
							case 0:
								$class		=	'';
								break;
							default:
								$class		=	'text-warning';
								break;
						}

						$contentTexts[]		=	'<span class="' . $class . '">' . htmlspecialchars( $text ) . '</span>';
					}
				}
			}

			if ( count( $contentTexts ) > 0 ) {
				if ( $cols || $rows ) {
					$content				=	moscomprofilerHTML::list2Table( $contentTexts, $cols, $rows, $size );
				} else {
					$content				=	implode( ', ', $contentTexts );
				}
			} else {
				$content					=	' - ';
			}

			return $content;
		} else {
			$options						=	array();

			if ( ! is_array( $value ) ) {
				$value						=	explode( '|*|', $value );
			}

			// remap literal groups (such as in default values) to the hardcoded CMS values:
			$value							=	$_CB_framework->acl->mapGroupNamesToValues( $value );
			foreach ( $value as $k => $v ) {
				$value[$k]					=	(string) $v;	// CB lists require strings to compare to values with ===
			}

			$value							=	implode( '|*|', $value );

			$defaults						=	array( '', '--- ' . ( $multi ? CBTxt::T( 'Select User Group (CTR/CMD-Click: Multiple)' ) : CBTxt::T( 'Select User Group' ) ) . ' ---' );

			$this->_list_options_default( $node, $options, $value, $defaults );
			$this->_list_options( $name, $node, $control_name, $options, $node->children(), true, $value );

			$hideChoices					=	trim( $node->attributes( 'hidechoices' ) );
			$sqlOptions						=	cbGetAllUsergroupsBelowMe();

			if ( $hideChoices !== '' ) {
				$choicesNo					=	explode( ',', $hideChoices );

				foreach ( $choicesNo as $choice ) {
					foreach ( $sqlOptions as $k => $opt ) {
						if ( (string) $opt->text === (string) $choice ) {
							unset ( $sqlOptions[$k] );
							break;
						}
					}
				}
			}

			$this->_list_options_data( $node, $options, $sqlOptions, false );

			$selected						=	explode( '|*|', $value );

			if ( ( checkJversion() >= 2 ) && ( $node->attributes( 'managegroups' ) != 'false' ) ) {
				$htmlManageLevels			=	' &nbsp; <a target="_blank" class="cbAdminSmallLink" href="' . htmlspecialchars( 'index.php?option=com_users&view=groups' ) . '">' . CBTxt::Th( 'Manage User Groups' ) . '</a>';
			} else {
				$htmlManageLevels			=	'';
			}

			return $this->selectList( $options, $node, $control_name, $name, $selected, $multi, false ) . $htmlManageLevels;
		}
	}