tag => view )
* @param atring $htmlFormatting ( 'table', 'td', 'none' )
*
*/
function renderEditRowView( &$modelOfView, &$modelOfData, &$controllerView, $options, $viewType = 'depends', $htmlFormatting = 'table' ) {
global $_CB_framework;
if ( $this->_parentModelOfView === null ) {
$this->setParentView( $modelOfView );
}
$this->pushModelOfData( $modelOfData );
$this->_controllerView =& $controllerView;
$this->_options = $options;
if ( $this->_extendViewParser ) {
$html = $this->_extendViewParser->renderEditRowView( $modelOfView, $modelOfData, $controllerView, $options, $viewType, $htmlFormatting );
if ( $html ) {
return $html;
}
}
$html = array();
if ( $htmlFormatting == 'table' ) {
$html[] = '';
}
$jsCode = $this->_compileJsCode();
if ( $jsCode && ( $htmlFormatting != 'fieldsListArray' ) ) {
$_CB_framework->document->addHeadScriptDeclaration( $jsCode );
}
return ( $htmlFormatting == 'fieldsListArray' ? $html : implode( "\n", $html ) );
}
/**
* @param string The name of the field
* @param mixed The default value if not found
* @return string
*/
function get( $key, $default=null ) {
if ( isset( $this->_modelOfData[0]->$key ) ) {
if (is_array( $default ) ) {
return explode( '|*|', $this->_modelOfData[0]->$key );
} else {
return $this->_modelOfData[0]->$key;
}
} else {
return $default;
}
}
function _compileJsCode( ) {
if ( count( $this->_jsif ) == 0 ) {
return null;
}
$js = '';
static $i = 0;
foreach ( $this->_jsif as $ifVal ) {
$ifName = $ifVal['ifname'];
$element = $ifVal['element'];
$name = $this->control_id( $ifVal['control_name'], $element->attributes( 'name' ) );
$operator = $element->attributes( 'operator' );
$value = $element->attributes( 'value' );
// $valuetype = $element->attributes( 'valuetype' );
if ( $operator ) {
$operatorNegation = array( '=' => '!=', '==' => '!=', '!=' => '==', '<>' => '==', '<' => '>=', '>' => '<=', '<=' => '>', '>=' => '<', 'regexp' => 'regexp' );
$revertedOp = $operatorNegation[$operator];
} elseif ( isset( $ifVal['onchange'] ) && ( $ifVal['onchange'] == 'evaluate' ) ) {
$revertedOp = 'evaluate';
} else {
$revertedOp = 'no-operator-specified-in-xml';
}
//if ( in_array( $valuetype, array( 'string', 'const:string', 'text', 'const:text' ) ) ) {
// $value = "\\'" . $value . "\\'";
//}
if ( isset( $ifVal['show'] ) && ( count( $ifVal['show'] ) > 0 ) ) {
$show = "['" . implode( "','", $ifVal['show'] ) . "']";
} else {
$show = "[]";
}
if ( isset( $ifVal['set'] ) && ( count( $ifVal['set'] ) > 0 ) ) {
$set = "['" . implode( "','", $ifVal['set'] ) . "']";
} else {
$set = "[]";
}
$js .= "cbHideFields[" . $i . "] = new Array();\n";
$js .= "cbHideFields[" . $i . "][0] = '" . $ifName . "';\n";
$js .= "cbHideFields[" . $i . "][1] = '" . $name . "';\n";
$js .= "cbHideFields[" . $i . "][2] = '" . $revertedOp . "';\n";
$js .= "cbHideFields[" . $i . "][3] = '" . str_replace( '\\', '\\\\', $value ) . "';\n";
$js .= "cbHideFields[" . $i . "][4] = " . $show . ";\n";
$js .= "cbHideFields[" . $i . "][5] = " . $set . ";\n";
$i++;
}
return $js;
}
function _evalIf( &$element ) {
$name = $element->attributes( 'name' );
$operator = $element->attributes( 'operator' );
$value = $element->attributes( 'value' );
// $valuetype = $element->attributes( 'valuetype' );
$paramValue = $this->get( $name ); //TBD: missing default value, but not easy to find, as it's in the view param for now: $param->attributes( 'default' ) );
if ( $element->attributes( 'translate' ) == '_UE' ) {
$value = getLangDefinition( $value );
} elseif ( $element->attributes( 'translate' ) == 'yes' ) {
$value = CBTxt::T( $value );
}
switch ( $operator ) {
case '=':
case '==':
$result = ( $paramValue == $value );
break;
case '!=':
case '<>':
$result = ( $paramValue != $value );
break;
case '<':
$result = ( $paramValue < $value );
break;
case '>':
$result = ( $paramValue > $value );
break;
case '<=':
$result = ( $paramValue <= $value );
break;
case '>=':
$result = ( $paramValue >= $value );
break;
case 'regexp':
$result = ( preg_match( '/' . $value . '/', $paramValue ) == 1 );
break;
default:
break;
}
return $result;
}
function _htmlId( $control_name, $element ) {
$name = $element->attributes( 'name' );
if ( $name ) {
return str_replace( array( '[', ']' ), '__', 'cbfr_' . ( $control_name ? $control_name . '_' : '' ) . $name );
} else {
return null;
}
}
function _outputIdEqualHtmlId( $control_name, $element ) {
$htmlid = $this->_htmlId( $control_name, $element );
if ( $htmlid ) {
$htmlid = ' id="' . htmlspecialchars( $htmlid ) . '"';
}
return $htmlid;
}
function _renderLine( $param, $result, $control_name='params', $htmlFormatting = 'table', $htmlid = true ) {
$html = array();
if ( $htmlid ) {
$htid = $this->_outputIdEqualHtmlId( $control_name, $param );
} else {
$htid = null;
}
if ( $htmlFormatting == 'table' ) {
$html[] = 'attributes( 'class' ) ) ? ' class="' . htmlspecialchars( $param->attributes( 'class' ) ) . '"' : '' )
. '>';
if ( $param->attributes( 'label' ) === '' ) {
$html[] = '| attributes( 'valuedescription' ) ) ? ' onmouseover="return overlib(\''. str_replace( array( "\n", "\r" ), array( "<br />", "\\r" ), htmlspecialchars( addslashes( $param->attributes( 'valuedescription' ) ) ) ) .'\', CAPTION, \''
. htmlspecialchars( addslashes( $param->attributes( 'valuedescriptiontitle' ) ) ) . '\', BELOW, RIGHT);" onmouseout="return nd();"' : '' )
. '>' . $result[1] . ' | ';
} else {
$html[] = '' . $result[0] . ' | ';
$html[] = 'attributes( 'valuedescription' ) ) ? ' onmouseover="return overlib(\''. str_replace( array( "\n", "\r" ), array( "<br />", "\\r" ), htmlspecialchars( addslashes( $param->attributes( 'valuedescription' ) ) ) ) .'\', CAPTION, \''
. htmlspecialchars( addslashes( $param->attributes( 'valuedescriptiontitle' ) ) ) . '\', BELOW, RIGHT);" onmouseout="return nd();"' : '' )
. '>' . $result[1] . ' | ';
}
$html[] = '' . $result[2] . " | ";
$html[] = '
';
} elseif ( $htmlFormatting == 'td' ) {
$type = $param->attributes( 'type' );
$rowspan = $param->attributes( 'rowspan' );
if ( ( $type != 'hidden' ) && ( ( ! $rowspan ) || ( ( $rowspan == 'all' ) && ( $this->_modelOfDataRowsNumber == 0 ) ) ) ) {
$html[] = "\t\t\tattributes( 'class' ) ) ? ' class="' . htmlspecialchars( $param->attributes( 'class' ) ) . '"' : '' )
. ( ( $param->attributes( 'align' ) ) ? ' style="text-align:' . htmlspecialchars( $param->attributes( 'align' ) ) . ';"' :
( in_array( $param->attributes( 'type' ), array( 'checkmark', 'published' ) ) ? ' style="text-align:center;"' : '' ) )
. ( ( $param->attributes( 'nowrap' ) ) || in_array( $param->attributes( 'type' ), array( 'checkmark', 'ordering' ) ) ? ' nowrap="nowrap"' : '' )
. ( ( $param->attributes( 'valuedescription' ) ) ? ' onmouseover="return overlib(\''. htmlspecialchars( addslashes( str_replace( array( "\n", "\r" ), array( " ", "\\r" ), $param->attributes( 'valuedescription' ) ) ) ) .'\', CAPTION, \''
. htmlspecialchars( addslashes( $param->attributes( 'valuedescriptiontitle' ) ) ) . '\', BELOW, RIGHT);" onmouseout="return nd();"' : '' )
. ( ( $rowspan == 'all' ) ? ' rowspan="' . (int) count( $this->_modelOfDataRows ) . '"' : '' )
. '>'
. $result[1]
. " | ";
} else {
$html[] = '';
}
} elseif ( $htmlFormatting == 'span' ) {
if (substr( $result[0], -1 ) == ":" ) {
$result[0] = substr( $result[0], 0, -1 );
}
if (substr( $result[0], -2 ) == "%s" ) {
$result[0] = substr( $result[0], 0, -2 );
$html[] = 'attributes( 'class' ) ) ? ' class="' . htmlspecialchars( $param->attributes( 'class' ) ) . '"' : '' )
. '>'
. '' . $result[0] . ''
. 'attributes( 'valuedescription' ) ) ? ' onmouseover="return overlib(\''. str_replace( array( "\n", "\r" ), array( "<br />", "\\r" ), htmlspecialchars( addslashes( $param->attributes( 'valuedescription' ) ) ) ) .'\', CAPTION, \''
. htmlspecialchars( addslashes( $param->attributes( 'valuedescriptiontitle' ) ) ) . '\', BELOW, RIGHT);" onmouseout="return nd();"' : '' )
. '>' . $result[1] . ' '
. '
';
} else {
$html[] = 'attributes( 'class' ) ) ? ' class="' . htmlspecialchars( $param->attributes( 'class' ) ) . '"' : '' )
. '>'
. 'attributes( 'valuedescription' ) ) ? ' onmouseover="return overlib(\''. str_replace( array( "\n", "\r" ), array( "<br />", "\\r" ), htmlspecialchars( addslashes( $param->attributes( 'valuedescription' ) ) ) ) .'\', CAPTION, \''
. htmlspecialchars( addslashes( $param->attributes( 'valuedescriptiontitle' ) ) ) . '\', BELOW, RIGHT);" onmouseout="return nd();"' : '' )
. '>' . $result[1] . ' '
. '' . $result[0] . ''
. '
';
}
} elseif ( in_array( $htmlFormatting, array( 'none', 'fieldsListArray' ) ) ) {
$html[] = $result[1];
} else {
$html[] = "*" . $result[1] . "*";
}
return ( $htmlFormatting == 'fieldsListArray' ? $html : implode( "\n", $html ) );
}
function & _parseParamsColumn( $paramsName ) {
if ( ! isset( $this->_paramsOfColumns[$paramsName] ) ) {
$this->_paramsOfColumns[$paramsName] = new cbParamsBase( isset( $this->_modelOfData[0]->$paramsName ) ? $this->_modelOfData[0]->$paramsName : '' );
}
return $this->_paramsOfColumns[$paramsName]->_params;
}
/**
* Renders all parameters (including inheritance magic)
*
* @param CBSimpleXMLElement $element
* @param string $control_name
* @param cbTabs $tabs
* @param atring $viewType ( 'view', 'param', 'depends': means: tag => param, tag => view )
* @param atring $htmlFormatting ( 'table', 'td', 'span', 'none' )
* @return string HTML
*/
function renderAllParams( &$xmlParentElement, $control_name='params', $tabs=null, $viewType = 'depends', $htmlFormatting = 'table' ) {
$html = array();
$extenders = array();
if ( ( $this->_inverted ) && ( count( $this->_extenders ) == 1 ) ) {
$element = array_shift( $this->_extenders );
array_unshift( $this->_extenders, array( &$xmlParentElement ) );
$this->_inverted = false;
} else {
$element =& $xmlParentElement;
}
if ( is_array( $element ) ) {
foreach ( $element as $el ) {
$html[] = $this->renderAllParams( $el, $control_name, $tabs, $viewType, $htmlFormatting );
}
} else {
$identicalMatches = array();
$nonMatches = array();
if ( count( $this->_extenders ) > 0 ) {
$extenders = array_shift( $this->_extenders );
foreach ( $extenders as $ext ) {
if ( ( $ext->name() == 'inherit' ) || ( ( ( $ext->name() == $element->name() ) ) && $ext->attributes( 'name' ) == $element->attributes( 'name' ) ) ) {
if ( count( $element->children() ) > 0 ) {
foreach ( $ext->children() as $chld ) {
$this->_addTagMatch( $identicalMatches, $chld );
}
} else {
foreach ( $ext->children() as $chld ) {
$saveExtTwo = $this->_extenders;
$this->_extenders = array ();
$html[] = $this->renderOneParamAndChildren( $chld, $control_name, $tabs, $viewType, $htmlFormatting );
$this->_extenders = $saveExtTwo;
}
}
} else {
foreach ( $ext->children() as $chld ) {
$nonMatches[] = $chld;
}
}
}
}
foreach ( $element->children() as $param ) {
$idkeyMatched = $this->_getKeyOfTagMatch( $identicalMatches, $param );
if ( $idkeyMatched !== null ) {
foreach ( $identicalMatches as $idkey => $idmatch ) {
if ( $idkey == $idkeyMatched ) {
break;
} else {
foreach ( $idmatch as $extparam ) {
$saveExtTwo = $this->_extenders;
$this->_extenders = array ( array( &$param ) );
$html[] = $this->renderOneParamAndChildren( $extparam, $control_name, $tabs, $viewType, $htmlFormatting );
$this->_extenders = $saveExtTwo;
}
unset( $identicalMatches[$idkey] );
}
}
foreach ( $identicalMatches[$idkeyMatched] as $k => $extparam ) {
$saveExtTwo = $this->_extenders;
$this->_extenders = array ( array( &$param ) );
$this->_inverted = true;
$html[] = $this->renderOneParamAndChildren( $extparam, $control_name, $tabs, $viewType, $htmlFormatting );
$this->_inverted = false;
$this->_extenders = $saveExtTwo;
unset( $identicalMatches[$idkeyMatched][$k] );
}
} else {
$html[] = $this->renderOneParamAndChildren( $param, $control_name, $tabs, $viewType, $htmlFormatting );
}
}
foreach ( $identicalMatches as $idmatch ) {
foreach ( $idmatch as $extparam ) {
$saveExtTwo = $this->_extenders;
$this->_extenders = array ();
$html[] = $this->renderOneParamAndChildren( $extparam, $control_name, $tabs, $viewType, $htmlFormatting );
$this->_extenders = $saveExtTwo;
}
}
foreach ( $nonMatches as $chld ) {
// if ( ( count( $chld->children() ) == 0 ) || in_array( $chld->name(), array( 'param', 'field' ) ) ) {
// $html[] = $this->renderOneParamAndChildren( $chld, $control_name, $tabs, $viewType, $htmlFormatting );
// unset( $this->_extenders[$k] );
// }
}
// $this->_extenders = $saveExt;
if ( ( count( $element->children() ) < 1 ) && ( count( $extenders ) == 0 ) ) {
if ( $htmlFormatting == 'table' ) {
$html[] = "| " . _UE_NO_PARAMS . /* ": " . $element->name() . '(' . implode( ',', $element->attributes() ) . ')' . */ " |
";
} elseif ( $htmlFormatting == 'td' ) {
$html[] = "" . _UE_NO_PARAMS . " | ";
} elseif ( $htmlFormatting == 'fieldsListArray' ) {
// nothing
} else {
$html[] = "" . _UE_NO_PARAMS . "";
}
}
}
return ( $htmlFormatting == 'fieldsListArray' ? $html : implode( "\n", $html ) );
}
/**
* Returns a unique text id of a xml element depending on name and attribute values
* @access private
*
* @param CBSimpleXMLElement $el
* @return string
*/
function _uniqueTag( &$el ) {
$add = '';
foreach ( $el->attributes() as $k => $v ) {
$add .= '|**|' . $k . '|==|' . $v;
}
return ( $el->name()) . $add;
}
/*
function _explodeTag( $uniqueTag ) {
$tags = explode( '|**|', $uniqueTag );
$name = $tags[0];
$attr = array();
for ( $i = 1, $n = count( $tags ); $i < $n; $i++ ) {
$parts = explode( '|==|', $tags[$i] );
$attr[$parts[0]] = $parts[1];
}
}
*/
function _addTagMatch( &$identicalMatches, $chld ) {
$identicalMatches[$this->_uniqueTag( $chld )][] = $chld;
}
function _getKeyOfTagMatch( &$identicalMatches, &$param ) {
$paramTag = $this->_uniqueTag( $param );
foreach ( array_keys( $identicalMatches ) as $k ) {
if ( strpos( $k, $paramTag ) === 0 ) {
return $k;
}
}
return null;
}
function _getKeyOfTagMatchOLD( &$identicalMatches, $param ) {
if ( isset( $identicalMatches[$this->_uniqueTag( $param )] ) ) {
return $this->_uniqueTag( $param );
} else {
return null;
}
}
/**
* renders one parameter and its children
*
* @param CBSimpleXMLElement $param
* @param string $control_name
* @param cbTabs $tabs
* @param atring $viewType ( 'view', 'param', 'depends': means: tag => param, tag => view )
* @param atring $htmlFormatting ( 'table', 'td', 'span', 'none' )
* @return string HTML
*/
var $_inverted = false;
var $_extenders = array();
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;
}
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 );
$html[] = $this->_renderLine( $param, $result, $control_name, $htmlFormatting );
if ( ( ! ( $viewType == 'view' ) ) && ( $param->attributes( 'onchange' ) == 'evaluate' ) ) {
$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 ) {
$valueObj =& $this->_parseParamsColumn( $paramsName );
$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 = htmlspecialchars( $param->attributes( 'title' ) );
if ( $title ) {
$title = ' title="' . $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( unHtmlspecialchars( $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] = '' . ( trim( $result[1] ) ? $result[1] : '---' ) . '';
} elseif ( $title ) {
$result[1] = '' . $result[1] . '';
}
}
$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 = '';
} elseif ( $htmlFormatting == 'span' ) {
$html[] = '';
} elseif ( $htmlFormatting == 'fieldsListArray' ) {
// nothing
} else {
$html[] = '';
}
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[] = '| ';
} elseif ( $htmlFormatting == 'td' ) {
$html[] = ' | ';
}
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[] = ' |
';
} elseif ( $htmlFormatting == 'td' ) {
$html[] = '';
}
}
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[] = '';
$tabName = $param->attributes( 'name' );
$tabTitle = $param->attributes( 'title' );
$description = $param->attributes( 'description' );
if ( $tabTitle ) {
$html[] = '' . CBTxt::Th( getLangDefinition( $tabTitle ) ) . ' |
';
}
if ( $description || ! $tabTitle ) {
$html[] = '| ' . CBTxt::Th( getLangDefinition( $description ) ) . ' |
'; // either description or a spacer.
}
}
$html[] = $this->renderAllParams( $param, $control_name, $tabs, $viewType, $htmlFormatting );
if ( $htmlFormatting != 'fieldsListArray' ) {
$html[] = "\n\t
";
$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 ) );
}
/**
* @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();
$name = $param->attributes( 'name' );
$label = CBTxt::T( getLangDefinition($param->attributes( 'label' )));
$description = CBTxt::T( getLangDefinition(htmlspecialchars($param->attributes( 'description' ))));
$value = $this->get( $name, $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] = '
';
} else if ( $result[0] ) {
if ($name == '@spacer') $result[0] = ''.$result[0].'';
else $result[0] .= ':';
}
$result[1] = null;
$type = $param->attributes( 'type' );
/* 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 ' . $o->name() . ' ' . $o->attributes( 'name' ) . ' type: ' . $o->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] = $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] = _HANDLER . ' = ' . $type;
}
if ( $description ) {
$result[2] = cbFieldTip( null, $description, $name );
} else {
$result[2] = '';
}
if ( ( ! $view ) && ( ! $result[1] ) ) {
$result = array( null, null, null );
}
return $result;
}
function control_name( $control_name, $name ) {
if ( $control_name ) {
return $control_name .'['. $name .']';
} else {
return $name;
}
}
function control_id( $control_name, $name ) {
return moscomprofilerHTML::htmlId( $this->control_name( $control_name, $name ) );
/*
if ( $control_name ) {
return str_replace( array( '[', ']' ), array( '__', '' ), $control_name ) .'__'. $name;
} else {
return $name;
}
*/
}
/**
* @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_text( $name, $value, &$node, $control_name ) {
$size = $node->attributes( 'size' );
$maxlength = $node->attributes( 'maxlength' );
return '';
}
/**
* Calls method or function of plugin/tab
*
* @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_custom( $name, $value, &$node, $control_name ) {
global $_CB_database, $_PLUGINS;
$pluginId = $this->_pluginObject->id;
$tabId = $this->_tabid;
$class = $node->attributes( 'class' );
$method = $node->attributes( 'method' );
if(!is_null($class) && strlen(trim($class)) > 0) {
if ($pluginId !== null) {
$params = null;
if ($tabId !== null) {
$_CB_database->setQuery( "SELECT * FROM #__comprofiler_tabs t"
. "\n WHERE t.enabled=1 AND t.tabid = " . (int) $tabId);
$oTabs = $_CB_database->loadObjectList();
if (count($oTabs)>0) $params = $oTabs[0]->params;
}
$args = array($name,$value,$control_name);
$_PLUGINS->plugVarValue($pluginId, "published", "1"); // need to be able to call also unpublished plugin for parametring
return $_PLUGINS->call($pluginId,$method,$class,$args,$params);
} else {
$udc = new $class();
if(method_exists($udc,$method)) {
return call_user_func_array(array($udc,$method),array($name,$value,$control_name));
}
}
} elseif (function_exists( $method )) {
return call_user_func_array( $method, array($name,$value,$control_name) );
}
return "";
}
/**
* @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_list( $name, $value, &$node, $control_name ) {
$options = array();
if ( ( $node->attributes( 'blanktext' ) ) && ( ( $node->attributes( 'hideblanktext' ) != 'true' ) || ( $value == $node->attributes( 'default' ) ) ) ) {
$options[] = moscomprofilerHTML::makeOption( $node->attributes( 'default' ), $node->attributes( 'blanktext' ) );
}
foreach ( $node->children() as $option ) {
if ( $option->name() == 'option' ) {
if ( $option->attributes( 'index' ) ) {
$val = $option->attributes( 'index' );
} else {
$val = $option->attributes( 'value' );
}
$text = CBTxt::T( getLangDefinition($option->data()) );
$options[] = moscomprofilerHTML::makeOption( $val, $text );
} elseif ( $option->name() == 'optgroup' ) {
$text = CBTxt::T( getLangDefinition( $option->attributes( 'label' ) ) );
$options[] = moscomprofilerHTML::makeOptGroup( $text );
foreach ( $option->children() as $optGroupOption ) {
if ( $optGroupOption->name() == 'option' ) {
if ( $optGroupOption->attributes( 'index' ) ) {
$val = $optGroupOption->attributes( 'index' );
} else {
$val = $optGroupOption->attributes( 'value' );
}
$text = CBTxt::T( getLangDefinition($optGroupOption->data()) );
$options[] = moscomprofilerHTML::makeOption( $val, $text );
}
}
$options[] = moscomprofilerHTML::makeOptGroup( null );
}
}
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
/**
* @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_radio( $name, $value, &$node, $control_name ) {
$options = array();
foreach ( $node->children() as $option ) {
if ( $option->attributes( 'index' ) ) {
$val = $option->attributes( 'index' );
} else {
$val = $option->attributes( 'value' );
}
$text = CBTxt::T( getLangDefinition($option->data()) );
$options[] = moscomprofilerHTML::makeOption( $val, $text );
}
return moscomprofilerHTML::radioList( $options, ''. $this->control_name( $control_name, $name ) . '', '', 'value', 'text', $value ); //TBD missing id : id="' . $this->control_id( $control_name, $name ) . '"
}
/**
* @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_mos_section( $name, $value, &$node, $control_name ) {
global $_CB_database;
$query = "SELECT id AS value, title AS text"
. "\n FROM #__sections"
. "\n WHERE published = 1 AND scope = 'content'"
. "\n ORDER BY title"
;
$_CB_database->setQuery( $query );
$options = $_CB_database->loadObjectList();
array_unshift( $options, moscomprofilerHTML::makeOption( '0', '- Select Content Section -' ) );
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
/**
* @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_mos_category( $name, $value, &$node, $control_name ) {
global $_CB_database;
$query = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text"
. "\n FROM #__categories AS c"
. "\n LEFT JOIN #__sections AS s ON s.id=c.section"
. "\n WHERE c.published = 1 AND s.scope='content'"
. "\n ORDER BY c.title"
;
$_CB_database->setQuery( $query );
$options = $_CB_database->loadObjectList();
array_unshift( $options, moscomprofilerHTML::makeOption( '0', '- Select Content Category -' ) );
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
/**
* @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_field( $name, $value, &$node, $control_name ) {
global $_CB_database;
$query = "SELECT f.fieldid AS value, f.title AS text"
. "\n FROM #__comprofiler_fields AS f"
. "\n LEFT JOIN #__comprofiler_tabs AS t ON t.tabid = f.tabid"
. "\n WHERE f.published = 1 AND f.name != 'NA'"
. "\n ORDER BY t.ordering, f.ordering"
;
$_CB_database->setQuery( $query );
$options = $_CB_database->loadObjectList();
for ($i=0, $n=count($options); $i<$n; $i++) {
$options[$i]->text = CBTxt::T( getLangDefinition( $options[$i]->text ) );
}
array_unshift( $options, moscomprofilerHTML::makeOption( '0', '- Select Field -' ) );
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
/**
* @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_mos_menu( $name, $value, &$node, $control_name ) {
$menuTypes = $this->_form_mos_menu__menutypes();
foreach( $menuTypes as $menutype ) {
$options[] = moscomprofilerHTML::makeOption( $menutype, $menutype );
}
array_unshift( $options, moscomprofilerHTML::makeOption( '', '- Select Menu -' ) );
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
function _form_mos_menu__menutypes() {
global $_CB_database;
$query = "SELECT params"
. "\n FROM #__modules"
. "\n WHERE module = 'mod_mainmenu'"
//. "\n ORDER BY title"
;
$_CB_database->setQuery( $query );
$modMenus = $_CB_database->loadObjectList();
$query = "SELECT menutype"
. "\n FROM #__menu"
. "\n GROUP BY menutype"
//. "\n ORDER BY menutype"
;
$_CB_database->setQuery( $query );
$menuMenus = $_CB_database->loadResultArray();
$menuTypes = array();
foreach ( $modMenus as $modMenu ) {
$modParams = new cbParamsBase( $modMenu->params );
$menuType = $modParams->get( 'menutype' );
if ( ! $menuType ) {
$menuType = 'mainmenu';
}
if ( ! in_array( $menuType, $menuTypes ) ) {
$menuTypes[] = $menuType;
}
}
foreach ( $menuMenus as $menuType ) {
if ( ! in_array( $menuType, $menuTypes ) ) {
$menuTypes[] = $menuType;
}
}
asort( $menuTypes );
return $menuTypes;
}
/**
* @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_imagelist( $name, $value, &$node, $control_name ) {
global $_CB_framework;
// path to images directory
$path = $_CB_framework->getCfg('absolute_path') . $node->attributes( 'directory' );
$files = cbReadDirectory( $path, '\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$' );
$options = array();
foreach ($files as $file) {
$options[] = moscomprofilerHTML::makeOption( $file, $file );
}
if ( !$node->attributes( 'hide_none' ) ) {
array_unshift( $options, moscomprofilerHTML::makeOption( '-1', '- Do not use an image -' ) );
}
if ( !$node->attributes( 'hide_default' ) ) {
array_unshift( $options, moscomprofilerHTML::makeOption( '', '- Use Default image -' ) );
}
return moscomprofilerHTML::selectList( $options, ''. $this->control_name( $control_name, $name ) . '', 'class="inputbox" id="' . $this->control_id( $control_name, $name ) . '"', 'value', 'text', $value, 2 );
}
/**
* @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_textarea( $name, $value, &$node, $control_name ) {
$rows = $node->attributes( 'rows' );
$cols = $node->attributes( 'cols' );
// convert
tags so they are not visible when editing
$value = str_replace( array( "\\\\", '\n', '\r' ), array( "\\", "\n", "\r" ), $value );
return '';
}
/**
* @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_spacer( $name, $value, &$node, $control_name ) {
if ( $value ) {
return ''.$value.'';
} else {
return '
';
}
}
/**
* @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 ); // size="10"
return $content;
}
/**
* special handling for textarea param
*/
function textareaHandling( &$txt ) {
$total = count( $txt );
for( $i=0; $i < $total; $i++ ) {
if ( strstr( $txt[$i], "\n" ) ) {
$txt[$i] = str_replace( array( "\\", "\n", "\r" ), array( "\\\\", '\n', '\r' ) , $txt[$i] );
}
}
$ret = implode( "\n", $txt );
return $ret;
}
}
/**
* This class is EXPERIMENTAL WIP (reasearch Work In Progress)
* It is not yet ready for use in CB API and will be developped in a probably incompatible way.
* That's why it's licence is not yet GPL. It will be released GPL once completed, but that's not this version yet.
* @license For CB 1.1 internal use only. Copying outside CB not permitted, as it's not yet final. Thanks.
*/
class cbDrawController {
/** CB page navigator (and ordering)
* @var cbPageNav */
var $pageNav;
/** @var CBSimpleXMLElement */
var $_tableBrowserModel;
/** element
* @var CBSimpleXMLElement*/
var $_actions;
var $_options;
var $_tableName;
var $_search;
var $_searchFields;
var $_filters;
var $_statistics;
var $_control_name;
function cbDrawController( $tableBrowserModel, $actions, $options ) {
$this->_tableBrowserModel =& $tableBrowserModel;
$this->_actions =& $actions;
$this->_options = $options;
$this->_tableName = $tableBrowserModel->attributes( 'name' ); // TBD: does this really belong here ???!
}
function fieldName( $fieldName ) {
// search, toggle, idcid[], order[], subtask
$arrayBrackets = '';
if ( substr( $fieldName, -2 ) == '[]' ) {
$fieldName = substr( $fieldName, 0 , -2 );
$arrayBrackets = '[]';
}
return $this->_tableName . '[' . $fieldName . ']' . $arrayBrackets;
}
function fieldId( $fieldId, $number=null, $htmlspecs=true ) { //TBD: htmlspecialchars....
// id
return 'cb' . $this->_tableName . $fieldId . $number;
}
function taskName( $subTask, $htmlspecs=true ) {
// for saveorder, publish, unpublish, orderup, orderdown
return $this->_options['task'];
}
function fieldValue( $fieldName ) {
if ( $fieldName == 'search' ) {
return $this->_search;
}
return '';
}
function subtaskName( $htmlspecs=true ) {
// saveorder, publish, unpublish, orderup, orderdown
return $this->fieldName( 'subtask' );
}
function subtaskValue( $subTask, $htmlspecs=true ) {
return $subTask;
}
function setSearch( &$search, $searchFields ) {
$this->_search =& $search;
$this->_searchFields = $searchFields;
}
function hasSearchFields( ) {
return ( $this->_searchFields == true );
}
function quicksearchfields() {
$result = '';
if ( $this->hasSearchFields() ) {
if ( $this->pageNav !== null ) {
$onchangeJs = $this->pageNav->js_limitstart(0);
} else {
$onchangeJs = 'cbParentForm(this).submit();';
}
$result = '';
}
return $result;
}
/**
* returns HTML code for the filters
*
* @param cbEditRowView $editRowView
* @param string $htmlFormatting ( 'table', 'td', 'none' )
* @return unknown
*/
function filters( &$editRowView, $htmlFormatting = 'none' ) {
global $_CB_framework;
$lists = array();
if ( count( $this->_filters ) > 0 ) {
/*
if ( $this->pageNav !== null ) {
$onchangeJs = $this->pageNav->js_limitstart(0);
} else {
$onchangeJs = 'cbParentForm(this).submit();';
}
*/
$valueObj = new stdClass();
$saveName = array();
foreach ( $this->_filters as $k => $v ) {
$valname = 'filter_' . $v['name'];
$valueObj->$valname = $v['value'];
// $filterXml = $v['xml'];
$saveName[$k] = $v['xml']->attributes( 'name' );
$this->_filters[$k]['xml']->addAttribute( 'name', 'filter_' . $saveName[$k] );
$editRowView->setSelectValues( $v['xml'], $v['selectValues'] );
}
$renderedViews = array();
foreach ( $this->_filters as $k => $v ) {
// tag: $v['xml']
$viewName = $v['xml']->attributes( 'view' );
if ( $viewName ) {
$view = $this->_filters[$k]['xmlparent']->getChildByNameAttr( 'view', 'name', $viewName );
if ( ! $view ) {
echo 'filter view ' . $viewName . ' not defined in filters';
}
} else {
$view = $this->_filters[$k]['xml']->getElementByPath( 'view' );
}
if ( $view ) {
if ( ( ! $viewName ) || ! in_array( $viewName, $renderedViews ) ) {
$lists[$k] = $editRowView->renderEditRowView( $view, $valueObj, $this, $this->_options, 'param', $htmlFormatting );
}
if ( $viewName ) {
$renderedViews[] = $viewName;
}
} else {
$editRowView->pushModelOfData( $valueObj );
$result = $editRowView->renderParam( $this->_filters[$k]['xml'], $this->control_name(), false );
$editRowView->popModelOfData();
$lists[$k] = ''
. '' . $result[0] . ' '
. '' . $result[2] . ''
. '' . $result[1] . ''
. '
';
}
}
foreach ( $this->_filters as $k => $v ) {
$this->_filters[$k]['xml']->addAttribute( 'name', $saveName[$k] );
}
if ( count( $lists ) > 1 ) {
$adminimagesdir = $_CB_framework->getCfg( 'live_site' ) . '/components/com_comprofiler/images/';
$lists[] = '';
}
}
return $lists;
}
function setFilters( &$filters ){
$this->_filters = $filters;
}
function setStatistics( &$statsArray ) {
$this->_statistics =& $statsArray;
}
function & getStatistics( ) {
return $this->_statistics;
}
function control_name( ) {
return $this->_control_name;
}
function setControl_name( $control_name ) {
$this->_control_name = $control_name;
}
function drawUrl( $cbUri, &$sourceElem, &$data, $id, $htmlspecialchars = true, $inPage = true ) {
global $_CB_framework;
$ui = $_CB_framework->getUi();
if ( substr( $cbUri, 0, 4 ) == 'cbo:' ) {
$subTaskValue = substr( $cbUri, 4 );
switch ( $subTaskValue ) {
case 'newrow':
$id = 0;
// fallthrough: no break on purpose.
case 'rowedit': //TBD this is duplicate of below
$baseUrl = ( ( $ui != 2 ) ? ( $inPage ? 'index.php' : 'index2.php' ) : ( $inPage ? 'index2.php' : 'index3.php' ) );
$baseUrl .= '?option=' . $this->_options['option'] . '&task=' . $this->_options['task'] . '&cid=' . $this->_options['pluginid'];
$url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes( 'name' ) . '&action=editrow'; // below: . '&tid=' . $id;
break;
case 'saveorder':
case 'editrows':
case 'deleterows':
case 'copyrows':
case 'updaterows':
case 'publish':
case 'unpublish':
case 'enable':
case 'disable':
default:
$url = 'javascript:cbDoListTask(this, ' // cb //TBD: this is duplicate of pager.
. "'" . $this->taskName( false ). "','" // task
. $this->subtaskName( false ). "','" // subtaskName
. $this->subtaskValue( $subTaskValue, false ) . "','" // subtaskValue
. $this->fieldId( 'id', null, false ) . "'" // fldName
. ");";
break;
}
} elseif ( substr( $cbUri, 0, 10 ) == 'cb_action:' ) {
$actionName = substr( $cbUri, 10 );
$action =& $this->_actions->getChildByNameAttr( 'action', 'name', $actionName );
if ( $action ) {
$requestNames = explode( ' ', $action->attributes( 'request' ) );
$requestValues = explode( ' ', $action->attributes( 'action' ) );
$parametersValues = explode( ' ', $action->attributes( 'parameters' ) );
$baseUrl = ( ( $ui != 2 ) ? ( $inPage ? 'index.php' : 'index2.php' ) : ( $inPage ? 'index2.php' : 'index3.php' ) );
$baseUrl .= '?';
$baseRequests = array( 'option' => 'option', 'task' => 'task', 'cid' => 'pluginid' );
$urlParams = array();
foreach ( $baseRequests as $breq => $breqOptionsValue ) {
if ( ( ! ( in_array( $breq, $requestNames ) || in_array( $breq, $parametersValues ) ) ) && isset( $this->_options[$breqOptionsValue] ) ) {
$urlParams[$breq] = $breq . '=' . $this->_options[$breqOptionsValue];
}
}
$url = $baseUrl;
for ( $i = 0, $n = count( $requestNames ); $i < $n; $i++ ) {
$urlParams[$requestNames[$i]] = $requestNames[$i] . '=' . $requestValues[$i]; // other parameters = paramvalues added below
}
$url = $baseUrl . implode( '&', $urlParams );
} else {
$url = "#action_not_defined:" . $actionName;
}
} else {
$url = $cbUri;
}
if ( ! cbStartOfStringMatch( $url, 'javascript:' ) ) {
// get the parameters of action/link from XML :
$parametersNames = explode( ' ', $sourceElem->attributes( 'parameters' ) );
$parametersValues = explode( ' ', $sourceElem->attributes( 'paramvalues' ) );
$parametersValuesTypes = explode( ' ', $sourceElem->attributes( 'paramvaluestypes' ) );
// add currently activated filters to the parameters:
if ( count( $this->_filters ) > 0 ) {
foreach ( $this->_filters as $k => $v ) {
$filterName = $this->fieldName( $k );
if ( ( $v['value'] != $v['default'] ) && ( ! in_array( $filterName, $parametersNames ) ) ) {
$parametersNames[] = $filterName;
$parametersValues[] = "'" . $v['value'] . "'"; //TBD: check this.
}
}
}
// add current search string, if any:
$searchName = $this->fieldName( 'search' );
$searchValue = $this->fieldValue( 'search' );
if ( $searchValue && ( ! in_array( $searchName, $parametersNames ) ) ) {
$parametersNames[] = $searchName;
$parametersValues[] = "'" . $searchValue . "'";
}
// generate current action (and parameters ?) as cbprevstate
$cbprevstate = array();
foreach ( $this->_options as $req => $act ) {
if ( $req && $act && ! in_array( $req, array( 'cbprevstate' ) ) ) {
$cbprevstate[] = $req . '=' . $act;
}
}
$parametersNames[] = 'cbprevstate';
$parametersValues[] = "'" . base64_encode( implode( '&', $cbprevstate ) ) . "'";
// finally generate URL:
for ( $i = 0, $n = count( $parametersNames ); $i < $n; $i++ ) {
$nameOfVariable = $parametersValues[$i];
if ( $nameOfVariable ) {
if ( isset( $parametersValuesTypes[$i] ) && $parametersValuesTypes[$i] ) {
if ( $parametersValuesTypes[$i] == 'sql:field' ) {
$nameOfVariable = $data->$nameOfVariable;
} else {
// $nameOfVariable untouched
}
} elseif ( ( substr( $nameOfVariable, 0, 1 ) == "'" ) && ( substr( $nameOfVariable, -1 ) == "'" ) ) {
$nameOfVariable = substr( $nameOfVariable, 1, -1 );
} else {
$nameOfVariable = $data->$nameOfVariable;
}
$url .= '&' . $parametersNames[$i] . '=' . urlencode( $nameOfVariable );
}
}
}
if ( $htmlspecialchars ) {
$url = htmlspecialchars( $url );
}
return $url;
}
function drawPageNvigator( $positionType /* , $viewModelElement ??? */ ) {
}
function createPageNvigator( $total, $limitstart, $limit ) {
cbimport( 'cb.pagination' );
$this->pageNav = new cbPageNav( $total, $limitstart, $limit, array( &$this, 'fieldName' ), $this );
$this->pageNav->setControllerView( $this );
}
/* $this->pageNav =& $pageNav;
$this->filters =& $this->filters;
$this->search =& $this->search;
*/
} // class cbDrawController
?>