function renderOneParamAndChildren( &$param, $control_name='params', $tabs=null, $viewType = 'depends', $htmlFormatting = 'table' ) { static $tabNavJS = array(); // javascript for all nested tabs. static $tabpaneCounter = 0; // level of tabs (for nested tabs) // static $tabpaneNames = array(); // names of the tabpanes of level [tabpaneCounter] for the tabpanetabs $html = array(); $viewMode = $param->attributes( 'mode' ); switch ( $viewMode ) { // case 'view': case 'show': $viewType = 'view'; break; // case 'param': case 'edit': $viewType = 'param'; break; default: break; } // treat any <attributes> below the tag to add attributes to the tag as needed: $this->extendParamAttributes( $param, $control_name, ( $viewType == 'view' ) ); switch ( $param->name() ) { case 'inherit': $from = $param->attributes( 'from' ); if ( $from ) { $fromXml = $param->xpath( $from ); if ( $fromXml && ( count( $fromXml ) > 0 ) ) { array_unshift( $this->_extenders, array( &$param ) ); foreach ( $fromXml as $fmx ) { $html[] = $this->renderAllParams( $fmx, $control_name, $tabs, $viewType, $htmlFormatting ); } } } break; case 'param': $result = $this->renderParam( $param, $control_name, ( $viewType == 'view' ), $htmlFormatting ); $dynamic = ( ( ! ( $viewType == 'view' ) ) && ( $param->attributes( 'onchange' ) == 'evaluate' ) ); if ( $dynamic && ( $viewType == 'param' ) && ( $htmlFormatting != 'fieldsListArray' ) ) { $result[1] .= '<noscript><button type="submit" name="cbdoevalpostagain" value="" class="button cbregOnChange">' . CBTxt::Th("Change") . '</button></noscript>'; } if ( $result[1] || ( $viewType != 'view' ) || ( $param->attributes( 'hideblanktext' ) != 'true' ) ) { $html[] = $this->_renderLine( $param, $result, $control_name, $htmlFormatting ); if ( $dynamic ) { $ifName = $this->_htmlId( $control_name, $param ); $this->_jsif[$ifName]['element'] = $param; $this->_jsif[$ifName]['control_name'] = $control_name; $this->_jsif[$ifName]['ifname'] = $ifName; $this->_jsif[$ifName]['onchange'] = $param->attributes( 'onchange' ); } } break; case 'params': $paramsName = $param->attributes( 'name' ); $paramsType = $param->attributes( 'type' ); if ( ( ( $paramsType == 'params' ) && $paramsName ) || ( $paramsType == 'pluginparams' ) ) { if ( $paramsType == 'params' ) { $valueObj =& $this->_parseParamsColumn( $paramsName ); } else { $valueObj =& $this->_pluginParams; } $this->pushModelOfData( $valueObj ); if ( $control_name ) { $child_cnam = $control_name . '[' . $paramsName . ']'; } else { $child_cnam = $paramsName; } $html[] = $this->renderAllParams( $param, $child_cnam, $tabs, $viewType, $htmlFormatting ); $this->popModelOfData(); } break; case 'field': $result = $this->renderParam( $param, $control_name, ( $viewType != 'param' ) ); $link = $param->attributes( 'link' ); $title = $param->attributes( 'title' ); if ( $title ) { $title = ' title="' . htmlspecialchars( CBPTXT::T( $title ) ) . '"'; } else { $title = ''; } if ( $htmlFormatting != 'fieldsListArray' ) { if ( $link ) { if ( $param->attributes( 'target' ) == '_blank' ) { $linkhref = $this->_controllerView->drawUrl( $link, $param, $this->_modelOfData[0], isset( $this->_modelOfData[0]->id ) ? $this->_modelOfData[0]->id : null, true, false ); //TBD NOT URGENT: hardcoded id column name 'id' $onclickJS = 'window.open(\'' . htmlspecialchars( cbUnHtmlspecialchars( $linkhref ) ) . '\', \'cbtablebrowserpopup\', \'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\'); return false;'; $rowOnclickHtml = ' onclick="' . $onclickJS . '"'; } else { $linkhref = $this->_controllerView->drawUrl( $link, $param, $this->_modelOfData[0], isset( $this->_modelOfData[0]->id ) ? $this->_modelOfData[0]->id : null, true ); //TBD NOT URGENT: hardcoded id column name 'id' $rowOnclickHtml = ''; } $result[1] = '<a href="' . $linkhref .'"' . $title . $rowOnclickHtml . '>' . ( trim( $result[1] ) ? $result[1] : '---' ) . '</a>'; } elseif ( $title ) { $result[1] = '<span' . $title . '>' . $result[1] . '</span>'; } } $html[] = $this->_renderLine( $param, $result, $control_name, $htmlFormatting, false ); break; case 'fieldset': $htid = $this->_outputIdEqualHtmlId( $control_name, $param ); $legend = $param->attributes( 'label' ); $description = $param->attributes( 'description' ); $name = $param->attributes( 'name' ); $class = $param->attributes( 'class' ); $fieldsethtml = '<fieldset' . ( $class ? ' class="' . $class . '"' : ( $name ? ( ' class="cbfieldset_' . $name . '"' ) : '' ) ) . '>'; if ( $htmlFormatting == 'table' ) { $html[] = '<tr' . $htid . '><td colspan="3" width="100%">' . $fieldsethtml; } elseif ( $htmlFormatting == 'td' ) { $html[] = "\t\t\t<td" . $htid . ">" . $fieldsethtml; } elseif ( $htmlFormatting == 'span' ) { $html[] = '<div' . $htid . '>' . $fieldsethtml; } elseif ( $htmlFormatting == 'fieldsListArray' ) { // nothing } else { $html[] = '<fieldset' . $htid . ( $name ? ( ' class="cbfieldset_' . $name . '"' ) : '' ) . '>'; } if ( $legend && ( $htmlFormatting != 'fieldsListArray' ) ) { $html[] = '<legend' . ( $class ? ' class="' . $class . '"' : '' ) . '>' . CBTxt::Th( getLangDefinition($legend) ) . '</legend>'; } if ( $htmlFormatting == 'table' ) { $html[] = '<table class="paramlist" cellspacing="0" cellpadding="0" width="100%">'; if ( $description ) { $html[] = '<tr><td colspan="3" width="100%"><strong>' . CBTxt::Th( getLangDefinition($description) ) . '</strong></td></tr>'; } } elseif ( $htmlFormatting == 'td' ) { if ( $description ) { $html[] = '<td colspan="3" width="100%"><strong>' . CBTxt::Th( getLangDefinition($description) ) . '</strong></td>'; } } elseif ( $htmlFormatting == 'span' ) { if ( $description ) { $html[] = '<span class="cbLabelSpan">' . CBTxt::Th( getLangDefinition($description) ) . '</span> '; } $html[] = '<span class="cbFieldSpan">'; } elseif ( $htmlFormatting == 'fieldsListArray' ) { // nothing } else { if ( $description ) { $html[] = '<strong>' . CBTxt::Th( getLangDefinition($description) ) . '</strong>'; } } $html[] = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); if ( $htmlFormatting == 'table' ) { $html[] = "\n\t</table>"; $html[] = '</fieldset></td></tr>'; } elseif ( $htmlFormatting == 'td' ) { $html[] = '</fieldset></td>'; } elseif ( $htmlFormatting == 'span' ) { $html[] = '</span></fieldset></div>'; } elseif ( $htmlFormatting == 'fieldsListArray' ) { // nothing } else { $html[] = '</fieldset>'; } break; case 'fields': case 'status': $html[] = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); break; case 'if': $showInside = true; $ifType = $param->attributes( 'type' ); if ( ( $ifType == 'showhide' ) && ( ! ( $viewType == 'view' ) ) ) { $ifName = $this->_htmlId( $control_name, $param ) . $param->attributes( 'operator' ) . $param->attributes( 'value' ). $param->attributes( 'valuetype' ); // $this->_jsif[$ifName] = array(); // $this->_jsif[$ifName]['show']= array(); // $this->_jsif[$ifName]['set'] = array(); if ( count( $param->children() ) > 0 ) { foreach ( $param->children() as $subParam ) { if ( $subParam->name() == 'showview' ) { $viewName = $subParam->attributes( 'view' ); $viewModel =& $this->_views->getChildByNameAttributes( 'view', array( 'ui' => 'admin', 'name' => $viewName ) ); if ( !$viewModel ) { echo 'Extended renderAllParams:showview: View ' . $viewName . ' not defined in XML'; return false; } foreach ( $viewModel->children() as $vChild ) { $this->_jsif[$ifName]['show'][] = $this->_htmlId( $control_name, $vChild ); } } elseif ( in_array( $subParam->name(), array( 'params', 'fields', 'status', 'if' ) ) ) { if ( count( $subParam->children() ) > 0 ) { if ( $subParam->name() == 'params' ) { $paramsName = $subParam->attributes( 'name' ); if ( $control_name ) { $child_cnam = $control_name . '[' . $paramsName . ']'; } else { $child_cnam = $paramsName; } } else { $child_cnam = $control_name; } foreach ( $subParam->children() as $vChild ) { if ( ! in_array( $vChild->name(), array( 'showview', 'if', 'else' ) ) ) { //TBD //FIXME: this avoids JS error but still shows sub-view ! recursive function needed here $this->_jsif[$ifName]['show'][] = $this->_htmlId( $child_cnam, $vChild ); } elseif ( $vChild->name() == 'if' ) { foreach ( $vChild->children() as $vvChild ) { if ( ! in_array( $vvChild->name(), array( 'showview', 'if', 'else', 'params', 'fields', 'status' ) ) ) { //TBD //FIXME: this avoids JS error but still shows sub-view ! recursive function needed here $this->_jsif[$ifName]['show'][] = $this->_htmlId( $child_cnam, $vvChild ); } elseif ( $vvChild->name() == 'if' ) { foreach ( $vvChild->children() as $vvvChild ) { if ( ! in_array( $vvvChild->name(), array( 'showview', 'if', 'else', 'params', 'fields', 'status' ) ) ) { //TBD //FIXME: this avoids JS error but still shows sub-view ! recursive function needed here $this->_jsif[$ifName]['show'][] = $this->_htmlId( $child_cnam, $vvvChild ); } } } } } } } } elseif ( $subParam->name() == 'else' ) { if ( $subParam->attributes( 'action' ) == 'set' ) { $correspondingParam = $param->getAnyChildByNameAttr( 'param', 'name', $subParam->attributes( 'name' ) ); if ( $correspondingParam ) { $this->_jsif[$ifName]['set'][] = $this->_htmlId( $control_name, $correspondingParam ) . '=' . $this->control_id( $control_name, $subParam->attributes( 'name' ) ) . '=' . $subParam->attributes( 'value' ); } else { echo 'No corresponding param to the else statement for name ' . $subParam->attributes( 'name' ) . ' !'; } } } else { $this->_jsif[$ifName]['show'][] = $this->_htmlId( $control_name, $subParam ); } } $this->_jsif[$ifName]['element'] = $param; $this->_jsif[$ifName]['control_name'] = $control_name; $this->_jsif[$ifName]['ifname'] = $this->_htmlId( $control_name, $param ); } } elseif ( ( $ifType == 'condition' ) || ( $viewType == 'view' ) ) { $showInside = $this->_evalIf( $param ); } if ( $showInside ) { $html[] = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); } break; case 'else': break; // implemented in if above it case 'toolbarmenu': break; // implemented in higher level case 'tabpane': // first render all tabpanetabs (including nested tabpanes): $tabpaneCounter++; $this->tabpaneNames[$tabpaneCounter] = $param->attributes( 'name' ); $subhtml = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); unset( $this->tabpaneNames[$tabpaneCounter] ); $tabpaneCounter--; if ( $htmlFormatting != 'fieldsListArray' ) { // then puts them together: $htid = $this->_outputIdEqualHtmlId( $control_name, $param ); if ( $htmlFormatting == 'table' ) { $html[] = '<tr' . $htid . '><td colspan="3" width="100%">'; } elseif ( $htmlFormatting == 'td' ) { $html[] = '<td' . $htid . '>'; } if ( $tabpaneCounter == 0 ) { $html[] = $tabs->_getTabNavJS( $param->attributes( 'name' ), $tabNavJS ); $tabNavJS = array(); } $html[] = $tabs->startPane( $param->attributes( 'name' ) ); } $html[] = $subhtml; if ( $htmlFormatting != 'fieldsListArray' ) { $html[] = $tabs->endPane(); if ( $htmlFormatting == 'table' ) { $html[] = '</td></tr>'; } elseif ( $htmlFormatting == 'td' ) { $html[] = '</td>'; } } break; case 'tabpanetab': if ( $htmlFormatting != 'fieldsListArray' ) { $i = $this->_i++; $idtab = $this->tabpaneNames[$tabpaneCounter] . $this->_i; $html[] = $tabs->startTab( $this->tabpaneNames[$tabpaneCounter], CBTxt::T( getLangDefinition( $param->attributes( 'label' ) ) ), $idtab ); $html[] = '<table class="paramlist" cellspacing="0" cellpadding="0" width="100%">'; $tabName = $param->attributes( 'name' ); $tabTitle = $param->attributes( 'title' ); $description = $param->attributes( 'description' ); if ( $tabTitle ) { $html[] = '<tr><td colspan="3" width="100%"><h3' . ( $tabName ? ' class="cbTH' . $this->tabpaneNames[$tabpaneCounter] . $tabName . '"' : '' ) . '>' . CBTxt::Th( getLangDefinition( $tabTitle ) ) . '</h3></td></tr>'; } if ( $description || ! $tabTitle ) { $html[] = '<tr><td colspan="3" width="100%"><strong>' . CBTxt::Th( getLangDefinition( $description ) ) . '</strong></td></tr>'; // either description or a spacer. } } $html[] = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); if ( $htmlFormatting != 'fieldsListArray' ) { $html[] = "\n\t</table>"; $html[] = $tabs->endTab(); $tabNavJS[$i]->nested = ( $tabpaneCounter > 1 ); $tabNavJS[$i]->name = CBTxt::T( getLangDefinition( $param->attributes( 'label' ) ) ); $tabNavJS[$i]->id = $idtab; $tabNavJS[$i]->pluginclass = $idtab; } break; case 'extendparser': $this->setExtendedViewParser( $param ); break; default: if ( $this->_extendViewParser ) { $html[] = $this->_extendViewParser->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting ); } else { echo 'Method to render XML view element ' . $param->name() . ' is not implemented !'; } break; } return ( $htmlFormatting == 'fieldsListArray' ? $html : implode( "\n", $html ) ); }