/** * @param CBSimpleXMLElement $param object A param tag node * @param string $control_name The control name * @param boolean $view true if view only, false if editable * @param string $htmlFormatting 'table', 'fieldsListArray', etc. * @return array Any array of the label, the form element and the tooltip */ function renderParam( &$param, $control_name = 'params', $view = true, $htmlFormatting = 'table' ) { if ( $htmlFormatting == 'fieldsListArray' ) { return array( null, $this->control_name( $control_name, $param->attributes( 'name' ) ), null ); } $result = array(); $type = $param->attributes( 'type' ); $name = $param->attributes( 'name' ); $label = CBTxt::T( getLangDefinition($param->attributes( 'label' ))); $description = $param->attributes( 'description' ); if ( $description !== null && $description !== '' ) { $description = CBTxt::T( getLangDefinition(htmlspecialchars( $description ))); } if ( $name ) { if ( $type == 'spacer' ) { $value = $param->attributes( 'default' ); } elseif ( ( $type == 'private' ) && ( ! ( get_class( $this->getModelOfData() ) == 'cbParamsBase' ) ) && ! isset( $this->getModelOfData()->$name ) ) { $value = $param->attributes( 'value' ); //TBD: we will need to improve this: this case is a workaround to avoid accessing with get() an unexistant variable } else { $value = $this->get( $name, $param->attributes( 'default' ) ); } } else { $value = $param->attributes( 'default' ); } if ( $param->attributes( 'translate' ) == '_UE' ) { $value = getLangDefinition( $value ); } elseif ( $param->attributes( 'translate' ) == 'yes' ) { $value = CBTxt::T( $value ); } $result[0] = $label ? $label : $name; if ( $result[0] == '@spacer' ) { $result[0] = '<hr/>'; } else if ( $result[0] ) { if ($name == '@spacer') { $result[0] = '<strong>'.$result[0].'</strong>'; } else { if ( trim( $result[0] ) ) { $result[0] .= ':'; } } } $result[1] = null; /* up to proof of contrary, not needed, as type="private" does it... //TBD remove this once sure if ( $type == 'privateparam' ) { $className = $param->attributes( 'class' ); $methodName = $param->attributes( 'method' ); if ( ! $className ) { $className = $this->_parentModelOfView->attributes( 'class' ); } if ( $className && $methodName && class_exists( $className ) ) { global $_CB_database; $obj = new $className( $_CB_database ); if ( method_exists( $obj, $methodName ) ) { $control_name_name = $this->control_name( $control_name, $name ); $result[1] = $obj->$methodName( $param, $control_name, $view, $name, $control_name_name, $value, $this->_pluginParams, $type ); //TBD FIXME: pluginParams should be available by the method params() of $obj, not as function parameter } else { $result[1] = "Missing method " . $methodName. " in class " . $className; } } else { $result[1] = "Missing class " . $className . ", and/or method " . $methodName . " in xml"; } } */ if ( substr( $type, 0, 4 ) == 'xml:' ) { $xmlType = substr( $type, 4 ); if ( $this->_types ) { $typeModel = $this->_types->getChildByNameAttr( 'type', 'name' , $xmlType ); // find root type: if ( $typeModel ) { $root = $typeModel; for ( $i = 0; $i < 100; $i++ ) { if ( substr( $root->attributes( 'base' ), 0, 4 ) == 'xml:' ) { $subbasetype = $root->attributes( 'base' ); $root = $this->_types->getChildByNameAttr( 'type', 'name' , substr( $subbasetype, 4 ) ); if ( ! $root ) { $result[1] = "Missing type definition of " . $subbasetype; break; } } else { // we found the root and type: $type = $root->attributes( 'base' ); break; } } if ( $i >= 99 ) { echo 'Error: recursion loop in XML type definition of ' . $typeModel->name() . ' ' . $typeModel->attributes( 'name' ) . ' type: ' . $typeModel->attributes( 'type' ); exit; } $levelModel = $typeModel; $insertAfter = array(); for ( $i = 0; $i < 100; $i++ ) { switch ( $type ) { case 'list': case 'multilist': case 'radio': case 'checkbox': if ( $view ) { $valueNode = $levelModel->getAnyChildByNameAttr( 'option', 'value', $value ); // recurse in children over optgroups if needed. if ( $valueNode ) { $result[1] = CBTxt::T( $valueNode->data() ); } } else { if ( $levelModel->attributes( 'insertbase' ) != 'before' ) { foreach ( $levelModel->children() as $option ) { if ( $option->name() == 'option' ) { $param->addChildWithAttr( 'option', $option->data(), null, $option->attributes() ); } elseif ( $option->name() == 'optgroup' ) { $paramOptgroup = $param->addChildWithAttr( 'optgroup', $option->data(), null, $option->attributes() ); // in HTML 4, optgroups can not be nested (w3c) foreach ( $option->children() as $optChild ) { if ( $optChild->name() == 'option' ) { $paramOptgroup->addChildWithAttr( 'option', $optChild->data(), null, $optChild->attributes() ); } } } } } else { $insertAfter[] = $levelModel; } } break; default: if ( $view ) { $result[1] = "Unknown base type " . $type . " in XML"; } else { $param->addChildWithAttr( 'option', "Unknown base type " . $type . " in XML", null, array( 'value' => '0') ); } break; } if ( ( $levelModel->attributes( 'name' ) == $typeModel->attributes( 'name' ) ) && ( substr( $levelModel->attributes( 'type' ), 0, 4 ) == 'xml:' ) ) { $levelModel = $this->_types->getChildByNameAttr( 'type', 'name' , substr( $levelModel->attributes( 'type' ), 4 ) ); } elseif ( substr( $levelModel->attributes( 'base' ), 0, 4 ) == 'xml:' ) { $levelModel = $this->_types->getChildByNameAttr( 'type', 'name' , substr( $levelModel->attributes( 'base' ), 4 ) ); } else { break; } } foreach ( $insertAfter as $levelModel ) { foreach ($levelModel->children() as $option ) { if ( $option->name() == 'option' ) { $param->addChildWithAttr( 'option', $option->data(), null, $option->attributes() ); } elseif ( $option->name() == 'optgroup' ) { $paramOptgroup = $param->addChildWithAttr( 'optgroup', $option->data(), null, $option->attributes() ); foreach ( $option->children() as $optChild ) { if ( $optChild->name() == 'option' ) { $paramOptgroup->addChildWithAttr( 'option', $optChild->data(), null, $optChild->attributes() ); } } } } } } else { $result[1] = "Missing type def. for param-type " . $param->attributes( 'type' ); } } else { $result[1] = "No types defined in XML"; } } if ( ! isset( $this->_methods ) ) { $this->_methods = get_class_methods( get_class( $this ) ); } if ($result[1] ) { // nothing to do } elseif ( $this->_extendViewParser && in_array( '_form_' . $type, $this->_extendViewParser->_methods ) ) { $this->_view = $view; $this->_extendViewParser->_view = $view; $result[1] = call_user_func( array( &$this->_extendViewParser, '_form_' . $type ), $name, $value, $param, $control_name ); } elseif (in_array( '_form_' . $type, $this->_methods )) { $this->_view = $view; $result[1] = call_user_func( array( &$this, '_form_' . $type ), $name, $value, $param, $control_name ); } else { $result[1] = sprintf( CBTxt::T("Parameter Handler for type=%s is not implemented or not loaded."), $type ); } if ( $result[1] && ( $htmlFormatting != 'fieldsListArray' ) ) { $validate = $param->attributes( 'validate' ); if ( ( ! $view ) && in_array( 'required', explode( ' ', $validate ) ) ) { $result[1] .= ' <span class="cbform_required_star" title="' . htmlspecialchars( _UE_FIELDREQUIRED ) . '">*</span> '; } } if ( $description ) { $result[2] = cbFieldTip( null, $description, $name ); } else { $result[2] = ''; } if ( ( ! $view ) && ( ! $result[1] ) ) { $result = array( null, null, null ); } return $result; }